| 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) {}; | |
| 133 ~RoutingInfo() {}; | |
| 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 | |
| 142 // Constructor. Default the run location to document end, which is like | 129 // Constructor. Default the run location to document end, which is like |
| 143 // Greasemonkey and probably more useful for typical scripts. | 130 // Greasemonkey and probably more useful for typical scripts. |
| 144 UserScript(); | 131 UserScript(); |
| 145 ~UserScript(); | 132 ~UserScript(); |
| 146 | 133 |
| 147 const std::string& name_space() const { return name_space_; } | 134 const std::string& name_space() const { return name_space_; } |
| 148 void set_name_space(const std::string& name_space) { | 135 void set_name_space(const std::string& name_space) { |
| 149 name_space_ = name_space; | 136 name_space_ = name_space; |
| 150 } | 137 } |
| 151 | 138 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 | 193 |
| 207 // List of css scripts for this user script | 194 // List of css scripts for this user script |
| 208 FileList& css_scripts() { return css_scripts_; } | 195 FileList& css_scripts() { return css_scripts_; } |
| 209 const FileList& css_scripts() const { return css_scripts_; } | 196 const FileList& css_scripts() const { return css_scripts_; } |
| 210 | 197 |
| 211 const std::string& extension_id() const { return host_id_.id(); } | 198 const std::string& extension_id() const { return host_id_.id(); } |
| 212 | 199 |
| 213 const HostID& host_id() const { return host_id_; } | 200 const HostID& host_id() const { return host_id_; } |
| 214 void set_host_id(const HostID& host_id) { host_id_ = host_id; } | 201 void set_host_id(const HostID& host_id) { host_id_ = host_id; } |
| 215 | 202 |
| 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 | |
| 229 int id() const { return user_script_id_; } | 203 int id() const { return user_script_id_; } |
| 230 void set_id(int id) { user_script_id_ = id; } | 204 void set_id(int id) { user_script_id_ = id; } |
| 231 | 205 |
| 232 bool is_incognito_enabled() const { return incognito_enabled_; } | 206 bool is_incognito_enabled() const { return incognito_enabled_; } |
| 233 void set_incognito_enabled(bool enabled) { incognito_enabled_ = enabled; } | 207 void set_incognito_enabled(bool enabled) { incognito_enabled_ = enabled; } |
| 234 | 208 |
| 235 bool is_standalone() const { return extension_id().empty(); } | 209 bool is_standalone() const { return extension_id().empty(); } |
| 236 | 210 |
| 237 // Returns true if the script should be applied to the specified URL, false | 211 // Returns true if the script should be applied to the specified URL, false |
| 238 // otherwise. | 212 // otherwise. |
| 239 bool MatchesURL(const GURL& url) const; | 213 bool MatchesURL(const GURL& url) const; |
| 240 | 214 |
| 241 // Serialize the UserScript into a pickle. The content of the scripts and | 215 // Serialize the UserScript into a pickle. The content of the scripts and |
| 242 // paths to UserScript::Files will not be serialized! | 216 // paths to UserScript::Files will not be serialized! |
| 243 void Pickle(::Pickle* pickle) const; | 217 void Pickle(::Pickle* pickle) const; |
| 244 | 218 |
| 245 // Deserialize the script from a pickle. Note that this always succeeds | 219 // Deserialize the script from a pickle. Note that this always succeeds |
| 246 // because presumably we were the one that pickled it, and we did it | 220 // because presumably we were the one that pickled it, and we did it |
| 247 // correctly. | 221 // correctly. |
| 248 void Unpickle(const ::Pickle& pickle, PickleIterator* iter); | 222 void Unpickle(const ::Pickle& pickle, PickleIterator* iter); |
| 249 | 223 |
| 250 private: | 224 private: |
| 251 // Pickle helper functions used to pickle the individual types of components. | 225 // Pickle helper functions used to pickle the individual types of components. |
| 252 void PickleGlobs(::Pickle* pickle, | 226 void PickleGlobs(::Pickle* pickle, |
| 253 const std::vector<std::string>& globs) const; | 227 const std::vector<std::string>& globs) const; |
| 254 void PickleHostID(::Pickle* pickle, const HostID& host_id) const; | 228 void PickleHostID(::Pickle* pickle, const HostID& host_id) const; |
| 255 void PickleRoutingInfo(::Pickle* pickle, | |
| 256 const RoutingInfo& routing_info) const; | |
| 257 void PickleURLPatternSet(::Pickle* pickle, | 229 void PickleURLPatternSet(::Pickle* pickle, |
| 258 const URLPatternSet& pattern_list) const; | 230 const URLPatternSet& pattern_list) const; |
| 259 void PickleScripts(::Pickle* pickle, const FileList& scripts) const; | 231 void PickleScripts(::Pickle* pickle, const FileList& scripts) const; |
| 260 | 232 |
| 261 // Unpickle helper functions used to unpickle individual types of components. | 233 // Unpickle helper functions used to unpickle individual types of components. |
| 262 void UnpickleGlobs(const ::Pickle& pickle, PickleIterator* iter, | 234 void UnpickleGlobs(const ::Pickle& pickle, PickleIterator* iter, |
| 263 std::vector<std::string>* globs); | 235 std::vector<std::string>* globs); |
| 264 void UnpickleHostID(const ::Pickle& pickle, | 236 void UnpickleHostID(const ::Pickle& pickle, |
| 265 PickleIterator* iter, | 237 PickleIterator* iter, |
| 266 HostID* host_id); | 238 HostID* host_id); |
| 267 void UnpickleRoutingInfo(const ::Pickle& pickle, | |
| 268 PickleIterator* iter, | |
| 269 RoutingInfo* routing_info); | |
| 270 void UnpickleURLPatternSet(const ::Pickle& pickle, PickleIterator* iter, | 239 void UnpickleURLPatternSet(const ::Pickle& pickle, PickleIterator* iter, |
| 271 URLPatternSet* pattern_list); | 240 URLPatternSet* pattern_list); |
| 272 void UnpickleScripts(const ::Pickle& pickle, PickleIterator* iter, | 241 void UnpickleScripts(const ::Pickle& pickle, PickleIterator* iter, |
| 273 FileList* scripts); | 242 FileList* scripts); |
| 274 | 243 |
| 275 // The location to run the script inside the document. | 244 // The location to run the script inside the document. |
| 276 RunLocation run_location_; | 245 RunLocation run_location_; |
| 277 | 246 |
| 278 // The namespace of the script. This is used by Greasemonkey in the same way | 247 // The namespace of the script. This is used by Greasemonkey in the same way |
| 279 // as XML namespaces. Only used when parsing Greasemonkey-style scripts. | 248 // as XML namespaces. Only used when parsing Greasemonkey-style scripts. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 302 // List of js scripts defined in content_scripts | 271 // List of js scripts defined in content_scripts |
| 303 FileList js_scripts_; | 272 FileList js_scripts_; |
| 304 | 273 |
| 305 // List of css scripts defined in content_scripts | 274 // List of css scripts defined in content_scripts |
| 306 FileList css_scripts_; | 275 FileList css_scripts_; |
| 307 | 276 |
| 308 // The ID of the host this script is a part of. The |ID| of the | 277 // The ID of the host this script is a part of. The |ID| of the |
| 309 // |host_id| can be empty if the script is a "standlone" user script. | 278 // |host_id| can be empty if the script is a "standlone" user script. |
| 310 HostID host_id_; | 279 HostID host_id_; |
| 311 | 280 |
| 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_; | |
| 317 | |
| 318 // The globally-unique id associated with this user script. Defaults to | 281 // The globally-unique id associated with this user script. Defaults to |
| 319 // -1 for invalid. | 282 // -1 for invalid. |
| 320 int user_script_id_; | 283 int user_script_id_; |
| 321 | 284 |
| 322 // Whether we should try to emulate Greasemonkey's APIs when running this | 285 // Whether we should try to emulate Greasemonkey's APIs when running this |
| 323 // script. | 286 // script. |
| 324 bool emulate_greasemonkey_; | 287 bool emulate_greasemonkey_; |
| 325 | 288 |
| 326 // Whether the user script should run in all frames, or only just the top one. | 289 // Whether the user script should run in all frames, or only just the top one. |
| 327 // Defaults to false. | 290 // Defaults to false. |
| 328 bool match_all_frames_; | 291 bool match_all_frames_; |
| 329 | 292 |
| 330 // Whether the user script should run in about:blank and about:srcdoc as well. | 293 // Whether the user script should run in about:blank and about:srcdoc as well. |
| 331 // Defaults to false. | 294 // Defaults to false. |
| 332 bool match_about_blank_; | 295 bool match_about_blank_; |
| 333 | 296 |
| 334 // True if the script should be injected into an incognito tab. | 297 // True if the script should be injected into an incognito tab. |
| 335 bool incognito_enabled_; | 298 bool incognito_enabled_; |
| 336 }; | 299 }; |
| 337 | 300 |
| 338 // For storing UserScripts with unique IDs in sets. | 301 // For storing UserScripts with unique IDs in sets. |
| 339 bool operator<(const UserScript& script1, const UserScript& script2); | 302 bool operator<(const UserScript& script1, const UserScript& script2); |
| 340 | 303 |
| 341 typedef std::vector<UserScript> UserScriptList; | 304 typedef std::vector<UserScript> UserScriptList; |
| 342 | 305 |
| 343 } // namespace extensions | 306 } // namespace extensions |
| 344 | 307 |
| 345 #endif // EXTENSIONS_COMMON_USER_SCRIPT_H_ | 308 #endif // EXTENSIONS_COMMON_USER_SCRIPT_H_ |
| OLD | NEW |