OLD | NEW |
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/common/service_worker/service_worker_utils.h" | 5 #include "content/common/service_worker/service_worker_utils.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
| 9 #include "base/command_line.h" |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "content/public/common/content_switches.h" |
11 #include "content/public/common/origin_util.h" | 13 #include "content/public/common/origin_util.h" |
12 | 14 |
13 namespace content { | 15 namespace content { |
14 | 16 |
15 namespace { | 17 namespace { |
16 | 18 |
17 bool PathContainsDisallowedCharacter(const GURL& url) { | 19 bool PathContainsDisallowedCharacter(const GURL& url) { |
18 std::string path = url.path(); | 20 std::string path = url.path(); |
19 DCHECK(base::IsStringUTF8(path)); | 21 DCHECK(base::IsStringUTF8(path)); |
20 | 22 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 return false; | 111 return false; |
110 } | 112 } |
111 | 113 |
112 // static | 114 // static |
113 bool ServiceWorkerUtils::CanRegisterServiceWorker(const GURL& context_url, | 115 bool ServiceWorkerUtils::CanRegisterServiceWorker(const GURL& context_url, |
114 const GURL& pattern, | 116 const GURL& pattern, |
115 const GURL& script_url) { | 117 const GURL& script_url) { |
116 DCHECK(context_url.is_valid()); | 118 DCHECK(context_url.is_valid()); |
117 DCHECK(pattern.is_valid()); | 119 DCHECK(pattern.is_valid()); |
118 DCHECK(script_url.is_valid()); | 120 DCHECK(script_url.is_valid()); |
119 return AllOriginsMatch(context_url, pattern, script_url) && | 121 return (AllOriginsMatch(context_url, pattern, script_url) || |
| 122 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 123 switches::kDisableWebSecurity)) && |
120 OriginCanAccessServiceWorkers(context_url) && | 124 OriginCanAccessServiceWorkers(context_url) && |
121 OriginCanAccessServiceWorkers(pattern) && | 125 OriginCanAccessServiceWorkers(pattern) && |
122 OriginCanAccessServiceWorkers(script_url); | 126 OriginCanAccessServiceWorkers(script_url); |
123 } | 127 } |
124 | 128 |
125 bool LongestScopeMatcher::MatchLongest(const GURL& scope) { | 129 bool LongestScopeMatcher::MatchLongest(const GURL& scope) { |
126 if (!ServiceWorkerUtils::ScopeMatches(scope, url_)) | 130 if (!ServiceWorkerUtils::ScopeMatches(scope, url_)) |
127 return false; | 131 return false; |
128 if (match_.is_empty() || match_.spec().size() < scope.spec().size()) { | 132 if (match_.is_empty() || match_.spec().size() < scope.spec().size()) { |
129 match_ = scope; | 133 match_ = scope; |
130 return true; | 134 return true; |
131 } | 135 } |
132 return false; | 136 return false; |
133 } | 137 } |
134 | 138 |
135 } // namespace content | 139 } // namespace content |
OLD | NEW |