OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/child/webmessageportchannel_impl.h" | 5 #include "content/child/webmessageportchannel_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop_proxy.h" | 8 #include "base/message_loop/message_loop_proxy.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "content/child/child_process.h" | 10 #include "content/child/child_process.h" |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 main_thread_task_runner_->ReleaseSoon(FROM_HERE, this); | 146 main_thread_task_runner_->ReleaseSoon(FROM_HERE, this); |
147 } | 147 } |
148 | 148 |
149 void WebMessagePortChannelImpl::postMessage( | 149 void WebMessagePortChannelImpl::postMessage( |
150 const WebString& message_as_string, | 150 const WebString& message_as_string, |
151 WebMessagePortChannelArray* channels) { | 151 WebMessagePortChannelArray* channels) { |
152 MessagePortMessage message(message_as_string); | 152 MessagePortMessage message(message_as_string); |
153 if (send_messages_as_values_) { | 153 if (send_messages_as_values_) { |
154 blink::WebSerializedScriptValue serialized_value = | 154 blink::WebSerializedScriptValue serialized_value = |
155 blink::WebSerializedScriptValue::fromString(message_as_string); | 155 blink::WebSerializedScriptValue::fromString(message_as_string); |
156 v8::Handle<v8::Value> v8_value = serialized_value.deserialize(); | 156 v8::Local<v8::Value> v8_value = serialized_value.deserialize(); |
157 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); | 157 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); |
158 converter->SetDateAllowed(true); | 158 converter->SetDateAllowed(true); |
159 converter->SetRegExpAllowed(true); | 159 converter->SetRegExpAllowed(true); |
160 scoped_ptr<base::Value> message_as_value(converter->FromV8Value( | 160 scoped_ptr<base::Value> message_as_value(converter->FromV8Value( |
161 v8_value, v8::Isolate::GetCurrent()->GetCurrentContext())); | 161 v8_value, v8::Isolate::GetCurrent()->GetCurrentContext())); |
162 message = MessagePortMessage(message_as_value.Pass()); | 162 message = MessagePortMessage(message_as_value.Pass()); |
163 } | 163 } |
164 if (!main_thread_task_runner_->BelongsToCurrentThread()) { | 164 if (!main_thread_task_runner_->BelongsToCurrentThread()) { |
165 main_thread_task_runner_->PostTask( | 165 main_thread_task_runner_->PostTask( |
166 FROM_HERE, base::Bind(&WebMessagePortChannelImpl::PostMessage, this, | 166 FROM_HERE, base::Bind(&WebMessagePortChannelImpl::PostMessage, this, |
(...skipping 20 matching lines...) Expand all Loading... |
187 | 187 |
188 const MessagePortMessage& data = message_queue_.front().message; | 188 const MessagePortMessage& data = message_queue_.front().message; |
189 DCHECK(data.is_string() != data.is_value()); | 189 DCHECK(data.is_string() != data.is_value()); |
190 if (data.is_value()) { | 190 if (data.is_value()) { |
191 v8::HandleScope handle_scope(client_->scriptIsolate()); | 191 v8::HandleScope handle_scope(client_->scriptIsolate()); |
192 v8::Context::Scope context_scope( | 192 v8::Context::Scope context_scope( |
193 client_->scriptContextForMessageConversion()); | 193 client_->scriptContextForMessageConversion()); |
194 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); | 194 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); |
195 converter->SetDateAllowed(true); | 195 converter->SetDateAllowed(true); |
196 converter->SetRegExpAllowed(true); | 196 converter->SetRegExpAllowed(true); |
197 v8::Handle<v8::Value> v8_value = converter->ToV8Value( | 197 v8::Local<v8::Value> v8_value = converter->ToV8Value( |
198 data.as_value(), client_->scriptContextForMessageConversion()); | 198 data.as_value(), client_->scriptContextForMessageConversion()); |
199 blink::WebSerializedScriptValue serialized_value = | 199 blink::WebSerializedScriptValue serialized_value = |
200 blink::WebSerializedScriptValue::serialize(v8_value); | 200 blink::WebSerializedScriptValue::serialize(v8_value); |
201 *message = serialized_value.toString(); | 201 *message = serialized_value.toString(); |
202 } else { | 202 } else { |
203 *message = message_queue_.front().message.message_as_string; | 203 *message = message_queue_.front().message.message_as_string; |
204 } | 204 } |
205 channels = message_queue_.front().ports; | 205 channels = message_queue_.front().ports; |
206 message_queue_.pop(); | 206 message_queue_.pop(); |
207 return true; | 207 return true; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 | 320 |
321 Release(); | 321 Release(); |
322 ChildProcess::current()->ReleaseProcess(); | 322 ChildProcess::current()->ReleaseProcess(); |
323 } | 323 } |
324 | 324 |
325 WebMessagePortChannelImpl::Message::Message() {} | 325 WebMessagePortChannelImpl::Message::Message() {} |
326 | 326 |
327 WebMessagePortChannelImpl::Message::~Message() {} | 327 WebMessagePortChannelImpl::Message::~Message() {} |
328 | 328 |
329 } // namespace content | 329 } // namespace content |
OLD | NEW |