OLD | NEW |
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 4276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4287 WebKit::WebDOMMessageEvent event) { | 4287 WebKit::WebDOMMessageEvent event) { |
4288 if (!is_swapped_out_) | 4288 if (!is_swapped_out_) |
4289 return false; | 4289 return false; |
4290 | 4290 |
4291 ViewMsg_PostMessage_Params params; | 4291 ViewMsg_PostMessage_Params params; |
4292 params.data = event.data().toString(); | 4292 params.data = event.data().toString(); |
4293 params.source_origin = event.origin(); | 4293 params.source_origin = event.origin(); |
4294 if (!target_origin.isNull()) | 4294 if (!target_origin.isNull()) |
4295 params.target_origin = target_origin.toString(); | 4295 params.target_origin = target_origin.toString(); |
4296 | 4296 |
| 4297 WebKit::WebMessagePortChannelArray channels = event.releaseChannels(); |
| 4298 if (!channels.isEmpty()) { |
| 4299 std::vector<int> message_port_ids(channels.size()); |
| 4300 // Extract the port IDs from the channel array. |
| 4301 for (size_t i = 0; i < channels.size(); ++i) { |
| 4302 WebMessagePortChannelImpl* webchannel = |
| 4303 static_cast<WebMessagePortChannelImpl*>(channels[i]); |
| 4304 message_port_ids[i] = webchannel->message_port_id(); |
| 4305 webchannel->QueueMessages(); |
| 4306 DCHECK_NE(message_port_ids[i], MSG_ROUTING_NONE); |
| 4307 } |
| 4308 params.message_port_ids = message_port_ids; |
| 4309 } |
| 4310 |
4297 // Include the routing ID for the source frame, which the browser process | 4311 // Include the routing ID for the source frame, which the browser process |
4298 // will translate into the routing ID for the equivalent frame in the target | 4312 // will translate into the routing ID for the equivalent frame in the target |
4299 // process. | 4313 // process. |
4300 params.source_routing_id = MSG_ROUTING_NONE; | 4314 params.source_routing_id = MSG_ROUTING_NONE; |
4301 RenderViewImpl* source_view = FromWebView(sourceFrame->view()); | 4315 RenderViewImpl* source_view = FromWebView(sourceFrame->view()); |
4302 if (source_view) | 4316 if (source_view) |
4303 params.source_routing_id = source_view->routing_id(); | 4317 params.source_routing_id = source_view->routing_id(); |
4304 | 4318 |
4305 Send(new ViewHostMsg_RouteMessageEvent(routing_id_, params)); | 4319 Send(new ViewHostMsg_RouteMessageEvent(routing_id_, params)); |
4306 return true; | 4320 return true; |
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5011 WebFrame* frame = webview()->mainFrame(); | 5025 WebFrame* frame = webview()->mainFrame(); |
5012 | 5026 |
5013 // Find the source frame if it exists. | 5027 // Find the source frame if it exists. |
5014 WebFrame* source_frame = NULL; | 5028 WebFrame* source_frame = NULL; |
5015 if (params.source_routing_id != MSG_ROUTING_NONE) { | 5029 if (params.source_routing_id != MSG_ROUTING_NONE) { |
5016 RenderViewImpl* source_view = FromRoutingID(params.source_routing_id); | 5030 RenderViewImpl* source_view = FromRoutingID(params.source_routing_id); |
5017 if (source_view) | 5031 if (source_view) |
5018 source_frame = source_view->webview()->mainFrame(); | 5032 source_frame = source_view->webview()->mainFrame(); |
5019 } | 5033 } |
5020 | 5034 |
| 5035 // If the message contained MessagePorts, create the corresponding endpoints. |
| 5036 DCHECK_EQ(params.message_port_ids.size(), params.new_routing_ids.size()); |
| 5037 WebKit::WebMessagePortChannelArray channels(params.message_port_ids.size()); |
| 5038 for (size_t i = 0; |
| 5039 i < params.message_port_ids.size() && i < params.new_routing_ids.size(); |
| 5040 ++i) { |
| 5041 channels[i] = |
| 5042 new WebMessagePortChannelImpl(params.new_routing_ids[i], |
| 5043 params.message_port_ids[i], |
| 5044 base::MessageLoopProxy::current().get()); |
| 5045 } |
| 5046 |
5021 // Create an event with the message. The final parameter to initMessageEvent | 5047 // Create an event with the message. The final parameter to initMessageEvent |
5022 // is the last event ID, which is not used with postMessage. | 5048 // is the last event ID, which is not used with postMessage. |
5023 WebDOMEvent event = frame->document().createEvent("MessageEvent"); | 5049 WebDOMEvent event = frame->document().createEvent("MessageEvent"); |
5024 WebDOMMessageEvent msg_event = event.to<WebDOMMessageEvent>(); | 5050 WebDOMMessageEvent msg_event = event.to<WebDOMMessageEvent>(); |
5025 msg_event.initMessageEvent("message", | 5051 msg_event.initMessageEvent("message", |
5026 // |canBubble| and |cancellable| are always false | 5052 // |canBubble| and |cancellable| are always false |
5027 false, false, | 5053 false, false, |
5028 WebSerializedScriptValue::fromString(params.data), | 5054 WebSerializedScriptValue::fromString(params.data), |
5029 params.source_origin, source_frame, ""); | 5055 params.source_origin, source_frame, "", channels); |
5030 | 5056 |
5031 // We must pass in the target_origin to do the security check on this side, | 5057 // We must pass in the target_origin to do the security check on this side, |
5032 // since it may have changed since the original postMessage call was made. | 5058 // since it may have changed since the original postMessage call was made. |
5033 WebSecurityOrigin target_origin; | 5059 WebSecurityOrigin target_origin; |
5034 if (!params.target_origin.empty()) { | 5060 if (!params.target_origin.empty()) { |
5035 target_origin = | 5061 target_origin = |
5036 WebSecurityOrigin::createFromString(WebString(params.target_origin)); | 5062 WebSecurityOrigin::createFromString(WebString(params.target_origin)); |
5037 } | 5063 } |
5038 frame->dispatchMessageEventWithOriginCheck(target_origin, msg_event); | 5064 frame->dispatchMessageEventWithOriginCheck(target_origin, msg_event); |
5039 } | 5065 } |
(...skipping 1532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6572 for (size_t i = 0; i < icon_urls.size(); i++) { | 6598 for (size_t i = 0; i < icon_urls.size(); i++) { |
6573 WebURL url = icon_urls[i].iconURL(); | 6599 WebURL url = icon_urls[i].iconURL(); |
6574 if (!url.isEmpty()) | 6600 if (!url.isEmpty()) |
6575 urls.push_back(FaviconURL(url, | 6601 urls.push_back(FaviconURL(url, |
6576 ToFaviconType(icon_urls[i].iconType()))); | 6602 ToFaviconType(icon_urls[i].iconType()))); |
6577 } | 6603 } |
6578 SendUpdateFaviconURL(urls); | 6604 SendUpdateFaviconURL(urls); |
6579 } | 6605 } |
6580 | 6606 |
6581 } // namespace content | 6607 } // namespace content |
OLD | NEW |