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/macros.h"
9 #include "base/memory/weak_ptr.h"
10 #include "mojo/common/handle_watcher.h"
11 #include "mojo/services/network/public/interfaces/url_loader.mojom.h"
12 #include "third_party/WebKit/public/platform/WebURLLoader.h"
13 #include "third_party/WebKit/public/platform/WebURLRequest.h"
18 // The concrete type of WebURLRequest::ExtraData.
19 class WebURLRequestExtraData
: public blink::WebURLRequest::ExtraData
{
21 WebURLRequestExtraData();
22 virtual ~WebURLRequestExtraData();
24 URLResponsePtr synthetic_response
;
27 class WebURLLoaderImpl
: public blink::WebURLLoader
{
29 explicit WebURLLoaderImpl(NetworkService
* network_service
);
32 virtual ~WebURLLoaderImpl();
34 // blink::WebURLLoader methods:
35 virtual void loadSynchronously(
36 const blink::WebURLRequest
& request
, blink::WebURLResponse
& response
,
37 blink::WebURLError
& error
, blink::WebData
& data
) override
;
38 virtual void loadAsynchronously(
39 const blink::WebURLRequest
&, blink::WebURLLoaderClient
* client
) override
;
40 virtual void cancel() override
;
41 virtual void setDefersLoading(bool defers_loading
) override
;
43 void OnReceivedResponse(URLResponsePtr response
);
44 void OnReceivedError(URLResponsePtr response
);
45 void OnReceivedRedirect(URLResponsePtr response
);
47 void WaitToReadMore();
48 void OnResponseBodyStreamReady(MojoResult result
);
50 blink::WebURLLoaderClient
* client_
;
52 URLLoaderPtr url_loader_
;
53 ScopedDataPipeConsumerHandle response_body_stream_
;
54 common::HandleWatcher handle_watcher_
;
56 base::WeakPtrFactory
<WebURLLoaderImpl
> weak_factory_
;
58 DISALLOW_COPY_AND_ASSIGN(WebURLLoaderImpl
);
63 #endif // MOJO_SERVICES_HTML_VIEWER_WEBURLLOADER_IMPL_H_