OLD | NEW |
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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 #include "third_party/WebKit/public/platform/WebStorageQuotaCallbacks.h" | 118 #include "third_party/WebKit/public/platform/WebStorageQuotaCallbacks.h" |
119 #include "third_party/WebKit/public/platform/WebString.h" | 119 #include "third_party/WebKit/public/platform/WebString.h" |
120 #include "third_party/WebKit/public/platform/WebURL.h" | 120 #include "third_party/WebKit/public/platform/WebURL.h" |
121 #include "third_party/WebKit/public/platform/WebURLError.h" | 121 #include "third_party/WebKit/public/platform/WebURLError.h" |
122 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 122 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
123 #include "third_party/WebKit/public/platform/WebVector.h" | 123 #include "third_party/WebKit/public/platform/WebVector.h" |
124 #include "third_party/WebKit/public/web/WebColorSuggestion.h" | 124 #include "third_party/WebKit/public/web/WebColorSuggestion.h" |
125 #include "third_party/WebKit/public/web/WebDocument.h" | 125 #include "third_party/WebKit/public/web/WebDocument.h" |
126 #include "third_party/WebKit/public/web/WebFrameWidget.h" | 126 #include "third_party/WebKit/public/web/WebFrameWidget.h" |
127 #include "third_party/WebKit/public/web/WebGlyphCache.h" | 127 #include "third_party/WebKit/public/web/WebGlyphCache.h" |
| 128 #include "third_party/WebKit/public/web/WebKit.h" |
128 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 129 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
129 #include "third_party/WebKit/public/web/WebMediaStreamRegistry.h" | 130 #include "third_party/WebKit/public/web/WebMediaStreamRegistry.h" |
130 #include "third_party/WebKit/public/web/WebNavigationPolicy.h" | 131 #include "third_party/WebKit/public/web/WebNavigationPolicy.h" |
131 #include "third_party/WebKit/public/web/WebPlugin.h" | 132 #include "third_party/WebKit/public/web/WebPlugin.h" |
132 #include "third_party/WebKit/public/web/WebPluginParams.h" | 133 #include "third_party/WebKit/public/web/WebPluginParams.h" |
133 #include "third_party/WebKit/public/web/WebPluginPlaceholder.h" | 134 #include "third_party/WebKit/public/web/WebPluginPlaceholder.h" |
134 #include "third_party/WebKit/public/web/WebRange.h" | 135 #include "third_party/WebKit/public/web/WebRange.h" |
135 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" | 136 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" |
136 #include "third_party/WebKit/public/web/WebScriptSource.h" | 137 #include "third_party/WebKit/public/web/WebScriptSource.h" |
137 #include "third_party/WebKit/public/web/WebSearchableFormData.h" | 138 #include "third_party/WebKit/public/web/WebSearchableFormData.h" |
138 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 139 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
139 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" | 140 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" |
| 141 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h" |
140 #include "third_party/WebKit/public/web/WebSettings.h" | 142 #include "third_party/WebKit/public/web/WebSettings.h" |
141 #include "third_party/WebKit/public/web/WebSurroundingText.h" | 143 #include "third_party/WebKit/public/web/WebSurroundingText.h" |
142 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | 144 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
143 #include "third_party/WebKit/public/web/WebView.h" | 145 #include "third_party/WebKit/public/web/WebView.h" |
144 #include "third_party/mojo/src/mojo/edk/js/core.h" | 146 #include "third_party/mojo/src/mojo/edk/js/core.h" |
145 #include "third_party/mojo/src/mojo/edk/js/support.h" | 147 #include "third_party/mojo/src/mojo/edk/js/support.h" |
146 | 148 |
147 #if defined(ENABLE_PLUGINS) | 149 #if defined(ENABLE_PLUGINS) |
148 #include "content/renderer/npapi/webplugin_impl.h" | 150 #include "content/renderer/npapi/webplugin_impl.h" |
149 #include "content/renderer/pepper/pepper_browser_connection.h" | 151 #include "content/renderer/pepper/pepper_browser_connection.h" |
(...skipping 29 matching lines...) Expand all Loading... |
179 #include "content/renderer/media/media_renderer_service_provider.h" | 181 #include "content/renderer/media/media_renderer_service_provider.h" |
180 #include "media/mojo/services/mojo_renderer_factory.h" | 182 #include "media/mojo/services/mojo_renderer_factory.h" |
181 #else | 183 #else |
182 #include "media/renderers/default_renderer_factory.h" | 184 #include "media/renderers/default_renderer_factory.h" |
183 #endif | 185 #endif |
184 | 186 |
185 using blink::WebContextMenuData; | 187 using blink::WebContextMenuData; |
186 using blink::WebData; | 188 using blink::WebData; |
187 using blink::WebDataSource; | 189 using blink::WebDataSource; |
188 using blink::WebDocument; | 190 using blink::WebDocument; |
| 191 using blink::WebDOMEvent; |
| 192 using blink::WebDOMMessageEvent; |
189 using blink::WebElement; | 193 using blink::WebElement; |
190 using blink::WebExternalPopupMenu; | 194 using blink::WebExternalPopupMenu; |
191 using blink::WebExternalPopupMenuClient; | 195 using blink::WebExternalPopupMenuClient; |
192 using blink::WebFrame; | 196 using blink::WebFrame; |
193 using blink::WebHistoryItem; | 197 using blink::WebHistoryItem; |
194 using blink::WebHTTPBody; | 198 using blink::WebHTTPBody; |
195 using blink::WebLocalFrame; | 199 using blink::WebLocalFrame; |
196 using blink::WebMediaPlayer; | 200 using blink::WebMediaPlayer; |
197 using blink::WebMediaPlayerClient; | 201 using blink::WebMediaPlayerClient; |
198 using blink::WebNavigationPolicy; | 202 using blink::WebNavigationPolicy; |
199 using blink::WebNavigationType; | 203 using blink::WebNavigationType; |
200 using blink::WebNode; | 204 using blink::WebNode; |
201 using blink::WebPluginParams; | 205 using blink::WebPluginParams; |
202 using blink::WebPopupMenuInfo; | 206 using blink::WebPopupMenuInfo; |
203 using blink::WebRange; | 207 using blink::WebRange; |
204 using blink::WebReferrerPolicy; | 208 using blink::WebReferrerPolicy; |
205 using blink::WebScriptSource; | 209 using blink::WebScriptSource; |
206 using blink::WebSearchableFormData; | 210 using blink::WebSearchableFormData; |
207 using blink::WebSecurityOrigin; | 211 using blink::WebSecurityOrigin; |
208 using blink::WebSecurityPolicy; | 212 using blink::WebSecurityPolicy; |
| 213 using blink::WebSerializedScriptValue; |
209 using blink::WebServiceWorkerProvider; | 214 using blink::WebServiceWorkerProvider; |
210 using blink::WebStorageQuotaCallbacks; | 215 using blink::WebStorageQuotaCallbacks; |
211 using blink::WebString; | 216 using blink::WebString; |
212 using blink::WebURL; | 217 using blink::WebURL; |
213 using blink::WebURLError; | 218 using blink::WebURLError; |
214 using blink::WebURLRequest; | 219 using blink::WebURLRequest; |
215 using blink::WebURLResponse; | 220 using blink::WebURLResponse; |
216 using blink::WebUserGestureIndicator; | 221 using blink::WebUserGestureIndicator; |
217 using blink::WebVector; | 222 using blink::WebVector; |
218 using blink::WebView; | 223 using blink::WebView; |
(...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1042 OnTextSurroundingSelectionRequest) | 1047 OnTextSurroundingSelectionRequest) |
1043 IPC_MESSAGE_HANDLER(FrameMsg_AddStyleSheetByURL, | 1048 IPC_MESSAGE_HANDLER(FrameMsg_AddStyleSheetByURL, |
1044 OnAddStyleSheetByURL) | 1049 OnAddStyleSheetByURL) |
1045 IPC_MESSAGE_HANDLER(FrameMsg_SetAccessibilityMode, | 1050 IPC_MESSAGE_HANDLER(FrameMsg_SetAccessibilityMode, |
1046 OnSetAccessibilityMode) | 1051 OnSetAccessibilityMode) |
1047 IPC_MESSAGE_HANDLER(FrameMsg_DisownOpener, OnDisownOpener) | 1052 IPC_MESSAGE_HANDLER(FrameMsg_DisownOpener, OnDisownOpener) |
1048 IPC_MESSAGE_HANDLER(FrameMsg_CommitNavigation, OnCommitNavigation) | 1053 IPC_MESSAGE_HANDLER(FrameMsg_CommitNavigation, OnCommitNavigation) |
1049 IPC_MESSAGE_HANDLER(FrameMsg_DidUpdateSandboxFlags, OnDidUpdateSandboxFlags) | 1054 IPC_MESSAGE_HANDLER(FrameMsg_DidUpdateSandboxFlags, OnDidUpdateSandboxFlags) |
1050 IPC_MESSAGE_HANDLER(FrameMsg_SetTextTrackSettings, | 1055 IPC_MESSAGE_HANDLER(FrameMsg_SetTextTrackSettings, |
1051 OnTextTrackSettingsChanged) | 1056 OnTextTrackSettingsChanged) |
| 1057 IPC_MESSAGE_HANDLER(FrameMsg_PostMessageEvent, OnPostMessageEvent) |
1052 #if defined(OS_ANDROID) | 1058 #if defined(OS_ANDROID) |
1053 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItems, OnSelectPopupMenuItems) | 1059 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItems, OnSelectPopupMenuItems) |
1054 #elif defined(OS_MACOSX) | 1060 #elif defined(OS_MACOSX) |
1055 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItem, OnSelectPopupMenuItem) | 1061 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItem, OnSelectPopupMenuItem) |
1056 IPC_MESSAGE_HANDLER(InputMsg_CopyToFindPboard, OnCopyToFindPboard) | 1062 IPC_MESSAGE_HANDLER(InputMsg_CopyToFindPboard, OnCopyToFindPboard) |
1057 #endif | 1063 #endif |
1058 IPC_END_MESSAGE_MAP() | 1064 IPC_END_MESSAGE_MAP() |
1059 | 1065 |
1060 return handled; | 1066 return handled; |
1061 } | 1067 } |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1595 render_view_->webview()->settings()->setTextTrackFontVariant( | 1601 render_view_->webview()->settings()->setTextTrackFontVariant( |
1596 WebString::fromUTF8(params.text_track_font_variant)); | 1602 WebString::fromUTF8(params.text_track_font_variant)); |
1597 render_view_->webview()->settings()->setTextTrackTextColor( | 1603 render_view_->webview()->settings()->setTextTrackTextColor( |
1598 WebString::fromUTF8(params.text_track_text_color)); | 1604 WebString::fromUTF8(params.text_track_text_color)); |
1599 render_view_->webview()->settings()->setTextTrackTextShadow( | 1605 render_view_->webview()->settings()->setTextTrackTextShadow( |
1600 WebString::fromUTF8(params.text_track_text_shadow)); | 1606 WebString::fromUTF8(params.text_track_text_shadow)); |
1601 render_view_->webview()->settings()->setTextTrackTextSize( | 1607 render_view_->webview()->settings()->setTextTrackTextSize( |
1602 WebString::fromUTF8(params.text_track_text_size)); | 1608 WebString::fromUTF8(params.text_track_text_size)); |
1603 } | 1609 } |
1604 | 1610 |
| 1611 void RenderFrameImpl::OnPostMessageEvent( |
| 1612 const FrameMsg_PostMessage_Params& params) { |
| 1613 // Find the source frame if it exists. |
| 1614 WebFrame* source_frame = NULL; |
| 1615 if (params.source_view_routing_id != MSG_ROUTING_NONE) { |
| 1616 // Support a legacy postMessage path for specifying a source RenderView; |
| 1617 // this is currently used when sending messages to Android WebView. |
| 1618 // TODO(alexmos): This path can be removed once crbug.com/473258 is fixed. |
| 1619 RenderViewImpl* source_view = |
| 1620 RenderViewImpl::FromRoutingID(params.source_view_routing_id); |
| 1621 if (source_view) |
| 1622 source_frame = source_view->webview()->mainFrame(); |
| 1623 } else if (params.source_routing_id != MSG_ROUTING_NONE) { |
| 1624 RenderFrameProxy* source_proxy = |
| 1625 RenderFrameProxy::FromRoutingID(params.source_routing_id); |
| 1626 if (source_proxy) { |
| 1627 // Currently, navigating a top-level frame cross-process does not swap |
| 1628 // the WebLocalFrame for a WebRemoteFrame in the frame tree, and the |
| 1629 // WebRemoteFrame will not have an associated blink::Frame. If this is |
| 1630 // the case for |source_proxy|, use the corresponding (swapped-out) |
| 1631 // WebLocalFrame instead, so that event.source for this message can be |
| 1632 // set and used properly. |
| 1633 if (source_proxy->IsMainFrameDetachedFromTree()) |
| 1634 source_frame = source_proxy->render_view()->webview()->mainFrame(); |
| 1635 else |
| 1636 source_frame = source_proxy->web_frame(); |
| 1637 } |
| 1638 } |
| 1639 |
| 1640 // If the message contained MessagePorts, create the corresponding endpoints. |
| 1641 blink::WebMessagePortChannelArray channels = |
| 1642 WebMessagePortChannelImpl::CreatePorts( |
| 1643 params.message_ports, params.new_routing_ids, |
| 1644 base::MessageLoopProxy::current().get()); |
| 1645 |
| 1646 WebSerializedScriptValue serialized_script_value; |
| 1647 if (params.is_data_raw_string) { |
| 1648 v8::HandleScope handle_scope(blink::mainThreadIsolate()); |
| 1649 v8::Local<v8::Context> context = frame_->mainWorldScriptContext(); |
| 1650 v8::Context::Scope context_scope(context); |
| 1651 V8ValueConverterImpl converter; |
| 1652 converter.SetDateAllowed(true); |
| 1653 converter.SetRegExpAllowed(true); |
| 1654 scoped_ptr<base::Value> value(new base::StringValue(params.data)); |
| 1655 v8::Handle<v8::Value> result_value = converter.ToV8Value(value.get(), |
| 1656 context); |
| 1657 serialized_script_value = WebSerializedScriptValue::serialize(result_value); |
| 1658 } else { |
| 1659 serialized_script_value = WebSerializedScriptValue::fromString(params.data); |
| 1660 } |
| 1661 |
| 1662 // Create an event with the message. The next-to-last parameter to |
| 1663 // initMessageEvent is the last event ID, which is not used with postMessage. |
| 1664 WebDOMEvent event = frame_->document().createEvent("MessageEvent"); |
| 1665 WebDOMMessageEvent msg_event = event.to<WebDOMMessageEvent>(); |
| 1666 msg_event.initMessageEvent("message", |
| 1667 // |canBubble| and |cancellable| are always false |
| 1668 false, false, |
| 1669 serialized_script_value, |
| 1670 params.source_origin, source_frame, "", channels); |
| 1671 |
| 1672 // We must pass in the target_origin to do the security check on this side, |
| 1673 // since it may have changed since the original postMessage call was made. |
| 1674 WebSecurityOrigin target_origin; |
| 1675 if (!params.target_origin.empty()) { |
| 1676 target_origin = |
| 1677 WebSecurityOrigin::createFromString(WebString(params.target_origin)); |
| 1678 } |
| 1679 frame_->dispatchMessageEventWithOriginCheck(target_origin, msg_event); |
| 1680 } |
| 1681 |
1605 #if defined(OS_ANDROID) | 1682 #if defined(OS_ANDROID) |
1606 void RenderFrameImpl::OnSelectPopupMenuItems( | 1683 void RenderFrameImpl::OnSelectPopupMenuItems( |
1607 bool canceled, | 1684 bool canceled, |
1608 const std::vector<int>& selected_indices) { | 1685 const std::vector<int>& selected_indices) { |
1609 // It is possible to receive more than one of these calls if the user presses | 1686 // It is possible to receive more than one of these calls if the user presses |
1610 // a select faster than it takes for the show-select-popup IPC message to make | 1687 // a select faster than it takes for the show-select-popup IPC message to make |
1611 // it to the browser UI thread. Ignore the extra-messages. | 1688 // it to the browser UI thread. Ignore the extra-messages. |
1612 // TODO(jcivelli): http:/b/5793321 Implement a better fix, as detailed in bug. | 1689 // TODO(jcivelli): http:/b/5793321 Implement a better fix, as detailed in bug. |
1613 if (!external_popup_menu_) | 1690 if (!external_popup_menu_) |
1614 return; | 1691 return; |
(...skipping 1949 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3564 return midi_dispatcher_; | 3641 return midi_dispatcher_; |
3565 } | 3642 } |
3566 | 3643 |
3567 bool RenderFrameImpl::willCheckAndDispatchMessageEvent( | 3644 bool RenderFrameImpl::willCheckAndDispatchMessageEvent( |
3568 blink::WebLocalFrame* source_frame, | 3645 blink::WebLocalFrame* source_frame, |
3569 blink::WebFrame* target_frame, | 3646 blink::WebFrame* target_frame, |
3570 blink::WebSecurityOrigin target_origin, | 3647 blink::WebSecurityOrigin target_origin, |
3571 blink::WebDOMMessageEvent event) { | 3648 blink::WebDOMMessageEvent event) { |
3572 DCHECK(!frame_ || frame_ == target_frame); | 3649 DCHECK(!frame_ || frame_ == target_frame); |
3573 | 3650 |
| 3651 // Currently, a postMessage that targets a cross-process frame can be plumbed |
| 3652 // either through this function or RenderFrameProxy::postMessageEvent. This |
| 3653 // function is used when the target cross-process frame is a top-level frame |
| 3654 // which has been swapped out. In that case, the corresponding WebLocalFrame |
| 3655 // currently remains in the frame tree even in site-per-process mode (see |
| 3656 // OnSwapOut). RenderFrameProxy::postMessageEvent is used in |
| 3657 // --site-per-process mode for all other cases. |
| 3658 // |
| 3659 // TODO(alexmos, nasko): When swapped-out:// disappears, this should be |
| 3660 // cleaned up so that RenderFrameProxy::postMessageEvent is the only path for |
| 3661 // cross-process postMessages. |
3574 if (!is_swapped_out_) | 3662 if (!is_swapped_out_) |
3575 return false; | 3663 return false; |
3576 | 3664 |
3577 ViewMsg_PostMessage_Params params; | 3665 CHECK(render_frame_proxy_); |
3578 params.is_data_raw_string = false; | 3666 render_frame_proxy_->postMessageEvent( |
3579 params.data = event.data().toString(); | 3667 source_frame, render_frame_proxy_->web_frame(), target_origin, event); |
3580 params.source_origin = event.origin(); | |
3581 if (!target_origin.isNull()) | |
3582 params.target_origin = target_origin.toString(); | |
3583 | |
3584 params.message_ports = | |
3585 WebMessagePortChannelImpl::ExtractMessagePortIDs(event.releaseChannels()); | |
3586 | |
3587 // Include the routing ID for the source frame (if one exists), which the | |
3588 // browser process will translate into the routing ID for the equivalent | |
3589 // frame in the target process. | |
3590 params.source_routing_id = MSG_ROUTING_NONE; | |
3591 if (source_frame) { | |
3592 RenderViewImpl* source_view = | |
3593 RenderViewImpl::FromWebView(source_frame->view()); | |
3594 if (source_view) | |
3595 params.source_routing_id = source_view->routing_id(); | |
3596 } | |
3597 | |
3598 Send(new ViewHostMsg_RouteMessageEvent(render_view_->routing_id_, params)); | |
3599 return true; | 3668 return true; |
3600 } | 3669 } |
3601 | 3670 |
3602 blink::WebString RenderFrameImpl::userAgentOverride(blink::WebLocalFrame* frame, | 3671 blink::WebString RenderFrameImpl::userAgentOverride(blink::WebLocalFrame* frame, |
3603 const blink::WebURL& url) { | 3672 const blink::WebURL& url) { |
3604 DCHECK(!frame_ || frame_ == frame); | 3673 DCHECK(!frame_ || frame_ == frame); |
3605 std::string user_agent_override_for_url = | 3674 std::string user_agent_override_for_url = |
3606 GetContentClient()->renderer()->GetUserAgentOverrideForURL(GURL(url)); | 3675 GetContentClient()->renderer()->GetUserAgentOverrideForURL(GURL(url)); |
3607 if (!user_agent_override_for_url.empty()) | 3676 if (!user_agent_override_for_url.empty()) |
3608 return WebString::fromUTF8(user_agent_override_for_url); | 3677 return WebString::fromUTF8(user_agent_override_for_url); |
(...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4701 #elif defined(ENABLE_BROWSER_CDMS) | 4770 #elif defined(ENABLE_BROWSER_CDMS) |
4702 cdm_manager_, | 4771 cdm_manager_, |
4703 #endif | 4772 #endif |
4704 this); | 4773 this); |
4705 } | 4774 } |
4706 | 4775 |
4707 return cdm_factory_; | 4776 return cdm_factory_; |
4708 } | 4777 } |
4709 | 4778 |
4710 } // namespace content | 4779 } // namespace content |
OLD | NEW |