Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: chrome/browser/chromeos/media/media_player.cc

Issue 10917188: Make Chrome OS Audio Player survive page reload and OS restart. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed debug trace Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/browser/chromeos/extensions/file_manager_util.h" 10 #include "chrome/browser/chromeos/extensions/file_manager_util.h"
11 #include "chrome/browser/chromeos/extensions/media_player_event_router.h" 11 #include "chrome/browser/chromeos/extensions/media_player_event_router.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/profiles/profile_manager.h" 13 #include "chrome/browser/profiles/profile_manager.h"
14 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_finder.h"
15 #include "chrome/browser/ui/browser_list.h" 16 #include "chrome/browser/ui/browser_list.h"
16 #include "chrome/browser/ui/browser_tabstrip.h" 17 #include "chrome/browser/ui/browser_tabstrip.h"
17 #include "chrome/browser/ui/browser_window.h" 18 #include "chrome/browser/ui/browser_window.h"
19 #include "chrome/browser/ui/tab_contents/tab_contents.h"
20 #include "chrome/browser/ui/tabs/tab_strip_model.h"
18 #include "chrome/common/chrome_notification_types.h" 21 #include "chrome/common/chrome_notification_types.h"
19 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/user_metrics.h" 23 #include "content/public/browser/user_metrics.h"
24 #include "content/public/browser/web_contents.h"
21 #include "net/url_request/url_request_job.h" 25 #include "net/url_request/url_request_job.h"
22 #include "ui/gfx/screen.h" 26 #include "ui/gfx/screen.h"
23 27
24 using content::BrowserThread; 28 using content::BrowserThread;
25 using content::UserMetricsAction; 29 using content::UserMetricsAction;
26 30
27 static const char* kMediaPlayerAppName = "mediaplayer"; 31 static const char* kMediaPlayerAppName = "mediaplayer";
28 static const int kPopupRight = 20; 32 static const int kPopupRight = 20;
29 static const int kPopupBottom = 50; 33 static const int kPopupBottom = 80;
30 static const int kPopupWidth = 280; 34 static const int kPopupWidth = 280;
31 35
32 // Set the initial height to the minimum possible height. Keep the constants 36 // Set the initial height to the minimum possible height. Keep the constants
33 // in sync with chrome/browser/resources/file_manager/css/audio_player.css. 37 // in sync with chrome/browser/resources/file_manager/css/audio_player.css.
34 // SetWindowHeight will be called soon after the popup creation with the correct 38 // SetWindowHeight will be called soon after the popup creation with the correct
35 // height which will cause a nice slide-up animation. 39 // height which will cause a nice slide-up animation.
36 // TODO(kaznacheev): Remove kTitleHeight when MediaPlayer becomes chromeless. 40 // TODO(kaznacheev): Remove kTitleHeight when MediaPlayer becomes chromeless.
37 static const int kTitleHeight = 24; 41 static const int kTitleHeight = 24;
38 static const int kTrackHeight = 58; 42 static const int kTrackHeight = 58;
39 static const int kControlsHeight = 35; 43 static const int kControlsHeight = 35;
(...skipping 15 matching lines...) Expand all
55 59
56 MediaPlayer::~MediaPlayer() { 60 MediaPlayer::~MediaPlayer() {
57 } 61 }
58 62
59 // static 63 // static
60 MediaPlayer* MediaPlayer::GetInstance() { 64 MediaPlayer* MediaPlayer::GetInstance() {
61 return Singleton<MediaPlayer>::get(); 65 return Singleton<MediaPlayer>::get();
62 } 66 }
63 67
64 void MediaPlayer::SetWindowHeight(int content_height) { 68 void MediaPlayer::SetWindowHeight(int content_height) {
65 if (mediaplayer_browser_ != NULL) { 69 Browser* browser = GetBrowser();
70 if (browser != NULL) {
66 int window_height = content_height + kTitleHeight; 71 int window_height = content_height + kTitleHeight;
67 gfx::Rect bounds = mediaplayer_browser_->window()->GetBounds(); 72 gfx::Rect bounds = browser->window()->GetBounds();
68 mediaplayer_browser_->window()->SetBounds(gfx::Rect( 73 browser->window()->SetBounds(gfx::Rect(
69 bounds.x(), 74 bounds.x(),
70 std::max(0, bounds.bottom() - window_height), 75 std::max(0, bounds.bottom() - window_height),
71 bounds.width(), 76 bounds.width(),
72 window_height)); 77 window_height));
73 } 78 }
74 } 79 }
75 80
76 void MediaPlayer::CloseWindow() { 81 void MediaPlayer::CloseWindow() {
77 if (mediaplayer_browser_ != NULL) { 82 Browser* browser = GetBrowser();
78 mediaplayer_browser_->window()->Close(); 83 if (browser != NULL) {
84 browser->window()->Close();
79 } 85 }
80 } 86 }
81 87
82 void MediaPlayer::ClearPlaylist() { 88 void MediaPlayer::ClearPlaylist() {
83 current_playlist_.clear(); 89 current_playlist_.clear();
84 } 90 }
85 91
86 void MediaPlayer::EnqueueMediaFileUrl(const GURL& url) { 92 void MediaPlayer::EnqueueMediaFileUrl(const GURL& url) {
87 current_playlist_.push_back(url); 93 current_playlist_.push_back(url);
88 } 94 }
89 95
90 void MediaPlayer::ForcePlayMediaURL(const GURL& url) { 96 void MediaPlayer::ForcePlayMediaURL(const GURL& url) {
91 ClearPlaylist(); 97 ClearPlaylist();
92 EnqueueMediaFileUrl(url); 98 EnqueueMediaFileUrl(url);
93 SetPlaylistPosition(0); 99 SetPlaylistPosition(0);
94 NotifyPlaylistChanged(); 100 NotifyPlaylistChanged();
95 } 101 }
96 102
97 void MediaPlayer::SetPlaylistPosition(int position) { 103 void MediaPlayer::SetPlaylistPosition(int position) {
98 current_position_ = position; 104 current_position_ = position;
99 } 105 }
100 106
101 void MediaPlayer::Observe(int type,
102 const content::NotificationSource& source,
103 const content::NotificationDetails& details) {
104 DCHECK(type == chrome::NOTIFICATION_BROWSER_CLOSED);
105 registrar_.Remove(this, chrome::NOTIFICATION_BROWSER_CLOSED, source);
106
107 if (content::Source<Browser>(source).ptr() == mediaplayer_browser_)
108 mediaplayer_browser_ = NULL;
109 }
110
111 void MediaPlayer::NotifyPlaylistChanged() { 107 void MediaPlayer::NotifyPlaylistChanged() {
112 ExtensionMediaPlayerEventRouter::GetInstance()->NotifyPlaylistChanged(); 108 ExtensionMediaPlayerEventRouter::GetInstance()->NotifyPlaylistChanged();
113 } 109 }
114 110
115 void MediaPlayer::PopupMediaPlayer() { 111 void MediaPlayer::PopupMediaPlayer() {
116 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { 112 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
117 BrowserThread::PostTask( 113 BrowserThread::PostTask(
118 BrowserThread::UI, FROM_HERE, 114 BrowserThread::UI, FROM_HERE,
119 base::Bind(&MediaPlayer::PopupMediaPlayer, 115 base::Bind(&MediaPlayer::PopupMediaPlayer,
120 base::Unretained(this) /*this class is a singleton*/)); 116 base::Unretained(this) /*this class is a singleton*/));
121 return; 117 return;
122 } 118 }
123 if (mediaplayer_browser_) { // Already opened. 119
124 mediaplayer_browser_->window()->Show(); 120 Browser* browser = GetBrowser();
125 return; 121 if (!browser) {
122 const gfx::Size screen = gfx::Screen::GetPrimaryDisplay().size();
123 const gfx::Rect bounds(screen.width() - kPopupRight - kPopupWidth,
124 screen.height() - kPopupBottom - kPopupHeight,
125 kPopupWidth,
126 kPopupHeight);
127
128 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord();
129 browser = new Browser(
130 Browser::CreateParams::CreateForApp(Browser::TYPE_PANEL,
131 kMediaPlayerAppName,
132 bounds,
133 profile));
134
135 chrome::AddSelectedTabWithURL(browser, GetMediaPlayerUrl(),
136 content::PAGE_TRANSITION_LINK);
126 } 137 }
127 138 browser->window()->Show();
128 const gfx::Size screen = gfx::Screen::GetPrimaryDisplay().size();
129 const gfx::Rect bounds(screen.width() - kPopupRight - kPopupWidth,
130 screen.height() - kPopupBottom - kPopupHeight,
131 kPopupWidth,
132 kPopupHeight);
133
134 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord();
135 mediaplayer_browser_ = new Browser(
136 Browser::CreateParams::CreateForApp(Browser::TYPE_PANEL,
137 kMediaPlayerAppName,
138 bounds,
139 profile));
140 registrar_.Add(this,
141 chrome::NOTIFICATION_BROWSER_CLOSED,
142 content::Source<Browser>(mediaplayer_browser_));
143
144 chrome::AddSelectedTabWithURL(mediaplayer_browser_, GetMediaPlayerUrl(),
145 content::PAGE_TRANSITION_LINK);
146 mediaplayer_browser_->window()->Show();
147 } 139 }
148 140
149 GURL MediaPlayer::GetMediaPlayerUrl() const { 141 GURL MediaPlayer::GetMediaPlayerUrl() {
150 return file_manager_util::GetMediaPlayerUrl(); 142 return file_manager_util::GetMediaPlayerUrl();
151 } 143 }
152 144
145 Browser* MediaPlayer::GetBrowser() {
146 for (BrowserList::const_iterator browser_iterator = BrowserList::begin();
147 browser_iterator != BrowserList::end(); ++browser_iterator) {
148 Browser* browser = *browser_iterator;
149 TabStripModel* tab_strip = browser->tab_strip_model();
150 for (int idx = 0; idx < tab_strip->count(); idx++) {
151 content::WebContents* web_contents =
152 tab_strip->GetTabContentsAt(idx)->web_contents();
153 const GURL& url = web_contents->GetURL();
154 GURL base_url(url.GetOrigin().spec() + url.path().substr(1));
155 if (base_url == GetMediaPlayerUrl())
156 return browser;
157 }
158 }
159 return NULL;
160 }
161
153 MediaPlayer::MediaPlayer() 162 MediaPlayer::MediaPlayer()
154 : current_position_(0), 163 : current_position_(0) {
155 mediaplayer_browser_(NULL) {
156 }; 164 };
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/media/media_player.h ('k') | chrome/browser/resources/file_manager/js/media/audio_player.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698