Commit b305873b authored by Hiroki Nakagawa's avatar Hiroki Nakagawa Committed by Commit Bot

Worker: Rename WorkerScriptLoader to WorkerClassicScriptLoader

This CL renames WorkerScriptLoader to WorkerClassicScriptLoader for clarifying
the loader is used for classic scripts, not for module scripts.

Bug: 680046
Change-Id: I037de4772e8323e4176989427fa6c2529c7fdab0
Reviewed-on: https://chromium-review.googlesource.com/965662Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Commit-Queue: Hiroki Nakagawa <nhiroki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543651}
parent eec47a70
......@@ -52,7 +52,7 @@ class SharedWorkerWebApplicationCacheHostImpl
kAppCacheNoHostId) {}
// Main resource loading is different for workers. The main resource is
// loaded by the worker using WorkerScriptLoader.
// loaded by the worker using WorkerClassicScriptLoader.
// These overrides are stubbed out.
void WillStartMainResourceRequest(
const blink::WebURL& url,
......
......@@ -46,10 +46,10 @@
#include "core/workers/SharedWorkerContentSettingsProxy.h"
#include "core/workers/SharedWorkerGlobalScope.h"
#include "core/workers/SharedWorkerThread.h"
#include "core/workers/WorkerClassicScriptLoader.h"
#include "core/workers/WorkerContentSettingsClient.h"
#include "core/workers/WorkerGlobalScope.h"
#include "core/workers/WorkerInspectorProxy.h"
#include "core/workers/WorkerScriptLoader.h"
#include "platform/CrossThreadFunctional.h"
#include "platform/heap/Handle.h"
#include "platform/heap/Persistent.h"
......@@ -118,7 +118,7 @@ void WebSharedWorkerImpl::OnShadowPageInitialized() {
DCHECK(!main_script_loader_);
shadow_page_->DocumentLoader()->SetServiceWorkerNetworkProvider(
client_->CreateServiceWorkerNetworkProvider());
main_script_loader_ = WorkerScriptLoader::Create();
main_script_loader_ = WorkerClassicScriptLoader::Create();
network::mojom::FetchRequestMode fetch_request_mode =
network::mojom::FetchRequestMode::kSameOrigin;
......
......@@ -54,8 +54,8 @@ class WebServiceWorkerNetworkProvider;
class WebSharedWorkerClient;
class WebString;
class WebURL;
class WorkerClassicScriptLoader;
class WorkerInspectorProxy;
class WorkerScriptLoader;
// This class is used by the worker process code to talk to the SharedWorker
// implementation. This is basically accessed on the main thread, but some
......@@ -131,7 +131,7 @@ class CORE_EXPORT WebSharedWorkerImpl final : public WebSharedWorker,
bool is_paused_on_start_ = false;
// Kept around only while main script loading is ongoing.
scoped_refptr<WorkerScriptLoader> main_script_loader_;
scoped_refptr<WorkerClassicScriptLoader> main_script_loader_;
WebURL url_;
WebString name_;
......
......@@ -52,6 +52,8 @@ blink_core_sources("workers") {
"WorkerBackingThread.cpp",
"WorkerBackingThread.h",
"WorkerBackingThreadStartupData.h",
"WorkerClassicScriptLoader.cpp",
"WorkerClassicScriptLoader.h",
"WorkerClients.cpp",
"WorkerClients.h",
"WorkerContentSettingsClient.cpp",
......@@ -73,8 +75,6 @@ blink_core_sources("workers") {
"WorkerOrWorkletModuleFetchCoordinatorProxy.cpp",
"WorkerOrWorkletModuleFetchCoordinatorProxy.h",
"WorkerReportingProxy.h",
"WorkerScriptLoader.cpp",
"WorkerScriptLoader.h",
"WorkerSettings.cpp",
"WorkerSettings.h",
"WorkerThread.cpp",
......
......@@ -17,10 +17,10 @@
#include "core/origin_trials/OriginTrialContext.h"
#include "core/probe/CoreProbes.h"
#include "core/workers/DedicatedWorkerMessagingProxy.h"
#include "core/workers/WorkerClassicScriptLoader.h"
#include "core/workers/WorkerClients.h"
#include "core/workers/WorkerContentSettingsClient.h"
#include "core/workers/WorkerOrWorkletModuleFetchCoordinator.h"
#include "core/workers/WorkerScriptLoader.h"
#include "platform/bindings/ScriptState.h"
#include "platform/weborigin/SecurityPolicy.h"
#include "public/platform/WebContentSettingsClient.h"
......@@ -124,8 +124,8 @@ void DedicatedWorker::Start() {
fetch_request_mode = network::mojom::FetchRequestMode::kNoCORS;
fetch_credentials_mode = network::mojom::FetchCredentialsMode::kInclude;
}
script_loader_ = WorkerScriptLoader::Create();
script_loader_->LoadAsynchronously(
classic_script_loader_ = WorkerClassicScriptLoader::Create();
classic_script_loader_->LoadAsynchronously(
*GetExecutionContext(), script_url_,
WebURLRequest::kRequestContextWorker, fetch_request_mode,
fetch_credentials_mode,
......@@ -154,8 +154,8 @@ void DedicatedWorker::terminate() {
void DedicatedWorker::ContextDestroyed(ExecutionContext*) {
DCHECK(IsMainThread());
if (script_loader_)
script_loader_->Cancel();
if (classic_script_loader_)
classic_script_loader_->Cancel();
terminate();
}
......@@ -163,7 +163,7 @@ bool DedicatedWorker::HasPendingActivity() const {
DCHECK(IsMainThread());
// The worker context does not exist while loading, so we must ensure that the
// worker object is not collected, nor are its event listeners.
return context_proxy_->HasPendingActivity() || script_loader_;
return context_proxy_->HasPendingActivity() || classic_script_loader_;
}
WorkerClients* DedicatedWorker::CreateWorkerClients() {
......@@ -185,32 +185,33 @@ WorkerClients* DedicatedWorker::CreateWorkerClients() {
void DedicatedWorker::OnResponse() {
DCHECK(IsMainThread());
probe::didReceiveScriptResponse(GetExecutionContext(),
script_loader_->Identifier());
classic_script_loader_->Identifier());
}
void DedicatedWorker::OnFinished(const v8_inspector::V8StackTraceId& stack_id) {
DCHECK(IsMainThread());
if (script_loader_->Canceled()) {
if (classic_script_loader_->Canceled()) {
// Do nothing.
} else if (script_loader_->Failed()) {
} else if (classic_script_loader_->Failed()) {
DispatchEvent(Event::CreateCancelable(EventTypeNames::error));
} else {
ReferrerPolicy referrer_policy = kReferrerPolicyDefault;
if (!script_loader_->GetReferrerPolicy().IsNull()) {
if (!classic_script_loader_->GetReferrerPolicy().IsNull()) {
SecurityPolicy::ReferrerPolicyFromHeaderValue(
script_loader_->GetReferrerPolicy(),
classic_script_loader_->GetReferrerPolicy(),
kDoNotSupportReferrerPolicyLegacyKeywords, &referrer_policy);
}
std::unique_ptr<GlobalScopeCreationParams> creation_params =
CreateGlobalScopeCreationParams();
creation_params->referrer_policy = referrer_policy;
context_proxy_->StartWorkerGlobalScope(std::move(creation_params), options_,
script_url_, stack_id,
script_loader_->SourceText());
probe::scriptImported(GetExecutionContext(), script_loader_->Identifier(),
script_loader_->SourceText());
context_proxy_->StartWorkerGlobalScope(
std::move(creation_params), options_, script_url_, stack_id,
classic_script_loader_->SourceText());
probe::scriptImported(GetExecutionContext(),
classic_script_loader_->Identifier(),
classic_script_loader_->SourceText());
}
script_loader_ = nullptr;
classic_script_loader_ = nullptr;
}
std::unique_ptr<GlobalScopeCreationParams>
......
......@@ -26,8 +26,8 @@ class DedicatedWorkerMessagingProxy;
class ExceptionState;
class ExecutionContext;
class ScriptState;
class WorkerClassicScriptLoader;
class WorkerClients;
class WorkerScriptLoader;
struct GlobalScopeCreationParams;
// Implementation of the Worker interface defined in the WebWorker HTML spec:
......@@ -81,8 +81,7 @@ class CORE_EXPORT DedicatedWorker final
WorkerClients* CreateWorkerClients();
// [classic script only]
// Callbacks for |script_loader_|.
// Callbacks for |classic_script_loader_|.
void OnResponse();
void OnFinished(const v8_inspector::V8StackTraceId&);
......@@ -93,7 +92,7 @@ class CORE_EXPORT DedicatedWorker final
const WorkerOptions options_;
const Member<DedicatedWorkerMessagingProxy> context_proxy_;
scoped_refptr<WorkerScriptLoader> script_loader_;
scoped_refptr<WorkerClassicScriptLoader> classic_script_loader_;
};
} // namespace blink
......
......@@ -25,7 +25,7 @@
*
*/
#include "core/workers/WorkerScriptLoader.h"
#include "core/workers/WorkerClassicScriptLoader.h"
#include <memory>
#include "base/memory/scoped_refptr.h"
......@@ -48,19 +48,19 @@
namespace blink {
WorkerScriptLoader::WorkerScriptLoader()
WorkerClassicScriptLoader::WorkerClassicScriptLoader()
: response_address_space_(mojom::IPAddressSpace::kPublic) {}
WorkerScriptLoader::~WorkerScriptLoader() {
WorkerClassicScriptLoader::~WorkerClassicScriptLoader() {
// If |m_threadableLoader| is still working, we have to cancel it here.
// Otherwise WorkerScriptLoader::didFail() of the deleted |this| will be
// called from DocumentThreadableLoader::notifyFinished() when the frame
// will be destroyed.
// Otherwise didFail() of the deleted |this| will be called from
// DocumentThreadableLoader::notifyFinished() when the frame will be
// destroyed.
if (need_to_cancel_)
Cancel();
}
void WorkerScriptLoader::LoadSynchronously(
void WorkerClassicScriptLoader::LoadSynchronously(
ExecutionContext& execution_context,
const KURL& url,
WebURLRequest::RequestContext request_context,
......@@ -87,7 +87,7 @@ void WorkerScriptLoader::LoadSynchronously(
resource_loader_options);
}
void WorkerScriptLoader::LoadAsynchronously(
void WorkerClassicScriptLoader::LoadAsynchronously(
ExecutionContext& execution_context,
const KURL& url,
WebURLRequest::RequestContext request_context,
......@@ -118,7 +118,7 @@ void WorkerScriptLoader::LoadAsynchronously(
// to this object, while some of the callchain assumes that the client and
// loader wouldn't be deleted within callbacks.
// (E.g. see crbug.com/524694 for why we can't easily remove this protect)
scoped_refptr<WorkerScriptLoader> protect(this);
scoped_refptr<WorkerClassicScriptLoader> protect(this);
need_to_cancel_ = true;
threadable_loader_ = ThreadableLoader::Create(
execution_context, this, options, resource_loader_options);
......@@ -127,12 +127,12 @@ void WorkerScriptLoader::LoadAsynchronously(
NotifyFinished();
}
const KURL& WorkerScriptLoader::ResponseURL() const {
const KURL& WorkerClassicScriptLoader::ResponseURL() const {
DCHECK(!Failed());
return response_url_;
}
void WorkerScriptLoader::DidReceiveResponse(
void WorkerClassicScriptLoader::DidReceiveResponse(
unsigned long identifier,
const ResourceResponse& response,
std::unique_ptr<WebDataConsumerHandle> handle) {
......@@ -166,7 +166,7 @@ void WorkerScriptLoader::DidReceiveResponse(
std::move(response_callback_).Run();
}
void WorkerScriptLoader::DidReceiveData(const char* data, unsigned len) {
void WorkerClassicScriptLoader::DidReceiveData(const char* data, unsigned len) {
if (failed_)
return;
......@@ -183,12 +183,14 @@ void WorkerScriptLoader::DidReceiveData(const char* data, unsigned len) {
source_text_.Append(decoder_->Decode(data, len));
}
void WorkerScriptLoader::DidReceiveCachedMetadata(const char* data, int size) {
void WorkerClassicScriptLoader::DidReceiveCachedMetadata(const char* data,
int size) {
cached_metadata_ = std::make_unique<Vector<char>>(size);
memcpy(cached_metadata_->data(), data, size);
}
void WorkerScriptLoader::DidFinishLoading(unsigned long identifier, double) {
void WorkerClassicScriptLoader::DidFinishLoading(unsigned long identifier,
double) {
need_to_cancel_ = false;
if (!failed_ && decoder_)
source_text_.Append(decoder_->Flush());
......@@ -196,29 +198,29 @@ void WorkerScriptLoader::DidFinishLoading(unsigned long identifier, double) {
NotifyFinished();
}
void WorkerScriptLoader::DidFail(const ResourceError& error) {
void WorkerClassicScriptLoader::DidFail(const ResourceError& error) {
need_to_cancel_ = false;
canceled_ = error.IsCancellation();
NotifyError();
}
void WorkerScriptLoader::DidFailRedirectCheck() {
void WorkerClassicScriptLoader::DidFailRedirectCheck() {
// When didFailRedirectCheck() is called, the ResourceLoader for the script
// is not canceled yet. So we don't reset |m_needToCancel| here.
NotifyError();
}
void WorkerScriptLoader::Cancel() {
void WorkerClassicScriptLoader::Cancel() {
need_to_cancel_ = false;
if (threadable_loader_)
threadable_loader_->Cancel();
}
String WorkerScriptLoader::SourceText() {
String WorkerClassicScriptLoader::SourceText() {
return source_text_.ToString();
}
void WorkerScriptLoader::NotifyError() {
void WorkerClassicScriptLoader::NotifyError() {
failed_ = true;
// notifyError() could be called before ThreadableLoader::create() returns
// e.g. from didFail(), and in that case m_threadableLoader is not yet set
......@@ -230,14 +232,14 @@ void WorkerScriptLoader::NotifyError() {
NotifyFinished();
}
void WorkerScriptLoader::NotifyFinished() {
void WorkerClassicScriptLoader::NotifyFinished() {
if (!finished_callback_)
return;
std::move(finished_callback_).Run();
}
void WorkerScriptLoader::ProcessContentSecurityPolicy(
void WorkerClassicScriptLoader::ProcessContentSecurityPolicy(
const ResourceResponse& response) {
// Per http://www.w3.org/TR/CSP2/#processing-model-workers, if the Worker's
// URL is not a GUID, then it grabs its CSP from the response headers
......
......@@ -25,8 +25,8 @@
*
*/
#ifndef WorkerScriptLoader_h
#define WorkerScriptLoader_h
#ifndef WorkerClassicScriptLoader_h
#define WorkerClassicScriptLoader_h
#include <memory>
#include "base/memory/scoped_refptr.h"
......@@ -51,14 +51,14 @@ class ResourceResponse;
class ExecutionContext;
class TextResourceDecoder;
class CORE_EXPORT WorkerScriptLoader final
: public RefCounted<WorkerScriptLoader>,
class CORE_EXPORT WorkerClassicScriptLoader final
: public RefCounted<WorkerClassicScriptLoader>,
public ThreadableLoaderClient {
USING_FAST_MALLOC(WorkerScriptLoader);
USING_FAST_MALLOC(WorkerClassicScriptLoader);
public:
static scoped_refptr<WorkerScriptLoader> Create() {
return base::AdoptRef(new WorkerScriptLoader());
static scoped_refptr<WorkerClassicScriptLoader> Create() {
return base::AdoptRef(new WorkerClassicScriptLoader());
}
void LoadSynchronously(ExecutionContext&,
......@@ -121,10 +121,10 @@ class CORE_EXPORT WorkerScriptLoader final
void DidFailRedirectCheck() override;
private:
friend class WTF::RefCounted<WorkerScriptLoader>;
friend class WTF::RefCounted<WorkerClassicScriptLoader>;
WorkerScriptLoader();
~WorkerScriptLoader() override;
WorkerClassicScriptLoader();
~WorkerClassicScriptLoader() override;
void NotifyError();
void NotifyFinished();
......@@ -159,4 +159,4 @@ class CORE_EXPORT WorkerScriptLoader final
} // namespace blink
#endif // WorkerScriptLoader_h
#endif // WorkerClassicScriptLoader_h
......@@ -50,11 +50,11 @@
#include "core/script/Modulator.h"
#include "core/workers/GlobalScopeCreationParams.h"
#include "core/workers/InstalledScriptsManager.h"
#include "core/workers/WorkerClassicScriptLoader.h"
#include "core/workers/WorkerLocation.h"
#include "core/workers/WorkerModuleTreeClient.h"
#include "core/workers/WorkerNavigator.h"
#include "core/workers/WorkerReportingProxy.h"
#include "core/workers/WorkerScriptLoader.h"
#include "core/workers/WorkerThread.h"
#include "platform/CrossThreadFunctional.h"
#include "platform/InstanceCounters.h"
......@@ -167,7 +167,7 @@ void WorkerGlobalScope::importScripts(const Vector<String>& urls,
// If the script wasn't provided by the InstalledScriptsManager, load from
// ResourceLoader.
if (result == LoadResult::kNotHandled) {
result = LoadingScriptFromWorkerScriptLoader(
result = LoadingScriptFromClassicScriptLoader(
complete_url, &response_url, &source_code, &cached_meta_data);
}
......@@ -227,27 +227,28 @@ WorkerGlobalScope::LoadingScriptFromInstalledScriptsManager(
}
WorkerGlobalScope::LoadResult
WorkerGlobalScope::LoadingScriptFromWorkerScriptLoader(
WorkerGlobalScope::LoadingScriptFromClassicScriptLoader(
const KURL& script_url,
KURL* out_response_url,
String* out_source_code,
std::unique_ptr<Vector<char>>* out_cached_meta_data) {
ExecutionContext* execution_context = GetExecutionContext();
scoped_refptr<WorkerScriptLoader> script_loader(WorkerScriptLoader::Create());
script_loader->LoadSynchronously(
scoped_refptr<WorkerClassicScriptLoader> classic_script_loader(
WorkerClassicScriptLoader::Create());
classic_script_loader->LoadSynchronously(
*execution_context, script_url, WebURLRequest::kRequestContextScript,
execution_context->GetSecurityContext().AddressSpace());
// If the fetching attempt failed, throw a NetworkError exception and
// abort all these steps.
if (script_loader->Failed())
if (classic_script_loader->Failed())
return LoadResult::kFailed;
*out_response_url = script_loader->ResponseURL();
*out_source_code = script_loader->SourceText();
*out_cached_meta_data = script_loader->ReleaseCachedMetadata();
probe::scriptImported(execution_context, script_loader->Identifier(),
script_loader->SourceText());
*out_response_url = classic_script_loader->ResponseURL();
*out_source_code = classic_script_loader->SourceText();
*out_cached_meta_data = classic_script_loader->ReleaseCachedMetadata();
probe::scriptImported(execution_context, classic_script_loader->Identifier(),
classic_script_loader->SourceText());
return LoadResult::kSuccess;
}
......
......@@ -176,10 +176,10 @@ class CORE_EXPORT WorkerGlobalScope
KURL* out_response_url,
String* out_source_code,
std::unique_ptr<Vector<char>>* out_cached_meta_data);
// Tries to load the script synchronously from the WorkerScriptLoader, which
// requests the script from the browser. This
// blocks until the script is received.
LoadResult LoadingScriptFromWorkerScriptLoader(
// Tries to load the script synchronously from the WorkerClassicScriptLoader,
// which requests the script from the browser. This blocks until the script is
// received.
LoadResult LoadingScriptFromClassicScriptLoader(
const KURL& script_url,
KURL* out_response_url,
String* out_source_code,
......
......@@ -41,10 +41,10 @@
#include "core/probe/CoreProbes.h"
#include "core/workers/ParentFrameTaskRunners.h"
#include "core/workers/WorkerBackingThreadStartupData.h"
#include "core/workers/WorkerClassicScriptLoader.h"
#include "core/workers/WorkerContentSettingsClient.h"
#include "core/workers/WorkerGlobalScope.h"
#include "core/workers/WorkerInspectorProxy.h"
#include "core/workers/WorkerScriptLoader.h"
#include "modules/indexeddb/IndexedDBClient.h"
#include "modules/serviceworkers/ServiceWorkerContainerClient.h"
#include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h"
......@@ -267,7 +267,7 @@ void WebEmbeddedWorkerImpl::OnShadowPageInitialized() {
}
DCHECK(!main_script_loader_);
main_script_loader_ = WorkerScriptLoader::Create();
main_script_loader_ = WorkerClassicScriptLoader::Create();
main_script_loader_->LoadAsynchronously(
*shadow_page_->GetDocument(), worker_start_data_.script_url,
WebURLRequest::kRequestContextServiceWorker,
......
......@@ -47,8 +47,8 @@ namespace blink {
class ContentSecurityPolicy;
class ServiceWorkerInstalledScriptsManager;
class WorkerClassicScriptLoader;
class WorkerInspectorProxy;
class WorkerScriptLoader;
class WorkerThread;
class MODULES_EXPORT WebEmbeddedWorkerImpl final
......@@ -105,7 +105,7 @@ class MODULES_EXPORT WebEmbeddedWorkerImpl final
std::unique_ptr<ServiceWorkerContentSettingsProxy> content_settings_client_;
// Kept around only while main script loading is ongoing.
scoped_refptr<WorkerScriptLoader> main_script_loader_;
scoped_refptr<WorkerClassicScriptLoader> main_script_loader_;
std::unique_ptr<WorkerThread> worker_thread_;
Persistent<WorkerInspectorProxy> worker_inspector_proxy_;
......
......@@ -38,7 +38,7 @@ ServiceWorkerInstalledScriptsManager::GetScriptData(
return ScriptStatus::kFailed;
}
// This is from WorkerScriptLoader::DidReceiveData.
// This is from WorkerClassicScriptLoader::DidReceiveData.
std::unique_ptr<TextResourceDecoder> decoder =
TextResourceDecoder::Create(TextResourceDecoderOptions(
TextResourceDecoderOptions::kPlainTextContent,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment