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/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_manifest_constants.h" | 12 #include "chrome/common/extensions/extension_manifest_constants.h" |
13 #include "chrome/common/extensions/feature_switch.h" | 13 #include "chrome/common/extensions/feature_switch.h" |
14 #include "chrome/common/extensions/manifest_handler_helpers.h" | 14 #include "chrome/common/extensions/manifest_handler_helpers.h" |
| 15 #include "extensions/common/install_warning.h" |
15 | 16 |
16 namespace errors = extension_manifest_errors; | 17 namespace errors = extension_manifest_errors; |
17 | 18 |
18 namespace extensions { | 19 namespace extensions { |
19 | 20 |
20 ScriptBadgeHandler::ScriptBadgeHandler() { | 21 ScriptBadgeHandler::ScriptBadgeHandler() { |
21 } | 22 } |
22 | 23 |
23 ScriptBadgeHandler::~ScriptBadgeHandler() { | 24 ScriptBadgeHandler::~ScriptBadgeHandler() { |
24 } | 25 } |
25 | 26 |
26 bool ScriptBadgeHandler::Parse(const base::Value* value, | 27 bool ScriptBadgeHandler::Parse(const base::Value* value, |
27 Extension* extension, | 28 Extension* extension, |
28 string16* error) { | 29 string16* error) { |
29 scoped_ptr<ActionInfo> action_info(new ActionInfo); | 30 scoped_ptr<ActionInfo> action_info(new ActionInfo); |
30 | 31 |
31 // So as to not confuse developers if they specify a script badge section | 32 // So as to not confuse developers if they specify a script badge section |
32 // in the manifest, show a warning if the script badge declaration isn't | 33 // in the manifest, show a warning if the script badge declaration isn't |
33 // going to have any effect. | 34 // going to have any effect. |
34 if (!FeatureSwitch::script_badges()->IsEnabled()) { | 35 if (!FeatureSwitch::script_badges()->IsEnabled()) { |
35 extension->AddInstallWarning( | 36 extension->AddInstallWarning( |
36 Extension::InstallWarning(Extension::InstallWarning::FORMAT_TEXT, | 37 InstallWarning(InstallWarning::FORMAT_TEXT, |
37 errors::kScriptBadgeRequiresFlag)); | 38 errors::kScriptBadgeRequiresFlag)); |
38 } | 39 } |
39 | 40 |
40 const DictionaryValue* dict = NULL; | 41 const DictionaryValue* dict = NULL; |
41 if (!value->GetAsDictionary(&dict)) { | 42 if (!value->GetAsDictionary(&dict)) { |
42 *error = ASCIIToUTF16(extension_manifest_errors::kInvalidScriptBadge); | 43 *error = ASCIIToUTF16(extension_manifest_errors::kInvalidScriptBadge); |
43 return false; | 44 return false; |
44 } | 45 } |
45 | 46 |
46 action_info = | 47 action_info = |
47 manifest_handler_helpers::LoadActionInfo(extension, dict, error); | 48 manifest_handler_helpers::LoadActionInfo(extension, dict, error); |
48 | 49 |
49 if (!action_info.get()) | 50 if (!action_info.get()) |
50 return false; // Failed to parse script badge definition. | 51 return false; // Failed to parse script badge definition. |
51 | 52 |
52 // Script badges always use their extension's title and icon so users can rely | 53 // Script badges always use their extension's title and icon so users can rely |
53 // on the visual appearance to know which extension is running. This isn't | 54 // on the visual appearance to know which extension is running. This isn't |
54 // bulletproof since an malicious extension could use a different 16x16 icon | 55 // bulletproof since an malicious extension could use a different 16x16 icon |
55 // that matches the icon of a trusted extension, and users wouldn't be warned | 56 // that matches the icon of a trusted extension, and users wouldn't be warned |
56 // during installation. | 57 // during installation. |
57 | 58 |
58 if (!action_info->default_title.empty()) { | 59 if (!action_info->default_title.empty()) { |
59 extension->AddInstallWarning( | 60 extension->AddInstallWarning( |
60 Extension::InstallWarning(Extension::InstallWarning::FORMAT_TEXT, | 61 InstallWarning(InstallWarning::FORMAT_TEXT, |
61 errors::kScriptBadgeTitleIgnored)); | 62 errors::kScriptBadgeTitleIgnored)); |
62 } | 63 } |
63 | 64 |
64 if (!action_info->default_icon.empty()) { | 65 if (!action_info->default_icon.empty()) { |
65 extension->AddInstallWarning( | 66 extension->AddInstallWarning( |
66 Extension::InstallWarning(Extension::InstallWarning::FORMAT_TEXT, | 67 InstallWarning(InstallWarning::FORMAT_TEXT, |
67 errors::kScriptBadgeIconIgnored)); | 68 errors::kScriptBadgeIconIgnored)); |
68 } | 69 } |
69 | 70 |
70 SetActionInfoDefaults(extension, action_info.get()); | 71 SetActionInfoDefaults(extension, action_info.get()); |
71 ActionInfo::SetScriptBadgeInfo(extension, action_info.release()); | 72 ActionInfo::SetScriptBadgeInfo(extension, action_info.release()); |
72 return true; | 73 return true; |
73 } | 74 } |
74 | 75 |
75 bool ScriptBadgeHandler::HasNoKey(Extension* extension, string16* error) { | 76 bool ScriptBadgeHandler::HasNoKey(Extension* extension, string16* error) { |
76 scoped_ptr<ActionInfo> action_info(new ActionInfo); | 77 scoped_ptr<ActionInfo> action_info(new ActionInfo); |
77 SetActionInfoDefaults(extension, action_info.get()); | 78 SetActionInfoDefaults(extension, action_info.get()); |
(...skipping 10 matching lines...) Expand all Loading... |
88 extension_misc::kScriptBadgeIconSizes[i], | 89 extension_misc::kScriptBadgeIconSizes[i], |
89 ExtensionIconSet::MATCH_BIGGER); | 90 ExtensionIconSet::MATCH_BIGGER); |
90 if (!path.empty()) { | 91 if (!path.empty()) { |
91 info->default_icon.Add( | 92 info->default_icon.Add( |
92 extension_misc::kScriptBadgeIconSizes[i], path); | 93 extension_misc::kScriptBadgeIconSizes[i], path); |
93 } | 94 } |
94 } | 95 } |
95 } | 96 } |
96 | 97 |
97 } // namespace extensions | 98 } // namespace extensions |
OLD | NEW |