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

Side by Side Diff: chrome/renderer/render_view.cc

Issue 401007: Make executeScript and insertCSS inject code into all frames. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 1 month 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
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 #if defined(ENABLE_PEPPER) 5 #if defined(ENABLE_PEPPER)
6 #define PEPPER_APIS_ENABLED 6 #define PEPPER_APIS_ENABLED
7 #endif 7 #endif
8 8
9 #include "chrome/renderer/render_view.h" 9 #include "chrome/renderer/render_view.h"
10 10
(...skipping 2333 matching lines...) Expand 10 before | Expand all | Expand 10 after
2344 RenderThread::current()->user_script_slave()->InjectScripts( 2344 RenderThread::current()->user_script_slave()->InjectScripts(
2345 frame, UserScript::DOCUMENT_IDLE); 2345 frame, UserScript::DOCUMENT_IDLE);
2346 } 2346 }
2347 2347
2348 WebFrame* main_frame = webview()->mainFrame(); 2348 WebFrame* main_frame = webview()->mainFrame();
2349 if (frame == main_frame) { 2349 if (frame == main_frame) {
2350 while (!pending_code_execution_queue_.empty()) { 2350 while (!pending_code_execution_queue_.empty()) {
2351 scoped_refptr<CodeExecutionInfo> info = 2351 scoped_refptr<CodeExecutionInfo> info =
2352 pending_code_execution_queue_.front(); 2352 pending_code_execution_queue_.front();
2353 ExecuteCodeImpl(main_frame, info->request_id, info->extension_id, 2353 ExecuteCodeImpl(main_frame, info->request_id, info->extension_id,
2354 info->is_js_code, info->code_string); 2354 info->is_js_code, info->code_string, info->all_frames);
2355 pending_code_execution_queue_.pop(); 2355 pending_code_execution_queue_.pop();
2356 } 2356 }
2357 } 2357 }
2358 } 2358 }
2359 2359
2360 void RenderView::didHandleOnloadEvents(WebFrame* frame) { 2360 void RenderView::didHandleOnloadEvents(WebFrame* frame) {
2361 // Ignore 2361 // Ignore
2362 } 2362 }
2363 2363
2364 void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) { 2364 void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
2983 2983
2984 void RenderView::OnSetPageEncoding(const std::string& encoding_name) { 2984 void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
2985 webview()->setPageEncoding(WebString::fromUTF8(encoding_name)); 2985 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
2986 } 2986 }
2987 2987
2988 void RenderView::OnResetPageEncodingToDefault() { 2988 void RenderView::OnResetPageEncodingToDefault() {
2989 WebString no_encoding; 2989 WebString no_encoding;
2990 webview()->setPageEncoding(no_encoding); 2990 webview()->setPageEncoding(no_encoding);
2991 } 2991 }
2992 2992
2993 bool RenderView::GetAllChildFrames(
2994 WebFrame* parent_frame,
2995 std::vector<WebFrame*>* frames_vector) const {
2996 if (!parent_frame)
2997 return false;
2998 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame;
2999 child_frame = child_frame->nextSibling()) {
3000 frames_vector->push_back(child_frame);
3001 GetAllChildFrames(child_frame, frames_vector);
3002 }
3003 return true;
3004 }
3005
2993 WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const { 3006 WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
2994 if (xpath.empty()) 3007 if (xpath.empty())
2995 return webview()->mainFrame(); 3008 return webview()->mainFrame();
2996 3009
2997 // xpath string can represent a frame deep down the tree (across multiple 3010 // xpath string can represent a frame deep down the tree (across multiple
2998 // frame DOMs). 3011 // frame DOMs).
2999 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0] 3012 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
3000 // should break into 2 xpaths 3013 // should break into 2 xpaths
3001 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0] 3014 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
3002 3015
(...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after
3764 print_helper_->Print(frame, script_initiated); 3777 print_helper_->Print(frame, script_initiated);
3765 } 3778 }
3766 3779
3767 void RenderView::OnSetEditCommandsForNextKeyEvent( 3780 void RenderView::OnSetEditCommandsForNextKeyEvent(
3768 const EditCommands& edit_commands) { 3781 const EditCommands& edit_commands) {
3769 edit_commands_ = edit_commands; 3782 edit_commands_ = edit_commands;
3770 } 3783 }
3771 3784
3772 void RenderView::OnExecuteCode(int request_id, const std::string& extension_id, 3785 void RenderView::OnExecuteCode(int request_id, const std::string& extension_id,
3773 bool is_js_code, 3786 bool is_js_code,
3774 const std::string& code_string) { 3787 const std::string& code_string,
3788 bool all_frames) {
3775 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL; 3789 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
3776 if (!main_frame) { 3790 if (!main_frame) {
3777 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, request_id, false)); 3791 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, request_id, false));
3778 return; 3792 return;
3779 } 3793 }
3780 3794
3781 WebDataSource* ds = main_frame->dataSource(); 3795 WebDataSource* ds = main_frame->dataSource();
3782 NavigationState* navigation_state = NavigationState::FromDataSource(ds); 3796 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3783 if (!navigation_state->user_script_idle_scheduler()->has_run()) { 3797 if (!navigation_state->user_script_idle_scheduler()->has_run()) {
3784 scoped_refptr<CodeExecutionInfo> info = new CodeExecutionInfo( 3798 scoped_refptr<CodeExecutionInfo> info = new CodeExecutionInfo(
3785 request_id, extension_id, is_js_code, code_string); 3799 request_id, extension_id, is_js_code, code_string, all_frames);
3786 pending_code_execution_queue_.push(info); 3800 pending_code_execution_queue_.push(info);
3787 return; 3801 return;
3788 } 3802 }
3789 3803
3790 ExecuteCodeImpl(main_frame, request_id, extension_id, is_js_code, 3804 ExecuteCodeImpl(main_frame, request_id, extension_id, is_js_code,
3791 code_string); 3805 code_string, all_frames);
3792 } 3806 }
3793 3807
3794 void RenderView::ExecuteCodeImpl(WebFrame* frame, 3808 void RenderView::ExecuteCodeImpl(WebFrame* frame,
3795 int request_id, 3809 int request_id,
3796 const std::string& extension_id, 3810 const std::string& extension_id,
3797 bool is_js_code, 3811 bool is_js_code,
3798 const std::string& code_string) { 3812 const std::string& code_string,
3799 if (is_js_code) { 3813 bool all_frames) {
3800 std::vector<WebScriptSource> sources; 3814 std::vector<WebFrame*> frame_vector;
3801 sources.push_back( 3815 frame_vector.push_back(frame);
3802 WebScriptSource(WebString::fromUTF8(code_string))); 3816 if (all_frames)
3803 UserScriptSlave::InsertInitExtensionCode(&sources, extension_id); 3817 GetAllChildFrames(frame, &frame_vector);
3804 frame->executeScriptInIsolatedWorld( 3818
3805 UserScriptSlave::GetIsolatedWorldId(extension_id), 3819 for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin();
3806 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS); 3820 frame_it != frame_vector.end(); ++frame_it) {
3807 } else { 3821 WebFrame* frame = *frame_it;
3808 frame->insertStyleText(WebString::fromUTF8(code_string), WebString()); 3822 if (is_js_code) {
3823 std::vector<WebScriptSource> sources;
3824 sources.push_back(
3825 WebScriptSource(WebString::fromUTF8(code_string)));
3826 UserScriptSlave::InsertInitExtensionCode(&sources, extension_id);
3827 frame->executeScriptInIsolatedWorld(
3828 UserScriptSlave::GetIsolatedWorldId(extension_id),
3829 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS);
3830 } else {
3831 frame->insertStyleText(WebString::fromUTF8(code_string), WebString());
3832 }
3809 } 3833 }
3810 3834
3811 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, request_id, true)); 3835 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, request_id, true));
3812 } 3836 }
3813 3837
3814 void RenderView::Close() { 3838 void RenderView::Close() {
3815 // We need to grab a pointer to the doomed WebView before we destroy it. 3839 // We need to grab a pointer to the doomed WebView before we destroy it.
3816 WebView* doomed = webview(); 3840 WebView* doomed = webview();
3817 RenderWidget::Close(); 3841 RenderWidget::Close();
3818 Singleton<ViewMap>::get()->erase(doomed); 3842 Singleton<ViewMap>::get()->erase(doomed);
(...skipping 20 matching lines...) Expand all
3839 new PluginMsg_SignalModalDialogEvent(host_window_)); 3863 new PluginMsg_SignalModalDialogEvent(host_window_));
3840 3864
3841 message->EnableMessagePumping(); // Runs a nested message loop. 3865 message->EnableMessagePumping(); // Runs a nested message loop.
3842 bool rv = Send(message); 3866 bool rv = Send(message);
3843 3867
3844 PluginChannelHost::Broadcast( 3868 PluginChannelHost::Broadcast(
3845 new PluginMsg_ResetModalDialogEvent(host_window_)); 3869 new PluginMsg_ResetModalDialogEvent(host_window_));
3846 3870
3847 return rv; 3871 return rv;
3848 } 3872 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698