| OLD | NEW |
| 1 // Copyright 2009 The Chromium Authors. All rights reserved. | 1 // Copyright 2009 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 CHROME_COMMON_EXTENSIONS_USER_SCRIPT_H_ | 5 #ifndef CHROME_COMMON_EXTENSIONS_USER_SCRIPT_H_ |
| 6 #define CHROME_COMMON_EXTENSIONS_USER_SCRIPT_H_ | 6 #define CHROME_COMMON_EXTENSIONS_USER_SCRIPT_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| 12 #include "base/string_piece.h" | 12 #include "base/string_piece.h" |
| 13 #include "chrome/common/extensions/url_pattern.h" | 13 #include "chrome/common/extensions/url_pattern.h" |
| 14 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
| 15 | 15 |
| 16 class Pickle; | 16 class Pickle; |
| 17 | 17 |
| 18 // Represents a user script, either a standalone one, or one that is part of an | 18 // Represents a user script, either a standalone one, or one that is part of an |
| 19 // extension. | 19 // extension. |
| 20 class UserScript { | 20 class UserScript { |
| 21 public: | 21 public: |
| 22 typedef std::vector<URLPattern> PatternList; |
| 23 |
| 22 // Locations that user scripts can be run inside the document. | 24 // Locations that user scripts can be run inside the document. |
| 23 enum RunLocation { | 25 enum RunLocation { |
| 24 DOCUMENT_START, // After the documentElemnet is created, but before | 26 DOCUMENT_START, // After the documentElemnet is created, but before |
| 25 // anything else happens. | 27 // anything else happens. |
| 26 DOCUMENT_END, // After the entire document is parsed. Same as | 28 DOCUMENT_END, // After the entire document is parsed. Same as |
| 27 // DOMContentLoaded. | 29 // DOMContentLoaded. |
| 28 | 30 |
| 29 RUN_LOCATION_LAST // Leave this as the last item. | 31 RUN_LOCATION_LAST // Leave this as the last item. |
| 30 }; | 32 }; |
| 31 | 33 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 void set_run_location(RunLocation location) { run_location_ = location; } | 92 void set_run_location(RunLocation location) { run_location_ = location; } |
| 91 | 93 |
| 92 // The globs, if any, that determine which pages this script runs against. | 94 // The globs, if any, that determine which pages this script runs against. |
| 93 // These are only used with "standalone" Greasemonkey-like user scripts. | 95 // These are only used with "standalone" Greasemonkey-like user scripts. |
| 94 const std::vector<std::string>& globs() const { return globs_; } | 96 const std::vector<std::string>& globs() const { return globs_; } |
| 95 void add_glob(const std::string& glob) { globs_.push_back(glob); } | 97 void add_glob(const std::string& glob) { globs_.push_back(glob); } |
| 96 void clear_globs() { globs_.clear(); } | 98 void clear_globs() { globs_.clear(); } |
| 97 | 99 |
| 98 // The URLPatterns, if any, that determine which pages this script runs | 100 // The URLPatterns, if any, that determine which pages this script runs |
| 99 // against. | 101 // against. |
| 100 const std::vector<URLPattern>& url_patterns() const { return url_patterns_; } | 102 const PatternList& url_patterns() const { return url_patterns_; } |
| 101 void add_url_pattern(const URLPattern& pattern) { | 103 void add_url_pattern(const URLPattern& pattern) { |
| 102 url_patterns_.push_back(pattern); | 104 url_patterns_.push_back(pattern); |
| 103 } | 105 } |
| 104 void clear_url_patterns() { url_patterns_.clear(); } | 106 void clear_url_patterns() { url_patterns_.clear(); } |
| 105 | 107 |
| 106 // List of js scripts for this user script | 108 // List of js scripts for this user script |
| 107 FileList& js_scripts() { return js_scripts_; } | 109 FileList& js_scripts() { return js_scripts_; } |
| 108 const FileList& js_scripts() const { return js_scripts_; } | 110 const FileList& js_scripts() const { return js_scripts_; } |
| 109 | 111 |
| 110 // List of css scripts for this user script | 112 // List of css scripts for this user script |
| (...skipping 21 matching lines...) Expand all Loading... |
| 132 private: | 134 private: |
| 133 // The location to run the script inside the document. | 135 // The location to run the script inside the document. |
| 134 RunLocation run_location_; | 136 RunLocation run_location_; |
| 135 | 137 |
| 136 // Greasemonkey-style globs that determine pages to inject the script into. | 138 // Greasemonkey-style globs that determine pages to inject the script into. |
| 137 // These are only used with standalone scripts. | 139 // These are only used with standalone scripts. |
| 138 std::vector<std::string> globs_; | 140 std::vector<std::string> globs_; |
| 139 | 141 |
| 140 // URLPatterns that determine pages to inject the script into. These are | 142 // URLPatterns that determine pages to inject the script into. These are |
| 141 // only used with scripts that are part of extensions. | 143 // only used with scripts that are part of extensions. |
| 142 std::vector<URLPattern> url_patterns_; | 144 PatternList url_patterns_; |
| 143 | 145 |
| 144 // List of js scripts defined in content_scripts | 146 // List of js scripts defined in content_scripts |
| 145 FileList js_scripts_; | 147 FileList js_scripts_; |
| 146 | 148 |
| 147 // List of css scripts defined in content_scripts | 149 // List of css scripts defined in content_scripts |
| 148 FileList css_scripts_; | 150 FileList css_scripts_; |
| 149 | 151 |
| 150 // The ID of the extension this script is a part of, if any. Can be empty if | 152 // The ID of the extension this script is a part of, if any. Can be empty if |
| 151 // the script is a "standlone" user script. | 153 // the script is a "standlone" user script. |
| 152 std::string extension_id_; | 154 std::string extension_id_; |
| 153 }; | 155 }; |
| 154 | 156 |
| 155 typedef std::vector<UserScript> UserScriptList; | 157 typedef std::vector<UserScript> UserScriptList; |
| 156 | 158 |
| 157 #endif // CHROME_COMMON_EXTENSIONS_USER_SCRIPT_H_ | 159 #endif // CHROME_COMMON_EXTENSIONS_USER_SCRIPT_H_ |
| OLD | NEW |