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

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

Issue 518653002: Add the "options_ui" extension manifest field. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build issue? Created 6 years, 3 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/manifest_url_handler.h" 5 #include "chrome/common/extensions/manifest_url_handler.h"
6 6
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 82
83 // static 83 // static
84 bool ManifestURL::UpdatesFromGallery(const base::DictionaryValue* manifest) { 84 bool ManifestURL::UpdatesFromGallery(const base::DictionaryValue* manifest) {
85 std::string url; 85 std::string url;
86 if (!manifest->GetString(keys::kUpdateURL, &url)) 86 if (!manifest->GetString(keys::kUpdateURL, &url))
87 return false; 87 return false;
88 return extension_urls::IsWebstoreUpdateUrl(GURL(url)); 88 return extension_urls::IsWebstoreUpdateUrl(GURL(url));
89 } 89 }
90 90
91 // static 91 // static
92 const GURL& ManifestURL::GetOptionsPage(const Extension* extension) {
93 return GetManifestURL(extension, keys::kOptionsPage);
94 }
95
96 // static
97 const GURL& ManifestURL::GetAboutPage(const Extension* extension) { 92 const GURL& ManifestURL::GetAboutPage(const Extension* extension) {
98 return GetManifestURL(extension, keys::kAboutPage); 93 return GetManifestURL(extension, keys::kAboutPage);
99 } 94 }
100 95
101 // static 96 // static
102 const GURL ManifestURL::GetDetailsURL(const Extension* extension) { 97 const GURL ManifestURL::GetDetailsURL(const Extension* extension) {
103 return extension->from_webstore() ? 98 return extension->from_webstore() ?
104 GURL(extension_urls::GetWebstoreItemDetailURLPrefix() + extension->id()) : 99 GURL(extension_urls::GetWebstoreItemDetailURLPrefix() + extension->id()) :
105 GURL::EmptyGURL(); 100 GURL::EmptyGURL();
106 } 101 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 } 197 }
203 198
204 extension->SetManifestData(keys::kUpdateURL, manifest_url.release()); 199 extension->SetManifestData(keys::kUpdateURL, manifest_url.release());
205 return true; 200 return true;
206 } 201 }
207 202
208 const std::vector<std::string> UpdateURLHandler::Keys() const { 203 const std::vector<std::string> UpdateURLHandler::Keys() const {
209 return SingleKey(keys::kUpdateURL); 204 return SingleKey(keys::kUpdateURL);
210 } 205 }
211 206
212 OptionsPageHandler::OptionsPageHandler() {
213 }
214
215 OptionsPageHandler::~OptionsPageHandler() {
216 }
217
218 bool OptionsPageHandler::Parse(Extension* extension, base::string16* error) {
219 scoped_ptr<ManifestURL> manifest_url(new ManifestURL);
220 std::string options_str;
221 if (!extension->manifest()->GetString(keys::kOptionsPage, &options_str)) {
222 *error = base::ASCIIToUTF16(errors::kInvalidOptionsPage);
223 return false;
224 }
225
226 if (extension->is_hosted_app()) {
227 // hosted apps require an absolute URL.
228 GURL options_url(options_str);
229 if (!options_url.is_valid() ||
230 !options_url.SchemeIsHTTPOrHTTPS()) {
231 *error = base::ASCIIToUTF16(errors::kInvalidOptionsPageInHostedApp);
232 return false;
233 }
234 manifest_url->url_ = options_url;
235 } else {
236 GURL absolute(options_str);
237 if (absolute.is_valid()) {
238 *error =
239 base::ASCIIToUTF16(errors::kInvalidOptionsPageExpectUrlInPackage);
240 return false;
241 }
242 manifest_url->url_ = extension->GetResourceURL(options_str);
243 if (!manifest_url->url_.is_valid()) {
244 *error = base::ASCIIToUTF16(errors::kInvalidOptionsPage);
245 return false;
246 }
247 }
248
249 extension->SetManifestData(keys::kOptionsPage, manifest_url.release());
250 return true;
251 }
252
253 bool OptionsPageHandler::Validate(const Extension* extension,
254 std::string* error,
255 std::vector<InstallWarning>* warnings) const {
256 // Validate path to the options page. Don't check the URL for hosted apps,
257 // because they are expected to refer to an external URL.
258 if (!extensions::ManifestURL::GetOptionsPage(extension).is_empty() &&
259 !extension->is_hosted_app()) {
260 const base::FilePath options_path =
261 extensions::file_util::ExtensionURLToRelativeFilePath(
262 extensions::ManifestURL::GetOptionsPage(extension));
263 const base::FilePath path =
264 extension->GetResource(options_path).GetFilePath();
265 if (path.empty() || !base::PathExists(path)) {
266 *error =
267 l10n_util::GetStringFUTF8(
268 IDS_EXTENSION_LOAD_OPTIONS_PAGE_FAILED,
269 options_path.LossyDisplayName());
270 return false;
271 }
272 }
273 return true;
274 }
275
276 const std::vector<std::string> OptionsPageHandler::Keys() const {
277 return SingleKey(keys::kOptionsPage);
278 }
279
280 AboutPageHandler::AboutPageHandler() { 207 AboutPageHandler::AboutPageHandler() {
281 } 208 }
282 209
283 AboutPageHandler::~AboutPageHandler() { 210 AboutPageHandler::~AboutPageHandler() {
284 } 211 }
285 212
286 bool AboutPageHandler::Parse(Extension* extension, base::string16* error) { 213 bool AboutPageHandler::Parse(Extension* extension, base::string16* error) {
287 scoped_ptr<ManifestURL> manifest_url(new ManifestURL); 214 scoped_ptr<ManifestURL> manifest_url(new ManifestURL);
288 std::string about_str; 215 std::string about_str;
289 if (!extension->manifest()->GetString(keys::kAboutPage, &about_str)) { 216 if (!extension->manifest()->GetString(keys::kAboutPage, &about_str)) {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 extension->SetManifestData(keys::kChromeURLOverrides, 316 extension->SetManifestData(keys::kChromeURLOverrides,
390 url_overrides.release()); 317 url_overrides.release());
391 return true; 318 return true;
392 } 319 }
393 320
394 const std::vector<std::string> URLOverridesHandler::Keys() const { 321 const std::vector<std::string> URLOverridesHandler::Keys() const {
395 return SingleKey(keys::kChromeURLOverrides); 322 return SingleKey(keys::kChromeURLOverrides);
396 } 323 }
397 324
398 } // namespace extensions 325 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698