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

Side by Side Diff: chrome/browser/extensions/extension.cc

Issue 31008: Coalesce more hardcoded schemes to using predefined constants. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/extensions/extension.h ('k') | chrome/browser/extensions/extension_protocols.cc » ('j') | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/browser/extensions/extension.h" 5 #include "chrome/browser/extensions/extension.h"
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "net/base/net_util.h" 10 #include "net/base/net_util.h"
11 #include "chrome/common/extensions/user_script.h" 11 #include "chrome/common/extensions/user_script.h"
12 12 #include "chrome/common/url_constants.h"
13 const char kExtensionURLScheme[] = "chrome-extension";
14 const char kUserScriptURLScheme[] = "chrome-user-script";
15 13
16 const char Extension::kManifestFilename[] = "manifest.json"; 14 const char Extension::kManifestFilename[] = "manifest.json";
17 15
18 const wchar_t* Extension::kContentScriptsKey = L"content_scripts"; 16 const wchar_t* Extension::kContentScriptsKey = L"content_scripts";
19 const wchar_t* Extension::kDescriptionKey = L"description"; 17 const wchar_t* Extension::kDescriptionKey = L"description";
20 const wchar_t* Extension::kFormatVersionKey = L"format_version"; 18 const wchar_t* Extension::kFormatVersionKey = L"format_version";
21 const wchar_t* Extension::kIdKey = L"id"; 19 const wchar_t* Extension::kIdKey = L"id";
22 const wchar_t* Extension::kJsKey = L"js"; 20 const wchar_t* Extension::kJsKey = L"js";
23 const wchar_t* Extension::kMatchesKey = L"matches"; 21 const wchar_t* Extension::kMatchesKey = L"matches";
24 const wchar_t* Extension::kNameKey = L"name"; 22 const wchar_t* Extension::kNameKey = L"name";
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 "Required value 'version' is missing or invalid."; 66 "Required value 'version' is missing or invalid.";
69 const char* Extension::kInvalidZipHashError = 67 const char* Extension::kInvalidZipHashError =
70 "Required key 'zip_hash' is missing or invalid."; 68 "Required key 'zip_hash' is missing or invalid.";
71 const char* Extension::kInvalidPluginsDirError = 69 const char* Extension::kInvalidPluginsDirError =
72 "Invalid value for 'plugins_dir'."; 70 "Invalid value for 'plugins_dir'.";
73 71
74 const std::string Extension::VersionString() const { 72 const std::string Extension::VersionString() const {
75 return version_->GetString(); 73 return version_->GetString();
76 } 74 }
77 75
78 // Defined in extension_protocols.h.
79 extern const char kExtensionURLScheme[];
80
81 // static 76 // static
82 GURL Extension::GetResourceURL(const GURL& extension_url, 77 GURL Extension::GetResourceURL(const GURL& extension_url,
83 const std::string& relative_path) { 78 const std::string& relative_path) {
84 DCHECK(extension_url.SchemeIs(kExtensionURLScheme)); 79 DCHECK(extension_url.SchemeIs(chrome::kExtensionScheme));
85 DCHECK(extension_url.path() == "/"); 80 DCHECK(extension_url.path() == "/");
86 81
87 GURL ret_val = GURL(extension_url.spec() + relative_path); 82 GURL ret_val = GURL(extension_url.spec() + relative_path);
88 DCHECK(StartsWithASCII(ret_val.spec(), extension_url.spec(), false)); 83 DCHECK(StartsWithASCII(ret_val.spec(), extension_url.spec(), false));
89 84
90 return ret_val; 85 return ret_val;
91 } 86 }
92 87
93 // static 88 // static
94 FilePath Extension::GetResourcePath(const FilePath& extension_path, 89 FilePath Extension::GetResourcePath(const FilePath& extension_path,
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 FilePath id_path; 183 FilePath id_path;
189 id_path = id_path.AppendASCII(id_); 184 id_path = id_path.AppendASCII(id_);
190 if ((id_path.value() == FilePath::kCurrentDirectory) || 185 if ((id_path.value() == FilePath::kCurrentDirectory) ||
191 (id_path.value() == FilePath::kParentDirectory) || 186 (id_path.value() == FilePath::kParentDirectory) ||
192 !(id_path.BaseName() == id_path)) { 187 !(id_path.BaseName() == id_path)) {
193 *error = kInvalidIdError; 188 *error = kInvalidIdError;
194 return false; 189 return false;
195 } 190 }
196 191
197 // Initialize URL. 192 // Initialize URL.
198 extension_url_ = GURL(std::string(kExtensionURLScheme) + "://" + id_ + "/"); 193 extension_url_ = GURL(std::string(chrome::kExtensionScheme) +
194 chrome::kStandardSchemeSeparator + id_ + "/");
199 195
200 // Initialize version. 196 // Initialize version.
201 std::string version_str; 197 std::string version_str;
202 if (!source.GetString(kVersionKey, &version_str)) { 198 if (!source.GetString(kVersionKey, &version_str)) {
203 *error = kInvalidVersionError; 199 *error = kInvalidVersionError;
204 return false; 200 return false;
205 } 201 }
206 version_.reset(Version::GetVersionFromString(version_str)); 202 version_.reset(Version::GetVersionFromString(version_str));
207 if (!version_.get()) { 203 if (!version_.get()) {
208 *error = kInvalidVersionError; 204 *error = kInvalidVersionError;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 script.set_path(Extension::GetResourcePath(path(), file)); 324 script.set_path(Extension::GetResourcePath(path(), file));
329 script.set_url(Extension::GetResourceURL(url(), file)); 325 script.set_url(Extension::GetResourceURL(url(), file));
330 326
331 content_scripts_.push_back(script); 327 content_scripts_.push_back(script);
332 } 328 }
333 } 329 }
334 330
335 return true; 331 return true;
336 } 332 }
337 333
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension.h ('k') | chrome/browser/extensions/extension_protocols.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698