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

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

Issue 11571014: Lazy load chrome.* APIs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: android compilation 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/miscellaneous_bindings.h" 5 #include "chrome/renderer/extensions/miscellaneous_bindings.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 static void ClearPortData(int port_id) { 61 static void ClearPortData(int port_id) {
62 g_extension_data.Get().ports.erase(port_id); 62 g_extension_data.Get().ports.erase(port_id);
63 } 63 }
64 64
65 const char kPortClosedError[] = "Attempting to use a disconnected port object"; 65 const char kPortClosedError[] = "Attempting to use a disconnected port object";
66 const char kReceivingEndDoesntExistError[] = 66 const char kReceivingEndDoesntExistError[] =
67 "Could not establish connection. Receiving end does not exist."; 67 "Could not establish connection. Receiving end does not exist.";
68 68
69 class ExtensionImpl : public extensions::ChromeV8Extension { 69 class ExtensionImpl : public extensions::ChromeV8Extension {
70 public: 70 public:
71 explicit ExtensionImpl(extensions::Dispatcher* dispatcher) 71 explicit ExtensionImpl(extensions::Dispatcher* dispatcher,
72 : extensions::ChromeV8Extension(dispatcher) { 72 v8::Handle<v8::Context> context)
73 : extensions::ChromeV8Extension(dispatcher, context) {
73 RouteStaticFunction("CloseChannel", &CloseChannel); 74 RouteStaticFunction("CloseChannel", &CloseChannel);
74 RouteStaticFunction("PortAddRef", &PortAddRef); 75 RouteStaticFunction("PortAddRef", &PortAddRef);
75 RouteStaticFunction("PortRelease", &PortRelease); 76 RouteStaticFunction("PortRelease", &PortRelease);
76 RouteStaticFunction("PostMessage", &PostMessage); 77 RouteStaticFunction("PostMessage", &PostMessage);
77 RouteStaticFunction("BindToGC", &BindToGC); 78 RouteStaticFunction("BindToGC", &BindToGC);
78 } 79 }
79 80
80 virtual ~ExtensionImpl() {} 81 virtual ~ExtensionImpl() {}
81 82
82 // Sends a message along the given channel. 83 // Sends a message along the given channel.
83 static v8::Handle<v8::Value> PostMessage(const v8::Arguments& args) { 84 static v8::Handle<v8::Value> PostMessage(const v8::Arguments& args) {
84 content::RenderView* renderview = GetCurrentRenderView(); 85 ExtensionImpl* self = GetFromArguments<ExtensionImpl>(args);
86 content::RenderView* renderview = self->GetRenderView();
85 if (!renderview) 87 if (!renderview)
86 return v8::Undefined(); 88 return v8::Undefined();
87 89
88 if (args.Length() >= 2 && args[0]->IsInt32() && args[1]->IsString()) { 90 if (args.Length() >= 2 && args[0]->IsInt32() && args[1]->IsString()) {
89 int port_id = args[0]->Int32Value(); 91 int port_id = args[0]->Int32Value();
90 if (!HasPortData(port_id)) { 92 if (!HasPortData(port_id)) {
91 return v8::ThrowException(v8::Exception::Error( 93 return v8::ThrowException(v8::Exception::Error(
92 v8::String::New(kPortClosedError))); 94 v8::String::New(kPortClosedError)));
93 } 95 }
94 std::string message = *v8::String::Utf8Value(args[1]->ToString()); 96 std::string message = *v8::String::Utf8Value(args[1]->ToString());
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 NOTREACHED(); 176 NOTREACHED();
175 } 177 }
176 return v8::Undefined(); 178 return v8::Undefined();
177 } 179 }
178 }; 180 };
179 181
180 } // namespace 182 } // namespace
181 183
182 namespace extensions { 184 namespace extensions {
183 185
184 ChromeV8Extension* MiscellaneousBindings::Get(Dispatcher* dispatcher) { 186 ChromeV8Extension* MiscellaneousBindings::Get(
185 return new ExtensionImpl(dispatcher); 187 Dispatcher* dispatcher,
188 v8::Handle<v8::Context> context) {
189 return new ExtensionImpl(dispatcher, context);
186 } 190 }
187 191
188 // static 192 // static
189 void MiscellaneousBindings::DispatchOnConnect( 193 void MiscellaneousBindings::DispatchOnConnect(
190 const ChromeV8ContextSet::ContextSet& contexts, 194 const ChromeV8ContextSet::ContextSet& contexts,
191 int target_port_id, 195 int target_port_id,
192 const std::string& channel_name, 196 const std::string& channel_name,
193 const std::string& tab_json, 197 const std::string& tab_json,
194 const std::string& source_extension_id, 198 const std::string& source_extension_id,
195 const std::string& target_extension_id, 199 const std::string& target_extension_id,
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 } else { 317 } else {
314 arguments.push_back(v8::Null()); 318 arguments.push_back(v8::Null());
315 } 319 }
316 (*it)->CallChromeHiddenMethod("Port.dispatchOnDisconnect", 320 (*it)->CallChromeHiddenMethod("Port.dispatchOnDisconnect",
317 arguments.size(), &arguments[0], 321 arguments.size(), &arguments[0],
318 NULL); 322 NULL);
319 } 323 }
320 } 324 }
321 325
322 } // namespace extensions 326 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/miscellaneous_bindings.h ('k') | chrome/renderer/extensions/module_system.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698