| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 CHROME_BROWSER_UI_WEBUI_MEDIAPLAYER_UI_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_MEDIAPLAYER_UI_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_MEDIAPLAYER_UI_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_MEDIAPLAYER_UI_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 12 #include "base/memory/singleton.h" |
| 13 #include "content/browser/webui/web_ui.h" | |
| 14 #include "content/common/notification_observer.h" | 13 #include "content/common/notification_observer.h" |
| 15 #include "content/common/notification_registrar.h" | 14 #include "content/common/notification_registrar.h" |
| 16 #include "content/common/notification_source.h" | 15 #include "content/common/notification_source.h" |
| 17 #include "content/common/notification_type.h" | 16 #include "content/common/notification_type.h" |
| 18 #include "net/base/directory_lister.h" | 17 |
| 19 #include "net/url_request/url_request.h" | 18 #include "net/url_request/url_request.h" |
| 20 | 19 |
| 21 template <typename T> struct DefaultSingletonTraits; | 20 template <typename T> struct DefaultSingletonTraits; |
| 22 | 21 |
| 23 class Browser; | 22 class Browser; |
| 24 class GURL; | 23 class GURL; |
| 25 class MediaplayerHandler; | |
| 26 class Profile; | 24 class Profile; |
| 27 | 25 |
| 28 class MediaPlayer : public NotificationObserver, | 26 class MediaPlayer : public NotificationObserver, |
| 29 public net::URLRequest::Interceptor { | 27 public net::URLRequest::Interceptor { |
| 30 public: | 28 public: |
| 29 struct MediaUrl; |
| 30 typedef std::vector<MediaUrl> UrlVector; |
| 31 |
| 31 ~MediaPlayer(); | 32 ~MediaPlayer(); |
| 32 | 33 |
| 33 // Enqueues this file into the current playlist. If the mediaplayer is | 34 // Enqueues this file into the current playlist. If the mediaplayer is |
| 34 // not currently visible, show it, and play the given url. | 35 // not currently visible, show it, and play the given url. |
| 35 void EnqueueMediaFile(Profile* profile, const FilePath& file_path, | 36 void EnqueueMediaFile(Profile* profile, const FilePath& file_path, |
| 36 Browser* creator); | 37 Browser* creator); |
| 37 | 38 |
| 38 // Enqueues this fileschema url into the current playlist. If the mediaplayer | 39 // Enqueues this fileschema url into the current playlist. If the mediaplayer |
| 39 // is not currently visible, show it, and play the given url. | 40 // is not currently visible, show it, and play the given url. |
| 40 void EnqueueMediaFileUrl(const GURL& url, Browser* creator); | 41 void EnqueueMediaFileUrl(const GURL& url, Browser* creator); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 54 | 55 |
| 55 // Force the playlist window to be shown. | 56 // Force the playlist window to be shown. |
| 56 void ShowPlaylistWindow(); | 57 void ShowPlaylistWindow(); |
| 57 | 58 |
| 58 // Toggle the mediaplayer between fullscreen and windowed. | 59 // Toggle the mediaplayer between fullscreen and windowed. |
| 59 void ToggleFullscreen(); | 60 void ToggleFullscreen(); |
| 60 | 61 |
| 61 // Force the playlist window to be closed. | 62 // Force the playlist window to be closed. |
| 62 void ClosePlaylistWindow(); | 63 void ClosePlaylistWindow(); |
| 63 | 64 |
| 64 // Sets the currently playing element to the given offset. | 65 // Sets the currently playing element to the given positions. |
| 65 void SetPlaylistOffset(int offset); | 66 void SetPlaylistPosition(int position); |
| 66 | 67 |
| 67 // Set a new playback handler to give events to, along with the | 68 // Returns current playlist. |
| 68 // tab contents of the page which holds the mediaplayer. it is expected | 69 const UrlVector& GetPlaylist() const; |
| 69 // That only one of these will exist at any given time. | |
| 70 void SetNewHandler(MediaplayerHandler* handler, | |
| 71 TabContents* contents); | |
| 72 | 70 |
| 73 // Removes the handler. | 71 // Returns current playlist position. |
| 74 void RemoveHandler(MediaplayerHandler* handler); | 72 int GetPlaylistPosition() const; |
| 75 | 73 |
| 76 // Registers a new playlist handler which receives events from the | 74 // Set flag that error occuires while playing the url. |
| 77 // mediaplayer, along with the tab contents which has the playlist in it. | 75 void SetPlaybackError(GURL const& url); |
| 78 void RegisterNewPlaylistHandler(MediaplayerHandler* handler, | |
| 79 TabContents* contents); | |
| 80 | 76 |
| 81 // Removes the playlist handler. | 77 // Notfies the mediaplayer that the playlist changed. This could be |
| 82 void RemovePlaylistHandler(MediaplayerHandler* handler); | |
| 83 | |
| 84 // Notfiys the mediaplayer that the playlist changed. This could be | |
| 85 // called from the mediaplayer itself for example. | 78 // called from the mediaplayer itself for example. |
| 86 void NotifyPlaylistChanged(); | 79 void NotifyPlaylistChanged(); |
| 87 | 80 |
| 81 // Retuen true if playback requested. Resets this flag. |
| 82 bool GetPendingPlayRequestAndReset(); |
| 83 |
| 84 // Requests starting playback of the current playlist item when the |
| 85 // mediaplayer get the playlist updated. |
| 86 void SetPlaybackRequest(); |
| 87 |
| 88 // Always returns NULL because we don't want to attempt a redirect | 88 // Always returns NULL because we don't want to attempt a redirect |
| 89 // before seeing the detected mime type of the request. | 89 // before seeing the detected mime type of the request. |
| 90 // Implementation of net::URLRequest::Interceptor. | 90 // Implementation of net::URLRequest::Interceptor. |
| 91 virtual net::URLRequestJob* MaybeIntercept(net::URLRequest* request); | 91 virtual net::URLRequestJob* MaybeIntercept(net::URLRequest* request); |
| 92 | 92 |
| 93 // Determines if the requested document can be viewed by the | 93 // Determines if the requested document can be viewed by the |
| 94 // MediaPlayer. If it can, returns a net::URLRequestJob that | 94 // MediaPlayer. If it can, returns a net::URLRequestJob that |
| 95 // redirects the browser to the view URL. | 95 // redirects the browser to the view URL. |
| 96 // Implementation of net::URLRequest::Interceptor. | 96 // Implementation of net::URLRequest::Interceptor. |
| 97 virtual net::URLRequestJob* MaybeInterceptResponse(net::URLRequest* request); | 97 virtual net::URLRequestJob* MaybeInterceptResponse(net::URLRequest* request); |
| 98 | 98 |
| 99 // Used to detect when the mediaplayer is closed. | 99 // Used to detect when the mediaplayer is closed. |
| 100 virtual void Observe(NotificationType type, | 100 virtual void Observe(NotificationType type, |
| 101 const NotificationSource& source, | 101 const NotificationSource& source, |
| 102 const NotificationDetails& details); | 102 const NotificationDetails& details); |
| 103 | 103 |
| 104 // Getter for the singleton. | 104 // Getter for the singleton. |
| 105 static MediaPlayer* GetInstance(); | 105 static MediaPlayer* GetInstance(); |
| 106 | 106 |
| 107 private: | 107 private: |
| 108 friend struct DefaultSingletonTraits<MediaPlayer>; | 108 friend struct DefaultSingletonTraits<MediaPlayer>; |
| 109 | 109 |
| 110 // The current playlist of urls. |
| 111 UrlVector current_playlist_; |
| 112 // The position into the current_playlist_ of the currently playing item. |
| 113 int current_position_; |
| 114 |
| 115 bool pending_playback_request_; |
| 116 |
| 110 MediaPlayer(); | 117 MediaPlayer(); |
| 111 | 118 |
| 119 GURL GetOriginUrl() const; |
| 120 GURL GetMediaplayerPlaylistUrl() const; |
| 121 GURL GetMediaPlayerUrl() const; |
| 122 |
| 112 // Popup the mediaplayer, this shows the browser, and sets up its | 123 // Popup the mediaplayer, this shows the browser, and sets up its |
| 113 // locations correctly. | 124 // locations correctly. |
| 114 void PopupMediaPlayer(Browser* creator); | 125 void PopupMediaPlayer(Browser* creator); |
| 115 | 126 |
| 116 // Popup the playlist. Shows the browser, sets it up to point at | 127 // Popup the playlist. Shows the browser, sets it up to point at |
| 117 // chrome://mediaplayer#playlist | 128 // chrome://mediaplayer#playlist |
| 118 void PopupPlaylist(Browser* creator); | 129 void PopupPlaylist(Browser* creator); |
| 119 | 130 |
| 120 // Registers the listeners for the close events on the browser windows. | 131 void EnqueueMediaFileUrl(const GURL& url); |
| 121 void RegisterListeners(); | |
| 122 | |
| 123 // Set when the register handler is called. When the media player is | |
| 124 // closed, this pointer is set back to NULL. | |
| 125 MediaplayerHandler* handler_; | |
| 126 | |
| 127 // Set when the register playlist handler is called. When the playlist | |
| 128 // is closed, this pointer is set back to NULL. | |
| 129 MediaplayerHandler* playlist_; | |
| 130 | 132 |
| 131 // Browser containing the playlist. Used to force closes. This is created | 133 // Browser containing the playlist. Used to force closes. This is created |
| 132 // By the PopupPlaylist call, and is NULLed out when the window is closed. | 134 // By the PopupPlaylist call, and is NULLed out when the window is closed. |
| 133 Browser* playlist_browser_; | 135 Browser* playlist_browser_; |
| 134 | 136 |
| 135 // Browser containing the Mediaplayer. Used to force closes. This is | 137 // Browser containing the Mediaplayer. Used to force closes. This is |
| 136 // created by the PopupMediaplayer call, and is NULLed out when the window | 138 // created by the PopupMediaplayer call, and is NULLed out when the window |
| 137 // is closed. | 139 // is closed. |
| 138 Browser* mediaplayer_browser_; | 140 Browser* mediaplayer_browser_; |
| 139 | 141 |
| 140 // List of URLs that were enqueued during the time that the mediaplayer | |
| 141 // had not poped up yet. This is claered out after the mediaplayer pops up. | |
| 142 std::vector<GURL> unhandled_urls_; | |
| 143 | |
| 144 // Used to register for events on the windows, like to listen for closes. | 142 // Used to register for events on the windows, like to listen for closes. |
| 145 NotificationRegistrar registrar_; | 143 NotificationRegistrar registrar_; |
| 146 | 144 |
| 147 // Tab contents of the mediaplayer. Used to listen for events | |
| 148 // which would cause the mediaplayer to be closed. These are cleared out | |
| 149 // when the mediaplayer is closed. | |
| 150 TabContents* mediaplayer_tab_; | |
| 151 | |
| 152 // Tab contents of the playlist tab. used to listen for events which would | |
| 153 // cause the mediaplayer to be closed. These are cleared out when the | |
| 154 // playlist is closed. | |
| 155 TabContents* playlist_tab_; | |
| 156 | |
| 157 // List of mimetypes that the mediaplayer should listen to. Used for | 145 // List of mimetypes that the mediaplayer should listen to. Used for |
| 158 // interceptions of url GETs. | 146 // interceptions of url GETs. |
| 159 std::set<std::string> supported_mime_types_; | 147 std::set<std::string> supported_mime_types_; |
| 160 DISALLOW_COPY_AND_ASSIGN(MediaPlayer); | 148 DISALLOW_COPY_AND_ASSIGN(MediaPlayer); |
| 161 }; | 149 }; |
| 162 | 150 |
| 163 class MediaplayerUI : public WebUI { | 151 struct MediaPlayer::MediaUrl { |
| 164 public: | 152 MediaUrl() {} |
| 165 explicit MediaplayerUI(TabContents* contents); | 153 explicit MediaUrl(const GURL& newurl) |
| 166 | 154 : url(newurl), |
| 167 private: | 155 haderror(false) {} |
| 168 DISALLOW_COPY_AND_ASSIGN(MediaplayerUI); | 156 GURL url; |
| 157 bool haderror; |
| 169 }; | 158 }; |
| 170 | 159 |
| 171 #endif // CHROME_BROWSER_UI_WEBUI_MEDIAPLAYER_UI_H_ | 160 #endif // CHROME_BROWSER_UI_WEBUI_MEDIAPLAYER_UI_H_ |
| OLD | NEW |