OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/extensions/extension_mediaplayer_private_api.h" |
| 6 |
| 7 #include "base/values.h" |
| 8 #include "chrome/browser/chromeos/media/media_player.h" |
| 9 |
| 10 static const char kPropertyPath[] = "path"; |
| 11 static const char kPropertyForce[] = "force"; |
| 12 static const char kPropertyItems[] = "items"; |
| 13 static const char kPropertyPosition[] = "position"; |
| 14 static const char kPropertyError[] = "error"; |
| 15 static const char kPropertyPendingPlaybackRequest[] = |
| 16 "pendingPlaybackRequest"; |
| 17 |
| 18 bool PlayAtMediaplayerFunction::RunImpl() { |
| 19 int position; |
| 20 if (!args_->GetInteger(0, &position)) |
| 21 return false; |
| 22 MediaPlayer::GetInstance()->SetPlaybackRequest(); |
| 23 MediaPlayer::GetInstance()->SetPlaylistPosition(position); |
| 24 return true; |
| 25 } |
| 26 |
| 27 static ListValue* GetPlaylistItems() { |
| 28 ListValue* result = new ListValue(); |
| 29 |
| 30 MediaPlayer::UrlVector const& src = MediaPlayer::GetInstance()->GetPlaylist(); |
| 31 |
| 32 for (size_t i = 0; i < src.size(); i++) { |
| 33 DictionaryValue* url_value = new DictionaryValue(); |
| 34 url_value->SetString(kPropertyPath, src[i].url.spec()); |
| 35 url_value->SetBoolean(kPropertyError, src[i].haderror); |
| 36 result->Append(url_value); |
| 37 } |
| 38 return result; |
| 39 } |
| 40 |
| 41 bool GetPlaylistMediaplayerFunction::RunImpl() { |
| 42 bool reset_pending_playback_request; |
| 43 if (!args_->GetBoolean(0, &reset_pending_playback_request)) |
| 44 return false; |
| 45 |
| 46 DictionaryValue* result = new DictionaryValue(); |
| 47 MediaPlayer* player = MediaPlayer::GetInstance(); |
| 48 |
| 49 result->Set(kPropertyItems, GetPlaylistItems()); |
| 50 result->SetInteger(kPropertyPosition, player->GetPlaylistPosition()); |
| 51 if (reset_pending_playback_request) { |
| 52 result->SetBoolean(kPropertyPendingPlaybackRequest, |
| 53 player->GetPendingPlayRequestAndReset()); |
| 54 } |
| 55 |
| 56 result_.reset(result); |
| 57 return true; |
| 58 } |
| 59 |
| 60 bool SetPlaybackErrorMediaplayerFunction::RunImpl() { |
| 61 std::string url; |
| 62 // Get path string. |
| 63 if (args_->GetString(0, &url)) |
| 64 MediaPlayer::GetInstance()->SetPlaybackError(GURL(url)); |
| 65 return true; |
| 66 } |
| 67 |
| 68 bool TogglePlaylistPanelMediaplayerFunction::RunImpl() { |
| 69 MediaPlayer::GetInstance()->TogglePlaylistWindowVisible(); |
| 70 return true; |
| 71 } |
| 72 |
| 73 bool ToggleFullscreenMediaplayerFunction::RunImpl() { |
| 74 MediaPlayer::GetInstance()->ToggleFullscreen(); |
| 75 return true; |
| 76 } |
OLD | NEW |