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

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: Charlie's nits 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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 #include "third_party/WebKit/public/web/WebFileChooserParams.h" 140 #include "third_party/WebKit/public/web/WebFileChooserParams.h"
141 #include "third_party/WebKit/public/web/WebFindOptions.h" 141 #include "third_party/WebKit/public/web/WebFindOptions.h"
142 #include "third_party/WebKit/public/web/WebFormControlElement.h" 142 #include "third_party/WebKit/public/web/WebFormControlElement.h"
143 #include "third_party/WebKit/public/web/WebFormElement.h" 143 #include "third_party/WebKit/public/web/WebFormElement.h"
144 #include "third_party/WebKit/public/web/WebFrame.h" 144 #include "third_party/WebKit/public/web/WebFrame.h"
145 #include "third_party/WebKit/public/web/WebGlyphCache.h" 145 #include "third_party/WebKit/public/web/WebGlyphCache.h"
146 #include "third_party/WebKit/public/web/WebHistoryItem.h" 146 #include "third_party/WebKit/public/web/WebHistoryItem.h"
147 #include "third_party/WebKit/public/web/WebHitTestResult.h" 147 #include "third_party/WebKit/public/web/WebHitTestResult.h"
148 #include "third_party/WebKit/public/web/WebInputElement.h" 148 #include "third_party/WebKit/public/web/WebInputElement.h"
149 #include "third_party/WebKit/public/web/WebInputEvent.h" 149 #include "third_party/WebKit/public/web/WebInputEvent.h"
150 #include "third_party/WebKit/public/web/WebKit.h"
151 #include "third_party/WebKit/public/web/WebLocalFrame.h" 150 #include "third_party/WebKit/public/web/WebLocalFrame.h"
152 #include "third_party/WebKit/public/web/WebMediaPlayerAction.h" 151 #include "third_party/WebKit/public/web/WebMediaPlayerAction.h"
153 #include "third_party/WebKit/public/web/WebNavigationPolicy.h" 152 #include "third_party/WebKit/public/web/WebNavigationPolicy.h"
154 #include "third_party/WebKit/public/web/WebNetworkStateNotifier.h" 153 #include "third_party/WebKit/public/web/WebNetworkStateNotifier.h"
155 #include "third_party/WebKit/public/web/WebNodeList.h" 154 #include "third_party/WebKit/public/web/WebNodeList.h"
156 #include "third_party/WebKit/public/web/WebPageSerializer.h" 155 #include "third_party/WebKit/public/web/WebPageSerializer.h"
157 #include "third_party/WebKit/public/web/WebPlugin.h" 156 #include "third_party/WebKit/public/web/WebPlugin.h"
158 #include "third_party/WebKit/public/web/WebPluginAction.h" 157 #include "third_party/WebKit/public/web/WebPluginAction.h"
159 #include "third_party/WebKit/public/web/WebPluginContainer.h" 158 #include "third_party/WebKit/public/web/WebPluginContainer.h"
160 #include "third_party/WebKit/public/web/WebPluginDocument.h" 159 #include "third_party/WebKit/public/web/WebPluginDocument.h"
161 #include "third_party/WebKit/public/web/WebRange.h" 160 #include "third_party/WebKit/public/web/WebRange.h"
162 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" 161 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
163 #include "third_party/WebKit/public/web/WebScriptSource.h" 162 #include "third_party/WebKit/public/web/WebScriptSource.h"
164 #include "third_party/WebKit/public/web/WebSearchableFormData.h" 163 #include "third_party/WebKit/public/web/WebSearchableFormData.h"
165 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" 164 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
166 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" 165 #include "third_party/WebKit/public/web/WebSecurityPolicy.h"
167 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h"
168 #include "third_party/WebKit/public/web/WebSettings.h" 166 #include "third_party/WebKit/public/web/WebSettings.h"
169 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" 167 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
170 #include "third_party/WebKit/public/web/WebView.h" 168 #include "third_party/WebKit/public/web/WebView.h"
171 #include "third_party/WebKit/public/web/WebWindowFeatures.h" 169 #include "third_party/WebKit/public/web/WebWindowFeatures.h"
172 #include "third_party/WebKit/public/web/default/WebRenderTheme.h" 170 #include "third_party/WebKit/public/web/default/WebRenderTheme.h"
173 #include "third_party/icu/source/common/unicode/uchar.h" 171 #include "third_party/icu/source/common/unicode/uchar.h"
174 #include "third_party/icu/source/common/unicode/uscript.h" 172 #include "third_party/icu/source/common/unicode/uscript.h"
175 #include "ui/base/clipboard/clipboard.h" 173 #include "ui/base/clipboard/clipboard.h"
176 #include "ui/base/ui_base_switches_util.h" 174 #include "ui/base/ui_base_switches_util.h"
177 #include "ui/events/latency_info.h" 175 #include "ui/events/latency_info.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 using blink::WebAXObject; 215 using blink::WebAXObject;
218 using blink::WebApplicationCacheHost; 216 using blink::WebApplicationCacheHost;
219 using blink::WebApplicationCacheHostClient; 217 using blink::WebApplicationCacheHostClient;
220 using blink::WebCString; 218 using blink::WebCString;
221 using blink::WebColor; 219 using blink::WebColor;
222 using blink::WebColorName; 220 using blink::WebColorName;
223 using blink::WebConsoleMessage; 221 using blink::WebConsoleMessage;
224 using blink::WebData; 222 using blink::WebData;
225 using blink::WebDataSource; 223 using blink::WebDataSource;
226 using blink::WebDocument; 224 using blink::WebDocument;
227 using blink::WebDOMEvent;
228 using blink::WebDOMMessageEvent;
229 using blink::WebDragData; 225 using blink::WebDragData;
230 using blink::WebDragOperation; 226 using blink::WebDragOperation;
231 using blink::WebDragOperationsMask; 227 using blink::WebDragOperationsMask;
232 using blink::WebElement; 228 using blink::WebElement;
233 using blink::WebFileChooserCompletion; 229 using blink::WebFileChooserCompletion;
234 using blink::WebFindOptions; 230 using blink::WebFindOptions;
235 using blink::WebFormControlElement; 231 using blink::WebFormControlElement;
236 using blink::WebFormElement; 232 using blink::WebFormElement;
237 using blink::WebFrame; 233 using blink::WebFrame;
238 using blink::WebGestureEvent; 234 using blink::WebGestureEvent;
(...skipping 19 matching lines...) Expand all
258 using blink::WebPluginContainer; 254 using blink::WebPluginContainer;
259 using blink::WebPluginDocument; 255 using blink::WebPluginDocument;
260 using blink::WebPoint; 256 using blink::WebPoint;
261 using blink::WebRange; 257 using blink::WebRange;
262 using blink::WebRect; 258 using blink::WebRect;
263 using blink::WebReferrerPolicy; 259 using blink::WebReferrerPolicy;
264 using blink::WebScriptSource; 260 using blink::WebScriptSource;
265 using blink::WebSearchableFormData; 261 using blink::WebSearchableFormData;
266 using blink::WebSecurityOrigin; 262 using blink::WebSecurityOrigin;
267 using blink::WebSecurityPolicy; 263 using blink::WebSecurityPolicy;
268 using blink::WebSerializedScriptValue;
269 using blink::WebSettings; 264 using blink::WebSettings;
270 using blink::WebSize; 265 using blink::WebSize;
271 using blink::WebStorageNamespace; 266 using blink::WebStorageNamespace;
272 using blink::WebStorageQuotaCallbacks; 267 using blink::WebStorageQuotaCallbacks;
273 using blink::WebStorageQuotaError; 268 using blink::WebStorageQuotaError;
274 using blink::WebStorageQuotaType; 269 using blink::WebStorageQuotaType;
275 using blink::WebString; 270 using blink::WebString;
276 using blink::WebTextAffinity; 271 using blink::WebTextAffinity;
277 using blink::WebTextDirection; 272 using blink::WebTextDirection;
278 using blink::WebTouchEvent; 273 using blink::WebTouchEvent;
(...skipping 994 matching lines...) Expand 10 before | Expand all | Expand 10 after
1273 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding) 1268 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
1274 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageScale, OnResetPageScale) 1269 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageScale, OnResetPageScale)
1275 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) 1270 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
1276 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL, 1271 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
1277 OnSetZoomLevelForLoadingURL) 1272 OnSetZoomLevelForLoadingURL)
1278 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForView, 1273 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForView,
1279 OnSetZoomLevelForView) 1274 OnSetZoomLevelForView)
1280 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding) 1275 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
1281 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault, 1276 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
1282 OnResetPageEncodingToDefault) 1277 OnResetPageEncodingToDefault)
1283 IPC_MESSAGE_HANDLER(ViewMsg_PostMessageEvent, OnPostMessageEvent)
1284 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter) 1278 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
1285 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver) 1279 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
1286 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave) 1280 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
1287 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop) 1281 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
1288 IPC_MESSAGE_HANDLER(DragMsg_SourceEnded, OnDragSourceEnded) 1282 IPC_MESSAGE_HANDLER(DragMsg_SourceEnded, OnDragSourceEnded)
1289 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded, 1283 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
1290 OnDragSourceSystemDragEnded) 1284 OnDragSourceSystemDragEnded)
1291 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings) 1285 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
1292 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus) 1286 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
1293 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck) 1287 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
(...skipping 1229 matching lines...) Expand 10 before | Expand all | Expand 10 after
2523 2517
2524 void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) { 2518 void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) {
2525 webview()->setPageEncoding(WebString::fromUTF8(encoding_name)); 2519 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
2526 } 2520 }
2527 2521
2528 void RenderViewImpl::OnResetPageEncodingToDefault() { 2522 void RenderViewImpl::OnResetPageEncodingToDefault() {
2529 WebString no_encoding; 2523 WebString no_encoding;
2530 webview()->setPageEncoding(no_encoding); 2524 webview()->setPageEncoding(no_encoding);
2531 } 2525 }
2532 2526
2533 void RenderViewImpl::OnPostMessageEvent(
2534 const ViewMsg_PostMessage_Params& params) {
2535 // TODO(nasko): Support sending to subframes.
2536 WebFrame* frame = webview()->mainFrame();
2537
2538 // Find the source frame if it exists.
2539 WebFrame* source_frame = NULL;
2540 if (params.source_routing_id != MSG_ROUTING_NONE) {
2541 RenderViewImpl* source_view = FromRoutingID(params.source_routing_id);
2542 if (source_view)
2543 source_frame = source_view->webview()->mainFrame();
2544 }
2545
2546 // If the message contained MessagePorts, create the corresponding endpoints.
2547 blink::WebMessagePortChannelArray channels =
2548 WebMessagePortChannelImpl::CreatePorts(
2549 params.message_ports, params.new_routing_ids,
2550 base::MessageLoopProxy::current().get());
2551
2552 WebSerializedScriptValue serialized_script_value;
2553 if (params.is_data_raw_string) {
2554 v8::HandleScope handle_scope(blink::mainThreadIsolate());
2555 v8::Local<v8::Context> context = frame->mainWorldScriptContext();
2556 v8::Context::Scope context_scope(context);
2557 V8ValueConverterImpl converter;
2558 converter.SetDateAllowed(true);
2559 converter.SetRegExpAllowed(true);
2560 scoped_ptr<base::Value> value(new base::StringValue(params.data));
2561 v8::Handle<v8::Value> result_value = converter.ToV8Value(value.get(),
2562 context);
2563 serialized_script_value = WebSerializedScriptValue::serialize(result_value);
2564 } else {
2565 serialized_script_value = WebSerializedScriptValue::fromString(params.data);
2566 }
2567
2568 // Create an event with the message. The final parameter to initMessageEvent
2569 // is the last event ID, which is not used with postMessage.
2570 WebDOMEvent event = frame->document().createEvent("MessageEvent");
2571 WebDOMMessageEvent msg_event = event.to<WebDOMMessageEvent>();
2572 msg_event.initMessageEvent("message",
2573 // |canBubble| and |cancellable| are always false
2574 false, false,
2575 serialized_script_value,
2576 params.source_origin, source_frame, "", channels);
2577
2578 // We must pass in the target_origin to do the security check on this side,
2579 // since it may have changed since the original postMessage call was made.
2580 WebSecurityOrigin target_origin;
2581 if (!params.target_origin.empty()) {
2582 target_origin =
2583 WebSecurityOrigin::createFromString(WebString(params.target_origin));
2584 }
2585 frame->dispatchMessageEventWithOriginCheck(target_origin, msg_event);
2586 }
2587
2588 void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) { 2527 void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) {
2589 if ((enabled_bindings_flags & BINDINGS_POLICY_WEB_UI) && 2528 if ((enabled_bindings_flags & BINDINGS_POLICY_WEB_UI) &&
2590 !(enabled_bindings_ & BINDINGS_POLICY_WEB_UI)) { 2529 !(enabled_bindings_ & BINDINGS_POLICY_WEB_UI)) {
2591 // WebUIExtensionData deletes itself when we're destroyed. 2530 // WebUIExtensionData deletes itself when we're destroyed.
2592 new WebUIExtensionData(this); 2531 new WebUIExtensionData(this);
2593 // WebUIMojo deletes itself when we're destroyed. 2532 // WebUIMojo deletes itself when we're destroyed.
2594 new WebUIMojo(this); 2533 new WebUIMojo(this);
2595 } 2534 }
2596 2535
2597 enabled_bindings_ |= enabled_bindings_flags; 2536 enabled_bindings_ |= enabled_bindings_flags;
(...skipping 1202 matching lines...) Expand 10 before | Expand all | Expand 10 after
3800 std::vector<gfx::Size> sizes; 3739 std::vector<gfx::Size> sizes;
3801 ConvertToFaviconSizes(icon_urls[i].sizes(), &sizes); 3740 ConvertToFaviconSizes(icon_urls[i].sizes(), &sizes);
3802 if (!url.isEmpty()) 3741 if (!url.isEmpty())
3803 urls.push_back( 3742 urls.push_back(
3804 FaviconURL(url, ToFaviconType(icon_urls[i].iconType()), sizes)); 3743 FaviconURL(url, ToFaviconType(icon_urls[i].iconType()), sizes));
3805 } 3744 }
3806 SendUpdateFaviconURL(urls); 3745 SendUpdateFaviconURL(urls);
3807 } 3746 }
3808 3747
3809 } // namespace content 3748 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_view_impl.h ('k') | content/test/data/frame_tree/page_with_post_message_frames.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698