OLD | NEW |
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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 | 73 |
74 // static | 74 // static |
75 bool ManifestURL::UpdatesFromGallery(const base::DictionaryValue* manifest) { | 75 bool ManifestURL::UpdatesFromGallery(const base::DictionaryValue* manifest) { |
76 std::string url; | 76 std::string url; |
77 if (!manifest->GetString(keys::kUpdateURL, &url)) | 77 if (!manifest->GetString(keys::kUpdateURL, &url)) |
78 return false; | 78 return false; |
79 return extension_urls::IsWebstoreUpdateUrl(GURL(url)); | 79 return extension_urls::IsWebstoreUpdateUrl(GURL(url)); |
80 } | 80 } |
81 | 81 |
82 // static | 82 // static |
83 const GURL& ManifestURL::GetOptionsPage(const Extension* extension) { | |
84 return GetManifestURL(extension, keys::kOptionsPage); | |
85 } | |
86 | |
87 // static | |
88 const GURL& ManifestURL::GetAboutPage(const Extension* extension) { | 83 const GURL& ManifestURL::GetAboutPage(const Extension* extension) { |
89 return GetManifestURL(extension, keys::kAboutPage); | 84 return GetManifestURL(extension, keys::kAboutPage); |
90 } | 85 } |
91 | 86 |
92 // static | 87 // static |
93 const GURL ManifestURL::GetDetailsURL(const Extension* extension) { | 88 const GURL ManifestURL::GetDetailsURL(const Extension* extension) { |
94 return extension->from_webstore() ? | 89 return extension->from_webstore() ? |
95 GURL(extension_urls::GetWebstoreItemDetailURLPrefix() + extension->id()) : | 90 GURL(extension_urls::GetWebstoreItemDetailURLPrefix() + extension->id()) : |
96 GURL::EmptyGURL(); | 91 GURL::EmptyGURL(); |
97 } | 92 } |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 } | 188 } |
194 | 189 |
195 extension->SetManifestData(keys::kUpdateURL, manifest_url.release()); | 190 extension->SetManifestData(keys::kUpdateURL, manifest_url.release()); |
196 return true; | 191 return true; |
197 } | 192 } |
198 | 193 |
199 const std::vector<std::string> UpdateURLHandler::Keys() const { | 194 const std::vector<std::string> UpdateURLHandler::Keys() const { |
200 return SingleKey(keys::kUpdateURL); | 195 return SingleKey(keys::kUpdateURL); |
201 } | 196 } |
202 | 197 |
203 OptionsPageHandler::OptionsPageHandler() { | |
204 } | |
205 | |
206 OptionsPageHandler::~OptionsPageHandler() { | |
207 } | |
208 | |
209 bool OptionsPageHandler::Parse(Extension* extension, base::string16* error) { | |
210 scoped_ptr<ManifestURL> manifest_url(new ManifestURL); | |
211 std::string options_str; | |
212 if (!extension->manifest()->GetString(keys::kOptionsPage, &options_str)) { | |
213 *error = base::ASCIIToUTF16(errors::kInvalidOptionsPage); | |
214 return false; | |
215 } | |
216 | |
217 if (extension->is_hosted_app()) { | |
218 // hosted apps require an absolute URL. | |
219 GURL options_url(options_str); | |
220 if (!options_url.is_valid() || | |
221 !options_url.SchemeIsHTTPOrHTTPS()) { | |
222 *error = base::ASCIIToUTF16(errors::kInvalidOptionsPageInHostedApp); | |
223 return false; | |
224 } | |
225 manifest_url->url_ = options_url; | |
226 } else { | |
227 GURL absolute(options_str); | |
228 if (absolute.is_valid()) { | |
229 *error = | |
230 base::ASCIIToUTF16(errors::kInvalidOptionsPageExpectUrlInPackage); | |
231 return false; | |
232 } | |
233 manifest_url->url_ = extension->GetResourceURL(options_str); | |
234 if (!manifest_url->url_.is_valid()) { | |
235 *error = base::ASCIIToUTF16(errors::kInvalidOptionsPage); | |
236 return false; | |
237 } | |
238 } | |
239 | |
240 extension->SetManifestData(keys::kOptionsPage, manifest_url.release()); | |
241 return true; | |
242 } | |
243 | |
244 bool OptionsPageHandler::Validate(const Extension* extension, | |
245 std::string* error, | |
246 std::vector<InstallWarning>* warnings) const { | |
247 // Validate path to the options page. Don't check the URL for hosted apps, | |
248 // because they are expected to refer to an external URL. | |
249 if (!extensions::ManifestURL::GetOptionsPage(extension).is_empty() && | |
250 !extension->is_hosted_app()) { | |
251 const base::FilePath options_path = | |
252 extensions::file_util::ExtensionURLToRelativeFilePath( | |
253 extensions::ManifestURL::GetOptionsPage(extension)); | |
254 const base::FilePath path = | |
255 extension->GetResource(options_path).GetFilePath(); | |
256 if (path.empty() || !base::PathExists(path)) { | |
257 *error = | |
258 l10n_util::GetStringFUTF8( | |
259 IDS_EXTENSION_LOAD_OPTIONS_PAGE_FAILED, | |
260 options_path.LossyDisplayName()); | |
261 return false; | |
262 } | |
263 } | |
264 return true; | |
265 } | |
266 | |
267 const std::vector<std::string> OptionsPageHandler::Keys() const { | |
268 return SingleKey(keys::kOptionsPage); | |
269 } | |
270 | |
271 AboutPageHandler::AboutPageHandler() { | 198 AboutPageHandler::AboutPageHandler() { |
272 } | 199 } |
273 | 200 |
274 AboutPageHandler::~AboutPageHandler() { | 201 AboutPageHandler::~AboutPageHandler() { |
275 } | 202 } |
276 | 203 |
277 bool AboutPageHandler::Parse(Extension* extension, base::string16* error) { | 204 bool AboutPageHandler::Parse(Extension* extension, base::string16* error) { |
278 scoped_ptr<ManifestURL> manifest_url(new ManifestURL); | 205 scoped_ptr<ManifestURL> manifest_url(new ManifestURL); |
279 std::string about_str; | 206 std::string about_str; |
280 if (!extension->manifest()->GetString(keys::kAboutPage, &about_str)) { | 207 if (!extension->manifest()->GetString(keys::kAboutPage, &about_str)) { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 extension->SetManifestData(keys::kChromeURLOverrides, | 307 extension->SetManifestData(keys::kChromeURLOverrides, |
381 url_overrides.release()); | 308 url_overrides.release()); |
382 return true; | 309 return true; |
383 } | 310 } |
384 | 311 |
385 const std::vector<std::string> URLOverridesHandler::Keys() const { | 312 const std::vector<std::string> URLOverridesHandler::Keys() const { |
386 return SingleKey(keys::kChromeURLOverrides); | 313 return SingleKey(keys::kChromeURLOverrides); |
387 } | 314 } |
388 | 315 |
389 } // namespace extensions | 316 } // namespace extensions |
OLD | NEW |