Chromium Code Reviews| 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/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 Loading... | |
| 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.GetFetchContext()) {} | |
| 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 error_message; | |
| 99 return worker_global_scope_->IsSecureContext(error_message); | |
| 100 } | |
| 101 | |
| 102 KURL FirstPartyForCookies() const override { | |
| 103 DCHECK(IsContextThread()); | |
| 104 // TODO(horo): Returns the FirstPartyForCookies of the parent frame for | |
| 105 // dedicated workers. | |
| 106 return worker_global_scope_->Url(); | |
| 107 } | |
| 108 | |
| 109 String UserAgent() const override { | |
| 110 DCHECK(IsContextThread()); | |
| 111 return worker_global_scope_->UserAgent(); | |
| 112 } | |
| 113 | |
| 114 Document* GetLoadingDocument() override { return nullptr; } | |
| 115 | |
| 116 RefPtr<WebTaskRunner> GetTaskRunner(TaskType type) override { | |
| 117 return fetch_context_->LoadingTaskRunner(); | |
| 118 } | |
| 119 | |
| 120 void RecordUseCount(UseCounter::Feature feature) override { | |
| 121 UseCounter::Count(worker_global_scope_, feature); | |
| 122 } | |
| 123 | |
| 124 DEFINE_INLINE_VIRTUAL_TRACE() { | |
| 125 visitor->Trace(fetch_context_); | |
| 126 visitor->Trace(worker_global_scope_); | |
| 127 ThreadableLoadingContext::Trace(visitor); | |
| 128 } | |
| 129 | |
| 130 private: | |
| 131 Member<WorkerGlobalScope> worker_global_scope_; | |
| 132 Member<WorkerFetchContext> fetch_context_; | |
| 133 }; | |
| 134 | |
| 69 ThreadableLoadingContext* ThreadableLoadingContext::Create(Document& document) { | 135 ThreadableLoadingContext* ThreadableLoadingContext::Create(Document& document) { |
| 70 // For now this is the only default implementation. | 136 // For now this is the only default implementation. |
|
kinuko
2017/05/13 13:26:42
Please remove this comment.
horo
2017/05/13 17:05:45
Done.
| |
| 71 return new DocumentThreadableLoadingContext(document); | 137 return new DocumentThreadableLoadingContext(document); |
| 72 } | 138 } |
| 73 | 139 |
| 140 ThreadableLoadingContext* ThreadableLoadingContext::Create( | |
| 141 WorkerGlobalScope& worker_global_scope) { | |
| 142 return new WorkerThreadableLoadingContext(worker_global_scope); | |
| 143 } | |
| 144 | |
| 74 } // namespace blink | 145 } // namespace blink |
| OLD | NEW |