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

Side by Side Diff: content/renderer/render_view_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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_view_impl.h" 5 #include "content/renderer/render_view_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 #include "third_party/WebKit/public/web/WebFileChooserParams.h" 141 #include "third_party/WebKit/public/web/WebFileChooserParams.h"
142 #include "third_party/WebKit/public/web/WebFindOptions.h" 142 #include "third_party/WebKit/public/web/WebFindOptions.h"
143 #include "third_party/WebKit/public/web/WebFormControlElement.h" 143 #include "third_party/WebKit/public/web/WebFormControlElement.h"
144 #include "third_party/WebKit/public/web/WebFormElement.h" 144 #include "third_party/WebKit/public/web/WebFormElement.h"
145 #include "third_party/WebKit/public/web/WebFrame.h" 145 #include "third_party/WebKit/public/web/WebFrame.h"
146 #include "third_party/WebKit/public/web/WebGlyphCache.h" 146 #include "third_party/WebKit/public/web/WebGlyphCache.h"
147 #include "third_party/WebKit/public/web/WebHistoryItem.h" 147 #include "third_party/WebKit/public/web/WebHistoryItem.h"
148 #include "third_party/WebKit/public/web/WebHitTestResult.h" 148 #include "third_party/WebKit/public/web/WebHitTestResult.h"
149 #include "third_party/WebKit/public/web/WebInputElement.h" 149 #include "third_party/WebKit/public/web/WebInputElement.h"
150 #include "third_party/WebKit/public/web/WebInputEvent.h" 150 #include "third_party/WebKit/public/web/WebInputEvent.h"
151 #include "third_party/WebKit/public/web/WebKit.h"
152 #include "third_party/WebKit/public/web/WebLocalFrame.h" 151 #include "third_party/WebKit/public/web/WebLocalFrame.h"
153 #include "third_party/WebKit/public/web/WebMediaPlayerAction.h" 152 #include "third_party/WebKit/public/web/WebMediaPlayerAction.h"
154 #include "third_party/WebKit/public/web/WebNavigationPolicy.h" 153 #include "third_party/WebKit/public/web/WebNavigationPolicy.h"
155 #include "third_party/WebKit/public/web/WebNetworkStateNotifier.h" 154 #include "third_party/WebKit/public/web/WebNetworkStateNotifier.h"
156 #include "third_party/WebKit/public/web/WebNodeList.h" 155 #include "third_party/WebKit/public/web/WebNodeList.h"
157 #include "third_party/WebKit/public/web/WebPageSerializer.h" 156 #include "third_party/WebKit/public/web/WebPageSerializer.h"
158 #include "third_party/WebKit/public/web/WebPlugin.h" 157 #include "third_party/WebKit/public/web/WebPlugin.h"
159 #include "third_party/WebKit/public/web/WebPluginAction.h" 158 #include "third_party/WebKit/public/web/WebPluginAction.h"
160 #include "third_party/WebKit/public/web/WebPluginContainer.h" 159 #include "third_party/WebKit/public/web/WebPluginContainer.h"
161 #include "third_party/WebKit/public/web/WebPluginDocument.h" 160 #include "third_party/WebKit/public/web/WebPluginDocument.h"
162 #include "third_party/WebKit/public/web/WebRange.h" 161 #include "third_party/WebKit/public/web/WebRange.h"
163 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" 162 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
164 #include "third_party/WebKit/public/web/WebScriptSource.h" 163 #include "third_party/WebKit/public/web/WebScriptSource.h"
165 #include "third_party/WebKit/public/web/WebSearchableFormData.h" 164 #include "third_party/WebKit/public/web/WebSearchableFormData.h"
166 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" 165 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
167 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" 166 #include "third_party/WebKit/public/web/WebSecurityPolicy.h"
168 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h"
169 #include "third_party/WebKit/public/web/WebSettings.h" 167 #include "third_party/WebKit/public/web/WebSettings.h"
170 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" 168 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
171 #include "third_party/WebKit/public/web/WebView.h" 169 #include "third_party/WebKit/public/web/WebView.h"
172 #include "third_party/WebKit/public/web/WebWindowFeatures.h" 170 #include "third_party/WebKit/public/web/WebWindowFeatures.h"
173 #include "third_party/WebKit/public/web/default/WebRenderTheme.h" 171 #include "third_party/WebKit/public/web/default/WebRenderTheme.h"
174 #include "third_party/icu/source/common/unicode/uchar.h" 172 #include "third_party/icu/source/common/unicode/uchar.h"
175 #include "third_party/icu/source/common/unicode/uscript.h" 173 #include "third_party/icu/source/common/unicode/uscript.h"
176 #include "ui/base/clipboard/clipboard.h" 174 #include "ui/base/clipboard/clipboard.h"
177 #include "ui/base/ui_base_switches_util.h" 175 #include "ui/base/ui_base_switches_util.h"
178 #include "ui/events/latency_info.h" 176 #include "ui/events/latency_info.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 using blink::WebAXObject; 217 using blink::WebAXObject;
220 using blink::WebApplicationCacheHost; 218 using blink::WebApplicationCacheHost;
221 using blink::WebApplicationCacheHostClient; 219 using blink::WebApplicationCacheHostClient;
222 using blink::WebCString; 220 using blink::WebCString;
223 using blink::WebColor; 221 using blink::WebColor;
224 using blink::WebColorName; 222 using blink::WebColorName;
225 using blink::WebConsoleMessage; 223 using blink::WebConsoleMessage;
226 using blink::WebData; 224 using blink::WebData;
227 using blink::WebDataSource; 225 using blink::WebDataSource;
228 using blink::WebDocument; 226 using blink::WebDocument;
229 using blink::WebDOMEvent;
230 using blink::WebDOMMessageEvent;
231 using blink::WebDragData; 227 using blink::WebDragData;
232 using blink::WebDragOperation; 228 using blink::WebDragOperation;
233 using blink::WebDragOperationsMask; 229 using blink::WebDragOperationsMask;
234 using blink::WebElement; 230 using blink::WebElement;
235 using blink::WebFileChooserCompletion; 231 using blink::WebFileChooserCompletion;
236 using blink::WebFindOptions; 232 using blink::WebFindOptions;
237 using blink::WebFormControlElement; 233 using blink::WebFormControlElement;
238 using blink::WebFormElement; 234 using blink::WebFormElement;
239 using blink::WebFrame; 235 using blink::WebFrame;
240 using blink::WebGestureEvent; 236 using blink::WebGestureEvent;
(...skipping 19 matching lines...) Expand all
260 using blink::WebPluginContainer; 256 using blink::WebPluginContainer;
261 using blink::WebPluginDocument; 257 using blink::WebPluginDocument;
262 using blink::WebPoint; 258 using blink::WebPoint;
263 using blink::WebRange; 259 using blink::WebRange;
264 using blink::WebRect; 260 using blink::WebRect;
265 using blink::WebReferrerPolicy; 261 using blink::WebReferrerPolicy;
266 using blink::WebScriptSource; 262 using blink::WebScriptSource;
267 using blink::WebSearchableFormData; 263 using blink::WebSearchableFormData;
268 using blink::WebSecurityOrigin; 264 using blink::WebSecurityOrigin;
269 using blink::WebSecurityPolicy; 265 using blink::WebSecurityPolicy;
270 using blink::WebSerializedScriptValue;
271 using blink::WebSettings; 266 using blink::WebSettings;
272 using blink::WebSize; 267 using blink::WebSize;
273 using blink::WebStorageNamespace; 268 using blink::WebStorageNamespace;
274 using blink::WebStorageQuotaCallbacks; 269 using blink::WebStorageQuotaCallbacks;
275 using blink::WebStorageQuotaError; 270 using blink::WebStorageQuotaError;
276 using blink::WebStorageQuotaType; 271 using blink::WebStorageQuotaType;
277 using blink::WebString; 272 using blink::WebString;
278 using blink::WebTextAffinity; 273 using blink::WebTextAffinity;
279 using blink::WebTextDirection; 274 using blink::WebTextDirection;
280 using blink::WebTouchEvent; 275 using blink::WebTouchEvent;
(...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after
1282 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding) 1277 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
1283 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageScale, OnResetPageScale) 1278 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageScale, OnResetPageScale)
1284 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) 1279 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
1285 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL, 1280 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
1286 OnSetZoomLevelForLoadingURL) 1281 OnSetZoomLevelForLoadingURL)
1287 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForView, 1282 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForView,
1288 OnSetZoomLevelForView) 1283 OnSetZoomLevelForView)
1289 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding) 1284 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
1290 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault, 1285 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
1291 OnResetPageEncodingToDefault) 1286 OnResetPageEncodingToDefault)
1292 IPC_MESSAGE_HANDLER(ViewMsg_PostMessageEvent, OnPostMessageEvent)
1293 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter) 1287 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
1294 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver) 1288 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
1295 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave) 1289 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
1296 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop) 1290 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
1297 IPC_MESSAGE_HANDLER(DragMsg_SourceEnded, OnDragSourceEnded) 1291 IPC_MESSAGE_HANDLER(DragMsg_SourceEnded, OnDragSourceEnded)
1298 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded, 1292 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
1299 OnDragSourceSystemDragEnded) 1293 OnDragSourceSystemDragEnded)
1300 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings) 1294 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
1301 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus) 1295 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
1302 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck) 1296 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
(...skipping 1383 matching lines...) Expand 10 before | Expand all | Expand 10 after
2686 2680
2687 void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) { 2681 void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) {
2688 webview()->setPageEncoding(WebString::fromUTF8(encoding_name)); 2682 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
2689 } 2683 }
2690 2684
2691 void RenderViewImpl::OnResetPageEncodingToDefault() { 2685 void RenderViewImpl::OnResetPageEncodingToDefault() {
2692 WebString no_encoding; 2686 WebString no_encoding;
2693 webview()->setPageEncoding(no_encoding); 2687 webview()->setPageEncoding(no_encoding);
2694 } 2688 }
2695 2689
2696 void RenderViewImpl::OnPostMessageEvent(
2697 const ViewMsg_PostMessage_Params& params) {
2698 // TODO(nasko): Support sending to subframes.
2699 WebFrame* frame = webview()->mainFrame();
2700
2701 // Find the source frame if it exists.
2702 WebFrame* source_frame = NULL;
2703 if (params.source_routing_id != MSG_ROUTING_NONE) {
2704 RenderViewImpl* source_view = FromRoutingID(params.source_routing_id);
2705 if (source_view)
2706 source_frame = source_view->webview()->mainFrame();
2707 }
2708
2709 // If the message contained MessagePorts, create the corresponding endpoints.
2710 blink::WebMessagePortChannelArray channels =
2711 WebMessagePortChannelImpl::CreatePorts(
2712 params.message_ports, params.new_routing_ids,
2713 base::MessageLoopProxy::current().get());
2714
2715 WebSerializedScriptValue serialized_script_value;
2716 if (params.is_data_raw_string) {
2717 v8::HandleScope handle_scope(blink::mainThreadIsolate());
2718 v8::Local<v8::Context> context = frame->mainWorldScriptContext();
2719 v8::Context::Scope context_scope(context);
2720 V8ValueConverterImpl converter;
2721 converter.SetDateAllowed(true);
2722 converter.SetRegExpAllowed(true);
2723 scoped_ptr<base::Value> value(new base::StringValue(params.data));
2724 v8::Handle<v8::Value> result_value = converter.ToV8Value(value.get(),
2725 context);
2726 serialized_script_value = WebSerializedScriptValue::serialize(result_value);
2727 } else {
2728 serialized_script_value = WebSerializedScriptValue::fromString(params.data);
2729 }
2730
2731 // Create an event with the message. The final parameter to initMessageEvent
2732 // is the last event ID, which is not used with postMessage.
2733 WebDOMEvent event = frame->document().createEvent("MessageEvent");
2734 WebDOMMessageEvent msg_event = event.to<WebDOMMessageEvent>();
2735 msg_event.initMessageEvent("message",
2736 // |canBubble| and |cancellable| are always false
2737 false, false,
2738 serialized_script_value,
2739 params.source_origin, source_frame, "", channels);
2740
2741 // We must pass in the target_origin to do the security check on this side,
2742 // since it may have changed since the original postMessage call was made.
2743 WebSecurityOrigin target_origin;
2744 if (!params.target_origin.empty()) {
2745 target_origin =
2746 WebSecurityOrigin::createFromString(WebString(params.target_origin));
2747 }
2748 frame->dispatchMessageEventWithOriginCheck(target_origin, msg_event);
2749 }
2750
2751 void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) { 2690 void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) {
2752 if ((enabled_bindings_flags & BINDINGS_POLICY_WEB_UI) && 2691 if ((enabled_bindings_flags & BINDINGS_POLICY_WEB_UI) &&
2753 !(enabled_bindings_ & BINDINGS_POLICY_WEB_UI)) { 2692 !(enabled_bindings_ & BINDINGS_POLICY_WEB_UI)) {
2754 // WebUIExtensionData deletes itself when we're destroyed. 2693 // WebUIExtensionData deletes itself when we're destroyed.
2755 new WebUIExtensionData(this); 2694 new WebUIExtensionData(this);
2756 // WebUIMojo deletes itself when we're destroyed. 2695 // WebUIMojo deletes itself when we're destroyed.
2757 new WebUIMojo(this); 2696 new WebUIMojo(this);
2758 } 2697 }
2759 2698
2760 enabled_bindings_ |= enabled_bindings_flags; 2699 enabled_bindings_ |= enabled_bindings_flags;
(...skipping 1202 matching lines...) Expand 10 before | Expand all | Expand 10 after
3963 std::vector<gfx::Size> sizes; 3902 std::vector<gfx::Size> sizes;
3964 ConvertToFaviconSizes(icon_urls[i].sizes(), &sizes); 3903 ConvertToFaviconSizes(icon_urls[i].sizes(), &sizes);
3965 if (!url.isEmpty()) 3904 if (!url.isEmpty())
3966 urls.push_back( 3905 urls.push_back(
3967 FaviconURL(url, ToFaviconType(icon_urls[i].iconType()), sizes)); 3906 FaviconURL(url, ToFaviconType(icon_urls[i].iconType()), sizes));
3968 } 3907 }
3969 SendUpdateFaviconURL(urls); 3908 SendUpdateFaviconURL(urls);
3970 } 3909 }
3971 3910
3972 } // namespace content 3911 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698