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

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

Issue 9460002: Convert app_bindings.js to the schema_generated_bindings.js infrastructure. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: aa comments 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
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[] = { 54 const char* kExtensionDeps[] = {
55 "extensions/event.js", 55 "extensions/event.js",
56 "extensions/json_schema.js", 56 "extensions/json_schema.js",
57 "extensions/miscellaneous_bindings.js",
58 "extensions/apitest.js"
59 }; 57 };
60 58
61 // Contains info relevant to a pending API request. 59 // Contains info relevant to a pending API request.
62 struct PendingRequest { 60 struct PendingRequest {
63 public : 61 public :
64 PendingRequest(v8::Persistent<v8::Context> context, const std::string& name, 62 PendingRequest(v8::Persistent<v8::Context> context, const std::string& name,
65 const std::string& extension_id) 63 const std::string& extension_id)
66 : context(context), name(name), extension_id(extension_id) { 64 : context(context), name(name), extension_id(extension_id) {
67 } 65 }
68 v8::Persistent<v8::Context> context; 66 v8::Persistent<v8::Context> context;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 } 133 }
136 134
137 static v8::Handle<v8::Value> GetExtensionAPIDefinition( 135 static v8::Handle<v8::Value> GetExtensionAPIDefinition(
138 const v8::Arguments& args) { 136 const v8::Arguments& args) {
139 ExtensionImpl* self = GetFromArguments<ExtensionImpl>(args); 137 ExtensionImpl* self = GetFromArguments<ExtensionImpl>(args);
140 ExtensionDispatcher* dispatcher = self->extension_dispatcher_; 138 ExtensionDispatcher* dispatcher = self->extension_dispatcher_;
141 139
142 ChromeV8Context* v8_context = dispatcher->v8_context_set().GetCurrent(); 140 ChromeV8Context* v8_context = dispatcher->v8_context_set().GetCurrent();
143 CHECK(v8_context); 141 CHECK(v8_context);
144 142
143 ExtensionAPI::SchemaMap schemas;
144
145 std::string extension_id = v8_context->extension_id(); 145 std::string extension_id = v8_context->extension_id();
146 ExtensionAPI::SchemaMap schemas; 146 // An Extension may not be found, but CHECK that as required.
147 ExtensionAPI::GetSchemasFilter filter = 147 const ::Extension* extension =
148 dispatcher->is_extension_process() ? 148 dispatcher->extensions()->GetByID(extension_id);
149 ExtensionAPI::ALL : ExtensionAPI::ONLY_UNPRIVILEGED;
150 149
151 if (dispatcher->IsTestExtensionId(extension_id)) { 150 if (dispatcher->IsTestExtensionId(extension_id)) {
152 ExtensionAPI::GetInstance()->GetDefaultSchemas(filter, &schemas); 151 ExtensionAPI::GetInstance()->GetDefaultSchemas(
152 ExtensionAPI::ONLY_UNPRIVILEGED, &schemas);
153 } else { 153 } else {
154 const ::Extension* extension = 154 switch (v8_context->context_type()) {
155 dispatcher->extensions()->GetByID(extension_id); 155 case ChromeV8Context::PRIVILEGED:
156 CHECK(extension) << extension_id << " not found"; 156 CHECK(extension) << extension_id << " not found";
157 ExtensionAPI::GetInstance()->GetSchemasForExtension( 157 ExtensionAPI::GetInstance()->GetSchemasForExtension(
Aaron Boodman 2012/02/29 01:03:58 Is it possible to consolidate this knowledge into
not at google - send to devlin 2012/03/05 07:46:54 Done. This is much nicer (I actually made it just
158 *extension, filter, &schemas); 158 *extension, ExtensionAPI::ALL, &schemas);
159 break;
160
161 case ChromeV8Context::CONTENT_SCRIPT:
162 case ChromeV8Context::UNPRIVILEGED:
163 CHECK(extension) << extension_id << " not found";
164 ExtensionAPI::GetInstance()->GetSchemasForExtension(
165 *extension, ExtensionAPI::ONLY_UNPRIVILEGED, &schemas);
166 break;
167
168 case ChromeV8Context::WEB_PAGE:
169 ExtensionAPI::GetInstance()->GetSchemasForURL(
170 UserScriptSlave::GetDataSourceURLForFrame(
171 v8_context->web_frame()),
172 &schemas);
173 break;
174 }
159 } 175 }
160 176
161 v8::Persistent<v8::Context> context(v8::Context::New()); 177 v8::Persistent<v8::Context> context(v8::Context::New());
162 v8::Context::Scope context_scope(context); 178 v8::Context::Scope context_scope(context);
163 v8::Handle<v8::Array> api(v8::Array::New(schemas.size())); 179 v8::Handle<v8::Array> api(v8::Array::New(schemas.size()));
164 size_t api_index = 0; 180 size_t api_index = 0;
165 for (ExtensionAPI::SchemaMap::iterator it = schemas.begin(); 181 for (ExtensionAPI::SchemaMap::iterator it = schemas.begin();
166 it != schemas.end(); ++it) { 182 it != schemas.end(); ++it) {
167 std::string api_name = it->first; 183 api->Set(api_index, GetV8SchemaForAPI(self, context, it->first));
168 api->Set(api_index, GetV8SchemaForAPI(self, context, api_name));
169 ++api_index; 184 ++api_index;
170 } 185 }
171 186
172 // The persistent extension_api_ will keep the context alive. 187 // The persistent extension_api_ will keep the context alive.
173 context.Dispose(); 188 context.Dispose();
174 189
175 return api; 190 return api;
176 } 191 }
177 192
178 static v8::Handle<v8::Value> GetNextRequestId(const v8::Arguments& args) { 193 static v8::Handle<v8::Value> GetNextRequestId(const v8::Arguments& args) {
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 const std::string& extension_id) { 426 const std::string& extension_id) {
412 for (PendingRequestMap::const_iterator it = g_pending_requests.Get().begin(); 427 for (PendingRequestMap::const_iterator it = g_pending_requests.Get().begin();
413 it != g_pending_requests.Get().end(); ++it) { 428 it != g_pending_requests.Get().end(); ++it) {
414 if (it->second->extension_id == extension_id) 429 if (it->second->extension_id == extension_id)
415 return true; 430 return true;
416 } 431 }
417 return false; 432 return false;
418 } 433 }
419 434
420 } // namespace 435 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698