| 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/extension_action/action_handler_helpers.h
" | 10 #include "chrome/common/extensions/api/extension_action/action_handler_helpers.h
" |
| 11 #include "chrome/common/extensions/extension.h" | 11 #include "chrome/common/extensions/extension.h" |
| 12 #include "chrome/common/extensions/extension_constants.h" | 12 #include "chrome/common/extensions/extension_constants.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 | 15 |
| 16 namespace errors = extension_manifest_errors; | 16 namespace errors = extension_manifest_errors; |
| 17 | 17 |
| 18 namespace extensions { | 18 namespace extensions { |
| 19 | 19 |
| 20 ScriptBadgeInfo::ScriptBadgeInfo(ActionInfo* action_info) | |
| 21 : script_badge_info(action_info) { | |
| 22 } | |
| 23 | |
| 24 ScriptBadgeInfo::~ScriptBadgeInfo() { | |
| 25 } | |
| 26 | |
| 27 // static | |
| 28 const ActionInfo* ScriptBadgeInfo::GetScriptBadge( | |
| 29 const Extension* extension) { | |
| 30 ScriptBadgeInfo* info = static_cast<ScriptBadgeInfo*>( | |
| 31 extension->GetManifestData(extension_manifest_keys::kScriptBadge)); | |
| 32 return info ? info->script_badge_info.get() : NULL; | |
| 33 } | |
| 34 | |
| 35 ScriptBadgeHandler::ScriptBadgeHandler() { | 20 ScriptBadgeHandler::ScriptBadgeHandler() { |
| 36 } | 21 } |
| 37 | 22 |
| 38 ScriptBadgeHandler::~ScriptBadgeHandler() { | 23 ScriptBadgeHandler::~ScriptBadgeHandler() { |
| 39 } | 24 } |
| 40 | 25 |
| 41 bool ScriptBadgeHandler::Parse(const base::Value* value, | 26 bool ScriptBadgeHandler::Parse(const base::Value* value, |
| 42 Extension* extension, | 27 Extension* extension, |
| 43 string16* error) { | 28 string16* error) { |
| 44 scoped_ptr<ActionInfo> action_info(new ActionInfo); | 29 scoped_ptr<ActionInfo> action_info(new ActionInfo); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 } | 61 } |
| 77 | 62 |
| 78 if (!action_info->default_icon.empty()) { | 63 if (!action_info->default_icon.empty()) { |
| 79 extension->AddInstallWarning( | 64 extension->AddInstallWarning( |
| 80 Extension::InstallWarning(Extension::InstallWarning::FORMAT_TEXT, | 65 Extension::InstallWarning(Extension::InstallWarning::FORMAT_TEXT, |
| 81 errors::kScriptBadgeIconIgnored)); | 66 errors::kScriptBadgeIconIgnored)); |
| 82 } | 67 } |
| 83 | 68 |
| 84 SetActionInfoDefaults(extension, action_info.get()); | 69 SetActionInfoDefaults(extension, action_info.get()); |
| 85 extension->SetManifestData(extension_manifest_keys::kScriptBadge, | 70 extension->SetManifestData(extension_manifest_keys::kScriptBadge, |
| 86 new ScriptBadgeInfo(action_info.release())); | 71 new ActionInfoData(action_info.release())); |
| 87 return true; | 72 return true; |
| 88 } | 73 } |
| 89 | 74 |
| 90 bool ScriptBadgeHandler::HasNoKey(Extension* extension, string16* error) { | 75 bool ScriptBadgeHandler::HasNoKey(Extension* extension, string16* error) { |
| 91 scoped_ptr<ActionInfo> action_info(new ActionInfo); | 76 scoped_ptr<ActionInfo> action_info(new ActionInfo); |
| 92 SetActionInfoDefaults(extension, action_info.get()); | 77 SetActionInfoDefaults(extension, action_info.get()); |
| 93 extension->SetManifestData(extension_manifest_keys::kScriptBadge, | 78 extension->SetManifestData(extension_manifest_keys::kScriptBadge, |
| 94 new ScriptBadgeInfo(action_info.release())); | 79 new ActionInfoData(action_info.release())); |
| 95 return true; | 80 return true; |
| 96 } | 81 } |
| 97 | 82 |
| 98 void ScriptBadgeHandler::SetActionInfoDefaults(const Extension* extension, | 83 void ScriptBadgeHandler::SetActionInfoDefaults(const Extension* extension, |
| 99 ActionInfo* info) { | 84 ActionInfo* info) { |
| 100 info->default_title = extension->name(); | 85 info->default_title = extension->name(); |
| 101 info->default_icon.Clear(); | 86 info->default_icon.Clear(); |
| 102 for (size_t i = 0; i < extension_misc::kNumScriptBadgeIconSizes; ++i) { | 87 for (size_t i = 0; i < extension_misc::kNumScriptBadgeIconSizes; ++i) { |
| 103 std::string path = extension->icons().Get( | 88 std::string path = extension->icons().Get( |
| 104 extension_misc::kScriptBadgeIconSizes[i], | 89 extension_misc::kScriptBadgeIconSizes[i], |
| 105 ExtensionIconSet::MATCH_BIGGER); | 90 ExtensionIconSet::MATCH_BIGGER); |
| 106 if (!path.empty()) { | 91 if (!path.empty()) { |
| 107 info->default_icon.Add( | 92 info->default_icon.Add( |
| 108 extension_misc::kScriptBadgeIconSizes[i], path); | 93 extension_misc::kScriptBadgeIconSizes[i], path); |
| 109 } | 94 } |
| 110 } | 95 } |
| 111 } | 96 } |
| 112 | 97 |
| 113 } // namespace extensions | 98 } // namespace extensions |
| OLD | NEW |