| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2013 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 #ifndef WEBKIT_RENDERER_MEDIA_MEDIA_INFO_LOADER_H_ |
| 6 #define WEBKIT_RENDERER_MEDIA_MEDIA_INFO_LOADER_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/callback.h" |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/time.h" |
| 13 #include "googleurl/src/gurl.h" |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayer.h" |
| 15 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" |
| 16 #include "webkit/renderer/media/active_loader.h" |
| 17 |
| 18 namespace WebKit { |
| 19 class WebFrame; |
| 20 class WebURLLoader; |
| 21 class WebURLRequest; |
| 22 } |
| 23 |
| 24 namespace webkit_media { |
| 25 |
| 26 // This class provides additional information about a media URL. Currently it |
| 27 // can be used to determine if a media URL has a single security origin and |
| 28 // whether the URL passes a CORS access check. |
| 29 class MediaInfoLoader : private WebKit::WebURLLoaderClient { |
| 30 public: |
| 31 // Status codes for start operations on MediaInfoLoader. |
| 32 enum Status { |
| 33 // The operation failed, which may have been due to: |
| 34 // - Page navigation |
| 35 // - Server replied 4xx/5xx |
| 36 // - The response was invalid |
| 37 // - Connection was terminated |
| 38 // |
| 39 // At this point you should delete the loader. |
| 40 kFailed, |
| 41 |
| 42 // Everything went as planned. |
| 43 kOk, |
| 44 }; |
| 45 |
| 46 // Start loading information about the given media URL. |
| 47 // |url| - URL for the media resource to be loaded. |
| 48 // |cors_mode| - HTML media element's crossorigin attribute. |
| 49 // |ready_cb| - Called when media info has finished or failed loading. |
| 50 typedef base::Callback<void(Status)> ReadyCB; |
| 51 MediaInfoLoader( |
| 52 const GURL& url, |
| 53 WebKit::WebMediaPlayer::CORSMode cors_mode, |
| 54 const ReadyCB& ready_cb); |
| 55 virtual ~MediaInfoLoader(); |
| 56 |
| 57 // Start loading media info. |
| 58 void Start(WebKit::WebFrame* frame); |
| 59 |
| 60 // Returns true if the media resource has a single origin, false otherwise. |
| 61 // Only valid to call after the loader becomes ready. |
| 62 bool HasSingleOrigin() const; |
| 63 |
| 64 // Returns true if the media resource passed a CORS access control check. |
| 65 // Only valid to call after the loader becomes ready. |
| 66 bool DidPassCORSAccessCheck() const; |
| 67 |
| 68 private: |
| 69 friend class MediaInfoLoaderTest; |
| 70 |
| 71 // WebKit::WebURLLoaderClient implementation. |
| 72 virtual void willSendRequest( |
| 73 WebKit::WebURLLoader* loader, |
| 74 WebKit::WebURLRequest& newRequest, |
| 75 const WebKit::WebURLResponse& redirectResponse); |
| 76 virtual void didSendData( |
| 77 WebKit::WebURLLoader* loader, |
| 78 unsigned long long bytesSent, |
| 79 unsigned long long totalBytesToBeSent); |
| 80 virtual void didReceiveResponse( |
| 81 WebKit::WebURLLoader* loader, |
| 82 const WebKit::WebURLResponse& response); |
| 83 virtual void didDownloadData( |
| 84 WebKit::WebURLLoader* loader, |
| 85 int data_length); |
| 86 virtual void didReceiveData( |
| 87 WebKit::WebURLLoader* loader, |
| 88 const char* data, |
| 89 int data_length, |
| 90 int encoded_data_length); |
| 91 virtual void didReceiveCachedMetadata( |
| 92 WebKit::WebURLLoader* loader, |
| 93 const char* data, int dataLength); |
| 94 virtual void didFinishLoading( |
| 95 WebKit::WebURLLoader* loader, |
| 96 double finishTime); |
| 97 virtual void didFail( |
| 98 WebKit::WebURLLoader* loader, |
| 99 const WebKit::WebURLError&); |
| 100 |
| 101 void DidBecomeReady(Status status); |
| 102 |
| 103 // Injected WebURLLoader instance for testing purposes. |
| 104 scoped_ptr<WebKit::WebURLLoader> test_loader_; |
| 105 |
| 106 // Keeps track of an active WebURLLoader and associated state. |
| 107 scoped_ptr<ActiveLoader> active_loader_; |
| 108 |
| 109 bool loader_failed_; |
| 110 GURL url_; |
| 111 WebKit::WebMediaPlayer::CORSMode cors_mode_; |
| 112 bool single_origin_; |
| 113 |
| 114 ReadyCB ready_cb_; |
| 115 base::TimeTicks start_time_; |
| 116 |
| 117 DISALLOW_COPY_AND_ASSIGN(MediaInfoLoader); |
| 118 }; |
| 119 |
| 120 } // namespace webkit_media |
| 121 |
| 122 #endif // WEBKIT_RENDERER_MEDIA_MEDIA_INFO_LOADER_H_ |
| OLD | NEW |