OLD | NEW |
---|---|
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "webkit/appcache/appcache.h" | 7 #include "webkit/appcache/appcache.h" |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 GURL* found_fallback_namespace, bool* found_network_namespace) { | 186 GURL* found_fallback_namespace, bool* found_network_namespace) { |
187 // Ignore fragments when looking up URL in the cache. | 187 // Ignore fragments when looking up URL in the cache. |
188 GURL url_no_ref; | 188 GURL url_no_ref; |
189 if (url.has_ref()) { | 189 if (url.has_ref()) { |
190 GURL::Replacements replacements; | 190 GURL::Replacements replacements; |
191 replacements.ClearRef(); | 191 replacements.ClearRef(); |
192 url_no_ref = url.ReplaceComponents(replacements); | 192 url_no_ref = url.ReplaceComponents(replacements); |
193 } else { | 193 } else { |
194 url_no_ref = url; | 194 url_no_ref = url; |
195 } | 195 } |
196 | |
197 // 6.6.6 Changes to the networking model | |
198 | |
196 AppCacheEntry* entry = GetEntry(url_no_ref); | 199 AppCacheEntry* entry = GetEntry(url_no_ref); |
197 if (entry) { | 200 if (entry) { |
198 *found_entry = *entry; | 201 *found_entry = *entry; |
199 return true; | 202 return true; |
200 } | 203 } |
201 | 204 |
205 if (*found_network_namespace = | |
206 IsInNetworkNamespace(url_no_ref, online_whitelist_namespaces_)) { | |
207 return true; | |
208 } | |
209 | |
202 FallbackNamespace* fallback_namespace = FindFallbackNamespace(url_no_ref); | 210 FallbackNamespace* fallback_namespace = FindFallbackNamespace(url_no_ref); |
203 if (fallback_namespace) { | 211 if (fallback_namespace) { |
204 entry = GetEntry(fallback_namespace->second); | 212 entry = GetEntry(fallback_namespace->second); |
205 DCHECK(entry); | 213 DCHECK(entry); |
206 *found_fallback_entry = *entry; | 214 *found_fallback_entry = *entry; |
207 *found_fallback_namespace = fallback_namespace->first; | 215 *found_fallback_namespace = fallback_namespace->first; |
208 return true; | 216 return true; |
209 } | 217 } |
210 | 218 |
211 *found_network_namespace = IsInNetworkNamespace(url_no_ref); | 219 *found_network_namespace = online_whitelist_all_; |
212 return *found_network_namespace; | 220 return *found_network_namespace; |
213 } | 221 } |
214 | 222 |
215 FallbackNamespace* AppCache::FindFallbackNamespace(const GURL& url) { | 223 FallbackNamespace* AppCache::FindFallbackNamespace(const GURL& url) { |
216 size_t count = fallback_namespaces_.size(); | 224 size_t count = fallback_namespaces_.size(); |
217 for (size_t i = 0; i < count; ++i) { | 225 for (size_t i = 0; i < count; ++i) { |
218 if (StartsWithASCII( | 226 if (StartsWithASCII( |
219 url.spec(), fallback_namespaces_[i].first.spec(), true)) { | 227 url.spec(), fallback_namespaces_[i].first.spec(), true)) { |
220 return &fallback_namespaces_[i]; | 228 return &fallback_namespaces_[i]; |
221 } | 229 } |
222 } | 230 } |
223 return NULL; | 231 return NULL; |
224 } | 232 } |
225 | 233 |
226 bool AppCache::IsInNetworkNamespace(const GURL& url) { | 234 // static |
227 if (online_whitelist_all_) | 235 bool AppCache::IsInNetworkNamespace( |
228 return true; | 236 const GURL& url, |
229 | 237 const std::vector<GURL> &namespaces) { |
230 // TODO(michaeln): There are certainly better 'prefix matching' | 238 // TODO(michaeln): There are certainly better 'prefix matching' |
231 // structures and algorithms that can be applied here and above. | 239 // structures and algorithms that can be applied here and above. |
232 size_t count = online_whitelist_namespaces_.size(); | 240 size_t count = namespaces.size(); |
233 for (size_t i = 0; i < count; ++i) { | 241 for (size_t i = 0; i < count; ++i) { |
234 if (StartsWithASCII( | 242 if (StartsWithASCII( url.spec(), namespaces[i].spec(), true)) |
kinuko
2010/11/19 00:28:51
nit: extra space before url.spec()
| |
235 url.spec(), online_whitelist_namespaces_[i].spec(), true)) { | |
236 return true; | 243 return true; |
237 } | |
238 } | 244 } |
239 return false; | 245 return false; |
240 } | 246 } |
241 | 247 |
242 } // namespace appcache | 248 } // namespace appcache |
OLD | NEW |