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

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: 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // A www. prefix is not informative and thus not worth the limited real estate
105 // in the permissions UI. 105 // in the permissions UI.
106 std::string RemoveWwwPrefix(const std::string& url) { 106 std::string RemoveWwwPrefix(const std::string& url) {
Devlin 2017/02/07 18:39:24 Optional nit: RemoveWwwPrefix is now only used fro
karandeepb 2017/02/07 19:22:15 Done.
107 if (base::StartsWith(url, kWwwPrefix, base::CompareCase::INSENSITIVE_ASCII)) 107 if (base::StartsWith(url, kWwwPrefix, base::CompareCase::INSENSITIVE_ASCII))
108 return url.substr(strlen(kWwwPrefix)); 108 return url.substr(strlen(kWwwPrefix));
109 return url; 109 return url;
110 } 110 }
111 111
112 std::string FormatUrlForDisplay(const GURL& url) {
113 return RemoveWwwPrefix(url.host());
Devlin 2017/02/07 18:39:24 Let's take the opportunity to make this a bit fast
karandeepb 2017/02/07 19:22:15 Done.
114 }
115
112 } // namespace 116 } // namespace
113 117
114 SettingsOverrides::SettingsOverrides() {} 118 SettingsOverrides::SettingsOverrides() {}
115 119
116 SettingsOverrides::~SettingsOverrides() {} 120 SettingsOverrides::~SettingsOverrides() {}
117 121
118 // static 122 // static
119 const SettingsOverrides* SettingsOverrides::Get( 123 const SettingsOverrides* SettingsOverrides::Get(
120 const Extension* extension) { 124 const Extension* extension) {
121 return static_cast<SettingsOverrides*>( 125 return static_cast<SettingsOverrides*>(
(...skipping 19 matching lines...) Expand all
141 info->startup_pages = ParseStartupPage(*settings, error); 145 info->startup_pages = ParseStartupPage(*settings, error);
142 if (!info->homepage && !info->search_engine && info->startup_pages.empty()) { 146 if (!info->homepage && !info->search_engine && info->startup_pages.empty()) {
143 *error = ErrorUtils::FormatErrorMessageUTF16( 147 *error = ErrorUtils::FormatErrorMessageUTF16(
144 manifest_errors::kInvalidEmptyDictionary, 148 manifest_errors::kInvalidEmptyDictionary,
145 manifest_keys::kSettingsOverride); 149 manifest_keys::kSettingsOverride);
146 return false; 150 return false;
147 } 151 }
148 152
149 if (info->search_engine) { 153 if (info->search_engine) {
150 PermissionsParser::AddAPIPermission( 154 PermissionsParser::AddAPIPermission(
151 extension, 155 extension, new SettingsOverrideAPIPermission(
152 new SettingsOverrideAPIPermission( 156 PermissionsInfo::GetInstance()->GetByID(
153 PermissionsInfo::GetInstance()->GetByID( 157 APIPermission::kSearchProvider),
154 APIPermission::kSearchProvider), 158 FormatUrlForDisplay(*CreateManifestURL(
155 RemoveWwwPrefix(CreateManifestURL(info->search_engine->search_url) 159 info->search_engine->search_url))));
156 ->GetOrigin()
157 .host())));
158 } 160 }
159 if (!info->startup_pages.empty()) { 161 if (!info->startup_pages.empty()) {
160 PermissionsParser::AddAPIPermission( 162 PermissionsParser::AddAPIPermission(
161 extension, 163 extension,
162 new SettingsOverrideAPIPermission( 164 new SettingsOverrideAPIPermission(
163 PermissionsInfo::GetInstance()->GetByID( 165 PermissionsInfo::GetInstance()->GetByID(
164 APIPermission::kStartupPages), 166 APIPermission::kStartupPages),
165 // We only support one startup page even though the type of the 167 // We only support one startup page even though the type of the
166 // manifest 168 // manifest property is a list, only the first one is used.
167 // property is a list, only the first one is used. 169 FormatUrlForDisplay(info->startup_pages[0])));
168 RemoveWwwPrefix(info->startup_pages[0].GetContent())));
169 } 170 }
170 if (info->homepage) { 171 if (info->homepage) {
171 PermissionsParser::AddAPIPermission( 172 PermissionsParser::AddAPIPermission(
172 extension, 173 extension,
173 new SettingsOverrideAPIPermission( 174 new SettingsOverrideAPIPermission(
174 PermissionsInfo::GetInstance()->GetByID(APIPermission::kHomepage), 175 PermissionsInfo::GetInstance()->GetByID(APIPermission::kHomepage),
175 RemoveWwwPrefix(info->homepage->GetContent()))); 176 FormatUrlForDisplay(*(info->homepage))));
176 } 177 }
177 extension->SetManifestData(manifest_keys::kSettingsOverride, 178 extension->SetManifestData(manifest_keys::kSettingsOverride,
178 info.release()); 179 info.release());
179 return true; 180 return true;
180 } 181 }
181 182
182 const std::vector<std::string> SettingsOverridesHandler::Keys() const { 183 const std::vector<std::string> SettingsOverridesHandler::Keys() const {
183 return SingleKey(manifest_keys::kSettingsOverride); 184 return SingleKey(manifest_keys::kSettingsOverride);
184 } 185 }
185 186
186 } // namespace extensions 187 } // 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