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

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: extend content api to set source origin 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
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"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/debug/alias.h" 15 #include "base/debug/alias.h"
16 #include "base/debug/trace_event.h" 16 #include "base/debug/trace_event.h"
17 #include "base/files/file_path.h" 17 #include "base/files/file_path.h"
18 #include "base/i18n/rtl.h" 18 #include "base/i18n/rtl.h"
19 #include "base/json/json_reader.h"
19 #include "base/json/json_writer.h" 20 #include "base/json/json_writer.h"
20 #include "base/lazy_instance.h" 21 #include "base/lazy_instance.h"
21 #include "base/memory/scoped_ptr.h" 22 #include "base/memory/scoped_ptr.h"
22 #include "base/message_loop/message_loop_proxy.h" 23 #include "base/message_loop/message_loop_proxy.h"
23 #include "base/metrics/field_trial.h" 24 #include "base/metrics/field_trial.h"
24 #include "base/metrics/histogram.h" 25 #include "base/metrics/histogram.h"
25 #include "base/path_service.h" 26 #include "base/path_service.h"
26 #include "base/process/kill.h" 27 #include "base/process/kill.h"
27 #include "base/process/process.h" 28 #include "base/process/process.h"
28 #include "base/strings/string_number_conversions.h" 29 #include "base/strings/string_number_conversions.h"
(...skipping 2933 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(v8::Isolate::GetCurrent());
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 base::Value* value = new base::StringValue(params.data);
mnaganov (inactive) 2014/07/14 15:19:29 Use scoped_ptr. The converter doesn't acquire owne
sgurun-gerrit only 2014/07/16 00:43:28 Done.
2982 v8::Handle<v8::Value> result_value = converter.ToV8Value(value, context);
2983 serialized_script_value = WebSerializedScriptValue::serialize(result_value);
2984 } else {
2985 serialized_script_value = WebSerializedScriptValue::fromString(params.data);
2986 }
2987
2972 // Create an event with the message. The final parameter to initMessageEvent 2988 // Create an event with the message. The final parameter to initMessageEvent
2973 // is the last event ID, which is not used with postMessage. 2989 // is the last event ID, which is not used with postMessage.
2974 WebDOMEvent event = frame->document().createEvent("MessageEvent"); 2990 WebDOMEvent event = frame->document().createEvent("MessageEvent");
2975 WebDOMMessageEvent msg_event = event.to<WebDOMMessageEvent>(); 2991 WebDOMMessageEvent msg_event = event.to<WebDOMMessageEvent>();
2976 msg_event.initMessageEvent("message", 2992 msg_event.initMessageEvent("message",
2977 // |canBubble| and |cancellable| are always false 2993 // |canBubble| and |cancellable| are always false
2978 false, false, 2994 false, false,
2979 WebSerializedScriptValue::fromString(params.data), 2995 serialized_script_value,
2980 params.source_origin, source_frame, "", channels); 2996 params.source_origin, source_frame, "", channels);
2981 2997
2982 // We must pass in the target_origin to do the security check on this side, 2998 // 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. 2999 // since it may have changed since the original postMessage call was made.
2984 WebSecurityOrigin target_origin; 3000 WebSecurityOrigin target_origin;
2985 if (!params.target_origin.empty()) { 3001 if (!params.target_origin.empty()) {
2986 target_origin = 3002 target_origin =
2987 WebSecurityOrigin::createFromString(WebString(params.target_origin)); 3003 WebSecurityOrigin::createFromString(WebString(params.target_origin));
2988 } 3004 }
2989 frame->dispatchMessageEventWithOriginCheck(target_origin, msg_event); 3005 frame->dispatchMessageEventWithOriginCheck(target_origin, msg_event);
(...skipping 1307 matching lines...) Expand 10 before | Expand all | Expand 10 after
4297 std::vector<gfx::Size> sizes; 4313 std::vector<gfx::Size> sizes;
4298 ConvertToFaviconSizes(icon_urls[i].sizes(), &sizes); 4314 ConvertToFaviconSizes(icon_urls[i].sizes(), &sizes);
4299 if (!url.isEmpty()) 4315 if (!url.isEmpty())
4300 urls.push_back( 4316 urls.push_back(
4301 FaviconURL(url, ToFaviconType(icon_urls[i].iconType()), sizes)); 4317 FaviconURL(url, ToFaviconType(icon_urls[i].iconType()), sizes));
4302 } 4318 }
4303 SendUpdateFaviconURL(urls); 4319 SendUpdateFaviconURL(urls);
4304 } 4320 }
4305 4321
4306 } // namespace content 4322 } // namespace content
OLDNEW
« content/browser/android/content_view_core_impl.cc ('K') | « content/renderer/render_frame_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698