| 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/pickle.h" | 12 #include "base/pickle.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 // Represents a user script, either a standalone one, or one that is part of an | 16 // Represents a user script, either a standalone one, or one that is part of an |
| 17 // extension. | 17 // extension. |
| 18 class UserScript { | 18 class UserScript { |
| 19 public: | 19 public: |
| 20 UserScript(){} | 20 // Locations that user scripts can be run inside the document. |
| 21 enum RunLocation { |
| 22 DOCUMENT_START, // After the documentElemnet is created, but before |
| 23 // anything else happens. |
| 24 DOCUMENT_END, // After the entire document is parsed. Same as |
| 25 // DOMContentLoaded. |
| 26 |
| 27 RUN_LOCATION_LAST // Leave this as the last item. |
| 28 }; |
| 29 |
| 30 // Constructor. Default the run location to document end, which is like |
| 31 // Greasemonkey and probably more useful for typical scripts. |
| 32 UserScript() : run_location_(DOCUMENT_END) {} |
| 21 | 33 |
| 22 // The URL to retrieve the content of this script at. | 34 // The URL to retrieve the content of this script at. |
| 23 const GURL& url() const { return url_; } | 35 const GURL& url() const { return url_; } |
| 24 void set_url(const GURL& url) { url_ = url; } | 36 void set_url(const GURL& url) { url_ = url; } |
| 25 | 37 |
| 26 // The path to find the script at. | 38 // The path to find the script at. |
| 27 const FilePath& path() const { return path_; } | 39 const FilePath& path() const { return path_; } |
| 28 void set_path(const FilePath& path) { path_ = path; } | 40 void set_path(const FilePath& path) { path_ = path; } |
| 29 | 41 |
| 42 // The place in the document to run the script. |
| 43 RunLocation run_location() const { return run_location_; } |
| 44 void set_run_location(RunLocation location) { run_location_ = location; } |
| 45 |
| 30 // The globs, if any, that determine which pages this script runs against. | 46 // The globs, if any, that determine which pages this script runs against. |
| 31 // These are only used with "standalone" Greasemonkey-like user scripts. | 47 // These are only used with "standalone" Greasemonkey-like user scripts. |
| 32 const std::vector<std::string>& globs() const { return globs_; } | 48 const std::vector<std::string>& globs() const { return globs_; } |
| 33 void add_glob(const std::string& glob) { globs_.push_back(glob); } | 49 void add_glob(const std::string& glob) { globs_.push_back(glob); } |
| 34 void clear_globs() { globs_.clear(); } | 50 void clear_globs() { globs_.clear(); } |
| 35 | 51 |
| 36 // The URLPatterns, if any, that determine which pages this script runs | 52 // The URLPatterns, if any, that determine which pages this script runs |
| 37 // against. | 53 // against. |
| 38 const std::vector<URLPattern>& url_patterns() const { return url_patterns_; } | 54 const std::vector<URLPattern>& url_patterns() const { return url_patterns_; } |
| 39 void add_url_pattern(const URLPattern& pattern) { | 55 void add_url_pattern(const URLPattern& pattern) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 53 // correctly. | 69 // correctly. |
| 54 void Unpickle(const ::Pickle& pickle, void** iter); | 70 void Unpickle(const ::Pickle& pickle, void** iter); |
| 55 | 71 |
| 56 private: | 72 private: |
| 57 // The URL to the content of the script. | 73 // The URL to the content of the script. |
| 58 GURL url_; | 74 GURL url_; |
| 59 | 75 |
| 60 // The path to the content of the script. | 76 // The path to the content of the script. |
| 61 FilePath path_; | 77 FilePath path_; |
| 62 | 78 |
| 79 // The location to run the script inside the document. |
| 80 RunLocation run_location_; |
| 81 |
| 63 // Greasemonkey-style globs that determine pages to inject the script into. | 82 // Greasemonkey-style globs that determine pages to inject the script into. |
| 64 // These are only used with standalone scripts. | 83 // These are only used with standalone scripts. |
| 65 std::vector<std::string> globs_; | 84 std::vector<std::string> globs_; |
| 66 | 85 |
| 67 // URLPatterns that determine pages to inject the script into. These are | 86 // URLPatterns that determine pages to inject the script into. These are |
| 68 // only used with scripts that are part of extensions. | 87 // only used with scripts that are part of extensions. |
| 69 std::vector<URLPattern> url_patterns_; | 88 std::vector<URLPattern> url_patterns_; |
| 70 }; | 89 }; |
| 71 | 90 |
| 72 typedef std::vector<UserScript> UserScriptList; | 91 typedef std::vector<UserScript> UserScriptList; |
| 73 | 92 |
| 74 #endif // CHROME_COMMON_EXTENSIONS_USER_SCRIPT_H_ | 93 #endif // CHROME_COMMON_EXTENSIONS_USER_SCRIPT_H_ |
| OLD | NEW |