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

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

Issue 9657026: Revert 125801 - Implement a module system for the extension bindings JS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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/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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #include "v8/include/v8.h" 44 #include "v8/include/v8.h"
45 #include "webkit/glue/webkit_glue.h" 45 #include "webkit/glue/webkit_glue.h"
46 46
47 using content::V8ValueConverter; 47 using content::V8ValueConverter;
48 using extensions::ExtensionAPI; 48 using extensions::ExtensionAPI;
49 using WebKit::WebFrame; 49 using WebKit::WebFrame;
50 using WebKit::WebSecurityOrigin; 50 using WebKit::WebSecurityOrigin;
51 51
52 namespace { 52 namespace {
53 53
54 const char* kExtensionDeps[] = {
55 "extensions/event.js",
56 "extensions/json_schema.js",
57 "extensions/miscellaneous_bindings.js",
58 "extensions/apitest.js"
59 };
60
54 // Contains info relevant to a pending API request. 61 // Contains info relevant to a pending API request.
55 struct PendingRequest { 62 struct PendingRequest {
56 public : 63 public :
57 PendingRequest(v8::Persistent<v8::Context> context, const std::string& name, 64 PendingRequest(v8::Persistent<v8::Context> context, const std::string& name,
58 const std::string& extension_id) 65 const std::string& extension_id)
59 : context(context), name(name), extension_id(extension_id) { 66 : context(context), name(name), extension_id(extension_id) {
60 } 67 }
61 v8::Persistent<v8::Context> context; 68 v8::Persistent<v8::Context> context;
62 std::string name; 69 std::string name;
63 std::string extension_id; 70 std::string extension_id;
64 }; 71 };
65 typedef std::map<int, linked_ptr<PendingRequest> > PendingRequestMap; 72 typedef std::map<int, linked_ptr<PendingRequest> > PendingRequestMap;
66 73
67 base::LazyInstance<PendingRequestMap> g_pending_requests = 74 base::LazyInstance<PendingRequestMap> g_pending_requests =
68 LAZY_INSTANCE_INITIALIZER; 75 LAZY_INSTANCE_INITIALIZER;
69 76
70 class ExtensionImpl : public ChromeV8Extension { 77 class ExtensionImpl : public ChromeV8Extension {
71 public: 78 public:
72 explicit ExtensionImpl(ExtensionDispatcher* extension_dispatcher) 79 explicit ExtensionImpl(ExtensionDispatcher* extension_dispatcher)
73 : ChromeV8Extension(extension_dispatcher) { 80 : ChromeV8Extension("extensions/schema_generated_bindings.js",
74 RouteStaticFunction("GetExtensionAPIDefinition", 81 IDR_SCHEMA_GENERATED_BINDINGS_JS,
75 &GetExtensionAPIDefinition); 82 arraysize(kExtensionDeps),
76 RouteStaticFunction("GetNextRequestId", &GetNextRequestId); 83 kExtensionDeps,
77 RouteStaticFunction("StartRequest", &StartRequest); 84 extension_dispatcher) {
78 RouteStaticFunction("SetIconCommon", &SetIconCommon);
79 } 85 }
80 86
81 ~ExtensionImpl() { 87 ~ExtensionImpl() {
82 // 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.
83 // Leaving this in here in case v8's implementation ever changes. 89 // Leaving this in here in case v8's implementation ever changes.
84 for (CachedSchemaMap::iterator it = schemas_.begin(); it != schemas_.end(); 90 for (CachedSchemaMap::iterator it = schemas_.begin(); it != schemas_.end();
85 ++it) { 91 ++it) {
86 if (!it->second.IsEmpty()) 92 if (!it->second.IsEmpty())
87 it->second.Dispose(); 93 it->second.Dispose();
88 } 94 }
89 } 95 }
90 96
97 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
98 v8::Handle<v8::String> name) OVERRIDE {
99 if (name->Equals(v8::String::New("GetExtensionAPIDefinition"))) {
100 return v8::FunctionTemplate::New(GetExtensionAPIDefinition,
101 v8::External::New(this));
102 } else if (name->Equals(v8::String::New("GetNextRequestId"))) {
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 }
114
91 private: 115 private:
92 static v8::Handle<v8::Value> GetV8SchemaForAPI( 116 static v8::Handle<v8::Value> GetV8SchemaForAPI(
93 ExtensionImpl* self, 117 ExtensionImpl* self,
94 v8::Handle<v8::Context> context, 118 v8::Handle<v8::Context> context,
95 const std::string& api_name) { 119 const std::string& api_name) {
96 CachedSchemaMap::iterator maybe_api = self->schemas_.find(api_name); 120 CachedSchemaMap::iterator maybe_api = self->schemas_.find(api_name);
97 if (maybe_api != self->schemas_.end()) 121 if (maybe_api != self->schemas_.end())
98 return maybe_api->second; 122 return maybe_api->second;
99 123
100 scoped_ptr<V8ValueConverter> v8_value_converter(V8ValueConverter::create()); 124 scoped_ptr<V8ValueConverter> v8_value_converter(V8ValueConverter::create());
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 // We store this so that we don't have to parse it over and over again for 340 // We store this so that we don't have to parse it over and over again for
317 // every context that uses it. 341 // every context that uses it.
318 typedef std::map<std::string, v8::Persistent<v8::Object> > CachedSchemaMap; 342 typedef std::map<std::string, v8::Persistent<v8::Object> > CachedSchemaMap;
319 CachedSchemaMap schemas_; 343 CachedSchemaMap schemas_;
320 }; 344 };
321 345
322 } // namespace 346 } // namespace
323 347
324 namespace extensions { 348 namespace extensions {
325 349
326 ChromeV8Extension* SchemaGeneratedBindings::Get( 350 v8::Extension* SchemaGeneratedBindings::Get(
327 ExtensionDispatcher* extension_dispatcher) { 351 ExtensionDispatcher* extension_dispatcher) {
328 return new ExtensionImpl(extension_dispatcher); 352 static v8::Extension* extension = new ExtensionImpl(extension_dispatcher);
353 CHECK_EQ(extension_dispatcher,
354 static_cast<ExtensionImpl*>(extension)->extension_dispatcher());
355 return extension;
329 } 356 }
330 357
331 // static 358 // static
332 void SchemaGeneratedBindings::HandleResponse(const ChromeV8ContextSet& contexts, 359 void SchemaGeneratedBindings::HandleResponse(const ChromeV8ContextSet& contexts,
333 int request_id, 360 int request_id,
334 bool success, 361 bool success,
335 const std::string& response, 362 const std::string& response,
336 const std::string& error, 363 const std::string& error,
337 std::string* extension_id) { 364 std::string* extension_id) {
338 PendingRequestMap::iterator request = 365 PendingRequestMap::iterator request =
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 const std::string& extension_id) { 411 const std::string& extension_id) {
385 for (PendingRequestMap::const_iterator it = g_pending_requests.Get().begin(); 412 for (PendingRequestMap::const_iterator it = g_pending_requests.Get().begin();
386 it != g_pending_requests.Get().end(); ++it) { 413 it != g_pending_requests.Get().end(); ++it) {
387 if (it->second->extension_id == extension_id) 414 if (it->second->extension_id == extension_id)
388 return true; 415 return true;
389 } 416 }
390 return false; 417 return false;
391 } 418 }
392 419
393 } // namespace 420 } // namespace
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/schema_generated_bindings.h ('k') | chrome/renderer/extensions/tabs_custom_bindings.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698