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_SERVICES_HTML_VIEWER_WEBURLLOADER_IMPL_H_
6 #define MOJO_SERVICES_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"
12 #include "third_party/WebKit/public/platform/WebURLRequest.h"
17 // The concrete type of WebURLRequest::ExtraData.
18 class WebURLRequestExtraData : public blink::WebURLRequest::ExtraData {
20 WebURLRequestExtraData();
21 virtual ~WebURLRequestExtraData();
23 URLResponsePtr synthetic_response;
26 class WebURLLoaderImpl : public blink::WebURLLoader {
28 explicit WebURLLoaderImpl(NetworkService* network_service);
31 virtual ~WebURLLoaderImpl();
33 // blink::WebURLLoader methods:
34 virtual void loadSynchronously(
35 const blink::WebURLRequest& request, blink::WebURLResponse& response,
36 blink::WebURLError& error, blink::WebData& data) OVERRIDE;
37 virtual void loadAsynchronously(
38 const blink::WebURLRequest&, blink::WebURLLoaderClient* client) OVERRIDE;
39 virtual void cancel() OVERRIDE;
40 virtual void setDefersLoading(bool defers_loading) OVERRIDE;
42 void OnReceivedResponse(URLResponsePtr response);
43 void OnReceivedError(URLResponsePtr response);
44 void OnReceivedRedirect(URLResponsePtr response);
46 void WaitToReadMore();
47 void OnResponseBodyStreamReady(MojoResult result);
49 blink::WebURLLoaderClient* client_;
51 URLLoaderPtr url_loader_;
52 ScopedDataPipeConsumerHandle response_body_stream_;
53 common::HandleWatcher handle_watcher_;
55 base::WeakPtrFactory<WebURLLoaderImpl> weak_factory_;
57 DISALLOW_COPY_AND_ASSIGN(WebURLLoaderImpl);
62 #endif // MOJO_SERVICES_HTML_VIEWER_WEBURLLOADER_IMPL_H_