| 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 <ostream> | 7 #include <ostream> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "base/stringprintf.h" | 22 #include "base/stringprintf.h" |
| 23 #include "base/utf_string_conversions.h" | 23 #include "base/utf_string_conversions.h" |
| 24 #include "base/values.h" | 24 #include "base/values.h" |
| 25 #include "base/version.h" | 25 #include "base/version.h" |
| 26 #include "chrome/common/chrome_constants.h" | 26 #include "chrome/common/chrome_constants.h" |
| 27 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
| 28 #include "chrome/common/chrome_version_info.h" | 28 #include "chrome/common/chrome_version_info.h" |
| 29 // TODO(rdevlin.cronin): Remove this once PageAction, BrowserAction, and | 29 // TODO(rdevlin.cronin): Remove this once PageAction, BrowserAction, and |
| 30 // SystemIndicator have been moved out of Extension. | 30 // SystemIndicator have been moved out of Extension. |
| 31 #include "chrome/common/extensions/api/extension_action/action_info.h" | 31 #include "chrome/common/extensions/api/extension_action/action_info.h" |
| 32 #include "chrome/common/extensions/api/extension_action/page_action_handler.h" |
| 32 #include "chrome/common/extensions/csp_validator.h" | 33 #include "chrome/common/extensions/csp_validator.h" |
| 33 #include "chrome/common/extensions/extension_manifest_constants.h" | 34 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 34 #include "chrome/common/extensions/extension_resource.h" | 35 #include "chrome/common/extensions/extension_resource.h" |
| 35 #include "chrome/common/extensions/feature_switch.h" | 36 #include "chrome/common/extensions/feature_switch.h" |
| 36 #include "chrome/common/extensions/features/base_feature_provider.h" | 37 #include "chrome/common/extensions/features/base_feature_provider.h" |
| 37 #include "chrome/common/extensions/features/feature.h" | 38 #include "chrome/common/extensions/features/feature.h" |
| 38 #include "chrome/common/extensions/manifest.h" | 39 #include "chrome/common/extensions/manifest.h" |
| 39 #include "chrome/common/extensions/manifest_handler.h" | 40 #include "chrome/common/extensions/manifest_handler.h" |
| 40 #include "chrome/common/extensions/manifest_handler_helpers.h" | 41 #include "chrome/common/extensions/manifest_handler_helpers.h" |
| 41 #include "chrome/common/extensions/manifest_url_handler.h" | 42 #include "chrome/common/extensions/manifest_url_handler.h" |
| (...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 900 DictionaryValue* theme_images = GetThemeImages(); | 901 DictionaryValue* theme_images = GetThemeImages(); |
| 901 if (theme_images) { | 902 if (theme_images) { |
| 902 for (DictionaryValue::Iterator it(*theme_images); !it.IsAtEnd(); | 903 for (DictionaryValue::Iterator it(*theme_images); !it.IsAtEnd(); |
| 903 it.Advance()) { | 904 it.Advance()) { |
| 904 std::string val; | 905 std::string val; |
| 905 if (it.value().GetAsString(&val)) | 906 if (it.value().GetAsString(&val)) |
| 906 image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(val))); | 907 image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(val))); |
| 907 } | 908 } |
| 908 } | 909 } |
| 909 | 910 |
| 910 if (page_action_info() && !page_action_info()->default_icon.empty()) { | 911 const ActionInfo* page_action_info = ActionInfo::GetPageActionInfo(this); |
| 912 if (page_action_info && !page_action_info->default_icon.empty()) { |
| 911 for (ExtensionIconSet::IconMap::const_iterator iter = | 913 for (ExtensionIconSet::IconMap::const_iterator iter = |
| 912 page_action_info()->default_icon.map().begin(); | 914 page_action_info->default_icon.map().begin(); |
| 913 iter != page_action_info()->default_icon.map().end(); | 915 iter != page_action_info->default_icon.map().end(); |
| 914 ++iter) { | 916 ++iter) { |
| 915 image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(iter->second))); | 917 image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(iter->second))); |
| 916 } | 918 } |
| 917 } | 919 } |
| 918 | 920 |
| 919 if (browser_action_info() && !browser_action_info()->default_icon.empty()) { | 921 if (browser_action_info() && !browser_action_info()->default_icon.empty()) { |
| 920 for (ExtensionIconSet::IconMap::const_iterator iter = | 922 for (ExtensionIconSet::IconMap::const_iterator iter = |
| 921 browser_action_info()->default_icon.map().begin(); | 923 browser_action_info()->default_icon.map().begin(); |
| 922 iter != browser_action_info()->default_icon.map().end(); | 924 iter != browser_action_info()->default_icon.map().end(); |
| 923 ++iter) { | 925 ++iter) { |
| (...skipping 1505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2429 } | 2431 } |
| 2430 | 2432 |
| 2431 bool Extension::LoadExtensionFeatures(APIPermissionSet* api_permissions, | 2433 bool Extension::LoadExtensionFeatures(APIPermissionSet* api_permissions, |
| 2432 string16* error) { | 2434 string16* error) { |
| 2433 if (manifest_->HasKey(keys::kConvertedFromUserScript)) | 2435 if (manifest_->HasKey(keys::kConvertedFromUserScript)) |
| 2434 manifest_->GetBoolean(keys::kConvertedFromUserScript, | 2436 manifest_->GetBoolean(keys::kConvertedFromUserScript, |
| 2435 &converted_from_user_script_); | 2437 &converted_from_user_script_); |
| 2436 | 2438 |
| 2437 if (!LoadManifestHandlerFeatures(error) || | 2439 if (!LoadManifestHandlerFeatures(error) || |
| 2438 !LoadContentScripts(error) || | 2440 !LoadContentScripts(error) || |
| 2439 !LoadPageAction(error) || | |
| 2440 !LoadBrowserAction(error) || | 2441 !LoadBrowserAction(error) || |
| 2441 !LoadSystemIndicator(api_permissions, error) || | 2442 !LoadSystemIndicator(api_permissions, error) || |
| 2442 !LoadIncognitoMode(error) || | 2443 !LoadIncognitoMode(error) || |
| 2443 !LoadContentSecurityPolicy(error)) | 2444 !LoadContentSecurityPolicy(error)) |
| 2444 return false; | 2445 return false; |
| 2445 | 2446 |
| 2446 return true; | 2447 return true; |
| 2447 } | 2448 } |
| 2448 | 2449 |
| 2449 bool Extension::LoadManifestHandlerFeatures(string16* error) { | 2450 bool Extension::LoadManifestHandlerFeatures(string16* error) { |
| 2450 std::vector<std::string> keys = ManifestHandler::GetKeys(); | 2451 std::vector<std::string> keys = ManifestHandler::GetKeys(); |
| 2451 for (size_t i = 0; i < keys.size(); ++i) { | 2452 for (size_t i = 0; i < keys.size(); ++i) { |
| 2452 Value* value = NULL; | 2453 Value* value = NULL; |
| 2453 if (!manifest_->Get(keys[i], &value)) { | 2454 if (!manifest_->Get(keys[i], &value)) { |
| 2454 if (!ManifestHandler::Get(keys[i])->HasNoKey(this, error)) | 2455 if (!ManifestHandler::Get(keys[i])->HasNoKey(this, error)) |
| 2455 return false; | 2456 return false; |
| 2456 } else if (!ManifestHandler::Get(keys[i])->Parse(value, this, error)) { | 2457 } else if (!ManifestHandler::Get(keys[i])->Parse(value, this, error)) { |
| 2457 return false; | 2458 return false; |
| 2458 } | 2459 } |
| 2459 } | 2460 } |
| 2461 |
| 2462 std::vector<ManifestMultiKeyHandler::KeySet> key_sets = |
| 2463 ManifestMultiKeyHandler::GetKeySets(); |
| 2464 for (size_t i = 0; i < key_sets.size(); ++i) { |
| 2465 scoped_ptr<DictionaryValue> dict(new DictionaryValue); |
| 2466 // TODO(yoz): should be a const_iterator |
| 2467 for (ManifestMultiKeyHandler::KeySet::iterator ki = key_sets[i].begin(); |
| 2468 ki != key_sets[i].end(); ++ki) { |
| 2469 Value* value = NULL; |
| 2470 if (manifest_->Get(*ki, &value)) { |
| 2471 dict->Set(*ki, value->DeepCopy()); |
| 2472 } |
| 2473 if (!ManifestMultiKeyHandler::Get(key_sets[i])->Parse( |
| 2474 dict.get(), this, error)) |
| 2475 return false; |
| 2476 } |
| 2477 } |
| 2478 |
| 2460 return true; | 2479 return true; |
| 2461 } | 2480 } |
| 2462 | 2481 |
| 2463 bool Extension::LoadContentScripts(string16* error) { | 2482 bool Extension::LoadContentScripts(string16* error) { |
| 2464 if (!manifest_->HasKey(keys::kContentScripts)) | 2483 if (!manifest_->HasKey(keys::kContentScripts)) |
| 2465 return true; | 2484 return true; |
| 2466 ListValue* list_value; | 2485 ListValue* list_value; |
| 2467 if (!manifest_->GetList(keys::kContentScripts, &list_value)) { | 2486 if (!manifest_->GetList(keys::kContentScripts, &list_value)) { |
| 2468 *error = ASCIIToUTF16(errors::kInvalidContentScriptsList); | 2487 *error = ASCIIToUTF16(errors::kInvalidContentScriptsList); |
| 2469 return false; | 2488 return false; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2483 script.set_extension_id(id()); | 2502 script.set_extension_id(id()); |
| 2484 if (converted_from_user_script_) { | 2503 if (converted_from_user_script_) { |
| 2485 script.set_emulate_greasemonkey(true); | 2504 script.set_emulate_greasemonkey(true); |
| 2486 script.set_match_all_frames(true); // Greasemonkey matches all frames. | 2505 script.set_match_all_frames(true); // Greasemonkey matches all frames. |
| 2487 } | 2506 } |
| 2488 content_scripts_.push_back(script); | 2507 content_scripts_.push_back(script); |
| 2489 } | 2508 } |
| 2490 return true; | 2509 return true; |
| 2491 } | 2510 } |
| 2492 | 2511 |
| 2493 bool Extension::LoadPageAction(string16* error) { | |
| 2494 DictionaryValue* page_action_value = NULL; | |
| 2495 | |
| 2496 if (manifest_->HasKey(keys::kPageActions)) { | |
| 2497 ListValue* list_value = NULL; | |
| 2498 if (!manifest_->GetList(keys::kPageActions, &list_value)) { | |
| 2499 *error = ASCIIToUTF16(errors::kInvalidPageActionsList); | |
| 2500 return false; | |
| 2501 } | |
| 2502 | |
| 2503 size_t list_value_length = list_value->GetSize(); | |
| 2504 | |
| 2505 if (list_value_length == 0u) { | |
| 2506 // A list with zero items is allowed, and is equivalent to not having | |
| 2507 // a page_actions key in the manifest. Don't set |page_action_value|. | |
| 2508 } else if (list_value_length == 1u) { | |
| 2509 if (!list_value->GetDictionary(0, &page_action_value)) { | |
| 2510 *error = ASCIIToUTF16(errors::kInvalidPageAction); | |
| 2511 return false; | |
| 2512 } | |
| 2513 } else { // list_value_length > 1u. | |
| 2514 *error = ASCIIToUTF16(errors::kInvalidPageActionsListSize); | |
| 2515 return false; | |
| 2516 } | |
| 2517 } else if (manifest_->HasKey(keys::kPageAction)) { | |
| 2518 if (!manifest_->GetDictionary(keys::kPageAction, &page_action_value)) { | |
| 2519 *error = ASCIIToUTF16(errors::kInvalidPageAction); | |
| 2520 return false; | |
| 2521 } | |
| 2522 } | |
| 2523 | |
| 2524 // If page_action_value is not NULL, then there was a valid page action. | |
| 2525 if (page_action_value) { | |
| 2526 page_action_info_ = LoadExtensionActionInfoHelper( | |
| 2527 this, page_action_value, error); | |
| 2528 if (!page_action_info_.get()) | |
| 2529 return false; // Failed to parse page action definition. | |
| 2530 } | |
| 2531 | |
| 2532 return true; | |
| 2533 } | |
| 2534 | |
| 2535 bool Extension::LoadBrowserAction(string16* error) { | 2512 bool Extension::LoadBrowserAction(string16* error) { |
| 2536 if (!manifest_->HasKey(keys::kBrowserAction)) | 2513 if (!manifest_->HasKey(keys::kBrowserAction)) |
| 2537 return true; | 2514 return true; |
| 2538 DictionaryValue* browser_action_value = NULL; | 2515 DictionaryValue* browser_action_value = NULL; |
| 2539 if (!manifest_->GetDictionary(keys::kBrowserAction, &browser_action_value)) { | 2516 if (!manifest_->GetDictionary(keys::kBrowserAction, &browser_action_value)) { |
| 2540 *error = ASCIIToUTF16(errors::kInvalidBrowserAction); | 2517 *error = ASCIIToUTF16(errors::kInvalidBrowserAction); |
| 2541 return false; | 2518 return false; |
| 2542 } | 2519 } |
| 2543 | 2520 |
| 2544 browser_action_info_ = LoadExtensionActionInfoHelper( | 2521 browser_action_info_ = LoadExtensionActionInfoHelper( |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3026 } | 3003 } |
| 3027 oauth2_info_.scopes.push_back(scope); | 3004 oauth2_info_.scopes.push_back(scope); |
| 3028 } | 3005 } |
| 3029 | 3006 |
| 3030 return true; | 3007 return true; |
| 3031 } | 3008 } |
| 3032 | 3009 |
| 3033 bool Extension::HasMultipleUISurfaces() const { | 3010 bool Extension::HasMultipleUISurfaces() const { |
| 3034 int num_surfaces = 0; | 3011 int num_surfaces = 0; |
| 3035 | 3012 |
| 3036 if (page_action_info()) | 3013 if (ActionInfo::GetPageActionInfo(this)) |
| 3037 ++num_surfaces; | 3014 ++num_surfaces; |
| 3038 | 3015 |
| 3039 if (browser_action_info()) | 3016 if (browser_action_info()) |
| 3040 ++num_surfaces; | 3017 ++num_surfaces; |
| 3041 | 3018 |
| 3042 if (is_app()) | 3019 if (is_app()) |
| 3043 ++num_surfaces; | 3020 ++num_surfaces; |
| 3044 | 3021 |
| 3045 return num_surfaces > 1; | 3022 return num_surfaces > 1; |
| 3046 } | 3023 } |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3214 | 3191 |
| 3215 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 3192 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
| 3216 const Extension* extension, | 3193 const Extension* extension, |
| 3217 const PermissionSet* permissions, | 3194 const PermissionSet* permissions, |
| 3218 Reason reason) | 3195 Reason reason) |
| 3219 : reason(reason), | 3196 : reason(reason), |
| 3220 extension(extension), | 3197 extension(extension), |
| 3221 permissions(permissions) {} | 3198 permissions(permissions) {} |
| 3222 | 3199 |
| 3223 } // namespace extensions | 3200 } // namespace extensions |
| OLD | NEW |