OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/string_piece.h" | 13 #include "base/string_piece.h" |
| 14 #include "googleurl/src/gurl.h" |
14 #include "chrome/common/extensions/url_pattern.h" | 15 #include "chrome/common/extensions/url_pattern.h" |
15 #include "googleurl/src/gurl.h" | |
16 | 16 |
17 class Pickle; | 17 class Pickle; |
| 18 class URLPattern; |
18 | 19 |
19 // Represents a user script, either a standalone one, or one that is part of an | 20 // Represents a user script, either a standalone one, or one that is part of an |
20 // extension. | 21 // extension. |
21 class UserScript { | 22 class UserScript { |
22 public: | 23 public: |
23 typedef std::vector<URLPattern> PatternList; | 24 typedef std::vector<URLPattern> PatternList; |
24 | 25 |
25 // The file extension for standalone user scripts. | 26 // The file extension for standalone user scripts. |
26 static const char kFileExtension[]; | 27 static const char kFileExtension[]; |
27 | 28 |
(...skipping 15 matching lines...) Expand all Loading... |
43 // min(DOM_CONTENT_LOADED + TIMEOUT, ONLOAD), but no | 44 // min(DOM_CONTENT_LOADED + TIMEOUT, ONLOAD), but no |
44 // particular injection point is guaranteed. | 45 // particular injection point is guaranteed. |
45 | 46 |
46 RUN_LOCATION_LAST // Leave this as the last item. | 47 RUN_LOCATION_LAST // Leave this as the last item. |
47 }; | 48 }; |
48 | 49 |
49 // Holds actual script file info. | 50 // Holds actual script file info. |
50 class File { | 51 class File { |
51 public: | 52 public: |
52 File(const FilePath& extension_root, const FilePath& relative_path, | 53 File(const FilePath& extension_root, const FilePath& relative_path, |
53 const GURL& url): | 54 const GURL& url); |
54 extension_root_(extension_root), | 55 File(); |
55 relative_path_(relative_path), | 56 ~File(); |
56 url_(url) { | |
57 } | |
58 File() {} | |
59 | 57 |
60 const FilePath& extension_root() const { return extension_root_; } | 58 const FilePath& extension_root() const { return extension_root_; } |
61 const FilePath& relative_path() const { return relative_path_; } | 59 const FilePath& relative_path() const { return relative_path_; } |
62 | 60 |
63 const GURL& url() const { return url_; } | 61 const GURL& url() const { return url_; } |
64 void set_url(const GURL& url) { url_ = url; } | 62 void set_url(const GURL& url) { url_ = url; } |
65 | 63 |
66 // If external_content_ is set returns it as content otherwise it returns | 64 // If external_content_ is set returns it as content otherwise it returns |
67 // content_ | 65 // content_ |
68 const base::StringPiece GetContent() const { | 66 const base::StringPiece GetContent() const { |
(...skipping 28 matching lines...) Expand all Loading... |
97 base::StringPiece external_content_; | 95 base::StringPiece external_content_; |
98 | 96 |
99 // Set when the content is loaded by LoadContent | 97 // Set when the content is loaded by LoadContent |
100 std::string content_; | 98 std::string content_; |
101 }; | 99 }; |
102 | 100 |
103 typedef std::vector<File> FileList; | 101 typedef std::vector<File> FileList; |
104 | 102 |
105 // Constructor. Default the run location to document end, which is like | 103 // Constructor. Default the run location to document end, which is like |
106 // Greasemonkey and probably more useful for typical scripts. | 104 // Greasemonkey and probably more useful for typical scripts. |
107 UserScript() | 105 UserScript(); |
108 : run_location_(DOCUMENT_IDLE), emulate_greasemonkey_(false), | 106 ~UserScript(); |
109 match_all_frames_(false), incognito_enabled_(false), | |
110 allow_file_access_(false) { | |
111 } | |
112 | 107 |
113 const std::string& name_space() const { return name_space_; } | 108 const std::string& name_space() const { return name_space_; } |
114 void set_name_space(const std::string& name_space) { | 109 void set_name_space(const std::string& name_space) { |
115 name_space_ = name_space; | 110 name_space_ = name_space; |
116 } | 111 } |
117 | 112 |
118 const std::string& name() const { return name_; } | 113 const std::string& name() const { return name_; } |
119 void set_name(const std::string& name) { name_ = name; } | 114 void set_name(const std::string& name) { name_ = name; } |
120 | 115 |
121 const std::string& version() const { return version_; } | 116 const std::string& version() const { return version_; } |
(...skipping 27 matching lines...) Expand all Loading... |
149 return exclude_globs_; | 144 return exclude_globs_; |
150 } | 145 } |
151 void add_exclude_glob(const std::string& glob) { | 146 void add_exclude_glob(const std::string& glob) { |
152 exclude_globs_.push_back(glob); | 147 exclude_globs_.push_back(glob); |
153 } | 148 } |
154 void clear_exclude_globs() { exclude_globs_.clear(); } | 149 void clear_exclude_globs() { exclude_globs_.clear(); } |
155 | 150 |
156 // The URLPatterns, if any, that determine which pages this script runs | 151 // The URLPatterns, if any, that determine which pages this script runs |
157 // against. | 152 // against. |
158 const PatternList& url_patterns() const { return url_patterns_; } | 153 const PatternList& url_patterns() const { return url_patterns_; } |
159 void add_url_pattern(const URLPattern& pattern) { | 154 void add_url_pattern(const URLPattern& pattern); |
160 url_patterns_.push_back(pattern); | 155 void clear_url_patterns(); |
161 } | |
162 void clear_url_patterns() { url_patterns_.clear(); } | |
163 | 156 |
164 // List of js scripts for this user script | 157 // List of js scripts for this user script |
165 FileList& js_scripts() { return js_scripts_; } | 158 FileList& js_scripts() { return js_scripts_; } |
166 const FileList& js_scripts() const { return js_scripts_; } | 159 const FileList& js_scripts() const { return js_scripts_; } |
167 | 160 |
168 // List of css scripts for this user script | 161 // List of css scripts for this user script |
169 FileList& css_scripts() { return css_scripts_; } | 162 FileList& css_scripts() { return css_scripts_; } |
170 const FileList& css_scripts() const { return css_scripts_; } | 163 const FileList& css_scripts() const { return css_scripts_; } |
171 | 164 |
172 const std::string& extension_id() const { return extension_id_; } | 165 const std::string& extension_id() const { return extension_id_; } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 // True if the script should be injected into an incognito tab. | 234 // True if the script should be injected into an incognito tab. |
242 bool incognito_enabled_; | 235 bool incognito_enabled_; |
243 | 236 |
244 // True if the user agreed to allow this script access to file URLs. | 237 // True if the user agreed to allow this script access to file URLs. |
245 bool allow_file_access_; | 238 bool allow_file_access_; |
246 }; | 239 }; |
247 | 240 |
248 typedef std::vector<UserScript> UserScriptList; | 241 typedef std::vector<UserScript> UserScriptList; |
249 | 242 |
250 #endif // CHROME_COMMON_EXTENSIONS_USER_SCRIPT_H_ | 243 #endif // CHROME_COMMON_EXTENSIONS_USER_SCRIPT_H_ |
OLD | NEW |