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

Side by Side Diff: content/browser/renderer_host/render_view_host.cc

Issue 8760024: Cross-process postMessage (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Some cleanup Created 9 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "content/browser/renderer_host/render_view_host.h" 5 #include "content/browser/renderer_host/render_view_host.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/i18n/rtl.h" 12 #include "base/i18n/rtl.h"
13 #include "base/json/json_reader.h" 13 #include "base/json/json_reader.h"
14 #include "base/message_loop.h" 14 #include "base/message_loop.h"
15 #include "base/stl_util.h" 15 #include "base/stl_util.h"
16 #include "base/string_util.h" 16 #include "base/string_util.h"
17 #include "base/time.h" 17 #include "base/time.h"
18 #include "base/utf_string_conversions.h" 18 #include "base/utf_string_conversions.h"
19 #include "base/values.h" 19 #include "base/values.h"
20 #include "content/browser/child_process_security_policy.h" 20 #include "content/browser/child_process_security_policy.h"
21 #include "content/browser/content_frame.h"
21 #include "content/browser/cross_site_request_manager.h" 22 #include "content/browser/cross_site_request_manager.h"
23 #include "content/browser/frame_map.h"
22 #include "content/browser/host_zoom_map.h" 24 #include "content/browser/host_zoom_map.h"
23 #include "content/browser/in_process_webkit/session_storage_namespace.h" 25 #include "content/browser/in_process_webkit/session_storage_namespace.h"
24 #include "content/browser/power_save_blocker.h" 26 #include "content/browser/power_save_blocker.h"
25 #include "content/browser/renderer_host/render_process_host_impl.h" 27 #include "content/browser/renderer_host/render_process_host_impl.h"
26 #include "content/browser/renderer_host/render_view_host_delegate.h" 28 #include "content/browser/renderer_host/render_view_host_delegate.h"
27 #include "content/browser/renderer_host/render_widget_host.h" 29 #include "content/browser/renderer_host/render_widget_host.h"
28 #include "content/browser/renderer_host/render_widget_host_view.h" 30 #include "content/browser/renderer_host/render_widget_host_view.h"
29 #include "content/browser/site_instance.h" 31 #include "content/browser/site_instance.h"
30 #include "content/common/desktop_notification_messages.h" 32 #include "content/common/desktop_notification_messages.h"
31 #include "content/common/drag_messages.h" 33 #include "content/common/drag_messages.h"
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 ClearPowerSaveBlockers(); 156 ClearPowerSaveBlockers();
155 157
156 delegate()->RenderViewDeleted(this); 158 delegate()->RenderViewDeleted(this);
157 159
158 // Be sure to clean up any leftover state from cross-site requests. 160 // Be sure to clean up any leftover state from cross-site requests.
159 CrossSiteRequestManager::GetInstance()->SetHasPendingCrossSiteRequest( 161 CrossSiteRequestManager::GetInstance()->SetHasPendingCrossSiteRequest(
160 process()->GetID(), routing_id(), false); 162 process()->GetID(), routing_id(), false);
161 } 163 }
162 164
163 bool RenderViewHost::CreateRenderView(const string16& frame_name, 165 bool RenderViewHost::CreateRenderView(const string16& frame_name,
166 int opener_route_id,
164 int32 max_page_id) { 167 int32 max_page_id) {
165 DCHECK(!IsRenderViewLive()) << "Creating view twice"; 168 DCHECK(!IsRenderViewLive()) << "Creating view twice";
166 169
167 // The process may (if we're sharing a process with another host that already 170 // The process may (if we're sharing a process with another host that already
168 // initialized it) or may not (we have our own process or the old process 171 // initialized it) or may not (we have our own process or the old process
169 // crashed) have been initialized. Calling Init multiple times will be 172 // crashed) have been initialized. Calling Init multiple times will be
170 // ignored, so this is safe. 173 // ignored, so this is safe.
171 if (!process()->Init(renderer_accessible())) 174 if (!process()->Init(renderer_accessible()))
172 return false; 175 return false;
173 DCHECK(process()->HasConnection()); 176 DCHECK(process()->HasConnection());
(...skipping 11 matching lines...) Expand all
185 next_page_id = max_page_id + 1; 188 next_page_id = max_page_id + 1;
186 189
187 ViewMsg_New_Params params; 190 ViewMsg_New_Params params;
188 params.parent_window = GetNativeViewId(); 191 params.parent_window = GetNativeViewId();
189 params.renderer_preferences = 192 params.renderer_preferences =
190 delegate_->GetRendererPrefs(process()->GetBrowserContext()); 193 delegate_->GetRendererPrefs(process()->GetBrowserContext());
191 params.web_preferences = delegate_->GetWebkitPrefs(); 194 params.web_preferences = delegate_->GetWebkitPrefs();
192 params.view_id = routing_id(); 195 params.view_id = routing_id();
193 params.session_storage_namespace_id = session_storage_namespace_->id(); 196 params.session_storage_namespace_id = session_storage_namespace_->id();
194 params.frame_name = frame_name; 197 params.frame_name = frame_name;
198 params.opener_route_id = opener_route_id;
195 params.next_page_id = next_page_id; 199 params.next_page_id = next_page_id;
196 Send(new ViewMsg_New(params)); 200 Send(new ViewMsg_New(params));
197 201
198 // If it's enabled, tell the renderer to set up the Javascript bindings for 202 // If it's enabled, tell the renderer to set up the Javascript bindings for
199 // sending messages back to the browser. 203 // sending messages back to the browser.
200 Send(new ViewMsg_AllowBindings(routing_id(), enabled_bindings_)); 204 Send(new ViewMsg_AllowBindings(routing_id(), enabled_bindings_));
201 // Let our delegate know that we created a RenderView. 205 // Let our delegate know that we created a RenderView.
202 delegate_->RenderViewCreated(this); 206 delegate_->RenderViewCreated(this);
203 207
204 FOR_EACH_OBSERVER( 208 FOR_EACH_OBSERVER(
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 // handler. 326 // handler.
323 is_waiting_for_beforeunload_ack_ = true; 327 is_waiting_for_beforeunload_ack_ = true;
324 unload_ack_is_for_cross_site_transition_ = for_cross_site_transition; 328 unload_ack_is_for_cross_site_transition_ = for_cross_site_transition;
325 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS)); 329 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS));
326 Send(new ViewMsg_ShouldClose(routing_id())); 330 Send(new ViewMsg_ShouldClose(routing_id()));
327 } 331 }
328 } 332 }
329 333
330 void RenderViewHost::SwapOut(int new_render_process_host_id, 334 void RenderViewHost::SwapOut(int new_render_process_host_id,
331 int new_request_id) { 335 int new_request_id) {
336 content::FrameMap& frame_mapper =
awong 2011/12/21 01:56:07 Should this be a const_ref?
337 process()->GetBrowserContext()->frame_mapper();
338 content::ContentFrame* topLevelFrame =
339 frame_mapper.FindTopLevelFrame(process()->GetID(), routing_id());
340 // TODO(supersat): Sometimes this can be null. Why?
341 DCHECK(topLevelFrame);
jam 2011/12/22 20:06:53 nit: dcheck not needed, will crash below. also top
342
343 SwapOutAndProxy(new_render_process_host_id, new_request_id,
344 topLevelFrame->id());
345 }
346
347 void RenderViewHost::SwapOutAndProxy(int new_render_process_host_id,
348 int new_request_id,
349 int64 content_frame) {
332 // Start filtering IPC messages to avoid confusing the delegate. This will 350 // Start filtering IPC messages to avoid confusing the delegate. This will
333 // prevent any dialogs from appearing during unload handlers, but we've 351 // prevent any dialogs from appearing during unload handlers, but we've
334 // already decided to silence them in crbug.com/68780. We will set it back 352 // already decided to silence them in crbug.com/68780. We will set it back
335 // to false in SetNavigationsSuspended if we swap back in. 353 // to false in SetNavigationsSuspended if we swap back in.
336 is_swapped_out_ = true; 354 is_swapped_out_ = true;
337 355
338 // This will be set back to false in OnSwapOutACK, just before we replace 356 // This will be set back to false in OnSwapOutACK, just before we replace
339 // this RVH with the pending RVH. 357 // this RVH with the pending RVH.
340 is_waiting_for_unload_ack_ = true; 358 is_waiting_for_unload_ack_ = true;
341 // Start the hang monitor in case the renderer hangs in the unload handler. 359 // Start the hang monitor in case the renderer hangs in the unload handler.
342 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS)); 360 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS));
343 361
344 ViewMsg_SwapOut_Params params; 362 ViewMsg_SwapOut_Params params;
345 params.closing_process_id = process()->GetID(); 363 params.closing_process_id = process()->GetID();
346 params.closing_route_id = routing_id(); 364 params.closing_route_id = routing_id();
347 params.new_render_process_host_id = new_render_process_host_id; 365 params.new_render_process_host_id = new_render_process_host_id;
348 params.new_request_id = new_request_id; 366 params.new_request_id = new_request_id;
367 params.content_frame_id = content_frame;
368
349 if (IsRenderViewLive()) { 369 if (IsRenderViewLive()) {
350 Send(new ViewMsg_SwapOut(routing_id(), params)); 370 Send(new ViewMsg_SwapOut(routing_id(), params));
351 } else { 371 } else {
352 // This RenderViewHost doesn't have a live renderer, so just skip the unload 372 // This RenderViewHost doesn't have a live renderer, so just skip the unload
353 // event. We must notify the ResourceDispatcherHost on the IO thread, 373 // event. We must notify the ResourceDispatcherHost on the IO thread,
354 // which we will do through the RenderProcessHost's widget helper. 374 // which we will do through the RenderProcessHost's widget helper.
355 process()->CrossSiteSwapOutACK(params); 375 process()->CrossSiteSwapOutACK(params);
356 } 376 }
357 } 377 }
358 378
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 return true; 793 return true;
774 } 794 }
775 795
776 void RenderViewHost::CreateNewWindow( 796 void RenderViewHost::CreateNewWindow(
777 int route_id, 797 int route_id,
778 const ViewHostMsg_CreateWindow_Params& params) { 798 const ViewHostMsg_CreateWindow_Params& params) {
779 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); 799 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate();
780 if (!view) 800 if (!view)
781 return; 801 return;
782 802
783 view->CreateNewWindow(route_id, params); 803 // Translate the opener_frame_id into a ContentFrame while we still know what
804 // process it was created on.
805
806 content::FrameMap& frame_map =
awong 2011/12/21 01:56:07 const ref?
807 process()->GetBrowserContext()->frame_mapper();
808 content::ContentFrame* opener =
809 frame_map.FindRendererFrame(process()->GetID(), params.opener_frame_id);
810 view->CreateNewWindow(route_id, params, opener);
784 } 811 }
785 812
786 void RenderViewHost::CreateNewWidget(int route_id, 813 void RenderViewHost::CreateNewWidget(int route_id,
787 WebKit::WebPopupType popup_type) { 814 WebKit::WebPopupType popup_type) {
788 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); 815 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate();
789 if (view) 816 if (view)
790 view->CreateNewWidget(route_id, popup_type); 817 view->CreateNewWidget(route_id, popup_type);
791 } 818 }
792 819
793 void RenderViewHost::CreateNewFullscreenWidget(int route_id) { 820 void RenderViewHost::CreateNewFullscreenWidget(int route_id) {
(...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after
1532 1559
1533 void RenderViewHost::OnWebUISend(const GURL& source_url, 1560 void RenderViewHost::OnWebUISend(const GURL& source_url,
1534 const std::string& name, 1561 const std::string& name,
1535 const base::ListValue& args) { 1562 const base::ListValue& args) {
1536 delegate_->WebUISend(this, source_url, name, args); 1563 delegate_->WebUISend(this, source_url, name, args);
1537 } 1564 }
1538 1565
1539 void RenderViewHost::ClearPowerSaveBlockers() { 1566 void RenderViewHost::ClearPowerSaveBlockers() {
1540 STLDeleteValues(&power_save_blockers_); 1567 STLDeleteValues(&power_save_blockers_);
1541 } 1568 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698