OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 EXTENSIONS_RENDERER_SCRIPT_CONTEXT_H_ | 5 #ifndef EXTENSIONS_RENDERER_SCRIPT_CONTEXT_H_ |
6 #define EXTENSIONS_RENDERER_SCRIPT_CONTEXT_H_ | 6 #define EXTENSIONS_RENDERER_SCRIPT_CONTEXT_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 | 31 |
32 // Extensions wrapper for a v8 context. | 32 // Extensions wrapper for a v8 context. |
33 class ScriptContext : public RequestSender::Source, public gin::Runner { | 33 class ScriptContext : public RequestSender::Source, public gin::Runner { |
34 public: | 34 public: |
35 ScriptContext(const v8::Handle<v8::Context>& context, | 35 ScriptContext(const v8::Handle<v8::Context>& context, |
36 blink::WebFrame* frame, | 36 blink::WebFrame* frame, |
37 const Extension* extension, | 37 const Extension* extension, |
38 Feature::Context context_type, | 38 Feature::Context context_type, |
39 const Extension* effective_extension, | 39 const Extension* effective_extension, |
40 Feature::Context effective_context_type); | 40 Feature::Context effective_context_type); |
41 virtual ~ScriptContext(); | 41 ~ScriptContext() override; |
42 | 42 |
43 // Clears the WebFrame for this contexts and invalidates the associated | 43 // Clears the WebFrame for this contexts and invalidates the associated |
44 // ModuleSystem. | 44 // ModuleSystem. |
45 void Invalidate(); | 45 void Invalidate(); |
46 | 46 |
47 // Returns true if this context is still valid, false if it isn't. | 47 // Returns true if this context is still valid, false if it isn't. |
48 // A context becomes invalid via Invalidate(). | 48 // A context becomes invalid via Invalidate(). |
49 bool is_valid() const { return !v8_context_.IsEmpty(); } | 49 bool is_valid() const { return !v8_context_.IsEmpty(); } |
50 | 50 |
51 v8::Handle<v8::Context> v8_context() const { | 51 v8::Handle<v8::Context> v8_context() const { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 static GURL GetDataSourceURLForFrame(const blink::WebFrame* frame); | 126 static GURL GetDataSourceURLForFrame(const blink::WebFrame* frame); |
127 | 127 |
128 // Returns the first non-about:-URL in the document hierarchy above and | 128 // Returns the first non-about:-URL in the document hierarchy above and |
129 // including |frame|. The document hierarchy is only traversed if | 129 // including |frame|. The document hierarchy is only traversed if |
130 // |document_url| is an about:-URL and if |match_about_blank| is true. | 130 // |document_url| is an about:-URL and if |match_about_blank| is true. |
131 static GURL GetEffectiveDocumentURL(const blink::WebFrame* frame, | 131 static GURL GetEffectiveDocumentURL(const blink::WebFrame* frame, |
132 const GURL& document_url, | 132 const GURL& document_url, |
133 bool match_about_blank); | 133 bool match_about_blank); |
134 | 134 |
135 // RequestSender::Source implementation. | 135 // RequestSender::Source implementation. |
136 virtual ScriptContext* GetContext() override; | 136 ScriptContext* GetContext() override; |
137 virtual void OnResponseReceived(const std::string& name, | 137 void OnResponseReceived(const std::string& name, |
138 int request_id, | 138 int request_id, |
139 bool success, | 139 bool success, |
140 const base::ListValue& response, | 140 const base::ListValue& response, |
141 const std::string& error) override; | 141 const std::string& error) override; |
142 | 142 |
143 // gin::Runner overrides. | 143 // gin::Runner overrides. |
144 virtual void Run(const std::string& source, | 144 void Run(const std::string& source, |
145 const std::string& resource_name) override; | 145 const std::string& resource_name) override; |
146 virtual v8::Handle<v8::Value> Call(v8::Handle<v8::Function> function, | 146 v8::Handle<v8::Value> Call(v8::Handle<v8::Function> function, |
147 v8::Handle<v8::Value> receiver, | 147 v8::Handle<v8::Value> receiver, |
148 int argc, | 148 int argc, |
149 v8::Handle<v8::Value> argv[]) override; | 149 v8::Handle<v8::Value> argv[]) override; |
150 virtual gin::ContextHolder* GetContextHolder() override; | 150 gin::ContextHolder* GetContextHolder() override; |
151 | 151 |
152 protected: | 152 protected: |
153 // The v8 context the bindings are accessible to. | 153 // The v8 context the bindings are accessible to. |
154 ScopedPersistent<v8::Context> v8_context_; | 154 ScopedPersistent<v8::Context> v8_context_; |
155 | 155 |
156 private: | 156 private: |
157 // The WebFrame associated with this context. This can be NULL because this | 157 // The WebFrame associated with this context. This can be NULL because this |
158 // object can outlive is destroyed asynchronously. | 158 // object can outlive is destroyed asynchronously. |
159 blink::WebFrame* web_frame_; | 159 blink::WebFrame* web_frame_; |
160 | 160 |
(...skipping 19 matching lines...) Expand all Loading... |
180 SafeBuiltins safe_builtins_; | 180 SafeBuiltins safe_builtins_; |
181 | 181 |
182 v8::Isolate* isolate_; | 182 v8::Isolate* isolate_; |
183 | 183 |
184 DISALLOW_COPY_AND_ASSIGN(ScriptContext); | 184 DISALLOW_COPY_AND_ASSIGN(ScriptContext); |
185 }; | 185 }; |
186 | 186 |
187 } // namespace extensions | 187 } // namespace extensions |
188 | 188 |
189 #endif // EXTENSIONS_RENDERER_SCRIPT_CONTEXT_H_ | 189 #endif // EXTENSIONS_RENDERER_SCRIPT_CONTEXT_H_ |
OLD | NEW |