Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: chrome/renderer/extensions/extension_base.h

Issue 7767011: Split extension_base.* out of bindings_utils.*. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_RENDERER_EXTENSIONS_EXTENSION_BASE_H_
6 #define CHROME_RENDERER_EXTENSIONS_EXTENSION_BASE_H_
7 #pragma once
8
9 #include "base/logging.h"
10 #include "v8/include/v8.h"
11
12 #include <string>
13
14 class Extension;
15 class ExtensionDispatcher;
16 class RenderView;
17
18 namespace WebKit {
19 class WebFrame;
20 }
21
22 // This is a base class for chrome extension bindings. Common features that
23 // are shared by different modules go here.
24 class ExtensionBase : public v8::Extension {
25 public:
26 static const char* GetStringResource(int resource_id);
27
28 ExtensionBase(const char* name,
29 const char* source,
30 int dep_count,
31 const char** deps,
32 ExtensionDispatcher* extension_dispatcher)
33 : v8::Extension(name, source, dep_count, deps),
34 extension_dispatcher_(extension_dispatcher) {
35 }
36
37 // Derived classes should call this at the end of their implementation in
38 // order to expose common native functions, like GetChromeHidden, to the
39 // v8 extension.
40 virtual v8::Handle<v8::FunctionTemplate>
41 GetNativeFunction(v8::Handle<v8::String> name);
42
43 // TODO(jstritar): Used for testing http://crbug.com/91582. Remove when done.
44 ExtensionDispatcher* extension_dispatcher() { return extension_dispatcher_; }
45
46 protected:
47 template<class T>
48 static T* GetFromArguments(const v8::Arguments& args) {
49 CHECK(!args.Data().IsEmpty());
50 T* result = static_cast<T*>(args.Data().As<v8::External>()->Value());
51 return result;
52 }
53
54 // Note: do not call this function before or during the chromeHidden.onLoad
55 // event dispatch. The URL might not have been committed yet and might not
56 // be an extension URL.
57 const ::Extension* GetExtensionForCurrentContext() const;
58
59 // Checks that the current context contains an extension that has permission
60 // to execute the specified function. If it does not, a v8 exception is thrown
61 // and the method returns false. Otherwise returns true.
62 bool CheckPermissionForCurrentContext(const std::string& function_name) const;
63
64 // Returns a hidden variable for use by the bindings that is unreachable
65 // by the page.
66 static v8::Handle<v8::Value> GetChromeHidden(const v8::Arguments& args);
67
68 ExtensionDispatcher* extension_dispatcher_;
69
70 private:
71 // Helper to print from bindings javascript.
72 static v8::Handle<v8::Value> Print(const v8::Arguments& args);
73 };
74
75 #endif // CHROME_RENDERER_EXTENSIONS_EXTENSION_BASE_H_
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/event_bindings.cc ('k') | chrome/renderer/extensions/extension_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698