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

Side by Side Diff: extensions/renderer/runtime_custom_bindings.cc

Issue 2300453002: [Extensions] Begin making Extension port initialization asynchronous (Closed)
Patch Set: Nasko's Created 4 years, 3 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
« no previous file with comments | « extensions/renderer/runtime_custom_bindings.h ('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 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"
13 #include "base/values.h" 12 #include "base/values.h"
14 #include "content/public/child/v8_value_converter.h" 13 #include "content/public/child/v8_value_converter.h"
15 #include "content/public/renderer/render_frame.h" 14 #include "content/public/renderer/render_frame.h"
16 #include "extensions/common/extension.h" 15 #include "extensions/common/extension.h"
17 #include "extensions/common/extension_messages.h" 16 #include "extensions/common/extension_messages.h"
18 #include "extensions/common/manifest.h" 17 #include "extensions/common/manifest.h"
19 #include "extensions/renderer/extension_frame_helper.h" 18 #include "extensions/renderer/extension_frame_helper.h"
20 #include "extensions/renderer/script_context.h" 19 #include "extensions/renderer/script_context.h"
21 #include "third_party/WebKit/public/web/WebLocalFrame.h" 20 #include "third_party/WebKit/public/web/WebLocalFrame.h"
22 21
23 namespace extensions { 22 namespace extensions {
24 23
25 RuntimeCustomBindings::RuntimeCustomBindings(ScriptContext* context) 24 RuntimeCustomBindings::RuntimeCustomBindings(ScriptContext* context)
26 : ObjectBackedNativeHandler(context) { 25 : ObjectBackedNativeHandler(context) {
27 RouteFunction( 26 RouteFunction(
28 "GetManifest", 27 "GetManifest",
29 base::Bind(&RuntimeCustomBindings::GetManifest, base::Unretained(this))); 28 base::Bind(&RuntimeCustomBindings::GetManifest, base::Unretained(this)));
30 RouteFunction("OpenChannelToExtension", "runtime.connect",
31 base::Bind(&RuntimeCustomBindings::OpenChannelToExtension,
32 base::Unretained(this)));
33 RouteFunction("OpenChannelToNativeApp", "runtime.connectNative",
34 base::Bind(&RuntimeCustomBindings::OpenChannelToNativeApp,
35 base::Unretained(this)));
36 RouteFunction("GetExtensionViews", 29 RouteFunction("GetExtensionViews",
37 base::Bind(&RuntimeCustomBindings::GetExtensionViews, 30 base::Bind(&RuntimeCustomBindings::GetExtensionViews,
38 base::Unretained(this))); 31 base::Unretained(this)));
39 } 32 }
40 33
41 RuntimeCustomBindings::~RuntimeCustomBindings() { 34 RuntimeCustomBindings::~RuntimeCustomBindings() {
42 } 35 }
43 36
44 void RuntimeCustomBindings::OpenChannelToExtension(
45 const v8::FunctionCallbackInfo<v8::Value>& args) {
46 // Get the current RenderFrame so that we can send a routed IPC message from
47 // the correct source.
48 content::RenderFrame* renderframe = context()->GetRenderFrame();
49 if (!renderframe)
50 return;
51
52 // The Javascript code should validate/fill the arguments.
53 CHECK_EQ(args.Length(), 3);
54 CHECK(args[0]->IsString() && args[1]->IsString() && args[2]->IsBoolean());
55
56 ExtensionMsg_ExternalConnectionInfo info;
57
58 // For messaging APIs, hosted apps should be considered a web page so hide
59 // its extension ID.
60 const Extension* extension = context()->extension();
61 if (extension && !extension->is_hosted_app())
62 info.source_id = extension->id();
63
64 info.target_id = *v8::String::Utf8Value(args[0]);
65 info.source_url = context()->url();
66 std::string channel_name = *v8::String::Utf8Value(args[1]);
67 bool include_tls_channel_id =
68 args.Length() > 2 ? args[2]->BooleanValue() : false;
69 int port_id = -1;
70 {
71 SCOPED_UMA_HISTOGRAM_TIMER(
72 "Extensions.Messaging.GetPortIdSyncTime.Extension");
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 }
78 args.GetReturnValue().Set(static_cast<int32_t>(port_id));
79 }
80
81 void RuntimeCustomBindings::OpenChannelToNativeApp(
82 const v8::FunctionCallbackInfo<v8::Value>& args) {
83 // The Javascript code should validate/fill the arguments.
84 CHECK_EQ(args.Length(), 1);
85 CHECK(args[0]->IsString());
86
87 // Verify that the extension has permission to use native messaging.
88 if (!context()->GetAvailability("runtime.connectNative").is_available())
89 return;
90
91 content::RenderFrame* render_frame = context()->GetRenderFrame();
92 if (!render_frame)
93 return;
94
95 std::string native_app_name = *v8::String::Utf8Value(args[0]);
96
97 int port_id = -1;
98 {
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 }
104 args.GetReturnValue().Set(static_cast<int32_t>(port_id));
105 }
106
107 void RuntimeCustomBindings::GetManifest( 37 void RuntimeCustomBindings::GetManifest(
108 const v8::FunctionCallbackInfo<v8::Value>& args) { 38 const v8::FunctionCallbackInfo<v8::Value>& args) {
109 CHECK(context()->extension()); 39 CHECK(context()->extension());
110 40
111 std::unique_ptr<content::V8ValueConverter> converter( 41 std::unique_ptr<content::V8ValueConverter> converter(
112 content::V8ValueConverter::create()); 42 content::V8ValueConverter::create());
113 args.GetReturnValue().Set(converter->ToV8Value( 43 args.GetReturnValue().Set(converter->ToV8Value(
114 context()->extension()->manifest()->value(), context()->v8_context())); 44 context()->extension()->manifest()->value(), context()->v8_context()));
115 } 45 }
116 46
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 v8::Maybe<bool> maybe = 108 v8::Maybe<bool> maybe =
179 v8_views->CreateDataProperty(v8_context, v8_index++, window); 109 v8_views->CreateDataProperty(v8_context, v8_index++, window);
180 CHECK(maybe.IsJust() && maybe.FromJust()); 110 CHECK(maybe.IsJust() && maybe.FromJust());
181 } 111 }
182 } 112 }
183 113
184 args.GetReturnValue().Set(v8_views); 114 args.GetReturnValue().Set(v8_views);
185 } 115 }
186 116
187 } // namespace extensions 117 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/runtime_custom_bindings.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698