Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: content/renderer/media/android/media_info_loader.cc

Issue 2399463007: AssociatedURLLoader shouldn't derive from WebURLLoader (Closed)
Patch Set: Rebase Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/media/android/media_info_loader.h" 5 #include "content/renderer/media/android/media_info_loader.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bits.h" 9 #include "base/bits.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
11 #include "base/metrics/histogram_macros.h" 11 #include "base/metrics/histogram_macros.h"
12 #include "third_party/WebKit/public/platform/WebURLError.h" 12 #include "third_party/WebKit/public/platform/WebURLError.h"
13 #include "third_party/WebKit/public/platform/WebURLLoader.h" 13 #include "third_party/WebKit/public/platform/WebURLRequest.h"
14 #include "third_party/WebKit/public/platform/WebURLResponse.h" 14 #include "third_party/WebKit/public/platform/WebURLResponse.h"
15 #include "third_party/WebKit/public/web/WebAssociatedURLLoader.h"
15 #include "third_party/WebKit/public/web/WebFrame.h" 16 #include "third_party/WebKit/public/web/WebFrame.h"
16 17
18 using blink::WebAssociatedURLLoader;
19 using blink::WebAssociatedURLLoaderOptions;
17 using blink::WebFrame; 20 using blink::WebFrame;
18 using blink::WebURLError; 21 using blink::WebURLError;
19 using blink::WebURLLoader;
20 using blink::WebURLLoaderOptions;
21 using blink::WebURLRequest; 22 using blink::WebURLRequest;
22 using blink::WebURLResponse; 23 using blink::WebURLResponse;
23 24
24 namespace content { 25 namespace content {
25 26
26 static const int kHttpOK = 200; 27 static const int kHttpOK = 200;
27 static const int kHttpPartialContentOK = 206; 28 static const int kHttpPartialContentOK = 206;
28 29
29 MediaInfoLoader::MediaInfoLoader( 30 MediaInfoLoader::MediaInfoLoader(
30 const GURL& url, 31 const GURL& url,
(...skipping 21 matching lines...) Expand all
52 // TODO(mkwst): Split this into video/audio. 53 // TODO(mkwst): Split this into video/audio.
53 request.setRequestContext(WebURLRequest::RequestContextVideo); 54 request.setRequestContext(WebURLRequest::RequestContextVideo);
54 frame->setReferrerForRequest(request, blink::WebURL()); 55 frame->setReferrerForRequest(request, blink::WebURL());
55 56
56 // Since we don't actually care about the media data at this time, use a two 57 // Since we don't actually care about the media data at this time, use a two
57 // byte range request to avoid unnecessarily downloading resources. Not all 58 // byte range request to avoid unnecessarily downloading resources. Not all
58 // servers support HEAD unfortunately, so use a range request; which is no 59 // servers support HEAD unfortunately, so use a range request; which is no
59 // worse than the previous request+cancel code. See http://crbug.com/400788 60 // worse than the previous request+cancel code. See http://crbug.com/400788
60 request.addHTTPHeaderField("Range", "bytes=0-1"); 61 request.addHTTPHeaderField("Range", "bytes=0-1");
61 62
62 std::unique_ptr<WebURLLoader> loader; 63 std::unique_ptr<WebAssociatedURLLoader> loader;
63 if (test_loader_) { 64 if (test_loader_) {
64 loader = std::move(test_loader_); 65 loader = std::move(test_loader_);
65 } else { 66 } else {
66 WebURLLoaderOptions options; 67 WebAssociatedURLLoaderOptions options;
67 if (cors_mode_ == blink::WebMediaPlayer::CORSModeUnspecified) { 68 if (cors_mode_ == blink::WebMediaPlayer::CORSModeUnspecified) {
68 options.allowCredentials = true; 69 options.allowCredentials = true;
69 options.crossOriginRequestPolicy = 70 options.crossOriginRequestPolicy =
70 WebURLLoaderOptions::CrossOriginRequestPolicyAllow; 71 WebAssociatedURLLoaderOptions::CrossOriginRequestPolicyAllow;
71 allow_stored_credentials_ = true; 72 allow_stored_credentials_ = true;
72 } else { 73 } else {
73 options.exposeAllResponseHeaders = true; 74 options.exposeAllResponseHeaders = true;
74 // The author header set is empty, no preflight should go ahead. 75 // The author header set is empty, no preflight should go ahead.
75 options.preflightPolicy = WebURLLoaderOptions::PreventPreflight; 76 options.preflightPolicy = WebAssociatedURLLoaderOptions::PreventPreflight;
76 options.crossOriginRequestPolicy = 77 options.crossOriginRequestPolicy = WebAssociatedURLLoaderOptions::
77 WebURLLoaderOptions::CrossOriginRequestPolicyUseAccessControl; 78 CrossOriginRequestPolicyUseAccessControl;
78 if (cors_mode_ == blink::WebMediaPlayer::CORSModeUseCredentials) { 79 if (cors_mode_ == blink::WebMediaPlayer::CORSModeUseCredentials) {
79 options.allowCredentials = true; 80 options.allowCredentials = true;
80 allow_stored_credentials_ = true; 81 allow_stored_credentials_ = true;
81 } 82 }
82 } 83 }
83 loader.reset(frame->createAssociatedURLLoader(options)); 84 loader.reset(frame->createAssociatedURLLoader(options));
84 } 85 }
85 86
86 // Start the resource loading. 87 // Start the resource loading.
87 loader->loadAsynchronously(request, this); 88 loader->loadAsynchronously(request, this);
88 active_loader_.reset(new media::ActiveLoader(std::move(loader))); 89 active_loader_.reset(new media::ActiveLoader(std::move(loader)));
89 } 90 }
90 91
91 ///////////////////////////////////////////////////////////////////////////// 92 /////////////////////////////////////////////////////////////////////////////
92 // blink::WebURLLoaderClient implementation. 93 // blink::WebAssociatedURLLoaderClient implementation.
93 bool MediaInfoLoader::willFollowRedirect( 94 bool MediaInfoLoader::willFollowRedirect(
94 WebURLLoader* loader, 95 const WebURLRequest& newRequest,
95 WebURLRequest& newRequest,
96 const WebURLResponse& redirectResponse) { 96 const WebURLResponse& redirectResponse) {
97 // The load may have been stopped and |ready_cb| is destroyed. 97 // The load may have been stopped and |ready_cb| is destroyed.
98 // In this case we shouldn't do anything. 98 // In this case we shouldn't do anything.
99 if (ready_cb_.is_null()) 99 if (ready_cb_.is_null())
100 return false; 100 return false;
101 101
102 // Only allow |single_origin_| if we haven't seen a different origin yet. 102 // Only allow |single_origin_| if we haven't seen a different origin yet.
103 if (single_origin_) 103 if (single_origin_)
104 single_origin_ = url_.GetOrigin() == GURL(newRequest.url()).GetOrigin(); 104 single_origin_ = url_.GetOrigin() == GURL(newRequest.url()).GetOrigin();
105 105
106 url_ = newRequest.url(); 106 url_ = newRequest.url();
107 first_party_url_ = newRequest.firstPartyForCookies(); 107 first_party_url_ = newRequest.firstPartyForCookies();
108 allow_stored_credentials_ = newRequest.allowStoredCredentials(); 108 allow_stored_credentials_ = newRequest.allowStoredCredentials();
109 109
110 return true; 110 return true;
111 } 111 }
112 112
113 void MediaInfoLoader::didSendData( 113 void MediaInfoLoader::didSendData(
114 WebURLLoader* loader,
115 unsigned long long bytes_sent, 114 unsigned long long bytes_sent,
116 unsigned long long total_bytes_to_be_sent) { 115 unsigned long long total_bytes_to_be_sent) {
117 NOTIMPLEMENTED(); 116 NOTIMPLEMENTED();
118 } 117 }
119 118
120 void MediaInfoLoader::didReceiveResponse( 119 void MediaInfoLoader::didReceiveResponse(
121 WebURLLoader* loader,
122 const WebURLResponse& response) { 120 const WebURLResponse& response) {
123 DVLOG(1) << "didReceiveResponse: HTTP/" 121 DVLOG(1) << "didReceiveResponse: HTTP/"
124 << (response.httpVersion() == WebURLResponse::HTTPVersion_0_9 122 << (response.httpVersion() == WebURLResponse::HTTPVersion_0_9
125 ? "0.9" 123 ? "0.9"
126 : response.httpVersion() == WebURLResponse::HTTPVersion_1_0 124 : response.httpVersion() == WebURLResponse::HTTPVersion_1_0
127 ? "1.0" 125 ? "1.0"
128 : response.httpVersion() == 126 : response.httpVersion() ==
129 WebURLResponse::HTTPVersion_1_1 127 WebURLResponse::HTTPVersion_1_1
130 ? "1.1" 128 ? "1.1"
131 : "Unknown") 129 : "Unknown")
132 << " " << response.httpStatusCode(); 130 << " " << response.httpStatusCode();
133 DCHECK(active_loader_.get()); 131 DCHECK(active_loader_.get());
134 if (!url_.SchemeIs(url::kHttpScheme) && !url_.SchemeIs(url::kHttpsScheme)) { 132 if (!url_.SchemeIs(url::kHttpScheme) && !url_.SchemeIs(url::kHttpsScheme)) {
135 DidBecomeReady(kOk); 133 DidBecomeReady(kOk);
136 return; 134 return;
137 } 135 }
138 if (response.httpStatusCode() == kHttpOK || 136 if (response.httpStatusCode() == kHttpOK ||
139 response.httpStatusCode() == kHttpPartialContentOK) { 137 response.httpStatusCode() == kHttpPartialContentOK) {
140 DidBecomeReady(kOk); 138 DidBecomeReady(kOk);
141 return; 139 return;
142 } 140 }
143 loader_failed_ = true; 141 loader_failed_ = true;
144 DidBecomeReady(kFailed); 142 DidBecomeReady(kFailed);
145 } 143 }
146 144
147 void MediaInfoLoader::didReceiveData(WebURLLoader* loader, 145 void MediaInfoLoader::didReceiveData(const char* data, int data_length) {
148 const char* data,
149 int data_length,
150 int encoded_data_length,
151 int encoded_body_length) {
152 // Ignored. 146 // Ignored.
153 } 147 }
154 148
155 void MediaInfoLoader::didDownloadData( 149 void MediaInfoLoader::didDownloadData(int dataLength) {
156 blink::WebURLLoader* loader,
157 int dataLength,
158 int encodedDataLength) {
159 NOTIMPLEMENTED(); 150 NOTIMPLEMENTED();
160 } 151 }
161 152
162 void MediaInfoLoader::didReceiveCachedMetadata( 153 void MediaInfoLoader::didReceiveCachedMetadata(const char* data,
163 WebURLLoader* loader, 154 int data_length) {
164 const char* data,
165 int data_length) {
166 NOTIMPLEMENTED(); 155 NOTIMPLEMENTED();
167 } 156 }
168 157
169 void MediaInfoLoader::didFinishLoading( 158 void MediaInfoLoader::didFinishLoading(double finishTime) {
170 WebURLLoader* loader,
171 double finishTime,
172 int64_t total_encoded_data_length) {
173 DCHECK(active_loader_.get()); 159 DCHECK(active_loader_.get());
174 DidBecomeReady(kOk); 160 DidBecomeReady(kOk);
175 } 161 }
176 162
177 void MediaInfoLoader::didFail( 163 void MediaInfoLoader::didFail(
178 WebURLLoader* loader,
179 const WebURLError& error) { 164 const WebURLError& error) {
180 DVLOG(1) << "didFail: reason=" << error.reason 165 DVLOG(1) << "didFail: reason=" << error.reason
181 << ", isCancellation=" << error.isCancellation 166 << ", isCancellation=" << error.isCancellation
182 << ", domain=" << error.domain.utf8().data() 167 << ", domain=" << error.domain.utf8().data()
183 << ", localizedDescription=" 168 << ", localizedDescription="
184 << error.localizedDescription.utf8().data(); 169 << error.localizedDescription.utf8().data();
185 DCHECK(active_loader_.get()); 170 DCHECK(active_loader_.get());
186 loader_failed_ = true; 171 loader_failed_ = true;
187 DidBecomeReady(kFailed); 172 DidBecomeReady(kFailed);
188 } 173 }
(...skipping 17 matching lines...) Expand all
206 void MediaInfoLoader::DidBecomeReady(Status status) { 191 void MediaInfoLoader::DidBecomeReady(Status status) {
207 UMA_HISTOGRAM_TIMES("Media.InfoLoadDelay", 192 UMA_HISTOGRAM_TIMES("Media.InfoLoadDelay",
208 base::TimeTicks::Now() - start_time_); 193 base::TimeTicks::Now() - start_time_);
209 active_loader_.reset(); 194 active_loader_.reset();
210 if (!ready_cb_.is_null()) 195 if (!ready_cb_.is_null())
211 base::ResetAndReturn(&ready_cb_).Run(status, url_, first_party_url_, 196 base::ResetAndReturn(&ready_cb_).Run(status, url_, first_party_url_,
212 allow_stored_credentials_); 197 allow_stored_credentials_);
213 } 198 }
214 199
215 } // namespace content 200 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/android/media_info_loader.h ('k') | content/renderer/media/android/media_info_loader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698