| 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/url_pattern.h" | 14 #include "extensions/common/url_pattern.h" |
| 15 #include "extensions/common/url_pattern_set.h" | 15 #include "extensions/common/url_pattern_set.h" |
| 16 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 17 | 17 |
| 18 class Pickle; | 18 class Pickle; |
| 19 class PickleIterator; | 19 class PickleIterator; |
| 20 | 20 |
| 21 namespace extensions { | 21 namespace extensions { |
| 22 | 22 |
| 23 // Represents a user script, either a standalone one, or one that is part of an | 23 // Represents a user script, either a standalone one, or one that is part of an |
| 24 // extension. | 24 // extension. |
| 25 class UserScript { | 25 class UserScript { |
| 26 public: | 26 public: |
| 27 // The file extension for standalone user scripts. | 27 // The file extension for standalone user scripts. |
| 28 static const char kFileExtension[]; | 28 static const char kFileExtension[]; |
| 29 | 29 |
| 30 static int GenerateUserScriptID(); |
| 31 |
| 30 // Check if a URL should be treated as a user script and converted to an | 32 // Check if a URL should be treated as a user script and converted to an |
| 31 // extension. | 33 // extension. |
| 32 static bool IsURLUserScript(const GURL& url, const std::string& mime_type); | 34 static bool IsURLUserScript(const GURL& url, const std::string& mime_type); |
| 33 | 35 |
| 34 // Get the valid user script schemes for the current process. If | 36 // Get the valid user script schemes for the current process. If |
| 35 // canExecuteScriptEverywhere is true, this will return ALL_SCHEMES. | 37 // canExecuteScriptEverywhere is true, this will return ALL_SCHEMES. |
| 36 static int ValidUserScriptSchemes(bool canExecuteScriptEverywhere = false); | 38 static int ValidUserScriptSchemes(bool canExecuteScriptEverywhere = false); |
| 37 | 39 |
| 38 // TODO(rdevlin.cronin) This and RunLocataion don't really belong here, since | 40 // TODO(rdevlin.cronin) This and RunLocataion don't really belong here, since |
| 39 // they are used for more than UserScripts (e.g., tabs.executeScript()). | 41 // they are used for more than UserScripts (e.g., tabs.executeScript()). |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 FileList& js_scripts() { return js_scripts_; } | 188 FileList& js_scripts() { return js_scripts_; } |
| 187 const FileList& js_scripts() const { return js_scripts_; } | 189 const FileList& js_scripts() const { return js_scripts_; } |
| 188 | 190 |
| 189 // List of css scripts for this user script | 191 // List of css scripts for this user script |
| 190 FileList& css_scripts() { return css_scripts_; } | 192 FileList& css_scripts() { return css_scripts_; } |
| 191 const FileList& css_scripts() const { return css_scripts_; } | 193 const FileList& css_scripts() const { return css_scripts_; } |
| 192 | 194 |
| 193 const std::string& extension_id() const { return extension_id_; } | 195 const std::string& extension_id() const { return extension_id_; } |
| 194 void set_extension_id(const std::string& id) { extension_id_ = id; } | 196 void set_extension_id(const std::string& id) { extension_id_ = id; } |
| 195 | 197 |
| 196 int64 id() const { return user_script_id_; } | 198 int id() const { return user_script_id_; } |
| 197 void set_id(int64 id) { user_script_id_ = id; } | 199 void set_id(int id) { user_script_id_ = id; } |
| 198 | 200 |
| 199 bool is_incognito_enabled() const { return incognito_enabled_; } | 201 bool is_incognito_enabled() const { return incognito_enabled_; } |
| 200 void set_incognito_enabled(bool enabled) { incognito_enabled_ = enabled; } | 202 void set_incognito_enabled(bool enabled) { incognito_enabled_ = enabled; } |
| 201 | 203 |
| 202 bool is_standalone() const { return extension_id_.empty(); } | 204 bool is_standalone() const { return extension_id_.empty(); } |
| 203 | 205 |
| 204 // Returns true if the script should be applied to the specified URL, false | 206 // Returns true if the script should be applied to the specified URL, false |
| 205 // otherwise. | 207 // otherwise. |
| 206 bool MatchesURL(const GURL& url) const; | 208 bool MatchesURL(const GURL& url) const; |
| 207 | 209 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 | 264 |
| 263 // List of css scripts defined in content_scripts | 265 // List of css scripts defined in content_scripts |
| 264 FileList css_scripts_; | 266 FileList css_scripts_; |
| 265 | 267 |
| 266 // The ID of the extension this script is a part of, if any. Can be empty if | 268 // The ID of the extension this script is a part of, if any. Can be empty if |
| 267 // the script is a "standlone" user script. | 269 // the script is a "standlone" user script. |
| 268 std::string extension_id_; | 270 std::string extension_id_; |
| 269 | 271 |
| 270 // The globally-unique id associated with this user script. Defaults to | 272 // The globally-unique id associated with this user script. Defaults to |
| 271 // -1 for invalid. | 273 // -1 for invalid. |
| 272 int64 user_script_id_; | 274 int user_script_id_; |
| 273 | 275 |
| 274 // Whether we should try to emulate Greasemonkey's APIs when running this | 276 // Whether we should try to emulate Greasemonkey's APIs when running this |
| 275 // script. | 277 // script. |
| 276 bool emulate_greasemonkey_; | 278 bool emulate_greasemonkey_; |
| 277 | 279 |
| 278 // Whether the user script should run in all frames, or only just the top one. | 280 // Whether the user script should run in all frames, or only just the top one. |
| 279 // Defaults to false. | 281 // Defaults to false. |
| 280 bool match_all_frames_; | 282 bool match_all_frames_; |
| 281 | 283 |
| 282 // Whether the user script should run in about:blank and about:srcdoc as well. | 284 // Whether the user script should run in about:blank and about:srcdoc as well. |
| 283 // Defaults to false. | 285 // Defaults to false. |
| 284 bool match_about_blank_; | 286 bool match_about_blank_; |
| 285 | 287 |
| 286 // True if the script should be injected into an incognito tab. | 288 // True if the script should be injected into an incognito tab. |
| 287 bool incognito_enabled_; | 289 bool incognito_enabled_; |
| 288 }; | 290 }; |
| 289 | 291 |
| 290 // For storing UserScripts with unique IDs in sets. | 292 // For storing UserScripts with unique IDs in sets. |
| 291 bool operator<(const UserScript& script1, const UserScript& script2); | 293 bool operator<(const UserScript& script1, const UserScript& script2); |
| 292 | 294 |
| 293 typedef std::vector<UserScript> UserScriptList; | 295 typedef std::vector<UserScript> UserScriptList; |
| 294 | 296 |
| 295 } // namespace extensions | 297 } // namespace extensions |
| 296 | 298 |
| 297 #endif // EXTENSIONS_COMMON_USER_SCRIPT_H_ | 299 #endif // EXTENSIONS_COMMON_USER_SCRIPT_H_ |
| OLD | NEW |