OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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. |
| 4 |
| 5 #include "chrome/common/extensions/manifest_handlers/extension_action_handler.h" |
| 6 |
| 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "base/values.h" |
| 9 #include "chrome/common/extensions/api/extension_action/action_info.h" |
| 10 #include "chrome/common/extensions/extension_constants.h" |
| 11 #include "chrome/grit/generated_resources.h" |
| 12 #include "extensions/common/extension.h" |
| 13 #include "extensions/common/file_util.h" |
| 14 #include "extensions/common/manifest_constants.h" |
| 15 |
| 16 namespace extensions { |
| 17 |
| 18 ExtensionActionHandler::ExtensionActionHandler() { |
| 19 } |
| 20 |
| 21 ExtensionActionHandler::~ExtensionActionHandler() { |
| 22 } |
| 23 |
| 24 bool ExtensionActionHandler::Parse(Extension* extension, |
| 25 base::string16* error) { |
| 26 const char* key = NULL; |
| 27 const char* error_key = NULL; |
| 28 if (extension->manifest()->HasKey(manifest_keys::kPageAction)) { |
| 29 key = manifest_keys::kPageAction; |
| 30 error_key = manifest_errors::kInvalidPageAction; |
| 31 } |
| 32 |
| 33 if (extension->manifest()->HasKey(manifest_keys::kBrowserAction)) { |
| 34 if (key != NULL) { |
| 35 // An extension cannot have both browser and page actions. |
| 36 *error = base::ASCIIToUTF16(manifest_errors::kOneUISurfaceOnly); |
| 37 return false; |
| 38 } |
| 39 key = manifest_keys::kBrowserAction; |
| 40 error_key = manifest_errors::kInvalidBrowserAction; |
| 41 } |
| 42 DCHECK(key); |
| 43 |
| 44 const base::DictionaryValue* dict = NULL; |
| 45 if (!extension->manifest()->GetDictionary(key, &dict)) { |
| 46 *error = base::ASCIIToUTF16(error_key); |
| 47 return false; |
| 48 } |
| 49 |
| 50 scoped_ptr<ActionInfo> action_info = ActionInfo::Load(extension, dict, error); |
| 51 if (!action_info) |
| 52 return false; // Failed to parse browser action definition. |
| 53 |
| 54 if (key == manifest_keys::kPageAction) |
| 55 ActionInfo::SetPageActionInfo(extension, action_info.release()); |
| 56 else |
| 57 ActionInfo::SetBrowserActionInfo(extension, action_info.release()); |
| 58 |
| 59 return true; |
| 60 } |
| 61 |
| 62 bool ExtensionActionHandler::Validate( |
| 63 const Extension* extension, |
| 64 std::string* error, |
| 65 std::vector<InstallWarning>* warnings) const { |
| 66 int error_message = 0; |
| 67 const ActionInfo* action = ActionInfo::GetPageActionInfo(extension); |
| 68 if (action) { |
| 69 error_message = IDS_EXTENSION_LOAD_ICON_FOR_PAGE_ACTION_FAILED; |
| 70 } else { |
| 71 action = ActionInfo::GetBrowserActionInfo(extension); |
| 72 error_message = IDS_EXTENSION_LOAD_ICON_FOR_BROWSER_ACTION_FAILED; |
| 73 } |
| 74 |
| 75 if (action && !action->default_icon.empty() && |
| 76 !file_util::ValidateExtensionIconSet( |
| 77 action->default_icon, extension, error_message, error)) { |
| 78 return false; |
| 79 } |
| 80 return true; |
| 81 } |
| 82 |
| 83 const std::vector<std::string> ExtensionActionHandler::Keys() const { |
| 84 std::vector<std::string> keys; |
| 85 keys.push_back(manifest_keys::kPageAction); |
| 86 keys.push_back(manifest_keys::kBrowserAction); |
| 87 return keys; |
| 88 } |
| 89 |
| 90 } // namespace extensions |
OLD | NEW |