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. 4 5 #ifndef MOJO_EXAMPLE_HTML_VIEWER_WEBURLLOADER_IMPL_H_ 6 #define MOJO_EXAMPLE_HTML_VIEWER_WEBURLLOADER_IMPL_H_ 7 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 13 namespace mojo { 14 class NetworkService; 15 16 namespace examples { 17 18 class WebURLLoaderImpl : public blink::WebURLLoader, 19 public URLLoaderClient { 20 public: 21 explicit WebURLLoaderImpl(NetworkService* network_service); 22 23 private: 24 virtual ~WebURLLoaderImpl(); 25 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; 34 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; 42 43 void ReadMore(); 44 void WaitToReadMore(); 45 void OnResponseBodyStreamReady(MojoResult result); 46 47 URLLoaderPtr url_loader_; 48 blink::WebURLLoaderClient* client_; 49 ScopedDataPipeConsumerHandle response_body_stream_; 50 common::HandleWatcher handle_watcher_; 51 52 base::WeakPtrFactory<WebURLLoaderImpl> weak_factory_; 53 54 DISALLOW_COPY_AND_ASSIGN(WebURLLoaderImpl); 55 }; 56 57 } // namespace examples 58 } // namespace mojo 59 60 #endif // MOJO_EXAMPLE_HTML_VIEWER_WEBURLLOADER_IMPL_H_ 61