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

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

Issue 332693004: Add a content API for postMessage (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address jochen's review Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « content/renderer/render_frame_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 #include "third_party/WebKit/public/web/WebElement.h" 153 #include "third_party/WebKit/public/web/WebElement.h"
154 #include "third_party/WebKit/public/web/WebFileChooserParams.h" 154 #include "third_party/WebKit/public/web/WebFileChooserParams.h"
155 #include "third_party/WebKit/public/web/WebFindOptions.h" 155 #include "third_party/WebKit/public/web/WebFindOptions.h"
156 #include "third_party/WebKit/public/web/WebFormControlElement.h" 156 #include "third_party/WebKit/public/web/WebFormControlElement.h"
157 #include "third_party/WebKit/public/web/WebFormElement.h" 157 #include "third_party/WebKit/public/web/WebFormElement.h"
158 #include "third_party/WebKit/public/web/WebFrame.h" 158 #include "third_party/WebKit/public/web/WebFrame.h"
159 #include "third_party/WebKit/public/web/WebGlyphCache.h" 159 #include "third_party/WebKit/public/web/WebGlyphCache.h"
160 #include "third_party/WebKit/public/web/WebHistoryItem.h" 160 #include "third_party/WebKit/public/web/WebHistoryItem.h"
161 #include "third_party/WebKit/public/web/WebInputElement.h" 161 #include "third_party/WebKit/public/web/WebInputElement.h"
162 #include "third_party/WebKit/public/web/WebInputEvent.h" 162 #include "third_party/WebKit/public/web/WebInputEvent.h"
163 #include "third_party/WebKit/public/web/WebKit.h"
163 #include "third_party/WebKit/public/web/WebLocalFrame.h" 164 #include "third_party/WebKit/public/web/WebLocalFrame.h"
164 #include "third_party/WebKit/public/web/WebMediaPlayerAction.h" 165 #include "third_party/WebKit/public/web/WebMediaPlayerAction.h"
165 #include "third_party/WebKit/public/web/WebNavigationPolicy.h" 166 #include "third_party/WebKit/public/web/WebNavigationPolicy.h"
166 #include "third_party/WebKit/public/web/WebNetworkStateNotifier.h" 167 #include "third_party/WebKit/public/web/WebNetworkStateNotifier.h"
167 #include "third_party/WebKit/public/web/WebNodeList.h" 168 #include "third_party/WebKit/public/web/WebNodeList.h"
168 #include "third_party/WebKit/public/web/WebPageSerializer.h" 169 #include "third_party/WebKit/public/web/WebPageSerializer.h"
169 #include "third_party/WebKit/public/web/WebPlugin.h" 170 #include "third_party/WebKit/public/web/WebPlugin.h"
170 #include "third_party/WebKit/public/web/WebPluginAction.h" 171 #include "third_party/WebKit/public/web/WebPluginAction.h"
171 #include "third_party/WebKit/public/web/WebPluginContainer.h" 172 #include "third_party/WebKit/public/web/WebPluginContainer.h"
172 #include "third_party/WebKit/public/web/WebPluginDocument.h" 173 #include "third_party/WebKit/public/web/WebPluginDocument.h"
(...skipping 2789 matching lines...) Expand 10 before | Expand all | Expand 10 after
2962 blink::WebMessagePortChannelArray channels(params.message_port_ids.size()); 2963 blink::WebMessagePortChannelArray channels(params.message_port_ids.size());
2963 for (size_t i = 0; 2964 for (size_t i = 0;
2964 i < params.message_port_ids.size() && i < params.new_routing_ids.size(); 2965 i < params.message_port_ids.size() && i < params.new_routing_ids.size();
2965 ++i) { 2966 ++i) {
2966 channels[i] = 2967 channels[i] =
2967 new WebMessagePortChannelImpl(params.new_routing_ids[i], 2968 new WebMessagePortChannelImpl(params.new_routing_ids[i],
2968 params.message_port_ids[i], 2969 params.message_port_ids[i],
2969 base::MessageLoopProxy::current().get()); 2970 base::MessageLoopProxy::current().get());
2970 } 2971 }
2971 2972
2973 WebSerializedScriptValue serialized_script_value;
2974 if (params.is_data_raw_string) {
2975 v8::HandleScope handle_scope(blink::mainThreadIsolate());
2976 v8::Local<v8::Context> context = frame->mainWorldScriptContext();
2977 v8::Context::Scope context_scope(context);
2978 V8ValueConverterImpl converter;
2979 converter.SetDateAllowed(true);
2980 converter.SetRegExpAllowed(true);
2981 scoped_ptr<base::Value> value(new base::StringValue(params.data));
2982 v8::Handle<v8::Value> result_value = converter.ToV8Value(value.get(),
2983 context);
2984 serialized_script_value = WebSerializedScriptValue::serialize(result_value);
2985 } else {
2986 serialized_script_value = WebSerializedScriptValue::fromString(params.data);
2987 }
2988
2972 // Create an event with the message. The final parameter to initMessageEvent 2989 // Create an event with the message. The final parameter to initMessageEvent
2973 // is the last event ID, which is not used with postMessage. 2990 // is the last event ID, which is not used with postMessage.
2974 WebDOMEvent event = frame->document().createEvent("MessageEvent"); 2991 WebDOMEvent event = frame->document().createEvent("MessageEvent");
2975 WebDOMMessageEvent msg_event = event.to<WebDOMMessageEvent>(); 2992 WebDOMMessageEvent msg_event = event.to<WebDOMMessageEvent>();
2976 msg_event.initMessageEvent("message", 2993 msg_event.initMessageEvent("message",
2977 // |canBubble| and |cancellable| are always false 2994 // |canBubble| and |cancellable| are always false
2978 false, false, 2995 false, false,
2979 WebSerializedScriptValue::fromString(params.data), 2996 serialized_script_value,
2980 params.source_origin, source_frame, "", channels); 2997 params.source_origin, source_frame, "", channels);
2981 2998
2982 // We must pass in the target_origin to do the security check on this side, 2999 // We must pass in the target_origin to do the security check on this side,
2983 // since it may have changed since the original postMessage call was made. 3000 // since it may have changed since the original postMessage call was made.
2984 WebSecurityOrigin target_origin; 3001 WebSecurityOrigin target_origin;
2985 if (!params.target_origin.empty()) { 3002 if (!params.target_origin.empty()) {
2986 target_origin = 3003 target_origin =
2987 WebSecurityOrigin::createFromString(WebString(params.target_origin)); 3004 WebSecurityOrigin::createFromString(WebString(params.target_origin));
2988 } 3005 }
2989 frame->dispatchMessageEventWithOriginCheck(target_origin, msg_event); 3006 frame->dispatchMessageEventWithOriginCheck(target_origin, msg_event);
(...skipping 1307 matching lines...) Expand 10 before | Expand all | Expand 10 after
4297 std::vector<gfx::Size> sizes; 4314 std::vector<gfx::Size> sizes;
4298 ConvertToFaviconSizes(icon_urls[i].sizes(), &sizes); 4315 ConvertToFaviconSizes(icon_urls[i].sizes(), &sizes);
4299 if (!url.isEmpty()) 4316 if (!url.isEmpty())
4300 urls.push_back( 4317 urls.push_back(
4301 FaviconURL(url, ToFaviconType(icon_urls[i].iconType()), sizes)); 4318 FaviconURL(url, ToFaviconType(icon_urls[i].iconType()), sizes));
4302 } 4319 }
4303 SendUpdateFaviconURL(urls); 4320 SendUpdateFaviconURL(urls);
4304 } 4321 }
4305 4322
4306 } // namespace content 4323 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_frame_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698