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

Side by Side Diff: chrome/common/extensions/manifest_handlers/settings_overrides_handler.cc

Issue 2676393002: Extensions: Only display host name for the overridden home and start-up pages. (Closed)
Patch Set: Address review Created 3 years, 10 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
« no previous file with comments | « no previous file | chrome/common/extensions/permissions/settings_override_permission_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 } 94 }
95 if (!CreateManifestURL(*overrides->search_provider->favicon_url)) { 95 if (!CreateManifestURL(*overrides->search_provider->favicon_url)) {
96 *error = extensions::ErrorUtils::FormatErrorMessageUTF16( 96 *error = extensions::ErrorUtils::FormatErrorMessageUTF16(
97 manifest_errors::kInvalidSearchEngineURL, 97 manifest_errors::kInvalidSearchEngineURL,
98 *overrides->search_provider->favicon_url); 98 *overrides->search_provider->favicon_url);
99 return std::unique_ptr<ChromeSettingsOverrides::Search_provider>(); 99 return std::unique_ptr<ChromeSettingsOverrides::Search_provider>();
100 } 100 }
101 return std::move(overrides->search_provider); 101 return std::move(overrides->search_provider);
102 } 102 }
103 103
104 // A www. prefix is not informative and thus not worth the limited real estate 104 std::string FormatUrlForDisplay(const GURL& url) {
105 // in the permissions UI. 105 base::StringPiece host = url.host_piece();
106 std::string RemoveWwwPrefix(const std::string& url) { 106 // A www. prefix is not informative and thus not worth the limited real estate
107 if (base::StartsWith(url, kWwwPrefix, base::CompareCase::INSENSITIVE_ASCII)) 107 // in the permissions UI.
108 return url.substr(strlen(kWwwPrefix)); 108 base::StringPiece formatted_host =
109 return url; 109 base::StartsWith(host, kWwwPrefix, base::CompareCase::INSENSITIVE_ASCII)
110 ? host.substr(strlen(kWwwPrefix))
111 : host;
112 return formatted_host.as_string();
110 } 113 }
111 114
112 } // namespace 115 } // namespace
113 116
114 SettingsOverrides::SettingsOverrides() {} 117 SettingsOverrides::SettingsOverrides() {}
115 118
116 SettingsOverrides::~SettingsOverrides() {} 119 SettingsOverrides::~SettingsOverrides() {}
117 120
118 // static 121 // static
119 const SettingsOverrides* SettingsOverrides::Get( 122 const SettingsOverrides* SettingsOverrides::Get(
(...skipping 21 matching lines...) Expand all
141 info->startup_pages = ParseStartupPage(*settings, error); 144 info->startup_pages = ParseStartupPage(*settings, error);
142 if (!info->homepage && !info->search_engine && info->startup_pages.empty()) { 145 if (!info->homepage && !info->search_engine && info->startup_pages.empty()) {
143 *error = ErrorUtils::FormatErrorMessageUTF16( 146 *error = ErrorUtils::FormatErrorMessageUTF16(
144 manifest_errors::kInvalidEmptyDictionary, 147 manifest_errors::kInvalidEmptyDictionary,
145 manifest_keys::kSettingsOverride); 148 manifest_keys::kSettingsOverride);
146 return false; 149 return false;
147 } 150 }
148 151
149 if (info->search_engine) { 152 if (info->search_engine) {
150 PermissionsParser::AddAPIPermission( 153 PermissionsParser::AddAPIPermission(
151 extension, 154 extension, new SettingsOverrideAPIPermission(
152 new SettingsOverrideAPIPermission( 155 PermissionsInfo::GetInstance()->GetByID(
153 PermissionsInfo::GetInstance()->GetByID( 156 APIPermission::kSearchProvider),
154 APIPermission::kSearchProvider), 157 FormatUrlForDisplay(*CreateManifestURL(
155 RemoveWwwPrefix(CreateManifestURL(info->search_engine->search_url) 158 info->search_engine->search_url))));
156 ->GetOrigin()
157 .host())));
158 } 159 }
159 if (!info->startup_pages.empty()) { 160 if (!info->startup_pages.empty()) {
160 PermissionsParser::AddAPIPermission( 161 PermissionsParser::AddAPIPermission(
161 extension, 162 extension,
162 new SettingsOverrideAPIPermission( 163 new SettingsOverrideAPIPermission(
163 PermissionsInfo::GetInstance()->GetByID( 164 PermissionsInfo::GetInstance()->GetByID(
164 APIPermission::kStartupPages), 165 APIPermission::kStartupPages),
165 // We only support one startup page even though the type of the 166 // We only support one startup page even though the type of the
166 // manifest 167 // manifest property is a list, only the first one is used.
167 // property is a list, only the first one is used. 168 FormatUrlForDisplay(info->startup_pages[0])));
168 RemoveWwwPrefix(info->startup_pages[0].GetContent())));
169 } 169 }
170 if (info->homepage) { 170 if (info->homepage) {
171 PermissionsParser::AddAPIPermission( 171 PermissionsParser::AddAPIPermission(
172 extension, 172 extension,
173 new SettingsOverrideAPIPermission( 173 new SettingsOverrideAPIPermission(
174 PermissionsInfo::GetInstance()->GetByID(APIPermission::kHomepage), 174 PermissionsInfo::GetInstance()->GetByID(APIPermission::kHomepage),
175 RemoveWwwPrefix(info->homepage->GetContent()))); 175 FormatUrlForDisplay(*(info->homepage))));
176 } 176 }
177 extension->SetManifestData(manifest_keys::kSettingsOverride, 177 extension->SetManifestData(manifest_keys::kSettingsOverride,
178 info.release()); 178 info.release());
179 return true; 179 return true;
180 } 180 }
181 181
182 const std::vector<std::string> SettingsOverridesHandler::Keys() const { 182 const std::vector<std::string> SettingsOverridesHandler::Keys() const {
183 return SingleKey(manifest_keys::kSettingsOverride); 183 return SingleKey(manifest_keys::kSettingsOverride);
184 } 184 }
185 185
186 } // namespace extensions 186 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/common/extensions/permissions/settings_override_permission_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698