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 #include "chrome/browser/dom_ui/mediaplayer_ui.h" | 5 #include "chrome/browser/dom_ui/mediaplayer_ui.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 void GetPlaylistValue(ListValue& value); | 97 void GetPlaylistValue(ListValue& value); |
98 | 98 |
99 // Callback for the "playbackError" message. | 99 // Callback for the "playbackError" message. |
100 void HandlePlaybackError(const Value* value); | 100 void HandlePlaybackError(const Value* value); |
101 | 101 |
102 // Callback for the "getCurrentPlaylist" message. | 102 // Callback for the "getCurrentPlaylist" message. |
103 void HandleGetCurrentPlaylist(const Value* value); | 103 void HandleGetCurrentPlaylist(const Value* value); |
104 | 104 |
105 void HandleTogglePlaylist(const Value* value); | 105 void HandleTogglePlaylist(const Value* value); |
106 void HandleSetCurrentPlaylistOffset(const Value* value); | 106 void HandleSetCurrentPlaylistOffset(const Value* value); |
| 107 void HandleToggleFullscreen(const Value* value); |
| 108 |
107 | 109 |
108 const std::vector<GURL>& GetCurrentPlaylist(); | 110 const std::vector<GURL>& GetCurrentPlaylist(); |
109 | 111 |
110 int GetCurrentPlaylistOffset(); | 112 int GetCurrentPlaylistOffset(); |
111 void SetCurrentPlaylistOffset(int offset); | 113 void SetCurrentPlaylistOffset(int offset); |
112 // Used to set the playlist for playlist views, since the playlist is | 114 // Used to set the playlist for playlist views, since the playlist is |
113 // maintained by the mediaplayer itself. | 115 // maintained by the mediaplayer itself. |
114 void SetCurrentPlaylist(const std::vector<GURL>& playlist, int offset); | 116 void SetCurrentPlaylist(const std::vector<GURL>& playlist, int offset); |
115 | 117 |
116 private: | 118 private: |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 dom_ui_->RegisterMessageCallback("currentOffsetChanged", | 209 dom_ui_->RegisterMessageCallback("currentOffsetChanged", |
208 NewCallback(this, &MediaplayerHandler::HandleCurrentOffsetChanged)); | 210 NewCallback(this, &MediaplayerHandler::HandleCurrentOffsetChanged)); |
209 dom_ui_->RegisterMessageCallback("playbackError", | 211 dom_ui_->RegisterMessageCallback("playbackError", |
210 NewCallback(this, &MediaplayerHandler::HandlePlaybackError)); | 212 NewCallback(this, &MediaplayerHandler::HandlePlaybackError)); |
211 dom_ui_->RegisterMessageCallback("getCurrentPlaylist", | 213 dom_ui_->RegisterMessageCallback("getCurrentPlaylist", |
212 NewCallback(this, &MediaplayerHandler::HandleGetCurrentPlaylist)); | 214 NewCallback(this, &MediaplayerHandler::HandleGetCurrentPlaylist)); |
213 dom_ui_->RegisterMessageCallback("togglePlaylist", | 215 dom_ui_->RegisterMessageCallback("togglePlaylist", |
214 NewCallback(this, &MediaplayerHandler::HandleTogglePlaylist)); | 216 NewCallback(this, &MediaplayerHandler::HandleTogglePlaylist)); |
215 dom_ui_->RegisterMessageCallback("setCurrentPlaylistOffset", | 217 dom_ui_->RegisterMessageCallback("setCurrentPlaylistOffset", |
216 NewCallback(this, &MediaplayerHandler::HandleSetCurrentPlaylistOffset)); | 218 NewCallback(this, &MediaplayerHandler::HandleSetCurrentPlaylistOffset)); |
| 219 dom_ui_->RegisterMessageCallback("toggleFullscreen", |
| 220 NewCallback(this, &MediaplayerHandler::HandleToggleFullscreen)); |
217 } | 221 } |
218 | 222 |
219 void MediaplayerHandler::GetPlaylistValue(ListValue& value) { | 223 void MediaplayerHandler::GetPlaylistValue(ListValue& value) { |
220 for (unsigned int x = 0; x < currentPlaylist_.size(); x++) { | 224 for (unsigned int x = 0; x < currentPlaylist_.size(); x++) { |
221 DictionaryValue* url_value = new DictionaryValue(); | 225 DictionaryValue* url_value = new DictionaryValue(); |
222 url_value->SetString(kPropertyPath, currentPlaylist_[x].spec()); | 226 url_value->SetString(kPropertyPath, currentPlaylist_[x].spec()); |
223 value.Append(url_value); | 227 value.Append(url_value); |
224 } | 228 } |
225 } | 229 } |
226 | 230 |
(...skipping 12 matching lines...) Expand all Loading... |
239 } | 243 } |
240 | 244 |
241 const std::vector<GURL>& MediaplayerHandler::GetCurrentPlaylist() { | 245 const std::vector<GURL>& MediaplayerHandler::GetCurrentPlaylist() { |
242 return currentPlaylist_; | 246 return currentPlaylist_; |
243 } | 247 } |
244 | 248 |
245 int MediaplayerHandler::GetCurrentPlaylistOffset() { | 249 int MediaplayerHandler::GetCurrentPlaylistOffset() { |
246 return currentOffset_; | 250 return currentOffset_; |
247 } | 251 } |
248 | 252 |
| 253 void MediaplayerHandler::HandleToggleFullscreen(const Value* value) { |
| 254 MediaPlayer::Get()->ToggleFullscreen(); |
| 255 } |
| 256 |
249 void MediaplayerHandler::HandleSetCurrentPlaylistOffset(const Value* value) { | 257 void MediaplayerHandler::HandleSetCurrentPlaylistOffset(const Value* value) { |
250 ListValue results_value; | 258 ListValue results_value; |
251 DictionaryValue info_value; | 259 DictionaryValue info_value; |
252 if (value && value->GetType() == Value::TYPE_LIST) { | 260 if (value && value->GetType() == Value::TYPE_LIST) { |
253 const ListValue* list_value = static_cast<const ListValue*>(value); | 261 const ListValue* list_value = static_cast<const ListValue*>(value); |
254 std::string val; | 262 std::string val; |
255 | 263 |
256 // Get the new playlist offset; | 264 // Get the new playlist offset; |
257 if (list_value->GetString(0, &val)) { | 265 if (list_value->GetString(0, &val)) { |
258 int id = atoi(val.c_str()); | 266 int id = atoi(val.c_str()); |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 } | 466 } |
459 } | 467 } |
460 | 468 |
461 void MediaPlayer::NotifyPlaylistChanged() { | 469 void MediaPlayer::NotifyPlaylistChanged() { |
462 if (handler_ && playlist_) { | 470 if (handler_ && playlist_) { |
463 playlist_->SetCurrentPlaylist(handler_->GetCurrentPlaylist(), | 471 playlist_->SetCurrentPlaylist(handler_->GetCurrentPlaylist(), |
464 handler_->GetCurrentPlaylistOffset()); | 472 handler_->GetCurrentPlaylistOffset()); |
465 } | 473 } |
466 } | 474 } |
467 | 475 |
| 476 void MediaPlayer::ToggleFullscreen() { |
| 477 if (handler_ && mediaplayer_browser_) { |
| 478 mediaplayer_browser_->ToggleFullscreenMode(); |
| 479 } |
| 480 } |
| 481 |
468 void MediaPlayer::RemoveHandler(MediaplayerHandler* handler) { | 482 void MediaPlayer::RemoveHandler(MediaplayerHandler* handler) { |
469 if (handler == handler_) { | 483 if (handler == handler_) { |
470 handler_ = NULL; | 484 handler_ = NULL; |
471 mediaplayer_browser_ = NULL; | 485 mediaplayer_browser_ = NULL; |
472 mediaplayer_tab_ = NULL; | 486 mediaplayer_tab_ = NULL; |
473 } | 487 } |
474 } | 488 } |
475 | 489 |
476 void MediaPlayer::PopupPlaylist() { | 490 void MediaPlayer::PopupPlaylist() { |
477 playlist_browser_ = Browser::CreateForPopup(profile_); | 491 playlist_browser_ = Browser::CreateForPopup(profile_); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 new MediaplayerUIHTMLSource(is_playlist); | 589 new MediaplayerUIHTMLSource(is_playlist); |
576 | 590 |
577 // Set up the chrome://mediaplayer/ source. | 591 // Set up the chrome://mediaplayer/ source. |
578 ChromeThread::PostTask( | 592 ChromeThread::PostTask( |
579 ChromeThread::IO, FROM_HERE, | 593 ChromeThread::IO, FROM_HERE, |
580 NewRunnableMethod( | 594 NewRunnableMethod( |
581 Singleton<ChromeURLDataManager>::get(), | 595 Singleton<ChromeURLDataManager>::get(), |
582 &ChromeURLDataManager::AddDataSource, | 596 &ChromeURLDataManager::AddDataSource, |
583 make_scoped_refptr(html_source))); | 597 make_scoped_refptr(html_source))); |
584 } | 598 } |
OLD | NEW |