summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authortangjie@chromium.org <tangjie@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-20 18:27:20 +0000
committertangjie@chromium.org <tangjie@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-20 18:27:20 +0000
commit20ad269e71dc2a920bb2dc6a71591066aa4192cf (patch)
tree162984e2e7d9fc8d95065f510e9d3aa4d8b03104 /chrome/browser
parentee607b3e208cca332328f219f58e133a08f998d9 (diff)
downloadchromium_src-20ad269e71dc2a920bb2dc6a71591066aa4192cf.zip
chromium_src-20ad269e71dc2a920bb2dc6a71591066aa4192cf.tar.gz
chromium_src-20ad269e71dc2a920bb2dc6a71591066aa4192cf.tar.bz2
Make executeScript and insertCSS inject code into all frames.
Patched from 401007(see http://codereview.chromium.org/401007/) to commit. Reviewed by aa and darin. R=aa,darin Review URL: http://codereview.chromium.org/421005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@32634 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/extensions/execute_code_in_tab_function.cc21
-rw-r--r--chrome/browser/extensions/execute_code_in_tab_function.h7
-rw-r--r--chrome/browser/extensions/execute_script_apitest.cc1
-rw-r--r--chrome/browser/extensions/extension_tabs_module_constants.cc4
-rw-r--r--chrome/browser/tab_contents/tab_contents.cc6
-rw-r--r--chrome/browser/tab_contents/tab_contents.h3
6 files changed, 32 insertions, 10 deletions
diff --git a/chrome/browser/extensions/execute_code_in_tab_function.cc b/chrome/browser/extensions/execute_code_in_tab_function.cc
index 98bd3be..3fb0e86 100644
--- a/chrome/browser/extensions/execute_code_in_tab_function.cc
+++ b/chrome/browser/extensions/execute_code_in_tab_function.cc
@@ -17,6 +17,7 @@ namespace keys = extension_tabs_module_constants;
const wchar_t* kCodeKey = L"code";
const wchar_t* kFileKey = L"file";
+const wchar_t* kAllFramesKey = L"allFrames";
bool ExecuteCodeInTabFunction::RunImpl() {
EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST));
@@ -28,9 +29,16 @@ bool ExecuteCodeInTabFunction::RunImpl() {
if (number_of_value == 0) {
error_ = keys::kNoCodeOrFileToExecuteError;
return false;
- } else if (number_of_value > 1) {
- error_ = keys::kMoreThanOneValuesError;
- return false;
+ } else {
+ bool has_code = script_info->HasKey(kCodeKey);
+ bool has_file = script_info->HasKey(kFileKey);
+ if (has_code && has_file) {
+ error_ = keys::kMoreThanOneValuesError;
+ return false;
+ } else if (!has_code && !has_file) {
+ error_ = keys::kNoCodeOrFileToExecuteError;
+ return false;
+ }
}
execute_tab_id_ = -1;
@@ -66,6 +74,11 @@ bool ExecuteCodeInTabFunction::RunImpl() {
return false;
}
+ if (script_info->HasKey(kAllFramesKey)) {
+ if (!script_info->GetBoolean(kAllFramesKey, &all_frames_))
+ return false;
+ }
+
std::string code_string;
if (script_info->HasKey(kCodeKey)) {
if (!script_info->GetString(kCodeKey, &code_string))
@@ -133,7 +146,7 @@ void ExecuteCodeInTabFunction::Execute(const std::string& code_string) {
NotificationService::AllSources());
AddRef(); // balanced in Observe()
contents->ExecuteCode(request_id(), extension_id(), is_js_code,
- code_string);
+ code_string, all_frames_);
}
void ExecuteCodeInTabFunction::Observe(NotificationType type,
diff --git a/chrome/browser/extensions/execute_code_in_tab_function.h b/chrome/browser/extensions/execute_code_in_tab_function.h
index 8215fd2..bd765f5 100644
--- a/chrome/browser/extensions/execute_code_in_tab_function.h
+++ b/chrome/browser/extensions/execute_code_in_tab_function.h
@@ -20,7 +20,8 @@ class MessageLoop;
class ExecuteCodeInTabFunction : public AsyncExtensionFunction,
public NotificationObserver {
public:
- ExecuteCodeInTabFunction() : execute_tab_id_(-1) {}
+ ExecuteCodeInTabFunction() : execute_tab_id_(-1),
+ all_frames_(false) {}
private:
virtual bool RunImpl();
@@ -44,6 +45,10 @@ class ExecuteCodeInTabFunction : public AsyncExtensionFunction,
// Contains extension resource built from path of file which is
// specified in JSON arguments.
ExtensionResource resource_;
+
+ // 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_;
};
class TabsExecuteScriptFunction : public ExecuteCodeInTabFunction {
diff --git a/chrome/browser/extensions/execute_script_apitest.cc b/chrome/browser/extensions/execute_script_apitest.cc
index f519702..2ac734b 100644
--- a/chrome/browser/extensions/execute_script_apitest.cc
+++ b/chrome/browser/extensions/execute_script_apitest.cc
@@ -10,4 +10,5 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ExecuteScript) {
StartHTTPServer();
ASSERT_TRUE(RunExtensionTest("executescript")) << message_;
+ ASSERT_TRUE(RunExtensionTest("executescript_in_frame")) << message_;
}
diff --git a/chrome/browser/extensions/extension_tabs_module_constants.cc b/chrome/browser/extensions/extension_tabs_module_constants.cc
index dac399f3..a3fc48d 100644
--- a/chrome/browser/extensions/extension_tabs_module_constants.cc
+++ b/chrome/browser/extensions/extension_tabs_module_constants.cc
@@ -47,8 +47,8 @@ const char kCannotAccessPageError[] = "Cannot access contents of url \"*\". "
const char kSupportedInWindowsOnlyError[] = "Supported in Windows only";
const char kNoCodeOrFileToExecuteError[] = "No source code or file specified.";
-const char kMoreThanOneValuesError[] = "There should be only one value (either"
- "code or file) in the second argument.";
+const char kMoreThanOneValuesError[] = "Code and file should not be specified "
+ "at the same time in the second argument.";
const char kLoadFileError[] = "Failed to load file: \"*\". ";
} // namespace extension_tabs_module_constants
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc
index 7706c5b..0251f03 100644
--- a/chrome/browser/tab_contents/tab_contents.cc
+++ b/chrome/browser/tab_contents/tab_contents.cc
@@ -815,10 +815,12 @@ void TabContents::CloseAllSuppressedPopups() {
}
void TabContents::ExecuteCode(int request_id, const std::string& extension_id,
- bool is_js_code, const std::string& code_string) {
+ bool is_js_code, const std::string& code_string,
+ bool all_frames) {
render_view_host()->Send(
new ViewMsg_ExecuteCode(render_view_host()->routing_id(), request_id,
- extension_id, is_js_code, code_string));
+ extension_id, is_js_code, code_string,
+ all_frames));
}
void TabContents::PopupNotificationVisibilityChanged(bool visible) {
diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h
index 1b1bd13..e440a53 100644
--- a/chrome/browser/tab_contents/tab_contents.h
+++ b/chrome/browser/tab_contents/tab_contents.h
@@ -363,7 +363,8 @@ class TabContents : public PageNavigator,
// Execute code in this tab.
void ExecuteCode(int request_id, const std::string& extension_id,
- bool is_js_code, const std::string& code_string);
+ bool is_js_code, const std::string& code_string,
+ bool all_frames);
// Called when the blocked popup notification is shown or hidden.
virtual void PopupNotificationVisibilityChanged(bool visible);