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

Unified Diff: third_party/WebKit/Source/core/loader/ThreadableLoadingContext.cpp

Issue 2816403002: test all
Patch Set: fix sharedworker Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
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..6e7584d5b020bcaa3f6b098e625d84391dfa351b 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,85 @@ 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.FetchContext()) {}
+
+ ~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 errorMessage;
+ return worker_global_scope_->IsSecureContext(errorMessage);
+ }
+
+ KURL FirstPartyForCookies() const override {
+ DCHECK(IsContextThread());
+ // TODO
+ 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 {
+ switch (type) {
+ case TaskType::kTimer:
+ return fetch_context_->TimerTaskRunner();
+ case TaskType::kUnspecedLoading:
+ case TaskType::kNetworking:
+ return fetch_context_->LoadingTaskRunner();
+ default:
+ return TaskRunnerHelper::Get(type, GetLoadingDocument());
+ }
+ }
+
+ 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

Powered by Google App Engine
This is Rietveld 408576698