Chromium Code Reviews| Index: chrome/browser/extensions/extension_mediaplayer_private_api.cc |
| diff --git a/chrome/browser/extensions/extension_mediaplayer_private_api.cc b/chrome/browser/extensions/extension_mediaplayer_private_api.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..96a97a8be876f4446254bed75e239448144fbc33 |
| --- /dev/null |
| +++ b/chrome/browser/extensions/extension_mediaplayer_private_api.cc |
| @@ -0,0 +1,75 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/extensions/extension_mediaplayer_private_api.h" |
| + |
| +#include "base/values.h" |
| +#include "chrome/browser/ui/webui/mediaplayer_ui.h" |
| + |
| +static const char kPropertyPath[] = "path"; |
| +static const char kPropertyForce[] = "force"; |
| +static const char kPropertyItems[] = "items"; |
| +static const char kPropertyPosition[] = "position"; |
| +static const char kPropertyError[] = "error"; |
| +static const char kPropertyPendingPlaybackRequest[] = |
| + "pending_playback_request"; |
| + |
| +bool SetPlaylistPositionAndPlayMediaplayerFunction::RunImpl() { |
| + int position; |
| + CHECK(args_->GetInteger(0, &position)); |
|
zel
2011/05/24 17:54:25
I would't crash here. Just return false if GetInte
SeRya
2011/05/25 14:23:49
Done.
|
| + MediaPlayer::GetInstance()->SetPlaybackRequest(); |
| + MediaPlayer::GetInstance()->SetPlaylistPosition(position); |
| + return true; |
| +} |
| + |
| +static ListValue* GetPlaylistItems() { |
| + ListValue* result = new ListValue(); |
| + |
| + MediaPlayer::UrlVector const& src = MediaPlayer::GetInstance()->GetPlaylist(); |
| + |
| + for (size_t i = 0; i < src.size(); i++) { |
| + DictionaryValue* url_value = new DictionaryValue(); |
| + url_value->SetString(kPropertyPath, src[i].url.spec()); |
| + url_value->SetBoolean(kPropertyError, src[i].haderror); |
| + result->Append(url_value); |
| + } |
| + return result; |
| +} |
| + |
| +bool GetPlaylistMediaplayerFunction::RunImpl() { |
| + DictionaryValue* result = new DictionaryValue(); |
| + MediaPlayer* player = MediaPlayer::GetInstance(); |
| + |
| + result->Set(kPropertyItems, GetPlaylistItems()); |
| + result->SetInteger(kPropertyPosition, player->GetPlaylistPosition()); |
| + result->SetBoolean(kPropertyPendingPlaybackRequest, |
| + player->GetPendingPlayRequestAndReset()); |
| + |
| + result_.reset(result); |
| + SendResponse(true); |
| + return true; |
| +} |
| + |
| +bool PlaybackErrorMediaplayerFunction::RunImpl() { |
| + std::string url; |
| + // Get path string. |
| + if (args_->GetString(0, &url)) |
| + MediaPlayer::GetInstance()->SetPlaybackError(GURL(url)); |
| + return true; |
| +} |
| + |
| +bool TogglePlaylistPanelMediaplayerFunction::RunImpl() { |
| + MediaPlayer::GetInstance()->TogglePlaylistWindowVisible(); |
| + return true; |
| +} |
| + |
| +bool ToggleFullscreenMediaplayerFunction::RunImpl() { |
| + MediaPlayer::GetInstance()->ToggleFullscreen(); |
| + return true; |
| +} |
| + |
| +bool ShowPlaylistPanelMediaplayerFunction::RunImpl() { |
| + MediaPlayer::GetInstance()->ShowPlaylistWindow(); |
| + return true; |
| +} |