1 // 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.
5 #ifndef MOJO_EXAMPLE_HTML_VIEWER_WEBURLLOADER_IMPL_H_
6 #define MOJO_EXAMPLE_HTML_VIEWER_WEBURLLOADER_IMPL_H_
8 #include "base/memory/weak_ptr.h"
9 #include "mojo/common/handle_watcher.h"
10 #include "mojo/services/public/interfaces/network/url_loader.mojom.h"
11 #include "third_party/WebKit/public/platform/WebURLLoader.h"
18 class WebURLLoaderImpl : public blink::WebURLLoader,
19 public URLLoaderClient {
21 explicit WebURLLoaderImpl(NetworkService* network_service);
24 virtual ~WebURLLoaderImpl();
26 // blink::WebURLLoader methods:
27 virtual void loadSynchronously(
28 const blink::WebURLRequest& request, blink::WebURLResponse& response,
29 blink::WebURLError& error, blink::WebData& data) OVERRIDE;
30 virtual void loadAsynchronously(
31 const blink::WebURLRequest&, blink::WebURLLoaderClient* client) OVERRIDE;
32 virtual void cancel() OVERRIDE;
33 virtual void setDefersLoading(bool defers_loading) OVERRIDE;
35 // URLLoaderClient methods:
36 virtual void OnReceivedRedirect(URLResponsePtr response,
37 const String& new_url,
38 const String& new_method) OVERRIDE;
39 virtual void OnReceivedResponse(URLResponsePtr response) OVERRIDE;
40 virtual void OnReceivedError(NetworkErrorPtr error) OVERRIDE;
41 virtual void OnReceivedEndOfResponseBody() OVERRIDE;
44 void WaitToReadMore();
45 void OnResponseBodyStreamReady(MojoResult result);
47 URLLoaderPtr url_loader_;
48 blink::WebURLLoaderClient* client_;
49 ScopedDataPipeConsumerHandle response_body_stream_;
50 common::HandleWatcher handle_watcher_;
52 base::WeakPtrFactory<WebURLLoaderImpl> weak_factory_;
54 DISALLOW_COPY_AND_ASSIGN(WebURLLoaderImpl);
57 } // namespace examples
60 #endif // MOJO_EXAMPLE_HTML_VIEWER_WEBURLLOADER_IMPL_H_