OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/manifest_handlers/extension_action_handler.h" | 5 #include "chrome/common/extensions/manifest_handlers/extension_action_handler.h" |
6 | 6 |
| 7 #include <memory> |
| 8 |
7 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
8 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
9 #include "base/values.h" | 11 #include "base/values.h" |
10 #include "chrome/common/extensions/api/extension_action/action_info.h" | 12 #include "chrome/common/extensions/api/extension_action/action_info.h" |
11 #include "chrome/common/extensions/extension_constants.h" | 13 #include "chrome/common/extensions/extension_constants.h" |
12 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
13 #include "extensions/common/extension.h" | 15 #include "extensions/common/extension.h" |
14 #include "extensions/common/feature_switch.h" | 16 #include "extensions/common/feature_switch.h" |
15 #include "extensions/common/file_util.h" | 17 #include "extensions/common/file_util.h" |
16 #include "extensions/common/manifest_constants.h" | 18 #include "extensions/common/manifest_constants.h" |
(...skipping 25 matching lines...) Expand all Loading... |
42 error_key = manifest_errors::kInvalidBrowserAction; | 44 error_key = manifest_errors::kInvalidBrowserAction; |
43 } | 45 } |
44 | 46 |
45 if (key) { | 47 if (key) { |
46 const base::DictionaryValue* dict = NULL; | 48 const base::DictionaryValue* dict = NULL; |
47 if (!extension->manifest()->GetDictionary(key, &dict)) { | 49 if (!extension->manifest()->GetDictionary(key, &dict)) { |
48 *error = base::ASCIIToUTF16(error_key); | 50 *error = base::ASCIIToUTF16(error_key); |
49 return false; | 51 return false; |
50 } | 52 } |
51 | 53 |
52 scoped_ptr<ActionInfo> action_info = | 54 std::unique_ptr<ActionInfo> action_info = |
53 ActionInfo::Load(extension, dict, error); | 55 ActionInfo::Load(extension, dict, error); |
54 if (!action_info) | 56 if (!action_info) |
55 return false; // Failed to parse extension action definition. | 57 return false; // Failed to parse extension action definition. |
56 | 58 |
57 if (key == manifest_keys::kPageAction) | 59 if (key == manifest_keys::kPageAction) |
58 ActionInfo::SetPageActionInfo(extension, action_info.release()); | 60 ActionInfo::SetPageActionInfo(extension, action_info.release()); |
59 else | 61 else |
60 ActionInfo::SetBrowserActionInfo(extension, action_info.release()); | 62 ActionInfo::SetBrowserActionInfo(extension, action_info.release()); |
61 } else { // No key, used for synthesizing an action for extensions with none. | 63 } else { // No key, used for synthesizing an action for extensions with none. |
62 if (!FeatureSwitch::extension_action_redesign()->IsEnabled()) | 64 if (!FeatureSwitch::extension_action_redesign()->IsEnabled()) |
63 return true; // Do nothing if the switch is off. | 65 return true; // Do nothing if the switch is off. |
64 if (Manifest::IsComponentLocation(extension->location())) | 66 if (Manifest::IsComponentLocation(extension->location())) |
65 return true; // Don't synthesize actions for component extensions. | 67 return true; // Don't synthesize actions for component extensions. |
66 if (extension->was_installed_by_default()) | 68 if (extension->was_installed_by_default()) |
67 return true; // Don't synthesize actions for default extensions. | 69 return true; // Don't synthesize actions for default extensions. |
68 if (extension->manifest()->HasKey( | 70 if (extension->manifest()->HasKey( |
69 manifest_keys::kSynthesizeExtensionAction)) { | 71 manifest_keys::kSynthesizeExtensionAction)) { |
70 *error = base::ASCIIToUTF16(base::StringPrintf( | 72 *error = base::ASCIIToUTF16(base::StringPrintf( |
71 "Key %s is reserved.", manifest_keys::kSynthesizeExtensionAction)); | 73 "Key %s is reserved.", manifest_keys::kSynthesizeExtensionAction)); |
72 return false; // No one should use this key. | 74 return false; // No one should use this key. |
73 } | 75 } |
74 | 76 |
75 // Set an empty page action. We use a page action (instead of a browser | 77 // Set an empty page action. We use a page action (instead of a browser |
76 // action) because the action should not be seen as enabled on every page. | 78 // action) because the action should not be seen as enabled on every page. |
77 scoped_ptr<ActionInfo> action_info(new ActionInfo()); | 79 std::unique_ptr<ActionInfo> action_info(new ActionInfo()); |
78 action_info->synthesized = true; | 80 action_info->synthesized = true; |
79 ActionInfo::SetPageActionInfo(extension, action_info.release()); | 81 ActionInfo::SetPageActionInfo(extension, action_info.release()); |
80 } | 82 } |
81 | 83 |
82 return true; | 84 return true; |
83 } | 85 } |
84 | 86 |
85 bool ExtensionActionHandler::Validate( | 87 bool ExtensionActionHandler::Validate( |
86 const Extension* extension, | 88 const Extension* extension, |
87 std::string* error, | 89 std::string* error, |
(...skipping 21 matching lines...) Expand all Loading... |
109 | 111 |
110 const std::vector<std::string> ExtensionActionHandler::Keys() const { | 112 const std::vector<std::string> ExtensionActionHandler::Keys() const { |
111 std::vector<std::string> keys; | 113 std::vector<std::string> keys; |
112 keys.push_back(manifest_keys::kPageAction); | 114 keys.push_back(manifest_keys::kPageAction); |
113 keys.push_back(manifest_keys::kBrowserAction); | 115 keys.push_back(manifest_keys::kBrowserAction); |
114 keys.push_back(manifest_keys::kSynthesizeExtensionAction); | 116 keys.push_back(manifest_keys::kSynthesizeExtensionAction); |
115 return keys; | 117 return keys; |
116 } | 118 } |
117 | 119 |
118 } // namespace extensions | 120 } // namespace extensions |
OLD | NEW |