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

Side by Side Diff: chrome/renderer/extensions/tabs_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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/renderer/extensions/tabs_custom_bindings.h"
6
7 #include <stdint.h>
8
9 #include <string>
10
11 #include "base/bind.h"
12 #include "base/metrics/histogram_macros.h"
13 #include "content/public/renderer/render_frame.h"
14 #include "extensions/common/extension_messages.h"
15 #include "extensions/renderer/script_context.h"
16 #include "v8/include/v8.h"
17
18 namespace extensions {
19
20 TabsCustomBindings::TabsCustomBindings(ScriptContext* context)
21 : ObjectBackedNativeHandler(context) {
22 RouteFunction("OpenChannelToTab", "tabs",
23 base::Bind(&TabsCustomBindings::OpenChannelToTab,
24 base::Unretained(this)));
25 }
26
27 void TabsCustomBindings::OpenChannelToTab(
28 const v8::FunctionCallbackInfo<v8::Value>& args) {
29 content::RenderFrame* render_frame = context()->GetRenderFrame();
30 if (!render_frame)
31 return;
32
33 // tabs_custom_bindings.js unwraps arguments to tabs.connect/sendMessage and
34 // passes them to OpenChannelToTab, in the following order:
35 // - |tab_id| - Positive number that specifies the destination of the channel.
36 // - |frame_id| - Target frame(s) in the tab where onConnect is dispatched:
37 // -1 for all frames, 0 for the main frame, >0 for a child frame.
38 // - |extension_id| - Extension ID of sender and destination.
39 // - |channel_name| - A user-defined channel name.
40 CHECK(args.Length() >= 4 &&
41 args[0]->IsInt32() &&
42 args[1]->IsInt32() &&
43 args[2]->IsString() &&
44 args[3]->IsString());
45
46 ExtensionMsg_TabTargetConnectionInfo info;
47 info.tab_id = args[0]->Int32Value();
48 info.frame_id = args[1]->Int32Value();
49 std::string extension_id = *v8::String::Utf8Value(args[2]);
50 std::string channel_name = *v8::String::Utf8Value(args[3]);
51 int port_id = -1;
52 {
53 SCOPED_UMA_HISTOGRAM_TIMER("Extensions.Messaging.GetPortIdSyncTime.Tab");
54 render_frame->Send(new ExtensionHostMsg_OpenChannelToTab(
55 render_frame->GetRoutingID(), info, extension_id, channel_name,
56 &port_id));
57 }
58 args.GetReturnValue().Set(static_cast<int32_t>(port_id));
59 }
60
61 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/tabs_custom_bindings.h ('k') | chrome/renderer/resources/extensions/tabs_custom_bindings.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698