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

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

Issue 485023003: Use range request for CORS access check on Android. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments. Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/bits.h" 7 #include "base/bits.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "third_party/WebKit/public/platform/WebURLError.h" 10 #include "third_party/WebKit/public/platform/WebURLError.h"
11 #include "third_party/WebKit/public/platform/WebURLLoader.h" 11 #include "third_party/WebKit/public/platform/WebURLLoader.h"
12 #include "third_party/WebKit/public/platform/WebURLResponse.h" 12 #include "third_party/WebKit/public/platform/WebURLResponse.h"
13 #include "third_party/WebKit/public/web/WebFrame.h" 13 #include "third_party/WebKit/public/web/WebFrame.h"
14 14
15 using blink::WebFrame; 15 using blink::WebFrame;
16 using blink::WebURLError; 16 using blink::WebURLError;
17 using blink::WebURLLoader; 17 using blink::WebURLLoader;
18 using blink::WebURLLoaderOptions; 18 using blink::WebURLLoaderOptions;
19 using blink::WebURLRequest; 19 using blink::WebURLRequest;
20 using blink::WebURLResponse; 20 using blink::WebURLResponse;
21 21
22 namespace content { 22 namespace content {
23 23
24 static const int kHttpOK = 200; 24 static const int kHttpOK = 200;
25 static const int kHttpPartialContentOK = 206;
25 26
26 MediaInfoLoader::MediaInfoLoader( 27 MediaInfoLoader::MediaInfoLoader(
27 const GURL& url, 28 const GURL& url,
28 blink::WebMediaPlayer::CORSMode cors_mode, 29 blink::WebMediaPlayer::CORSMode cors_mode,
29 const ReadyCB& ready_cb) 30 const ReadyCB& ready_cb)
30 : loader_failed_(false), 31 : loader_failed_(false),
31 url_(url), 32 url_(url),
32 allow_stored_credentials_(false), 33 allow_stored_credentials_(false),
33 cors_mode_(cors_mode), 34 cors_mode_(cors_mode),
34 single_origin_(true), 35 single_origin_(true),
35 ready_cb_(ready_cb) {} 36 ready_cb_(ready_cb) {}
36 37
37 MediaInfoLoader::~MediaInfoLoader() {} 38 MediaInfoLoader::~MediaInfoLoader() {}
38 39
39 void MediaInfoLoader::Start(blink::WebFrame* frame) { 40 void MediaInfoLoader::Start(blink::WebFrame* frame) {
40 // Make sure we have not started. 41 // Make sure we have not started.
41 DCHECK(!ready_cb_.is_null()); 42 DCHECK(!ready_cb_.is_null());
42 CHECK(frame); 43 CHECK(frame);
43 44
44 start_time_ = base::TimeTicks::Now(); 45 start_time_ = base::TimeTicks::Now();
45 first_party_url_ = frame->document().firstPartyForCookies(); 46 first_party_url_ = frame->document().firstPartyForCookies();
46 47
47 // Prepare the request. 48 // Prepare the request.
48 WebURLRequest request(url_); 49 WebURLRequest request(url_);
49 // TODO(mkwst): Split this into video/audio. 50 // TODO(mkwst): Split this into video/audio.
50 request.setRequestContext(WebURLRequest::RequestContextVideo); 51 request.setRequestContext(WebURLRequest::RequestContextVideo);
51 frame->setReferrerForRequest(request, blink::WebURL()); 52 frame->setReferrerForRequest(request, blink::WebURL());
52 53
54 // Since we don't actually care about the media data at this time, use a two
55 // byte range request to avoid unnecessarily downloading resources. Not all
56 // servers support HEAD unfortunately, so use a range request; which is no
57 // worse than the previous request+cancel code. See http://crbug.com/400788
58 request.addHTTPHeaderField("Range", "bytes=0-1");
59
53 scoped_ptr<WebURLLoader> loader; 60 scoped_ptr<WebURLLoader> loader;
54 if (test_loader_) { 61 if (test_loader_) {
55 loader = test_loader_.Pass(); 62 loader = test_loader_.Pass();
56 } else { 63 } else {
57 WebURLLoaderOptions options; 64 WebURLLoaderOptions options;
58 if (cors_mode_ == blink::WebMediaPlayer::CORSModeUnspecified) { 65 if (cors_mode_ == blink::WebMediaPlayer::CORSModeUnspecified) {
59 options.allowCredentials = true; 66 options.allowCredentials = true;
60 options.crossOriginRequestPolicy = 67 options.crossOriginRequestPolicy =
61 WebURLLoaderOptions::CrossOriginRequestPolicyAllow; 68 WebURLLoaderOptions::CrossOriginRequestPolicyAllow;
62 allow_stored_credentials_ = true; 69 allow_stored_credentials_ = true;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 << (response.httpVersion() == WebURLResponse::HTTP_0_9 ? "0.9" : 123 << (response.httpVersion() == WebURLResponse::HTTP_0_9 ? "0.9" :
117 response.httpVersion() == WebURLResponse::HTTP_1_0 ? "1.0" : 124 response.httpVersion() == WebURLResponse::HTTP_1_0 ? "1.0" :
118 response.httpVersion() == WebURLResponse::HTTP_1_1 ? "1.1" : 125 response.httpVersion() == WebURLResponse::HTTP_1_1 ? "1.1" :
119 "Unknown") 126 "Unknown")
120 << " " << response.httpStatusCode(); 127 << " " << response.httpStatusCode();
121 DCHECK(active_loader_.get()); 128 DCHECK(active_loader_.get());
122 if (!url_.SchemeIs("http") && !url_.SchemeIs("https")) { 129 if (!url_.SchemeIs("http") && !url_.SchemeIs("https")) {
123 DidBecomeReady(kOk); 130 DidBecomeReady(kOk);
124 return; 131 return;
125 } 132 }
126 if (response.httpStatusCode() == kHttpOK) { 133 if (response.httpStatusCode() == kHttpOK ||
134 response.httpStatusCode() == kHttpPartialContentOK) {
127 DidBecomeReady(kOk); 135 DidBecomeReady(kOk);
128 return; 136 return;
129 } 137 }
130 loader_failed_ = true; 138 loader_failed_ = true;
131 DidBecomeReady(kFailed); 139 DidBecomeReady(kFailed);
132 } 140 }
133 141
134 void MediaInfoLoader::didReceiveData( 142 void MediaInfoLoader::didReceiveData(
135 WebURLLoader* loader, 143 WebURLLoader* loader,
136 const char* data, 144 const char* data,
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 void MediaInfoLoader::DidBecomeReady(Status status) { 201 void MediaInfoLoader::DidBecomeReady(Status status) {
194 UMA_HISTOGRAM_TIMES("Media.InfoLoadDelay", 202 UMA_HISTOGRAM_TIMES("Media.InfoLoadDelay",
195 base::TimeTicks::Now() - start_time_); 203 base::TimeTicks::Now() - start_time_);
196 active_loader_.reset(); 204 active_loader_.reset();
197 if (!ready_cb_.is_null()) 205 if (!ready_cb_.is_null())
198 base::ResetAndReturn(&ready_cb_).Run(status, url_, first_party_url_, 206 base::ResetAndReturn(&ready_cb_).Run(status, url_, first_party_url_,
199 allow_stored_credentials_); 207 allow_stored_credentials_);
200 } 208 }
201 209
202 } // namespace content 210 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698