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

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

Issue 1101033003: Move IsOriginSecure() into //content and use it in ServiceWorker (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_dispatcher_host.h" 5 #include "content/browser/service_worker/service_worker_dispatcher_host.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/profiler/scoped_tracker.h" 8 #include "base/profiler/scoped_tracker.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
11 #include "content/browser/message_port_message_filter.h" 11 #include "content/browser/message_port_message_filter.h"
12 #include "content/browser/message_port_service.h" 12 #include "content/browser/message_port_service.h"
13 #include "content/browser/service_worker/embedded_worker_registry.h" 13 #include "content/browser/service_worker/embedded_worker_registry.h"
14 #include "content/browser/service_worker/service_worker_context_core.h" 14 #include "content/browser/service_worker/service_worker_context_core.h"
15 #include "content/browser/service_worker/service_worker_context_wrapper.h" 15 #include "content/browser/service_worker/service_worker_context_wrapper.h"
16 #include "content/browser/service_worker/service_worker_handle.h" 16 #include "content/browser/service_worker/service_worker_handle.h"
17 #include "content/browser/service_worker/service_worker_registration.h" 17 #include "content/browser/service_worker/service_worker_registration.h"
18 #include "content/browser/service_worker/service_worker_registration_handle.h" 18 #include "content/browser/service_worker/service_worker_registration_handle.h"
19 #include "content/browser/service_worker/service_worker_utils.h" 19 #include "content/browser/service_worker/service_worker_utils.h"
20 #include "content/common/service_worker/embedded_worker_messages.h" 20 #include "content/common/service_worker/embedded_worker_messages.h"
21 #include "content/common/service_worker/service_worker_messages.h" 21 #include "content/common/service_worker/service_worker_messages.h"
22 #include "content/common/service_worker/service_worker_types.h" 22 #include "content/common/service_worker/service_worker_types.h"
23 #include "content/public/browser/content_browser_client.h" 23 #include "content/public/browser/content_browser_client.h"
24 #include "content/public/common/content_client.h" 24 #include "content/public/common/content_client.h"
25 #include "content/public/common/origin_util.h"
25 #include "ipc/ipc_message_macros.h" 26 #include "ipc/ipc_message_macros.h"
26 #include "net/base/net_util.h" 27 #include "net/base/net_util.h"
27 #include "third_party/WebKit/public/platform/WebServiceWorkerError.h" 28 #include "third_party/WebKit/public/platform/WebServiceWorkerError.h"
28 #include "url/gurl.h" 29 #include "url/gurl.h"
29 30
30 using blink::WebServiceWorkerError; 31 using blink::WebServiceWorkerError;
31 32
32 namespace content { 33 namespace content {
33 34
34 namespace { 35 namespace {
35 36
36 const char kNoDocumentURLErrorMessage[] = 37 const char kNoDocumentURLErrorMessage[] =
37 "No URL is associated with the caller's document."; 38 "No URL is associated with the caller's document.";
38 const char kShutdownErrorMessage[] = 39 const char kShutdownErrorMessage[] =
39 "The Service Worker system has shutdown."; 40 "The Service Worker system has shutdown.";
40 const char kUserDeniedPermissionMessage[] = 41 const char kUserDeniedPermissionMessage[] =
41 "The user denied permission to use Service Worker."; 42 "The user denied permission to use Service Worker.";
42 43
43 const uint32 kFilteredMessageClasses[] = { 44 const uint32 kFilteredMessageClasses[] = {
44 ServiceWorkerMsgStart, 45 ServiceWorkerMsgStart,
45 EmbeddedWorkerMsgStart, 46 EmbeddedWorkerMsgStart,
46 }; 47 };
47 48
48 bool AllOriginsMatch(const GURL& url_a, const GURL& url_b, const GURL& url_c) { 49 bool AllOriginsMatch(const GURL& url_a, const GURL& url_b, const GURL& url_c) {
49 return url_a.GetOrigin() == url_b.GetOrigin() && 50 return url_a.GetOrigin() == url_b.GetOrigin() &&
50 url_a.GetOrigin() == url_c.GetOrigin(); 51 url_a.GetOrigin() == url_c.GetOrigin();
51 } 52 }
52 53
53 // TODO(dominicc): When crbug.com/362214 is fixed use that to be
54 // consistent with Blink's
55 // SecurityOrigin::canAccessFeatureRequiringSecureOrigin.
56 bool OriginCanAccessServiceWorkers(const GURL& url) { 54 bool OriginCanAccessServiceWorkers(const GURL& url) {
57 return url.SchemeIsHTTPOrHTTPS() && 55 return url.SchemeIsHTTPOrHTTPS() && IsOriginSecure(url);
58 (url.SchemeIsSecure() || net::IsLocalhost(url.host()));
59 } 56 }
60 57
61 bool CanRegisterServiceWorker(const GURL& document_url, 58 bool CanRegisterServiceWorker(const GURL& document_url,
62 const GURL& pattern, 59 const GURL& pattern,
63 const GURL& script_url) { 60 const GURL& script_url) {
64 DCHECK(document_url.is_valid()); 61 DCHECK(document_url.is_valid());
65 DCHECK(pattern.is_valid()); 62 DCHECK(pattern.is_valid());
66 DCHECK(script_url.is_valid()); 63 DCHECK(script_url.is_valid());
67 return AllOriginsMatch(document_url, pattern, script_url) && 64 return AllOriginsMatch(document_url, pattern, script_url) &&
68 OriginCanAccessServiceWorkers(document_url) && 65 OriginCanAccessServiceWorkers(document_url) &&
(...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after
1035 ServiceWorkerHandle* handle = handles_.Lookup(handle_id); 1032 ServiceWorkerHandle* handle = handles_.Lookup(handle_id);
1036 if (!handle) { 1033 if (!handle) {
1037 BadMessageReceived(); 1034 BadMessageReceived();
1038 return; 1035 return;
1039 } 1036 }
1040 handle->version()->StopWorker( 1037 handle->version()->StopWorker(
1041 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); 1038 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
1042 } 1039 }
1043 1040
1044 } // namespace content 1041 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698