| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "android_webview/renderer/aw_message_port_client.h" | 5 #include "android_webview/renderer/aw_message_port_client.h" |
| 6 | 6 |
| 7 #include "android_webview/common/aw_message_port_messages.h" | 7 #include "android_webview/common/aw_message_port_messages.h" |
| 8 #include "content/public/child/v8_value_converter.h" | 8 #include "content/public/child/v8_value_converter.h" |
| 9 #include "content/public/renderer/render_frame.h" | 9 #include "content/public/renderer/render_frame.h" |
| 10 #include "content/public/renderer/render_view.h" | 10 #include "content/public/renderer/render_view.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 render_frame()->GetRenderView()->GetWebView()->mainFrame(); | 50 render_frame()->GetRenderView()->GetWebView()->mainFrame(); |
| 51 if (main_frame == nullptr) { | 51 if (main_frame == nullptr) { |
| 52 return; | 52 return; |
| 53 } | 53 } |
| 54 v8::Local<v8::Context> context = main_frame->mainWorldScriptContext(); | 54 v8::Local<v8::Context> context = main_frame->mainWorldScriptContext(); |
| 55 v8::Context::Scope context_scope(context); | 55 v8::Context::Scope context_scope(context); |
| 56 DCHECK(!context.IsEmpty()); | 56 DCHECK(!context.IsEmpty()); |
| 57 WebSerializedScriptValue v = WebSerializedScriptValue::fromString(message); | 57 WebSerializedScriptValue v = WebSerializedScriptValue::fromString(message); |
| 58 v8::Local<v8::Value> v8value = v.deserialize(); | 58 v8::Local<v8::Value> v8value = v.deserialize(); |
| 59 | 59 |
| 60 scoped_ptr<V8ValueConverter> converter; | 60 std::unique_ptr<V8ValueConverter> converter; |
| 61 converter.reset(V8ValueConverter::create()); | 61 converter.reset(V8ValueConverter::create()); |
| 62 converter->SetDateAllowed(true); | 62 converter->SetDateAllowed(true); |
| 63 converter->SetRegExpAllowed(true); | 63 converter->SetRegExpAllowed(true); |
| 64 base::ListValue result; | 64 base::ListValue result; |
| 65 base::Value* value = converter->FromV8Value(v8value, context); | 65 base::Value* value = converter->FromV8Value(v8value, context); |
| 66 if (value) { | 66 if (value) { |
| 67 result.Append(value); | 67 result.Append(value); |
| 68 } | 68 } |
| 69 | 69 |
| 70 Send(new AwMessagePortHostMsg_ConvertedWebToAppMessage( | 70 Send(new AwMessagePortHostMsg_ConvertedWebToAppMessage( |
| 71 render_frame()->GetRoutingID(), message_port_id, result, | 71 render_frame()->GetRoutingID(), message_port_id, result, |
| 72 sent_message_port_ids)); | 72 sent_message_port_ids)); |
| 73 } | 73 } |
| 74 | 74 |
| 75 void AwMessagePortClient::OnAppToWebMessage( | 75 void AwMessagePortClient::OnAppToWebMessage( |
| 76 int message_port_id, | 76 int message_port_id, |
| 77 const base::string16& message, | 77 const base::string16& message, |
| 78 const vector<int>& sent_message_port_ids) { | 78 const vector<int>& sent_message_port_ids) { |
| 79 v8::HandleScope handle_scope(blink::mainThreadIsolate()); | 79 v8::HandleScope handle_scope(blink::mainThreadIsolate()); |
| 80 blink::WebFrame* main_frame = | 80 blink::WebFrame* main_frame = |
| 81 render_frame()->GetRenderView()->GetWebView()->mainFrame(); | 81 render_frame()->GetRenderView()->GetWebView()->mainFrame(); |
| 82 if (main_frame == nullptr) { | 82 if (main_frame == nullptr) { |
| 83 return; | 83 return; |
| 84 } | 84 } |
| 85 v8::Local<v8::Context> context = main_frame->mainWorldScriptContext(); | 85 v8::Local<v8::Context> context = main_frame->mainWorldScriptContext(); |
| 86 v8::Context::Scope context_scope(context); | 86 v8::Context::Scope context_scope(context); |
| 87 DCHECK(!context.IsEmpty()); | 87 DCHECK(!context.IsEmpty()); |
| 88 scoped_ptr<V8ValueConverter> converter; | 88 std::unique_ptr<V8ValueConverter> converter; |
| 89 converter.reset(V8ValueConverter::create()); | 89 converter.reset(V8ValueConverter::create()); |
| 90 converter->SetDateAllowed(true); | 90 converter->SetDateAllowed(true); |
| 91 converter->SetRegExpAllowed(true); | 91 converter->SetRegExpAllowed(true); |
| 92 scoped_ptr<base::Value> value(new base::StringValue(message)); | 92 std::unique_ptr<base::Value> value(new base::StringValue(message)); |
| 93 v8::Local<v8::Value> result_value = | 93 v8::Local<v8::Value> result_value = |
| 94 converter->ToV8Value(value.get(), context); | 94 converter->ToV8Value(value.get(), context); |
| 95 WebSerializedScriptValue serialized_script_value = | 95 WebSerializedScriptValue serialized_script_value = |
| 96 WebSerializedScriptValue::serialize(result_value); | 96 WebSerializedScriptValue::serialize(result_value); |
| 97 base::string16 result = serialized_script_value.toString(); | 97 base::string16 result = serialized_script_value.toString(); |
| 98 Send(new AwMessagePortHostMsg_ConvertedAppToWebMessage( | 98 Send(new AwMessagePortHostMsg_ConvertedAppToWebMessage( |
| 99 render_frame()->GetRoutingID(), message_port_id, | 99 render_frame()->GetRoutingID(), message_port_id, |
| 100 result, sent_message_port_ids)); | 100 result, sent_message_port_ids)); |
| 101 } | 101 } |
| 102 | 102 |
| 103 void AwMessagePortClient::OnClosePort(int message_port_id) { | 103 void AwMessagePortClient::OnClosePort(int message_port_id) { |
| 104 Send(new AwMessagePortHostMsg_ClosePortAck(render_frame()->GetRoutingID(), | 104 Send(new AwMessagePortHostMsg_ClosePortAck(render_frame()->GetRoutingID(), |
| 105 message_port_id)); | 105 message_port_id)); |
| 106 } | 106 } |
| 107 | 107 |
| 108 } | 108 } |
| OLD | NEW |