OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 "base/values.h" | |
6 #include "chrome/browser/chromeos/media/media_player.h" | |
7 #include "chrome/browser/chromeos/media/media_player_extension_api.h" | |
8 | |
9 static const char kPropertyItems[] = "items"; | |
10 static const char kPropertyPosition[] = "position"; | |
11 | |
12 bool PlayMediaplayerFunction::RunImpl() { | |
13 if (args_->GetSize() < 2) { | |
14 return false; | |
15 } | |
16 | |
17 ListValue* url_list = NULL; | |
18 if (!args_->GetList(0, &url_list)) | |
19 return false; | |
20 | |
21 int position; | |
22 if (!args_->GetInteger(1, &position)) | |
23 return false; | |
24 | |
25 MediaPlayer* player = MediaPlayer::GetInstance(); | |
26 | |
27 player->PopupMediaPlayer(); | |
28 player->ClearPlaylist(); | |
29 | |
30 size_t len = url_list->GetSize(); | |
31 for (size_t i = 0; i < len; ++i) { | |
32 std::string path; | |
33 url_list->GetString(i, &path); | |
34 player->EnqueueMediaFileUrl(GURL(path)); | |
35 } | |
36 | |
37 player->SetPlaylistPosition(position); | |
38 player->NotifyPlaylistChanged(); | |
39 | |
40 return true; | |
41 } | |
42 | |
43 static ListValue* GetPlaylistItems() { | |
44 ListValue* result = new ListValue(); | |
45 | |
46 MediaPlayer::UrlVector const& src = MediaPlayer::GetInstance()->GetPlaylist(); | |
47 | |
48 for (size_t i = 0; i < src.size(); i++) { | |
49 result->Append(new base::StringValue(src[i].spec())); | |
50 } | |
51 return result; | |
52 } | |
53 | |
54 bool GetPlaylistMediaplayerFunction::RunImpl() { | |
55 DictionaryValue* result = new DictionaryValue(); | |
56 MediaPlayer* player = MediaPlayer::GetInstance(); | |
57 | |
58 result->Set(kPropertyItems, GetPlaylistItems()); | |
59 result->SetInteger(kPropertyPosition, player->GetPlaylistPosition()); | |
60 | |
61 SetResult(result); | |
62 return true; | |
63 } | |
64 | |
65 // TODO(kaznacheev): rename the API method to adjustWindowHeight here and in | |
66 // media_player_private.json. | |
67 bool SetWindowHeightMediaplayerFunction::RunImpl() { | |
68 int height_diff; | |
69 if (!args_->GetInteger(0, &height_diff)) | |
70 return false; | |
71 MediaPlayer::GetInstance()->AdjustWindowHeight(height_diff); | |
72 return true; | |
73 } | |
74 | |
75 bool CloseWindowMediaplayerFunction::RunImpl() { | |
76 MediaPlayer::GetInstance()->CloseWindow(); | |
77 return true; | |
78 } | |
OLD | NEW |