Index: third_party/WebKit/Source/core/loader/ThreadableLoadingContext.cpp |
diff --git a/third_party/WebKit/Source/core/loader/ThreadableLoadingContext.cpp b/third_party/WebKit/Source/core/loader/ThreadableLoadingContext.cpp |
index 0df2ad47213df7af3b4e772b0f8176aebe3ac48d..551dd18c046896d657658ce0ba857ba03f1f5304 100644 |
--- a/third_party/WebKit/Source/core/loader/ThreadableLoadingContext.cpp |
+++ b/third_party/WebKit/Source/core/loader/ThreadableLoadingContext.cpp |
@@ -6,6 +6,8 @@ |
#include "core/dom/Document.h" |
#include "core/dom/TaskRunnerHelper.h" |
+#include "core/loader/WorkerFetchContext.h" |
+#include "core/workers/WorkerGlobalScope.h" |
#include "platform/loader/fetch/ResourceFetcher.h" |
namespace blink { |
@@ -66,9 +68,77 @@ class DocumentThreadableLoadingContext final : public ThreadableLoadingContext { |
Member<Document> document_; |
}; |
+class WorkerThreadableLoadingContext : public ThreadableLoadingContext { |
+ public: |
+ explicit WorkerThreadableLoadingContext( |
+ WorkerGlobalScope& worker_global_scope) |
+ : worker_global_scope_(&worker_global_scope), |
+ fetch_context_(worker_global_scope.GetFetchContext()) {} |
+ |
+ ~WorkerThreadableLoadingContext() override = default; |
+ |
+ bool IsContextThread() const override { |
+ DCHECK(fetch_context_); |
+ DCHECK(worker_global_scope_); |
+ return worker_global_scope_->IsContextThread(); |
+ } |
+ |
+ ResourceFetcher* GetResourceFetcher() override { |
+ DCHECK(IsContextThread()); |
+ return fetch_context_->GetResourceFetcher(); |
+ } |
+ |
+ SecurityOrigin* GetSecurityOrigin() override { |
+ DCHECK(IsContextThread()); |
+ return worker_global_scope_->GetSecurityOrigin(); |
+ } |
+ |
+ bool IsSecureContext() const override { |
+ DCHECK(IsContextThread()); |
+ String error_message; |
+ return worker_global_scope_->IsSecureContext(error_message); |
+ } |
+ |
+ KURL FirstPartyForCookies() const override { |
+ DCHECK(IsContextThread()); |
+ // TODO(horo): Returns the FirstPartyForCookies of the parent frame for |
+ // dedicated workers. |
+ return worker_global_scope_->Url(); |
+ } |
+ |
+ String UserAgent() const override { |
+ DCHECK(IsContextThread()); |
+ return worker_global_scope_->UserAgent(); |
+ } |
+ |
+ Document* GetLoadingDocument() override { return nullptr; } |
+ |
+ RefPtr<WebTaskRunner> GetTaskRunner(TaskType type) override { |
+ return fetch_context_->LoadingTaskRunner(); |
+ } |
+ |
+ void RecordUseCount(UseCounter::Feature feature) override { |
+ UseCounter::Count(worker_global_scope_, feature); |
+ } |
+ |
+ DEFINE_INLINE_VIRTUAL_TRACE() { |
+ visitor->Trace(fetch_context_); |
+ visitor->Trace(worker_global_scope_); |
+ ThreadableLoadingContext::Trace(visitor); |
+ } |
+ |
+ private: |
+ Member<WorkerGlobalScope> worker_global_scope_; |
+ Member<WorkerFetchContext> fetch_context_; |
+}; |
+ |
ThreadableLoadingContext* ThreadableLoadingContext::Create(Document& document) { |
- // For now this is the only default implementation. |
return new DocumentThreadableLoadingContext(document); |
} |
+ThreadableLoadingContext* ThreadableLoadingContext::Create( |
+ WorkerGlobalScope& worker_global_scope) { |
+ return new WorkerThreadableLoadingContext(worker_global_scope); |
+} |
+ |
} // namespace blink |