OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_COMMON_USER_SCRIPT_H_ | 5 #ifndef EXTENSIONS_COMMON_USER_SCRIPT_H_ |
6 #define EXTENSIONS_COMMON_USER_SCRIPT_H_ | 6 #define EXTENSIONS_COMMON_USER_SCRIPT_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 // The script content. It can be set to either loaded_content_ or | 119 // The script content. It can be set to either loaded_content_ or |
120 // externally allocated string. | 120 // externally allocated string. |
121 base::StringPiece external_content_; | 121 base::StringPiece external_content_; |
122 | 122 |
123 // Set when the content is loaded by LoadContent | 123 // Set when the content is loaded by LoadContent |
124 std::string content_; | 124 std::string content_; |
125 }; | 125 }; |
126 | 126 |
127 typedef std::vector<File> FileList; | 127 typedef std::vector<File> FileList; |
128 | 128 |
129 // Render's routing info of a <webview> that the user script will be injected | |
130 // on. Only user scripts from <webview>s have a custom routing info. | |
131 struct RoutingInfo { | |
132 RoutingInfo() : render_process_id(-1), render_view_id(-1) {}; | |
Nico
2015/03/04 15:35:01
nit: no ';' after method bodies
| |
133 ~RoutingInfo() {}; | |
Nico
2015/03/04 15:35:01
likewise
| |
134 | |
135 int render_process_id; | |
136 int render_view_id; | |
137 }; | |
138 | |
139 // Type of a API consumer instance that user scripts will be injected on. | |
140 enum ConsumerInstanceType { TAB, WEBVIEW }; | |
141 | |
129 // Constructor. Default the run location to document end, which is like | 142 // Constructor. Default the run location to document end, which is like |
130 // Greasemonkey and probably more useful for typical scripts. | 143 // Greasemonkey and probably more useful for typical scripts. |
131 UserScript(); | 144 UserScript(); |
132 ~UserScript(); | 145 ~UserScript(); |
133 | 146 |
134 const std::string& name_space() const { return name_space_; } | 147 const std::string& name_space() const { return name_space_; } |
135 void set_name_space(const std::string& name_space) { | 148 void set_name_space(const std::string& name_space) { |
136 name_space_ = name_space; | 149 name_space_ = name_space; |
137 } | 150 } |
138 | 151 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 | 206 |
194 // List of css scripts for this user script | 207 // List of css scripts for this user script |
195 FileList& css_scripts() { return css_scripts_; } | 208 FileList& css_scripts() { return css_scripts_; } |
196 const FileList& css_scripts() const { return css_scripts_; } | 209 const FileList& css_scripts() const { return css_scripts_; } |
197 | 210 |
198 const std::string& extension_id() const { return host_id_.id(); } | 211 const std::string& extension_id() const { return host_id_.id(); } |
199 | 212 |
200 const HostID& host_id() const { return host_id_; } | 213 const HostID& host_id() const { return host_id_; } |
201 void set_host_id(const HostID& host_id) { host_id_ = host_id; } | 214 void set_host_id(const HostID& host_id) { host_id_ = host_id; } |
202 | 215 |
216 const ConsumerInstanceType& consumer_instance_type() const { | |
217 return consumer_instance_type_; | |
218 } | |
219 void set_consumer_instance_type( | |
220 const ConsumerInstanceType& consumer_instance_type) { | |
221 consumer_instance_type_ = consumer_instance_type; | |
222 } | |
223 | |
224 const RoutingInfo& routing_info() const { return routing_info_; } | |
225 void set_routing_info(const RoutingInfo& routing_info) { | |
226 routing_info_ = routing_info; | |
227 } | |
228 | |
203 int id() const { return user_script_id_; } | 229 int id() const { return user_script_id_; } |
204 void set_id(int id) { user_script_id_ = id; } | 230 void set_id(int id) { user_script_id_ = id; } |
205 | 231 |
206 bool is_incognito_enabled() const { return incognito_enabled_; } | 232 bool is_incognito_enabled() const { return incognito_enabled_; } |
207 void set_incognito_enabled(bool enabled) { incognito_enabled_ = enabled; } | 233 void set_incognito_enabled(bool enabled) { incognito_enabled_ = enabled; } |
208 | 234 |
209 bool is_standalone() const { return extension_id().empty(); } | 235 bool is_standalone() const { return extension_id().empty(); } |
210 | 236 |
211 // Returns true if the script should be applied to the specified URL, false | 237 // Returns true if the script should be applied to the specified URL, false |
212 // otherwise. | 238 // otherwise. |
213 bool MatchesURL(const GURL& url) const; | 239 bool MatchesURL(const GURL& url) const; |
214 | 240 |
215 // Serialize the UserScript into a pickle. The content of the scripts and | 241 // Serialize the UserScript into a pickle. The content of the scripts and |
216 // paths to UserScript::Files will not be serialized! | 242 // paths to UserScript::Files will not be serialized! |
217 void Pickle(::Pickle* pickle) const; | 243 void Pickle(::Pickle* pickle) const; |
218 | 244 |
219 // Deserialize the script from a pickle. Note that this always succeeds | 245 // Deserialize the script from a pickle. Note that this always succeeds |
220 // because presumably we were the one that pickled it, and we did it | 246 // because presumably we were the one that pickled it, and we did it |
221 // correctly. | 247 // correctly. |
222 void Unpickle(const ::Pickle& pickle, PickleIterator* iter); | 248 void Unpickle(const ::Pickle& pickle, PickleIterator* iter); |
223 | 249 |
224 private: | 250 private: |
225 // Pickle helper functions used to pickle the individual types of components. | 251 // Pickle helper functions used to pickle the individual types of components. |
226 void PickleGlobs(::Pickle* pickle, | 252 void PickleGlobs(::Pickle* pickle, |
227 const std::vector<std::string>& globs) const; | 253 const std::vector<std::string>& globs) const; |
228 void PickleHostID(::Pickle* pickle, const HostID& host_id) const; | 254 void PickleHostID(::Pickle* pickle, const HostID& host_id) const; |
255 void PickleRoutingInfo(::Pickle* pickle, | |
256 const RoutingInfo& routing_info) const; | |
229 void PickleURLPatternSet(::Pickle* pickle, | 257 void PickleURLPatternSet(::Pickle* pickle, |
230 const URLPatternSet& pattern_list) const; | 258 const URLPatternSet& pattern_list) const; |
231 void PickleScripts(::Pickle* pickle, const FileList& scripts) const; | 259 void PickleScripts(::Pickle* pickle, const FileList& scripts) const; |
232 | 260 |
233 // Unpickle helper functions used to unpickle individual types of components. | 261 // Unpickle helper functions used to unpickle individual types of components. |
234 void UnpickleGlobs(const ::Pickle& pickle, PickleIterator* iter, | 262 void UnpickleGlobs(const ::Pickle& pickle, PickleIterator* iter, |
235 std::vector<std::string>* globs); | 263 std::vector<std::string>* globs); |
236 void UnpickleHostID(const ::Pickle& pickle, | 264 void UnpickleHostID(const ::Pickle& pickle, |
237 PickleIterator* iter, | 265 PickleIterator* iter, |
238 HostID* host_id); | 266 HostID* host_id); |
267 void UnpickleRoutingInfo(const ::Pickle& pickle, | |
268 PickleIterator* iter, | |
269 RoutingInfo* routing_info); | |
239 void UnpickleURLPatternSet(const ::Pickle& pickle, PickleIterator* iter, | 270 void UnpickleURLPatternSet(const ::Pickle& pickle, PickleIterator* iter, |
240 URLPatternSet* pattern_list); | 271 URLPatternSet* pattern_list); |
241 void UnpickleScripts(const ::Pickle& pickle, PickleIterator* iter, | 272 void UnpickleScripts(const ::Pickle& pickle, PickleIterator* iter, |
242 FileList* scripts); | 273 FileList* scripts); |
243 | 274 |
244 // The location to run the script inside the document. | 275 // The location to run the script inside the document. |
245 RunLocation run_location_; | 276 RunLocation run_location_; |
246 | 277 |
247 // The namespace of the script. This is used by Greasemonkey in the same way | 278 // The namespace of the script. This is used by Greasemonkey in the same way |
248 // as XML namespaces. Only used when parsing Greasemonkey-style scripts. | 279 // as XML namespaces. Only used when parsing Greasemonkey-style scripts. |
(...skipping 22 matching lines...) Expand all Loading... | |
271 // List of js scripts defined in content_scripts | 302 // List of js scripts defined in content_scripts |
272 FileList js_scripts_; | 303 FileList js_scripts_; |
273 | 304 |
274 // List of css scripts defined in content_scripts | 305 // List of css scripts defined in content_scripts |
275 FileList css_scripts_; | 306 FileList css_scripts_; |
276 | 307 |
277 // The ID of the host this script is a part of. The |ID| of the | 308 // The ID of the host this script is a part of. The |ID| of the |
278 // |host_id| can be empty if the script is a "standlone" user script. | 309 // |host_id| can be empty if the script is a "standlone" user script. |
279 HostID host_id_; | 310 HostID host_id_; |
280 | 311 |
312 // The type of the consumer instance that the script will be injected. | |
313 ConsumerInstanceType consumer_instance_type_; | |
314 | |
315 // The render side's rounting info for content_scripts of <webview>. | |
316 RoutingInfo routing_info_; | |
Nico
2015/03/05 00:40:11
You don't initialize this in the constructor, whic
Devlin
2015/03/05 00:42:49
This comment refers to the variable on line 313. :
Nico
2015/03/05 00:45:10
Duh, yes, sorry :-(
| |
317 | |
281 // The globally-unique id associated with this user script. Defaults to | 318 // The globally-unique id associated with this user script. Defaults to |
282 // -1 for invalid. | 319 // -1 for invalid. |
283 int user_script_id_; | 320 int user_script_id_; |
284 | 321 |
285 // Whether we should try to emulate Greasemonkey's APIs when running this | 322 // Whether we should try to emulate Greasemonkey's APIs when running this |
286 // script. | 323 // script. |
287 bool emulate_greasemonkey_; | 324 bool emulate_greasemonkey_; |
288 | 325 |
289 // Whether the user script should run in all frames, or only just the top one. | 326 // Whether the user script should run in all frames, or only just the top one. |
290 // Defaults to false. | 327 // Defaults to false. |
291 bool match_all_frames_; | 328 bool match_all_frames_; |
292 | 329 |
293 // Whether the user script should run in about:blank and about:srcdoc as well. | 330 // Whether the user script should run in about:blank and about:srcdoc as well. |
294 // Defaults to false. | 331 // Defaults to false. |
295 bool match_about_blank_; | 332 bool match_about_blank_; |
296 | 333 |
297 // True if the script should be injected into an incognito tab. | 334 // True if the script should be injected into an incognito tab. |
298 bool incognito_enabled_; | 335 bool incognito_enabled_; |
299 }; | 336 }; |
300 | 337 |
301 // For storing UserScripts with unique IDs in sets. | 338 // For storing UserScripts with unique IDs in sets. |
302 bool operator<(const UserScript& script1, const UserScript& script2); | 339 bool operator<(const UserScript& script1, const UserScript& script2); |
303 | 340 |
304 typedef std::vector<UserScript> UserScriptList; | 341 typedef std::vector<UserScript> UserScriptList; |
305 | 342 |
306 } // namespace extensions | 343 } // namespace extensions |
307 | 344 |
308 #endif // EXTENSIONS_COMMON_USER_SCRIPT_H_ | 345 #endif // EXTENSIONS_COMMON_USER_SCRIPT_H_ |
OLD | NEW |