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 "chrome/renderer/extensions/chrome_v8_context.h" | 10 #include "chrome/renderer/extensions/chrome_v8_context.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 scoped_ptr<ChromeV8Context> context(new ChromeV8Context( | 55 scoped_ptr<ChromeV8Context> context(new ChromeV8Context( |
56 GetOrCreateContext(), | 56 GetOrCreateContext(), |
57 NULL, // no frame | 57 NULL, // no frame |
58 NULL, // no extension | 58 NULL, // no extension |
59 Feature::UNSPECIFIED_CONTEXT)); | 59 Feature::UNSPECIFIED_CONTEXT)); |
60 return scoped_ptr<NativeHandler>( | 60 return scoped_ptr<NativeHandler>( |
61 new SchemaRegistryNativeHandler(this, context.Pass())); | 61 new SchemaRegistryNativeHandler(this, context.Pass())); |
62 } | 62 } |
63 | 63 |
64 v8::Handle<v8::Array> V8SchemaRegistry::GetSchemas( | 64 v8::Handle<v8::Array> V8SchemaRegistry::GetSchemas( |
65 const std::set<std::string>& apis) { | 65 const std::vector<std::string>& apis) { |
66 v8::HandleScope handle_scope; | 66 v8::HandleScope handle_scope; |
67 v8::Context::Scope context_scope(GetOrCreateContext()); | 67 v8::Context::Scope context_scope(GetOrCreateContext()); |
68 | 68 |
69 v8::Handle<v8::Array> v8_apis(v8::Array::New(apis.size())); | 69 v8::Handle<v8::Array> v8_apis(v8::Array::New(apis.size())); |
70 size_t api_index = 0; | 70 size_t api_index = 0; |
71 for (std::set<std::string>::const_iterator i = apis.begin(); i != apis.end(); | 71 for (std::vector<std::string>::const_iterator i = apis.begin(); |
72 ++i) { | 72 i != apis.end(); ++i) { |
73 v8_apis->Set(api_index++, GetSchema(*i)); | 73 v8_apis->Set(api_index++, GetSchema(*i)); |
74 } | 74 } |
75 return handle_scope.Close(v8_apis); | 75 return handle_scope.Close(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 v8::HandleScope handle_scope; | 79 v8::HandleScope handle_scope; |
80 | 80 |
81 SchemaCache::iterator maybe_schema = schema_cache_.find(api); | 81 SchemaCache::iterator maybe_schema = schema_cache_.find(api); |
82 if (maybe_schema != schema_cache_.end()) | 82 if (maybe_schema != schema_cache_.end()) |
(...skipping 21 matching lines...) Expand all Loading... |
104 if (context_.get().IsEmpty()) { | 104 if (context_.get().IsEmpty()) { |
105 v8::Handle<v8::Context> context = | 105 v8::Handle<v8::Context> context = |
106 v8::Context::New(v8::Isolate::GetCurrent()); | 106 v8::Context::New(v8::Isolate::GetCurrent()); |
107 context_.reset(context); | 107 context_.reset(context); |
108 return context; | 108 return context; |
109 } | 109 } |
110 return v8::Local<v8::Context>::New(context_.get()); | 110 return v8::Local<v8::Context>::New(context_.get()); |
111 } | 111 } |
112 | 112 |
113 } // namespace extensions | 113 } // namespace extensions |
OLD | NEW |