OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/renderer/v8_schema_registry.h" | 5 #include "extensions/renderer/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 "content/public/renderer/v8_value_converter.h" | 9 #include "content/public/renderer/v8_value_converter.h" |
10 #include "extensions/common/extension_api.h" | 10 #include "extensions/common/extension_api.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 | 43 |
44 V8SchemaRegistry::V8SchemaRegistry() { | 44 V8SchemaRegistry::V8SchemaRegistry() { |
45 } | 45 } |
46 | 46 |
47 V8SchemaRegistry::~V8SchemaRegistry() { | 47 V8SchemaRegistry::~V8SchemaRegistry() { |
48 } | 48 } |
49 | 49 |
50 scoped_ptr<NativeHandler> V8SchemaRegistry::AsNativeHandler() { | 50 scoped_ptr<NativeHandler> V8SchemaRegistry::AsNativeHandler() { |
51 scoped_ptr<ScriptContext> context( | 51 scoped_ptr<ScriptContext> context( |
52 new ScriptContext(GetOrCreateContext(v8::Isolate::GetCurrent()), | 52 new ScriptContext(GetOrCreateContext(v8::Isolate::GetCurrent()), |
53 NULL, // no frame | 53 nullptr, // no frame |
54 NULL, // no extension | 54 nullptr, // no extension |
55 Feature::UNSPECIFIED_CONTEXT, | 55 Feature::UNSPECIFIED_CONTEXT, |
56 NULL, // no effective extension | 56 nullptr, // no effective 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::vector<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::EscapableHandleScope handle_scope(isolate); | 65 v8::EscapableHandleScope handle_scope(isolate); |
66 v8::Context::Scope context_scope(GetOrCreateContext(isolate)); | 66 v8::Context::Scope context_scope(GetOrCreateContext(isolate)); |
67 | 67 |
68 v8::Local<v8::Array> v8_apis(v8::Array::New(isolate, apis.size())); | 68 v8::Local<v8::Array> v8_apis(v8::Array::New(isolate, apis.size())); |
69 size_t api_index = 0; | 69 size_t api_index = 0; |
70 for (std::vector<std::string>::const_iterator i = apis.begin(); | 70 for (std::vector<std::string>::const_iterator i = apis.begin(); |
71 i != apis.end(); | 71 i != apis.end(); |
72 ++i) { | 72 ++i) { |
73 v8_apis->Set(api_index++, GetSchema(*i)); | 73 v8_apis->Set(api_index++, GetSchema(*i)); |
74 } | 74 } |
75 return handle_scope.Escape(v8_apis); | 75 return handle_scope.Escape(v8_apis); |
76 } | 76 } |
77 | 77 |
78 v8::Handle<v8::Object> V8SchemaRegistry::GetSchema(const std::string& api) { | 78 v8::Handle<v8::Object> V8SchemaRegistry::GetSchema(const std::string& api) { |
79 if (schema_cache_ != NULL) { | 79 if (schema_cache_ != nullptr) { |
80 v8::Local<v8::Object> cached_schema = schema_cache_->Get(api); | 80 v8::Local<v8::Object> cached_schema = schema_cache_->Get(api); |
81 if (!cached_schema.IsEmpty()) { | 81 if (!cached_schema.IsEmpty()) { |
82 return cached_schema; | 82 return cached_schema; |
83 } | 83 } |
84 } | 84 } |
85 | 85 |
86 // Slow path: Need to build schema first. | 86 // Slow path: Need to build schema first. |
87 | 87 |
88 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 88 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
89 v8::EscapableHandleScope handle_scope(isolate); | 89 v8::EscapableHandleScope handle_scope(isolate); |
(...skipping 20 matching lines...) Expand all Loading... |
110 if (!context_holder_) { | 110 if (!context_holder_) { |
111 context_holder_.reset(new gin::ContextHolder(isolate)); | 111 context_holder_.reset(new gin::ContextHolder(isolate)); |
112 context_holder_->SetContext(v8::Context::New(isolate)); | 112 context_holder_->SetContext(v8::Context::New(isolate)); |
113 schema_cache_.reset(new SchemaCache(isolate)); | 113 schema_cache_.reset(new SchemaCache(isolate)); |
114 return context_holder_->context(); | 114 return context_holder_->context(); |
115 } | 115 } |
116 return context_holder_->context(); | 116 return context_holder_->context(); |
117 } | 117 } |
118 | 118 |
119 } // namespace extensions | 119 } // namespace extensions |
OLD | NEW |