Chromium Code Reviews| 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 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
| 14 #include "extensions/common/consumer_instance_info.h" | |
| 14 #include "extensions/common/host_id.h" | 15 #include "extensions/common/host_id.h" |
| 15 #include "extensions/common/url_pattern.h" | 16 #include "extensions/common/url_pattern.h" |
| 16 #include "extensions/common/url_pattern_set.h" | 17 #include "extensions/common/url_pattern_set.h" |
| 17 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 18 | 19 |
| 19 class Pickle; | 20 class Pickle; |
| 20 class PickleIterator; | 21 class PickleIterator; |
| 21 | 22 |
| 22 namespace extensions { | 23 namespace extensions { |
| 23 | 24 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 // The script content. It can be set to either loaded_content_ or | 120 // The script content. It can be set to either loaded_content_ or |
| 120 // externally allocated string. | 121 // externally allocated string. |
| 121 base::StringPiece external_content_; | 122 base::StringPiece external_content_; |
| 122 | 123 |
| 123 // Set when the content is loaded by LoadContent | 124 // Set when the content is loaded by LoadContent |
| 124 std::string content_; | 125 std::string content_; |
| 125 }; | 126 }; |
| 126 | 127 |
| 127 typedef std::vector<File> FileList; | 128 typedef std::vector<File> FileList; |
| 128 | 129 |
| 130 // Render's routing info of a <webview> that the user script will be injected | |
| 131 // on. Only user scripts from <webview>s have a custom routing info. | |
| 132 struct RoutingInfo { | |
| 133 RoutingInfo() : render_process_id(-1), render_view_id(-1) {}; | |
| 134 ~RoutingInfo() {}; | |
| 135 | |
| 136 int render_process_id; | |
| 137 int render_view_id; | |
| 138 }; | |
| 139 | |
| 129 // Constructor. Default the run location to document end, which is like | 140 // Constructor. Default the run location to document end, which is like |
| 130 // Greasemonkey and probably more useful for typical scripts. | 141 // Greasemonkey and probably more useful for typical scripts. |
| 131 UserScript(); | 142 UserScript(); |
| 132 ~UserScript(); | 143 ~UserScript(); |
| 133 | 144 |
| 134 const std::string& name_space() const { return name_space_; } | 145 const std::string& name_space() const { return name_space_; } |
| 135 void set_name_space(const std::string& name_space) { | 146 void set_name_space(const std::string& name_space) { |
| 136 name_space_ = name_space; | 147 name_space_ = name_space; |
| 137 } | 148 } |
| 138 | 149 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 | 204 |
| 194 // List of css scripts for this user script | 205 // List of css scripts for this user script |
| 195 FileList& css_scripts() { return css_scripts_; } | 206 FileList& css_scripts() { return css_scripts_; } |
| 196 const FileList& css_scripts() const { return css_scripts_; } | 207 const FileList& css_scripts() const { return css_scripts_; } |
| 197 | 208 |
| 198 const std::string& extension_id() const { return host_id_.id(); } | 209 const std::string& extension_id() const { return host_id_.id(); } |
| 199 | 210 |
| 200 const HostID& host_id() const { return host_id_; } | 211 const HostID& host_id() const { return host_id_; } |
| 201 void set_host_id(const HostID& host_id) { host_id_ = host_id; } | 212 void set_host_id(const HostID& host_id) { host_id_ = host_id; } |
| 202 | 213 |
| 214 const ConsumerInstanceInfo& consumer_instance_info() const { | |
| 215 return consumer_instance_info_; | |
| 216 } | |
| 217 void set_consumer_instance_info(const ConsumerInstanceInfo& instance_info) { | |
|
Devlin
2015/02/11 20:29:01
I don't see these being set anywhere yet - are the
Xi Han
2015/02/11 21:57:24
Yes, once we have add/remove content scripts APIs
| |
| 218 consumer_instance_info_ = instance_info; | |
| 219 } | |
| 220 | |
| 221 const RoutingInfo& routing_info() const { return routing_info_; } | |
| 222 void set_routing_info(const RoutingInfo& routing_info) { | |
| 223 routing_info_ = routing_info; | |
| 224 } | |
| 225 | |
| 203 int id() const { return user_script_id_; } | 226 int id() const { return user_script_id_; } |
| 204 void set_id(int id) { user_script_id_ = id; } | 227 void set_id(int id) { user_script_id_ = id; } |
| 205 | 228 |
| 206 bool is_incognito_enabled() const { return incognito_enabled_; } | 229 bool is_incognito_enabled() const { return incognito_enabled_; } |
| 207 void set_incognito_enabled(bool enabled) { incognito_enabled_ = enabled; } | 230 void set_incognito_enabled(bool enabled) { incognito_enabled_ = enabled; } |
| 208 | 231 |
| 209 bool is_standalone() const { return extension_id().empty(); } | 232 bool is_standalone() const { return extension_id().empty(); } |
| 210 | 233 |
| 211 // Returns true if the script should be applied to the specified URL, false | 234 // Returns true if the script should be applied to the specified URL, false |
| 212 // otherwise. | 235 // otherwise. |
| 213 bool MatchesURL(const GURL& url) const; | 236 bool MatchesURL(const GURL& url) const; |
| 214 | 237 |
| 215 // Serialize the UserScript into a pickle. The content of the scripts and | 238 // Serialize the UserScript into a pickle. The content of the scripts and |
| 216 // paths to UserScript::Files will not be serialized! | 239 // paths to UserScript::Files will not be serialized! |
| 217 void Pickle(::Pickle* pickle) const; | 240 void Pickle(::Pickle* pickle) const; |
| 218 | 241 |
| 219 // Deserialize the script from a pickle. Note that this always succeeds | 242 // 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 | 243 // because presumably we were the one that pickled it, and we did it |
| 221 // correctly. | 244 // correctly. |
| 222 void Unpickle(const ::Pickle& pickle, PickleIterator* iter); | 245 void Unpickle(const ::Pickle& pickle, PickleIterator* iter); |
| 223 | 246 |
| 224 private: | 247 private: |
| 225 // Pickle helper functions used to pickle the individual types of components. | 248 // Pickle helper functions used to pickle the individual types of components. |
| 226 void PickleGlobs(::Pickle* pickle, | 249 void PickleGlobs(::Pickle* pickle, |
| 227 const std::vector<std::string>& globs) const; | 250 const std::vector<std::string>& globs) const; |
| 228 void PickleHostID(::Pickle* pickle, const HostID& host_id) const; | 251 void PickleHostID(::Pickle* pickle, const HostID& host_id) const; |
| 252 void PickleConsumerInstanceInfo( | |
| 253 ::Pickle* pickle, | |
| 254 const ConsumerInstanceInfo& consumer_instance_info) 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 UnpickleConsumerInstanceInfo( | |
| 268 const ::Pickle& pickle, | |
| 269 PickleIterator* iter, | |
| 270 ConsumerInstanceInfo* consumer_instance_info); | |
| 271 void UnpickleRoutingInfo(const ::Pickle& pickle, | |
| 272 PickleIterator* iter, | |
| 273 RoutingInfo* routing_info); | |
| 239 void UnpickleURLPatternSet(const ::Pickle& pickle, PickleIterator* iter, | 274 void UnpickleURLPatternSet(const ::Pickle& pickle, PickleIterator* iter, |
| 240 URLPatternSet* pattern_list); | 275 URLPatternSet* pattern_list); |
| 241 void UnpickleScripts(const ::Pickle& pickle, PickleIterator* iter, | 276 void UnpickleScripts(const ::Pickle& pickle, PickleIterator* iter, |
| 242 FileList* scripts); | 277 FileList* scripts); |
| 243 | 278 |
| 244 // The location to run the script inside the document. | 279 // The location to run the script inside the document. |
| 245 RunLocation run_location_; | 280 RunLocation run_location_; |
| 246 | 281 |
| 247 // The namespace of the script. This is used by Greasemonkey in the same way | 282 // 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. | 283 // 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 | 306 // List of js scripts defined in content_scripts |
| 272 FileList js_scripts_; | 307 FileList js_scripts_; |
| 273 | 308 |
| 274 // List of css scripts defined in content_scripts | 309 // List of css scripts defined in content_scripts |
| 275 FileList css_scripts_; | 310 FileList css_scripts_; |
| 276 | 311 |
| 277 // The ID of the host this script is a part of. The |ID| of the | 312 // 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. | 313 // |host_id| can be empty if the script is a "standlone" user script. |
| 279 HostID host_id_; | 314 HostID host_id_; |
| 280 | 315 |
| 316 // The type and id of the consumer instance that the script will be injected. | |
| 317 ConsumerInstanceInfo consumer_instance_info_; | |
| 318 | |
| 319 // The render side's rounting info for content_scripts of <webview>. | |
| 320 RoutingInfo routing_info_; | |
| 321 | |
| 281 // The globally-unique id associated with this user script. Defaults to | 322 // The globally-unique id associated with this user script. Defaults to |
| 282 // -1 for invalid. | 323 // -1 for invalid. |
| 283 int user_script_id_; | 324 int user_script_id_; |
| 284 | 325 |
| 285 // Whether we should try to emulate Greasemonkey's APIs when running this | 326 // Whether we should try to emulate Greasemonkey's APIs when running this |
| 286 // script. | 327 // script. |
| 287 bool emulate_greasemonkey_; | 328 bool emulate_greasemonkey_; |
| 288 | 329 |
| 289 // Whether the user script should run in all frames, or only just the top one. | 330 // Whether the user script should run in all frames, or only just the top one. |
| 290 // Defaults to false. | 331 // Defaults to false. |
| 291 bool match_all_frames_; | 332 bool match_all_frames_; |
| 292 | 333 |
| 293 // Whether the user script should run in about:blank and about:srcdoc as well. | 334 // Whether the user script should run in about:blank and about:srcdoc as well. |
| 294 // Defaults to false. | 335 // Defaults to false. |
| 295 bool match_about_blank_; | 336 bool match_about_blank_; |
| 296 | 337 |
| 297 // True if the script should be injected into an incognito tab. | 338 // True if the script should be injected into an incognito tab. |
| 298 bool incognito_enabled_; | 339 bool incognito_enabled_; |
| 299 }; | 340 }; |
| 300 | 341 |
| 301 // For storing UserScripts with unique IDs in sets. | 342 // For storing UserScripts with unique IDs in sets. |
| 302 bool operator<(const UserScript& script1, const UserScript& script2); | 343 bool operator<(const UserScript& script1, const UserScript& script2); |
| 303 | 344 |
| 304 typedef std::vector<UserScript> UserScriptList; | 345 typedef std::vector<UserScript> UserScriptList; |
| 305 | 346 |
| 306 } // namespace extensions | 347 } // namespace extensions |
| 307 | 348 |
| 308 #endif // EXTENSIONS_COMMON_USER_SCRIPT_H_ | 349 #endif // EXTENSIONS_COMMON_USER_SCRIPT_H_ |
| OLD | NEW |