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

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

Issue 2481923002: [WIP] make GURL::path() return a StringPiece (Closed)
Patch Set: thanks asan Created 4 years, 1 month 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
« no previous file with comments | « content/common/plugin_list.cc ('k') | content/renderer/render_frame_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "content/public/common/origin_util.h" 12 #include "content/public/common/origin_util.h"
13 13
14 namespace content { 14 namespace content {
15 15
16 namespace { 16 namespace {
17 17
18 bool PathContainsDisallowedCharacter(const GURL& url) { 18 bool PathContainsDisallowedCharacter(const GURL& url) {
19 std::string path = url.path(); 19 base::StringPiece path = url.path();
20 DCHECK(base::IsStringUTF8(path)); 20 DCHECK(base::IsStringUTF8(path));
21 21
22 // We should avoid these escaped characters in the path component because 22 // We should avoid these escaped characters in the path component because
23 // these can be handled differently depending on server implementation. 23 // these can be handled differently depending on server implementation.
24 if (path.find("%2f") != std::string::npos || 24 if (path.find("%2f") != std::string::npos ||
25 path.find("%2F") != std::string::npos) { 25 path.find("%2F") != std::string::npos) {
26 return true; 26 return true;
27 } 27 }
28 if (path.find("%5c") != std::string::npos || 28 if (path.find("%5c") != std::string::npos ||
29 path.find("%5C") != std::string::npos) { 29 path.find("%5C") != std::string::npos) {
(...skipping 28 matching lines...) Expand all
58 58
59 std::string max_scope_string; 59 std::string max_scope_string;
60 if (service_worker_allowed_header_value) { 60 if (service_worker_allowed_header_value) {
61 GURL max_scope = script_url.Resolve(*service_worker_allowed_header_value); 61 GURL max_scope = script_url.Resolve(*service_worker_allowed_header_value);
62 if (!max_scope.is_valid()) { 62 if (!max_scope.is_valid()) {
63 *error_message = "An invalid Service-Worker-Allowed header value ('"; 63 *error_message = "An invalid Service-Worker-Allowed header value ('";
64 error_message->append(*service_worker_allowed_header_value); 64 error_message->append(*service_worker_allowed_header_value);
65 error_message->append("') was received when fetching the script."); 65 error_message->append("') was received when fetching the script.");
66 return false; 66 return false;
67 } 67 }
68 max_scope_string = max_scope.path(); 68 max_scope_string = max_scope.path().as_string();
69 } else { 69 } else {
70 max_scope_string = script_url.Resolve(".").path(); 70 max_scope_string = script_url.Resolve(".").path().as_string();
71 } 71 }
72 72
73 std::string scope_string = scope.path(); 73 base::StringPiece scope_string = scope.path();
74 if (!base::StartsWith(scope_string, max_scope_string, 74 if (!base::StartsWith(scope_string, max_scope_string,
75 base::CompareCase::SENSITIVE)) { 75 base::CompareCase::SENSITIVE)) {
76 *error_message = "The path of the provided scope ('"; 76 *error_message = "The path of the provided scope ('";
77 error_message->append(scope_string); 77 error_message->append(scope_string.as_string());
78 error_message->append("') is not under the max scope allowed ("); 78 error_message->append("') is not under the max scope allowed (");
79 if (service_worker_allowed_header_value) 79 if (service_worker_allowed_header_value)
80 error_message->append("set by Service-Worker-Allowed: "); 80 error_message->append("set by Service-Worker-Allowed: ");
81 error_message->append("'"); 81 error_message->append("'");
82 error_message->append(max_scope_string); 82 error_message->append(max_scope_string);
83 error_message->append( 83 error_message->append(
84 "'). Adjust the scope, move the Service Worker script, or use the " 84 "'). Adjust the scope, move the Service Worker script, or use the "
85 "Service-Worker-Allowed HTTP header to allow the scope."); 85 "Service-Worker-Allowed HTTP header to allow the scope.");
86 return false; 86 return false;
87 } 87 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 if (!ServiceWorkerUtils::ScopeMatches(scope, url_)) 142 if (!ServiceWorkerUtils::ScopeMatches(scope, url_))
143 return false; 143 return false;
144 if (match_.is_empty() || match_.spec().size() < scope.spec().size()) { 144 if (match_.is_empty() || match_.spec().size() < scope.spec().size()) {
145 match_ = scope; 145 match_ = scope;
146 return true; 146 return true;
147 } 147 }
148 return false; 148 return false;
149 } 149 }
150 150
151 } // namespace content 151 } // namespace content
OLDNEW
« no previous file with comments | « content/common/plugin_list.cc ('k') | content/renderer/render_frame_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698