| 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/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 12 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
| 13 #include "extensions/common/url_pattern.h" | 14 #include "extensions/common/url_pattern.h" |
| 14 #include "extensions/common/url_pattern_set.h" | 15 #include "extensions/common/url_pattern_set.h" |
| 15 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 16 | 17 |
| 17 class Pickle; | 18 class Pickle; |
| 18 class PickleIterator; | 19 class PickleIterator; |
| 19 | 20 |
| 20 namespace extensions { | 21 namespace extensions { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 38 enum RunLocation { | 39 enum RunLocation { |
| 39 UNDEFINED, | 40 UNDEFINED, |
| 40 DOCUMENT_START, // After the documentElement is created, but before | 41 DOCUMENT_START, // After the documentElement is created, but before |
| 41 // anything else happens. | 42 // anything else happens. |
| 42 DOCUMENT_END, // After the entire document is parsed. Same as | 43 DOCUMENT_END, // After the entire document is parsed. Same as |
| 43 // DOMContentLoaded. | 44 // DOMContentLoaded. |
| 44 DOCUMENT_IDLE, // Sometime after DOMContentLoaded, as soon as the document | 45 DOCUMENT_IDLE, // Sometime after DOMContentLoaded, as soon as the document |
| 45 // is "idle". Currently this uses the simple heuristic of: | 46 // is "idle". Currently this uses the simple heuristic of: |
| 46 // min(DOM_CONTENT_LOADED + TIMEOUT, ONLOAD), but no | 47 // min(DOM_CONTENT_LOADED + TIMEOUT, ONLOAD), but no |
| 47 // particular injection point is guaranteed. | 48 // particular injection point is guaranteed. |
| 49 RUN_DEFERRED, // The user script's injection was deferred for permissions |
| 50 // reasons, and was executed at a later time. |
| 48 RUN_LOCATION_LAST // Leave this as the last item. | 51 RUN_LOCATION_LAST // Leave this as the last item. |
| 49 }; | 52 }; |
| 50 | 53 |
| 51 // Holds actual script file info. | 54 // Holds actual script file info. |
| 52 class File { | 55 class File { |
| 53 public: | 56 public: |
| 54 File(const base::FilePath& extension_root, | 57 File(const base::FilePath& extension_root, |
| 55 const base::FilePath& relative_path, | 58 const base::FilePath& relative_path, |
| 56 const GURL& url); | 59 const GURL& url); |
| 57 File(); | 60 File(); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 FileList& js_scripts() { return js_scripts_; } | 170 FileList& js_scripts() { return js_scripts_; } |
| 168 const FileList& js_scripts() const { return js_scripts_; } | 171 const FileList& js_scripts() const { return js_scripts_; } |
| 169 | 172 |
| 170 // List of css scripts for this user script | 173 // List of css scripts for this user script |
| 171 FileList& css_scripts() { return css_scripts_; } | 174 FileList& css_scripts() { return css_scripts_; } |
| 172 const FileList& css_scripts() const { return css_scripts_; } | 175 const FileList& css_scripts() const { return css_scripts_; } |
| 173 | 176 |
| 174 const std::string& extension_id() const { return extension_id_; } | 177 const std::string& extension_id() const { return extension_id_; } |
| 175 void set_extension_id(const std::string& id) { extension_id_ = id; } | 178 void set_extension_id(const std::string& id) { extension_id_ = id; } |
| 176 | 179 |
| 180 int64 id() const { return user_script_id_; } |
| 181 void set_id(int64 id) { user_script_id_ = id; } |
| 182 |
| 177 bool is_incognito_enabled() const { return incognito_enabled_; } | 183 bool is_incognito_enabled() const { return incognito_enabled_; } |
| 178 void set_incognito_enabled(bool enabled) { incognito_enabled_ = enabled; } | 184 void set_incognito_enabled(bool enabled) { incognito_enabled_ = enabled; } |
| 179 | 185 |
| 180 bool is_standalone() const { return extension_id_.empty(); } | 186 bool is_standalone() const { return extension_id_.empty(); } |
| 181 | 187 |
| 182 // Returns true if the script should be applied to the specified URL, false | 188 // Returns true if the script should be applied to the specified URL, false |
| 183 // otherwise. | 189 // otherwise. |
| 184 bool MatchesURL(const GURL& url) const; | 190 bool MatchesURL(const GURL& url) const; |
| 185 | 191 |
| 186 // Serialize the UserScript into a pickle. The content of the scripts and | 192 // Serialize the UserScript into a pickle. The content of the scripts and |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 // List of js scripts defined in content_scripts | 244 // List of js scripts defined in content_scripts |
| 239 FileList js_scripts_; | 245 FileList js_scripts_; |
| 240 | 246 |
| 241 // List of css scripts defined in content_scripts | 247 // List of css scripts defined in content_scripts |
| 242 FileList css_scripts_; | 248 FileList css_scripts_; |
| 243 | 249 |
| 244 // The ID of the extension this script is a part of, if any. Can be empty if | 250 // The ID of the extension this script is a part of, if any. Can be empty if |
| 245 // the script is a "standlone" user script. | 251 // the script is a "standlone" user script. |
| 246 std::string extension_id_; | 252 std::string extension_id_; |
| 247 | 253 |
| 254 // The globally-unique id associated with this user script. Defaults to |
| 255 // -1 for invalid. |
| 256 int64 user_script_id_; |
| 257 |
| 248 // Whether we should try to emulate Greasemonkey's APIs when running this | 258 // Whether we should try to emulate Greasemonkey's APIs when running this |
| 249 // script. | 259 // script. |
| 250 bool emulate_greasemonkey_; | 260 bool emulate_greasemonkey_; |
| 251 | 261 |
| 252 // Whether the user script should run in all frames, or only just the top one. | 262 // Whether the user script should run in all frames, or only just the top one. |
| 253 // Defaults to false. | 263 // Defaults to false. |
| 254 bool match_all_frames_; | 264 bool match_all_frames_; |
| 255 | 265 |
| 256 // Whether the user script should run in about:blank and about:srcdoc as well. | 266 // Whether the user script should run in about:blank and about:srcdoc as well. |
| 257 // Defaults to false. | 267 // Defaults to false. |
| 258 bool match_about_blank_; | 268 bool match_about_blank_; |
| 259 | 269 |
| 260 // True if the script should be injected into an incognito tab. | 270 // True if the script should be injected into an incognito tab. |
| 261 bool incognito_enabled_; | 271 bool incognito_enabled_; |
| 262 }; | 272 }; |
| 263 | 273 |
| 264 typedef std::vector<UserScript> UserScriptList; | 274 typedef std::vector<UserScript> UserScriptList; |
| 265 | 275 |
| 266 } // namespace extensions | 276 } // namespace extensions |
| 267 | 277 |
| 268 #endif // EXTENSIONS_COMMON_USER_SCRIPT_H_ | 278 #endif // EXTENSIONS_COMMON_USER_SCRIPT_H_ |
| OLD | NEW |