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

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

Issue 9386001: Implement a module system for the extension bindings JS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 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
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_CHROME_V8_CONTEXT_H_ 5 #ifndef CHROME_RENDERER_EXTENSIONS_CHROME_V8_CONTEXT_H_
6 #define CHROME_RENDERER_EXTENSIONS_CHROME_V8_CONTEXT_H_ 6 #define CHROME_RENDERER_EXTENSIONS_CHROME_V8_CONTEXT_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 #include <vector>
10 11
11 #include "base/basictypes.h" 12 #include "base/basictypes.h"
12 #include "v8/include/v8.h" 13 #include "v8/include/v8.h"
13 14
14 namespace WebKit { 15 namespace WebKit {
15 class WebFrame; 16 class WebFrame;
16 } 17 }
17 18
18 namespace content { 19 namespace content {
19 class RenderView; 20 class RenderView;
20 } 21 }
21 22
23 class ChromeV8Extension;
24
22 // Chrome's wrapper for a v8 context. 25 // Chrome's wrapper for a v8 context.
23 // 26 //
24 // TODO(aa): Consider converting this back to a set of bindings_utils. It would 27 // TODO(aa): Consider converting this back to a set of bindings_utils. It would
25 // require adding WebFrame::GetIsolatedWorldIdByV8Context() to WebCore, but then 28 // require adding WebFrame::GetIsolatedWorldIdByV8Context() to WebCore, but then
26 // we won't need this object and it's a bit less state to keep track of. 29 // we won't need this object and it's a bit less state to keep track of.
27 class ChromeV8Context { 30 class ChromeV8Context {
28 public: 31 public:
29 ChromeV8Context(v8::Handle<v8::Context> context, 32 ChromeV8Context(v8::Handle<v8::Context> context,
30 WebKit::WebFrame* frame, 33 WebKit::WebFrame* frame,
31 const std::string& extension_id); 34 const std::string& extension_id);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 // Call the named method of the chromeHidden object in this context. 75 // Call the named method of the chromeHidden object in this context.
73 // The function can be a sub-property like "Port.dispatchOnMessage". Returns 76 // The function can be a sub-property like "Port.dispatchOnMessage". Returns
74 // the result of the function call in |result| if |result| is non-NULL. If the 77 // the result of the function call in |result| if |result| is non-NULL. If the
75 // named method does not exist, returns false. 78 // named method does not exist, returns false.
76 bool CallChromeHiddenMethod( 79 bool CallChromeHiddenMethod(
77 const std::string& function_name, 80 const std::string& function_name,
78 int argc, 81 int argc,
79 v8::Handle<v8::Value>* argv, 82 v8::Handle<v8::Value>* argv,
80 v8::Handle<v8::Value>* result) const; 83 v8::Handle<v8::Value>* result) const;
81 84
85 void RegisterExtension(ChromeV8Extension* extension);
Aaron Boodman 2012/02/16 01:54:42 Needs comments.
86
87 v8::Handle<v8::Object> natives() const { return natives_; }
88
82 private: 89 private:
83 // The v8 context the bindings are accessible to. We keep a strong reference 90 // The v8 context the bindings are accessible to. We keep a strong reference
84 // to it for simplicity. In the case of content scripts, this is necessary 91 // to it for simplicity. In the case of content scripts, this is necessary
85 // because we want all scripts from the same extension for the same frame to 92 // because we want all scripts from the same extension for the same frame to
86 // run in the same context, so we can't have the contexts being GC'd if 93 // run in the same context, so we can't have the contexts being GC'd if
87 // nothing is happening. In the case of page contexts, this isn't necessary 94 // nothing is happening. In the case of page contexts, this isn't necessary
88 // since the DOM keeps the context alive, but it makes things simpler to not 95 // since the DOM keeps the context alive, but it makes things simpler to not
89 // distinguish the two cases. 96 // distinguish the two cases.
90 v8::Persistent<v8::Context> v8_context_; 97 v8::Persistent<v8::Context> v8_context_;
91 98
99 v8::Persistent<v8::Object> natives_;
Aaron Boodman 2012/02/16 01:54:42 needs comments.
100
92 // The WebFrame associated with this context. This can be NULL because this 101 // The WebFrame associated with this context. This can be NULL because this
93 // object can outlive is destroyed asynchronously. 102 // object can outlive is destroyed asynchronously.
94 WebKit::WebFrame* web_frame_; 103 WebKit::WebFrame* web_frame_;
95 104
96 // The extension ID this context is associated with. 105 // The extension ID this context is associated with.
97 std::string extension_id_; 106 std::string extension_id_;
98 107
108 // The list of extensions this context owns.
109 std::vector<ChromeV8Extension*> extensions_;
110
99 DISALLOW_COPY_AND_ASSIGN(ChromeV8Context); 111 DISALLOW_COPY_AND_ASSIGN(ChromeV8Context);
100 }; 112 };
101 113
102 #endif // CHROME_RENDERER_EXTENSIONS_CHROME_V8_CONTEXT_H_ 114 #endif // CHROME_RENDERER_EXTENSIONS_CHROME_V8_CONTEXT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698