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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension.cc
diff --git a/chrome/browser/extensions/extension.cc b/chrome/browser/extensions/extension.cc
index 11cab38ce8c109cbbf1ea4b16a29029ddad065de..d1d52a516867e9abfe357f596998d5cbe7588db2 100644
--- a/chrome/browser/extensions/extension.cc
+++ b/chrome/browser/extensions/extension.cc
@@ -22,9 +22,13 @@ const wchar_t* Extension::kIdKey = L"id";
const wchar_t* Extension::kMatchesKey = L"matches";
const wchar_t* Extension::kNameKey = L"name";
const wchar_t* Extension::kUserScriptsKey = L"user_scripts";
+const wchar_t* Extension::kRunAtKey = L"run_at";
const wchar_t* Extension::kVersionKey = L"version";
const wchar_t* Extension::kZipHashKey = L"zip_hash";
+const char* Extension::kRunAtDocumentStartValue = "document_start";
+const char* Extension::kRunAtDocumentEndValue = "document_end";
+
// Extension-related error messages. Some of these are simple patterns, where a
// '*' is replaced at runtime with a specific value. This is used instead of
// printf because we want to unit test them and scanf is hard to make
@@ -53,6 +57,8 @@ const char* Extension::kInvalidMatchesError =
"Required value 'user_scripts[*].matches' is missing or invalid.";
const char* Extension::kInvalidNameError =
"Required value 'name' is missing or invalid.";
+const char* Extension::kInvalidRunAtError =
+ "Invalid value for 'user_scripts[*].run_at'.";
const char* Extension::kInvalidUserScriptError =
"Invalid value for 'user_scripts[*]'.";
const char* Extension::kInvalidUserScriptsListError =
@@ -264,6 +270,23 @@ bool Extension::InitFromValue(const DictionaryValue& source,
}
UserScript script;
+ if (user_script->HasKey(kRunAtKey)) {
+ std::string run_location;
+ if (!user_script->GetString(kRunAtKey, &run_location)) {
+ *error = FormatErrorMessage(kInvalidRunAtError, IntToString(i));
+ return false;
+ }
+
+ if (run_location == kRunAtDocumentStartValue) {
+ script.set_run_location(UserScript::DOCUMENT_START);
+ } else if (run_location == kRunAtDocumentEndValue) {
+ script.set_run_location(UserScript::DOCUMENT_END);
+ } else {
+ *error = FormatErrorMessage(kInvalidRunAtError, IntToString(i));
+ return false;
+ }
+ }
+
for (size_t j = 0; j < matches->GetSize(); ++j) {
std::string match_str;
if (!matches->GetString(j, &match_str)) {

Powered by Google App Engine
This is Rietveld 408576698