| 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/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 BrowserThread::IO, FROM_HERE, | 213 BrowserThread::IO, FROM_HERE, |
| 214 NewRunnableMethod( | 214 NewRunnableMethod( |
| 215 ChromeURLDataManager::GetInstance(), | 215 ChromeURLDataManager::GetInstance(), |
| 216 &ChromeURLDataManager::AddDataSource, | 216 &ChromeURLDataManager::AddDataSource, |
| 217 make_scoped_refptr(new DOMUIFavIconSource(dom_ui->GetProfile())))); | 217 make_scoped_refptr(new DOMUIFavIconSource(dom_ui->GetProfile())))); |
| 218 | 218 |
| 219 return DOMMessageHandler::Attach(dom_ui); | 219 return DOMMessageHandler::Attach(dom_ui); |
| 220 } | 220 } |
| 221 | 221 |
| 222 void MediaplayerHandler::Init(bool is_playlist, TabContents* contents) { | 222 void MediaplayerHandler::Init(bool is_playlist, TabContents* contents) { |
| 223 MediaPlayer* player = MediaPlayer::Get(); | 223 MediaPlayer* player = MediaPlayer::GetInstance(); |
| 224 if (!is_playlist) { | 224 if (!is_playlist) { |
| 225 player->SetNewHandler(this, contents); | 225 player->SetNewHandler(this, contents); |
| 226 } else { | 226 } else { |
| 227 player->RegisterNewPlaylistHandler(this, contents); | 227 player->RegisterNewPlaylistHandler(this, contents); |
| 228 } | 228 } |
| 229 } | 229 } |
| 230 | 230 |
| 231 void MediaplayerHandler::RegisterMessages() { | 231 void MediaplayerHandler::RegisterMessages() { |
| 232 dom_ui_->RegisterMessageCallback("currentOffsetChanged", | 232 dom_ui_->RegisterMessageCallback("currentOffsetChanged", |
| 233 NewCallback(this, &MediaplayerHandler::HandleCurrentOffsetChanged)); | 233 NewCallback(this, &MediaplayerHandler::HandleCurrentOffsetChanged)); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 251 url_value->SetString(kPropertyPath, current_playlist_[x].url.spec()); | 251 url_value->SetString(kPropertyPath, current_playlist_[x].url.spec()); |
| 252 url_value->SetBoolean(kPropertyError, current_playlist_[x].haderror); | 252 url_value->SetBoolean(kPropertyError, current_playlist_[x].haderror); |
| 253 urls.Append(url_value); | 253 urls.Append(url_value); |
| 254 } | 254 } |
| 255 } | 255 } |
| 256 | 256 |
| 257 void MediaplayerHandler::PlaybackMediaFile(const GURL& url) { | 257 void MediaplayerHandler::PlaybackMediaFile(const GURL& url) { |
| 258 current_playlist_.clear(); | 258 current_playlist_.clear(); |
| 259 current_playlist_.push_back(MediaplayerHandler::MediaUrl(url)); | 259 current_playlist_.push_back(MediaplayerHandler::MediaUrl(url)); |
| 260 FirePlaylistChanged(url.spec(), true, 0); | 260 FirePlaylistChanged(url.spec(), true, 0); |
| 261 MediaPlayer::Get()->NotifyPlaylistChanged(); | 261 MediaPlayer::GetInstance()->NotifyPlaylistChanged(); |
| 262 } | 262 } |
| 263 | 263 |
| 264 const MediaplayerHandler::UrlVector& MediaplayerHandler::GetCurrentPlaylist() { | 264 const MediaplayerHandler::UrlVector& MediaplayerHandler::GetCurrentPlaylist() { |
| 265 return current_playlist_; | 265 return current_playlist_; |
| 266 } | 266 } |
| 267 | 267 |
| 268 int MediaplayerHandler::GetCurrentPlaylistOffset() { | 268 int MediaplayerHandler::GetCurrentPlaylistOffset() { |
| 269 return current_offset_; | 269 return current_offset_; |
| 270 } | 270 } |
| 271 | 271 |
| 272 void MediaplayerHandler::HandleToggleFullscreen(const ListValue* args) { | 272 void MediaplayerHandler::HandleToggleFullscreen(const ListValue* args) { |
| 273 MediaPlayer::Get()->ToggleFullscreen(); | 273 MediaPlayer::GetInstance()->ToggleFullscreen(); |
| 274 } | 274 } |
| 275 | 275 |
| 276 void MediaplayerHandler::HandleSetCurrentPlaylistOffset(const ListValue* args) { | 276 void MediaplayerHandler::HandleSetCurrentPlaylistOffset(const ListValue* args) { |
| 277 int id; | 277 int id; |
| 278 CHECK(ExtractIntegerValue(args, &id)); | 278 CHECK(ExtractIntegerValue(args, &id)); |
| 279 MediaPlayer::Get()->SetPlaylistOffset(id); | 279 MediaPlayer::GetInstance()->SetPlaylistOffset(id); |
| 280 } | 280 } |
| 281 | 281 |
| 282 void MediaplayerHandler::FirePlaylistChanged(const std::string& path, | 282 void MediaplayerHandler::FirePlaylistChanged(const std::string& path, |
| 283 bool force, | 283 bool force, |
| 284 int offset) { | 284 int offset) { |
| 285 DictionaryValue info_value; | 285 DictionaryValue info_value; |
| 286 ListValue urls; | 286 ListValue urls; |
| 287 GetPlaylistValue(urls); | 287 GetPlaylistValue(urls); |
| 288 info_value.SetString(kPropertyPath, path); | 288 info_value.SetString(kPropertyPath, path); |
| 289 info_value.SetBoolean(kPropertyForce, force); | 289 info_value.SetBoolean(kPropertyForce, force); |
| 290 info_value.SetInteger(kPropertyOffset, offset); | 290 info_value.SetInteger(kPropertyOffset, offset); |
| 291 dom_ui_->CallJavascriptFunction(L"playlistChanged", info_value, urls); | 291 dom_ui_->CallJavascriptFunction(L"playlistChanged", info_value, urls); |
| 292 } | 292 } |
| 293 | 293 |
| 294 void MediaplayerHandler::SetCurrentPlaylistOffset(int offset) { | 294 void MediaplayerHandler::SetCurrentPlaylistOffset(int offset) { |
| 295 current_offset_ = offset; | 295 current_offset_ = offset; |
| 296 FirePlaylistChanged(std::string(), true, current_offset_); | 296 FirePlaylistChanged(std::string(), true, current_offset_); |
| 297 } | 297 } |
| 298 | 298 |
| 299 void MediaplayerHandler::SetCurrentPlaylist( | 299 void MediaplayerHandler::SetCurrentPlaylist( |
| 300 const MediaplayerHandler::UrlVector& playlist, int offset) { | 300 const MediaplayerHandler::UrlVector& playlist, int offset) { |
| 301 current_playlist_ = playlist; | 301 current_playlist_ = playlist; |
| 302 current_offset_ = offset; | 302 current_offset_ = offset; |
| 303 FirePlaylistChanged(std::string(), false, current_offset_); | 303 FirePlaylistChanged(std::string(), false, current_offset_); |
| 304 } | 304 } |
| 305 | 305 |
| 306 void MediaplayerHandler::EnqueueMediaFile(const GURL& url) { | 306 void MediaplayerHandler::EnqueueMediaFile(const GURL& url) { |
| 307 current_playlist_.push_back(MediaplayerHandler::MediaUrl(url)); | 307 current_playlist_.push_back(MediaplayerHandler::MediaUrl(url)); |
| 308 FirePlaylistChanged(url.spec(), false, current_offset_); | 308 FirePlaylistChanged(url.spec(), false, current_offset_); |
| 309 MediaPlayer::Get()->NotifyPlaylistChanged(); | 309 MediaPlayer::GetInstance()->NotifyPlaylistChanged(); |
| 310 } | 310 } |
| 311 | 311 |
| 312 void MediaplayerHandler::HandleCurrentOffsetChanged(const ListValue* args) { | 312 void MediaplayerHandler::HandleCurrentOffsetChanged(const ListValue* args) { |
| 313 CHECK(ExtractIntegerValue(args, ¤t_offset_)); | 313 CHECK(ExtractIntegerValue(args, ¤t_offset_)); |
| 314 MediaPlayer::Get()->NotifyPlaylistChanged(); | 314 MediaPlayer::GetInstance()->NotifyPlaylistChanged(); |
| 315 } | 315 } |
| 316 | 316 |
| 317 void MediaplayerHandler::HandlePlaybackError(const ListValue* args) { | 317 void MediaplayerHandler::HandlePlaybackError(const ListValue* args) { |
| 318 std::string error; | 318 std::string error; |
| 319 std::string url; | 319 std::string url; |
| 320 // Get path string. | 320 // Get path string. |
| 321 if (args->GetString(0, &error)) | 321 if (args->GetString(0, &error)) |
| 322 LOG(ERROR) << "Playback error" << error; | 322 LOG(ERROR) << "Playback error" << error; |
| 323 if (args->GetString(1, &url)) { | 323 if (args->GetString(1, &url)) { |
| 324 for (size_t x = 0; x < current_playlist_.size(); x++) { | 324 for (size_t x = 0; x < current_playlist_.size(); x++) { |
| 325 if (current_playlist_[x].url == GURL(url)) { | 325 if (current_playlist_[x].url == GURL(url)) { |
| 326 current_playlist_[x].haderror = true; | 326 current_playlist_[x].haderror = true; |
| 327 } | 327 } |
| 328 } | 328 } |
| 329 FirePlaylistChanged(std::string(), false, current_offset_); | 329 FirePlaylistChanged(std::string(), false, current_offset_); |
| 330 } | 330 } |
| 331 } | 331 } |
| 332 | 332 |
| 333 void MediaplayerHandler::HandleGetCurrentPlaylist(const ListValue* args) { | 333 void MediaplayerHandler::HandleGetCurrentPlaylist(const ListValue* args) { |
| 334 FirePlaylistChanged(std::string(), false, current_offset_); | 334 FirePlaylistChanged(std::string(), false, current_offset_); |
| 335 } | 335 } |
| 336 | 336 |
| 337 void MediaplayerHandler::HandleTogglePlaylist(const ListValue* args) { | 337 void MediaplayerHandler::HandleTogglePlaylist(const ListValue* args) { |
| 338 MediaPlayer::Get()->TogglePlaylistWindowVisible(); | 338 MediaPlayer::GetInstance()->TogglePlaylistWindowVisible(); |
| 339 } | 339 } |
| 340 | 340 |
| 341 void MediaplayerHandler::HandleShowPlaylist(const ListValue* args) { | 341 void MediaplayerHandler::HandleShowPlaylist(const ListValue* args) { |
| 342 MediaPlayer::Get()->ShowPlaylistWindow(); | 342 MediaPlayer::GetInstance()->ShowPlaylistWindow(); |
| 343 } | 343 } |
| 344 | 344 |
| 345 //////////////////////////////////////////////////////////////////////////////// | 345 //////////////////////////////////////////////////////////////////////////////// |
| 346 // | 346 // |
| 347 // Mediaplayer | 347 // Mediaplayer |
| 348 // | 348 // |
| 349 //////////////////////////////////////////////////////////////////////////////// | 349 //////////////////////////////////////////////////////////////////////////////// |
| 350 | 350 |
| 351 // Allows InvokeLater without adding refcounting. This class is a Singleton and | 351 // Allows InvokeLater without adding refcounting. This class is a Singleton and |
| 352 // won't be deleted until it's last InvokeLater is run. | 352 // won't be deleted until it's last InvokeLater is run. |
| 353 DISABLE_RUNNABLE_METHOD_REFCOUNT(MediaPlayer); | 353 DISABLE_RUNNABLE_METHOD_REFCOUNT(MediaPlayer); |
| 354 | 354 |
| 355 MediaPlayer::~MediaPlayer() { | 355 MediaPlayer::~MediaPlayer() { |
| 356 } | 356 } |
| 357 | 357 |
| 358 // static | 358 // static |
| 359 MediaPlayer* MediaPlayer::Get() { | 359 MediaPlayer* MediaPlayer::GetInstance() { |
| 360 return Singleton<MediaPlayer>::get(); | 360 return Singleton<MediaPlayer>::get(); |
| 361 } | 361 } |
| 362 | 362 |
| 363 void MediaPlayer::EnqueueMediaURL(const GURL& url, Browser* creator) { | 363 void MediaPlayer::EnqueueMediaURL(const GURL& url, Browser* creator) { |
| 364 if (!Enabled()) { | 364 if (!Enabled()) { |
| 365 return; | 365 return; |
| 366 } | 366 } |
| 367 if (handler_ == NULL) { | 367 if (handler_ == NULL) { |
| 368 unhandled_urls_.push_back(url); | 368 unhandled_urls_.push_back(url); |
| 369 PopupMediaPlayer(creator); | 369 PopupMediaPlayer(creator); |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 new MediaplayerUIHTMLSource(is_playlist); | 612 new MediaplayerUIHTMLSource(is_playlist); |
| 613 | 613 |
| 614 // Set up the chrome://mediaplayer/ source. | 614 // Set up the chrome://mediaplayer/ source. |
| 615 BrowserThread::PostTask( | 615 BrowserThread::PostTask( |
| 616 BrowserThread::IO, FROM_HERE, | 616 BrowserThread::IO, FROM_HERE, |
| 617 NewRunnableMethod( | 617 NewRunnableMethod( |
| 618 ChromeURLDataManager::GetInstance(), | 618 ChromeURLDataManager::GetInstance(), |
| 619 &ChromeURLDataManager::AddDataSource, | 619 &ChromeURLDataManager::AddDataSource, |
| 620 make_scoped_refptr(html_source))); | 620 make_scoped_refptr(html_source))); |
| 621 } | 621 } |
| OLD | NEW |