Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(636)

Side by Side Diff: chrome/common/extensions/user_script.cc

Issue 3207002: FBTF: Forward declare and move constructors in chrome/common/extensions/. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Win fixes Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #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 static bool UrlMatchesPatterns(const UserScript::PatternList* patterns, 11
12 const GURL& url) { 12 bool UrlMatchesPatterns(const UserScript::PatternList* patterns,
13 const GURL& url) {
13 for (UserScript::PatternList::const_iterator pattern = patterns->begin(); 14 for (UserScript::PatternList::const_iterator pattern = patterns->begin();
14 pattern != patterns->end(); ++pattern) { 15 pattern != patterns->end(); ++pattern) {
15 if (pattern->MatchesUrl(url)) 16 if (pattern->MatchesUrl(url))
16 return true; 17 return true;
17 } 18 }
18 19
19 return false; 20 return false;
20 } 21 }
21 22
22 static bool UrlMatchesGlobs(const std::vector<std::string>* globs, 23 bool UrlMatchesGlobs(const std::vector<std::string>* globs,
23 const GURL& url) { 24 const GURL& url) {
24 for (std::vector<std::string>::const_iterator glob = globs->begin(); 25 for (std::vector<std::string>::const_iterator glob = globs->begin();
25 glob != globs->end(); ++glob) { 26 glob != globs->end(); ++glob) {
26 if (MatchPatternASCII(url.spec(), *glob)) 27 if (MatchPatternASCII(url.spec(), *glob))
27 return true; 28 return true;
28 } 29 }
29 30
30 return false; 31 return false;
31 } 32 }
32 } 33
34 } // namespace
33 35
34 // static 36 // static
35 const char UserScript::kFileExtension[] = ".user.js"; 37 const char UserScript::kFileExtension[] = ".user.js";
36 38
37 // static 39 // static
38 const int UserScript::kValidUserScriptSchemes = 40 const int UserScript::kValidUserScriptSchemes =
39 URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS | 41 URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS |
40 URLPattern::SCHEME_FILE | URLPattern::SCHEME_FTP; 42 URLPattern::SCHEME_FILE | URLPattern::SCHEME_FTP;
41 43
42 bool UserScript::HasUserScriptFileExtension(const GURL& url) { 44 bool UserScript::HasUserScriptFileExtension(const GURL& url) {
43 return EndsWith(url.ExtractFileName(), kFileExtension, false); 45 return EndsWith(url.ExtractFileName(), kFileExtension, false);
44 } 46 }
45 47
46 bool UserScript::HasUserScriptFileExtension(const FilePath& path) { 48 bool UserScript::HasUserScriptFileExtension(const FilePath& path) {
47 static FilePath extension(FilePath().AppendASCII(kFileExtension)); 49 static FilePath extension(FilePath().AppendASCII(kFileExtension));
48 return EndsWith(path.BaseName().value(), extension.value(), false); 50 return EndsWith(path.BaseName().value(), extension.value(), false);
49 } 51 }
50 52
53
54 UserScript::File::File(const FilePath& extension_root,
55 const FilePath& relative_path,
56 const GURL& url)
57 : extension_root_(extension_root),
58 relative_path_(relative_path),
59 url_(url) {
60 }
61
62 UserScript::File::File() {}
63
64 UserScript::File::~File() {}
65
66 UserScript::UserScript()
67 : run_location_(DOCUMENT_IDLE), emulate_greasemonkey_(false),
68 match_all_frames_(false), incognito_enabled_(false),
69 allow_file_access_(false) {
70 }
71
72 UserScript::~UserScript() {
73 }
74
75 void UserScript::add_url_pattern(const URLPattern& pattern) {
76 url_patterns_.push_back(pattern);
77 }
78
79 void UserScript::clear_url_patterns() { url_patterns_.clear(); }
80
51 bool UserScript::MatchesUrl(const GURL& url) const { 81 bool UserScript::MatchesUrl(const GURL& url) const {
52 if (url_patterns_.size() > 0) { 82 if (url_patterns_.size() > 0) {
53 if (!UrlMatchesPatterns(&url_patterns_, url)) 83 if (!UrlMatchesPatterns(&url_patterns_, url))
54 return false; 84 return false;
55 } 85 }
56 86
57 if (globs_.size() > 0) { 87 if (globs_.size() > 0) {
58 if (!UrlMatchesGlobs(&globs_, url)) 88 if (!UrlMatchesGlobs(&globs_, url))
59 return false; 89 return false;
60 } 90 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 // Read css scripts. 212 // Read css scripts.
183 size_t num_css_files = 0; 213 size_t num_css_files = 0;
184 CHECK(pickle.ReadSize(iter, &num_css_files)); 214 CHECK(pickle.ReadSize(iter, &num_css_files));
185 css_scripts_.clear(); 215 css_scripts_.clear();
186 for (size_t i = 0; i < num_css_files; ++i) { 216 for (size_t i = 0; i < num_css_files; ++i) {
187 File file; 217 File file;
188 file.Unpickle(pickle, iter); 218 file.Unpickle(pickle, iter);
189 css_scripts_.push_back(file); 219 css_scripts_.push_back(file);
190 } 220 }
191 } 221 }
OLDNEW
« chrome/common/extensions/update_manifest.h ('K') | « chrome/common/extensions/user_script.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698