Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/manifest_handlers/settings_overrides_handler. h" | 5 #include "chrome/common/extensions/manifest_handlers/settings_overrides_handler. h" |
| 6 | 6 |
| 7 #include "base/strings/string_util.h" | |
| 7 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/common/extensions/permissions/permissions_data.h" | |
| 10 #include "chrome/common/extensions/permissions/settings_override_permission.h" | |
| 8 #include "extensions/common/error_utils.h" | 11 #include "extensions/common/error_utils.h" |
| 9 #include "extensions/common/manifest_constants.h" | 12 #include "extensions/common/manifest_constants.h" |
| 13 #include "extensions/common/permissions/api_permission_set.h" | |
| 14 #include "extensions/common/permissions/permissions_info.h" | |
| 15 #include "url/gurl.h" | |
| 10 | 16 |
| 11 using extensions::api::manifest_types::ChromeSettingsOverrides; | 17 using extensions::api::manifest_types::ChromeSettingsOverrides; |
| 12 | 18 |
| 13 namespace extensions { | 19 namespace extensions { |
| 14 namespace { | 20 namespace { |
| 15 | 21 |
| 16 scoped_ptr<GURL> CreateManifestURL(const std::string& url) { | 22 scoped_ptr<GURL> CreateManifestURL(const std::string& url) { |
| 17 scoped_ptr<GURL> manifest_url(new GURL(url)); | 23 scoped_ptr<GURL> manifest_url(new GURL(url)); |
| 18 if (!manifest_url->is_valid() || | 24 if (!manifest_url->is_valid() || |
| 19 !manifest_url->SchemeIsHTTPOrHTTPS()) | 25 !manifest_url->SchemeIsHTTPOrHTTPS()) |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 47 *error = extensions::ErrorUtils::FormatErrorMessageUTF16( | 53 *error = extensions::ErrorUtils::FormatErrorMessageUTF16( |
| 48 manifest_errors::kInvalidStartupOverrideURL, *i); | 54 manifest_errors::kInvalidStartupOverrideURL, *i); |
| 49 } else { | 55 } else { |
| 50 urls.push_back(GURL()); | 56 urls.push_back(GURL()); |
| 51 urls.back().Swap(manifest_url.get()); | 57 urls.back().Swap(manifest_url.get()); |
| 52 } | 58 } |
| 53 } | 59 } |
| 54 return urls; | 60 return urls; |
| 55 } | 61 } |
| 56 | 62 |
| 63 // When we display a full URL for a permission confirmation, we don't want to | |
| 64 // see the scheme, and also remove www. if present. | |
|
gab
2013/11/01 22:35:40
I would quote the "www." here; otherwise the '.' f
MAD
2013/11/03 02:21:20
Done.
| |
| 65 std::string GetURLDisplayText(const GURL& url) { | |
| 66 // GetContent skips the scheme. | |
| 67 std::string result(url.GetContent()); | |
|
gab
2013/11/01 22:35:40
static const char kWwwPrefix[] = "www.";
and use
MAD
2013/11/03 02:21:20
Done.
| |
| 68 if (StartsWithASCII(result, "www.", false)) | |
| 69 result = result.substr(4); | |
| 70 return result; | |
| 71 } | |
| 72 | |
| 57 } // namespace | 73 } // namespace |
| 58 | 74 |
| 59 SettingsOverrides::SettingsOverrides() {} | 75 SettingsOverrides::SettingsOverrides() {} |
| 60 | 76 |
| 61 SettingsOverrides::~SettingsOverrides() {} | 77 SettingsOverrides::~SettingsOverrides() {} |
| 62 | 78 |
| 63 const SettingsOverrides* SettingsOverrides::Get( | 79 const SettingsOverrides* SettingsOverrides::Get( |
| 64 const Extension* extension) { | 80 const Extension* extension) { |
| 65 return static_cast<SettingsOverrides*>( | 81 return static_cast<SettingsOverrides*>( |
| 66 extension->GetManifestData(manifest_keys::kSettingsOverride)); | 82 extension->GetManifestData(manifest_keys::kSettingsOverride)); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 79 return false; | 95 return false; |
| 80 | 96 |
| 81 scoped_ptr<SettingsOverrides> info(new SettingsOverrides); | 97 scoped_ptr<SettingsOverrides> info(new SettingsOverrides); |
| 82 info->homepage = ParseHomepage(*settings, error); | 98 info->homepage = ParseHomepage(*settings, error); |
| 83 info->search_engine = settings->search_provider.Pass(); | 99 info->search_engine = settings->search_provider.Pass(); |
| 84 info->startup_pages = ParseStartupPage(*settings, error); | 100 info->startup_pages = ParseStartupPage(*settings, error); |
| 85 if (!info->homepage && !info->search_engine && info->startup_pages.empty()) { | 101 if (!info->homepage && !info->search_engine && info->startup_pages.empty()) { |
| 86 *error = ASCIIToUTF16(manifest_errors::kInvalidEmptySettingsOverrides); | 102 *error = ASCIIToUTF16(manifest_errors::kInvalidEmptySettingsOverrides); |
| 87 return false; | 103 return false; |
| 88 } | 104 } |
| 105 APIPermissionSet* permission_set = | |
| 106 PermissionsData::GetInitialAPIPermissions(extension); | |
|
gab
2013/11/01 22:35:40
Feels kind of weird to use a static call to get da
gab
2013/11/01 22:35:40
This method states this is only non-NULL during ex
MAD
2013/11/03 02:21:20
Done.
MAD
2013/11/03 02:21:20
It's because it needs to go through private data..
| |
| 107 if (info->search_engine) { | |
| 108 permission_set->insert(new SettingsOverrideAPIPermission( | |
| 109 PermissionsInfo::GetInstance()->GetByID(APIPermission::kSearchSettings), | |
| 110 CreateManifestURL(info->search_engine->search_url)-> | |
|
gab
2013/11/01 22:35:40
Why doesn't this use GetURLDisplayText()?
MAD
2013/11/03 02:21:20
This was because it doesn't have the same needs, s
| |
| 111 GetOrigin().host())); | |
| 112 } | |
| 113 if (!info->startup_pages.empty()) { | |
| 114 permission_set->insert(new SettingsOverrideAPIPermission( | |
| 115 PermissionsInfo::GetInstance()->GetByID(APIPermission::kStartupPages), | |
| 116 // We only support one startup page. | |
| 117 GetURLDisplayText(info->startup_pages[0]))); | |
| 118 } | |
| 119 if (info->homepage) { | |
| 120 permission_set->insert(new SettingsOverrideAPIPermission( | |
| 121 PermissionsInfo::GetInstance()->GetByID(APIPermission::kHomePage), | |
| 122 GetURLDisplayText(*info->homepage.get()))); | |
| 123 } | |
| 89 extension->SetManifestData(manifest_keys::kSettingsOverride, | 124 extension->SetManifestData(manifest_keys::kSettingsOverride, |
| 90 info.release()); | 125 info.release()); |
| 91 return true; | 126 return true; |
| 92 } | 127 } |
| 93 | 128 |
| 94 const std::vector<std::string> SettingsOverridesHandler::Keys() const { | 129 const std::vector<std::string> SettingsOverridesHandler::Keys() const { |
| 95 return SingleKey(manifest_keys::kSettingsOverride); | 130 return SingleKey(manifest_keys::kSettingsOverride); |
| 96 } | 131 } |
| 97 | 132 |
| 98 } // namespace extensions | 133 } // namespace extensions |
| OLD | NEW |