OLD | NEW |
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" |
15 #include "public/platform/WebWorkerFetchContext.h" | 18 #include "public/platform/WebWorkerFetchContext.h" |
16 | 19 |
17 namespace blink { | 20 namespace blink { |
18 | 21 |
19 namespace { | 22 namespace { |
20 | 23 |
21 // WorkerFetchContextHolder is used to pass the WebWorkerFetchContext from the | 24 // WorkerFetchContextHolder is used to pass the WebWorkerFetchContext from the |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 DCHECK(worker_global_scope.IsContextThread()); | 60 DCHECK(worker_global_scope.IsContextThread()); |
58 WorkerClients* worker_clients = worker_global_scope.Clients(); | 61 WorkerClients* worker_clients = worker_global_scope.Clients(); |
59 DCHECK(worker_clients); | 62 DCHECK(worker_clients); |
60 WorkerFetchContextHolder* holder = | 63 WorkerFetchContextHolder* holder = |
61 static_cast<WorkerFetchContextHolder*>(Supplement<WorkerClients>::From( | 64 static_cast<WorkerFetchContextHolder*>(Supplement<WorkerClients>::From( |
62 *worker_clients, WorkerFetchContextHolder::SupplementName())); | 65 *worker_clients, WorkerFetchContextHolder::SupplementName())); |
63 if (!holder) | 66 if (!holder) |
64 return nullptr; | 67 return nullptr; |
65 std::unique_ptr<WebWorkerFetchContext> web_context = holder->TakeContext(); | 68 std::unique_ptr<WebWorkerFetchContext> web_context = holder->TakeContext(); |
66 DCHECK(web_context); | 69 DCHECK(web_context); |
67 return new WorkerFetchContext(std::move(web_context)); | 70 return new WorkerFetchContext(worker_global_scope, std::move(web_context)); |
68 } | 71 } |
69 | 72 |
70 WorkerFetchContext::WorkerFetchContext( | 73 WorkerFetchContext::WorkerFetchContext( |
| 74 WorkerGlobalScope& worker_global_scope, |
71 std::unique_ptr<WebWorkerFetchContext> web_context) | 75 std::unique_ptr<WebWorkerFetchContext> web_context) |
72 : web_context_(std::move(web_context)) { | 76 : BaseFetchContext(&worker_global_scope), |
73 web_context_->InitializeOnWorkerThread(Platform::Current() | 77 worker_global_scope_(worker_global_scope), |
74 ->CurrentThread() | 78 web_context_(std::move(web_context)), |
75 ->Scheduler() | 79 loading_task_runner_(Platform::Current() |
76 ->LoadingTaskRunner() | 80 ->CurrentThread() |
77 ->ToSingleThreadTaskRunner()); | 81 ->Scheduler() |
| 82 ->LoadingTaskRunner()) { |
| 83 web_context_->InitializeOnWorkerThread( |
| 84 loading_task_runner_->ToSingleThreadTaskRunner()); |
| 85 } |
| 86 |
| 87 ResourceFetcher* WorkerFetchContext::GetResourceFetcher() { |
| 88 if (resource_fetcher_) |
| 89 return resource_fetcher_; |
| 90 resource_fetcher_ = ResourceFetcher::Create(this); |
| 91 return resource_fetcher_; |
| 92 } |
| 93 |
| 94 ContentSettingsClient* WorkerFetchContext::GetContentSettingsClient() const { |
| 95 // TODO(horo): Implement this. |
| 96 return nullptr; |
| 97 } |
| 98 |
| 99 Settings* WorkerFetchContext::GetSettings() const { |
| 100 // TODO(horo): Implement this. |
| 101 return nullptr; |
| 102 } |
| 103 |
| 104 SubresourceFilter* WorkerFetchContext::GetSubresourceFilter() const { |
| 105 // TODO(horo): Implement this. |
| 106 return nullptr; |
| 107 } |
| 108 |
| 109 SecurityContext* WorkerFetchContext::GetParentSecurityContext() const { |
| 110 // TODO(horo): Implement this. |
| 111 return nullptr; |
| 112 } |
| 113 |
| 114 bool WorkerFetchContext::ShouldBlockRequestByInspector( |
| 115 const ResourceRequest& resource_request) const { |
| 116 // TODO(horo): Implement this. |
| 117 return false; |
| 118 } |
| 119 |
| 120 void WorkerFetchContext::DispatchDidBlockRequest( |
| 121 const ResourceRequest& resource_request, |
| 122 const FetchInitiatorInfo& fetch_initiator_info, |
| 123 ResourceRequestBlockedReason blocked_reason) const { |
| 124 // TODO(horo): Implement this. |
| 125 } |
| 126 |
| 127 void WorkerFetchContext::ReportLocalLoadFailed(const KURL&) const { |
| 128 // TODO(horo): Implement this. |
| 129 } |
| 130 |
| 131 bool WorkerFetchContext::ShouldBypassMainWorldCSP() const { |
| 132 // TODO(horo): Implement this. |
| 133 return false; |
| 134 } |
| 135 |
| 136 bool WorkerFetchContext::IsSVGImageChromeClient() const { |
| 137 return false; |
| 138 } |
| 139 |
| 140 void WorkerFetchContext::CountUsage(UseCounter::Feature feature) const { |
| 141 UseCounter::Count(worker_global_scope_, feature); |
| 142 } |
| 143 |
| 144 void WorkerFetchContext::CountDeprecation(UseCounter::Feature feature) const { |
| 145 Deprecation::CountDeprecation(worker_global_scope_, feature); |
| 146 } |
| 147 |
| 148 bool WorkerFetchContext::ShouldBlockFetchByMixedContentCheck( |
| 149 const ResourceRequest& resource_request, |
| 150 const KURL& url, |
| 151 SecurityViolationReportingPolicy reporting_policy) const { |
| 152 // TODO(horo): Implement this. |
| 153 return false; |
78 } | 154 } |
79 | 155 |
80 std::unique_ptr<WebURLLoader> WorkerFetchContext::CreateURLLoader() { | 156 std::unique_ptr<WebURLLoader> WorkerFetchContext::CreateURLLoader() { |
81 return web_context_->CreateURLLoader(); | 157 return web_context_->CreateURLLoader(); |
82 } | 158 } |
83 | 159 |
84 bool WorkerFetchContext::IsControlledByServiceWorker() const { | 160 bool WorkerFetchContext::IsControlledByServiceWorker() const { |
85 return web_context_->IsControlledByServiceWorker(); | 161 return web_context_->IsControlledByServiceWorker(); |
86 } | 162 } |
87 | 163 |
88 void WorkerFetchContext::PrepareRequest(ResourceRequest& request, | 164 void WorkerFetchContext::PrepareRequest(ResourceRequest& request, |
89 RedirectType) { | 165 RedirectType) { |
| 166 request.SetIsMojoIPCForced(true); |
90 WrappedResourceRequest webreq(request); | 167 WrappedResourceRequest webreq(request); |
91 web_context_->WillSendRequest(webreq); | 168 web_context_->WillSendRequest(webreq); |
92 } | 169 } |
93 | 170 |
| 171 RefPtr<WebTaskRunner> WorkerFetchContext::LoadingTaskRunner() const { |
| 172 return loading_task_runner_; |
| 173 } |
| 174 |
| 175 DEFINE_TRACE(WorkerFetchContext) { |
| 176 visitor->Trace(worker_global_scope_); |
| 177 visitor->Trace(resource_fetcher_); |
| 178 BaseFetchContext::Trace(visitor); |
| 179 } |
| 180 |
94 void ProvideWorkerFetchContextToWorker( | 181 void ProvideWorkerFetchContextToWorker( |
95 WorkerClients* clients, | 182 WorkerClients* clients, |
96 std::unique_ptr<WebWorkerFetchContext> web_context) { | 183 std::unique_ptr<WebWorkerFetchContext> web_context) { |
97 DCHECK(clients); | 184 DCHECK(clients); |
98 WorkerFetchContextHolder::ProvideTo( | 185 WorkerFetchContextHolder::ProvideTo( |
99 *clients, WorkerFetchContextHolder::SupplementName(), | 186 *clients, WorkerFetchContextHolder::SupplementName(), |
100 new WorkerFetchContextHolder(std::move(web_context))); | 187 new WorkerFetchContextHolder(std::move(web_context))); |
101 } | 188 } |
102 | 189 |
103 } // namespace blink | 190 } // namespace blink |
OLD | NEW |