OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 #include "content/renderer/fetchers/web_url_loader_client_impl.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "third_party/WebKit/public/platform/WebURLError.h" | |
9 #include "third_party/WebKit/public/platform/WebURLLoader.h" | |
10 #include "third_party/WebKit/public/platform/WebURLResponse.h" | |
11 | |
12 namespace content { | |
13 | |
14 WebURLLoaderClientImpl::WebURLLoaderClientImpl() | |
15 : completed_(false) | |
16 , status_(LOADING) { | |
17 } | |
18 | |
19 WebURLLoaderClientImpl::~WebURLLoaderClientImpl() { | |
20 } | |
21 | |
22 void WebURLLoaderClientImpl::didReceiveResponse( | |
23 blink::WebURLLoader* loader, const blink::WebURLResponse& response) { | |
24 DCHECK(!completed_); | |
25 response_ = response; | |
26 } | |
27 | |
28 void WebURLLoaderClientImpl::didReceiveData(blink::WebURLLoader* loader, | |
29 const char* data, | |
30 int data_length, | |
31 int encoded_data_length, | |
32 int encoded_body_length) { | |
33 // The AssociatedURLLoader will continue after a load failure. | |
34 // For example, for an Access Control error. | |
35 if (completed_) | |
36 return; | |
37 DCHECK(data_length > 0); | |
38 | |
39 data_.append(data, data_length); | |
40 } | |
41 | |
42 void WebURLLoaderClientImpl::didReceiveCachedMetadata( | |
43 blink::WebURLLoader* loader, | |
44 const char* data, | |
45 int data_length) { | |
46 DCHECK(!completed_); | |
47 DCHECK(data_length > 0); | |
48 | |
49 metadata_.assign(data, data_length); | |
50 } | |
51 | |
52 void WebURLLoaderClientImpl::didFinishLoading( | |
53 blink::WebURLLoader* loader, | |
54 double finishTime, | |
55 int64_t total_encoded_data_length) { | |
56 // The AssociatedURLLoader will continue after a load failure. | |
57 // For example, for an Access Control error. | |
58 if (completed_) | |
59 return; | |
60 OnLoadCompleteInternal(LOAD_SUCCEEDED); | |
61 } | |
62 | |
63 void WebURLLoaderClientImpl::didFail(blink::WebURLLoader* loader, | |
64 const blink::WebURLError& error) { | |
65 OnLoadCompleteInternal(LOAD_FAILED); | |
66 } | |
67 | |
68 void WebURLLoaderClientImpl::Cancel() { | |
69 OnLoadCompleteInternal(LOAD_FAILED); | |
70 } | |
71 | |
72 void WebURLLoaderClientImpl::OnLoadCompleteInternal(LoadStatus status) { | |
73 DCHECK(!completed_); | |
74 DCHECK(status_ == LOADING); | |
75 | |
76 completed_ = true; | |
77 status_ = status; | |
78 | |
79 OnLoadComplete(); | |
80 } | |
81 | |
82 } // namespace content | |
OLD | NEW |