blob: 554d1a950d736f81531c4615d622ba5c0042329e [file] [log] [blame]
[email protected]b8ce52f2014-04-04 22:45:151// Copyright 2014 The Chromium Authors. All rights reserved.
[email protected]58e10452012-02-22 03:34:452// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]b8ce52f2014-04-04 22:45:155#ifndef EXTENSIONS_RENDERER_NATIVE_HANDLER_H_
6#define EXTENSIONS_RENDERER_NATIVE_HANDLER_H_
[email protected]58e10452012-02-22 03:34:457
avi2d124c02015-12-23 06:36:428#include "base/macros.h"
[email protected]58e10452012-02-22 03:34:459#include "v8/include/v8.h"
10
[email protected]3c6babd2012-08-28 03:17:2911namespace extensions {
12
[email protected]ecde1912012-03-16 06:25:3113// NativeHandlers are intended to be used with a ModuleSystem. The ModuleSystem
14// will assume ownership of the NativeHandler, and as a ModuleSystem is tied to
15// a single v8::Context, this implies that NativeHandlers will also be tied to
[email protected]4f1633f2013-03-09 14:26:2416// a single v8::Context.
[email protected]ecde1912012-03-16 06:25:3117// TODO(koz): Rename this to NativeJavaScriptModule.
[email protected]58e10452012-02-22 03:34:4518class NativeHandler {
19 public:
[email protected]4f1633f2013-03-09 14:26:2420 NativeHandler();
[email protected]e3e778722013-03-03 23:28:0321 virtual ~NativeHandler();
[email protected]58e10452012-02-22 03:34:4522
Devlin Cronind9ea8342018-01-27 06:00:0423 // Initializes the native handler.
24 virtual void Initialize() = 0;
25
Devlin Cronin6fed7f02018-01-31 22:38:2026 // Returns true if the handler has been initialized.
27 virtual bool IsInitialized() = 0;
28
[email protected]4f1633f2013-03-09 14:26:2429 // Create a new instance of the object this handler specifies.
tfarinaf85316f2015-04-29 17:03:4030 virtual v8::Local<v8::Object> NewInstance() = 0;
[email protected]4f1633f2013-03-09 14:26:2431
32 // Invalidate this object so it cannot be used any more. This is needed
33 // because it's possible for this to outlive its owner context. Invalidate
34 // must be called before this happens.
35 //
36 // Subclasses should override to invalidate their own V8 state. If they do
37 // they must call their superclass' Invalidate().
kalmanb0c1c502015-04-15 00:25:0638 //
39 // Invalidate() will be called on destruction, if it hasn't already been.
40 // Subclasses don't need to do it themselves.
[email protected]4f1633f2013-03-09 14:26:2441 virtual void Invalidate();
[email protected]e3e778722013-03-03 23:28:0342
43 protected:
[email protected]4f1633f2013-03-09 14:26:2444 // Allow subclasses to query valid state.
45 bool is_valid() { return is_valid_; }
[email protected]e3e778722013-03-03 23:28:0346
47 private:
[email protected]4f1633f2013-03-09 14:26:2448 bool is_valid_;
[email protected]630b9deb2013-03-07 18:38:3449
50 DISALLOW_COPY_AND_ASSIGN(NativeHandler);
[email protected]58e10452012-02-22 03:34:4551};
52
[email protected]b8ce52f2014-04-04 22:45:1553} // namespace extensions
[email protected]3c6babd2012-08-28 03:17:2954
[email protected]b8ce52f2014-04-04 22:45:1555#endif // EXTENSIONS_RENDERER_NATIVE_HANDLER_H_