| 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 #ifndef CONTENT_RENDERER_MEDIA_ANDROID_MEDIA_INFO_LOADER_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_ANDROID_MEDIA_INFO_LOADER_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_ANDROID_MEDIA_INFO_LOADER_H_ | 6 #define CONTENT_RENDERER_MEDIA_ANDROID_MEDIA_INFO_LOADER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
| 17 #include "media/blink/active_loader.h" | 17 #include "media/blink/active_loader.h" |
| 18 #include "third_party/WebKit/public/platform/WebMediaPlayer.h" | 18 #include "third_party/WebKit/public/platform/WebMediaPlayer.h" |
| 19 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" | 19 #include "third_party/WebKit/public/web/WebAssociatedURLLoaderClient.h" |
| 20 #include "third_party/WebKit/public/web/WebDocument.h" | 20 #include "third_party/WebKit/public/web/WebDocument.h" |
| 21 #include "url/gurl.h" | 21 #include "url/gurl.h" |
| 22 | 22 |
| 23 namespace blink { | 23 namespace blink { |
| 24 class WebAssociatedURLLoader; |
| 24 class WebFrame; | 25 class WebFrame; |
| 25 class WebURLLoader; | |
| 26 class WebURLRequest; | 26 class WebURLRequest; |
| 27 } | 27 } |
| 28 | 28 |
| 29 namespace content { | 29 namespace content { |
| 30 | 30 |
| 31 // This class provides additional information about a media URL. Currently it | 31 // This class provides additional information about a media URL. Currently it |
| 32 // can be used to determine if a media URL has a single security origin and | 32 // can be used to determine if a media URL has a single security origin and |
| 33 // whether the URL passes a CORS access check. | 33 // whether the URL passes a CORS access check. |
| 34 class CONTENT_EXPORT MediaInfoLoader : private blink::WebURLLoaderClient { | 34 class CONTENT_EXPORT MediaInfoLoader |
| 35 : private blink::WebAssociatedURLLoaderClient { |
| 35 public: | 36 public: |
| 36 // Status codes for start operations on MediaInfoLoader. | 37 // Status codes for start operations on MediaInfoLoader. |
| 37 enum Status { | 38 enum Status { |
| 38 // The operation failed, which may have been due to: | 39 // The operation failed, which may have been due to: |
| 39 // - Page navigation | 40 // - Page navigation |
| 40 // - Server replied 4xx/5xx | 41 // - Server replied 4xx/5xx |
| 41 // - The response was invalid | 42 // - The response was invalid |
| 42 // - Connection was terminated | 43 // - Connection was terminated |
| 43 // | 44 // |
| 44 // At this point you should delete the loader. | 45 // At this point you should delete the loader. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 71 // Only valid to call after the loader becomes ready. | 72 // Only valid to call after the loader becomes ready. |
| 72 bool HasSingleOrigin() const; | 73 bool HasSingleOrigin() const; |
| 73 | 74 |
| 74 // Returns true if the media resource passed a CORS access control check. | 75 // Returns true if the media resource passed a CORS access control check. |
| 75 // Only valid to call after the loader becomes ready. | 76 // Only valid to call after the loader becomes ready. |
| 76 bool DidPassCORSAccessCheck() const; | 77 bool DidPassCORSAccessCheck() const; |
| 77 | 78 |
| 78 private: | 79 private: |
| 79 friend class MediaInfoLoaderTest; | 80 friend class MediaInfoLoaderTest; |
| 80 | 81 |
| 81 // blink::WebURLLoaderClient implementation. | 82 // blink::WebAssociatedURLLoaderClient implementation. |
| 82 bool willFollowRedirect( | 83 bool willFollowRedirect( |
| 83 blink::WebURLLoader* loader, | 84 const blink::WebURLRequest& newRequest, |
| 84 blink::WebURLRequest& newRequest, | |
| 85 const blink::WebURLResponse& redirectResponse) override; | 85 const blink::WebURLResponse& redirectResponse) override; |
| 86 void didSendData(blink::WebURLLoader* loader, | 86 void didSendData(unsigned long long bytesSent, |
| 87 unsigned long long bytesSent, | |
| 88 unsigned long long totalBytesToBeSent) override; | 87 unsigned long long totalBytesToBeSent) override; |
| 89 void didReceiveResponse(blink::WebURLLoader* loader, | 88 void didReceiveResponse(const blink::WebURLResponse& response) override; |
| 90 const blink::WebURLResponse& response) override; | 89 void didDownloadData(int data_length) override; |
| 91 void didDownloadData(blink::WebURLLoader* loader, | 90 void didReceiveData(const char* data, int data_length) override; |
| 92 int data_length, | 91 void didReceiveCachedMetadata(const char* data, int dataLength) override; |
| 93 int encodedDataLength) override; | 92 void didFinishLoading(double finishTime) override; |
| 94 void didReceiveData(blink::WebURLLoader* loader, | 93 void didFail(const blink::WebURLError&) override; |
| 95 const char* data, | |
| 96 int data_length, | |
| 97 int encoded_data_length, | |
| 98 int encoded_body_length) override; | |
| 99 void didReceiveCachedMetadata(blink::WebURLLoader* loader, | |
| 100 const char* data, | |
| 101 int dataLength) override; | |
| 102 void didFinishLoading(blink::WebURLLoader* loader, | |
| 103 double finishTime, | |
| 104 int64_t total_encoded_data_length) override; | |
| 105 void didFail(blink::WebURLLoader* loader, const blink::WebURLError&) override; | |
| 106 | 94 |
| 107 void DidBecomeReady(Status status); | 95 void DidBecomeReady(Status status); |
| 108 | 96 |
| 109 // Injected WebURLLoader instance for testing purposes. | 97 // Injected WebAssociatedURLLoader instance for testing purposes. |
| 110 std::unique_ptr<blink::WebURLLoader> test_loader_; | 98 std::unique_ptr<blink::WebAssociatedURLLoader> test_loader_; |
| 111 | 99 |
| 112 // Keeps track of an active WebURLLoader and associated state. | 100 // Keeps track of an active WebAssociatedURLLoader and associated state. |
| 113 std::unique_ptr<media::ActiveLoader> active_loader_; | 101 std::unique_ptr<media::ActiveLoader> active_loader_; |
| 114 | 102 |
| 115 bool loader_failed_; | 103 bool loader_failed_; |
| 116 GURL url_; | 104 GURL url_; |
| 117 GURL first_party_url_; | 105 GURL first_party_url_; |
| 118 bool allow_stored_credentials_; | 106 bool allow_stored_credentials_; |
| 119 blink::WebMediaPlayer::CORSMode cors_mode_; | 107 blink::WebMediaPlayer::CORSMode cors_mode_; |
| 120 bool single_origin_; | 108 bool single_origin_; |
| 121 | 109 |
| 122 ReadyCB ready_cb_; | 110 ReadyCB ready_cb_; |
| 123 base::TimeTicks start_time_; | 111 base::TimeTicks start_time_; |
| 124 | 112 |
| 125 DISALLOW_COPY_AND_ASSIGN(MediaInfoLoader); | 113 DISALLOW_COPY_AND_ASSIGN(MediaInfoLoader); |
| 126 }; | 114 }; |
| 127 | 115 |
| 128 } // namespace content | 116 } // namespace content |
| 129 | 117 |
| 130 #endif // CONTENT_RENDERER_MEDIA_ANDROID_MEDIA_INFO_LOADER_H_ | 118 #endif // CONTENT_RENDERER_MEDIA_ANDROID_MEDIA_INFO_LOADER_H_ |
| OLD | NEW |