OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/extension.h" | 5 #include "chrome/common/extensions/extension.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/i18n/rtl.h" | 12 #include "base/i18n/rtl.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
16 #include "base/string16.h" | 16 #include "base/string16.h" |
17 #include "base/string_piece.h" | 17 #include "base/string_piece.h" |
18 #include "base/string_util.h" | 18 #include "base/string_util.h" |
19 #include "base/stringprintf.h" | 19 #include "base/stringprintf.h" |
20 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
21 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
22 #include "base/values.h" | 22 #include "base/values.h" |
23 #include "base/version.h" | 23 #include "base/version.h" |
24 #include "chrome/common/chrome_constants.h" | 24 #include "chrome/common/chrome_constants.h" |
25 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
26 #include "chrome/common/chrome_version_info.h" | 26 #include "chrome/common/chrome_version_info.h" |
27 // TODO(rdevlin.cronin): Remove this once PageAction, BrowserAction, and | 27 // TODO(rdevlin.cronin): Remove this once PageAction, BrowserAction, and |
28 // SystemIndicator have been moved out of Extension. | 28 // SystemIndicator have been moved out of Extension. |
29 #include "chrome/common/extensions/api/extension_action/action_info.h" | 29 #include "chrome/common/extensions/api/extension_action/action_info.h" |
| 30 #include "chrome/common/extensions/api/extension_action/page_action_handler.h" |
30 #include "chrome/common/extensions/api/themes/theme_handler.h" | 31 #include "chrome/common/extensions/api/themes/theme_handler.h" |
31 #include "chrome/common/extensions/csp_validator.h" | 32 #include "chrome/common/extensions/csp_validator.h" |
32 #include "chrome/common/extensions/extension_manifest_constants.h" | 33 #include "chrome/common/extensions/extension_manifest_constants.h" |
33 #include "chrome/common/extensions/extension_resource.h" | 34 #include "chrome/common/extensions/extension_resource.h" |
34 #include "chrome/common/extensions/feature_switch.h" | 35 #include "chrome/common/extensions/feature_switch.h" |
35 #include "chrome/common/extensions/features/base_feature_provider.h" | 36 #include "chrome/common/extensions/features/base_feature_provider.h" |
36 #include "chrome/common/extensions/features/feature.h" | 37 #include "chrome/common/extensions/features/feature.h" |
37 #include "chrome/common/extensions/manifest.h" | 38 #include "chrome/common/extensions/manifest.h" |
38 #include "chrome/common/extensions/manifest_handler.h" | 39 #include "chrome/common/extensions/manifest_handler.h" |
39 #include "chrome/common/extensions/manifest_handler_helpers.h" | 40 #include "chrome/common/extensions/manifest_handler_helpers.h" |
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
818 DictionaryValue* theme_images = ThemeInfo::GetThemeImages(this); | 819 DictionaryValue* theme_images = ThemeInfo::GetThemeImages(this); |
819 if (theme_images) { | 820 if (theme_images) { |
820 for (DictionaryValue::Iterator it(*theme_images); !it.IsAtEnd(); | 821 for (DictionaryValue::Iterator it(*theme_images); !it.IsAtEnd(); |
821 it.Advance()) { | 822 it.Advance()) { |
822 std::string val; | 823 std::string val; |
823 if (it.value().GetAsString(&val)) | 824 if (it.value().GetAsString(&val)) |
824 image_paths.insert(base::FilePath::FromWStringHack(UTF8ToWide(val))); | 825 image_paths.insert(base::FilePath::FromWStringHack(UTF8ToWide(val))); |
825 } | 826 } |
826 } | 827 } |
827 | 828 |
828 if (page_action_info() && !page_action_info()->default_icon.empty()) { | 829 const ActionInfo* page_action_info = ActionInfo::GetPageActionInfo(this); |
| 830 if (page_action_info && !page_action_info->default_icon.empty()) { |
829 for (ExtensionIconSet::IconMap::const_iterator iter = | 831 for (ExtensionIconSet::IconMap::const_iterator iter = |
830 page_action_info()->default_icon.map().begin(); | 832 page_action_info->default_icon.map().begin(); |
831 iter != page_action_info()->default_icon.map().end(); | 833 iter != page_action_info->default_icon.map().end(); |
832 ++iter) { | 834 ++iter) { |
833 image_paths.insert( | 835 image_paths.insert( |
834 base::FilePath::FromWStringHack(UTF8ToWide(iter->second))); | 836 base::FilePath::FromWStringHack(UTF8ToWide(iter->second))); |
835 } | 837 } |
836 } | 838 } |
837 | 839 |
838 const ActionInfo* browser_action = ActionInfo::GetBrowserActionInfo(this); | 840 const ActionInfo* browser_action = ActionInfo::GetBrowserActionInfo(this); |
839 if (browser_action && !browser_action->default_icon.empty()) { | 841 if (browser_action && !browser_action->default_icon.empty()) { |
840 for (ExtensionIconSet::IconMap::const_iterator iter = | 842 for (ExtensionIconSet::IconMap::const_iterator iter = |
841 browser_action->default_icon.map().begin(); | 843 browser_action->default_icon.map().begin(); |
(...skipping 1409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2251 return true; | 2253 return true; |
2252 } | 2254 } |
2253 | 2255 |
2254 bool Extension::LoadExtensionFeatures(APIPermissionSet* api_permissions, | 2256 bool Extension::LoadExtensionFeatures(APIPermissionSet* api_permissions, |
2255 string16* error) { | 2257 string16* error) { |
2256 if (manifest_->HasKey(keys::kConvertedFromUserScript)) | 2258 if (manifest_->HasKey(keys::kConvertedFromUserScript)) |
2257 manifest_->GetBoolean(keys::kConvertedFromUserScript, | 2259 manifest_->GetBoolean(keys::kConvertedFromUserScript, |
2258 &converted_from_user_script_); | 2260 &converted_from_user_script_); |
2259 | 2261 |
2260 if (!LoadContentScripts(error) || | 2262 if (!LoadContentScripts(error) || |
2261 !LoadPageAction(error) || | |
2262 !LoadSystemIndicator(api_permissions, error) || | 2263 !LoadSystemIndicator(api_permissions, error) || |
2263 !LoadIncognitoMode(error) || | 2264 !LoadIncognitoMode(error) || |
2264 !LoadContentSecurityPolicy(error)) | 2265 !LoadContentSecurityPolicy(error)) |
2265 return false; | 2266 return false; |
2266 | 2267 |
2267 return true; | 2268 return true; |
2268 } | 2269 } |
2269 | 2270 |
2270 bool Extension::LoadContentScripts(string16* error) { | 2271 bool Extension::LoadContentScripts(string16* error) { |
2271 if (!manifest_->HasKey(keys::kContentScripts)) | 2272 if (!manifest_->HasKey(keys::kContentScripts)) |
(...skipping 18 matching lines...) Expand all Loading... |
2290 script.set_extension_id(id()); | 2291 script.set_extension_id(id()); |
2291 if (converted_from_user_script_) { | 2292 if (converted_from_user_script_) { |
2292 script.set_emulate_greasemonkey(true); | 2293 script.set_emulate_greasemonkey(true); |
2293 script.set_match_all_frames(true); // Greasemonkey matches all frames. | 2294 script.set_match_all_frames(true); // Greasemonkey matches all frames. |
2294 } | 2295 } |
2295 content_scripts_.push_back(script); | 2296 content_scripts_.push_back(script); |
2296 } | 2297 } |
2297 return true; | 2298 return true; |
2298 } | 2299 } |
2299 | 2300 |
2300 bool Extension::LoadPageAction(string16* error) { | |
2301 DictionaryValue* page_action_value = NULL; | |
2302 | |
2303 if (manifest_->HasKey(keys::kPageActions)) { | |
2304 ListValue* list_value = NULL; | |
2305 if (!manifest_->GetList(keys::kPageActions, &list_value)) { | |
2306 *error = ASCIIToUTF16(errors::kInvalidPageActionsList); | |
2307 return false; | |
2308 } | |
2309 | |
2310 size_t list_value_length = list_value->GetSize(); | |
2311 | |
2312 if (list_value_length == 0u) { | |
2313 // A list with zero items is allowed, and is equivalent to not having | |
2314 // a page_actions key in the manifest. Don't set |page_action_value|. | |
2315 } else if (list_value_length == 1u) { | |
2316 if (!list_value->GetDictionary(0, &page_action_value)) { | |
2317 *error = ASCIIToUTF16(errors::kInvalidPageAction); | |
2318 return false; | |
2319 } | |
2320 } else { // list_value_length > 1u. | |
2321 *error = ASCIIToUTF16(errors::kInvalidPageActionsListSize); | |
2322 return false; | |
2323 } | |
2324 } else if (manifest_->HasKey(keys::kPageAction)) { | |
2325 if (!manifest_->GetDictionary(keys::kPageAction, &page_action_value)) { | |
2326 *error = ASCIIToUTF16(errors::kInvalidPageAction); | |
2327 return false; | |
2328 } | |
2329 } | |
2330 | |
2331 // If page_action_value is not NULL, then there was a valid page action. | |
2332 if (page_action_value) { | |
2333 page_action_info_ = LoadExtensionActionInfoHelper( | |
2334 this, page_action_value, error); | |
2335 if (!page_action_info_.get()) | |
2336 return false; // Failed to parse page action definition. | |
2337 } | |
2338 | |
2339 return true; | |
2340 } | |
2341 | |
2342 bool Extension::LoadSystemIndicator(APIPermissionSet* api_permissions, | 2301 bool Extension::LoadSystemIndicator(APIPermissionSet* api_permissions, |
2343 string16* error) { | 2302 string16* error) { |
2344 if (!manifest_->HasKey(keys::kSystemIndicator)) { | 2303 if (!manifest_->HasKey(keys::kSystemIndicator)) { |
2345 // There was no manifest entry for the system indicator. | 2304 // There was no manifest entry for the system indicator. |
2346 return true; | 2305 return true; |
2347 } | 2306 } |
2348 | 2307 |
2349 DictionaryValue* system_indicator_value = NULL; | 2308 DictionaryValue* system_indicator_value = NULL; |
2350 if (!manifest_->GetDictionary(keys::kSystemIndicator, | 2309 if (!manifest_->GetDictionary(keys::kSystemIndicator, |
2351 &system_indicator_value)) { | 2310 &system_indicator_value)) { |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2662 | 2621 |
2663 (instance->*add_method)(glob); | 2622 (instance->*add_method)(glob); |
2664 } | 2623 } |
2665 | 2624 |
2666 return true; | 2625 return true; |
2667 } | 2626 } |
2668 | 2627 |
2669 bool Extension::HasMultipleUISurfaces() const { | 2628 bool Extension::HasMultipleUISurfaces() const { |
2670 int num_surfaces = 0; | 2629 int num_surfaces = 0; |
2671 | 2630 |
2672 if (page_action_info()) | 2631 if (ActionInfo::GetPageActionInfo(this)) |
2673 ++num_surfaces; | 2632 ++num_surfaces; |
2674 | 2633 |
2675 if (ActionInfo::GetBrowserActionInfo(this)) | 2634 if (ActionInfo::GetBrowserActionInfo(this)) |
2676 ++num_surfaces; | 2635 ++num_surfaces; |
2677 | 2636 |
2678 if (is_app()) | 2637 if (is_app()) |
2679 ++num_surfaces; | 2638 ++num_surfaces; |
2680 | 2639 |
2681 return num_surfaces > 1; | 2640 return num_surfaces > 1; |
2682 } | 2641 } |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2835 | 2794 |
2836 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 2795 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
2837 const Extension* extension, | 2796 const Extension* extension, |
2838 const PermissionSet* permissions, | 2797 const PermissionSet* permissions, |
2839 Reason reason) | 2798 Reason reason) |
2840 : reason(reason), | 2799 : reason(reason), |
2841 extension(extension), | 2800 extension(extension), |
2842 permissions(permissions) {} | 2801 permissions(permissions) {} |
2843 | 2802 |
2844 } // namespace extensions | 2803 } // namespace extensions |
OLD | NEW |