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

Side by Side Diff: chrome/common/extensions/api/url_overrides/url_overrides_handler.cc

Issue 11660016: Move the parsing of "chrome_url_overrides" out of Extension. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 8 years 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/api/url_overrides/url_overrides_handler.h"
6
7 #include "base/memory/scoped_ptr.h"
8 #include "base/string_util.h"
9 #include "base/stringprintf.h"
10 #include "base/utf_string_conversions.h"
11 #include "base/values.h"
12 #include "chrome/common/chrome_constants.h"
13 #include "chrome/common/extensions/extension_manifest_constants.h"
14 #include "chrome/common/url_constants.h"
15 #include "extensions/common/error_utils.h"
16
17 namespace keys = extension_manifest_keys;
18 namespace errors = extension_manifest_errors;
19
20 namespace extensions {
21
22 namespace {
23 const char kOverrideExtentUrlPatternFormat[] = "chrome://%s/*";
24 } // namespace
25
26 // static
27 const URLOverridesInfo::URLOverrideMap
28 URLOverridesInfo::GetChromeURLOverrides(const Extension* extension) {
Yoyo Zhou 2012/12/28 03:59:45 This reads somewhat redundantly. Can this Info be
Joe Thomas 2012/12/29 14:44:28 Yes we can combine, but I think that will increase
Yoyo Zhou 2013/01/03 22:36:03 As I see it, URLInfo is a general-purpose thing fo
Joe Thomas 2013/01/04 23:36:11 Ah Ok. I misunderstood your previous comment. Done
29 URLOverridesInfo* info = static_cast<URLOverridesInfo*>(
30 extension->GetManifestData(keys::kChromeURLOverrides));
31 if (info)
32 return info->chrome_url_overrides_;
33 return URLOverrideMap();
34 }
35
36
37 URLOverridesHandler::URLOverridesHandler() {
38 }
39
40 URLOverridesHandler::~URLOverridesHandler() {
41 }
42
43 bool URLOverridesHandler::Parse(const base::Value* value,
44 Extension* extension,
45 string16* error) {
46 const DictionaryValue* overrides = NULL;
47 if (!value->GetAsDictionary(&overrides)) {
48 *error = ASCIIToUTF16(errors::kInvalidChromeURLOverrides);
49 return false;
50 }
51 scoped_ptr<URLOverridesInfo> info(new URLOverridesInfo);
52 // Validate that the overrides are all strings
53 for (DictionaryValue::key_iterator iter = overrides->begin_keys();
54 iter != overrides->end_keys(); ++iter) {
55 std::string page = *iter;
56 std::string val;
57 // Restrict override pages to a list of supported URLs.
58 bool is_override = (page != chrome::kChromeUINewTabHost &&
59 page != chrome::kChromeUIBookmarksHost &&
60 page != chrome::kChromeUIHistoryHost);
61 #if defined(OS_CHROMEOS)
62 is_override = (is_override &&
63 page != chrome::kChromeUIActivationMessageHost);
64 #endif
65 #if defined(FILE_MANAGER_EXTENSION)
66 is_override = (is_override &&
67 !(extension->location() == Extension::COMPONENT &&
68 page == chrome::kChromeUIFileManagerHost));
69 #endif
70
71 if (is_override || !overrides->GetStringWithoutPathExpansion(*iter, &val)) {
72 *error = ASCIIToUTF16(errors::kInvalidChromeURLOverrides);
73 return false;
74 }
75 // Replace the entry with a fully qualified chrome-extension:// URL.
76 info->chrome_url_overrides_[page] = extension->GetResourceURL(val);
77
78 // For component extensions, add override URL to extent patterns.
79 if (extension->is_legacy_packaged_app() &&
80 extension->location() == Extension::COMPONENT) {
81 URLPattern pattern(URLPattern::SCHEME_CHROMEUI);
82 std::string url = base::StringPrintf(kOverrideExtentUrlPatternFormat,
83 page.c_str());
84 if (pattern.Parse(url) != URLPattern::PARSE_SUCCESS) {
85 *error = ErrorUtils::FormatErrorMessageUTF16(
86 errors::kInvalidURLPatternError, url);
87 return false;
88 }
89 extension->AddWebExtentPattern(pattern);
90 }
91 }
92
93 // An extension may override at most one page.
94 if (overrides->size() > 1) {
95 *error = ASCIIToUTF16(errors::kMultipleOverrides);
96 return false;
97 }
98 extension->SetManifestData(keys::kChromeURLOverrides, info.release());
99 return true;
100 }
101
102 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698