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

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

Issue 11726002: Move the parsing of 'update_url' & 'options_page' URLs out of Extension. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@url_parse
Patch Set: fixed HomepageURLManifestTest.GetHomepageURL 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
« no previous file with comments | « chrome/common/extensions/manifest_url_handler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
(...skipping 30 matching lines...) Expand all
41 // static 41 // static
42 const GURL ManifestURL::GetHomepageURL(const Extension* extension) { 42 const GURL ManifestURL::GetHomepageURL(const Extension* extension) {
43 const GURL& homepage_url = GetManifestURL(extension, keys::kHomepageURL); 43 const GURL& homepage_url = GetManifestURL(extension, keys::kHomepageURL);
44 if (homepage_url.is_valid()) 44 if (homepage_url.is_valid())
45 return homepage_url; 45 return homepage_url;
46 return extension->UpdatesFromGallery() ? 46 return extension->UpdatesFromGallery() ?
47 GURL(extension_urls::GetWebstoreItemDetailURLPrefix() + extension->id()) : 47 GURL(extension_urls::GetWebstoreItemDetailURLPrefix() + extension->id()) :
48 GURL::EmptyGURL(); 48 GURL::EmptyGURL();
49 } 49 }
50 50
51 // static
52 const GURL& ManifestURL::GetUpdateURL(const Extension* extension) {
53 return GetManifestURL(extension, keys::kUpdateURL);
54 }
55
56 // static
57 const GURL& ManifestURL::GetOptionsPage(const Extension* extension) {
58 return GetManifestURL(extension, keys::kOptionsPage);
59 }
60
51 URLOverrides::URLOverrides() { 61 URLOverrides::URLOverrides() {
52 } 62 }
53 63
54 URLOverrides::~URLOverrides() { 64 URLOverrides::~URLOverrides() {
55 } 65 }
56 66
57 static base::LazyInstance<URLOverrides::URLOverrideMap> g_empty_url_overrides = 67 static base::LazyInstance<URLOverrides::URLOverrideMap> g_empty_url_overrides =
58 LAZY_INSTANCE_INITIALIZER; 68 LAZY_INSTANCE_INITIALIZER;
59 69
60 // static 70 // static
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 (!manifest_url->url_.SchemeIs("http") && 118 (!manifest_url->url_.SchemeIs("http") &&
109 !manifest_url->url_.SchemeIs("https"))) { 119 !manifest_url->url_.SchemeIs("https"))) {
110 *error = ErrorUtils::FormatErrorMessageUTF16( 120 *error = ErrorUtils::FormatErrorMessageUTF16(
111 errors::kInvalidHomepageURL, homepage_url_str); 121 errors::kInvalidHomepageURL, homepage_url_str);
112 return false; 122 return false;
113 } 123 }
114 extension->SetManifestData(keys::kHomepageURL, manifest_url.release()); 124 extension->SetManifestData(keys::kHomepageURL, manifest_url.release());
115 return true; 125 return true;
116 } 126 }
117 127
128 UpdateURLHandler::UpdateURLHandler() {
129 }
130
131 UpdateURLHandler::~UpdateURLHandler() {
132 }
133
134 bool UpdateURLHandler::Parse(const base::Value* value,
135 Extension* extension,
136 string16* error) {
137 scoped_ptr<ManifestURL> manifest_url(new ManifestURL);
138 std::string tmp_update_url;
139
140 if (!value->GetAsString(&tmp_update_url)) {
141 *error = ErrorUtils::FormatErrorMessageUTF16(
142 errors::kInvalidUpdateURL, "");
143 return false;
144 }
145
146 manifest_url->url_ = GURL(tmp_update_url);
147 if (!manifest_url->url_.is_valid() ||
148 manifest_url->url_.has_ref()) {
149 *error = ErrorUtils::FormatErrorMessageUTF16(
150 errors::kInvalidUpdateURL, tmp_update_url);
151 return false;
152 }
153
154 extension->SetManifestData(keys::kUpdateURL, manifest_url.release());
155 return true;
156 }
157
158 OptionsPageHandler::OptionsPageHandler() {
159 }
160
161 OptionsPageHandler::~OptionsPageHandler() {
162 }
163
164 bool OptionsPageHandler::Parse(const base::Value* value,
165 Extension* extension,
166 string16* error) {
167 scoped_ptr<ManifestURL> manifest_url(new ManifestURL);
168 std::string options_str;
169 if (!value->GetAsString(&options_str)) {
170 *error = ASCIIToUTF16(errors::kInvalidOptionsPage);
171 return false;
172 }
173
174 if (extension->is_hosted_app()) {
175 // hosted apps require an absolute URL.
176 GURL options_url(options_str);
177 if (!options_url.is_valid() ||
178 !(options_url.SchemeIs("http") || options_url.SchemeIs("https"))) {
179 *error = ASCIIToUTF16(errors::kInvalidOptionsPageInHostedApp);
180 return false;
181 }
182 manifest_url->url_ = options_url;
183 } else {
184 GURL absolute(options_str);
185 if (absolute.is_valid()) {
186 *error = ASCIIToUTF16(errors::kInvalidOptionsPageExpectUrlInPackage);
187 return false;
188 }
189 manifest_url->url_ = extension->GetResourceURL(options_str);
190 if (!manifest_url->url_.is_valid()) {
191 *error = ASCIIToUTF16(errors::kInvalidOptionsPage);
192 return false;
193 }
194 }
195
196 extension->SetManifestData(keys::kOptionsPage, manifest_url.release());
197 return true;
198 }
199
118 URLOverridesHandler::URLOverridesHandler() { 200 URLOverridesHandler::URLOverridesHandler() {
119 } 201 }
120 202
121 URLOverridesHandler::~URLOverridesHandler() { 203 URLOverridesHandler::~URLOverridesHandler() {
122 } 204 }
123 205
124 bool URLOverridesHandler::Parse(const base::Value* value, 206 bool URLOverridesHandler::Parse(const base::Value* value,
125 Extension* extension, 207 Extension* extension,
126 string16* error) { 208 string16* error) {
127 const DictionaryValue* overrides = NULL; 209 const DictionaryValue* overrides = NULL;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 if (overrides->size() > 1) { 257 if (overrides->size() > 1) {
176 *error = ASCIIToUTF16(errors::kMultipleOverrides); 258 *error = ASCIIToUTF16(errors::kMultipleOverrides);
177 return false; 259 return false;
178 } 260 }
179 extension->SetManifestData(keys::kChromeURLOverrides, 261 extension->SetManifestData(keys::kChromeURLOverrides,
180 url_overrides.release()); 262 url_overrides.release());
181 return true; 263 return true;
182 } 264 }
183 265
184 } // namespace extensions 266 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/common/extensions/manifest_url_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698