| OLD | NEW |
| 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() {} | 16 V8SchemaRegistry::V8SchemaRegistry() {} |
| 17 | 17 |
| 18 V8SchemaRegistry::~V8SchemaRegistry() { | 18 V8SchemaRegistry::~V8SchemaRegistry() { |
| 19 v8::HandleScope handle_scope; | 19 v8::HandleScope handle_scope; |
| 20 | 20 |
| 21 for (SchemaCache::iterator i = schema_cache_.begin(); | 21 for (SchemaCache::iterator i = schema_cache_.begin(); |
| 22 i != schema_cache_.end(); ++i) { | 22 i != schema_cache_.end(); ++i) { |
| 23 i->second.Dispose(i->second->CreationContext()->GetIsolate()); | 23 i->second.Dispose(i->second->CreationContext()->GetIsolate()); |
| 24 } | 24 } |
| 25 } | 25 } |
| 26 | 26 |
| 27 v8::Handle<v8::Array> V8SchemaRegistry::GetSchemas( | 27 v8::Handle<v8::Array> V8SchemaRegistry::GetSchemas( |
| 28 const std::set<std::string>& apis) { | 28 const std::vector<std::string>& apis) { |
| 29 v8::HandleScope handle_scope; | 29 v8::HandleScope handle_scope; |
| 30 v8::Context::Scope context_scope(GetOrCreateContext()); | 30 v8::Context::Scope context_scope(GetOrCreateContext()); |
| 31 | 31 |
| 32 v8::Handle<v8::Array> v8_apis(v8::Array::New(apis.size())); | 32 v8::Handle<v8::Array> v8_apis(v8::Array::New(apis.size())); |
| 33 size_t api_index = 0; | 33 size_t api_index = 0; |
| 34 for (std::set<std::string>::const_iterator i = apis.begin(); i != apis.end(); | 34 for (std::vector<std::string>::const_iterator i = apis.begin(); |
| 35 ++i) { | 35 i != apis.end(); ++i) { |
| 36 v8_apis->Set(api_index++, GetSchema(*i)); | 36 v8_apis->Set(api_index++, GetSchema(*i)); |
| 37 } | 37 } |
| 38 return handle_scope.Close(v8_apis); | 38 return handle_scope.Close(v8_apis); |
| 39 } | 39 } |
| 40 | 40 |
| 41 v8::Handle<v8::Object> V8SchemaRegistry::GetSchema(const std::string& api) { | 41 v8::Handle<v8::Object> V8SchemaRegistry::GetSchema(const std::string& api) { |
| 42 v8::HandleScope handle_scope; | 42 v8::HandleScope handle_scope; |
| 43 | 43 |
| 44 SchemaCache::iterator maybe_schema = schema_cache_.find(api); | 44 SchemaCache::iterator maybe_schema = schema_cache_.find(api); |
| 45 if (maybe_schema != schema_cache_.end()) | 45 if (maybe_schema != schema_cache_.end()) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 67 if (context_.get().IsEmpty()) { | 67 if (context_.get().IsEmpty()) { |
| 68 v8::Handle<v8::Context> context = | 68 v8::Handle<v8::Context> context = |
| 69 v8::Context::New(v8::Isolate::GetCurrent()); | 69 v8::Context::New(v8::Isolate::GetCurrent()); |
| 70 context_.reset(context); | 70 context_.reset(context); |
| 71 return context; | 71 return context; |
| 72 } | 72 } |
| 73 return v8::Local<v8::Context>::New(context_.get()); | 73 return v8::Local<v8::Context>::New(context_.get()); |
| 74 } | 74 } |
| 75 | 75 |
| 76 } // namespace extensions | 76 } // namespace extensions |
| OLD | NEW |