1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/common/extensions/api/extension_action/browser_action_handler.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "base/values.h"
10 #include "extensions/common/extension.h"
11 #include "extensions/common/feature_switch.h"
12 #include "extensions/common/file_util.h"
13 #include "extensions/common/manifest.h"
14 #include "extensions/common/manifest_constants.h"
15 #include "grit/generated_resources.h"
17 namespace extensions
{
19 BrowserActionHandler::BrowserActionHandler() {
22 BrowserActionHandler::~BrowserActionHandler() {
25 bool BrowserActionHandler::Parse(Extension
* extension
,
26 base::string16
* error
) {
27 const base::DictionaryValue
* dict
= NULL
;
28 if (!extension
->manifest()->GetDictionary(
29 manifest_keys::kBrowserAction
, &dict
)) {
30 *error
= base::ASCIIToUTF16(manifest_errors::kInvalidBrowserAction
);
34 scoped_ptr
<ActionInfo
> action_info
= ActionInfo::Load(extension
, dict
, error
);
35 if (!action_info
.get())
36 return false; // Failed to parse browser action definition.
38 ActionInfo::SetBrowserActionInfo(extension
, action_info
.release());
43 bool BrowserActionHandler::Validate(
44 const Extension
* extension
,
46 std::vector
<InstallWarning
>* warnings
) const {
47 const ActionInfo
* action
= ActionInfo::GetBrowserActionInfo(extension
);
48 if (action
&& !action
->default_icon
.empty() &&
49 !file_util::ValidateExtensionIconSet(
52 IDS_EXTENSION_LOAD_ICON_FOR_BROWSER_ACTION_FAILED
,
59 const std::vector
<std::string
> BrowserActionHandler::Keys() const {
60 return SingleKey(manifest_keys::kBrowserAction
);
63 } // namespace extensions