Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(401)

Side by Side Diff: chrome/common/extensions/extension.cc

Issue 11624036: Move the parsing of homepage_url" and "devtools_page" out of Extension. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/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"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/file_path.h" 12 #include "base/file_path.h"
13 #include "base/file_util.h" 13 #include "base/file_util.h"
14 #include "base/i18n/rtl.h" 14 #include "base/i18n/rtl.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/memory/singleton.h" 16 #include "base/memory/singleton.h"
17 #include "base/stl_util.h" 17 #include "base/stl_util.h"
18 #include "base/string16.h" 18 #include "base/string16.h"
19 #include "base/string_number_conversions.h" 19 #include "base/string_number_conversions.h"
20 #include "base/string_piece.h" 20 #include "base/string_piece.h"
21 #include "base/string_util.h" 21 #include "base/string_util.h"
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 #include "chrome/common/extensions/api/url_parser/url_info.h"
29 #include "chrome/common/extensions/csp_validator.h" 30 #include "chrome/common/extensions/csp_validator.h"
30 #include "chrome/common/extensions/extension_manifest_constants.h" 31 #include "chrome/common/extensions/extension_manifest_constants.h"
31 #include "chrome/common/extensions/extension_resource.h" 32 #include "chrome/common/extensions/extension_resource.h"
32 #include "chrome/common/extensions/feature_switch.h" 33 #include "chrome/common/extensions/feature_switch.h"
33 #include "chrome/common/extensions/features/base_feature_provider.h" 34 #include "chrome/common/extensions/features/base_feature_provider.h"
34 #include "chrome/common/extensions/features/feature.h" 35 #include "chrome/common/extensions/features/feature.h"
35 #include "chrome/common/extensions/file_browser_handler.h" 36 #include "chrome/common/extensions/file_browser_handler.h"
36 #include "chrome/common/extensions/manifest.h" 37 #include "chrome/common/extensions/manifest.h"
37 #include "chrome/common/extensions/manifest_handler.h" 38 #include "chrome/common/extensions/manifest_handler.h"
38 #include "chrome/common/extensions/permissions/permission_set.h" 39 #include "chrome/common/extensions/permissions/permission_set.h"
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 DictionaryValue* info) const { 478 DictionaryValue* info) const {
478 info->SetString(info_keys::kIdKey, id()); 479 info->SetString(info_keys::kIdKey, id());
479 info->SetString(info_keys::kNameKey, name()); 480 info->SetString(info_keys::kNameKey, name());
480 info->SetBoolean(info_keys::kEnabledKey, enabled); 481 info->SetBoolean(info_keys::kEnabledKey, enabled);
481 info->SetBoolean(info_keys::kOfflineEnabledKey, offline_enabled()); 482 info->SetBoolean(info_keys::kOfflineEnabledKey, offline_enabled());
482 info->SetString(info_keys::kVersionKey, VersionString()); 483 info->SetString(info_keys::kVersionKey, VersionString());
483 info->SetString(info_keys::kDescriptionKey, description()); 484 info->SetString(info_keys::kDescriptionKey, description());
484 info->SetString(info_keys::kOptionsUrlKey, 485 info->SetString(info_keys::kOptionsUrlKey,
485 options_url().possibly_invalid_spec()); 486 options_url().possibly_invalid_spec());
486 info->SetString(info_keys::kHomepageUrlKey, 487 info->SetString(info_keys::kHomepageUrlKey,
487 GetHomepageURL().possibly_invalid_spec()); 488 URLInfo::url(this, URLInfo::HOMEPAGE_URL).possibly_invalid_spec());
488 info->SetString(info_keys::kDetailsUrlKey, 489 info->SetString(info_keys::kDetailsUrlKey,
489 details_url().possibly_invalid_spec()); 490 details_url().possibly_invalid_spec());
490 info->SetBoolean(info_keys::kPackagedAppKey, is_platform_app()); 491 info->SetBoolean(info_keys::kPackagedAppKey, is_platform_app());
491 } 492 }
492 493
493 Extension::Type Extension::GetType() const { 494 Extension::Type Extension::GetType() const {
494 return converted_from_user_script() ? TYPE_USER_SCRIPT : manifest_->type(); 495 return converted_from_user_script() ? TYPE_USER_SCRIPT : manifest_->type();
495 } 496 }
496 497
497 // static 498 // static
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 } 943 }
943 944
944 bool Extension::ShowConfigureContextMenus() const { 945 bool Extension::ShowConfigureContextMenus() const {
945 // Don't show context menu for component extensions. We might want to show 946 // Don't show context menu for component extensions. We might want to show
946 // options for component extension button but now there is no component 947 // options for component extension button but now there is no component
947 // extension with options. All other menu items like uninstall have 948 // extension with options. All other menu items like uninstall have
948 // no sense for component extensions. 949 // no sense for component extensions.
949 return location() != Extension::COMPONENT; 950 return location() != Extension::COMPONENT;
950 } 951 }
951 952
952 GURL Extension::GetHomepageURL() const {
953 if (homepage_url_.is_valid())
954 return homepage_url_;
955
956 return UpdatesFromGallery() ?
957 GURL(extension_urls::GetWebstoreItemDetailURLPrefix() + id()) : GURL();
958 }
959
960 std::set<FilePath> Extension::GetBrowserImages() const { 953 std::set<FilePath> Extension::GetBrowserImages() const {
961 std::set<FilePath> image_paths; 954 std::set<FilePath> image_paths;
962 // TODO(viettrungluu): These |FilePath::FromWStringHack(UTF8ToWide())| 955 // TODO(viettrungluu): These |FilePath::FromWStringHack(UTF8ToWide())|
963 // indicate that we're doing something wrong. 956 // indicate that we're doing something wrong.
964 957
965 // Extension icons. 958 // Extension icons.
966 for (ExtensionIconSet::IconMap::const_iterator iter = icons().map().begin(); 959 for (ExtensionIconSet::IconMap::const_iterator iter = icons().map().begin();
967 iter != icons().map().end(); ++iter) { 960 iter != icons().map().end(); ++iter) {
968 image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(iter->second))); 961 image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(iter->second)));
969 } 962 }
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after
1580 return false; 1573 return false;
1581 1574
1582 if (!LoadThemeFeatures(error)) 1575 if (!LoadThemeFeatures(error))
1583 return false; 1576 return false;
1584 1577
1585 if (HasMultipleUISurfaces()) { 1578 if (HasMultipleUISurfaces()) {
1586 *error = ASCIIToUTF16(errors::kOneUISurfaceOnly); 1579 *error = ASCIIToUTF16(errors::kOneUISurfaceOnly);
1587 return false; 1580 return false;
1588 } 1581 }
1589 1582
1583 finished_parsing_manifest_ = true;
Yoyo Zhou 2012/12/27 17:16:17 Why is this being moved? By the way, Devlin is cha
Joe Thomas 2012/12/30 04:26:00 PermissionSet constructor below queries for "devto
Yoyo Zhou 2013/01/03 01:45:54 Once that lands, you should not need to change thi
1584
1590 runtime_data_.SetActivePermissions(new PermissionSet( 1585 runtime_data_.SetActivePermissions(new PermissionSet(
1591 this, api_permissions, host_permissions)); 1586 this, api_permissions, host_permissions));
1592 required_permission_set_ = new PermissionSet( 1587 required_permission_set_ = new PermissionSet(
1593 this, api_permissions, host_permissions); 1588 this, api_permissions, host_permissions);
1594 optional_permission_set_ = new PermissionSet( 1589 optional_permission_set_ = new PermissionSet(
1595 optional_api_permissions, optional_host_permissions, URLPatternSet()); 1590 optional_api_permissions, optional_host_permissions, URLPatternSet());
1596 1591
1597 finished_parsing_manifest_ = true;
1598
1599 return true; 1592 return true;
1600 } 1593 }
1601 1594
1602 bool Extension::LoadAppIsolation(const APIPermissionSet& api_permissions, 1595 bool Extension::LoadAppIsolation(const APIPermissionSet& api_permissions,
1603 string16* error) { 1596 string16* error) {
1604 // Platform apps always get isolated storage. 1597 // Platform apps always get isolated storage.
1605 if (is_platform_app()) { 1598 if (is_platform_app()) {
1606 is_storage_isolated_ = true; 1599 is_storage_isolated_ = true;
1607 return true; 1600 return true;
1608 } 1601 }
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
1927 extent_.ClearPatterns(); 1920 extent_.ClearPatterns();
1928 } 1921 }
1929 1922
1930 return true; 1923 return true;
1931 } 1924 }
1932 1925
1933 bool Extension::LoadSharedFeatures( 1926 bool Extension::LoadSharedFeatures(
1934 const APIPermissionSet& api_permissions, 1927 const APIPermissionSet& api_permissions,
1935 string16* error) { 1928 string16* error) {
1936 if (!LoadDescription(error) || 1929 if (!LoadDescription(error) ||
1937 !LoadHomepageURL(error) ||
1938 !LoadUpdateURL(error) || 1930 !LoadUpdateURL(error) ||
1939 !LoadIcons(error) || 1931 !LoadIcons(error) ||
1940 !LoadCommands(error) || 1932 !LoadCommands(error) ||
1941 !LoadPlugins(error) || 1933 !LoadPlugins(error) ||
1942 !LoadNaClModules(error) || 1934 !LoadNaClModules(error) ||
1943 !LoadWebAccessibleResources(error) || 1935 !LoadWebAccessibleResources(error) ||
1944 !LoadSandboxedPages(error) || 1936 !LoadSandboxedPages(error) ||
1945 !LoadRequirements(error) || 1937 !LoadRequirements(error) ||
1946 !LoadDefaultLocale(error) || 1938 !LoadDefaultLocale(error) ||
1947 !LoadOfflineEnabled(error) || 1939 !LoadOfflineEnabled(error) ||
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1986 switches::kAllowLegacyExtensionManifests)) { 1978 switches::kAllowLegacyExtensionManifests)) {
1987 *error = ErrorUtils::FormatErrorMessageUTF16( 1979 *error = ErrorUtils::FormatErrorMessageUTF16(
1988 errors::kInvalidManifestVersionOld, 1980 errors::kInvalidManifestVersionOld,
1989 base::IntToString(kModernManifestVersion)); 1981 base::IntToString(kModernManifestVersion));
1990 return false; 1982 return false;
1991 } 1983 }
1992 1984
1993 return true; 1985 return true;
1994 } 1986 }
1995 1987
1996 bool Extension::LoadHomepageURL(string16* error) {
1997 if (!manifest_->HasKey(keys::kHomepageURL))
1998 return true;
1999 std::string tmp_homepage_url;
2000 if (!manifest_->GetString(keys::kHomepageURL, &tmp_homepage_url)) {
2001 *error = ErrorUtils::FormatErrorMessageUTF16(
2002 errors::kInvalidHomepageURL, "");
2003 return false;
2004 }
2005 homepage_url_ = GURL(tmp_homepage_url);
2006 if (!homepage_url_.is_valid() ||
2007 (!homepage_url_.SchemeIs("http") &&
2008 !homepage_url_.SchemeIs("https"))) {
2009 *error = ErrorUtils::FormatErrorMessageUTF16(
2010 errors::kInvalidHomepageURL, tmp_homepage_url);
2011 return false;
2012 }
2013 return true;
2014 }
2015
2016 bool Extension::LoadUpdateURL(string16* error) { 1988 bool Extension::LoadUpdateURL(string16* error) {
2017 if (!manifest_->HasKey(keys::kUpdateURL)) 1989 if (!manifest_->HasKey(keys::kUpdateURL))
2018 return true; 1990 return true;
2019 std::string tmp_update_url; 1991 std::string tmp_update_url;
2020 if (!manifest_->GetString(keys::kUpdateURL, &tmp_update_url)) { 1992 if (!manifest_->GetString(keys::kUpdateURL, &tmp_update_url)) {
2021 *error = ErrorUtils::FormatErrorMessageUTF16( 1993 *error = ErrorUtils::FormatErrorMessageUTF16(
2022 errors::kInvalidUpdateURL, ""); 1994 errors::kInvalidUpdateURL, "");
2023 return false; 1995 return false;
2024 } 1996 }
2025 update_url_ = GURL(tmp_update_url); 1997 update_url_ = GURL(tmp_update_url);
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after
2784 return true; 2756 return true;
2785 } 2757 }
2786 2758
2787 bool Extension::LoadExtensionFeatures(APIPermissionSet* api_permissions, 2759 bool Extension::LoadExtensionFeatures(APIPermissionSet* api_permissions,
2788 string16* error) { 2760 string16* error) {
2789 if (manifest_->HasKey(keys::kConvertedFromUserScript)) 2761 if (manifest_->HasKey(keys::kConvertedFromUserScript))
2790 manifest_->GetBoolean(keys::kConvertedFromUserScript, 2762 manifest_->GetBoolean(keys::kConvertedFromUserScript,
2791 &converted_from_user_script_); 2763 &converted_from_user_script_);
2792 2764
2793 if (!LoadManifestHandlerFeatures(error) || 2765 if (!LoadManifestHandlerFeatures(error) ||
2794 !LoadDevToolsPage(error) ||
2795 !LoadInputComponents(*api_permissions, error) || 2766 !LoadInputComponents(*api_permissions, error) ||
2796 !LoadContentScripts(error) || 2767 !LoadContentScripts(error) ||
2797 !LoadPageAction(error) || 2768 !LoadPageAction(error) ||
2798 !LoadBrowserAction(error) || 2769 !LoadBrowserAction(error) ||
2799 !LoadSystemIndicator(api_permissions, error) || 2770 !LoadSystemIndicator(api_permissions, error) ||
2800 !LoadScriptBadge(error) || 2771 !LoadScriptBadge(error) ||
2801 !LoadFileBrowserHandlers(error) || 2772 !LoadFileBrowserHandlers(error) ||
2802 !LoadChromeURLOverrides(error) || 2773 !LoadChromeURLOverrides(error) ||
2803 !LoadTextToSpeechVoices(error) || 2774 !LoadTextToSpeechVoices(error) ||
2804 !LoadIncognitoMode(error) || 2775 !LoadIncognitoMode(error) ||
2805 !LoadFileHandlers(error) || 2776 !LoadFileHandlers(error) ||
2806 !LoadContentSecurityPolicy(error)) 2777 !LoadContentSecurityPolicy(error))
2807 return false; 2778 return false;
2808 2779
2809 return true; 2780 return true;
2810 } 2781 }
2811 2782
2812 bool Extension::LoadManifestHandlerFeatures(string16* error) { 2783 bool Extension::LoadManifestHandlerFeatures(string16* error) {
2813 std::vector<std::string> keys = ManifestHandler::GetKeys(); 2784 std::vector<std::string> keys = ManifestHandler::GetKeys();
2814 for (size_t i = 0; i < keys.size(); ++i) { 2785 for (size_t i = 0; i < keys.size(); ++i) {
2815 Value* value = NULL; 2786 Value* value = NULL;
2816 if (!manifest_->Get(keys[i], &value)) 2787 if (!manifest_->Get(keys[i], &value))
2817 continue; 2788 continue;
2818 if (!ManifestHandler::Get(keys[i])->Parse(value, this, error)) 2789 if (!ManifestHandler::Get(keys[i])->Parse(value, this, error))
2819 return false; 2790 return false;
2820 } 2791 }
2821 return true; 2792 return true;
2822 } 2793 }
2823 2794
2824 bool Extension::LoadDevToolsPage(string16* error) {
2825 if (!manifest_->HasKey(keys::kDevToolsPage))
2826 return true;
2827 std::string devtools_str;
2828 if (!manifest_->GetString(keys::kDevToolsPage, &devtools_str)) {
2829 *error = ASCIIToUTF16(errors::kInvalidDevToolsPage);
2830 return false;
2831 }
2832 devtools_url_ = GetResourceURL(devtools_str);
2833 return true;
2834 }
2835
2836 bool Extension::LoadInputComponents(const APIPermissionSet& api_permissions, 2795 bool Extension::LoadInputComponents(const APIPermissionSet& api_permissions,
2837 string16* error) { 2796 string16* error) {
2838 if (!manifest_->HasKey(keys::kInputComponents)) 2797 if (!manifest_->HasKey(keys::kInputComponents))
2839 return true; 2798 return true;
2840 ListValue* list_value = NULL; 2799 ListValue* list_value = NULL;
2841 if (!manifest_->GetList(keys::kInputComponents, &list_value)) { 2800 if (!manifest_->GetList(keys::kInputComponents, &list_value)) {
2842 *error = ASCIIToUTF16(errors::kInvalidInputComponents); 2801 *error = ASCIIToUTF16(errors::kInvalidInputComponents);
2843 return false; 2802 return false;
2844 } 2803 }
2845 2804
(...skipping 1378 matching lines...) Expand 10 before | Expand all | Expand 10 after
4224 4183
4225 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( 4184 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo(
4226 const Extension* extension, 4185 const Extension* extension,
4227 const PermissionSet* permissions, 4186 const PermissionSet* permissions,
4228 Reason reason) 4187 Reason reason)
4229 : reason(reason), 4188 : reason(reason),
4230 extension(extension), 4189 extension(extension),
4231 permissions(permissions) {} 4190 permissions(permissions) {}
4232 4191
4233 } // namespace extensions 4192 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698