OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/renderer/runtime_custom_bindings.h" | 5 #include "extensions/renderer/runtime_custom_bindings.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/metrics/histogram_macros.h" |
12 #include "base/values.h" | 13 #include "base/values.h" |
13 #include "content/public/child/v8_value_converter.h" | 14 #include "content/public/child/v8_value_converter.h" |
14 #include "content/public/renderer/render_frame.h" | 15 #include "content/public/renderer/render_frame.h" |
15 #include "extensions/common/extension.h" | 16 #include "extensions/common/extension.h" |
16 #include "extensions/common/extension_messages.h" | 17 #include "extensions/common/extension_messages.h" |
17 #include "extensions/common/manifest.h" | 18 #include "extensions/common/manifest.h" |
18 #include "extensions/renderer/extension_frame_helper.h" | 19 #include "extensions/renderer/extension_frame_helper.h" |
19 #include "extensions/renderer/script_context.h" | 20 #include "extensions/renderer/script_context.h" |
20 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 21 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
21 | 22 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 const Extension* extension = context()->extension(); | 60 const Extension* extension = context()->extension(); |
60 if (extension && !extension->is_hosted_app()) | 61 if (extension && !extension->is_hosted_app()) |
61 info.source_id = extension->id(); | 62 info.source_id = extension->id(); |
62 | 63 |
63 info.target_id = *v8::String::Utf8Value(args[0]); | 64 info.target_id = *v8::String::Utf8Value(args[0]); |
64 info.source_url = context()->url(); | 65 info.source_url = context()->url(); |
65 std::string channel_name = *v8::String::Utf8Value(args[1]); | 66 std::string channel_name = *v8::String::Utf8Value(args[1]); |
66 bool include_tls_channel_id = | 67 bool include_tls_channel_id = |
67 args.Length() > 2 ? args[2]->BooleanValue() : false; | 68 args.Length() > 2 ? args[2]->BooleanValue() : false; |
68 int port_id = -1; | 69 int port_id = -1; |
69 // TODO(devlin): This file is littered with sync IPCs. Yuck. | 70 { |
70 renderframe->Send(new ExtensionHostMsg_OpenChannelToExtension( | 71 SCOPED_UMA_HISTOGRAM_TIMER( |
71 renderframe->GetRoutingID(), info, channel_name, include_tls_channel_id, | 72 "Extensions.Messaging.GetPortIdSyncTime.Extension"); |
72 &port_id)); | 73 // TODO(devlin): This file is littered with sync IPCs. Yuck. |
| 74 renderframe->Send(new ExtensionHostMsg_OpenChannelToExtension( |
| 75 renderframe->GetRoutingID(), info, channel_name, include_tls_channel_id, |
| 76 &port_id)); |
| 77 } |
73 args.GetReturnValue().Set(static_cast<int32_t>(port_id)); | 78 args.GetReturnValue().Set(static_cast<int32_t>(port_id)); |
74 } | 79 } |
75 | 80 |
76 void RuntimeCustomBindings::OpenChannelToNativeApp( | 81 void RuntimeCustomBindings::OpenChannelToNativeApp( |
77 const v8::FunctionCallbackInfo<v8::Value>& args) { | 82 const v8::FunctionCallbackInfo<v8::Value>& args) { |
78 // The Javascript code should validate/fill the arguments. | 83 // The Javascript code should validate/fill the arguments. |
79 CHECK_EQ(args.Length(), 1); | 84 CHECK_EQ(args.Length(), 1); |
80 CHECK(args[0]->IsString()); | 85 CHECK(args[0]->IsString()); |
81 | 86 |
82 // Verify that the extension has permission to use native messaging. | 87 // Verify that the extension has permission to use native messaging. |
83 if (!context()->GetAvailability("runtime.connectNative").is_available()) | 88 if (!context()->GetAvailability("runtime.connectNative").is_available()) |
84 return; | 89 return; |
85 | 90 |
86 content::RenderFrame* render_frame = context()->GetRenderFrame(); | 91 content::RenderFrame* render_frame = context()->GetRenderFrame(); |
87 if (!render_frame) | 92 if (!render_frame) |
88 return; | 93 return; |
89 | 94 |
90 std::string native_app_name = *v8::String::Utf8Value(args[0]); | 95 std::string native_app_name = *v8::String::Utf8Value(args[0]); |
91 | 96 |
92 int port_id = -1; | 97 int port_id = -1; |
93 render_frame->Send(new ExtensionHostMsg_OpenChannelToNativeApp( | 98 { |
94 render_frame->GetRoutingID(), native_app_name, &port_id)); | 99 SCOPED_UMA_HISTOGRAM_TIMER( |
| 100 "Extensions.Messaging.GetPortIdSyncTime.NativeApp"); |
| 101 render_frame->Send(new ExtensionHostMsg_OpenChannelToNativeApp( |
| 102 render_frame->GetRoutingID(), native_app_name, &port_id)); |
| 103 } |
95 args.GetReturnValue().Set(static_cast<int32_t>(port_id)); | 104 args.GetReturnValue().Set(static_cast<int32_t>(port_id)); |
96 } | 105 } |
97 | 106 |
98 void RuntimeCustomBindings::GetManifest( | 107 void RuntimeCustomBindings::GetManifest( |
99 const v8::FunctionCallbackInfo<v8::Value>& args) { | 108 const v8::FunctionCallbackInfo<v8::Value>& args) { |
100 CHECK(context()->extension()); | 109 CHECK(context()->extension()); |
101 | 110 |
102 std::unique_ptr<content::V8ValueConverter> converter( | 111 std::unique_ptr<content::V8ValueConverter> converter( |
103 content::V8ValueConverter::create()); | 112 content::V8ValueConverter::create()); |
104 args.GetReturnValue().Set(converter->ToV8Value( | 113 args.GetReturnValue().Set(converter->ToV8Value( |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 v8::Maybe<bool> maybe = | 178 v8::Maybe<bool> maybe = |
170 v8_views->CreateDataProperty(v8_context, v8_index++, window); | 179 v8_views->CreateDataProperty(v8_context, v8_index++, window); |
171 CHECK(maybe.IsJust() && maybe.FromJust()); | 180 CHECK(maybe.IsJust() && maybe.FromJust()); |
172 } | 181 } |
173 } | 182 } |
174 | 183 |
175 args.GetReturnValue().Set(v8_views); | 184 args.GetReturnValue().Set(v8_views); |
176 } | 185 } |
177 | 186 |
178 } // namespace extensions | 187 } // namespace extensions |
OLD | NEW |