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

Side by Side 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 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/ThreadableLoadingContext.h" 5 #include "core/loader/ThreadableLoadingContext.h"
6 6
7 #include "core/dom/Document.h" 7 #include "core/dom/Document.h"
8 #include "core/dom/TaskRunnerHelper.h" 8 #include "core/dom/TaskRunnerHelper.h"
9 #include "core/loader/WorkerFetchContext.h"
10 #include "core/workers/WorkerGlobalScope.h"
9 #include "platform/loader/fetch/ResourceFetcher.h" 11 #include "platform/loader/fetch/ResourceFetcher.h"
10 12
11 namespace blink { 13 namespace blink {
12 14
13 class DocumentThreadableLoadingContext final : public ThreadableLoadingContext { 15 class DocumentThreadableLoadingContext final : public ThreadableLoadingContext {
14 public: 16 public:
15 explicit DocumentThreadableLoadingContext(Document& document) 17 explicit DocumentThreadableLoadingContext(Document& document)
16 : document_(&document) {} 18 : document_(&document) {}
17 19
18 ~DocumentThreadableLoadingContext() override = default; 20 ~DocumentThreadableLoadingContext() override = default;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 61
60 DEFINE_INLINE_VIRTUAL_TRACE() { 62 DEFINE_INLINE_VIRTUAL_TRACE() {
61 visitor->Trace(document_); 63 visitor->Trace(document_);
62 ThreadableLoadingContext::Trace(visitor); 64 ThreadableLoadingContext::Trace(visitor);
63 } 65 }
64 66
65 private: 67 private:
66 Member<Document> document_; 68 Member<Document> document_;
67 }; 69 };
68 70
71 class WorkerThreadableLoadingContext : public ThreadableLoadingContext {
72 public:
73 explicit WorkerThreadableLoadingContext(
74 WorkerGlobalScope& worker_global_scope)
75 : worker_global_scope_(&worker_global_scope),
76 fetch_context_(worker_global_scope.FetchContext()) {}
77
78 ~WorkerThreadableLoadingContext() override = default;
79
80 bool IsContextThread() const override {
81 DCHECK(fetch_context_);
82 DCHECK(worker_global_scope_);
83 return worker_global_scope_->IsContextThread();
84 }
85
86 ResourceFetcher* GetResourceFetcher() override {
87 DCHECK(IsContextThread());
88 return fetch_context_->GetResourceFetcher();
89 }
90
91 SecurityOrigin* GetSecurityOrigin() override {
92 DCHECK(IsContextThread());
93 return worker_global_scope_->GetSecurityOrigin();
94 }
95
96 bool IsSecureContext() const override {
97 DCHECK(IsContextThread());
98 String errorMessage;
99 return worker_global_scope_->IsSecureContext(errorMessage);
100 }
101
102 KURL FirstPartyForCookies() const override {
103 DCHECK(IsContextThread());
104 // TODO
105 return worker_global_scope_->Url();
106 }
107
108 String UserAgent() const override {
109 DCHECK(IsContextThread());
110 return worker_global_scope_->UserAgent();
111 }
112
113 Document* GetLoadingDocument() override { return nullptr; }
114
115 RefPtr<WebTaskRunner> GetTaskRunner(TaskType type) override {
116 switch (type) {
117 case TaskType::kTimer:
118 return fetch_context_->TimerTaskRunner();
119 case TaskType::kUnspecedLoading:
120 case TaskType::kNetworking:
121 return fetch_context_->LoadingTaskRunner();
122 default:
123 return TaskRunnerHelper::Get(type, GetLoadingDocument());
124 }
125 }
126
127 void RecordUseCount(UseCounter::Feature feature) override {
128 UseCounter::Count(worker_global_scope_, feature);
129 }
130
131 DEFINE_INLINE_VIRTUAL_TRACE() {
132 visitor->Trace(fetch_context_);
133 visitor->Trace(worker_global_scope_);
134 ThreadableLoadingContext::Trace(visitor);
135 }
136
137 private:
138 Member<WorkerGlobalScope> worker_global_scope_;
139 Member<WorkerFetchContext> fetch_context_;
140 };
141
69 ThreadableLoadingContext* ThreadableLoadingContext::Create(Document& document) { 142 ThreadableLoadingContext* ThreadableLoadingContext::Create(Document& document) {
70 // For now this is the only default implementation. 143 // For now this is the only default implementation.
71 return new DocumentThreadableLoadingContext(document); 144 return new DocumentThreadableLoadingContext(document);
72 } 145 }
73 146
147 ThreadableLoadingContext* ThreadableLoadingContext::Create(
148 WorkerGlobalScope& worker_global_scope) {
149 return new WorkerThreadableLoadingContext(worker_global_scope);
150 }
151
74 } // namespace blink 152 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698