| 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 #ifndef CHROME_RENDERER_EXTENSIONS_V8_SCHEMA_REGISTRY_H_ | 5 #ifndef CHROME_RENDERER_EXTENSIONS_V8_SCHEMA_REGISTRY_H_ |
| 6 #define CHROME_RENDERER_EXTENSIONS_V8_SCHEMA_REGISTRY_H_ | 6 #define CHROME_RENDERER_EXTENSIONS_V8_SCHEMA_REGISTRY_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | |
| 10 #include <string> | 9 #include <string> |
| 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "chrome/renderer/extensions/scoped_persistent.h" | 14 #include "chrome/renderer/extensions/scoped_persistent.h" |
| 15 #include "v8/include/v8.h" | 15 #include "v8/include/v8.h" |
| 16 | 16 |
| 17 namespace extensions { | 17 namespace extensions { |
| 18 class NativeHandler; | 18 class NativeHandler; |
| 19 | 19 |
| 20 // A registry for the v8::Value representations of extension API schemas. | 20 // A registry for the v8::Value representations of extension API schemas. |
| 21 // In a way, the v8 counterpart to ExtensionAPI. | 21 // In a way, the v8 counterpart to ExtensionAPI. |
| 22 class V8SchemaRegistry { | 22 class V8SchemaRegistry { |
| 23 public: | 23 public: |
| 24 V8SchemaRegistry(); | 24 V8SchemaRegistry(); |
| 25 ~V8SchemaRegistry(); | 25 ~V8SchemaRegistry(); |
| 26 | 26 |
| 27 // Creates a NativeHandler wrapper |this|. Supports GetSchema. | 27 // Creates a NativeHandler wrapper |this|. Supports GetSchema. |
| 28 scoped_ptr<NativeHandler> AsNativeHandler(); | 28 scoped_ptr<NativeHandler> AsNativeHandler(); |
| 29 | 29 |
| 30 // Returns a v8::Array with all the schemas for the APIs in |apis|. | 30 // Returns a v8::Array with all the schemas for the APIs in |apis|. |
| 31 v8::Handle<v8::Array> GetSchemas(const std::set<std::string>& apis); | 31 v8::Handle<v8::Array> GetSchemas(const std::vector<std::string>& apis); |
| 32 | 32 |
| 33 // Returns a v8::Object for the schema for |api|, possibly from the cache. | 33 // Returns a v8::Object for the schema for |api|, possibly from the cache. |
| 34 v8::Handle<v8::Object> GetSchema(const std::string& api); | 34 v8::Handle<v8::Object> GetSchema(const std::string& api); |
| 35 | 35 |
| 36 private: | 36 private: |
| 37 // Gets the separate context that backs the registry, creating a new one if | 37 // Gets the separate context that backs the registry, creating a new one if |
| 38 // if necessary. | 38 // if necessary. |
| 39 v8::Handle<v8::Context> GetOrCreateContext(); | 39 v8::Handle<v8::Context> GetOrCreateContext(); |
| 40 | 40 |
| 41 // Cache of schemas. | 41 // Cache of schemas. |
| 42 typedef std::map<std::string, v8::Persistent<v8::Object> > SchemaCache; | 42 typedef std::map<std::string, v8::Persistent<v8::Object> > SchemaCache; |
| 43 SchemaCache schema_cache_; | 43 SchemaCache schema_cache_; |
| 44 | 44 |
| 45 // Single per-instance v8::Context to create v8::Values. | 45 // Single per-instance v8::Context to create v8::Values. |
| 46 // Created lazily via GetOrCreateContext. | 46 // Created lazily via GetOrCreateContext. |
| 47 ScopedPersistent<v8::Context> context_; | 47 ScopedPersistent<v8::Context> context_; |
| 48 | 48 |
| 49 DISALLOW_COPY_AND_ASSIGN(V8SchemaRegistry); | 49 DISALLOW_COPY_AND_ASSIGN(V8SchemaRegistry); |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 } // namespace extensions | 52 } // namespace extensions |
| 53 | 53 |
| 54 #endif // CHROME_RENDERER_EXTENSIONS_V8_SCHEMA_REGISTRY_H_ | 54 #endif // CHROME_RENDERER_EXTENSIONS_V8_SCHEMA_REGISTRY_H_ |
| OLD | NEW |