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

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

Issue 2196633002: [ServiceWorker] Don't check the origin equality when disable-web-security flag is set. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: incorporated nhiroki's comment Created 4 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
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 #ifndef CONTENT_COMMON_SERVICE_WORKER_SERVICE_WORKER_UTILS_H_ 5 #ifndef CONTENT_COMMON_SERVICE_WORKER_SERVICE_WORKER_UTILS_H_
6 #define CONTENT_COMMON_SERVICE_WORKER_SERVICE_WORKER_UTILS_H_ 6 #define CONTENT_COMMON_SERVICE_WORKER_SERVICE_WORKER_UTILS_H_
7 7
8 #include "base/command_line.h"
8 #include "base/macros.h" 9 #include "base/macros.h"
9 #include "content/common/content_export.h" 10 #include "content/common/content_export.h"
10 #include "content/common/service_worker/service_worker_status_code.h" 11 #include "content/common/service_worker/service_worker_status_code.h"
11 #include "content/common/service_worker/service_worker_types.h" 12 #include "content/common/service_worker/service_worker_types.h"
13 #include "content/public/common/content_switches.h"
12 #include "content/public/common/resource_type.h" 14 #include "content/public/common/resource_type.h"
13 #include "url/gurl.h" 15 #include "url/gurl.h"
14 16
15 namespace content { 17 namespace content {
16 18
17 class ServiceWorkerUtils { 19 class ServiceWorkerUtils {
18 public: 20 public:
19 static bool IsMainResourceType(ResourceType type) { 21 static bool IsMainResourceType(ResourceType type) {
20 return IsResourceTypeFrame(type) || type == RESOURCE_TYPE_SHARED_WORKER; 22 return IsResourceTypeFrame(type) || type == RESOURCE_TYPE_SHARED_WORKER;
21 } 23 }
(...skipping 15 matching lines...) Expand all
37 std::string* error_message); 39 std::string* error_message);
38 40
39 static bool ContainsDisallowedCharacter(const GURL& scope, 41 static bool ContainsDisallowedCharacter(const GURL& scope,
40 const GURL& script_url, 42 const GURL& script_url,
41 std::string* error_message); 43 std::string* error_message);
42 44
43 static bool CanRegisterServiceWorker(const GURL& context_url, 45 static bool CanRegisterServiceWorker(const GURL& context_url,
44 const GURL& pattern, 46 const GURL& pattern,
45 const GURL& script_url); 47 const GURL& script_url);
46 48
49 // Returns true when '--disable-web-security' flag is set. Otherwise returns
50 // whether the all origins of |urls| are same as the origin of |url|.
51 template <typename... Args>
52 static bool PassOriginEqualitySecurityCheck(const GURL& url,
53 const Args&... urls) {
54 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
55 switches::kDisableWebSecurity))
56 return true;
57 for (const GURL& u : {urls...}) {
58 if (url.GetOrigin() != u.GetOrigin())
59 return false;
60 }
61 return true;
62 }
63
47 // PlzNavigate 64 // PlzNavigate
48 // Returns true if the |provider_id| was assigned by the browser process. 65 // Returns true if the |provider_id| was assigned by the browser process.
49 static bool IsBrowserAssignedProviderId(int provider_id) { 66 static bool IsBrowserAssignedProviderId(int provider_id) {
50 return provider_id < kInvalidServiceWorkerProviderId; 67 return provider_id < kInvalidServiceWorkerProviderId;
51 } 68 }
52 }; 69 };
53 70
54 class CONTENT_EXPORT LongestScopeMatcher { 71 class CONTENT_EXPORT LongestScopeMatcher {
55 public: 72 public:
56 explicit LongestScopeMatcher(const GURL& url) : url_(url) {} 73 explicit LongestScopeMatcher(const GURL& url) : url_(url) {}
57 virtual ~LongestScopeMatcher() {} 74 virtual ~LongestScopeMatcher() {}
58 75
59 // Returns true if |scope| matches |url_| longer than |match_|. 76 // Returns true if |scope| matches |url_| longer than |match_|.
60 bool MatchLongest(const GURL& scope); 77 bool MatchLongest(const GURL& scope);
61 78
62 private: 79 private:
63 const GURL url_; 80 const GURL url_;
64 GURL match_; 81 GURL match_;
65 82
66 DISALLOW_COPY_AND_ASSIGN(LongestScopeMatcher); 83 DISALLOW_COPY_AND_ASSIGN(LongestScopeMatcher);
67 }; 84 };
68 85
69 } // namespace content 86 } // namespace content
70 87
71 #endif // CONTENT_COMMON_SERVICE_WORKER_SERVICE_WORKER_UTILS_H_ 88 #endif // CONTENT_COMMON_SERVICE_WORKER_SERVICE_WORKER_UTILS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698