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

Side by Side Diff: content/renderer/render_frame_impl.cc

Issue 1046933005: Refactor postMessage for out-of-process iframes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Enable SupportCrossProcessPostMessage test on FYI bots Created 5 years, 8 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/renderer/render_frame_impl.h" 5 #include "content/renderer/render_frame_impl.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 #include "third_party/WebKit/public/platform/WebStorageQuotaCallbacks.h" 117 #include "third_party/WebKit/public/platform/WebStorageQuotaCallbacks.h"
118 #include "third_party/WebKit/public/platform/WebString.h" 118 #include "third_party/WebKit/public/platform/WebString.h"
119 #include "third_party/WebKit/public/platform/WebURL.h" 119 #include "third_party/WebKit/public/platform/WebURL.h"
120 #include "third_party/WebKit/public/platform/WebURLError.h" 120 #include "third_party/WebKit/public/platform/WebURLError.h"
121 #include "third_party/WebKit/public/platform/WebURLResponse.h" 121 #include "third_party/WebKit/public/platform/WebURLResponse.h"
122 #include "third_party/WebKit/public/platform/WebVector.h" 122 #include "third_party/WebKit/public/platform/WebVector.h"
123 #include "third_party/WebKit/public/web/WebColorSuggestion.h" 123 #include "third_party/WebKit/public/web/WebColorSuggestion.h"
124 #include "third_party/WebKit/public/web/WebDocument.h" 124 #include "third_party/WebKit/public/web/WebDocument.h"
125 #include "third_party/WebKit/public/web/WebFrameWidget.h" 125 #include "third_party/WebKit/public/web/WebFrameWidget.h"
126 #include "third_party/WebKit/public/web/WebGlyphCache.h" 126 #include "third_party/WebKit/public/web/WebGlyphCache.h"
127 #include "third_party/WebKit/public/web/WebKit.h"
127 #include "third_party/WebKit/public/web/WebLocalFrame.h" 128 #include "third_party/WebKit/public/web/WebLocalFrame.h"
128 #include "third_party/WebKit/public/web/WebMediaStreamRegistry.h" 129 #include "third_party/WebKit/public/web/WebMediaStreamRegistry.h"
129 #include "third_party/WebKit/public/web/WebNavigationPolicy.h" 130 #include "third_party/WebKit/public/web/WebNavigationPolicy.h"
130 #include "third_party/WebKit/public/web/WebPlugin.h" 131 #include "third_party/WebKit/public/web/WebPlugin.h"
131 #include "third_party/WebKit/public/web/WebPluginParams.h" 132 #include "third_party/WebKit/public/web/WebPluginParams.h"
132 #include "third_party/WebKit/public/web/WebPluginPlaceholder.h" 133 #include "third_party/WebKit/public/web/WebPluginPlaceholder.h"
133 #include "third_party/WebKit/public/web/WebRange.h" 134 #include "third_party/WebKit/public/web/WebRange.h"
134 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" 135 #include "third_party/WebKit/public/web/WebScopedUserGesture.h"
135 #include "third_party/WebKit/public/web/WebScriptSource.h" 136 #include "third_party/WebKit/public/web/WebScriptSource.h"
136 #include "third_party/WebKit/public/web/WebSearchableFormData.h" 137 #include "third_party/WebKit/public/web/WebSearchableFormData.h"
137 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" 138 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
138 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" 139 #include "third_party/WebKit/public/web/WebSecurityPolicy.h"
140 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h"
139 #include "third_party/WebKit/public/web/WebSurroundingText.h" 141 #include "third_party/WebKit/public/web/WebSurroundingText.h"
140 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" 142 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
141 #include "third_party/WebKit/public/web/WebView.h" 143 #include "third_party/WebKit/public/web/WebView.h"
142 #include "third_party/mojo/src/mojo/edk/js/core.h" 144 #include "third_party/mojo/src/mojo/edk/js/core.h"
143 #include "third_party/mojo/src/mojo/edk/js/support.h" 145 #include "third_party/mojo/src/mojo/edk/js/support.h"
144 146
145 #if defined(ENABLE_PLUGINS) 147 #if defined(ENABLE_PLUGINS)
146 #include "content/renderer/npapi/webplugin_impl.h" 148 #include "content/renderer/npapi/webplugin_impl.h"
147 #include "content/renderer/pepper/pepper_browser_connection.h" 149 #include "content/renderer/pepper/pepper_browser_connection.h"
148 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" 150 #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
(...skipping 28 matching lines...) Expand all
177 #include "content/renderer/media/media_renderer_service_provider.h" 179 #include "content/renderer/media/media_renderer_service_provider.h"
178 #include "media/mojo/services/mojo_renderer_factory.h" 180 #include "media/mojo/services/mojo_renderer_factory.h"
179 #else 181 #else
180 #include "media/renderers/default_renderer_factory.h" 182 #include "media/renderers/default_renderer_factory.h"
181 #endif 183 #endif
182 184
183 using blink::WebContextMenuData; 185 using blink::WebContextMenuData;
184 using blink::WebData; 186 using blink::WebData;
185 using blink::WebDataSource; 187 using blink::WebDataSource;
186 using blink::WebDocument; 188 using blink::WebDocument;
189 using blink::WebDOMEvent;
190 using blink::WebDOMMessageEvent;
187 using blink::WebElement; 191 using blink::WebElement;
188 using blink::WebExternalPopupMenu; 192 using blink::WebExternalPopupMenu;
189 using blink::WebExternalPopupMenuClient; 193 using blink::WebExternalPopupMenuClient;
190 using blink::WebFrame; 194 using blink::WebFrame;
191 using blink::WebHistoryItem; 195 using blink::WebHistoryItem;
192 using blink::WebHTTPBody; 196 using blink::WebHTTPBody;
193 using blink::WebLocalFrame; 197 using blink::WebLocalFrame;
194 using blink::WebMediaPlayer; 198 using blink::WebMediaPlayer;
195 using blink::WebMediaPlayerClient; 199 using blink::WebMediaPlayerClient;
196 using blink::WebNavigationPolicy; 200 using blink::WebNavigationPolicy;
197 using blink::WebNavigationType; 201 using blink::WebNavigationType;
198 using blink::WebNode; 202 using blink::WebNode;
199 using blink::WebPluginParams; 203 using blink::WebPluginParams;
200 using blink::WebPopupMenuInfo; 204 using blink::WebPopupMenuInfo;
201 using blink::WebRange; 205 using blink::WebRange;
202 using blink::WebReferrerPolicy; 206 using blink::WebReferrerPolicy;
203 using blink::WebScriptSource; 207 using blink::WebScriptSource;
204 using blink::WebSearchableFormData; 208 using blink::WebSearchableFormData;
205 using blink::WebSecurityOrigin; 209 using blink::WebSecurityOrigin;
206 using blink::WebSecurityPolicy; 210 using blink::WebSecurityPolicy;
211 using blink::WebSerializedScriptValue;
207 using blink::WebServiceWorkerProvider; 212 using blink::WebServiceWorkerProvider;
208 using blink::WebStorageQuotaCallbacks; 213 using blink::WebStorageQuotaCallbacks;
209 using blink::WebString; 214 using blink::WebString;
210 using blink::WebURL; 215 using blink::WebURL;
211 using blink::WebURLError; 216 using blink::WebURLError;
212 using blink::WebURLRequest; 217 using blink::WebURLRequest;
213 using blink::WebURLResponse; 218 using blink::WebURLResponse;
214 using blink::WebUserGestureIndicator; 219 using blink::WebUserGestureIndicator;
215 using blink::WebVector; 220 using blink::WebVector;
216 using blink::WebView; 221 using blink::WebView;
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 IPC_MESSAGE_HANDLER(FrameMsg_Reload, OnReload) 1026 IPC_MESSAGE_HANDLER(FrameMsg_Reload, OnReload)
1022 IPC_MESSAGE_HANDLER(FrameMsg_TextSurroundingSelectionRequest, 1027 IPC_MESSAGE_HANDLER(FrameMsg_TextSurroundingSelectionRequest,
1023 OnTextSurroundingSelectionRequest) 1028 OnTextSurroundingSelectionRequest)
1024 IPC_MESSAGE_HANDLER(FrameMsg_AddStyleSheetByURL, 1029 IPC_MESSAGE_HANDLER(FrameMsg_AddStyleSheetByURL,
1025 OnAddStyleSheetByURL) 1030 OnAddStyleSheetByURL)
1026 IPC_MESSAGE_HANDLER(FrameMsg_SetAccessibilityMode, 1031 IPC_MESSAGE_HANDLER(FrameMsg_SetAccessibilityMode,
1027 OnSetAccessibilityMode) 1032 OnSetAccessibilityMode)
1028 IPC_MESSAGE_HANDLER(FrameMsg_DisownOpener, OnDisownOpener) 1033 IPC_MESSAGE_HANDLER(FrameMsg_DisownOpener, OnDisownOpener)
1029 IPC_MESSAGE_HANDLER(FrameMsg_CommitNavigation, OnCommitNavigation) 1034 IPC_MESSAGE_HANDLER(FrameMsg_CommitNavigation, OnCommitNavigation)
1030 IPC_MESSAGE_HANDLER(FrameMsg_DidUpdateSandboxFlags, OnDidUpdateSandboxFlags) 1035 IPC_MESSAGE_HANDLER(FrameMsg_DidUpdateSandboxFlags, OnDidUpdateSandboxFlags)
1036 IPC_MESSAGE_HANDLER(FrameMsg_PostMessageEvent, OnPostMessageEvent)
1031 #if defined(OS_ANDROID) 1037 #if defined(OS_ANDROID)
1032 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItems, OnSelectPopupMenuItems) 1038 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItems, OnSelectPopupMenuItems)
1033 #elif defined(OS_MACOSX) 1039 #elif defined(OS_MACOSX)
1034 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItem, OnSelectPopupMenuItem) 1040 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
1035 IPC_MESSAGE_HANDLER(InputMsg_CopyToFindPboard, OnCopyToFindPboard) 1041 IPC_MESSAGE_HANDLER(InputMsg_CopyToFindPboard, OnCopyToFindPboard)
1036 #endif 1042 #endif
1037 IPC_END_MESSAGE_MAP() 1043 IPC_END_MESSAGE_MAP()
1038 1044
1039 return handled; 1045 return handled;
1040 } 1046 }
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
1546 CHECK(!frame_->parent()); 1552 CHECK(!frame_->parent());
1547 1553
1548 if (frame_->opener()) 1554 if (frame_->opener())
1549 frame_->setOpener(NULL); 1555 frame_->setOpener(NULL);
1550 } 1556 }
1551 1557
1552 void RenderFrameImpl::OnDidUpdateSandboxFlags(SandboxFlags flags) { 1558 void RenderFrameImpl::OnDidUpdateSandboxFlags(SandboxFlags flags) {
1553 frame_->setFrameOwnerSandboxFlags(ContentToWebSandboxFlags(flags)); 1559 frame_->setFrameOwnerSandboxFlags(ContentToWebSandboxFlags(flags));
1554 } 1560 }
1555 1561
1562 void RenderFrameImpl::OnPostMessageEvent(
1563 const FrameMsg_PostMessage_Params& params) {
1564 // Find the source frame if it exists.
1565 WebFrame* source_frame = NULL;
1566 if (params.source_view_routing_id != MSG_ROUTING_NONE) {
1567 // Support a legacy postMessage path for specifying a source RenderView;
1568 // this is currently used when sending messages to Android WebView.
1569 // TODO(alexmos): This path can be removed once crbug.com/473258 is fixed.
1570 RenderViewImpl* source_view =
1571 RenderViewImpl::FromRoutingID(params.source_view_routing_id);
1572 if (source_view)
1573 source_frame = source_view->webview()->mainFrame();
1574 } else if (params.source_routing_id != MSG_ROUTING_NONE) {
1575 RenderFrameProxy* source_proxy =
1576 RenderFrameProxy::FromRoutingID(params.source_routing_id);
1577 if (source_proxy) {
1578 // Currently, navigating a top-level frame cross-process does not swap
1579 // the WebLocalFrame for a WebRemoteFrame in the frame tree, and the
1580 // WebRemoteFrame will not have an associated blink::Frame. If this is
1581 // the case for |source_proxy|, use the corresponding (swapped-out)
1582 // WebLocalFrame instead, so that event.source for this message can be
1583 // set and used properly.
1584 if (source_proxy->IsMainFrameDetachedFromTree())
1585 source_frame = source_proxy->render_view()->webview()->mainFrame();
1586 else
1587 source_frame = source_proxy->web_frame();
1588 }
1589 }
1590
1591 // If the message contained MessagePorts, create the corresponding endpoints.
1592 blink::WebMessagePortChannelArray channels =
1593 WebMessagePortChannelImpl::CreatePorts(
1594 params.message_ports, params.new_routing_ids,
1595 base::MessageLoopProxy::current().get());
1596
1597 WebSerializedScriptValue serialized_script_value;
1598 if (params.is_data_raw_string) {
1599 v8::HandleScope handle_scope(blink::mainThreadIsolate());
1600 v8::Local<v8::Context> context = frame_->mainWorldScriptContext();
1601 v8::Context::Scope context_scope(context);
1602 V8ValueConverterImpl converter;
1603 converter.SetDateAllowed(true);
1604 converter.SetRegExpAllowed(true);
1605 scoped_ptr<base::Value> value(new base::StringValue(params.data));
1606 v8::Handle<v8::Value> result_value = converter.ToV8Value(value.get(),
1607 context);
1608 serialized_script_value = WebSerializedScriptValue::serialize(result_value);
1609 } else {
1610 serialized_script_value = WebSerializedScriptValue::fromString(params.data);
1611 }
1612
1613 // Create an event with the message. The next-to-last parameter to
1614 // initMessageEvent is the last event ID, which is not used with postMessage.
1615 WebDOMEvent event = frame_->document().createEvent("MessageEvent");
1616 WebDOMMessageEvent msg_event = event.to<WebDOMMessageEvent>();
1617 msg_event.initMessageEvent("message",
1618 // |canBubble| and |cancellable| are always false
1619 false, false,
1620 serialized_script_value,
1621 params.source_origin, source_frame, "", channels);
1622
1623 // We must pass in the target_origin to do the security check on this side,
1624 // since it may have changed since the original postMessage call was made.
1625 WebSecurityOrigin target_origin;
1626 if (!params.target_origin.empty()) {
1627 target_origin =
1628 WebSecurityOrigin::createFromString(WebString(params.target_origin));
1629 }
1630 frame_->dispatchMessageEventWithOriginCheck(target_origin, msg_event);
1631 }
1632
1556 #if defined(OS_ANDROID) 1633 #if defined(OS_ANDROID)
1557 void RenderFrameImpl::OnSelectPopupMenuItems( 1634 void RenderFrameImpl::OnSelectPopupMenuItems(
1558 bool canceled, 1635 bool canceled,
1559 const std::vector<int>& selected_indices) { 1636 const std::vector<int>& selected_indices) {
1560 // It is possible to receive more than one of these calls if the user presses 1637 // It is possible to receive more than one of these calls if the user presses
1561 // a select faster than it takes for the show-select-popup IPC message to make 1638 // a select faster than it takes for the show-select-popup IPC message to make
1562 // it to the browser UI thread. Ignore the extra-messages. 1639 // it to the browser UI thread. Ignore the extra-messages.
1563 // TODO(jcivelli): http:/b/5793321 Implement a better fix, as detailed in bug. 1640 // TODO(jcivelli): http:/b/5793321 Implement a better fix, as detailed in bug.
1564 if (!external_popup_menu_) 1641 if (!external_popup_menu_)
1565 return; 1642 return;
(...skipping 1886 matching lines...) Expand 10 before | Expand all | Expand 10 after
3452 return midi_dispatcher_; 3529 return midi_dispatcher_;
3453 } 3530 }
3454 3531
3455 bool RenderFrameImpl::willCheckAndDispatchMessageEvent( 3532 bool RenderFrameImpl::willCheckAndDispatchMessageEvent(
3456 blink::WebLocalFrame* source_frame, 3533 blink::WebLocalFrame* source_frame,
3457 blink::WebFrame* target_frame, 3534 blink::WebFrame* target_frame,
3458 blink::WebSecurityOrigin target_origin, 3535 blink::WebSecurityOrigin target_origin,
3459 blink::WebDOMMessageEvent event) { 3536 blink::WebDOMMessageEvent event) {
3460 DCHECK(!frame_ || frame_ == target_frame); 3537 DCHECK(!frame_ || frame_ == target_frame);
3461 3538
3539 // Currently, a postMessage that targets a cross-process frame can be plumbed
3540 // either through this function or RenderFrameProxy::postMessageEvent. This
3541 // function is used when the target cross-process frame is a top-level frame
3542 // which has been swapped out. In that case, the corresponding WebLocalFrame
3543 // currently remains in the frame tree even in site-per-process mode (see
3544 // OnSwapOut). RenderFrameProxy::postMessageEvent is used in
3545 // --site-per-process mode for all other cases.
3546 //
3547 // TODO(alexmos, nasko): When swapped-out:// disappears, this should be
3548 // cleaned up so that RenderFrameProxy::postMessageEvent is the only path for
3549 // cross-process postMessages.
3462 if (!is_swapped_out_) 3550 if (!is_swapped_out_)
3463 return false; 3551 return false;
3464 3552
3465 ViewMsg_PostMessage_Params params; 3553 CHECK(render_frame_proxy_);
alexmos 2015/04/02 23:17:00 Am I correct in assuming the proxy_ will always ex
Charlie Reis 2015/04/06 16:18:55 I think the only way it could happen is in a befor
alexmos 2015/04/07 18:44:39 Just to summarize what we discussed offline. befo
3466 params.is_data_raw_string = false; 3554 render_frame_proxy_->postMessageEvent(
3467 params.data = event.data().toString(); 3555 source_frame, render_frame_proxy_->web_frame(), target_origin, event);
3468 params.source_origin = event.origin();
3469 if (!target_origin.isNull())
3470 params.target_origin = target_origin.toString();
3471
3472 params.message_ports =
3473 WebMessagePortChannelImpl::ExtractMessagePortIDs(event.releaseChannels());
3474
3475 // Include the routing ID for the source frame (if one exists), which the
3476 // browser process will translate into the routing ID for the equivalent
3477 // frame in the target process.
3478 params.source_routing_id = MSG_ROUTING_NONE;
3479 if (source_frame) {
3480 RenderViewImpl* source_view =
3481 RenderViewImpl::FromWebView(source_frame->view());
3482 if (source_view)
3483 params.source_routing_id = source_view->routing_id();
3484 }
3485
3486 Send(new ViewHostMsg_RouteMessageEvent(render_view_->routing_id_, params));
3487 return true; 3556 return true;
3488 } 3557 }
3489 3558
3490 blink::WebString RenderFrameImpl::userAgentOverride(blink::WebLocalFrame* frame, 3559 blink::WebString RenderFrameImpl::userAgentOverride(blink::WebLocalFrame* frame,
3491 const blink::WebURL& url) { 3560 const blink::WebURL& url) {
3492 DCHECK(!frame_ || frame_ == frame); 3561 DCHECK(!frame_ || frame_ == frame);
3493 std::string user_agent_override_for_url = 3562 std::string user_agent_override_for_url =
3494 GetContentClient()->renderer()->GetUserAgentOverrideForURL(GURL(url)); 3563 GetContentClient()->renderer()->GetUserAgentOverrideForURL(GURL(url));
3495 if (!user_agent_override_for_url.empty()) 3564 if (!user_agent_override_for_url.empty())
3496 return WebString::fromUTF8(user_agent_override_for_url); 3565 return WebString::fromUTF8(user_agent_override_for_url);
(...skipping 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after
4541 4610
4542 #if defined(ENABLE_BROWSER_CDMS) 4611 #if defined(ENABLE_BROWSER_CDMS)
4543 RendererCdmManager* RenderFrameImpl::GetCdmManager() { 4612 RendererCdmManager* RenderFrameImpl::GetCdmManager() {
4544 if (!cdm_manager_) 4613 if (!cdm_manager_)
4545 cdm_manager_ = new RendererCdmManager(this); 4614 cdm_manager_ = new RendererCdmManager(this);
4546 return cdm_manager_; 4615 return cdm_manager_;
4547 } 4616 }
4548 #endif // defined(ENABLE_BROWSER_CDMS) 4617 #endif // defined(ENABLE_BROWSER_CDMS)
4549 4618
4550 } // namespace content 4619 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698