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

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

Issue 2082493002: Remove WebFrame::canHaveSecureChild (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: patch for landing 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/dom/Document.cpp » ('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/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/platform/WebSecurityOrigin.h"
14 #include "third_party/WebKit/public/web/WebLocalFrame.h" 15 #include "third_party/WebKit/public/web/WebLocalFrame.h"
15 #include "third_party/WebKit/public/web/WebSandboxFlags.h" 16 #include "third_party/WebKit/public/web/WebSandboxFlags.h"
16 17
17 namespace content { 18 namespace content {
18 19
19 namespace { 20 namespace {
20 21
21 const char kUserDataKey[] = "SWProviderKey"; 22 const char kUserDataKey[] = "SWProviderKey";
22 23
23 // Must be unique in the child process. 24 // Must be unique in the child process.
24 int GetNextProviderId() { 25 int GetNextProviderId() {
25 static base::StaticAtomicSequenceNumber sequence; 26 static base::StaticAtomicSequenceNumber sequence;
26 return sequence.GetNext(); // We start at zero. 27 return sequence.GetNext(); // We start at zero.
27 } 28 }
28 29
30 // Returns whether it's possible for a document whose frame is a descendant of
31 // |frame| to be a secure context, not considering scheme exceptions (since any
32 // document can be a secure context if it has a scheme exception). See
33 // Document::isSecureContextImpl for more details.
34 bool IsFrameSecure(blink::WebFrame* frame) {
35 while (frame) {
36 if (!frame->getSecurityOrigin().isPotentiallyTrustworthy())
37 return false;
38 frame = frame->parent();
39 }
40 return true;
41 }
42
29 } // namespace 43 } // namespace
30 44
31 void ServiceWorkerNetworkProvider::AttachToDocumentState( 45 void ServiceWorkerNetworkProvider::AttachToDocumentState(
32 base::SupportsUserData* datasource_userdata, 46 base::SupportsUserData* datasource_userdata,
33 std::unique_ptr<ServiceWorkerNetworkProvider> network_provider) { 47 std::unique_ptr<ServiceWorkerNetworkProvider> network_provider) {
34 datasource_userdata->SetUserData(&kUserDataKey, network_provider.release()); 48 datasource_userdata->SetUserData(&kUserDataKey, network_provider.release());
35 } 49 }
36 50
37 ServiceWorkerNetworkProvider* ServiceWorkerNetworkProvider::FromDocumentState( 51 ServiceWorkerNetworkProvider* ServiceWorkerNetworkProvider::FromDocumentState(
38 base::SupportsUserData* datasource_userdata) { 52 base::SupportsUserData* datasource_userdata) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 blink::WebSandboxFlags::Origin); 85 blink::WebSandboxFlags::Origin);
72 } 86 }
73 87
74 // Now create the ServiceWorkerNetworkProvider (with invalid id if needed). 88 // Now create the ServiceWorkerNetworkProvider (with invalid id if needed).
75 if (should_create_provider_for_window) { 89 if (should_create_provider_for_window) {
76 // Ideally Document::isSecureContext would be called here, but the document 90 // 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 91 // 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 92 // 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 93 // context security when deciding whether to allow a service worker to
80 // control the document. 94 // control the document.
81 bool is_parent_frame_secure = 95 const bool is_parent_frame_secure = IsFrameSecure(frame->parent());
82 !frame->parent() || frame->parent()->canHaveSecureChild();
83 96
84 if (service_worker_provider_id == kInvalidServiceWorkerProviderId) { 97 if (service_worker_provider_id == kInvalidServiceWorkerProviderId) {
85 network_provider = std::unique_ptr<ServiceWorkerNetworkProvider>( 98 network_provider = std::unique_ptr<ServiceWorkerNetworkProvider>(
86 new ServiceWorkerNetworkProvider(route_id, 99 new ServiceWorkerNetworkProvider(route_id,
87 SERVICE_WORKER_PROVIDER_FOR_WINDOW, 100 SERVICE_WORKER_PROVIDER_FOR_WINDOW,
88 is_parent_frame_secure)); 101 is_parent_frame_secure));
89 } else { 102 } else {
90 CHECK(browser_side_navigation); 103 CHECK(browser_side_navigation);
91 DCHECK(ServiceWorkerUtils::IsBrowserAssignedProviderId( 104 DCHECK(ServiceWorkerUtils::IsBrowserAssignedProviderId(
92 service_worker_provider_id)); 105 service_worker_provider_id));
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 return; // May be null in some tests. 160 return; // May be null in some tests.
148 ChildThreadImpl::current()->Send( 161 ChildThreadImpl::current()->Send(
149 new ServiceWorkerHostMsg_SetVersionId(provider_id_, version_id)); 162 new ServiceWorkerHostMsg_SetVersionId(provider_id_, version_id));
150 } 163 }
151 164
152 bool ServiceWorkerNetworkProvider::IsControlledByServiceWorker() const { 165 bool ServiceWorkerNetworkProvider::IsControlledByServiceWorker() const {
153 return context() && context()->controller(); 166 return context() && context()->controller();
154 } 167 }
155 168
156 } // namespace content 169 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/dom/Document.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698