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

Side by Side Diff: content/browser/service_worker/service_worker_utils.cc

Issue 294593002: ServiceWorker: Support longest-prefix-match for registration scope (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remake (drop the exact-match) Created 6 years, 6 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/browser/service_worker/service_worker_utils.h" 5 #include "content/browser/service_worker/service_worker_utils.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "content/public/common/content_switches.h" 9 #include "content/public/common/content_switches.h"
10 10
(...skipping 12 matching lines...) Expand all
23 DCHECK(!url.has_ref()); 23 DCHECK(!url.has_ref());
24 const std::string& scope_spec = scope.spec(); 24 const std::string& scope_spec = scope.spec();
25 const std::string& url_spec = url.spec(); 25 const std::string& url_spec = url.spec();
26 26
27 size_t len = scope_spec.size(); 27 size_t len = scope_spec.size();
28 if (len > 0 && scope_spec[len - 1] == '*') 28 if (len > 0 && scope_spec[len - 1] == '*')
29 return scope_spec.compare(0, len - 1, url_spec, 0, len - 1) == 0; 29 return scope_spec.compare(0, len - 1, url_spec, 0, len - 1) == 0;
30 return scope_spec == url_spec; 30 return scope_spec == url_spec;
31 } 31 }
32 32
33 bool ServiceWorkerUtils::FindLongestScopeMatch(
34 const std::vector<GURL>& scopes, const GURL& url, size_t* pos) {
35 DCHECK(!url.has_ref());
36 DCHECK(pos);
37
38 bool found = false;
39 for (size_t i = 0; i < scopes.size(); ++i) {
40 if (!ScopeMatches(scopes[i], url))
41 continue;
42 if (!found || scopes.at(*pos) < scopes.at(i)) {
jsbell 2014/06/02 18:33:41 This use of < here is weird. Do you mean to be com
jsbell 2014/06/02 18:36:54 Uh, ignore this. My brain is on backwards today.
jsbell 2014/06/02 19:31:22 Ah, I did find a counterexample: url......: "foo/
nhiroki 2014/06/03 18:05:03 You're right!
43 *pos = i;
44 found = true;
45 }
46 }
47 return found;
48 }
49
33 } // namespace content 50 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698