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

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

Issue 11571014: Lazy load chrome.* APIs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: windows interactive_ui_tests fix 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 "content/public/renderer/render_view.h" 14 #include "content/public/renderer/render_view.h"
15 #include "content/public/renderer/v8_value_converter.h" 15 #include "content/public/renderer/v8_value_converter.h"
16 16
17 using content::V8ValueConverter; 17 using content::V8ValueConverter;
18 18
19 namespace extensions { 19 namespace extensions {
20 20
21 RuntimeCustomBindings::RuntimeCustomBindings(ChromeV8Context* context) 21 RuntimeCustomBindings::RuntimeCustomBindings(Dispatcher* dispatcher,
22 : ChromeV8Extension(NULL), context_(context) { 22 ChromeV8Context* context)
23 : ChromeV8Extension(dispatcher, context->v8_context()),
24 context_(context) {
23 RouteFunction("GetManifest", 25 RouteFunction("GetManifest",
24 base::Bind(&RuntimeCustomBindings::GetManifest, base::Unretained(this))); 26 base::Bind(&RuntimeCustomBindings::GetManifest, base::Unretained(this)));
25 RouteStaticFunction("OpenChannelToExtension", &OpenChannelToExtension); 27 RouteStaticFunction("OpenChannelToExtension", &OpenChannelToExtension);
26 RouteStaticFunction("OpenChannelToNativeApp", &OpenChannelToNativeApp); 28 RouteStaticFunction("OpenChannelToNativeApp", &OpenChannelToNativeApp);
27 } 29 }
28 30
29 RuntimeCustomBindings::~RuntimeCustomBindings() {} 31 RuntimeCustomBindings::~RuntimeCustomBindings() {}
30 32
31 // static 33 // static
32 v8::Handle<v8::Value> RuntimeCustomBindings::OpenChannelToExtension( 34 v8::Handle<v8::Value> RuntimeCustomBindings::OpenChannelToExtension(
33 const v8::Arguments& args) { 35 const v8::Arguments& args) {
34 // Get the current RenderView so that we can send a routed IPC message from 36 // Get the current RenderView so that we can send a routed IPC message from
35 // the correct source. 37 // the correct source.
36 content::RenderView* renderview = GetCurrentRenderView(); 38 RuntimeCustomBindings* self = GetFromArguments<RuntimeCustomBindings>(args);
39 content::RenderView* renderview = self->GetRenderView();
37 if (!renderview) 40 if (!renderview)
38 return v8::Undefined(); 41 return v8::Undefined();
39 42
40 // The Javascript code should validate/fill the arguments. 43 // The Javascript code should validate/fill the arguments.
41 CHECK(args.Length() >= 3 && 44 CHECK(args.Length() >= 3 &&
42 args[0]->IsString() && 45 args[0]->IsString() &&
43 args[1]->IsString() && 46 args[1]->IsString() &&
44 args[2]->IsString()); 47 args[2]->IsString());
45 48
46 std::string source_id = *v8::String::Utf8Value(args[0]->ToString()); 49 std::string source_id = *v8::String::Utf8Value(args[0]->ToString());
47 std::string target_id = *v8::String::Utf8Value(args[1]->ToString()); 50 std::string target_id = *v8::String::Utf8Value(args[1]->ToString());
48 std::string channel_name = *v8::String::Utf8Value(args[2]->ToString()); 51 std::string channel_name = *v8::String::Utf8Value(args[2]->ToString());
49 int port_id = -1; 52 int port_id = -1;
50 renderview->Send(new ExtensionHostMsg_OpenChannelToExtension( 53 renderview->Send(new ExtensionHostMsg_OpenChannelToExtension(
51 renderview->GetRoutingID(), 54 renderview->GetRoutingID(),
52 source_id, 55 source_id,
53 target_id, 56 target_id,
54 channel_name, 57 channel_name,
55 &port_id)); 58 &port_id));
56 return v8::Integer::New(port_id); 59 return v8::Integer::New(port_id);
57 } 60 }
58 61
59 // static 62 // static
60 v8::Handle<v8::Value> RuntimeCustomBindings::OpenChannelToNativeApp( 63 v8::Handle<v8::Value> RuntimeCustomBindings::OpenChannelToNativeApp(
61 const v8::Arguments& args) { 64 const v8::Arguments& args) {
62 // Get the current RenderView so that we can send a routed IPC message from 65 // Get the current RenderView so that we can send a routed IPC message from
63 // the correct source. 66 // the correct source.
64 content::RenderView* renderview = GetCurrentRenderView(); 67 RuntimeCustomBindings* self = GetFromArguments<RuntimeCustomBindings>(args);
68 content::RenderView* renderview = self->GetRenderView();
65 if (!renderview) 69 if (!renderview)
66 return v8::Undefined(); 70 return v8::Undefined();
67 71
68 // The Javascript code should validate/fill the arguments. 72 // The Javascript code should validate/fill the arguments.
69 CHECK(args.Length() >= 2 && 73 CHECK(args.Length() >= 2 &&
70 args[0]->IsString() && 74 args[0]->IsString() &&
71 args[1]->IsString()); 75 args[1]->IsString());
72 76
73 std::string extension_id = *v8::String::Utf8Value(args[0]->ToString()); 77 std::string extension_id = *v8::String::Utf8Value(args[0]->ToString());
74 std::string native_app_name = *v8::String::Utf8Value(args[1]->ToString()); 78 std::string native_app_name = *v8::String::Utf8Value(args[1]->ToString());
(...skipping 10 matching lines...) Expand all
85 v8::Handle<v8::Value> RuntimeCustomBindings::GetManifest( 89 v8::Handle<v8::Value> RuntimeCustomBindings::GetManifest(
86 const v8::Arguments& args) { 90 const v8::Arguments& args) {
87 CHECK(context_->extension()); 91 CHECK(context_->extension());
88 92
89 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); 93 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create());
90 return converter->ToV8Value(context_->extension()->manifest()->value(), 94 return converter->ToV8Value(context_->extension()->manifest()->value(),
91 context_->v8_context()); 95 context_->v8_context());
92 } 96 }
93 97
94 } // extensions 98 } // extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698