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

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

Issue 9386001: Implement a module system for the extension bindings JS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 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/schema_generated_bindings.h" 5 #include "chrome/renderer/extensions/schema_generated_bindings.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 10
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 ~ExtensionImpl() { 87 ~ExtensionImpl() {
88 // TODO(aa): It seems that v8 never deletes us, so this doesn't get called. 88 // TODO(aa): It seems that v8 never deletes us, so this doesn't get called.
89 // Leaving this in here in case v8's implementation ever changes. 89 // Leaving this in here in case v8's implementation ever changes.
90 for (CachedSchemaMap::iterator it = schemas_.begin(); it != schemas_.end(); 90 for (CachedSchemaMap::iterator it = schemas_.begin(); it != schemas_.end();
91 ++it) { 91 ++it) {
92 if (!it->second.IsEmpty()) 92 if (!it->second.IsEmpty())
93 it->second.Dispose(); 93 it->second.Dispose();
94 } 94 }
95 } 95 }
96 96
97 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( 97 void SetNativeFunctions(v8::Handle<v8::Object> object) {
98 v8::Handle<v8::String> name) OVERRIDE { 98 RouteFunctionToStatic("GetExtensionAPIDefinition",
99 if (name->Equals(v8::String::New("GetExtensionAPIDefinition"))) { 99 GetExtensionAPIDefinition, object);
100 return v8::FunctionTemplate::New(GetExtensionAPIDefinition, 100 RouteFunctionToStatic("GetNextRequestId", GetNextRequestId, object);
101 v8::External::New(this)); 101 RouteFunctionToStatic("StartRequest", StartRequest, object);
102 } else if (name->Equals(v8::String::New("GetNextRequestId"))) { 102 RouteFunctionToStatic("SetIconCommon", SetIconCommon, object);
103 return v8::FunctionTemplate::New(GetNextRequestId);
104 } else if (name->Equals(v8::String::New("StartRequest"))) {
105 return v8::FunctionTemplate::New(StartRequest,
106 v8::External::New(this));
107 } else if (name->Equals(v8::String::New("SetIconCommon"))) {
108 return v8::FunctionTemplate::New(SetIconCommon,
109 v8::External::New(this));
110 }
111
112 return ChromeV8Extension::GetNativeFunction(name);
113 } 103 }
114 104
115 private: 105 private:
116 static v8::Handle<v8::Value> GetV8SchemaForAPI( 106 static v8::Handle<v8::Value> GetV8SchemaForAPI(
117 ExtensionImpl* self, 107 ExtensionImpl* self,
118 v8::Handle<v8::Context> context, 108 v8::Handle<v8::Context> context,
119 const std::string& api_name) { 109 const std::string& api_name) {
120 CachedSchemaMap::iterator maybe_api = self->schemas_.find(api_name); 110 CachedSchemaMap::iterator maybe_api = self->schemas_.find(api_name);
121 if (maybe_api != self->schemas_.end()) 111 if (maybe_api != self->schemas_.end())
122 return maybe_api->second; 112 return maybe_api->second;
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 // We store this so that we don't have to parse it over and over again for 325 // We store this so that we don't have to parse it over and over again for
336 // every context that uses it. 326 // every context that uses it.
337 typedef std::map<std::string, v8::Persistent<v8::Object> > CachedSchemaMap; 327 typedef std::map<std::string, v8::Persistent<v8::Object> > CachedSchemaMap;
338 CachedSchemaMap schemas_; 328 CachedSchemaMap schemas_;
339 }; 329 };
340 330
341 } // namespace 331 } // namespace
342 332
343 namespace extensions { 333 namespace extensions {
344 334
345 v8::Extension* SchemaGeneratedBindings::Get( 335 ChromeV8Extension* SchemaGeneratedBindings::Get(
346 ExtensionDispatcher* extension_dispatcher) { 336 ExtensionDispatcher* extension_dispatcher) {
347 static v8::Extension* extension = new ExtensionImpl(extension_dispatcher); 337 return new ExtensionImpl(extension_dispatcher);
348 CHECK_EQ(extension_dispatcher,
349 static_cast<ExtensionImpl*>(extension)->extension_dispatcher());
350 return extension;
351 } 338 }
352 339
353 // static 340 // static
354 void SchemaGeneratedBindings::HandleResponse(const ChromeV8ContextSet& contexts, 341 void SchemaGeneratedBindings::HandleResponse(const ChromeV8ContextSet& contexts,
355 int request_id, 342 int request_id,
356 bool success, 343 bool success,
357 const std::string& response, 344 const std::string& response,
358 const std::string& error, 345 const std::string& error,
359 std::string* extension_id) { 346 std::string* extension_id) {
360 PendingRequestMap::iterator request = 347 PendingRequestMap::iterator request =
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 const std::string& extension_id) { 393 const std::string& extension_id) {
407 for (PendingRequestMap::const_iterator it = g_pending_requests.Get().begin(); 394 for (PendingRequestMap::const_iterator it = g_pending_requests.Get().begin();
408 it != g_pending_requests.Get().end(); ++it) { 395 it != g_pending_requests.Get().end(); ++it) {
409 if (it->second->extension_id == extension_id) 396 if (it->second->extension_id == extension_id)
410 return true; 397 return true;
411 } 398 }
412 return false; 399 return false;
413 } 400 }
414 401
415 } // namespace 402 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698