Chromium Code Reviews| 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/script_badge_handler.h" | 5 #include "chrome/common/extensions/api/extension_action/script_badge_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/api/icons/icons_handler.h" | |
| 10 #include "chrome/common/extensions/extension.h" | 11 #include "chrome/common/extensions/extension.h" |
| 11 #include "chrome/common/extensions/extension_constants.h" | 12 #include "chrome/common/extensions/extension_constants.h" |
| 12 #include "chrome/common/extensions/extension_manifest_constants.h" | 13 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 13 #include "chrome/common/extensions/feature_switch.h" | 14 #include "chrome/common/extensions/feature_switch.h" |
| 14 #include "chrome/common/extensions/manifest.h" | 15 #include "chrome/common/extensions/manifest.h" |
| 15 #include "chrome/common/extensions/manifest_handler_helpers.h" | 16 #include "chrome/common/extensions/manifest_handler_helpers.h" |
| 16 #include "extensions/common/install_warning.h" | 17 #include "extensions/common/install_warning.h" |
| 17 | 18 |
| 18 namespace errors = extension_manifest_errors; | 19 namespace errors = extension_manifest_errors; |
| 19 | 20 |
| 20 namespace extensions { | 21 namespace extensions { |
| 21 | 22 |
| 22 ScriptBadgeHandler::ScriptBadgeHandler() { | 23 ScriptBadgeHandler::ScriptBadgeHandler() { |
| 24 prerequisite_keys_.push_back(extension_manifest_keys::kIcons); | |
| 23 } | 25 } |
| 24 | 26 |
| 25 ScriptBadgeHandler::~ScriptBadgeHandler() { | 27 ScriptBadgeHandler::~ScriptBadgeHandler() { |
| 26 } | 28 } |
| 27 | 29 |
| 30 const std::vector<std::string>& ScriptBadgeHandler::PrerequisiteKeys() { | |
|
Yoyo Zhou
2013/02/27 20:09:14
By the way, I later realized, it doesn't make sens
| |
| 31 return prerequisite_keys_; | |
| 32 } | |
| 33 | |
| 28 bool ScriptBadgeHandler::Parse(Extension* extension, string16* error) { | 34 bool ScriptBadgeHandler::Parse(Extension* extension, string16* error) { |
| 29 scoped_ptr<ActionInfo> action_info(new ActionInfo); | 35 scoped_ptr<ActionInfo> action_info(new ActionInfo); |
| 30 | 36 |
| 31 // Provide a default script badge if one isn't declared in the manifest. | 37 // Provide a default script badge if one isn't declared in the manifest. |
| 32 if (!extension->manifest()->HasKey(extension_manifest_keys::kScriptBadge)) { | 38 if (!extension->manifest()->HasKey(extension_manifest_keys::kScriptBadge)) { |
| 33 SetActionInfoDefaults(extension, action_info.get()); | 39 SetActionInfoDefaults(extension, action_info.get()); |
| 34 ActionInfo::SetScriptBadgeInfo(extension, action_info.release()); | 40 ActionInfo::SetScriptBadgeInfo(extension, action_info.release()); |
| 35 return true; | 41 return true; |
| 36 } | 42 } |
| 37 | 43 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 | 88 |
| 83 bool ScriptBadgeHandler::AlwaysParseForType(Manifest::Type type) { | 89 bool ScriptBadgeHandler::AlwaysParseForType(Manifest::Type type) { |
| 84 return type == Manifest::TYPE_EXTENSION; | 90 return type == Manifest::TYPE_EXTENSION; |
| 85 } | 91 } |
| 86 | 92 |
| 87 void ScriptBadgeHandler::SetActionInfoDefaults(const Extension* extension, | 93 void ScriptBadgeHandler::SetActionInfoDefaults(const Extension* extension, |
| 88 ActionInfo* info) { | 94 ActionInfo* info) { |
| 89 info->default_title = extension->name(); | 95 info->default_title = extension->name(); |
| 90 info->default_icon.Clear(); | 96 info->default_icon.Clear(); |
| 91 for (size_t i = 0; i < extension_misc::kNumScriptBadgeIconSizes; ++i) { | 97 for (size_t i = 0; i < extension_misc::kNumScriptBadgeIconSizes; ++i) { |
| 92 std::string path = extension->icons().Get( | 98 std::string path = IconsInfo::GetIcons(extension).Get( |
| 93 extension_misc::kScriptBadgeIconSizes[i], | 99 extension_misc::kScriptBadgeIconSizes[i], |
| 94 ExtensionIconSet::MATCH_BIGGER); | 100 ExtensionIconSet::MATCH_BIGGER); |
| 95 if (!path.empty()) { | 101 if (!path.empty()) { |
| 96 info->default_icon.Add( | 102 info->default_icon.Add( |
| 97 extension_misc::kScriptBadgeIconSizes[i], path); | 103 extension_misc::kScriptBadgeIconSizes[i], path); |
| 98 } | 104 } |
| 99 } | 105 } |
| 100 } | 106 } |
| 101 | 107 |
| 102 } // namespace extensions | 108 } // namespace extensions |
| OLD | NEW |