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

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

Issue 15091002: Lazily load API schemas from resource files and convert all APIs to features (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix chromeos tests Created 7 years, 6 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/v8_schema_registry.h" 5 #include "chrome/renderer/extensions/v8_schema_registry.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/common/extensions/api/extension_api.h" 9 #include "chrome/common/extensions/api/extension_api.h"
10 #include "chrome/renderer/extensions/chrome_v8_context.h" 10 #include "chrome/renderer/extensions/chrome_v8_context.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 scoped_ptr<ChromeV8Context> context(new ChromeV8Context( 53 scoped_ptr<ChromeV8Context> context(new ChromeV8Context(
54 GetOrCreateContext(v8::Isolate::GetCurrent()), 54 GetOrCreateContext(v8::Isolate::GetCurrent()),
55 NULL, // no frame 55 NULL, // no frame
56 NULL, // no extension 56 NULL, // no extension
57 Feature::UNSPECIFIED_CONTEXT)); 57 Feature::UNSPECIFIED_CONTEXT));
58 return scoped_ptr<NativeHandler>( 58 return scoped_ptr<NativeHandler>(
59 new SchemaRegistryNativeHandler(this, context.Pass())); 59 new SchemaRegistryNativeHandler(this, context.Pass()));
60 } 60 }
61 61
62 v8::Handle<v8::Array> V8SchemaRegistry::GetSchemas( 62 v8::Handle<v8::Array> V8SchemaRegistry::GetSchemas(
63 const std::set<std::string>& apis) { 63 const std::vector<std::string>& apis) {
64 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 64 v8::Isolate* isolate = v8::Isolate::GetCurrent();
65 v8::HandleScope handle_scope(isolate); 65 v8::HandleScope handle_scope(isolate);
66 v8::Context::Scope context_scope(GetOrCreateContext(isolate)); 66 v8::Context::Scope context_scope(GetOrCreateContext(isolate));
67 67
68 v8::Handle<v8::Array> v8_apis(v8::Array::New(apis.size())); 68 v8::Handle<v8::Array> v8_apis(v8::Array::New(apis.size()));
69 size_t api_index = 0; 69 size_t api_index = 0;
70 for (std::set<std::string>::const_iterator i = apis.begin(); i != apis.end(); 70 for (std::vector<std::string>::const_iterator i = apis.begin();
71 ++i) { 71 i != apis.end(); ++i) {
72 v8_apis->Set(api_index++, GetSchema(*i)); 72 v8_apis->Set(api_index++, GetSchema(*i));
73 } 73 }
74 return handle_scope.Close(v8_apis); 74 return handle_scope.Close(v8_apis);
75 } 75 }
76 76
77 v8::Handle<v8::Object> V8SchemaRegistry::GetSchema(const std::string& api) { 77 v8::Handle<v8::Object> V8SchemaRegistry::GetSchema(const std::string& api) {
78 78
79 SchemaCache::iterator maybe_schema = schema_cache_.find(api); 79 SchemaCache::iterator maybe_schema = schema_cache_.find(api);
80 if (maybe_schema != schema_cache_.end()) 80 if (maybe_schema != schema_cache_.end())
81 return maybe_schema->second.newLocal(v8::Isolate::GetCurrent()); 81 return maybe_schema->second.newLocal(v8::Isolate::GetCurrent());
(...skipping 24 matching lines...) Expand all
106 // when we have a HandleScope. 106 // when we have a HandleScope.
107 if (context_.get().IsEmpty()) { 107 if (context_.get().IsEmpty()) {
108 v8::Handle<v8::Context> context = v8::Context::New(isolate); 108 v8::Handle<v8::Context> context = v8::Context::New(isolate);
109 context_.reset(context); 109 context_.reset(context);
110 return context; 110 return context;
111 } 111 }
112 return v8::Local<v8::Context>::New(isolate, context_.get()); 112 return v8::Local<v8::Context>::New(isolate, context_.get());
113 } 113 }
114 114
115 } // namespace extensions 115 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/v8_schema_registry.h ('k') | chrome/renderer/resources/extensions/test_custom_bindings.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698