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/host_id.h" | |
15 #include "extensions/common/url_pattern.h" | 14 #include "extensions/common/url_pattern.h" |
16 #include "extensions/common/url_pattern_set.h" | 15 #include "extensions/common/url_pattern_set.h" |
17 #include "url/gurl.h" | 16 #include "url/gurl.h" |
18 | 17 |
19 class Pickle; | 18 class Pickle; |
20 class PickleIterator; | 19 class PickleIterator; |
21 | 20 |
22 namespace extensions { | 21 namespace extensions { |
23 | 22 |
24 // 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 |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 void add_exclude_url_pattern(const URLPattern& pattern); | 187 void add_exclude_url_pattern(const URLPattern& pattern); |
189 | 188 |
190 // List of js scripts for this user script | 189 // List of js scripts for this user script |
191 FileList& js_scripts() { return js_scripts_; } | 190 FileList& js_scripts() { return js_scripts_; } |
192 const FileList& js_scripts() const { return js_scripts_; } | 191 const FileList& js_scripts() const { return js_scripts_; } |
193 | 192 |
194 // List of css scripts for this user script | 193 // List of css scripts for this user script |
195 FileList& css_scripts() { return css_scripts_; } | 194 FileList& css_scripts() { return css_scripts_; } |
196 const FileList& css_scripts() const { return css_scripts_; } | 195 const FileList& css_scripts() const { return css_scripts_; } |
197 | 196 |
198 const std::string& extension_id() const { return host_id_.id(); } | 197 const std::string& extension_id() const { return extension_id_; } |
199 | 198 void set_extension_id(const std::string& id) { extension_id_ = id; } |
200 const HostID& host_id() const { return host_id_; } | |
201 void set_host_id(const HostID& host_id) { host_id_ = host_id; } | |
202 | 199 |
203 int id() const { return user_script_id_; } | 200 int id() const { return user_script_id_; } |
204 void set_id(int id) { user_script_id_ = id; } | 201 void set_id(int id) { user_script_id_ = id; } |
205 | 202 |
206 bool is_incognito_enabled() const { return incognito_enabled_; } | 203 bool is_incognito_enabled() const { return incognito_enabled_; } |
207 void set_incognito_enabled(bool enabled) { incognito_enabled_ = enabled; } | 204 void set_incognito_enabled(bool enabled) { incognito_enabled_ = enabled; } |
208 | 205 |
209 bool is_standalone() const { return extension_id().empty(); } | 206 bool is_standalone() const { return extension_id_.empty(); } |
210 | 207 |
211 // Returns true if the script should be applied to the specified URL, false | 208 // Returns true if the script should be applied to the specified URL, false |
212 // otherwise. | 209 // otherwise. |
213 bool MatchesURL(const GURL& url) const; | 210 bool MatchesURL(const GURL& url) const; |
214 | 211 |
215 // Serialize the UserScript into a pickle. The content of the scripts and | 212 // Serialize the UserScript into a pickle. The content of the scripts and |
216 // paths to UserScript::Files will not be serialized! | 213 // paths to UserScript::Files will not be serialized! |
217 void Pickle(::Pickle* pickle) const; | 214 void Pickle(::Pickle* pickle) const; |
218 | 215 |
219 // Deserialize the script from a pickle. Note that this always succeeds | 216 // 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 | 217 // because presumably we were the one that pickled it, and we did it |
221 // correctly. | 218 // correctly. |
222 void Unpickle(const ::Pickle& pickle, PickleIterator* iter); | 219 void Unpickle(const ::Pickle& pickle, PickleIterator* iter); |
223 | 220 |
224 private: | 221 private: |
225 // Pickle helper functions used to pickle the individual types of components. | 222 // Pickle helper functions used to pickle the individual types of components. |
226 void PickleGlobs(::Pickle* pickle, | 223 void PickleGlobs(::Pickle* pickle, |
227 const std::vector<std::string>& globs) const; | 224 const std::vector<std::string>& globs) const; |
228 void PickleHostID(::Pickle* pickle, const HostID& host_id) const; | |
229 void PickleURLPatternSet(::Pickle* pickle, | 225 void PickleURLPatternSet(::Pickle* pickle, |
230 const URLPatternSet& pattern_list) const; | 226 const URLPatternSet& pattern_list) const; |
231 void PickleScripts(::Pickle* pickle, const FileList& scripts) const; | 227 void PickleScripts(::Pickle* pickle, const FileList& scripts) const; |
232 | 228 |
233 // Unpickle helper functions used to unpickle individual types of components. | 229 // Unpickle helper functions used to unpickle individual types of components. |
234 void UnpickleGlobs(const ::Pickle& pickle, PickleIterator* iter, | 230 void UnpickleGlobs(const ::Pickle& pickle, PickleIterator* iter, |
235 std::vector<std::string>* globs); | 231 std::vector<std::string>* globs); |
236 void UnpickleHostID(const ::Pickle& pickle, | |
237 PickleIterator* iter, | |
238 HostID* host_id); | |
239 void UnpickleURLPatternSet(const ::Pickle& pickle, PickleIterator* iter, | 232 void UnpickleURLPatternSet(const ::Pickle& pickle, PickleIterator* iter, |
240 URLPatternSet* pattern_list); | 233 URLPatternSet* pattern_list); |
241 void UnpickleScripts(const ::Pickle& pickle, PickleIterator* iter, | 234 void UnpickleScripts(const ::Pickle& pickle, PickleIterator* iter, |
242 FileList* scripts); | 235 FileList* scripts); |
243 | 236 |
244 // The location to run the script inside the document. | 237 // The location to run the script inside the document. |
245 RunLocation run_location_; | 238 RunLocation run_location_; |
246 | 239 |
247 // The namespace of the script. This is used by Greasemonkey in the same way | 240 // 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. | 241 // as XML namespaces. Only used when parsing Greasemonkey-style scripts. |
(...skipping 18 matching lines...) Expand all Loading... |
267 // only used with scripts that are part of extensions. | 260 // only used with scripts that are part of extensions. |
268 URLPatternSet url_set_; | 261 URLPatternSet url_set_; |
269 URLPatternSet exclude_url_set_; | 262 URLPatternSet exclude_url_set_; |
270 | 263 |
271 // List of js scripts defined in content_scripts | 264 // List of js scripts defined in content_scripts |
272 FileList js_scripts_; | 265 FileList js_scripts_; |
273 | 266 |
274 // List of css scripts defined in content_scripts | 267 // List of css scripts defined in content_scripts |
275 FileList css_scripts_; | 268 FileList css_scripts_; |
276 | 269 |
277 // The ID of the host this script is a part of. The |ID| of the | 270 // The ID of the extension this script is a part of, if any. Can be empty if |
278 // |host_id| can be empty if the script is a "standlone" user script. | 271 // the script is a "standlone" user script. |
279 HostID host_id_; | 272 std::string extension_id_; |
280 | 273 |
281 // The globally-unique id associated with this user script. Defaults to | 274 // The globally-unique id associated with this user script. Defaults to |
282 // -1 for invalid. | 275 // -1 for invalid. |
283 int user_script_id_; | 276 int user_script_id_; |
284 | 277 |
285 // Whether we should try to emulate Greasemonkey's APIs when running this | 278 // Whether we should try to emulate Greasemonkey's APIs when running this |
286 // script. | 279 // script. |
287 bool emulate_greasemonkey_; | 280 bool emulate_greasemonkey_; |
288 | 281 |
289 // Whether the user script should run in all frames, or only just the top one. | 282 // Whether the user script should run in all frames, or only just the top one. |
290 // Defaults to false. | 283 // Defaults to false. |
291 bool match_all_frames_; | 284 bool match_all_frames_; |
292 | 285 |
293 // Whether the user script should run in about:blank and about:srcdoc as well. | 286 // Whether the user script should run in about:blank and about:srcdoc as well. |
294 // Defaults to false. | 287 // Defaults to false. |
295 bool match_about_blank_; | 288 bool match_about_blank_; |
296 | 289 |
297 // True if the script should be injected into an incognito tab. | 290 // True if the script should be injected into an incognito tab. |
298 bool incognito_enabled_; | 291 bool incognito_enabled_; |
299 }; | 292 }; |
300 | 293 |
301 // For storing UserScripts with unique IDs in sets. | 294 // For storing UserScripts with unique IDs in sets. |
302 bool operator<(const UserScript& script1, const UserScript& script2); | 295 bool operator<(const UserScript& script1, const UserScript& script2); |
303 | 296 |
304 typedef std::vector<UserScript> UserScriptList; | 297 typedef std::vector<UserScript> UserScriptList; |
305 | 298 |
306 } // namespace extensions | 299 } // namespace extensions |
307 | 300 |
308 #endif // EXTENSIONS_COMMON_USER_SCRIPT_H_ | 301 #endif // EXTENSIONS_COMMON_USER_SCRIPT_H_ |
OLD | NEW |