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

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

Issue 518013: Merge 32634 - Make executeScript and insertCSS inject code into all frames.... (Closed) Base URL: svn://svn.chromium.org/chrome/branches/249/src/
Patch Set: Created 11 years 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 2308 matching lines...) Expand 10 before | Expand all | Expand 10 after
2319 RenderThread::current()->user_script_slave()->InjectScripts( 2319 RenderThread::current()->user_script_slave()->InjectScripts(
2320 frame, UserScript::DOCUMENT_IDLE); 2320 frame, UserScript::DOCUMENT_IDLE);
2321 } 2321 }
2322 2322
2323 WebFrame* main_frame = webview()->mainFrame(); 2323 WebFrame* main_frame = webview()->mainFrame();
2324 if (frame == main_frame) { 2324 if (frame == main_frame) {
2325 while (!pending_code_execution_queue_.empty()) { 2325 while (!pending_code_execution_queue_.empty()) {
2326 scoped_refptr<CodeExecutionInfo> info = 2326 scoped_refptr<CodeExecutionInfo> info =
2327 pending_code_execution_queue_.front(); 2327 pending_code_execution_queue_.front();
2328 ExecuteCodeImpl(main_frame, info->request_id, info->extension_id, 2328 ExecuteCodeImpl(main_frame, info->request_id, info->extension_id,
2329 info->is_js_code, info->code_string); 2329 info->is_js_code, info->code_string, info->all_frames);
2330 pending_code_execution_queue_.pop(); 2330 pending_code_execution_queue_.pop();
2331 } 2331 }
2332 } 2332 }
2333 } 2333 }
2334 2334
2335 void RenderView::didHandleOnloadEvents(WebFrame* frame) { 2335 void RenderView::didHandleOnloadEvents(WebFrame* frame) {
2336 // Ignore 2336 // Ignore
2337 } 2337 }
2338 2338
2339 void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) { 2339 void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
2957 2957
2958 void RenderView::OnSetPageEncoding(const std::string& encoding_name) { 2958 void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
2959 webview()->setPageEncoding(WebString::fromUTF8(encoding_name)); 2959 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
2960 } 2960 }
2961 2961
2962 void RenderView::OnResetPageEncodingToDefault() { 2962 void RenderView::OnResetPageEncodingToDefault() {
2963 WebString no_encoding; 2963 WebString no_encoding;
2964 webview()->setPageEncoding(no_encoding); 2964 webview()->setPageEncoding(no_encoding);
2965 } 2965 }
2966 2966
2967 bool RenderView::GetAllChildFrames(
2968 WebFrame* parent_frame,
2969 std::vector<WebFrame*>* frames_vector) const {
2970 if (!parent_frame)
2971 return false;
2972 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame;
2973 child_frame = child_frame->nextSibling()) {
2974 frames_vector->push_back(child_frame);
2975 GetAllChildFrames(child_frame, frames_vector);
2976 }
2977 return true;
2978 }
2979
2967 WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const { 2980 WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
2968 if (xpath.empty()) 2981 if (xpath.empty())
2969 return webview()->mainFrame(); 2982 return webview()->mainFrame();
2970 2983
2971 // xpath string can represent a frame deep down the tree (across multiple 2984 // xpath string can represent a frame deep down the tree (across multiple
2972 // frame DOMs). 2985 // frame DOMs).
2973 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0] 2986 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
2974 // should break into 2 xpaths 2987 // should break into 2 xpaths
2975 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0] 2988 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
2976 2989
(...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after
3738 print_helper_->Print(frame, script_initiated); 3751 print_helper_->Print(frame, script_initiated);
3739 } 3752 }
3740 3753
3741 void RenderView::OnSetEditCommandsForNextKeyEvent( 3754 void RenderView::OnSetEditCommandsForNextKeyEvent(
3742 const EditCommands& edit_commands) { 3755 const EditCommands& edit_commands) {
3743 edit_commands_ = edit_commands; 3756 edit_commands_ = edit_commands;
3744 } 3757 }
3745 3758
3746 void RenderView::OnExecuteCode(int request_id, const std::string& extension_id, 3759 void RenderView::OnExecuteCode(int request_id, const std::string& extension_id,
3747 bool is_js_code, 3760 bool is_js_code,
3748 const std::string& code_string) { 3761 const std::string& code_string,
3762 bool all_frames) {
3749 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL; 3763 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
3750 if (!main_frame) { 3764 if (!main_frame) {
3751 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, request_id, false)); 3765 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, request_id, false));
3752 return; 3766 return;
3753 } 3767 }
3754 3768
3755 WebDataSource* ds = main_frame->dataSource(); 3769 WebDataSource* ds = main_frame->dataSource();
3756 NavigationState* navigation_state = NavigationState::FromDataSource(ds); 3770 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3757 if (!navigation_state->user_script_idle_scheduler()->has_run()) { 3771 if (!navigation_state->user_script_idle_scheduler()->has_run()) {
3758 scoped_refptr<CodeExecutionInfo> info = new CodeExecutionInfo( 3772 scoped_refptr<CodeExecutionInfo> info = new CodeExecutionInfo(
3759 request_id, extension_id, is_js_code, code_string); 3773 request_id, extension_id, is_js_code, code_string, all_frames);
3760 pending_code_execution_queue_.push(info); 3774 pending_code_execution_queue_.push(info);
3761 return; 3775 return;
3762 } 3776 }
3763 3777
3764 ExecuteCodeImpl(main_frame, request_id, extension_id, is_js_code, 3778 ExecuteCodeImpl(main_frame, request_id, extension_id, is_js_code,
3765 code_string); 3779 code_string, all_frames);
3766 } 3780 }
3767 3781
3768 void RenderView::ExecuteCodeImpl(WebFrame* frame, 3782 void RenderView::ExecuteCodeImpl(WebFrame* frame,
3769 int request_id, 3783 int request_id,
3770 const std::string& extension_id, 3784 const std::string& extension_id,
3771 bool is_js_code, 3785 bool is_js_code,
3772 const std::string& code_string) { 3786 const std::string& code_string,
3773 if (is_js_code) { 3787 bool all_frames) {
3774 std::vector<WebScriptSource> sources; 3788 std::vector<WebFrame*> frame_vector;
3775 sources.push_back( 3789 frame_vector.push_back(frame);
3776 WebScriptSource(WebString::fromUTF8(code_string))); 3790 if (all_frames)
3777 UserScriptSlave::InsertInitExtensionCode(&sources, extension_id); 3791 GetAllChildFrames(frame, &frame_vector);
3778 frame->executeScriptInIsolatedWorld( 3792
3779 UserScriptSlave::GetIsolatedWorldId(extension_id), 3793 for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin();
3780 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS); 3794 frame_it != frame_vector.end(); ++frame_it) {
3781 } else { 3795 WebFrame* frame = *frame_it;
3782 frame->insertStyleText(WebString::fromUTF8(code_string), WebString()); 3796 if (is_js_code) {
3797 std::vector<WebScriptSource> sources;
3798 sources.push_back(
3799 WebScriptSource(WebString::fromUTF8(code_string)));
3800 UserScriptSlave::InsertInitExtensionCode(&sources, extension_id);
3801 frame->executeScriptInIsolatedWorld(
3802 UserScriptSlave::GetIsolatedWorldId(extension_id),
3803 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS);
3804 } else {
3805 frame->insertStyleText(WebString::fromUTF8(code_string), WebString());
3806 }
3783 } 3807 }
3784 3808
3785 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, request_id, true)); 3809 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, request_id, true));
3786 } 3810 }
3787 3811
3788 void RenderView::Close() { 3812 void RenderView::Close() {
3789 // We need to grab a pointer to the doomed WebView before we destroy it. 3813 // We need to grab a pointer to the doomed WebView before we destroy it.
3790 WebView* doomed = webview(); 3814 WebView* doomed = webview();
3791 RenderWidget::Close(); 3815 RenderWidget::Close();
3792 Singleton<ViewMap>::get()->erase(doomed); 3816 Singleton<ViewMap>::get()->erase(doomed);
(...skipping 20 matching lines...) Expand all
3813 new PluginMsg_SignalModalDialogEvent(host_window_)); 3837 new PluginMsg_SignalModalDialogEvent(host_window_));
3814 3838
3815 message->EnableMessagePumping(); // Runs a nested message loop. 3839 message->EnableMessagePumping(); // Runs a nested message loop.
3816 bool rv = Send(message); 3840 bool rv = Send(message);
3817 3841
3818 PluginChannelHost::Broadcast( 3842 PluginChannelHost::Broadcast(
3819 new PluginMsg_ResetModalDialogEvent(host_window_)); 3843 new PluginMsg_ResetModalDialogEvent(host_window_));
3820 3844
3821 return rv; 3845 return rv;
3822 } 3846 }
OLDNEW
« no previous file with comments | « chrome/renderer/render_view.h ('k') | chrome/test/data/extensions/api_test/executescript/test.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698