| OLD | NEW |
| 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 WebKit::WebFrame; | 15 using blink::WebFrame; |
| 16 using WebKit::WebURLError; | 16 using blink::WebURLError; |
| 17 using WebKit::WebURLLoader; | 17 using blink::WebURLLoader; |
| 18 using WebKit::WebURLLoaderOptions; | 18 using blink::WebURLLoaderOptions; |
| 19 using WebKit::WebURLRequest; | 19 using blink::WebURLRequest; |
| 20 using WebKit::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 | 25 |
| 26 MediaInfoLoader::MediaInfoLoader( | 26 MediaInfoLoader::MediaInfoLoader( |
| 27 const GURL& url, | 27 const GURL& url, |
| 28 WebKit::WebMediaPlayer::CORSMode cors_mode, | 28 blink::WebMediaPlayer::CORSMode cors_mode, |
| 29 const ReadyCB& ready_cb) | 29 const ReadyCB& ready_cb) |
| 30 : loader_failed_(false), | 30 : loader_failed_(false), |
| 31 url_(url), | 31 url_(url), |
| 32 cors_mode_(cors_mode), | 32 cors_mode_(cors_mode), |
| 33 single_origin_(true), | 33 single_origin_(true), |
| 34 ready_cb_(ready_cb) {} | 34 ready_cb_(ready_cb) {} |
| 35 | 35 |
| 36 MediaInfoLoader::~MediaInfoLoader() {} | 36 MediaInfoLoader::~MediaInfoLoader() {} |
| 37 | 37 |
| 38 void MediaInfoLoader::Start(WebKit::WebFrame* frame) { | 38 void MediaInfoLoader::Start(blink::WebFrame* frame) { |
| 39 // Make sure we have not started. | 39 // Make sure we have not started. |
| 40 DCHECK(!ready_cb_.is_null()); | 40 DCHECK(!ready_cb_.is_null()); |
| 41 CHECK(frame); | 41 CHECK(frame); |
| 42 | 42 |
| 43 start_time_ = base::TimeTicks::Now(); | 43 start_time_ = base::TimeTicks::Now(); |
| 44 | 44 |
| 45 // Prepare the request. | 45 // Prepare the request. |
| 46 WebURLRequest request(url_); | 46 WebURLRequest request(url_); |
| 47 request.setTargetType(WebURLRequest::TargetIsMedia); | 47 request.setTargetType(WebURLRequest::TargetIsMedia); |
| 48 frame->setReferrerForRequest(request, WebKit::WebURL()); | 48 frame->setReferrerForRequest(request, blink::WebURL()); |
| 49 | 49 |
| 50 scoped_ptr<WebURLLoader> loader; | 50 scoped_ptr<WebURLLoader> loader; |
| 51 if (test_loader_) { | 51 if (test_loader_) { |
| 52 loader = test_loader_.Pass(); | 52 loader = test_loader_.Pass(); |
| 53 } else { | 53 } else { |
| 54 WebURLLoaderOptions options; | 54 WebURLLoaderOptions options; |
| 55 if (cors_mode_ == WebKit::WebMediaPlayer::CORSModeUnspecified) { | 55 if (cors_mode_ == blink::WebMediaPlayer::CORSModeUnspecified) { |
| 56 options.allowCredentials = true; | 56 options.allowCredentials = true; |
| 57 options.crossOriginRequestPolicy = | 57 options.crossOriginRequestPolicy = |
| 58 WebURLLoaderOptions::CrossOriginRequestPolicyAllow; | 58 WebURLLoaderOptions::CrossOriginRequestPolicyAllow; |
| 59 } else { | 59 } else { |
| 60 options.exposeAllResponseHeaders = true; | 60 options.exposeAllResponseHeaders = true; |
| 61 options.crossOriginRequestPolicy = | 61 options.crossOriginRequestPolicy = |
| 62 WebURLLoaderOptions::CrossOriginRequestPolicyUseAccessControl; | 62 WebURLLoaderOptions::CrossOriginRequestPolicyUseAccessControl; |
| 63 if (cors_mode_ == WebKit::WebMediaPlayer::CORSModeUseCredentials) | 63 if (cors_mode_ == blink::WebMediaPlayer::CORSModeUseCredentials) |
| 64 options.allowCredentials = true; | 64 options.allowCredentials = true; |
| 65 } | 65 } |
| 66 loader.reset(frame->createAssociatedURLLoader(options)); | 66 loader.reset(frame->createAssociatedURLLoader(options)); |
| 67 } | 67 } |
| 68 | 68 |
| 69 // Start the resource loading. | 69 // Start the resource loading. |
| 70 loader->loadAsynchronously(request, this); | 70 loader->loadAsynchronously(request, this); |
| 71 active_loader_.reset(new ActiveLoader(loader.Pass())); | 71 active_loader_.reset(new ActiveLoader(loader.Pass())); |
| 72 } | 72 } |
| 73 | 73 |
| 74 ///////////////////////////////////////////////////////////////////////////// | 74 ///////////////////////////////////////////////////////////////////////////// |
| 75 // WebKit::WebURLLoaderClient implementation. | 75 // blink::WebURLLoaderClient implementation. |
| 76 void MediaInfoLoader::willSendRequest( | 76 void MediaInfoLoader::willSendRequest( |
| 77 WebURLLoader* loader, | 77 WebURLLoader* loader, |
| 78 WebURLRequest& newRequest, | 78 WebURLRequest& newRequest, |
| 79 const WebURLResponse& redirectResponse) { | 79 const WebURLResponse& redirectResponse) { |
| 80 // The load may have been stopped and |ready_cb| is destroyed. | 80 // The load may have been stopped and |ready_cb| is destroyed. |
| 81 // In this case we shouldn't do anything. | 81 // In this case we shouldn't do anything. |
| 82 if (ready_cb_.is_null()) { | 82 if (ready_cb_.is_null()) { |
| 83 // Set the url in the request to an invalid value (empty url). | 83 // Set the url in the request to an invalid value (empty url). |
| 84 newRequest.setURL(WebKit::WebURL()); | 84 newRequest.setURL(blink::WebURL()); |
| 85 return; | 85 return; |
| 86 } | 86 } |
| 87 | 87 |
| 88 // Only allow |single_origin_| if we haven't seen a different origin yet. | 88 // Only allow |single_origin_| if we haven't seen a different origin yet. |
| 89 if (single_origin_) | 89 if (single_origin_) |
| 90 single_origin_ = url_.GetOrigin() == GURL(newRequest.url()).GetOrigin(); | 90 single_origin_ = url_.GetOrigin() == GURL(newRequest.url()).GetOrigin(); |
| 91 | 91 |
| 92 url_ = newRequest.url(); | 92 url_ = newRequest.url(); |
| 93 } | 93 } |
| 94 | 94 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 119 | 119 |
| 120 void MediaInfoLoader::didReceiveData( | 120 void MediaInfoLoader::didReceiveData( |
| 121 WebURLLoader* loader, | 121 WebURLLoader* loader, |
| 122 const char* data, | 122 const char* data, |
| 123 int data_length, | 123 int data_length, |
| 124 int encoded_data_length) { | 124 int encoded_data_length) { |
| 125 // Ignored. | 125 // Ignored. |
| 126 } | 126 } |
| 127 | 127 |
| 128 void MediaInfoLoader::didDownloadData( | 128 void MediaInfoLoader::didDownloadData( |
| 129 WebKit::WebURLLoader* loader, | 129 blink::WebURLLoader* loader, |
| 130 int dataLength, | 130 int dataLength, |
| 131 int encodedDataLength) { | 131 int encodedDataLength) { |
| 132 NOTIMPLEMENTED(); | 132 NOTIMPLEMENTED(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 void MediaInfoLoader::didReceiveCachedMetadata( | 135 void MediaInfoLoader::didReceiveCachedMetadata( |
| 136 WebURLLoader* loader, | 136 WebURLLoader* loader, |
| 137 const char* data, | 137 const char* data, |
| 138 int data_length) { | 138 int data_length) { |
| 139 NOTIMPLEMENTED(); | 139 NOTIMPLEMENTED(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 162 bool MediaInfoLoader::HasSingleOrigin() const { | 162 bool MediaInfoLoader::HasSingleOrigin() const { |
| 163 DCHECK(ready_cb_.is_null()) | 163 DCHECK(ready_cb_.is_null()) |
| 164 << "Must become ready before calling HasSingleOrigin()"; | 164 << "Must become ready before calling HasSingleOrigin()"; |
| 165 return single_origin_; | 165 return single_origin_; |
| 166 } | 166 } |
| 167 | 167 |
| 168 bool MediaInfoLoader::DidPassCORSAccessCheck() const { | 168 bool MediaInfoLoader::DidPassCORSAccessCheck() const { |
| 169 DCHECK(ready_cb_.is_null()) | 169 DCHECK(ready_cb_.is_null()) |
| 170 << "Must become ready before calling DidPassCORSAccessCheck()"; | 170 << "Must become ready before calling DidPassCORSAccessCheck()"; |
| 171 return !loader_failed_ && | 171 return !loader_failed_ && |
| 172 cors_mode_ != WebKit::WebMediaPlayer::CORSModeUnspecified; | 172 cors_mode_ != blink::WebMediaPlayer::CORSModeUnspecified; |
| 173 } | 173 } |
| 174 | 174 |
| 175 ///////////////////////////////////////////////////////////////////////////// | 175 ///////////////////////////////////////////////////////////////////////////// |
| 176 // Helper methods. | 176 // Helper methods. |
| 177 | 177 |
| 178 void MediaInfoLoader::DidBecomeReady(Status status) { | 178 void MediaInfoLoader::DidBecomeReady(Status status) { |
| 179 UMA_HISTOGRAM_TIMES("Media.InfoLoadDelay", | 179 UMA_HISTOGRAM_TIMES("Media.InfoLoadDelay", |
| 180 base::TimeTicks::Now() - start_time_); | 180 base::TimeTicks::Now() - start_time_); |
| 181 active_loader_.reset(); | 181 active_loader_.reset(); |
| 182 if (!ready_cb_.is_null()) | 182 if (!ready_cb_.is_null()) |
| 183 base::ResetAndReturn(&ready_cb_).Run(status); | 183 base::ResetAndReturn(&ready_cb_).Run(status); |
| 184 } | 184 } |
| 185 | 185 |
| 186 } // namespace content | 186 } // namespace content |
| OLD | NEW |