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

Side by Side Diff: content/child/service_worker/service_worker_network_provider.cc

Issue 2009453002: service worker: Don't control a subframe of an insecure context (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: refactor errorMessage Created 4 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
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/child/service_worker/service_worker_network_provider.h" 5 #include "content/child/service_worker/service_worker_network_provider.h"
6 6
7 #include "base/atomic_sequence_num.h" 7 #include "base/atomic_sequence_num.h"
8 #include "content/child/child_thread_impl.h" 8 #include "content/child/child_thread_impl.h"
9 #include "content/child/service_worker/service_worker_provider_context.h" 9 #include "content/child/service_worker/service_worker_provider_context.h"
10 #include "content/common/navigation_params.h" 10 #include "content/common/navigation_params.h"
11 #include "content/common/service_worker/service_worker_messages.h" 11 #include "content/common/service_worker/service_worker_messages.h"
12 #include "content/common/service_worker/service_worker_utils.h" 12 #include "content/common/service_worker/service_worker_utils.h"
13 #include "content/public/common/browser_side_navigation_policy.h" 13 #include "content/public/common/browser_side_navigation_policy.h"
14 #include "third_party/WebKit/public/web/WebLocalFrame.h"
15 #include "third_party/WebKit/public/web/WebSandboxFlags.h"
14 16
15 namespace content { 17 namespace content {
16 18
17 namespace { 19 namespace {
18 20
19 const char kUserDataKey[] = "SWProviderKey"; 21 const char kUserDataKey[] = "SWProviderKey";
20 22
21 // Must be unique in the child process. 23 // Must be unique in the child process.
22 int GetNextProviderId() { 24 int GetNextProviderId() {
23 static base::StaticAtomicSequenceNumber sequence; 25 static base::StaticAtomicSequenceNumber sequence;
(...skipping 12 matching lines...) Expand all
36 base::SupportsUserData* datasource_userdata) { 38 base::SupportsUserData* datasource_userdata) {
37 return static_cast<ServiceWorkerNetworkProvider*>( 39 return static_cast<ServiceWorkerNetworkProvider*>(
38 datasource_userdata->GetUserData(&kUserDataKey)); 40 datasource_userdata->GetUserData(&kUserDataKey));
39 } 41 }
40 42
41 // static 43 // static
42 std::unique_ptr<ServiceWorkerNetworkProvider> 44 std::unique_ptr<ServiceWorkerNetworkProvider>
43 ServiceWorkerNetworkProvider::CreateForNavigation( 45 ServiceWorkerNetworkProvider::CreateForNavigation(
44 int route_id, 46 int route_id,
45 const RequestNavigationParams& request_params, 47 const RequestNavigationParams& request_params,
46 blink::WebSandboxFlags sandbox_flags, 48 blink::WebLocalFrame* frame,
47 bool content_initiated) { 49 bool content_initiated) {
48 bool browser_side_navigation = IsBrowserSideNavigationEnabled(); 50 bool browser_side_navigation = IsBrowserSideNavigationEnabled();
49 bool should_create_provider_for_window = false; 51 bool should_create_provider_for_window = false;
50 int service_worker_provider_id = kInvalidServiceWorkerProviderId; 52 int service_worker_provider_id = kInvalidServiceWorkerProviderId;
51 std::unique_ptr<ServiceWorkerNetworkProvider> network_provider; 53 std::unique_ptr<ServiceWorkerNetworkProvider> network_provider;
52 54
53 // Determine if a ServiceWorkerNetworkProvider should be created and properly 55 // Determine if a ServiceWorkerNetworkProvider should be created and properly
54 // initialized for the navigation. A default ServiceWorkerNetworkProvider 56 // initialized for the navigation. A default ServiceWorkerNetworkProvider
55 // will always be created since it is expected in a certain number of places, 57 // will always be created since it is expected in a certain number of places,
56 // however it will have an invalid id. 58 // however it will have an invalid id.
57 // PlzNavigate: |service_worker_provider_id| can be sent by the browser, if 59 // PlzNavigate: |service_worker_provider_id| can be sent by the browser, if
58 // it already created the SeviceWorkerProviderHost. 60 // it already created the SeviceWorkerProviderHost.
59 if (browser_side_navigation && !content_initiated) { 61 if (browser_side_navigation && !content_initiated) {
60 should_create_provider_for_window = 62 should_create_provider_for_window =
61 request_params.should_create_service_worker; 63 request_params.should_create_service_worker;
62 service_worker_provider_id = request_params.service_worker_provider_id; 64 service_worker_provider_id = request_params.service_worker_provider_id;
63 DCHECK(ServiceWorkerUtils::IsBrowserAssignedProviderId( 65 DCHECK(ServiceWorkerUtils::IsBrowserAssignedProviderId(
64 service_worker_provider_id) || 66 service_worker_provider_id) ||
65 service_worker_provider_id == kInvalidServiceWorkerProviderId); 67 service_worker_provider_id == kInvalidServiceWorkerProviderId);
66 } else { 68 } else {
67 should_create_provider_for_window = 69 should_create_provider_for_window =
68 (sandbox_flags & blink::WebSandboxFlags::Origin) != 70 ((frame->effectiveSandboxFlags() & blink::WebSandboxFlags::Origin) !=
69 blink::WebSandboxFlags::Origin; 71 blink::WebSandboxFlags::Origin);
70 } 72 }
71 73
72 // Now create the ServiceWorkerNetworkProvider (with invalid id if needed). 74 // Now create the ServiceWorkerNetworkProvider (with invalid id if needed).
73 if (should_create_provider_for_window) { 75 if (should_create_provider_for_window) {
76 // Ideally Document::isSecureContext would be called here, but the document
77 // is not created yet, and due to redirects the URL may change. So pass
78 // is_parent_frame_secure to the browser process, so it can determine the
79 // context security when deciding whether to allow a service worker to
80 // control the document.
81 bool is_parent_frame_secure =
82 !frame->parent() || frame->parent()->canHaveSecureChild();
83
74 if (service_worker_provider_id == kInvalidServiceWorkerProviderId) { 84 if (service_worker_provider_id == kInvalidServiceWorkerProviderId) {
75 network_provider = std::unique_ptr<ServiceWorkerNetworkProvider>( 85 network_provider = std::unique_ptr<ServiceWorkerNetworkProvider>(
76 new ServiceWorkerNetworkProvider(route_id, 86 new ServiceWorkerNetworkProvider(route_id,
77 SERVICE_WORKER_PROVIDER_FOR_WINDOW)); 87 SERVICE_WORKER_PROVIDER_FOR_WINDOW,
88 is_parent_frame_secure));
78 } else { 89 } else {
79 CHECK(browser_side_navigation); 90 CHECK(browser_side_navigation);
80 DCHECK(ServiceWorkerUtils::IsBrowserAssignedProviderId( 91 DCHECK(ServiceWorkerUtils::IsBrowserAssignedProviderId(
81 service_worker_provider_id)); 92 service_worker_provider_id));
82 network_provider = std::unique_ptr<ServiceWorkerNetworkProvider>( 93 network_provider = std::unique_ptr<ServiceWorkerNetworkProvider>(
83 new ServiceWorkerNetworkProvider(route_id, 94 new ServiceWorkerNetworkProvider(
84 SERVICE_WORKER_PROVIDER_FOR_WINDOW, 95 route_id, SERVICE_WORKER_PROVIDER_FOR_WINDOW,
85 service_worker_provider_id)); 96 service_worker_provider_id, is_parent_frame_secure));
86 } 97 }
87 } else { 98 } else {
88 network_provider = std::unique_ptr<ServiceWorkerNetworkProvider>( 99 network_provider = std::unique_ptr<ServiceWorkerNetworkProvider>(
89 new ServiceWorkerNetworkProvider()); 100 new ServiceWorkerNetworkProvider());
90 } 101 }
91 return network_provider; 102 return network_provider;
92 } 103 }
93 104
94 ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider( 105 ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider(
95 int route_id, 106 int route_id,
96 ServiceWorkerProviderType provider_type, 107 ServiceWorkerProviderType provider_type,
97 int browser_provider_id) 108 int browser_provider_id,
109 bool is_parent_frame_secure)
98 : provider_id_(browser_provider_id) { 110 : provider_id_(browser_provider_id) {
99 if (provider_id_ == kInvalidServiceWorkerProviderId) 111 if (provider_id_ == kInvalidServiceWorkerProviderId)
100 return; 112 return;
101 if (!ChildThreadImpl::current()) 113 if (!ChildThreadImpl::current())
102 return; // May be null in some tests. 114 return; // May be null in some tests.
103 context_ = new ServiceWorkerProviderContext( 115 context_ = new ServiceWorkerProviderContext(
104 provider_id_, provider_type, 116 provider_id_, provider_type,
105 ChildThreadImpl::current()->thread_safe_sender()); 117 ChildThreadImpl::current()->thread_safe_sender());
106 ChildThreadImpl::current()->Send(new ServiceWorkerHostMsg_ProviderCreated( 118 ChildThreadImpl::current()->Send(new ServiceWorkerHostMsg_ProviderCreated(
107 provider_id_, route_id, provider_type)); 119 provider_id_, route_id, provider_type, is_parent_frame_secure));
108 } 120 }
109 121
110 ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider( 122 ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider(
111 int route_id, 123 int route_id,
112 ServiceWorkerProviderType provider_type) 124 ServiceWorkerProviderType provider_type,
125 bool is_parent_frame_secure)
113 : ServiceWorkerNetworkProvider(route_id, 126 : ServiceWorkerNetworkProvider(route_id,
114 provider_type, 127 provider_type,
115 GetNextProviderId()) {} 128 GetNextProviderId(),
129 is_parent_frame_secure) {}
116 130
117 ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider() 131 ServiceWorkerNetworkProvider::ServiceWorkerNetworkProvider()
118 : provider_id_(kInvalidServiceWorkerProviderId) {} 132 : provider_id_(kInvalidServiceWorkerProviderId) {}
119 133
120 ServiceWorkerNetworkProvider::~ServiceWorkerNetworkProvider() { 134 ServiceWorkerNetworkProvider::~ServiceWorkerNetworkProvider() {
121 if (provider_id_ == kInvalidServiceWorkerProviderId) 135 if (provider_id_ == kInvalidServiceWorkerProviderId)
122 return; 136 return;
123 if (!ChildThreadImpl::current()) 137 if (!ChildThreadImpl::current())
124 return; // May be null in some tests. 138 return; // May be null in some tests.
125 ChildThreadImpl::current()->Send( 139 ChildThreadImpl::current()->Send(
126 new ServiceWorkerHostMsg_ProviderDestroyed(provider_id_)); 140 new ServiceWorkerHostMsg_ProviderDestroyed(provider_id_));
127 } 141 }
128 142
129 void ServiceWorkerNetworkProvider::SetServiceWorkerVersionId( 143 void ServiceWorkerNetworkProvider::SetServiceWorkerVersionId(
130 int64_t version_id) { 144 int64_t version_id) {
131 DCHECK_NE(kInvalidServiceWorkerProviderId, provider_id_); 145 DCHECK_NE(kInvalidServiceWorkerProviderId, provider_id_);
132 if (!ChildThreadImpl::current()) 146 if (!ChildThreadImpl::current())
133 return; // May be null in some tests. 147 return; // May be null in some tests.
134 ChildThreadImpl::current()->Send( 148 ChildThreadImpl::current()->Send(
135 new ServiceWorkerHostMsg_SetVersionId(provider_id_, version_id)); 149 new ServiceWorkerHostMsg_SetVersionId(provider_id_, version_id));
136 } 150 }
137 151
138 bool ServiceWorkerNetworkProvider::IsControlledByServiceWorker() const { 152 bool ServiceWorkerNetworkProvider::IsControlledByServiceWorker() const {
139 return context() && context()->controller(); 153 return context() && context()->controller();
140 } 154 }
141 155
142 } // namespace content 156 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698