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

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

Issue 11571014: Lazy load chrome.* APIs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: android compilation Created 7 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/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 "content/public/renderer/v8_value_converter.h" 10 #include "content/public/renderer/v8_value_converter.h"
11 11
12 using content::V8ValueConverter; 12 using content::V8ValueConverter;
13 13
14 namespace extensions { 14 namespace extensions {
15 15
16 V8SchemaRegistry::V8SchemaRegistry() : context_(v8::Context::New()) {} 16 V8SchemaRegistry::V8SchemaRegistry() : context_(v8::Context::New()) {}
17 17
18 V8SchemaRegistry::~V8SchemaRegistry() { 18 V8SchemaRegistry::~V8SchemaRegistry() {
19 v8::Isolate* isolate = context_->GetIsolate(); 19 v8::Isolate* isolate = context_->GetIsolate();
20 for (SchemaCache::iterator i = schema_cache_.begin(); 20 for (SchemaCache::iterator i = schema_cache_.begin();
21 i != schema_cache_.end(); ++i) { 21 i != schema_cache_.end(); ++i) {
22 i->second.Dispose(isolate); 22 i->second.Dispose(isolate);
23 } 23 }
24 context_.Dispose(isolate);
25 } 24 }
26 25
27 v8::Handle<v8::Array> V8SchemaRegistry::GetSchemas( 26 v8::Handle<v8::Array> V8SchemaRegistry::GetSchemas(
28 const std::set<std::string>& apis) { 27 const std::set<std::string>& apis) {
29 v8::Context::Scope context_scope(context_); 28 v8::Context::Scope context_scope(context_.get());
30 v8::Handle<v8::Array> v8_apis(v8::Array::New(apis.size())); 29 v8::Handle<v8::Array> v8_apis(v8::Array::New(apis.size()));
31 size_t api_index = 0; 30 size_t api_index = 0;
32 for (std::set<std::string>::const_iterator i = apis.begin(); i != apis.end(); 31 for (std::set<std::string>::const_iterator i = apis.begin(); i != apis.end();
33 ++i) { 32 ++i) {
34 v8_apis->Set(api_index++, GetSchema(*i)); 33 v8_apis->Set(api_index++, GetSchema(*i));
35 } 34 }
36 return v8_apis; 35 return v8_apis;
37 } 36 }
38 37
39 v8::Handle<v8::Object> V8SchemaRegistry::GetSchema(const std::string& api) { 38 v8::Handle<v8::Object> V8SchemaRegistry::GetSchema(const std::string& api) {
40 SchemaCache::iterator maybe_schema = schema_cache_.find(api); 39 SchemaCache::iterator maybe_schema = schema_cache_.find(api);
41 if (maybe_schema != schema_cache_.end()) 40 if (maybe_schema != schema_cache_.end())
42 return maybe_schema->second; 41 return maybe_schema->second;
43 42
44 const base::DictionaryValue* schema = 43 const base::DictionaryValue* schema =
45 ExtensionAPI::GetSharedInstance()->GetSchema(api); 44 ExtensionAPI::GetSharedInstance()->GetSchema(api);
46 CHECK(schema) << api; 45 CHECK(schema) << api;
47 46
48 scoped_ptr<V8ValueConverter> v8_value_converter(V8ValueConverter::create()); 47 scoped_ptr<V8ValueConverter> v8_value_converter(V8ValueConverter::create());
49 v8::Persistent<v8::Object> v8_schema = 48 v8::Persistent<v8::Object> v8_schema =
50 v8::Persistent<v8::Object>::New( 49 v8::Persistent<v8::Object>::New(
51 context_->GetIsolate(), 50 context_->GetIsolate(),
52 v8::Handle<v8::Object>::Cast( 51 v8::Handle<v8::Object>::Cast(
53 v8_value_converter->ToV8Value(schema, context_))); 52 v8_value_converter->ToV8Value(schema, context_.get())));
54 CHECK(!v8_schema.IsEmpty()); 53 CHECK(!v8_schema.IsEmpty());
55 schema_cache_[api] = v8_schema; 54 schema_cache_[api] = v8_schema;
56 return v8_schema; 55 return v8_schema;
57 } 56 }
58 57
59 } // namespace extensions 58 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/v8_schema_registry.h ('k') | chrome/renderer/extensions/web_request_custom_bindings.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698