OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/common/extensions/api/extension_action/browser_action_handler.h
" | 5 #include "chrome/common/extensions/api/extension_action/browser_action_handler.h
" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/common/extensions/extension.h" | 10 #include "chrome/common/extensions/extension.h" |
11 #include "chrome/common/extensions/extension_constants.h" | 11 #include "chrome/common/extensions/extension_constants.h" |
12 #include "chrome/common/extensions/extension_file_util.h" | 12 #include "chrome/common/extensions/extension_file_util.h" |
13 #include "chrome/common/extensions/extension_manifest_constants.h" | 13 #include "chrome/common/extensions/extension_manifest_constants.h" |
14 #include "chrome/common/extensions/feature_switch.h" | 14 #include "chrome/common/extensions/feature_switch.h" |
15 #include "chrome/common/extensions/manifest.h" | 15 #include "chrome/common/extensions/manifest.h" |
16 #include "chrome/common/extensions/manifest_handler_helpers.h" | |
17 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
18 | 17 |
19 namespace extensions { | 18 namespace extensions { |
20 | 19 |
21 BrowserActionHandler::BrowserActionHandler() { | 20 BrowserActionHandler::BrowserActionHandler() { |
22 } | 21 } |
23 | 22 |
24 BrowserActionHandler::~BrowserActionHandler() { | 23 BrowserActionHandler::~BrowserActionHandler() { |
25 } | 24 } |
26 | 25 |
27 bool BrowserActionHandler::Parse(Extension* extension, | 26 bool BrowserActionHandler::Parse(Extension* extension, |
28 string16* error) { | 27 string16* error) { |
29 const DictionaryValue* dict = NULL; | 28 const DictionaryValue* dict = NULL; |
30 if (!extension->manifest()->GetDictionary( | 29 if (!extension->manifest()->GetDictionary( |
31 extension_manifest_keys::kBrowserAction, &dict)) { | 30 extension_manifest_keys::kBrowserAction, &dict)) { |
32 *error = ASCIIToUTF16(extension_manifest_errors::kInvalidBrowserAction); | 31 *error = ASCIIToUTF16(extension_manifest_errors::kInvalidBrowserAction); |
33 return false; | 32 return false; |
34 } | 33 } |
35 | 34 |
36 scoped_ptr<ActionInfo> action_info = | 35 scoped_ptr<ActionInfo> action_info = ActionInfo::Load(extension, dict, error); |
37 manifest_handler_helpers::LoadActionInfo(extension, dict, error); | |
38 if (!action_info.get()) | 36 if (!action_info.get()) |
39 return false; // Failed to parse browser action definition. | 37 return false; // Failed to parse browser action definition. |
40 | 38 |
41 ActionInfo::SetBrowserActionInfo(extension, action_info.release()); | 39 ActionInfo::SetBrowserActionInfo(extension, action_info.release()); |
42 | 40 |
43 return true; | 41 return true; |
44 } | 42 } |
45 | 43 |
46 bool BrowserActionHandler::Validate( | 44 bool BrowserActionHandler::Validate( |
47 const Extension* extension, | 45 const Extension* extension, |
48 std::string* error, | 46 std::string* error, |
49 std::vector<InstallWarning>* warnings) const { | 47 std::vector<InstallWarning>* warnings) const { |
50 const ActionInfo* action = | 48 const ActionInfo* action = ActionInfo::GetBrowserActionInfo(extension); |
51 extensions::ActionInfo::GetBrowserActionInfo(extension); | |
52 if (action && !action->default_icon.empty() && | 49 if (action && !action->default_icon.empty() && |
53 !extension_file_util::ValidateExtensionIconSet( | 50 !extension_file_util::ValidateExtensionIconSet( |
54 action->default_icon, | 51 action->default_icon, |
55 extension, | 52 extension, |
56 IDS_EXTENSION_LOAD_ICON_FOR_BROWSER_ACTION_FAILED, | 53 IDS_EXTENSION_LOAD_ICON_FOR_BROWSER_ACTION_FAILED, |
57 error)) { | 54 error)) { |
58 return false; | 55 return false; |
59 } | 56 } |
60 return true; | 57 return true; |
61 } | 58 } |
62 | 59 |
63 const std::vector<std::string> BrowserActionHandler::Keys() const { | 60 const std::vector<std::string> BrowserActionHandler::Keys() const { |
64 return SingleKey(extension_manifest_keys::kBrowserAction); | 61 return SingleKey(extension_manifest_keys::kBrowserAction); |
65 } | 62 } |
66 | 63 |
67 } // namespace extensions | 64 } // namespace extensions |
OLD | NEW |