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

Side by Side Diff: extensions/renderer/script_context.h

Issue 498513002: Respect the clipboardRead and clipboardWrite permissions in content scripts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix extensions test compile Created 6 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
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 17 matching lines...) Expand all
28 28
29 namespace extensions { 29 namespace extensions {
30 class Extension; 30 class Extension;
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,
40 Feature::Context effective_context_type);
39 virtual ~ScriptContext(); 41 virtual ~ScriptContext();
40 42
41 // Clears the WebFrame for this contexts and invalidates the associated 43 // Clears the WebFrame for this contexts and invalidates the associated
42 // ModuleSystem. 44 // ModuleSystem.
43 void Invalidate(); 45 void Invalidate();
44 46
45 // 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.
46 // A context becomes invalid via Invalidate(). 48 // A context becomes invalid via Invalidate().
47 bool is_valid() const { return !v8_context_.IsEmpty(); } 49 bool is_valid() const { return !v8_context_.IsEmpty(); }
48 50
49 v8::Handle<v8::Context> v8_context() const { 51 v8::Handle<v8::Context> v8_context() const {
50 return v8_context_.NewHandle(isolate()); 52 return v8_context_.NewHandle(isolate());
51 } 53 }
52 54
53 const Extension* extension() const { return extension_.get(); } 55 const Extension* extension() const { return extension_.get(); }
54 56
57 const Extension* effective_extension() const {
58 return effective_extension_.get();
59 }
60
55 blink::WebFrame* web_frame() const { return web_frame_; } 61 blink::WebFrame* web_frame() const { return web_frame_; }
56 62
57 Feature::Context context_type() const { return context_type_; } 63 Feature::Context context_type() const { return context_type_; }
58 64
65 Feature::Context effective_context_type() const {
66 return effective_context_type_;
67 }
68
59 void set_module_system(scoped_ptr<ModuleSystem> module_system) { 69 void set_module_system(scoped_ptr<ModuleSystem> module_system) {
60 module_system_ = module_system.Pass(); 70 module_system_ = module_system.Pass();
61 } 71 }
62 72
63 ModuleSystem* module_system() { return module_system_.get(); } 73 ModuleSystem* module_system() { return module_system_.get(); }
64 74
65 SafeBuiltins* safe_builtins() { return &safe_builtins_; } 75 SafeBuiltins* safe_builtins() { return &safe_builtins_; }
66 76
67 const SafeBuiltins* safe_builtins() const { return &safe_builtins_; } 77 const SafeBuiltins* safe_builtins() const { return &safe_builtins_; }
68 78
69 // Returns the ID of the extension associated with this context, or empty 79 // Returns the ID of the extension associated with this context, or empty
70 // string if there is no such extension. 80 // string if there is no such extension.
71 const std::string& GetExtensionID() const; 81 const std::string& GetExtensionID() const;
72 82
83 // Returns the ID of the effective extension associated with this context, or
84 // empty string if there is no such extension.
Devlin 2014/09/03 22:09:16 Are all of these accessors really needed? If not
Marijn Kruisselbrink 2014/09/03 23:54:07 Well, it's the "or empty string" part that makes i
85 const std::string& GetEffectiveExtensionID() const;
86
73 // Returns the RenderView associated with this context. Can return NULL if the 87 // Returns the RenderView associated with this context. Can return NULL if the
74 // context is in the process of being destroyed. 88 // context is in the process of being destroyed.
75 content::RenderView* GetRenderView() const; 89 content::RenderView* GetRenderView() const;
76 90
77 // Returns the RenderFrame associated with this context. Can return NULL if 91 // Returns the RenderFrame associated with this context. Can return NULL if
78 // the context is in the process of being destroyed. 92 // the context is in the process of being destroyed.
79 content::RenderFrame* GetRenderFrame() const; 93 content::RenderFrame* GetRenderFrame() const;
80 94
81 // Runs |function| with appropriate scopes. Doesn't catch exceptions, callers 95 // Runs |function| with appropriate scopes. Doesn't catch exceptions, callers
82 // must do that if they want. 96 // must do that if they want.
83 // 97 //
84 // USE THIS METHOD RATHER THAN v8::Function::Call WHEREVER POSSIBLE. 98 // USE THIS METHOD RATHER THAN v8::Function::Call WHEREVER POSSIBLE.
85 v8::Local<v8::Value> CallFunction(v8::Handle<v8::Function> function, 99 v8::Local<v8::Value> CallFunction(v8::Handle<v8::Function> function,
86 int argc, 100 int argc,
87 v8::Handle<v8::Value> argv[]) const; 101 v8::Handle<v8::Value> argv[]) const;
88 102
89 void DispatchEvent(const char* event_name, v8::Handle<v8::Array> args) const; 103 void DispatchEvent(const char* event_name, v8::Handle<v8::Array> args) const;
90 104
91 // Fires the onunload event on the unload_event module. 105 // Fires the onunload event on the unload_event module.
92 void DispatchOnUnloadEvent(); 106 void DispatchOnUnloadEvent();
93 107
94 // Returns the availability of the API |api_name|. 108 // Returns the availability of the API |api_name|.
95 Feature::Availability GetAvailability(const std::string& api_name); 109 Feature::Availability GetAvailability(const std::string& api_name);
96 110
97 // Returns a string description of the type of context this is. 111 // Returns a string description of the type of context this is.
Devlin 2014/09/03 22:09:16 nit: "...of the |context_type|."
Marijn Kruisselbrink 2014/09/03 23:54:07 Acknowledged.
112 static std::string GetContextTypeDescription(Feature::Context context_type);
113
114 // Returns a string description of the type of context this is.
98 std::string GetContextTypeDescription(); 115 std::string GetContextTypeDescription();
99 116
117 // Returns a string description of the type of context this is.
Devlin 2014/09/03 22:09:16 ... of the effective type of context...
Marijn Kruisselbrink 2014/09/03 23:54:07 Done.
118 std::string GetEffectiveContextTypeDescription();
119
100 v8::Isolate* isolate() const { return isolate_; } 120 v8::Isolate* isolate() const { return isolate_; }
101 121
102 // Get the URL of this context's web frame. 122 // Get the URL of this context's web frame.
103 GURL GetURL() const; 123 GURL GetURL() const;
104 124
105 // Returns whether the API |api| or any part of the API could be 125 // Returns whether the API |api| or any part of the API could be
106 // available in this context without taking into account the context's 126 // available in this context without taking into account the context's
107 // extension. 127 // extension.
108 bool IsAnyFeatureAvailableToContext(const extensions::Feature& api); 128 bool IsAnyFeatureAvailableToContext(const extensions::Feature& api);
109 129
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 // object can outlive is destroyed asynchronously. 165 // object can outlive is destroyed asynchronously.
146 blink::WebFrame* web_frame_; 166 blink::WebFrame* web_frame_;
147 167
148 // The extension associated with this context, or NULL if there is none. This 168 // The extension associated with this context, or NULL if there is none. This
149 // might be a hosted app in the case that this context is hosting a web URL. 169 // might be a hosted app in the case that this context is hosting a web URL.
150 scoped_refptr<const Extension> extension_; 170 scoped_refptr<const Extension> extension_;
151 171
152 // The type of context. 172 // The type of context.
153 Feature::Context context_type_; 173 Feature::Context context_type_;
154 174
175 // The effective extension associated with this context, or NULL if there is
176 // none. This is different from the above extension if this context is in an
177 // about:blank iframe for example.
178 scoped_refptr<const Extension> effective_extension_;
179
180 // The type of context.
181 Feature::Context effective_context_type_;
182
155 // Owns and structures the JS that is injected to set up extension bindings. 183 // Owns and structures the JS that is injected to set up extension bindings.
156 scoped_ptr<ModuleSystem> module_system_; 184 scoped_ptr<ModuleSystem> module_system_;
157 185
158 // Contains safe copies of builtin objects like Function.prototype. 186 // Contains safe copies of builtin objects like Function.prototype.
159 SafeBuiltins safe_builtins_; 187 SafeBuiltins safe_builtins_;
160 188
161 v8::Isolate* isolate_; 189 v8::Isolate* isolate_;
162 190
163 DISALLOW_COPY_AND_ASSIGN(ScriptContext); 191 DISALLOW_COPY_AND_ASSIGN(ScriptContext);
164 }; 192 };
165 193
166 } // namespace extensions 194 } // namespace extensions
167 195
168 #endif // EXTENSIONS_RENDERER_SCRIPT_CONTEXT_H_ 196 #endif // EXTENSIONS_RENDERER_SCRIPT_CONTEXT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698