| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/browser/media/android/browser_media_player_manager.h" | 5 #include "content/browser/media/android/browser_media_player_manager.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "content/browser/android/content_view_core_impl.h" | 8 #include "content/browser/android/content_view_core_impl.h" |
| 9 #include "content/browser/media/android/browser_demuxer_android.h" | 9 #include "content/browser/media/android/browser_demuxer_android.h" |
| 10 #include "content/browser/media/android/media_resource_getter_impl.h" | 10 #include "content/browser/media/android/media_resource_getter_impl.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 } | 44 } |
| 45 | 45 |
| 46 // static | 46 // static |
| 47 BrowserMediaPlayerManager* BrowserMediaPlayerManager::Create( | 47 BrowserMediaPlayerManager* BrowserMediaPlayerManager::Create( |
| 48 RenderViewHost* rvh) { | 48 RenderViewHost* rvh) { |
| 49 if (g_factory) | 49 if (g_factory) |
| 50 return g_factory(rvh); | 50 return g_factory(rvh); |
| 51 return new BrowserMediaPlayerManager(rvh); | 51 return new BrowserMediaPlayerManager(rvh); |
| 52 } | 52 } |
| 53 | 53 |
| 54 ContentViewCoreImpl* BrowserMediaPlayerManager::GetContentViewCore() const { |
| 55 return ContentViewCoreImpl::FromWebContents(web_contents()); |
| 56 } |
| 57 |
| 54 #if !defined(GOOGLE_TV) | 58 #if !defined(GOOGLE_TV) |
| 55 // static | 59 // static |
| 56 MediaPlayerAndroid* BrowserMediaPlayerManager::CreateMediaPlayer( | 60 MediaPlayerAndroid* BrowserMediaPlayerManager::CreateMediaPlayer( |
| 57 MediaPlayerHostMsg_Initialize_Type type, | 61 MediaPlayerHostMsg_Initialize_Type type, |
| 58 int player_id, | 62 int player_id, |
| 59 const GURL& url, | 63 const GURL& url, |
| 60 const GURL& first_party_for_cookies, | 64 const GURL& first_party_for_cookies, |
| 61 int demuxer_client_id, | 65 int demuxer_client_id, |
| 62 bool hide_url_log, | 66 bool hide_url_log, |
| 63 MediaPlayerManager* manager, | 67 MediaPlayerManager* manager, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 93 NOTREACHED(); | 97 NOTREACHED(); |
| 94 return NULL; | 98 return NULL; |
| 95 } | 99 } |
| 96 #endif | 100 #endif |
| 97 | 101 |
| 98 BrowserMediaPlayerManager::BrowserMediaPlayerManager( | 102 BrowserMediaPlayerManager::BrowserMediaPlayerManager( |
| 99 RenderViewHost* render_view_host) | 103 RenderViewHost* render_view_host) |
| 100 : WebContentsObserver(WebContents::FromRenderViewHost(render_view_host)), | 104 : WebContentsObserver(WebContents::FromRenderViewHost(render_view_host)), |
| 101 fullscreen_player_id_(-1), | 105 fullscreen_player_id_(-1), |
| 102 pending_fullscreen_player_id_(-1), | 106 pending_fullscreen_player_id_(-1), |
| 103 fullscreen_player_is_released_(false), | |
| 104 web_contents_(WebContents::FromRenderViewHost(render_view_host)), | 107 web_contents_(WebContents::FromRenderViewHost(render_view_host)), |
| 105 weak_ptr_factory_(this) { | 108 weak_ptr_factory_(this) { |
| 106 } | 109 } |
| 107 | 110 |
| 108 BrowserMediaPlayerManager::~BrowserMediaPlayerManager() {} | 111 BrowserMediaPlayerManager::~BrowserMediaPlayerManager() {} |
| 109 | 112 |
| 110 bool BrowserMediaPlayerManager::OnMessageReceived(const IPC::Message& msg) { | 113 bool BrowserMediaPlayerManager::OnMessageReceived(const IPC::Message& msg) { |
| 111 bool handled = true; | 114 bool handled = true; |
| 112 IPC_BEGIN_MESSAGE_MAP(BrowserMediaPlayerManager, msg) | 115 IPC_BEGIN_MESSAGE_MAP(BrowserMediaPlayerManager, msg) |
| 113 IPC_MESSAGE_HANDLER(MediaPlayerHostMsg_EnterFullscreen, OnEnterFullscreen) | 116 IPC_MESSAGE_HANDLER(MediaPlayerHostMsg_EnterFullscreen, OnEnterFullscreen) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 133 OnNotifyExternalSurface) | 136 OnNotifyExternalSurface) |
| 134 #endif | 137 #endif |
| 135 IPC_MESSAGE_UNHANDLED(handled = false) | 138 IPC_MESSAGE_UNHANDLED(handled = false) |
| 136 IPC_END_MESSAGE_MAP() | 139 IPC_END_MESSAGE_MAP() |
| 137 return handled; | 140 return handled; |
| 138 } | 141 } |
| 139 | 142 |
| 140 void BrowserMediaPlayerManager::FullscreenPlayerPlay() { | 143 void BrowserMediaPlayerManager::FullscreenPlayerPlay() { |
| 141 MediaPlayerAndroid* player = GetFullscreenPlayer(); | 144 MediaPlayerAndroid* player = GetFullscreenPlayer(); |
| 142 if (player) { | 145 if (player) { |
| 143 if (fullscreen_player_is_released_) { | |
| 144 video_view_->OpenVideo(); | |
| 145 fullscreen_player_is_released_ = false; | |
| 146 } | |
| 147 player->Start(); | 146 player->Start(); |
| 148 Send(new MediaPlayerMsg_DidMediaPlayerPlay( | 147 Send(new MediaPlayerMsg_DidMediaPlayerPlay( |
| 149 routing_id(), fullscreen_player_id_)); | 148 routing_id(), fullscreen_player_id_)); |
| 150 } | 149 } |
| 151 } | 150 } |
| 152 | 151 |
| 153 void BrowserMediaPlayerManager::FullscreenPlayerPause() { | 152 void BrowserMediaPlayerManager::FullscreenPlayerPause() { |
| 154 MediaPlayerAndroid* player = GetFullscreenPlayer(); | 153 MediaPlayerAndroid* player = GetFullscreenPlayer(); |
| 155 if (player) { | 154 if (player) { |
| 156 player->Pause(true); | 155 player->Pause(true); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 177 MediaPlayerAndroid* player = GetFullscreenPlayer(); | 176 MediaPlayerAndroid* player = GetFullscreenPlayer(); |
| 178 fullscreen_player_id_ = -1; | 177 fullscreen_player_id_ = -1; |
| 179 if (!player) | 178 if (!player) |
| 180 return; | 179 return; |
| 181 if (release_media_player) | 180 if (release_media_player) |
| 182 player->Release(); | 181 player->Release(); |
| 183 else | 182 else |
| 184 player->SetVideoSurface(gfx::ScopedJavaSurface()); | 183 player->SetVideoSurface(gfx::ScopedJavaSurface()); |
| 185 } | 184 } |
| 186 | 185 |
| 186 void BrowserMediaPlayerManager::SuspendFullscreen() { |
| 187 MediaPlayerAndroid* player = GetFullscreenPlayer(); |
| 188 if (player) |
| 189 player->SetVideoSurface(gfx::ScopedJavaSurface()); |
| 190 } |
| 191 |
| 192 void BrowserMediaPlayerManager::ResumeFullscreen( |
| 193 gfx::ScopedJavaSurface surface) { |
| 194 MediaPlayerAndroid* player = GetFullscreenPlayer(); |
| 195 if (player) |
| 196 player->SetVideoSurface(surface.Pass()); |
| 197 } |
| 198 |
| 187 void BrowserMediaPlayerManager::OnTimeUpdate(int player_id, | 199 void BrowserMediaPlayerManager::OnTimeUpdate(int player_id, |
| 188 base::TimeDelta current_time) { | 200 base::TimeDelta current_time) { |
| 189 Send(new MediaPlayerMsg_MediaTimeUpdate( | 201 Send(new MediaPlayerMsg_MediaTimeUpdate( |
| 190 routing_id(), player_id, current_time)); | 202 routing_id(), player_id, current_time)); |
| 191 } | 203 } |
| 192 | 204 |
| 193 void BrowserMediaPlayerManager::SetVideoSurface( | 205 void BrowserMediaPlayerManager::SetVideoSurface( |
| 194 gfx::ScopedJavaSurface surface) { | 206 gfx::ScopedJavaSurface surface) { |
| 195 MediaPlayerAndroid* player = GetFullscreenPlayer(); | 207 MediaPlayerAndroid* player = GetFullscreenPlayer(); |
| 196 if (player) { | 208 if (player) { |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 void BrowserMediaPlayerManager::OnEnterFullscreen(int player_id) { | 458 void BrowserMediaPlayerManager::OnEnterFullscreen(int player_id) { |
| 447 DCHECK_EQ(fullscreen_player_id_, -1); | 459 DCHECK_EQ(fullscreen_player_id_, -1); |
| 448 if (media_keys_ids_pending_approval_.find(player_id) != | 460 if (media_keys_ids_pending_approval_.find(player_id) != |
| 449 media_keys_ids_pending_approval_.end()) { | 461 media_keys_ids_pending_approval_.end()) { |
| 450 return; | 462 return; |
| 451 } | 463 } |
| 452 | 464 |
| 453 if (video_view_.get()) { | 465 if (video_view_.get()) { |
| 454 fullscreen_player_id_ = player_id; | 466 fullscreen_player_id_ = player_id; |
| 455 video_view_->OpenVideo(); | 467 video_view_->OpenVideo(); |
| 456 } else if (!ContentVideoView::HasContentVideoView()) { | 468 } else if (!ContentVideoView::GetInstance()) { |
| 457 // In Android WebView, two ContentViewCores could both try to enter | 469 // In Android WebView, two ContentViewCores could both try to enter |
| 458 // fullscreen video, we just ignore the second one. | 470 // fullscreen video, we just ignore the second one. |
| 459 fullscreen_player_id_ = player_id; | 471 fullscreen_player_id_ = player_id; |
| 460 ContentViewCoreImpl* content_view_core_impl = | 472 video_view_.reset(new ContentVideoView(this)); |
| 461 ContentViewCoreImpl::FromWebContents(web_contents()); | |
| 462 video_view_.reset(new ContentVideoView(content_view_core_impl->GetContext(), | |
| 463 content_view_core_impl->GetContentVideoViewClient(), this)); | |
| 464 } | 473 } |
| 465 } | 474 } |
| 466 | 475 |
| 467 void BrowserMediaPlayerManager::OnExitFullscreen(int player_id) { | 476 void BrowserMediaPlayerManager::OnExitFullscreen(int player_id) { |
| 468 if (fullscreen_player_id_ == player_id) { | 477 if (fullscreen_player_id_ == player_id) { |
| 469 MediaPlayerAndroid* player = GetPlayer(player_id); | 478 MediaPlayerAndroid* player = GetPlayer(player_id); |
| 470 if (player) | 479 if (player) |
| 471 player->SetVideoSurface(gfx::ScopedJavaSurface()); | 480 player->SetVideoSurface(gfx::ScopedJavaSurface()); |
| 472 video_view_->OnExitFullscreen(); | 481 video_view_->OnExitFullscreen(); |
| 473 } | 482 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 void BrowserMediaPlayerManager::OnSetVolume(int player_id, double volume) { | 527 void BrowserMediaPlayerManager::OnSetVolume(int player_id, double volume) { |
| 519 MediaPlayerAndroid* player = GetPlayer(player_id); | 528 MediaPlayerAndroid* player = GetPlayer(player_id); |
| 520 if (player) | 529 if (player) |
| 521 player->SetVolume(volume); | 530 player->SetVolume(volume); |
| 522 } | 531 } |
| 523 | 532 |
| 524 void BrowserMediaPlayerManager::OnReleaseResources(int player_id) { | 533 void BrowserMediaPlayerManager::OnReleaseResources(int player_id) { |
| 525 MediaPlayerAndroid* player = GetPlayer(player_id); | 534 MediaPlayerAndroid* player = GetPlayer(player_id); |
| 526 if (player) | 535 if (player) |
| 527 player->Release(); | 536 player->Release(); |
| 528 if (player_id == fullscreen_player_id_) | |
| 529 fullscreen_player_is_released_ = true; | |
| 530 | 537 |
| 531 #if defined(GOOGLE_TV) | 538 #if defined(GOOGLE_TV) |
| 532 WebContentsViewAndroid* view = | 539 WebContentsViewAndroid* view = |
| 533 static_cast<WebContentsViewAndroid*>(web_contents_->GetView()); | 540 static_cast<WebContentsViewAndroid*>(web_contents_->GetView()); |
| 534 if (view) | 541 if (view) |
| 535 view->NotifyExternalSurface(player_id, false, gfx::RectF()); | 542 view->NotifyExternalSurface(player_id, false, gfx::RectF()); |
| 536 #endif | 543 #endif |
| 537 } | 544 } |
| 538 | 545 |
| 539 void BrowserMediaPlayerManager::OnDestroyPlayer(int player_id) { | 546 void BrowserMediaPlayerManager::OnDestroyPlayer(int player_id) { |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 740 if (pending_fullscreen_player_id_ != media_keys_id) | 747 if (pending_fullscreen_player_id_ != media_keys_id) |
| 741 return; | 748 return; |
| 742 | 749 |
| 743 pending_fullscreen_player_id_ = -1; | 750 pending_fullscreen_player_id_ = -1; |
| 744 MediaPlayerAndroid* player = GetPlayer(media_keys_id); | 751 MediaPlayerAndroid* player = GetPlayer(media_keys_id); |
| 745 if (player->IsPlaying()) | 752 if (player->IsPlaying()) |
| 746 OnProtectedSurfaceRequested(media_keys_id); | 753 OnProtectedSurfaceRequested(media_keys_id); |
| 747 } | 754 } |
| 748 | 755 |
| 749 } // namespace content | 756 } // namespace content |
| OLD | NEW |