blob: 3372f437467a610ab248768b58191533df5d9da5 [file] [log] [blame]
Adam Barth06caa3d2014-10-23 11:15:41 -07001// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef SKY_VIEWER_PLATFORM_WEBURLLOADER_IMPL_H_
6#define SKY_VIEWER_PLATFORM_WEBURLLOADER_IMPL_H_
7
8#include "base/memory/weak_ptr.h"
9#include "mojo/common/handle_watcher.h"
Colin Blundellb470fa12014-12-10 16:28:40 +010010#include "mojo/services/network/public/interfaces/url_loader.mojom.h"
Adam Barth06caa3d2014-10-23 11:15:41 -070011#include "sky/engine/public/platform/WebURLLoader.h"
12#include "sky/engine/public/platform/WebURLRequest.h"
13
14namespace mojo {
15class NetworkService;
16}
17
18namespace sky {
Adam Barth06caa3d2014-10-23 11:15:41 -070019
20class WebURLLoaderImpl : public blink::WebURLLoader {
21 public:
22 explicit WebURLLoaderImpl(mojo::NetworkService* network_service);
23
24 private:
25 virtual ~WebURLLoaderImpl();
26
27 // blink::WebURLLoader methods:
28 virtual void loadAsynchronously(
29 const blink::WebURLRequest&, blink::WebURLLoaderClient* client) override;
30 virtual void cancel() override;
31
32 void OnReceivedResponse(mojo::URLResponsePtr response);
33 void OnReceivedError(mojo::URLResponsePtr response);
34 void OnReceivedRedirect(mojo::URLResponsePtr response);
35 void ReadMore();
36 void WaitToReadMore();
37 void OnResponseBodyStreamReady(MojoResult result);
38
39 blink::WebURLLoaderClient* client_;
40 GURL url_;
41 mojo::URLLoaderPtr url_loader_;
42 mojo::ScopedDataPipeConsumerHandle response_body_stream_;
43 mojo::common::HandleWatcher handle_watcher_;
44
45 base::WeakPtrFactory<WebURLLoaderImpl> weak_factory_;
46
47 DISALLOW_COPY_AND_ASSIGN(WebURLLoaderImpl);
48};
49
50} // namespace sky
51
52#endif // SKY_VIEWER_PLATFORM_WEBURLLOADER_IMPL_H_