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

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

Issue 165366: Merge 22260 - When a content script has a match pattern of http://*/*, we... (Closed) Base URL: svn://chrome-svn/chrome/branches/195/src/
Patch Set: Created 11 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/common/extensions/url_pattern_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:mergeinfo
Merged /trunk/src/chrome/common/extensions/url_pattern.cc:r22260
Merged /branches/chrome_webkit_merge_branch/chrome/common/extensions/url_pattern.cc:r69-2775
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-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/url_pattern.h" 5 #include "chrome/common/extensions/url_pattern.h"
6 6
7 #include "base/string_piece.h" 7 #include "base/string_piece.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "chrome/common/url_constants.h" 9 #include "chrome/common/url_constants.h"
10 10
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 if (!MatchesHost(test)) 87 if (!MatchesHost(test))
88 return false; 88 return false;
89 89
90 if (!MatchesPath(test)) 90 if (!MatchesPath(test))
91 return false; 91 return false;
92 92
93 return true; 93 return true;
94 } 94 }
95 95
96 bool URLPattern::MatchesHost(const GURL& test) const { 96 bool URLPattern::MatchesHost(const GURL& test) const {
97 // If the hosts are exactly equal, we have a match.
97 if (test.host() == host_) 98 if (test.host() == host_)
98 return true; 99 return true;
99 100
100 if (!match_subdomains_ || test.HostIsIPAddress()) 101 // If we're matching subdomains, and we have no host in the match pattern,
102 // that means that we're matching all hosts, which means we have a match no
103 // matter what the test host is.
104 if (match_subdomains_ && host_.empty())
105 return true;
106
107 // Otherwise, we can only match if our match pattern matches subdomains.
108 if (!match_subdomains_)
101 return false; 109 return false;
102 110
103 // If we're matching subdomains, and we have no host, that means the pattern 111 // We don't do subdomain matching against IP addresses, so we can give up now
104 // was <scheme>://*/<whatever>, so we match anything. 112 // if the test host is an IP address.
105 if (host_.empty()) 113 if (test.HostIsIPAddress())
106 return true; 114 return false;
107 115
108 // Check if the test host is a subdomain of our host. 116 // Check if the test host is a subdomain of our host.
109 if (test.host().length() <= (host_.length() + 1)) 117 if (test.host().length() <= (host_.length() + 1))
110 return false; 118 return false;
111 119
112 if (test.host().compare(test.host().length() - host_.length(), 120 if (test.host().compare(test.host().length() - host_.length(),
113 host_.length(), host_) != 0) 121 host_.length(), host_) != 0)
114 return false; 122 return false;
115 123
116 return test.host()[test.host().length() - host_.length() - 1] == '.'; 124 return test.host()[test.host().length() - host_.length() - 1] == '.';
(...skipping 22 matching lines...) Expand all
139 } 147 }
140 148
141 if (!host_.empty()) 149 if (!host_.empty())
142 spec += host_; 150 spec += host_;
143 151
144 if (!path_.empty()) 152 if (!path_.empty())
145 spec += path_; 153 spec += path_;
146 154
147 return spec; 155 return spec;
148 } 156 }
OLDNEW
« no previous file with comments | « no previous file | chrome/common/extensions/url_pattern_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698