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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/render_view.h ('k') | chrome/renderer/user_script_slave.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/renderer/render_view.h" 5 #include "chrome/renderer/render_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 19 matching lines...) Expand all
30 #include "chrome/common/jstemplate_builder.h" 30 #include "chrome/common/jstemplate_builder.h"
31 #include "chrome/common/page_zoom.h" 31 #include "chrome/common/page_zoom.h"
32 #include "chrome/common/render_messages.h" 32 #include "chrome/common/render_messages.h"
33 #include "chrome/common/renderer_preferences.h" 33 #include "chrome/common/renderer_preferences.h"
34 #include "chrome/common/thumbnail_score.h" 34 #include "chrome/common/thumbnail_score.h"
35 #include "chrome/common/url_constants.h" 35 #include "chrome/common/url_constants.h"
36 #include "chrome/renderer/about_handler.h" 36 #include "chrome/renderer/about_handler.h"
37 #include "chrome/renderer/audio_message_filter.h" 37 #include "chrome/renderer/audio_message_filter.h"
38 #include "chrome/renderer/devtools_agent.h" 38 #include "chrome/renderer/devtools_agent.h"
39 #include "chrome/renderer/devtools_client.h" 39 #include "chrome/renderer/devtools_client.h"
40 #include "chrome/renderer/extension_groups.h"
40 #include "chrome/renderer/extensions/event_bindings.h" 41 #include "chrome/renderer/extensions/event_bindings.h"
41 #include "chrome/renderer/extensions/extension_process_bindings.h" 42 #include "chrome/renderer/extensions/extension_process_bindings.h"
42 #include "chrome/renderer/extensions/renderer_extension_bindings.h" 43 #include "chrome/renderer/extensions/renderer_extension_bindings.h"
43 #include "chrome/renderer/localized_error.h" 44 #include "chrome/renderer/localized_error.h"
44 #include "chrome/renderer/media/audio_renderer_impl.h" 45 #include "chrome/renderer/media/audio_renderer_impl.h"
45 #include "chrome/renderer/navigation_state.h" 46 #include "chrome/renderer/navigation_state.h"
46 #include "chrome/renderer/print_web_view_helper.h" 47 #include "chrome/renderer/print_web_view_helper.h"
47 #include "chrome/renderer/render_process.h" 48 #include "chrome/renderer/render_process.h"
48 #include "chrome/renderer/user_script_slave.h" 49 #include "chrome/renderer/user_script_slave.h"
49 #include "chrome/renderer/visitedlink_slave.h" 50 #include "chrome/renderer/visitedlink_slave.h"
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 OnEnableIntrinsicWidthChangedMode) 436 OnEnableIntrinsicWidthChangedMode)
436 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs) 437 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
437 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId, 438 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId,
438 OnUpdateBrowserWindowId) 439 OnUpdateBrowserWindowId)
439 IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType, 440 IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType,
440 OnNotifyRendererViewType) 441 OnNotifyRendererViewType)
441 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt) 442 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
442 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive) 443 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
443 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent, 444 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
444 OnSetEditCommandsForNextKeyEvent); 445 OnSetEditCommandsForNextKeyEvent);
446 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode,
447 OnExecuteCode)
445 448
446 // Have the super handle all other messages. 449 // Have the super handle all other messages.
447 IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message)) 450 IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
448 IPC_END_MESSAGE_MAP() 451 IPC_END_MESSAGE_MAP()
449 } 452 }
450 453
451 void RenderView::SendThumbnail() { 454 void RenderView::SendThumbnail() {
452 WebFrame* main_frame = webview()->GetMainFrame(); 455 WebFrame* main_frame = webview()->GetMainFrame();
453 if (!main_frame) 456 if (!main_frame)
454 return; 457 return;
(...skipping 1617 matching lines...) Expand 10 before | Expand all | Expand 10 after
2072 external_host_bindings_.BindToJavascript(frame, L"externalHost"); 2075 external_host_bindings_.BindToJavascript(frame, L"externalHost");
2073 } 2076 }
2074 } 2077 }
2075 2078
2076 void RenderView::didCreateDocumentElement(WebFrame* frame) { 2079 void RenderView::didCreateDocumentElement(WebFrame* frame) {
2077 if (RenderThread::current()) { // Will be NULL during unit tests. 2080 if (RenderThread::current()) { // Will be NULL during unit tests.
2078 RenderThread::current()->user_script_slave()->InjectScripts( 2081 RenderThread::current()->user_script_slave()->InjectScripts(
2079 frame, UserScript::DOCUMENT_START); 2082 frame, UserScript::DOCUMENT_START);
2080 } 2083 }
2081 2084
2085 while (!pending_code_execution_queue_.empty()) {
2086 scoped_refptr<CodeExecutionInfo> info =
2087 pending_code_execution_queue_.front();
2088 OnExecuteCode(info->request_id, info->extension_id, info->is_js_code,
2089 info->code_string);
2090 pending_code_execution_queue_.pop();
2091 }
2092
2082 // Notify the browser about non-blank documents loading in the top frame. 2093 // Notify the browser about non-blank documents loading in the top frame.
2083 GURL url = frame->url(); 2094 GURL url = frame->url();
2084 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) { 2095 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
2085 if (frame == webview()->GetMainFrame()) 2096 if (frame == webview()->GetMainFrame())
2086 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_)); 2097 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2087 } 2098 }
2088 } 2099 }
2089 2100
2090 void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) { 2101 void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) {
2091 UpdateTitle(frame, title); 2102 UpdateTitle(frame, title);
(...skipping 1381 matching lines...) Expand 10 before | Expand all | Expand 10 after
3473 print_helper_.reset(new PrintWebViewHelper(this)); 3484 print_helper_.reset(new PrintWebViewHelper(this));
3474 } 3485 }
3475 print_helper_->Print(frame, script_initiated); 3486 print_helper_->Print(frame, script_initiated);
3476 } 3487 }
3477 3488
3478 void RenderView::OnSetEditCommandsForNextKeyEvent( 3489 void RenderView::OnSetEditCommandsForNextKeyEvent(
3479 const EditCommands& edit_commands) { 3490 const EditCommands& edit_commands) {
3480 edit_commands_ = edit_commands; 3491 edit_commands_ = edit_commands;
3481 } 3492 }
3482 3493
3494 void RenderView::OnExecuteCode(int request_id, const std::string& extension_id,
3495 bool is_js_code,
3496 const std::string& code_string) {
3497 if (is_loading_) {
3498 scoped_refptr<CodeExecutionInfo> info = new CodeExecutionInfo(
3499 request_id, extension_id, is_js_code, code_string);
3500 pending_code_execution_queue_.push(info);
3501 return;
3502 }
3503 WebFrame* main_frame = webview() ? webview()->GetMainFrame() : NULL;
3504 if (!main_frame) {
3505 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, request_id, false));
3506 return;
3507 }
3508
3509 if (is_js_code) {
3510 std::vector<WebScriptSource> sources;
3511 sources.push_back(
3512 WebScriptSource(WebString::fromUTF8(code_string)));
3513 UserScriptSlave::InsertInitExtensionCode(&sources, extension_id);
3514 main_frame->executeScriptInNewWorld(&sources.front(), sources.size(),
3515 EXTENSION_GROUP_CONTENT_SCRIPTS);
3516 } else {
3517 main_frame->insertStyleText(WebString::fromUTF8(code_string), WebString());
3518 }
3519
3520 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, request_id, true));
3521 }
3522
3483 void RenderView::DidHandleKeyEvent() { 3523 void RenderView::DidHandleKeyEvent() {
3484 edit_commands_.clear(); 3524 edit_commands_.clear();
3485 } 3525 }
3486 3526
3487 bool RenderView::HandleCurrentKeyboardEvent() { 3527 bool RenderView::HandleCurrentKeyboardEvent() {
3488 if (edit_commands_.empty()) 3528 if (edit_commands_.empty())
3489 return false; 3529 return false;
3490 3530
3491 WebFrame* frame = webview()->GetFocusedFrame(); 3531 WebFrame* frame = webview()->GetFocusedFrame();
3492 if (!frame) 3532 if (!frame)
(...skipping 15 matching lines...) Expand all
3508 // TODO(darin): There's actually no reason for this to be here. We should 3548 // TODO(darin): There's actually no reason for this to be here. We should
3509 // have the browser side manage the document tag. 3549 // have the browser side manage the document tag.
3510 #if defined(OS_MACOSX) 3550 #if defined(OS_MACOSX)
3511 if (!has_document_tag_) { 3551 if (!has_document_tag_) {
3512 // Make the call to get the tag. 3552 // Make the call to get the tag.
3513 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_)); 3553 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_));
3514 has_document_tag_ = true; 3554 has_document_tag_ = true;
3515 } 3555 }
3516 #endif 3556 #endif
3517 } 3557 }
OLDNEW
« 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