OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/common/extensions/user_script.h" | 5 #include "chrome/common/extensions/user_script.h" |
6 | 6 |
7 #include "base/pickle.h" | 7 #include "base/pickle.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 | 9 |
10 namespace { | 10 namespace { |
11 | 11 |
12 bool UrlMatchesGlobs(const std::vector<std::string>* globs, | 12 bool UrlMatchesGlobs(const std::vector<std::string>* globs, |
13 const GURL& url) { | 13 const GURL& url) { |
14 for (std::vector<std::string>::const_iterator glob = globs->begin(); | 14 for (std::vector<std::string>::const_iterator glob = globs->begin(); |
15 glob != globs->end(); ++glob) { | 15 glob != globs->end(); ++glob) { |
16 if (MatchPattern(url.spec(), *glob)) | 16 if (MatchPattern(url.spec(), *glob)) |
17 return true; | 17 return true; |
18 } | 18 } |
19 | 19 |
20 return false; | 20 return false; |
21 } | 21 } |
22 | 22 |
23 } // namespace | 23 } // namespace |
24 | 24 |
25 // static | 25 // static |
26 const char UserScript::kFileExtension[] = ".user.js"; | 26 const char UserScript::kFileExtension[] = ".user.js"; |
27 | 27 |
28 // static | |
29 const int UserScript::kValidUserScriptSchemes = | |
30 URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS | | |
31 URLPattern::SCHEME_FILE | URLPattern::SCHEME_FTP; | |
32 | |
33 bool UserScript::IsURLUserScript(const GURL& url, | 28 bool UserScript::IsURLUserScript(const GURL& url, |
34 const std::string& mime_type) { | 29 const std::string& mime_type) { |
35 return EndsWith(url.ExtractFileName(), kFileExtension, false) && | 30 return EndsWith(url.ExtractFileName(), kFileExtension, false) && |
36 mime_type != "text/html"; | 31 mime_type != "text/html"; |
37 } | 32 } |
38 | 33 |
39 UserScript::File::File(const FilePath& extension_root, | 34 UserScript::File::File(const FilePath& extension_root, |
40 const FilePath& relative_path, | 35 const FilePath& relative_path, |
41 const GURL& url) | 36 const GURL& url) |
42 : extension_root_(extension_root), | 37 : extension_root_(extension_root), |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 // Read css scripts. | 207 // Read css scripts. |
213 size_t num_css_files = 0; | 208 size_t num_css_files = 0; |
214 CHECK(pickle.ReadSize(iter, &num_css_files)); | 209 CHECK(pickle.ReadSize(iter, &num_css_files)); |
215 css_scripts_.clear(); | 210 css_scripts_.clear(); |
216 for (size_t i = 0; i < num_css_files; ++i) { | 211 for (size_t i = 0; i < num_css_files; ++i) { |
217 File file; | 212 File file; |
218 file.Unpickle(pickle, iter); | 213 file.Unpickle(pickle, iter); |
219 css_scripts_.push_back(file); | 214 css_scripts_.push_back(file); |
220 } | 215 } |
221 } | 216 } |
OLD | NEW |