summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authoreaugusti@chromium.org <eaugusti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-13 19:00:24 +0000
committereaugusti@chromium.org <eaugusti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-13 19:00:24 +0000
commite7d6ec8594d224d2967de6edc94ddbd58419f218 (patch)
treee3b294198b1b56f6d0133888a8aa5712a14eb094 /chrome/browser
parent009266504f0b83aa61cbf91c4ed29c429f7674c2 (diff)
downloadchromium_src-e7d6ec8594d224d2967de6edc94ddbd58419f218.zip
chromium_src-e7d6ec8594d224d2967de6edc94ddbd58419f218.tar.gz
chromium_src-e7d6ec8594d224d2967de6edc94ddbd58419f218.tar.bz2
Adding run_at to chrome.tabs.executeScript/insertCss.
As per Aaron's suggestion I extended the functionality of UserScriptIdleScheduler to run different scripts at different times depending on when the script requested to be run. chrome.tabs.executeScript/insertCss now accept a 'runAt' parameter that follows the semantics specified here: http://code.google.com/chrome/extensions/content_scripts.html The script will be injected as earliest as the 'runAt' parameter. So I guess it is now more of a UserScriptScheduler. BUG=107286 Review URL: http://codereview.chromium.org/9456037 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132230 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/chromeos/accessibility/accessibility_util.cc7
-rw-r--r--chrome/browser/extensions/execute_code_in_tab_function.cc20
-rw-r--r--chrome/browser/extensions/execute_code_in_tab_function.h6
-rw-r--r--chrome/browser/extensions/execute_script_apitest.cc6
-rw-r--r--chrome/browser/extensions/extension_tabs_module.cc2
-rw-r--r--chrome/browser/extensions/extension_tabs_module_constants.cc1
-rw-r--r--chrome/browser/extensions/extension_tabs_module_constants.h1
7 files changed, 39 insertions, 4 deletions
diff --git a/chrome/browser/chromeos/accessibility/accessibility_util.cc b/chrome/browser/chromeos/accessibility/accessibility_util.cc
index 3207321..7ff99f2 100644
--- a/chrome/browser/chromeos/accessibility/accessibility_util.cc
+++ b/chrome/browser/chromeos/accessibility/accessibility_util.cc
@@ -17,6 +17,7 @@
#include "chrome/browser/speech/extension_api/tts_extension_api_platform.h"
#include "chrome/common/extensions/extension_messages.h"
#include "chrome/common/extensions/extension_resource.h"
+#include "chrome/common/extensions/user_script.h"
#include "chrome/common/pref_names.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
@@ -71,6 +72,7 @@ class ContentScriptLoader {
params.extension_id = extension_id_;
params.is_javascript = true;
params.code = data;
+ params.run_at = UserScript::DOCUMENT_IDLE;
params.all_frames = true;
params.in_main_world = false;
render_view_host_->Send(new ExtensionMsg_ExecuteCode(
@@ -110,7 +112,7 @@ void EnableSpokenFeedback(bool enabled, content::WebUI* login_web_ui) {
profile->GetExtensionService();
FilePath path = FilePath(extension_misc::kAccessExtensionPath)
.AppendASCII(extension_misc::kChromeVoxDirectoryName);
- if (enabled) { // Load ChromeVox
+ if (enabled) { // Load ChromeVox
const Extension* extension =
extension_service->component_loader()->Add(IDR_CHROMEVOX_MANIFEST,
path);
@@ -125,6 +127,7 @@ void EnableSpokenFeedback(bool enabled, content::WebUI* login_web_ui) {
params.extension_id = extension->id();
params.is_javascript = true;
params.code = "window.INJECTED_AFTER_LOAD = true;";
+ params.run_at = UserScript::DOCUMENT_IDLE;
params.all_frames = true;
params.in_main_world = false;
render_view_host->Send(new ExtensionMsg_ExecuteCode(
@@ -147,7 +150,7 @@ void EnableSpokenFeedback(bool enabled, content::WebUI* login_web_ui) {
}
DLOG(INFO) << "ChromeVox was Loaded.";
- } else { // Unload ChromeVox
+ } else { // Unload ChromeVox
extension_service->component_loader()->Remove(path);
DLOG(INFO) << "ChromeVox was Unloaded.";
}
diff --git a/chrome/browser/extensions/execute_code_in_tab_function.cc b/chrome/browser/extensions/execute_code_in_tab_function.cc
index d17de24..ee3f5be 100644
--- a/chrome/browser/extensions/execute_code_in_tab_function.cc
+++ b/chrome/browser/extensions/execute_code_in_tab_function.cc
@@ -20,6 +20,7 @@
#include "chrome/common/extensions/extension_error_utils.h"
#include "chrome/common/extensions/extension_file_util.h"
#include "chrome/common/extensions/extension_l10n_util.h"
+#include "chrome/common/extensions/extension_manifest_constants.h"
#include "chrome/common/extensions/extension_message_bundle.h"
#include "chrome/common/extensions/extension_messages.h"
#include "content/public/browser/render_view_host.h"
@@ -31,7 +32,8 @@ namespace keys = extension_tabs_module_constants;
ExecuteCodeInTabFunction::ExecuteCodeInTabFunction()
: execute_tab_id_(-1),
- all_frames_(false) {
+ all_frames_(false),
+ run_at_(UserScript::DOCUMENT_IDLE) {
}
ExecuteCodeInTabFunction::~ExecuteCodeInTabFunction() {
@@ -95,6 +97,21 @@ bool ExecuteCodeInTabFunction::RunImpl() {
return false;
}
+ if (script_info->HasKey(keys::kRunAtKey)) {
+ std::string run_string;
+ EXTENSION_FUNCTION_VALIDATE(script_info->GetString(
+ keys::kRunAtKey, &run_string));
+
+ if (run_string == extension_manifest_values::kRunAtDocumentStart)
+ run_at_ = UserScript::DOCUMENT_START;
+ else if (run_string == extension_manifest_values::kRunAtDocumentEnd)
+ run_at_ = UserScript::DOCUMENT_END;
+ else if (run_string == extension_manifest_values::kRunAtDocumentIdle)
+ run_at_ = UserScript::DOCUMENT_IDLE;
+ else
+ EXTENSION_FUNCTION_VALIDATE(false);
+ }
+
std::string code_string;
if (script_info->HasKey(keys::kCodeKey)) {
if (!script_info->GetString(keys::kCodeKey, &code_string))
@@ -222,6 +239,7 @@ bool ExecuteCodeInTabFunction::Execute(const std::string& code_string) {
params.is_javascript = is_js_code;
params.code = code_string;
params.all_frames = all_frames_;
+ params.run_at = run_at_;
params.in_main_world = false;
contents->web_contents()->GetRenderViewHost()->Send(
new ExtensionMsg_ExecuteCode(
diff --git a/chrome/browser/extensions/execute_code_in_tab_function.h b/chrome/browser/extensions/execute_code_in_tab_function.h
index fb36fa9..ccdee29 100644
--- a/chrome/browser/extensions/execute_code_in_tab_function.h
+++ b/chrome/browser/extensions/execute_code_in_tab_function.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -10,6 +10,7 @@
#include "chrome/browser/extensions/extension_function.h"
#include "chrome/common/extensions/extension_resource.h"
+#include "chrome/common/extensions/user_script.h"
#include "content/public/browser/web_contents_observer.h"
// Implement API call tabs.executeScript and tabs.insertCSS.
@@ -58,6 +59,9 @@ class ExecuteCodeInTabFunction : public AsyncExtensionFunction,
// If all_frames_ is true, script or CSS text would be injected
// to all frames; Otherwise only injected to top main frame.
bool all_frames_;
+
+ // The intended time to run the script.
+ UserScript::RunLocation run_at_;
};
class TabsExecuteScriptFunction : public ExecuteCodeInTabFunction {
diff --git a/chrome/browser/extensions/execute_script_apitest.cc b/chrome/browser/extensions/execute_script_apitest.cc
index 0a4cfaa..0594c79 100644
--- a/chrome/browser/extensions/execute_script_apitest.cc
+++ b/chrome/browser/extensions/execute_script_apitest.cc
@@ -72,3 +72,9 @@ IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, ExecuteScriptFrameAfterLoad) {
ASSERT_TRUE(StartTestServer());
ASSERT_TRUE(RunExtensionTest("executescript/frame_after_load")) << message_;
}
+
+IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, ExecuteScriptRunAt) {
+ SetupDelayedHostResolver();
+ ASSERT_TRUE(StartTestServer());
+ ASSERT_TRUE(RunExtensionTest("executescript/run_at")) << message_;
+}
diff --git a/chrome/browser/extensions/extension_tabs_module.cc b/chrome/browser/extensions/extension_tabs_module.cc
index ef450fd..e7bbd73 100644
--- a/chrome/browser/extensions/extension_tabs_module.cc
+++ b/chrome/browser/extensions/extension_tabs_module.cc
@@ -48,6 +48,7 @@
#include "chrome/common/extensions/extension_manifest_constants.h"
#include "chrome/common/extensions/extension_error_utils.h"
#include "chrome/common/extensions/extension_messages.h"
+#include "chrome/common/extensions/user_script.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "content/public/browser/navigation_controller.h"
@@ -1313,6 +1314,7 @@ bool UpdateTabFunction::UpdateURLIfPresent(DictionaryValue* update_props,
params.extension_id = extension_id();
params.is_javascript = true;
params.code = url.path();
+ params.run_at = UserScript::DOCUMENT_IDLE;
params.all_frames = false;
params.in_main_world = true;
diff --git a/chrome/browser/extensions/extension_tabs_module_constants.cc b/chrome/browser/extensions/extension_tabs_module_constants.cc
index 02cd07b..7ddd6e3 100644
--- a/chrome/browser/extensions/extension_tabs_module_constants.cc
+++ b/chrome/browser/extensions/extension_tabs_module_constants.cc
@@ -32,6 +32,7 @@ const char kOpenerTabIdKey[] = "openerTabId";
const char kPinnedKey[] = "pinned";
const char kQualityKey[] = "quality";
const char kHighlightedKey[] = "highlighted";
+const char kRunAtKey[] = "runAt";
const char kSelectedKey[] = "selected";
const char kShowStateKey[] = "state";
const char kStatusKey[] = "status";
diff --git a/chrome/browser/extensions/extension_tabs_module_constants.h b/chrome/browser/extensions/extension_tabs_module_constants.h
index 76d5f7f..daa35f4 100644
--- a/chrome/browser/extensions/extension_tabs_module_constants.h
+++ b/chrome/browser/extensions/extension_tabs_module_constants.h
@@ -36,6 +36,7 @@ extern const char kOpenerTabIdKey[];
extern const char kPinnedKey[];
extern const char kQualityKey[];
extern const char kHighlightedKey[];
+extern const char kRunAtKey[];
extern const char kSelectedKey[];
extern const char kShowStateKey[];
extern const char kStatusKey[];