summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/extensions/chrome_v8_extension.h
blob: e12af644124408cd5daa716d60e3ab06822eca6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_RENDERER_EXTENSIONS_CHROME_V8_EXTENSION_H_
#define CHROME_RENDERER_EXTENSIONS_CHROME_V8_EXTENSION_H_

#include "base/logging.h"
#include "base/memory/linked_ptr.h"
#include "base/string_piece.h"
#include "chrome/renderer/extensions/chrome_v8_extension_handler.h"
#include "chrome/renderer/extensions/native_handler.h"
#include "v8/include/v8.h"

#include <map>
#include <set>
#include <string>


namespace content {
class RenderView;
}

namespace extensions {
class ChromeV8Context;
class Dispatcher;
class Extension;

// This is a base class for chrome extension bindings.  Common features that
// are shared by different modules go here.
// TODO(koz): Rename this to ExtensionNativeModule.
class ChromeV8Extension : public NativeHandler {
 public:
  typedef std::set<ChromeV8Extension*> InstanceSet;
  static const InstanceSet& GetAll();

  explicit ChromeV8Extension(Dispatcher* dispatcher);
  virtual ~ChromeV8Extension();

  Dispatcher* dispatcher() { return dispatcher_; }

 protected:
  template<class T>
  static T* GetFromArguments(const v8::Arguments& args) {
    CHECK(!args.Data().IsEmpty());
    T* result = static_cast<T*>(args.Data().As<v8::External>()->Value());
    return result;
  }

  // Gets the render view for the current v8 context.
  static content::RenderView* GetCurrentRenderView();

  // Note: do not call this function before or during the chromeHidden.onLoad
  // event dispatch. The URL might not have been committed yet and might not
  // be an extension URL.
  const Extension* GetExtensionForCurrentRenderView() const;

  // Returns the chromeHidden object for the current context.
  static v8::Handle<v8::Value> GetChromeHidden(const v8::Arguments& args);

  Dispatcher* dispatcher_;

 private:
  DISALLOW_COPY_AND_ASSIGN(ChromeV8Extension);
};

}  // namespace extensions

#endif  // CHROME_RENDERER_EXTENSIONS_CHROME_V8_EXTENSION_H_