summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/loader/modulescript/document_module_script_fetcher.h
blob: be860391b5224d960fec5934616111cff33e15b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_LOADER_MODULESCRIPT_DOCUMENT_MODULE_SCRIPT_FETCHER_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_LOADER_MODULESCRIPT_DOCUMENT_MODULE_SCRIPT_FETCHER_H_

#include "base/optional.h"
#include "third_party/blink/renderer/core/loader/modulescript/module_script_creation_params.h"
#include "third_party/blink/renderer/core/loader/modulescript/module_script_fetcher.h"
#include "third_party/blink/renderer/core/loader/resource/script_resource.h"
#include "third_party/blink/renderer/core/script/modulator.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_parameters.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_fetcher.h"
#include "third_party/blink/renderer/platform/weborigin/security_origin.h"

namespace blink {

class ConsoleMessage;

// DocumentModuleScriptFetcher is used to fetch module scripts used in main
// documents and workers (but not worklets).
//
// DocumentModuleScriptFetcher emits FetchParameters to ResourceFetcher
// (via ScriptResource::Fetch). Then, it keeps track of the fetch progress by
// being a ResourceClient. Finally, it returns its client a fetched resource as
// ModuleScriptCreationParams.
class CORE_EXPORT DocumentModuleScriptFetcher : public ModuleScriptFetcher,
                                                public ResourceClient {
  USING_GARBAGE_COLLECTED_MIXIN(DocumentModuleScriptFetcher);

 public:
  explicit DocumentModuleScriptFetcher(ResourceFetcher*);

  void Fetch(FetchParameters&, ModuleScriptFetcher::Client*) final;

  // Implements ResourceClient
  void NotifyFinished(Resource*) final;
  String DebugName() const final { return "DocumentModuleScriptFetcher"; }

  void Trace(blink::Visitor*) override;

 private:
  void Finalize(const base::Optional<ModuleScriptCreationParams>&,
                const HeapVector<Member<ConsoleMessage>>& error_messages);

  // Returns true if loaded as Layered API.
  bool FetchIfLayeredAPI(FetchParameters&);

  Member<ResourceFetcher> fetcher_;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_LOADER_MODULESCRIPT_DOCUMENT_MODULE_SCRIPT_FETCHER_H_