| 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/string_piece.h" | 12 #include "base/string_piece.h" |
| 13 #include "chrome/common/extensions/extension_resource.h" |
| 13 #include "chrome/common/extensions/url_pattern.h" | 14 #include "chrome/common/extensions/url_pattern.h" |
| 14 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
| 15 | 16 |
| 16 class Pickle; | 17 class Pickle; |
| 17 | 18 |
| 18 // Represents a user script, either a standalone one, or one that is part of an | 19 // Represents a user script, either a standalone one, or one that is part of an |
| 19 // extension. | 20 // extension. |
| 20 class UserScript { | 21 class UserScript { |
| 21 public: | 22 public: |
| 22 typedef std::vector<URLPattern> PatternList; | 23 typedef std::vector<URLPattern> PatternList; |
| 23 | 24 |
| 24 // Locations that user scripts can be run inside the document. | 25 // Locations that user scripts can be run inside the document. |
| 25 enum RunLocation { | 26 enum RunLocation { |
| 26 DOCUMENT_START, // After the documentElemnet is created, but before | 27 DOCUMENT_START, // After the documentElemnet is created, but before |
| 27 // anything else happens. | 28 // anything else happens. |
| 28 DOCUMENT_END, // After the entire document is parsed. Same as | 29 DOCUMENT_END, // After the entire document is parsed. Same as |
| 29 // DOMContentLoaded. | 30 // DOMContentLoaded. |
| 30 | 31 |
| 31 RUN_LOCATION_LAST // Leave this as the last item. | 32 RUN_LOCATION_LAST // Leave this as the last item. |
| 32 }; | 33 }; |
| 33 | 34 |
| 34 // Holds actual script file info. | 35 // Holds actual script file info. |
| 35 class File { | 36 class File { |
| 36 public: | 37 public: |
| 37 File(const FilePath& path, const GURL& url): | 38 File(const ExtensionResource& resource, const GURL& url): |
| 38 path_(path), | 39 resource_(resource), |
| 39 url_(url) { | 40 url_(url) { |
| 40 } | 41 } |
| 41 File() {} | 42 File() {} |
| 42 | 43 |
| 43 const FilePath& path() const { return path_; } | 44 const ExtensionResource& resource() const { return resource_; } |
| 44 void set_path(const FilePath& path) { path_ = path; } | 45 void set_resource(const ExtensionResource& resource) { |
| 46 resource_ = resource; |
| 47 } |
| 45 | 48 |
| 46 const GURL& url() const { return url_; } | 49 const GURL& url() const { return url_; } |
| 47 void set_url(const GURL& url) { url_ = url; } | 50 void set_url(const GURL& url) { url_ = url; } |
| 48 | 51 |
| 49 // If external_content_ is set returns it as content otherwise it returns | 52 // If external_content_ is set returns it as content otherwise it returns |
| 50 // content_ | 53 // content_ |
| 51 const base::StringPiece GetContent() const { | 54 const base::StringPiece GetContent() const { |
| 52 if (external_content_.data()) | 55 if (external_content_.data()) |
| 53 return external_content_; | 56 return external_content_; |
| 54 else | 57 else |
| 55 return content_; | 58 return content_; |
| 56 } | 59 } |
| 57 void set_external_content(const base::StringPiece& content) { | 60 void set_external_content(const base::StringPiece& content) { |
| 58 external_content_ = content; | 61 external_content_ = content; |
| 59 } | 62 } |
| 60 const void set_content(const base::StringPiece& content) { | 63 const void set_content(const base::StringPiece& content) { |
| 61 content_.assign(content.begin(), content.end()); | 64 content_.assign(content.begin(), content.end()); |
| 62 } | 65 } |
| 63 | 66 |
| 64 // Serialization support. The content and path_ member will not be | 67 // Serialization support. The content and resource_ member will not be |
| 65 // serialized! | 68 // serialized! |
| 66 void Pickle(::Pickle* pickle) const; | 69 void Pickle(::Pickle* pickle) const; |
| 67 void Unpickle(const ::Pickle& pickle, void** iter); | 70 void Unpickle(const ::Pickle& pickle, void** iter); |
| 68 | 71 |
| 69 private: | 72 private: |
| 70 // Where is the script file lives on the disk. | 73 // Where the script file lives on the disk. |
| 71 FilePath path_; | 74 ExtensionResource resource_; |
| 72 | 75 |
| 73 // The url to this scipt file. | 76 // The url to this scipt file. |
| 74 GURL url_; | 77 GURL url_; |
| 75 | 78 |
| 76 // The script content. It can be set to either loaded_content_ or | 79 // The script content. It can be set to either loaded_content_ or |
| 77 // externally allocated string. | 80 // externally allocated string. |
| 78 base::StringPiece external_content_; | 81 base::StringPiece external_content_; |
| 79 | 82 |
| 80 // Set when the content is loaded by LoadContent | 83 // Set when the content is loaded by LoadContent |
| 81 std::string content_; | 84 std::string content_; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 FileList css_scripts_; | 153 FileList css_scripts_; |
| 151 | 154 |
| 152 // The ID of the extension this script is a part of, if any. Can be empty if | 155 // The ID of the extension this script is a part of, if any. Can be empty if |
| 153 // the script is a "standlone" user script. | 156 // the script is a "standlone" user script. |
| 154 std::string extension_id_; | 157 std::string extension_id_; |
| 155 }; | 158 }; |
| 156 | 159 |
| 157 typedef std::vector<UserScript> UserScriptList; | 160 typedef std::vector<UserScript> UserScriptList; |
| 158 | 161 |
| 159 #endif // CHROME_COMMON_EXTENSIONS_USER_SCRIPT_H_ | 162 #endif // CHROME_COMMON_EXTENSIONS_USER_SCRIPT_H_ |
| OLD | NEW |