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