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

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

Issue 12300041: Add nativeMessaging extension permission (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 "chrome/renderer/extensions/runtime_custom_bindings.h" 5 #include "chrome/renderer/extensions/runtime_custom_bindings.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/common/extensions/extension.h" 10 #include "chrome/common/extensions/extension.h"
11 #include "chrome/common/extensions/extension_messages.h" 11 #include "chrome/common/extensions/extension_messages.h"
12 #include "chrome/common/extensions/manifest.h" 12 #include "chrome/common/extensions/manifest.h"
13 #include "chrome/renderer/extensions/chrome_v8_context.h" 13 #include "chrome/renderer/extensions/chrome_v8_context.h"
14 #include "chrome/renderer/extensions/dispatcher.h"
14 #include "content/public/renderer/render_view.h" 15 #include "content/public/renderer/render_view.h"
15 #include "content/public/renderer/v8_value_converter.h" 16 #include "content/public/renderer/v8_value_converter.h"
16 17
17 using content::V8ValueConverter; 18 using content::V8ValueConverter;
18 19
19 namespace extensions { 20 namespace extensions {
20 21
21 RuntimeCustomBindings::RuntimeCustomBindings(ChromeV8Context* context) 22 RuntimeCustomBindings::RuntimeCustomBindings(Dispatcher* dispatcher,
22 : ChromeV8Extension(NULL), context_(context) { 23 ChromeV8Context* context)
24 : ChromeV8Extension(dispatcher), context_(context) {
23 RouteFunction("GetManifest", 25 RouteFunction("GetManifest",
24 base::Bind(&RuntimeCustomBindings::GetManifest, base::Unretained(this))); 26 base::Bind(&RuntimeCustomBindings::GetManifest,
27 base::Unretained(this)));
25 RouteStaticFunction("OpenChannelToExtension", &OpenChannelToExtension); 28 RouteStaticFunction("OpenChannelToExtension", &OpenChannelToExtension);
26 RouteStaticFunction("OpenChannelToNativeApp", &OpenChannelToNativeApp); 29 RouteFunction("OpenChannelToNativeApp",
30 base::Bind(&RuntimeCustomBindings::OpenChannelToNativeApp,
31 base::Unretained(this)));
27 } 32 }
28 33
29 RuntimeCustomBindings::~RuntimeCustomBindings() {} 34 RuntimeCustomBindings::~RuntimeCustomBindings() {}
30 35
31 // static 36 // static
32 v8::Handle<v8::Value> RuntimeCustomBindings::OpenChannelToExtension( 37 v8::Handle<v8::Value> RuntimeCustomBindings::OpenChannelToExtension(
33 const v8::Arguments& args) { 38 const v8::Arguments& args) {
34 // Get the current RenderView so that we can send a routed IPC message from 39 // Get the current RenderView so that we can send a routed IPC message from
35 // the correct source. 40 // the correct source.
36 content::RenderView* renderview = GetCurrentRenderView(); 41 content::RenderView* renderview = GetCurrentRenderView();
(...skipping 12 matching lines...) Expand all
49 int port_id = -1; 54 int port_id = -1;
50 renderview->Send(new ExtensionHostMsg_OpenChannelToExtension( 55 renderview->Send(new ExtensionHostMsg_OpenChannelToExtension(
51 renderview->GetRoutingID(), 56 renderview->GetRoutingID(),
52 source_id, 57 source_id,
53 target_id, 58 target_id,
54 channel_name, 59 channel_name,
55 &port_id)); 60 &port_id));
56 return v8::Integer::New(port_id); 61 return v8::Integer::New(port_id);
57 } 62 }
58 63
59 // static
60 v8::Handle<v8::Value> RuntimeCustomBindings::OpenChannelToNativeApp( 64 v8::Handle<v8::Value> RuntimeCustomBindings::OpenChannelToNativeApp(
61 const v8::Arguments& args) { 65 const v8::Arguments& args) {
66 // Verify that the extension has permission to use native messaging.
67 if (!dispatcher()->CheckCurrentContextAccessToExtensionAPI(
68 "nativeMessaging")) {
69 return v8::Undefined();
70 }
71
62 // Get the current RenderView so that we can send a routed IPC message from 72 // Get the current RenderView so that we can send a routed IPC message from
63 // the correct source. 73 // the correct source.
64 content::RenderView* renderview = GetCurrentRenderView(); 74 content::RenderView* renderview = GetCurrentRenderView();
65 if (!renderview) 75 if (!renderview)
66 return v8::Undefined(); 76 return v8::Undefined();
67 77
68 // The Javascript code should validate/fill the arguments. 78 // The Javascript code should validate/fill the arguments.
69 CHECK(args.Length() >= 2 && 79 CHECK(args.Length() >= 2 &&
70 args[0]->IsString() && 80 args[0]->IsString() &&
71 args[1]->IsString()); 81 args[1]->IsString());
(...skipping 13 matching lines...) Expand all
85 v8::Handle<v8::Value> RuntimeCustomBindings::GetManifest( 95 v8::Handle<v8::Value> RuntimeCustomBindings::GetManifest(
86 const v8::Arguments& args) { 96 const v8::Arguments& args) {
87 CHECK(context_->extension()); 97 CHECK(context_->extension());
88 98
89 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); 99 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create());
90 return converter->ToV8Value(context_->extension()->manifest()->value(), 100 return converter->ToV8Value(context_->extension()->manifest()->value(),
91 context_->v8_context()); 101 context_->v8_context());
92 } 102 }
93 103
94 } // extensions 104 } // extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698