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

Side by Side Diff: chrome/common/extensions/manifest_url_handler.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: Review comments incorporated Created 7 years, 11 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/common/extensions/manifest_url_handler.h"
6
7 #include "base/memory/scoped_ptr.h"
8 #include "base/utf_string_conversions.h"
9 #include "base/values.h"
10 #include "chrome/common/extensions/extension_manifest_constants.h"
11 #include "extensions/common/error_utils.h"
12
13 namespace keys = extension_manifest_keys;
14 namespace errors = extension_manifest_errors;
15
16 namespace extensions {
17
18 // static
19 const GURL& ManifestURL::GetDevToolsPage(const Extension* extension) {
20 ManifestURL* info = static_cast<ManifestURL*>(
21 extension->GetManifestData(keys::kDevToolsPage));
22 return info ? info->url_ : GURL::EmptyGURL();
23 }
24
25 // static
26 const GURL ManifestURL::GetHomepageURL(const Extension* extension) {
27 ManifestURL* info = static_cast<ManifestURL*>(
28 extension->GetManifestData(keys::kHomepageURL));
29
30 if (info && info->url_.is_valid())
31 return info->url_;
32 return extension->UpdatesFromGallery() ?
33 GURL(extension_urls::GetWebstoreItemDetailURLPrefix() + extension->id()) :
34 GURL::EmptyGURL();
35 }
36
37 DevToolsPageHandler::DevToolsPageHandler() {
38 }
39
40 DevToolsPageHandler::~DevToolsPageHandler() {
41 }
42
43 bool DevToolsPageHandler::Parse(const base::Value* value,
44 Extension* extension,
45 string16* error) {
46 scoped_ptr<ManifestURL> info(new ManifestURL);
47 std::string devtools_str;
48 if (!value->GetAsString(&devtools_str)) {
49 *error = ASCIIToUTF16(errors::kInvalidDevToolsPage);
50 return false;
51 }
52 info->url_ = extension->GetResourceURL(devtools_str);
53 extension->SetManifestData(keys::kDevToolsPage, info.release());
54 return true;
55 }
56
57 HomepageURLHandler::HomepageURLHandler() {
58 }
59
60 HomepageURLHandler::~HomepageURLHandler() {
61 }
62
63 bool HomepageURLHandler::Parse(const base::Value* value,
64 Extension* extension,
65 string16* error) {
66 scoped_ptr<ManifestURL> info(new ManifestURL);
67 std::string homepage_url_str;
68 if (!value->GetAsString(&homepage_url_str)) {
69 *error = ErrorUtils::FormatErrorMessageUTF16(
70 errors::kInvalidHomepageURL, "");
71 return false;
72 }
73 info->url_ = GURL(homepage_url_str);
74 if (!info->url_.is_valid() ||
75 (!info->url_.SchemeIs("http") &&
76 !info->url_.SchemeIs("https"))) {
77 *error = ErrorUtils::FormatErrorMessageUTF16(
78 errors::kInvalidHomepageURL, homepage_url_str);
79 return false;
80 }
81 extension->SetManifestData(keys::kHomepageURL, info.release());
82 return true;
83 }
84
85 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698