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

Unified Diff: chrome/renderer/render_view.cc

Issue 173556: Implement script API:executeScript (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 3 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
« no previous file with comments | « chrome/renderer/render_view.h ('k') | chrome/renderer/user_script_slave.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/render_view.cc
===================================================================
--- chrome/renderer/render_view.cc (revision 26435)
+++ chrome/renderer/render_view.cc (working copy)
@@ -37,6 +37,7 @@
#include "chrome/renderer/audio_message_filter.h"
#include "chrome/renderer/devtools_agent.h"
#include "chrome/renderer/devtools_client.h"
+#include "chrome/renderer/extension_groups.h"
#include "chrome/renderer/extensions/event_bindings.h"
#include "chrome/renderer/extensions/extension_process_bindings.h"
#include "chrome/renderer/extensions/renderer_extension_bindings.h"
@@ -442,6 +443,8 @@
IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
OnSetEditCommandsForNextKeyEvent);
+ IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode,
+ OnExecuteCode)
// Have the super handle all other messages.
IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
@@ -2079,6 +2082,14 @@
frame, UserScript::DOCUMENT_START);
}
+ while (!pending_code_execution_queue_.empty()) {
+ scoped_refptr<CodeExecutionInfo> info =
+ pending_code_execution_queue_.front();
+ OnExecuteCode(info->request_id, info->extension_id, info->is_js_code,
+ info->code_string);
+ pending_code_execution_queue_.pop();
+ }
+
// Notify the browser about non-blank documents loading in the top frame.
GURL url = frame->url();
if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
@@ -3480,6 +3491,35 @@
edit_commands_ = edit_commands;
}
+void RenderView::OnExecuteCode(int request_id, const std::string& extension_id,
+ bool is_js_code,
+ const std::string& code_string) {
+ if (is_loading_) {
+ scoped_refptr<CodeExecutionInfo> info = new CodeExecutionInfo(
+ request_id, extension_id, is_js_code, code_string);
+ pending_code_execution_queue_.push(info);
+ return;
+ }
+ WebFrame* main_frame = webview() ? webview()->GetMainFrame() : NULL;
+ if (!main_frame) {
+ Send(new ViewMsg_ExecuteCodeFinished(routing_id_, request_id, false));
+ return;
+ }
+
+ if (is_js_code) {
+ std::vector<WebScriptSource> sources;
+ sources.push_back(
+ WebScriptSource(WebString::fromUTF8(code_string)));
+ UserScriptSlave::InsertInitExtensionCode(&sources, extension_id);
+ main_frame->executeScriptInNewWorld(&sources.front(), sources.size(),
+ EXTENSION_GROUP_CONTENT_SCRIPTS);
+ } else {
+ main_frame->insertStyleText(WebString::fromUTF8(code_string), WebString());
+ }
+
+ Send(new ViewMsg_ExecuteCodeFinished(routing_id_, request_id, true));
+}
+
void RenderView::DidHandleKeyEvent() {
edit_commands_.clear();
}
« no previous file with comments | « chrome/renderer/render_view.h ('k') | chrome/renderer/user_script_slave.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698