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

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

Issue 19624: Add early-injection capability to user scripts. I haven't yet (Closed)
Patch Set: Use new documentElementAvailable() callback 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
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
13 const char kExtensionURLScheme[] = "chrome-extension"; 13 const char kExtensionURLScheme[] = "chrome-extension";
14 const char kUserScriptURLScheme[] = "chrome-user-script"; 14 const char kUserScriptURLScheme[] = "chrome-user-script";
15 15
16 const char Extension::kManifestFilename[] = "manifest.json"; 16 const char Extension::kManifestFilename[] = "manifest.json";
17 17
18 const wchar_t* Extension::kDescriptionKey = L"description"; 18 const wchar_t* Extension::kDescriptionKey = L"description";
19 const wchar_t* Extension::kFilesKey = L"files"; 19 const wchar_t* Extension::kFilesKey = L"files";
20 const wchar_t* Extension::kFormatVersionKey = L"format_version"; 20 const wchar_t* Extension::kFormatVersionKey = L"format_version";
21 const wchar_t* Extension::kIdKey = L"id"; 21 const wchar_t* Extension::kIdKey = L"id";
22 const wchar_t* Extension::kMatchesKey = L"matches"; 22 const wchar_t* Extension::kMatchesKey = L"matches";
23 const wchar_t* Extension::kNameKey = L"name"; 23 const wchar_t* Extension::kNameKey = L"name";
24 const wchar_t* Extension::kUserScriptsKey = L"user_scripts"; 24 const wchar_t* Extension::kUserScriptsKey = L"user_scripts";
25 const wchar_t* Extension::kRunAtKey = L"run_at";
25 const wchar_t* Extension::kVersionKey = L"version"; 26 const wchar_t* Extension::kVersionKey = L"version";
26 const wchar_t* Extension::kZipHashKey = L"zip_hash"; 27 const wchar_t* Extension::kZipHashKey = L"zip_hash";
27 28
29 const char* Extension::kRunAtDocumentStartValue = "document_start";
30 const char* Extension::kRunAtDocumentEndValue = "document_end";
31
28 // Extension-related error messages. Some of these are simple patterns, where a 32 // Extension-related error messages. Some of these are simple patterns, where a
29 // '*' is replaced at runtime with a specific value. This is used instead of 33 // '*' is replaced at runtime with a specific value. This is used instead of
30 // printf because we want to unit test them and scanf is hard to make 34 // printf because we want to unit test them and scanf is hard to make
31 // cross-platform. 35 // cross-platform.
32 const char* Extension::kInvalidDescriptionError = 36 const char* Extension::kInvalidDescriptionError =
33 "Invalid value for 'description'."; 37 "Invalid value for 'description'.";
34 const char* Extension::kInvalidFileCountError = 38 const char* Extension::kInvalidFileCountError =
35 "Invalid value for 'user_scripts[*].files. Only one file is currently " 39 "Invalid value for 'user_scripts[*].files. Only one file is currently "
36 "supported per-user script."; 40 "supported per-user script.";
37 const char* Extension::kInvalidFileError = 41 const char* Extension::kInvalidFileError =
38 "Invalid value for 'user_scripts[*].files[*]'."; 42 "Invalid value for 'user_scripts[*].files[*]'.";
39 const char* Extension::kInvalidFilesError = 43 const char* Extension::kInvalidFilesError =
40 "Required value 'user_scripts[*].files is missing or invalid."; 44 "Required value 'user_scripts[*].files is missing or invalid.";
41 const char* Extension::kInvalidFormatVersionError = 45 const char* Extension::kInvalidFormatVersionError =
42 "Required value 'format_version' is missing or invalid."; 46 "Required value 'format_version' is missing or invalid.";
43 const char* Extension::kInvalidIdError = 47 const char* Extension::kInvalidIdError =
44 "Required value 'id' is missing or invalid."; 48 "Required value 'id' is missing or invalid.";
45 const char* Extension::kInvalidManifestError = 49 const char* Extension::kInvalidManifestError =
46 "Manifest is missing or invalid."; 50 "Manifest is missing or invalid.";
47 const char* Extension::kInvalidMatchCountError = 51 const char* Extension::kInvalidMatchCountError =
48 "Invalid value for 'user_scripts[*].matches. There must be at least one " 52 "Invalid value for 'user_scripts[*].matches. There must be at least one "
49 "match specified."; 53 "match specified.";
50 const char* Extension::kInvalidMatchError = 54 const char* Extension::kInvalidMatchError =
51 "Invalid value for 'user_scripts[*].matches[*]'."; 55 "Invalid value for 'user_scripts[*].matches[*]'.";
52 const char* Extension::kInvalidMatchesError = 56 const char* Extension::kInvalidMatchesError =
53 "Required value 'user_scripts[*].matches' is missing or invalid."; 57 "Required value 'user_scripts[*].matches' is missing or invalid.";
54 const char* Extension::kInvalidNameError = 58 const char* Extension::kInvalidNameError =
55 "Required value 'name' is missing or invalid."; 59 "Required value 'name' is missing or invalid.";
60 const char* Extension::kInvalidRunAtError =
61 "Invalid value for 'user_scripts[*].run_at'.";
56 const char* Extension::kInvalidUserScriptError = 62 const char* Extension::kInvalidUserScriptError =
57 "Invalid value for 'user_scripts[*]'."; 63 "Invalid value for 'user_scripts[*]'.";
58 const char* Extension::kInvalidUserScriptsListError = 64 const char* Extension::kInvalidUserScriptsListError =
59 "Invalid value for 'user_scripts'."; 65 "Invalid value for 'user_scripts'.";
60 const char* Extension::kInvalidVersionError = 66 const char* Extension::kInvalidVersionError =
61 "Required value 'version' is missing or invalid."; 67 "Required value 'version' is missing or invalid.";
62 const char* Extension::kInvalidZipHashError = 68 const char* Extension::kInvalidZipHashError =
63 "Required key 'zip_hash' is missing or invalid."; 69 "Required key 'zip_hash' is missing or invalid.";
64 70
65 const std::string Extension::VersionString() const { 71 const std::string Extension::VersionString() const {
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 return false; 263 return false;
258 } 264 }
259 265
260 // NOTE: Only one file is supported right now. 266 // NOTE: Only one file is supported right now.
261 if (files->GetSize() != 1) { 267 if (files->GetSize() != 1) {
262 *error = FormatErrorMessage(kInvalidFileCountError, IntToString(i)); 268 *error = FormatErrorMessage(kInvalidFileCountError, IntToString(i));
263 return false; 269 return false;
264 } 270 }
265 271
266 UserScript script; 272 UserScript script;
273 if (user_script->HasKey(kRunAtKey)) {
274 std::string run_location;
275 if (!user_script->GetString(kRunAtKey, &run_location)) {
276 *error = FormatErrorMessage(kInvalidRunAtError, IntToString(i));
277 return false;
278 }
279
280 if (run_location == kRunAtDocumentStartValue) {
281 script.set_run_location(UserScript::DOCUMENT_START);
282 } else if (run_location == kRunAtDocumentEndValue) {
283 script.set_run_location(UserScript::DOCUMENT_END);
284 } else {
285 *error = FormatErrorMessage(kInvalidRunAtError, IntToString(i));
286 return false;
287 }
288 }
289
267 for (size_t j = 0; j < matches->GetSize(); ++j) { 290 for (size_t j = 0; j < matches->GetSize(); ++j) {
268 std::string match_str; 291 std::string match_str;
269 if (!matches->GetString(j, &match_str)) { 292 if (!matches->GetString(j, &match_str)) {
270 *error = FormatErrorMessage(kInvalidMatchError, IntToString(i), 293 *error = FormatErrorMessage(kInvalidMatchError, IntToString(i),
271 IntToString(j)); 294 IntToString(j));
272 return false; 295 return false;
273 } 296 }
274 297
275 URLPattern pattern; 298 URLPattern pattern;
276 if (!pattern.Parse(match_str)) { 299 if (!pattern.Parse(match_str)) {
(...skipping 15 matching lines...) Expand all
292 script.set_path(Extension::GetResourcePath(path(), file)); 315 script.set_path(Extension::GetResourcePath(path(), file));
293 script.set_url(Extension::GetResourceURL(url(), file)); 316 script.set_url(Extension::GetResourceURL(url(), file));
294 317
295 user_scripts_.push_back(script); 318 user_scripts_.push_back(script);
296 } 319 }
297 } 320 }
298 321
299 return true; 322 return true;
300 } 323 }
301 324
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698