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

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

Issue 16032015: Extensions: pass ChromeV8Context around instead of v8::Handle. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 7 years, 6 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 "chrome/renderer/extensions/dispatcher.h"
15 #include "content/public/renderer/render_view.h" 15 #include "content/public/renderer/render_view.h"
16 #include "content/public/renderer/v8_value_converter.h" 16 #include "content/public/renderer/v8_value_converter.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
20 20
21 using content::V8ValueConverter; 21 using content::V8ValueConverter;
22 22
23 namespace extensions { 23 namespace extensions {
24 24
25 RuntimeCustomBindings::RuntimeCustomBindings(Dispatcher* dispatcher, 25 RuntimeCustomBindings::RuntimeCustomBindings(Dispatcher* dispatcher,
26 ChromeV8Context* context) 26 ChromeV8Context* context)
27 : ChromeV8Extension(dispatcher, context->v8_context()), 27 : ChromeV8Extension(dispatcher, context) {
28 context_(context) {
29 RouteFunction("GetManifest", 28 RouteFunction("GetManifest",
30 base::Bind(&RuntimeCustomBindings::GetManifest, 29 base::Bind(&RuntimeCustomBindings::GetManifest,
31 base::Unretained(this))); 30 base::Unretained(this)));
32 RouteFunction("OpenChannelToExtension", 31 RouteFunction("OpenChannelToExtension",
33 base::Bind(&RuntimeCustomBindings::OpenChannelToExtension, 32 base::Bind(&RuntimeCustomBindings::OpenChannelToExtension,
34 base::Unretained(this))); 33 base::Unretained(this)));
35 RouteFunction("OpenChannelToNativeApp", 34 RouteFunction("OpenChannelToNativeApp",
36 base::Bind(&RuntimeCustomBindings::OpenChannelToNativeApp, 35 base::Bind(&RuntimeCustomBindings::OpenChannelToNativeApp,
37 base::Unretained(this))); 36 base::Unretained(this)));
38 } 37 }
(...skipping 22 matching lines...) Expand all
61 int port_id = -1; 60 int port_id = -1;
62 renderview->Send(new ExtensionHostMsg_OpenChannelToExtension( 61 renderview->Send(new ExtensionHostMsg_OpenChannelToExtension(
63 renderview->GetRoutingID(), info, channel_name, &port_id)); 62 renderview->GetRoutingID(), info, channel_name, &port_id));
64 return v8::Integer::New(port_id); 63 return v8::Integer::New(port_id);
65 } 64 }
66 65
67 v8::Handle<v8::Value> RuntimeCustomBindings::OpenChannelToNativeApp( 66 v8::Handle<v8::Value> RuntimeCustomBindings::OpenChannelToNativeApp(
68 const v8::Arguments& args) { 67 const v8::Arguments& args) {
69 // Verify that the extension has permission to use native messaging. 68 // Verify that the extension has permission to use native messaging.
70 if (!dispatcher()->CheckContextAccessToExtensionAPI( 69 if (!dispatcher()->CheckContextAccessToExtensionAPI(
71 "nativeMessaging", context_)) { 70 "nativeMessaging", context())) {
72 return v8::Undefined(); 71 return v8::Undefined();
73 } 72 }
74 73
75 // Get the current RenderView so that we can send a routed IPC message from 74 // Get the current RenderView so that we can send a routed IPC message from
76 // the correct source. 75 // the correct source.
77 content::RenderView* renderview = GetRenderView(); 76 content::RenderView* renderview = GetRenderView();
78 if (!renderview) 77 if (!renderview)
79 return v8::Undefined(); 78 return v8::Undefined();
80 79
81 // The Javascript code should validate/fill the arguments. 80 // The Javascript code should validate/fill the arguments.
82 CHECK(args.Length() >= 2 && 81 CHECK(args.Length() >= 2 &&
83 args[0]->IsString() && 82 args[0]->IsString() &&
84 args[1]->IsString()); 83 args[1]->IsString());
85 84
86 std::string extension_id = *v8::String::Utf8Value(args[0]->ToString()); 85 std::string extension_id = *v8::String::Utf8Value(args[0]->ToString());
87 std::string native_app_name = *v8::String::Utf8Value(args[1]->ToString()); 86 std::string native_app_name = *v8::String::Utf8Value(args[1]->ToString());
88 87
89 int port_id = -1; 88 int port_id = -1;
90 renderview->Send(new ExtensionHostMsg_OpenChannelToNativeApp( 89 renderview->Send(new ExtensionHostMsg_OpenChannelToNativeApp(
91 renderview->GetRoutingID(), 90 renderview->GetRoutingID(),
92 extension_id, 91 extension_id,
93 native_app_name, 92 native_app_name,
94 &port_id)); 93 &port_id));
95 return v8::Integer::New(port_id); 94 return v8::Integer::New(port_id);
96 } 95 }
97 96
98 v8::Handle<v8::Value> RuntimeCustomBindings::GetManifest( 97 v8::Handle<v8::Value> RuntimeCustomBindings::GetManifest(
99 const v8::Arguments& args) { 98 const v8::Arguments& args) {
100 CHECK(context_->extension()); 99 CHECK(context()->extension());
101 100
102 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); 101 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create());
103 return converter->ToV8Value(context_->extension()->manifest()->value(), 102 return converter->ToV8Value(context()->extension()->manifest()->value(),
104 context_->v8_context()); 103 context()->v8_context());
105 } 104 }
106 105
107 } // extensions 106 } // extensions
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/runtime_custom_bindings.h ('k') | chrome/renderer/extensions/send_request_natives.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698