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" | 14 #include "extensions/common/host_id.h" |
15 #include "extensions/common/url_pattern.h" | 15 #include "extensions/common/url_pattern.h" |
16 #include "extensions/common/url_pattern_set.h" | 16 #include "extensions/common/url_pattern_set.h" |
17 #include "url/gurl.h" | 17 #include "url/gurl.h" |
18 | 18 |
| 19 namespace base { |
19 class Pickle; | 20 class Pickle; |
20 class PickleIterator; | 21 class PickleIterator; |
| 22 } |
21 | 23 |
22 namespace extensions { | 24 namespace extensions { |
23 | 25 |
24 // Represents a user script, either a standalone one, or one that is part of an | 26 // Represents a user script, either a standalone one, or one that is part of an |
25 // extension. | 27 // extension. |
26 class UserScript { | 28 class UserScript { |
27 public: | 29 public: |
28 // The file extension for standalone user scripts. | 30 // The file extension for standalone user scripts. |
29 static const char kFileExtension[]; | 31 static const char kFileExtension[]; |
30 | 32 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 } | 99 } |
98 void set_external_content(const base::StringPiece& content) { | 100 void set_external_content(const base::StringPiece& content) { |
99 external_content_ = content; | 101 external_content_ = content; |
100 } | 102 } |
101 void set_content(const base::StringPiece& content) { | 103 void set_content(const base::StringPiece& content) { |
102 content_.assign(content.begin(), content.end()); | 104 content_.assign(content.begin(), content.end()); |
103 } | 105 } |
104 | 106 |
105 // Serialization support. The content and FilePath members will not be | 107 // Serialization support. The content and FilePath members will not be |
106 // serialized! | 108 // serialized! |
107 void Pickle(::Pickle* pickle) const; | 109 void Pickle(base::Pickle* pickle) const; |
108 void Unpickle(const ::Pickle& pickle, PickleIterator* iter); | 110 void Unpickle(const base::Pickle& pickle, base::PickleIterator* iter); |
109 | 111 |
110 private: | 112 private: |
111 // Where the script file lives on the disk. We keep the path split so that | 113 // Where the script file lives on the disk. We keep the path split so that |
112 // it can be localized at will. | 114 // it can be localized at will. |
113 base::FilePath extension_root_; | 115 base::FilePath extension_root_; |
114 base::FilePath relative_path_; | 116 base::FilePath relative_path_; |
115 | 117 |
116 // The url to this scipt file. | 118 // The url to this scipt file. |
117 GURL url_; | 119 GURL url_; |
118 | 120 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 void set_incognito_enabled(bool enabled) { incognito_enabled_ = enabled; } | 220 void set_incognito_enabled(bool enabled) { incognito_enabled_ = enabled; } |
219 | 221 |
220 bool is_standalone() const { return extension_id().empty(); } | 222 bool is_standalone() const { return extension_id().empty(); } |
221 | 223 |
222 // Returns true if the script should be applied to the specified URL, false | 224 // Returns true if the script should be applied to the specified URL, false |
223 // otherwise. | 225 // otherwise. |
224 bool MatchesURL(const GURL& url) const; | 226 bool MatchesURL(const GURL& url) const; |
225 | 227 |
226 // Serialize the UserScript into a pickle. The content of the scripts and | 228 // Serialize the UserScript into a pickle. The content of the scripts and |
227 // paths to UserScript::Files will not be serialized! | 229 // paths to UserScript::Files will not be serialized! |
228 void Pickle(::Pickle* pickle) const; | 230 void Pickle(base::Pickle* pickle) const; |
229 | 231 |
230 // Deserialize the script from a pickle. Note that this always succeeds | 232 // Deserialize the script from a pickle. Note that this always succeeds |
231 // because presumably we were the one that pickled it, and we did it | 233 // because presumably we were the one that pickled it, and we did it |
232 // correctly. | 234 // correctly. |
233 void Unpickle(const ::Pickle& pickle, PickleIterator* iter); | 235 void Unpickle(const base::Pickle& pickle, base::PickleIterator* iter); |
234 | 236 |
235 private: | 237 private: |
236 // Pickle helper functions used to pickle the individual types of components. | 238 // Pickle helper functions used to pickle the individual types of components. |
237 void PickleGlobs(::Pickle* pickle, | 239 void PickleGlobs(base::Pickle* pickle, |
238 const std::vector<std::string>& globs) const; | 240 const std::vector<std::string>& globs) const; |
239 void PickleHostID(::Pickle* pickle, const HostID& host_id) const; | 241 void PickleHostID(base::Pickle* pickle, const HostID& host_id) const; |
240 void PickleURLPatternSet(::Pickle* pickle, | 242 void PickleURLPatternSet(base::Pickle* pickle, |
241 const URLPatternSet& pattern_list) const; | 243 const URLPatternSet& pattern_list) const; |
242 void PickleScripts(::Pickle* pickle, const FileList& scripts) const; | 244 void PickleScripts(base::Pickle* pickle, const FileList& scripts) const; |
243 | 245 |
244 // Unpickle helper functions used to unpickle individual types of components. | 246 // Unpickle helper functions used to unpickle individual types of components. |
245 void UnpickleGlobs(const ::Pickle& pickle, PickleIterator* iter, | 247 void UnpickleGlobs(const base::Pickle& pickle, |
| 248 base::PickleIterator* iter, |
246 std::vector<std::string>* globs); | 249 std::vector<std::string>* globs); |
247 void UnpickleHostID(const ::Pickle& pickle, | 250 void UnpickleHostID(const base::Pickle& pickle, |
248 PickleIterator* iter, | 251 base::PickleIterator* iter, |
249 HostID* host_id); | 252 HostID* host_id); |
250 void UnpickleURLPatternSet(const ::Pickle& pickle, PickleIterator* iter, | 253 void UnpickleURLPatternSet(const base::Pickle& pickle, |
| 254 base::PickleIterator* iter, |
251 URLPatternSet* pattern_list); | 255 URLPatternSet* pattern_list); |
252 void UnpickleScripts(const ::Pickle& pickle, PickleIterator* iter, | 256 void UnpickleScripts(const base::Pickle& pickle, |
| 257 base::PickleIterator* iter, |
253 FileList* scripts); | 258 FileList* scripts); |
254 | 259 |
255 // The location to run the script inside the document. | 260 // The location to run the script inside the document. |
256 RunLocation run_location_; | 261 RunLocation run_location_; |
257 | 262 |
258 // The namespace of the script. This is used by Greasemonkey in the same way | 263 // The namespace of the script. This is used by Greasemonkey in the same way |
259 // as XML namespaces. Only used when parsing Greasemonkey-style scripts. | 264 // as XML namespaces. Only used when parsing Greasemonkey-style scripts. |
260 std::string name_space_; | 265 std::string name_space_; |
261 | 266 |
262 // The script's name. Only used when parsing Greasemonkey-style scripts. | 267 // The script's name. Only used when parsing Greasemonkey-style scripts. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 }; | 318 }; |
314 | 319 |
315 // For storing UserScripts with unique IDs in sets. | 320 // For storing UserScripts with unique IDs in sets. |
316 bool operator<(const UserScript& script1, const UserScript& script2); | 321 bool operator<(const UserScript& script1, const UserScript& script2); |
317 | 322 |
318 typedef std::vector<UserScript> UserScriptList; | 323 typedef std::vector<UserScript> UserScriptList; |
319 | 324 |
320 } // namespace extensions | 325 } // namespace extensions |
321 | 326 |
322 #endif // EXTENSIONS_COMMON_USER_SCRIPT_H_ | 327 #endif // EXTENSIONS_COMMON_USER_SCRIPT_H_ |
OLD | NEW |