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

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: 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 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 142
145 std::string extension_id = v8_context->extension_id(); 143 std::string extension_id = v8_context->extension_id();
146 ExtensionAPI::SchemaMap schemas; 144 ExtensionAPI::SchemaMap schemas;
147 ExtensionAPI::GetSchemasFilter filter = 145 ExtensionAPI::GetSchemasFilter filter =
148 dispatcher->is_extension_process() ? 146 dispatcher->is_extension_process() ?
149 ExtensionAPI::ALL : ExtensionAPI::ONLY_UNPRIVILEGED; 147 ExtensionAPI::ALL : ExtensionAPI::ONLY_UNPRIVILEGED;
150 148
151 if (dispatcher->IsTestExtensionId(extension_id)) { 149 if (dispatcher->IsTestExtensionId(extension_id)) {
152 ExtensionAPI::GetInstance()->GetDefaultSchemas(filter, &schemas); 150 ExtensionAPI::GetInstance()->GetDefaultSchemas(filter, &schemas);
153 } else { 151 } else {
154 const ::Extension* extension = 152 // UNPRIVILEGED context_type refers to the v8 context this request is
153 // from (as opposed to an extension or content script context), and isn't
154 // related to "unprivileged" in the extension API sense. This distinction
155 // will be sanitized soon, when ExtensionAPI uses Features.
156 if (v8_context->context_type() == ChromeV8Context::UNPRIVILEGED) {
157 GURL frame_url =
158 UserScriptSlave::GetDataSourceURLForFrame(v8_context->web_frame());
159 ExtensionAPI::GetInstance()->GetSchemasForURL(frame_url, &schemas);
160 } else {
161 const ::Extension* extension =
155 dispatcher->extensions()->GetByID(extension_id); 162 dispatcher->extensions()->GetByID(extension_id);
156 CHECK(extension) << extension_id << " not found"; 163 CHECK(extension) << extension_id << " not found";
157 ExtensionAPI::GetInstance()->GetSchemasForExtension( 164 ExtensionAPI::GetInstance()->GetSchemasForExtension(
158 *extension, filter, &schemas); 165 *extension, filter, &schemas);
166 }
159 } 167 }
160 168
161 v8::Persistent<v8::Context> context(v8::Context::New()); 169 v8::Persistent<v8::Context> context(v8::Context::New());
162 v8::Context::Scope context_scope(context); 170 v8::Context::Scope context_scope(context);
163 v8::Handle<v8::Array> api(v8::Array::New(schemas.size())); 171 v8::Handle<v8::Array> api(v8::Array::New(schemas.size()));
164 size_t api_index = 0; 172 size_t api_index = 0;
165 for (ExtensionAPI::SchemaMap::iterator it = schemas.begin(); 173 for (ExtensionAPI::SchemaMap::iterator it = schemas.begin();
166 it != schemas.end(); ++it) { 174 it != schemas.end(); ++it) {
167 std::string api_name = it->first; 175 api->Set(api_index, GetV8SchemaForAPI(self, context, it->first));
168 api->Set(api_index, GetV8SchemaForAPI(self, context, api_name));
169 ++api_index; 176 ++api_index;
170 } 177 }
171 178
172 // The persistent extension_api_ will keep the context alive. 179 // The persistent extension_api_ will keep the context alive.
173 context.Dispose(); 180 context.Dispose();
174 181
175 return api; 182 return api;
176 } 183 }
177 184
178 static v8::Handle<v8::Value> GetNextRequestId(const v8::Arguments& args) { 185 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) { 418 const std::string& extension_id) {
412 for (PendingRequestMap::const_iterator it = g_pending_requests.Get().begin(); 419 for (PendingRequestMap::const_iterator it = g_pending_requests.Get().begin();
413 it != g_pending_requests.Get().end(); ++it) { 420 it != g_pending_requests.Get().end(); ++it) {
414 if (it->second->extension_id == extension_id) 421 if (it->second->extension_id == extension_id)
415 return true; 422 return true;
416 } 423 }
417 return false; 424 return false;
418 } 425 }
419 426
420 } // namespace 427 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698