summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/loader/web_associated_url_loader_impl.h
blob: 9c9ef87280d8de7a3f430c6d9e545ed2fca0d32f (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright 2016 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_WEB_ASSOCIATED_URL_LOADER_IMPL_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_LOADER_WEB_ASSOCIATED_URL_LOADER_IMPL_H_

#include "base/macros.h"
#include "base/memory/scoped_refptr.h"
#include "base/single_thread_task_runner.h"
#include "third_party/blink/public/web/web_associated_url_loader.h"
#include "third_party/blink/public/web/web_associated_url_loader_options.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/platform/heap/persistent.h"

namespace blink {

class ThreadableLoader;
class WebAssociatedURLLoaderClient;
class ExecutionContext;

// This class is used to implement WebFrame::createAssociatedURLLoader.
class CORE_EXPORT WebAssociatedURLLoaderImpl final
    : public WebAssociatedURLLoader {
  USING_FAST_MALLOC(WebAssociatedURLLoaderImpl);

 public:
  WebAssociatedURLLoaderImpl(ExecutionContext*,
                             const WebAssociatedURLLoaderOptions&);
  ~WebAssociatedURLLoaderImpl() override;

  void LoadAsynchronously(const WebURLRequest&,
                          WebAssociatedURLLoaderClient*) override;
  void Cancel() override;
  void SetDefersLoading(bool) override;
  void SetLoadingTaskRunner(base::SingleThreadTaskRunner*) override;

  // Called by ClientAdapter to handle completion of loading.
  void ClientAdapterDone();

 private:
  class ClientAdapter;
  class Observer;

  void ContextDestroyed();
  void CancelLoader();
  void DisposeObserver();

  WebAssociatedURLLoaderClient* ReleaseClient() {
    WebAssociatedURLLoaderClient* client = client_;
    client_ = nullptr;
    return client;
  }

  WebAssociatedURLLoaderClient* client_;
  WebAssociatedURLLoaderOptions options_;

  // Converts ThreadableLoaderClient method calls into WebURLLoaderClient method
  // calls.
  Persistent<ClientAdapter> client_adapter_;
  Persistent<ThreadableLoader> loader_;

  // A ExecutionContextLifecycleObserver for cancelling |loader_| when the
  // context is detached.
  Persistent<Observer> observer_;

  DISALLOW_COPY_AND_ASSIGN(WebAssociatedURLLoaderImpl);
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_LOADER_WEB_ASSOCIATED_URL_LOADER_IMPL_H_