blob: 749aa1c081c5817c178970e9bdd0cef6fcb5d5a2 [file] [log] [blame]
[email protected]bcd9580f2014-04-17 19:17:591// Copyright 2014 The Chromium Authors. All rights reserved.
[email protected]7b1780c82012-03-21 11:48:092// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]bcd9580f2014-04-17 19:17:595#ifndef EXTENSIONS_RENDERER_V8_SCHEMA_REGISTRY_H_
6#define EXTENSIONS_RENDERER_V8_SCHEMA_REGISTRY_H_
[email protected]7b1780c82012-03-21 11:48:097
8#include <map>
dchengf6f80662016-04-20 20:26:049#include <memory>
[email protected]7b1780c82012-03-21 11:48:0910#include <string>
[email protected]6876bb92013-06-14 06:03:5111#include <vector>
[email protected]7b1780c82012-03-21 11:48:0912
avi2d124c02015-12-23 06:36:4213#include "base/macros.h"
[email protected]d9f51dad2014-07-09 05:39:3814#include "gin/public/context_holder.h"
[email protected]b90d08c2014-04-04 16:37:5115#include "v8/include/v8-util.h"
[email protected]7b1780c82012-03-21 11:48:0916#include "v8/include/v8.h"
17
18namespace extensions {
[email protected]f8d87d32013-06-06 02:51:2919class NativeHandler;
[email protected]7b1780c82012-03-21 11:48:0920
21// A registry for the v8::Value representations of extension API schemas.
22// In a way, the v8 counterpart to ExtensionAPI.
23class V8SchemaRegistry {
24 public:
25 V8SchemaRegistry();
26 ~V8SchemaRegistry();
27
[email protected]f8d87d32013-06-06 02:51:2928 // Creates a NativeHandler wrapper |this|. Supports GetSchema.
dchengf6f80662016-04-20 20:26:0429 std::unique_ptr<NativeHandler> AsNativeHandler();
[email protected]f8d87d32013-06-06 02:51:2930
[email protected]7b1780c82012-03-21 11:48:0931 // Returns a v8::Array with all the schemas for the APIs in |apis|.
tfarinaf85316f2015-04-29 17:03:4032 v8::Local<v8::Array> GetSchemas(const std::vector<std::string>& apis);
[email protected]7b1780c82012-03-21 11:48:0933
[email protected]7b1780c82012-03-21 11:48:0934 // Returns a v8::Object for the schema for |api|, possibly from the cache.
tfarinaf85316f2015-04-29 17:03:4035 v8::Local<v8::Object> GetSchema(const std::string& api);
[email protected]7b1780c82012-03-21 11:48:0936
[email protected]4f1633f2013-03-09 14:26:2437 private:
[email protected]b28deed92013-03-12 23:01:1138 // Gets the separate context that backs the registry, creating a new one if
[email protected]b90d08c2014-04-04 16:37:5139 // if necessary. Will also initialize schema_cache_.
tfarinaf85316f2015-04-29 17:03:4040 v8::Local<v8::Context> GetOrCreateContext(v8::Isolate* isolate);
[email protected]b28deed92013-03-12 23:01:1141
[email protected]b90d08c2014-04-04 16:37:5142 // Cache of schemas. Created lazily by GetOrCreateContext.
dcarney36f78b642015-04-24 10:22:4943 typedef v8::StdGlobalValueMap<std::string, v8::Object> SchemaCache;
dchengf6f80662016-04-20 20:26:0444 std::unique_ptr<SchemaCache> schema_cache_;
[email protected]7b1780c82012-03-21 11:48:0945
[email protected]d9f51dad2014-07-09 05:39:3846 // Single per-instance gin::ContextHolder to create v8::Values.
[email protected]b28deed92013-03-12 23:01:1147 // Created lazily via GetOrCreateContext.
dchengf6f80662016-04-20 20:26:0448 std::unique_ptr<gin::ContextHolder> context_holder_;
[email protected]7b1780c82012-03-21 11:48:0949
50 DISALLOW_COPY_AND_ASSIGN(V8SchemaRegistry);
51};
52
53} // namespace extensions
54
[email protected]bcd9580f2014-04-17 19:17:5955#endif // EXTENSIONS_RENDERER_V8_SCHEMA_REGISTRY_H_