OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "googleurl/src/gurl.h" |
15 #include "chrome/common/extensions/url_pattern.h" | 15 #include "chrome/common/extensions/url_pattern.h" |
16 #include "chrome/common/extensions/url_pattern_set.h" | 16 #include "chrome/common/extensions/url_pattern_set.h" |
17 | 17 |
18 class Pickle; | 18 class Pickle; |
| 19 class PickleIterator; |
19 | 20 |
20 // Represents a user script, either a standalone one, or one that is part of an | 21 // Represents a user script, either a standalone one, or one that is part of an |
21 // extension. | 22 // extension. |
22 class UserScript { | 23 class UserScript { |
23 public: | 24 public: |
24 // The file extension for standalone user scripts. | 25 // The file extension for standalone user scripts. |
25 static const char kFileExtension[]; | 26 static const char kFileExtension[]; |
26 | 27 |
27 // The bitmask for valid user script injectable schemes used by URLPattern. | 28 // The bitmask for valid user script injectable schemes used by URLPattern. |
28 enum { | 29 enum { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 void set_external_content(const base::StringPiece& content) { | 76 void set_external_content(const base::StringPiece& content) { |
76 external_content_ = content; | 77 external_content_ = content; |
77 } | 78 } |
78 void set_content(const base::StringPiece& content) { | 79 void set_content(const base::StringPiece& content) { |
79 content_.assign(content.begin(), content.end()); | 80 content_.assign(content.begin(), content.end()); |
80 } | 81 } |
81 | 82 |
82 // Serialization support. The content and FilePath members will not be | 83 // Serialization support. The content and FilePath members will not be |
83 // serialized! | 84 // serialized! |
84 void Pickle(::Pickle* pickle) const; | 85 void Pickle(::Pickle* pickle) const; |
85 void Unpickle(const ::Pickle& pickle, void** iter); | 86 void Unpickle(const ::Pickle& pickle, PickleIterator* iter); |
86 | 87 |
87 private: | 88 private: |
88 // Where the script file lives on the disk. We keep the path split so that | 89 // Where the script file lives on the disk. We keep the path split so that |
89 // it can be localized at will. | 90 // it can be localized at will. |
90 FilePath extension_root_; | 91 FilePath extension_root_; |
91 FilePath relative_path_; | 92 FilePath relative_path_; |
92 | 93 |
93 // The url to this scipt file. | 94 // The url to this scipt file. |
94 GURL url_; | 95 GURL url_; |
95 | 96 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 // otherwise. | 181 // otherwise. |
181 bool MatchesURL(const GURL& url) const; | 182 bool MatchesURL(const GURL& url) const; |
182 | 183 |
183 // Serialize the UserScript into a pickle. The content of the scripts and | 184 // Serialize the UserScript into a pickle. The content of the scripts and |
184 // paths to UserScript::Files will not be serialized! | 185 // paths to UserScript::Files will not be serialized! |
185 void Pickle(::Pickle* pickle) const; | 186 void Pickle(::Pickle* pickle) const; |
186 | 187 |
187 // Deserialize the script from a pickle. Note that this always succeeds | 188 // Deserialize the script from a pickle. Note that this always succeeds |
188 // because presumably we were the one that pickled it, and we did it | 189 // because presumably we were the one that pickled it, and we did it |
189 // correctly. | 190 // correctly. |
190 void Unpickle(const ::Pickle& pickle, void** iter); | 191 void Unpickle(const ::Pickle& pickle, PickleIterator* iter); |
191 | 192 |
192 private: | 193 private: |
193 // Pickle helper functions used to pickle the individual types of components. | 194 // Pickle helper functions used to pickle the individual types of components. |
194 void PickleGlobs(::Pickle* pickle, | 195 void PickleGlobs(::Pickle* pickle, |
195 const std::vector<std::string>& globs) const; | 196 const std::vector<std::string>& globs) const; |
196 void PickleURLPatternSet(::Pickle* pickle, | 197 void PickleURLPatternSet(::Pickle* pickle, |
197 const URLPatternSet& pattern_list) const; | 198 const URLPatternSet& pattern_list) const; |
198 void PickleScripts(::Pickle* pickle, const FileList& scripts) const; | 199 void PickleScripts(::Pickle* pickle, const FileList& scripts) const; |
199 | 200 |
200 // Unpickle helper functions used to unpickle individual types of components. | 201 // Unpickle helper functions used to unpickle individual types of components. |
201 void UnpickleGlobs(const ::Pickle& pickle, void** iter, | 202 void UnpickleGlobs(const ::Pickle& pickle, PickleIterator* iter, |
202 std::vector<std::string>* globs); | 203 std::vector<std::string>* globs); |
203 void UnpickleURLPatternSet(const ::Pickle& pickle, void** iter, | 204 void UnpickleURLPatternSet(const ::Pickle& pickle, PickleIterator* iter, |
204 URLPatternSet* pattern_list); | 205 URLPatternSet* pattern_list); |
205 void UnpickleScripts(const ::Pickle& pickle, void** iter, | 206 void UnpickleScripts(const ::Pickle& pickle, PickleIterator* iter, |
206 FileList* scripts); | 207 FileList* scripts); |
207 | 208 |
208 // The location to run the script inside the document. | 209 // The location to run the script inside the document. |
209 RunLocation run_location_; | 210 RunLocation run_location_; |
210 | 211 |
211 // The namespace of the script. This is used by Greasemonkey in the same way | 212 // The namespace of the script. This is used by Greasemonkey in the same way |
212 // as XML namespaces. Only used when parsing Greasemonkey-style scripts. | 213 // as XML namespaces. Only used when parsing Greasemonkey-style scripts. |
213 std::string name_space_; | 214 std::string name_space_; |
214 | 215 |
215 // The script's name. Only used when parsing Greasemonkey-style scripts. | 216 // The script's name. Only used when parsing Greasemonkey-style scripts. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 // Defaults to false. | 251 // Defaults to false. |
251 bool match_all_frames_; | 252 bool match_all_frames_; |
252 | 253 |
253 // True if the script should be injected into an incognito tab. | 254 // True if the script should be injected into an incognito tab. |
254 bool incognito_enabled_; | 255 bool incognito_enabled_; |
255 }; | 256 }; |
256 | 257 |
257 typedef std::vector<UserScript> UserScriptList; | 258 typedef std::vector<UserScript> UserScriptList; |
258 | 259 |
259 #endif // CHROME_COMMON_EXTENSIONS_USER_SCRIPT_H_ | 260 #endif // CHROME_COMMON_EXTENSIONS_USER_SCRIPT_H_ |
OLD | NEW |