summaryrefslogtreecommitdiffstats
path: root/components/html_viewer/web_url_loader_impl.h
blob: 4a92a8aa58227015a55ceca70f242197a93e3529 (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
73
74
75
76
77
78
// Copyright 2014 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 COMPONENTS_HTML_VIEWER_WEB_URL_LOADER_IMPL_H_
#define COMPONENTS_HTML_VIEWER_WEB_URL_LOADER_IMPL_H_

#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "components/html_viewer/mock_web_blob_registry_impl.h"
#include "mojo/common/handle_watcher.h"
#include "mojo/services/network/public/interfaces/url_loader.mojom.h"
#include "third_party/WebKit/public/platform/WebBlobData.h"
#include "third_party/WebKit/public/platform/WebReferrerPolicy.h"
#include "third_party/WebKit/public/platform/WebURLLoader.h"
#include "third_party/WebKit/public/platform/WebURLRequest.h"

namespace mojo {
class NetworkService;
}

namespace html_viewer {

// The concrete type of WebURLRequest::ExtraData.
class WebURLRequestExtraData : public blink::WebURLRequest::ExtraData {
 public:
  WebURLRequestExtraData();
  virtual ~WebURLRequestExtraData();

  mojo::URLResponsePtr synthetic_response;
};

class WebURLLoaderImpl : public blink::WebURLLoader {
 public:
  explicit WebURLLoaderImpl(mojo::NetworkService* network_service,
                            MockWebBlobRegistryImpl* web_blob_registry);

 private:
  virtual ~WebURLLoaderImpl();

  // blink::WebURLLoader methods:
  virtual void loadSynchronously(const blink::WebURLRequest& request,
                                 blink::WebURLResponse& response,
                                 blink::WebURLError& error,
                                 blink::WebData& data);
  virtual void loadAsynchronously(const blink::WebURLRequest&,
                                  blink::WebURLLoaderClient* client);
  virtual void cancel();
  virtual void setDefersLoading(bool defers_loading);

  void OnReceivedResponse(const blink::WebURLRequest& request,
                          mojo::URLResponsePtr response);
  void OnReceivedError(mojo::URLResponsePtr response);
  void OnReceivedRedirect(const blink::WebURLRequest& request,
                          mojo::URLResponsePtr response);
  void OnReceiveWebBlobData(
      const blink::WebURLRequest& request,
      const blink::WebVector<blink::WebBlobData::Item*>& items);
  void ReadMore();
  void WaitToReadMore();
  void OnResponseBodyStreamReady(MojoResult result);

  blink::WebURLLoaderClient* client_;
  MockWebBlobRegistryImpl* web_blob_registry_;
  GURL url_;
  blink::WebReferrerPolicy referrer_policy_;
  mojo::URLLoaderPtr url_loader_;
  mojo::ScopedDataPipeConsumerHandle response_body_stream_;
  mojo::common::HandleWatcher handle_watcher_;

  base::WeakPtrFactory<WebURLLoaderImpl> weak_factory_;

  DISALLOW_COPY_AND_ASSIGN(WebURLLoaderImpl);
};

}  // namespace html_viewer

#endif  // COMPONENTS_HTML_VIEWER_WEB_URL_LOADER_IMPL_H_