OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // An extremely simple implementation of DataSource that downloads the entire | 5 // An extremely simple implementation of DataSource that downloads the entire |
6 // media resource into memory before signaling that initialization has finished. | 6 // media resource into memory before signaling that initialization has finished. |
7 // Primarily used to test <audio> and <video> with buffering/caching removed | 7 // Primarily used to test <audio> and <video> with buffering/caching removed |
8 // from the equation. | 8 // from the equation. |
9 | 9 |
10 #ifndef WEBKIT_GLUE_MEDIA_SIMPLE_DATA_SOURCE_H_ | 10 #ifndef WEBKIT_GLUE_MEDIA_SIMPLE_DATA_SOURCE_H_ |
11 #define WEBKIT_GLUE_MEDIA_SIMPLE_DATA_SOURCE_H_ | 11 #define WEBKIT_GLUE_MEDIA_SIMPLE_DATA_SOURCE_H_ |
12 | 12 |
13 #include <algorithm> | |
14 #include <string> | |
15 | |
16 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
17 #include "base/scoped_ptr.h" | 14 #include "base/scoped_ptr.h" |
18 #include "media/base/filters.h" | 15 #include "media/base/filters.h" |
19 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" | 16 #include "webkit/glue/media/media_resource_loader_bridge_factory.h" |
20 #include "third_party/WebKit/WebKit/chromium/public/WebURLLoader.h" | |
21 #include "third_party/WebKit/WebKit/chromium/public/WebURLLoaderClient.h" | |
22 #include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h" | |
23 #include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h" | |
24 #include "webkit/glue/media/web_data_source.h" | 17 #include "webkit/glue/media/web_data_source.h" |
25 | 18 |
26 class MessageLoop; | 19 class MessageLoop; |
27 class WebMediaPlayerDelegateImpl; | 20 class WebMediaPlayerDelegateImpl; |
28 | 21 |
29 namespace webkit_glue { | 22 namespace webkit_glue { |
30 | 23 |
31 class SimpleDataSource : public WebDataSource, | 24 class SimpleDataSource : public WebDataSource, |
32 public WebKit::WebURLLoaderClient { | 25 public webkit_glue::ResourceLoaderBridge::Peer { |
33 public: | 26 public: |
34 SimpleDataSource(MessageLoop* render_loop, WebKit::WebFrame* frame); | 27 SimpleDataSource( |
| 28 MessageLoop* render_loop, |
| 29 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory); |
35 virtual ~SimpleDataSource(); | 30 virtual ~SimpleDataSource(); |
36 | 31 |
37 // media::Filter implementation. | 32 // media::Filter implementation. |
38 virtual void Stop(media::FilterCallback* callback); | 33 virtual void Stop(media::FilterCallback* callback); |
39 | 34 |
40 // media::DataSource implementation. | 35 // media::DataSource implementation. |
41 virtual void Initialize(const std::string& url, | 36 virtual void Initialize(const std::string& url, |
42 media::FilterCallback* callback); | 37 media::FilterCallback* callback); |
43 virtual const media::MediaFormat& media_format(); | 38 virtual const media::MediaFormat& media_format(); |
44 virtual void Read(int64 position, size_t size, | 39 virtual void Read(int64 position, size_t size, |
45 uint8* data, ReadCallback* read_callback); | 40 uint8* data, ReadCallback* read_callback); |
46 virtual bool GetSize(int64* size_out); | 41 virtual bool GetSize(int64* size_out); |
47 virtual bool IsStreaming(); | 42 virtual bool IsStreaming(); |
48 | 43 |
49 // Used to inject a mock used for unittests. | 44 // webkit_glue::ResourceLoaderBridge::Peer implementation. |
50 virtual void SetURLLoaderForTest(WebKit::WebURLLoader* mock_loader); | 45 virtual void OnUploadProgress(uint64 position, uint64 size) {} |
51 | 46 virtual bool OnReceivedRedirect( |
52 // WebKit::WebURLLoaderClient implementations. | 47 const GURL& new_url, |
53 virtual void willSendRequest( | 48 const webkit_glue::ResourceResponseInfo& info, |
54 WebKit::WebURLLoader* loader, | 49 bool* has_new_first_party_for_cookies, |
55 WebKit::WebURLRequest& newRequest, | 50 GURL* new_first_party_for_cookies); |
56 const WebKit::WebURLResponse& redirectResponse); | 51 virtual void OnReceivedResponse( |
57 virtual void didSendData( | 52 const webkit_glue::ResourceResponseInfo& info, |
58 WebKit::WebURLLoader* loader, | 53 bool content_filtered); |
59 unsigned long long bytesSent, | 54 virtual void OnDownloadedData(int len) {} |
60 unsigned long long totalBytesToBeSent); | 55 virtual void OnReceivedData(const char* data, int len); |
61 virtual void didReceiveResponse( | 56 virtual void OnCompletedRequest(const URLRequestStatus& status, |
62 WebKit::WebURLLoader* loader, | 57 const std::string& security_info, |
63 const WebKit::WebURLResponse& response); | 58 const base::Time& completion_time); |
64 virtual void didDownloadData( | |
65 WebKit::WebURLLoader* loader, | |
66 int dataLength); | |
67 virtual void didReceiveData( | |
68 WebKit::WebURLLoader* loader, | |
69 const char* data, | |
70 int dataLength); | |
71 virtual void didReceiveCachedMetadata( | |
72 WebKit::WebURLLoader* loader, | |
73 const char* data, int dataLength); | |
74 virtual void didFinishLoading( | |
75 WebKit::WebURLLoader* loader, | |
76 double finishTime); | |
77 virtual void didFail( | |
78 WebKit::WebURLLoader* loader, | |
79 const WebKit::WebURLError&); | |
80 | 59 |
81 // webkit_glue::WebDataSource implementation. | 60 // webkit_glue::WebDataSource implementation. |
82 virtual bool HasSingleOrigin(); | 61 virtual bool HasSingleOrigin(); |
83 virtual void Abort(); | 62 virtual void Abort(); |
84 | 63 |
85 private: | 64 private: |
86 // Updates |url_| and |media_format_| with the given URL. | 65 // Updates |url_| and |media_format_| with the given URL. |
87 void SetURL(const GURL& url); | 66 void SetURL(const GURL& url); |
88 | 67 |
89 // Creates and starts the resource loading on the render thread. | 68 // Creates and starts the resource loading on the render thread. |
90 void StartTask(); | 69 void StartTask(); |
91 | 70 |
92 // Cancels and deletes the resource loading on the render thread. | 71 // Cancels and deletes the resource loading on the render thread. |
93 void CancelTask(); | 72 void CancelTask(); |
94 | 73 |
95 // Perform initialization completion tasks under a lock. | 74 // Perform initialization completion tasks under a lock. |
96 void DoneInitialization_Locked(bool success); | 75 void DoneInitialization_Locked(bool success); |
97 | 76 |
98 // Primarily used for asserting the bridge is loading on the render thread. | 77 // Primarily used for asserting the bridge is loading on the render thread. |
99 MessageLoop* render_loop_; | 78 MessageLoop* render_loop_; |
100 | 79 |
101 // A webframe for loading. | 80 // Factory to create a bridge. |
102 WebKit::WebFrame* frame_; | 81 scoped_ptr<webkit_glue::MediaResourceLoaderBridgeFactory> bridge_factory_; |
103 | 82 |
104 // Does the work of loading and sends data back to this client. | 83 // Bridge used to load the media resource. |
105 scoped_ptr<WebKit::WebURLLoader> url_loader_; | 84 scoped_ptr<webkit_glue::ResourceLoaderBridge> bridge_; |
106 | 85 |
107 media::MediaFormat media_format_; | 86 media::MediaFormat media_format_; |
108 GURL url_; | 87 GURL url_; |
109 std::string data_; | 88 std::string data_; |
110 int64 size_; | 89 int64 size_; |
111 bool single_origin_; | 90 bool single_origin_; |
112 | 91 |
113 // Simple state tracking variable. | 92 // Simple state tracking variable. |
114 enum State { | 93 enum State { |
115 UNINITIALIZED, | 94 UNINITIALIZED, |
116 INITIALIZING, | 95 INITIALIZING, |
117 INITIALIZED, | 96 INITIALIZED, |
118 STOPPED, | 97 STOPPED, |
119 }; | 98 }; |
120 State state_; | 99 State state_; |
121 | 100 |
122 // Used for accessing |state_|. | 101 // Used for accessing |state_|. |
123 Lock lock_; | 102 Lock lock_; |
124 | 103 |
125 // Filter callbacks. | 104 // Filter callbacks. |
126 scoped_ptr<media::FilterCallback> initialize_callback_; | 105 scoped_ptr<media::FilterCallback> initialize_callback_; |
127 | 106 |
128 // Used to ensure mocks for unittests are used instead of reset in Start(). | |
129 bool keep_test_loader_; | |
130 | |
131 DISALLOW_COPY_AND_ASSIGN(SimpleDataSource); | 107 DISALLOW_COPY_AND_ASSIGN(SimpleDataSource); |
132 }; | 108 }; |
133 | 109 |
134 } // namespace webkit_glue | 110 } // namespace webkit_glue |
135 | 111 |
136 #endif // WEBKIT_GLUE_MEDIA_SIMPLE_DATA_SOURCE_H_ | 112 #endif // WEBKIT_GLUE_MEDIA_SIMPLE_DATA_SOURCE_H_ |
OLD | NEW |