| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/chromeos/media/media_player.h" | 5 #include "chrome/browser/chromeos/media/media_player.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 #include "content/public/browser/download_manager.h" | 39 #include "content/public/browser/download_manager.h" |
| 40 #include "content/public/browser/user_metrics.h" | 40 #include "content/public/browser/user_metrics.h" |
| 41 #include "grit/browser_resources.h" | 41 #include "grit/browser_resources.h" |
| 42 #include "grit/chromium_strings.h" | 42 #include "grit/chromium_strings.h" |
| 43 #include "grit/generated_resources.h" | 43 #include "grit/generated_resources.h" |
| 44 #include "grit/locale_settings.h" | 44 #include "grit/locale_settings.h" |
| 45 #include "net/base/escape.h" | 45 #include "net/base/escape.h" |
| 46 #include "net/base/load_flags.h" | 46 #include "net/base/load_flags.h" |
| 47 #include "net/url_request/url_request_job.h" | 47 #include "net/url_request/url_request_job.h" |
| 48 #include "ui/base/resource/resource_bundle.h" | 48 #include "ui/base/resource/resource_bundle.h" |
| 49 #include "ui/gfx/screen.h" |
| 49 | 50 |
| 50 #if defined(OS_CHROMEOS) && defined(TOOLKIT_USES_GTK) | 51 #if defined(OS_CHROMEOS) && defined(TOOLKIT_USES_GTK) |
| 51 #include "chrome/browser/chromeos/frame/panel_browser_view.h" | 52 #include "chrome/browser/chromeos/frame/panel_browser_view.h" |
| 52 #endif | 53 #endif |
| 53 | 54 |
| 54 using content::BrowserThread; | 55 using content::BrowserThread; |
| 55 using content::UserMetricsAction; | 56 using content::UserMetricsAction; |
| 56 | 57 |
| 57 static const char* kMediaPlayerAppName = "mediaplayer"; | 58 static const char* kMediaPlayerAppName = "mediaplayer"; |
| 58 static const int kPopupLeft = 0; | 59 static const int kPopupRight = 20; |
| 59 static const int kPopupTop = 0; | 60 static const int kPopupBottom = 50; |
| 60 static const int kPopupWidth = 280; | 61 static const int kPopupWidth = 280; |
| 61 | 62 |
| 62 // Set the initial height to the minimum possible height. Keep the constants | 63 // Set the initial height to the minimum possible height. Keep the constants |
| 63 // in sync with chrome/browser/resources/file_manager/css/audio_player.css. | 64 // in sync with chrome/browser/resources/file_manager/css/audio_player.css. |
| 64 // SetWindowHeight will be called soon after the popup creation with the correct | 65 // SetWindowHeight will be called soon after the popup creation with the correct |
| 65 // height which will cause a nice slide-up animation. | 66 // height which will cause a nice slide-up animation. |
| 66 // TODO(kaznacheev): Remove kTitleHeight when MediaPlayer becomes chromeless. | 67 // TODO(kaznacheev): Remove kTitleHeight when MediaPlayer becomes chromeless. |
| 67 static const int kTitleHeight = 24; | 68 static const int kTitleHeight = 24; |
| 68 static const int kTrackHeight = 58; | 69 static const int kTrackHeight = 58; |
| 69 static const int kControlsHeight = 35; | 70 static const int kControlsHeight = 35; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 84 //////////////////////////////////////////////////////////////////////////////// | 85 //////////////////////////////////////////////////////////////////////////////// |
| 85 | 86 |
| 86 MediaPlayer::~MediaPlayer() { | 87 MediaPlayer::~MediaPlayer() { |
| 87 } | 88 } |
| 88 | 89 |
| 89 // static | 90 // static |
| 90 MediaPlayer* MediaPlayer::GetInstance() { | 91 MediaPlayer* MediaPlayer::GetInstance() { |
| 91 return Singleton<MediaPlayer>::get(); | 92 return Singleton<MediaPlayer>::get(); |
| 92 } | 93 } |
| 93 | 94 |
| 94 void MediaPlayer::SetWindowHeight(int height) { | 95 void MediaPlayer::SetWindowHeight(int content_height) { |
| 95 if (mediaplayer_browser_ != NULL) { | 96 if (mediaplayer_browser_ != NULL) { |
| 96 mediaplayer_browser_->window()->SetBounds(gfx::Rect(kPopupLeft, | 97 int window_height = content_height + kTitleHeight; |
| 97 kPopupTop, | 98 gfx::Rect bounds = mediaplayer_browser_->window()->GetBounds(); |
| 98 kPopupWidth, | 99 mediaplayer_browser_->window()->SetBounds(gfx::Rect( |
| 99 height + kTitleHeight)); | 100 bounds.x(), |
| 101 std::max(0, bounds.bottom() - window_height), |
| 102 bounds.width(), |
| 103 window_height)); |
| 100 } | 104 } |
| 101 } | 105 } |
| 102 | 106 |
| 103 void MediaPlayer::CloseWindow() { | 107 void MediaPlayer::CloseWindow() { |
| 104 if (mediaplayer_browser_ != NULL) { | 108 if (mediaplayer_browser_ != NULL) { |
| 105 mediaplayer_browser_->window()->Close(); | 109 mediaplayer_browser_->window()->Close(); |
| 106 } | 110 } |
| 107 } | 111 } |
| 108 | 112 |
| 109 void MediaPlayer::ClearPlaylist() { | 113 void MediaPlayer::ClearPlaylist() { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 154 |
| 151 void MediaPlayer::PopupMediaPlayer(Browser* creator) { | 155 void MediaPlayer::PopupMediaPlayer(Browser* creator) { |
| 152 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 156 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 153 BrowserThread::PostTask( | 157 BrowserThread::PostTask( |
| 154 BrowserThread::UI, FROM_HERE, | 158 BrowserThread::UI, FROM_HERE, |
| 155 base::Bind(&MediaPlayer::PopupMediaPlayer, | 159 base::Bind(&MediaPlayer::PopupMediaPlayer, |
| 156 base::Unretained(this), // this class is a singleton. | 160 base::Unretained(this), // this class is a singleton. |
| 157 static_cast<Browser*>(NULL))); | 161 static_cast<Browser*>(NULL))); |
| 158 return; | 162 return; |
| 159 } | 163 } |
| 160 if (mediaplayer_browser_) | 164 if (mediaplayer_browser_) { // Already opened. |
| 161 return; // Already opened. | 165 mediaplayer_browser_->window()->Show(); |
| 166 return; |
| 167 } |
| 168 |
| 169 const gfx::Size screen = gfx::Screen::GetPrimaryMonitorSize(); |
| 170 const gfx::Rect bounds(screen.width() - kPopupRight - kPopupWidth, |
| 171 screen.height() - kPopupBottom - kPopupHeight, |
| 172 kPopupWidth, |
| 173 kPopupHeight); |
| 162 | 174 |
| 163 Profile* profile = BrowserList::GetLastActive()->profile(); | 175 Profile* profile = BrowserList::GetLastActive()->profile(); |
| 164 mediaplayer_browser_ = Browser::CreateForApp(Browser::TYPE_PANEL, | 176 mediaplayer_browser_ = Browser::CreateForApp(Browser::TYPE_PANEL, |
| 165 kMediaPlayerAppName, | 177 kMediaPlayerAppName, |
| 166 gfx::Rect(kPopupLeft, | 178 bounds, |
| 167 kPopupTop, | |
| 168 kPopupWidth, | |
| 169 kPopupHeight), | |
| 170 profile); | 179 profile); |
| 171 registrar_.Add(this, | 180 registrar_.Add(this, |
| 172 chrome::NOTIFICATION_BROWSER_CLOSED, | 181 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 173 content::Source<Browser>(mediaplayer_browser_)); | 182 content::Source<Browser>(mediaplayer_browser_)); |
| 174 | 183 |
| 175 #if defined(OS_CHROMEOS) && defined(TOOLKIT_USES_GTK) | 184 #if defined(OS_CHROMEOS) && defined(TOOLKIT_USES_GTK) |
| 176 // Since we are on chromeos, popups should be a PanelBrowserView, | 185 // Since we are on chromeos, popups should be a PanelBrowserView, |
| 177 // so we can just cast it. | 186 // so we can just cast it. |
| 178 if (creator) { | 187 if (creator) { |
| 179 chromeos::PanelBrowserView* creatorview = | 188 chromeos::PanelBrowserView* creatorview = |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 return file_manager_util::GetMediaPlayerUrl(); | 240 return file_manager_util::GetMediaPlayerUrl(); |
| 232 } | 241 } |
| 233 | 242 |
| 234 MediaPlayer::MediaPlayer() | 243 MediaPlayer::MediaPlayer() |
| 235 : current_position_(0), | 244 : current_position_(0), |
| 236 mediaplayer_browser_(NULL) { | 245 mediaplayer_browser_(NULL) { |
| 237 for (size_t i = 0; i < arraysize(supported_mime_type_list); ++i) { | 246 for (size_t i = 0; i < arraysize(supported_mime_type_list); ++i) { |
| 238 supported_mime_types_.insert(supported_mime_type_list[i]); | 247 supported_mime_types_.insert(supported_mime_type_list[i]); |
| 239 } | 248 } |
| 240 }; | 249 }; |
| OLD | NEW |