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

Side by Side Diff: third_party/WebKit/Source/core/loader/WorkerFetchContext.cpp

Issue 2880733002: Partially implement WorkerFetchContext and WorkerThreadableLoadingContext and add virtual tests (Closed)
Patch Set: incorporated kinuko's comment Created 3 years, 7 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "core/loader/WorkerFetchContext.h" 5 #include "core/loader/WorkerFetchContext.h"
6 6
7 #include "core/frame/Deprecation.h"
8 #include "core/frame/UseCounter.h"
7 #include "core/workers/WorkerClients.h" 9 #include "core/workers/WorkerClients.h"
8 #include "core/workers/WorkerGlobalScope.h" 10 #include "core/workers/WorkerGlobalScope.h"
9 #include "platform/Supplementable.h" 11 #include "platform/Supplementable.h"
10 #include "platform/WebTaskRunner.h" 12 #include "platform/WebTaskRunner.h"
11 #include "platform/exported/WrappedResourceRequest.h" 13 #include "platform/exported/WrappedResourceRequest.h"
14 #include "platform/loader/fetch/ResourceFetcher.h"
12 #include "platform/scheduler/child/web_scheduler.h" 15 #include "platform/scheduler/child/web_scheduler.h"
13 #include "public/platform/Platform.h" 16 #include "public/platform/Platform.h"
14 #include "public/platform/WebThread.h" 17 #include "public/platform/WebThread.h"
18 #include "public/platform/WebURLRequest.h"
15 #include "public/platform/WebWorkerFetchContext.h" 19 #include "public/platform/WebWorkerFetchContext.h"
16 20
17 namespace blink { 21 namespace blink {
18 22
19 namespace { 23 namespace {
20 24
21 // WorkerFetchContextHolder is used to pass the WebWorkerFetchContext from the 25 // WorkerFetchContextHolder is used to pass the WebWorkerFetchContext from the
22 // main thread to the worker thread by attaching to the WorkerClients as a 26 // main thread to the worker thread by attaching to the WorkerClients as a
23 // Supplement. 27 // Supplement.
24 class WorkerFetchContextHolder final 28 class WorkerFetchContextHolder final
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 DCHECK(worker_global_scope.IsContextThread()); 61 DCHECK(worker_global_scope.IsContextThread());
58 WorkerClients* worker_clients = worker_global_scope.Clients(); 62 WorkerClients* worker_clients = worker_global_scope.Clients();
59 DCHECK(worker_clients); 63 DCHECK(worker_clients);
60 WorkerFetchContextHolder* holder = 64 WorkerFetchContextHolder* holder =
61 static_cast<WorkerFetchContextHolder*>(Supplement<WorkerClients>::From( 65 static_cast<WorkerFetchContextHolder*>(Supplement<WorkerClients>::From(
62 *worker_clients, WorkerFetchContextHolder::SupplementName())); 66 *worker_clients, WorkerFetchContextHolder::SupplementName()));
63 if (!holder) 67 if (!holder)
64 return nullptr; 68 return nullptr;
65 std::unique_ptr<WebWorkerFetchContext> web_context = holder->TakeContext(); 69 std::unique_ptr<WebWorkerFetchContext> web_context = holder->TakeContext();
66 DCHECK(web_context); 70 DCHECK(web_context);
67 return new WorkerFetchContext(std::move(web_context)); 71 return new WorkerFetchContext(worker_global_scope, std::move(web_context));
68 } 72 }
69 73
70 WorkerFetchContext::WorkerFetchContext( 74 WorkerFetchContext::WorkerFetchContext(
75 WorkerGlobalScope& worker_global_scope,
71 std::unique_ptr<WebWorkerFetchContext> web_context) 76 std::unique_ptr<WebWorkerFetchContext> web_context)
72 : web_context_(std::move(web_context)) { 77 : BaseFetchContext(&worker_global_scope),
73 web_context_->InitializeOnWorkerThread(Platform::Current() 78 worker_global_scope_(worker_global_scope),
74 ->CurrentThread() 79 web_context_(std::move(web_context)),
75 ->Scheduler() 80 loading_task_runner_(Platform::Current()
76 ->LoadingTaskRunner() 81 ->CurrentThread()
77 ->ToSingleThreadTaskRunner()); 82 ->Scheduler()
83 ->LoadingTaskRunner()) {
84 web_context_->InitializeOnWorkerThread(
85 loading_task_runner_->ToSingleThreadTaskRunner());
86 }
87
88 ResourceFetcher* WorkerFetchContext::GetResourceFetcher() {
89 if (resource_fetcher_)
90 return resource_fetcher_;
91 resource_fetcher_ = ResourceFetcher::Create(this);
92 return resource_fetcher_;
93 }
94
95 ContentSettingsClient* WorkerFetchContext::GetContentSettingsClient() const {
96 // TODO(horo): Implement this.
97 return nullptr;
98 }
99
100 Settings* WorkerFetchContext::GetSettings() const {
101 // TODO(horo): Implement this.
102 return nullptr;
103 }
104
105 SubresourceFilter* WorkerFetchContext::GetSubresourceFilter() const {
106 // TODO(horo): Implement this.
107 return nullptr;
108 }
109
110 SecurityContext* WorkerFetchContext::GetParentSecurityContext() const {
111 // TODO(horo): Implement this.
112 return nullptr;
113 }
114
115 bool WorkerFetchContext::ShouldBlockRequestByInspector(
116 const ResourceRequest& resource_request) const {
117 // TODO(horo): Implement this.
118 return false;
119 }
120
121 void WorkerFetchContext::DispatchDidBlockRequest(
122 const ResourceRequest& resource_request,
123 const FetchInitiatorInfo& fetch_initiator_info,
124 ResourceRequestBlockedReason blocked_reason) const {
125 // TODO(horo): Implement this.
126 }
127
128 void WorkerFetchContext::ReportLocalLoadFailed(const KURL&) const {
129 // TODO(horo): Implement this.
130 }
131
132 bool WorkerFetchContext::ShouldBypassMainWorldCSP() const {
133 // TODO(horo): Implement this.
134 return false;
135 }
136
137 bool WorkerFetchContext::IsSVGImageChromeClient() const {
138 return false;
139 }
140
141 void WorkerFetchContext::CountUsage(UseCounter::Feature feature) const {
142 UseCounter::Count(worker_global_scope_, feature);
143 }
144
145 void WorkerFetchContext::CountDeprecation(UseCounter::Feature feature) const {
146 Deprecation::CountDeprecation(worker_global_scope_, feature);
147 }
148
149 bool WorkerFetchContext::ShouldBlockFetchByMixedContentCheck(
150 const ResourceRequest& resource_request,
151 const KURL& url,
152 SecurityViolationReportingPolicy reporting_policy) const {
153 // TODO(horo): Implement this.
154 return false;
78 } 155 }
79 156
80 std::unique_ptr<WebURLLoader> WorkerFetchContext::CreateURLLoader() { 157 std::unique_ptr<WebURLLoader> WorkerFetchContext::CreateURLLoader() {
81 return web_context_->CreateURLLoader(); 158 return web_context_->CreateURLLoader();
82 } 159 }
83 160
84 bool WorkerFetchContext::IsControlledByServiceWorker() const { 161 bool WorkerFetchContext::IsControlledByServiceWorker() const {
85 return web_context_->IsControlledByServiceWorker(); 162 return web_context_->IsControlledByServiceWorker();
86 } 163 }
87 164
88 void WorkerFetchContext::PrepareRequest(ResourceRequest& request, 165 void WorkerFetchContext::PrepareRequest(ResourceRequest& request,
89 RedirectType) { 166 RedirectType) {
167 request.OverrideLoadingIPCType(WebURLRequest::LoadingIPCType::kMojo);
90 WrappedResourceRequest webreq(request); 168 WrappedResourceRequest webreq(request);
91 web_context_->WillSendRequest(webreq); 169 web_context_->WillSendRequest(webreq);
92 } 170 }
93 171
172 RefPtr<WebTaskRunner> WorkerFetchContext::LoadingTaskRunner() const {
173 return loading_task_runner_;
174 }
175
176 DEFINE_TRACE(WorkerFetchContext) {
177 visitor->Trace(worker_global_scope_);
178 visitor->Trace(resource_fetcher_);
179 BaseFetchContext::Trace(visitor);
180 }
181
94 void ProvideWorkerFetchContextToWorker( 182 void ProvideWorkerFetchContextToWorker(
95 WorkerClients* clients, 183 WorkerClients* clients,
96 std::unique_ptr<WebWorkerFetchContext> web_context) { 184 std::unique_ptr<WebWorkerFetchContext> web_context) {
97 DCHECK(clients); 185 DCHECK(clients);
98 WorkerFetchContextHolder::ProvideTo( 186 WorkerFetchContextHolder::ProvideTo(
99 *clients, WorkerFetchContextHolder::SupplementName(), 187 *clients, WorkerFetchContextHolder::SupplementName(),
100 new WorkerFetchContextHolder(std::move(web_context))); 188 new WorkerFetchContextHolder(std::move(web_context)));
101 } 189 }
102 190
103 } // namespace blink 191 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698