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

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: make test extension ID tests pass 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 13 matching lines...) Expand all
24 #include "chrome/common/extensions/api/extension_api.h" 24 #include "chrome/common/extensions/api/extension_api.h"
25 #include "chrome/common/render_messages.h" 25 #include "chrome/common/render_messages.h"
26 #include "chrome/renderer/chrome_render_process_observer.h" 26 #include "chrome/renderer/chrome_render_process_observer.h"
27 #include "chrome/renderer/extensions/chrome_v8_context.h" 27 #include "chrome/renderer/extensions/chrome_v8_context.h"
28 #include "chrome/renderer/extensions/chrome_v8_context_set.h" 28 #include "chrome/renderer/extensions/chrome_v8_context_set.h"
29 #include "chrome/renderer/extensions/chrome_v8_extension.h" 29 #include "chrome/renderer/extensions/chrome_v8_extension.h"
30 #include "chrome/renderer/extensions/event_bindings.h" 30 #include "chrome/renderer/extensions/event_bindings.h"
31 #include "chrome/renderer/extensions/extension_dispatcher.h" 31 #include "chrome/renderer/extensions/extension_dispatcher.h"
32 #include "chrome/renderer/extensions/miscellaneous_bindings.h" 32 #include "chrome/renderer/extensions/miscellaneous_bindings.h"
33 #include "chrome/renderer/extensions/user_script_slave.h" 33 #include "chrome/renderer/extensions/user_script_slave.h"
34 #include "content/public/renderer/render_thread.h"
34 #include "content/public/renderer/render_view.h" 35 #include "content/public/renderer/render_view.h"
35 #include "content/public/renderer/v8_value_converter.h" 36 #include "content/public/renderer/v8_value_converter.h"
36 #include "grit/common_resources.h" 37 #include "grit/common_resources.h"
37 #include "grit/renderer_resources.h" 38 #include "grit/renderer_resources.h"
38 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 39 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
39 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 40 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
40 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" 41 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
41 #include "third_party/skia/include/core/SkBitmap.h" 42 #include "third_party/skia/include/core/SkBitmap.h"
42 #include "third_party/skia/include/core/SkColor.h" 43 #include "third_party/skia/include/core/SkColor.h"
43 #include "ui/base/resource/resource_bundle.h" 44 #include "ui/base/resource/resource_bundle.h"
44 #include "v8/include/v8.h" 45 #include "v8/include/v8.h"
45 #include "webkit/glue/webkit_glue.h" 46 #include "webkit/glue/webkit_glue.h"
46 47
48 using content::RenderThread;
47 using content::V8ValueConverter; 49 using content::V8ValueConverter;
48 using extensions::ExtensionAPI; 50 using extensions::ExtensionAPI;
51 using extensions::Feature;
49 using WebKit::WebFrame; 52 using WebKit::WebFrame;
50 using WebKit::WebSecurityOrigin; 53 using WebKit::WebSecurityOrigin;
51 54
52 namespace { 55 namespace {
53 56
54 // Contains info relevant to a pending API request. 57 // Contains info relevant to a pending API request.
55 struct PendingRequest { 58 struct PendingRequest {
56 public : 59 public :
57 PendingRequest(v8::Persistent<v8::Context> context, const std::string& name, 60 PendingRequest(v8::Persistent<v8::Context> context, const std::string& name,
58 const std::string& extension_id) 61 const std::string& extension_id)
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 } 114 }
112 115
113 static v8::Handle<v8::Value> GetExtensionAPIDefinition( 116 static v8::Handle<v8::Value> GetExtensionAPIDefinition(
114 const v8::Arguments& args) { 117 const v8::Arguments& args) {
115 ExtensionImpl* self = GetFromArguments<ExtensionImpl>(args); 118 ExtensionImpl* self = GetFromArguments<ExtensionImpl>(args);
116 ExtensionDispatcher* dispatcher = self->extension_dispatcher_; 119 ExtensionDispatcher* dispatcher = self->extension_dispatcher_;
117 120
118 ChromeV8Context* v8_context = dispatcher->v8_context_set().GetCurrent(); 121 ChromeV8Context* v8_context = dispatcher->v8_context_set().GetCurrent();
119 CHECK(v8_context); 122 CHECK(v8_context);
120 123
121 std::string extension_id = v8_context->extension_id(); 124 // TODO(kalman): This is being calculated twice, first in
122 ExtensionAPI::SchemaMap schemas; 125 // ExtensionDispatcher then again here. It might as well be a property of
123 ExtensionAPI::GetSchemasFilter filter = 126 // ChromeV8Context, however, this would require making ChromeV8Context take
124 dispatcher->is_extension_process() ? 127 // an Extension rather than an extension ID. In itself this is fine,
125 ExtensionAPI::ALL : ExtensionAPI::ONLY_UNPRIVILEGED; 128 // however it does not play correctly with the "IsTestExtensionId" checks.
129 // We need to remove that first.
130 scoped_ptr<std::set<std::string> > apis;
126 131
132 const std::string& extension_id = v8_context->extension_id();
127 if (dispatcher->IsTestExtensionId(extension_id)) { 133 if (dispatcher->IsTestExtensionId(extension_id)) {
128 ExtensionAPI::GetInstance()->GetDefaultSchemas(filter, &schemas); 134 apis.reset(new std::set<std::string>());
135 // The minimal set of APIs that tests need.
136 apis->insert("extension");
129 } else { 137 } else {
130 const ::Extension* extension = 138 apis = ExtensionAPI::GetInstance()->GetAPIsForContext(
131 dispatcher->extensions()->GetByID(extension_id); 139 v8_context->context_type(),
132 CHECK(extension) << extension_id << " not found"; 140 dispatcher->extensions()->GetByID(extension_id),
133 ExtensionAPI::GetInstance()->GetSchemasForExtension( 141 UserScriptSlave::GetDataSourceURLForFrame(v8_context->web_frame()));
134 *extension, filter, &schemas);
135 } 142 }
136 143
137 v8::Persistent<v8::Context> context(v8::Context::New()); 144 v8::Persistent<v8::Context> context(v8::Context::New());
138 v8::Context::Scope context_scope(context); 145 v8::Context::Scope context_scope(context);
139 v8::Handle<v8::Array> api(v8::Array::New(schemas.size())); 146 v8::Handle<v8::Array> api(v8::Array::New(apis->size()));
140 size_t api_index = 0; 147 size_t api_index = 0;
141 for (ExtensionAPI::SchemaMap::iterator it = schemas.begin(); 148 for (std::set<std::string>::iterator i = apis->begin(); i != apis->end();
142 it != schemas.end(); ++it) { 149 ++i) {
143 std::string api_name = it->first; 150 // TODO(kalman): this caching is actually useless now, because
144 api->Set(api_index, GetV8SchemaForAPI(self, context, api_name)); 151 // SchemaGeneratedBindings is per-context not per-process. We should
152 // (e.g.) hang a SchemaRegistry off ExtensionDispatcher (which maintains
153 // a *single* v8::Context rather than multiple ones as here).
154 api->Set(api_index, GetV8SchemaForAPI(self, context, *i));
145 ++api_index; 155 ++api_index;
146 } 156 }
147 157
148 // The persistent extension_api_ will keep the context alive. 158 // The persistent extension_api_ will keep the context alive.
149 context.Dispose(); 159 context.Dispose();
150 160
151 return api; 161 return api;
152 } 162 }
153 163
154 static v8::Handle<v8::Value> GetNextRequestId(const v8::Arguments& args) { 164 static v8::Handle<v8::Value> GetNextRequestId(const v8::Arguments& args) {
(...skipping 161 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 326 // We store this so that we don't have to parse it over and over again for
317 // every context that uses it. 327 // every context that uses it.
318 typedef std::map<std::string, v8::Persistent<v8::Object> > CachedSchemaMap; 328 typedef std::map<std::string, v8::Persistent<v8::Object> > CachedSchemaMap;
319 CachedSchemaMap schemas_; 329 CachedSchemaMap schemas_;
320 }; 330 };
321 331
322 } // namespace 332 } // namespace
323 333
324 namespace extensions { 334 namespace extensions {
325 335
336 // static
326 ChromeV8Extension* SchemaGeneratedBindings::Get( 337 ChromeV8Extension* SchemaGeneratedBindings::Get(
327 ExtensionDispatcher* extension_dispatcher) { 338 ExtensionDispatcher* extension_dispatcher) {
328 return new ExtensionImpl(extension_dispatcher); 339 return new ExtensionImpl(extension_dispatcher);
329 } 340 }
330 341
331 // static 342 // static
332 void SchemaGeneratedBindings::HandleResponse(const ChromeV8ContextSet& contexts, 343 void SchemaGeneratedBindings::HandleResponse(const ChromeV8ContextSet& contexts,
333 int request_id, 344 int request_id,
334 bool success, 345 bool success,
335 const std::string& response, 346 const std::string& response,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 const std::string& extension_id) { 395 const std::string& extension_id) {
385 for (PendingRequestMap::const_iterator it = g_pending_requests.Get().begin(); 396 for (PendingRequestMap::const_iterator it = g_pending_requests.Get().begin();
386 it != g_pending_requests.Get().end(); ++it) { 397 it != g_pending_requests.Get().end(); ++it) {
387 if (it->second->extension_id == extension_id) 398 if (it->second->extension_id == extension_id)
388 return true; 399 return true;
389 } 400 }
390 return false; 401 return false;
391 } 402 }
392 403
393 } // namespace 404 } // namespace
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/extension_dispatcher.cc ('k') | chrome/renderer/renderer_resources.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698