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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 } | 52 } |
53 | 53 |
54 // static | 54 // static |
55 BrowserMediaPlayerManager* BrowserMediaPlayerManager::Create( | 55 BrowserMediaPlayerManager* BrowserMediaPlayerManager::Create( |
56 RenderViewHost* rvh) { | 56 RenderViewHost* rvh) { |
57 if (g_factory) | 57 if (g_factory) |
58 return g_factory(rvh); | 58 return g_factory(rvh); |
59 return new BrowserMediaPlayerManager(rvh); | 59 return new BrowserMediaPlayerManager(rvh); |
60 } | 60 } |
61 | 61 |
| 62 ContentViewCoreImpl* BrowserMediaPlayerManager::GetContentViewCore() const { |
| 63 return ContentViewCoreImpl::FromWebContents(web_contents()); |
| 64 } |
| 65 |
62 #if !defined(GOOGLE_TV) | 66 #if !defined(GOOGLE_TV) |
63 // static | 67 // static |
64 MediaPlayerAndroid* BrowserMediaPlayerManager::CreateMediaPlayer( | 68 MediaPlayerAndroid* BrowserMediaPlayerManager::CreateMediaPlayer( |
65 MediaPlayerHostMsg_Initialize_Type type, | 69 MediaPlayerHostMsg_Initialize_Type type, |
66 int player_id, | 70 int player_id, |
67 const GURL& url, | 71 const GURL& url, |
68 const GURL& first_party_for_cookies, | 72 const GURL& first_party_for_cookies, |
69 int demuxer_client_id, | 73 int demuxer_client_id, |
70 bool hide_url_log, | 74 bool hide_url_log, |
71 MediaPlayerManager* manager, | 75 MediaPlayerManager* manager, |
(...skipping 29 matching lines...) Expand all Loading... |
101 NOTREACHED(); | 105 NOTREACHED(); |
102 return NULL; | 106 return NULL; |
103 } | 107 } |
104 #endif | 108 #endif |
105 | 109 |
106 BrowserMediaPlayerManager::BrowserMediaPlayerManager( | 110 BrowserMediaPlayerManager::BrowserMediaPlayerManager( |
107 RenderViewHost* render_view_host) | 111 RenderViewHost* render_view_host) |
108 : WebContentsObserver(WebContents::FromRenderViewHost(render_view_host)), | 112 : WebContentsObserver(WebContents::FromRenderViewHost(render_view_host)), |
109 fullscreen_player_id_(-1), | 113 fullscreen_player_id_(-1), |
110 pending_fullscreen_player_id_(-1), | 114 pending_fullscreen_player_id_(-1), |
111 fullscreen_player_is_released_(false), | |
112 web_contents_(WebContents::FromRenderViewHost(render_view_host)), | 115 web_contents_(WebContents::FromRenderViewHost(render_view_host)), |
113 weak_ptr_factory_(this) { | 116 weak_ptr_factory_(this) { |
114 } | 117 } |
115 | 118 |
116 BrowserMediaPlayerManager::~BrowserMediaPlayerManager() {} | 119 BrowserMediaPlayerManager::~BrowserMediaPlayerManager() {} |
117 | 120 |
118 bool BrowserMediaPlayerManager::OnMessageReceived(const IPC::Message& msg) { | 121 bool BrowserMediaPlayerManager::OnMessageReceived(const IPC::Message& msg) { |
119 bool handled = true; | 122 bool handled = true; |
120 IPC_BEGIN_MESSAGE_MAP(BrowserMediaPlayerManager, msg) | 123 IPC_BEGIN_MESSAGE_MAP(BrowserMediaPlayerManager, msg) |
121 IPC_MESSAGE_HANDLER(MediaPlayerHostMsg_EnterFullscreen, OnEnterFullscreen) | 124 IPC_MESSAGE_HANDLER(MediaPlayerHostMsg_EnterFullscreen, OnEnterFullscreen) |
(...skipping 17 matching lines...) Expand all Loading... |
139 OnNotifyExternalSurface) | 142 OnNotifyExternalSurface) |
140 #endif // defined(VIDEO_HOLE) | 143 #endif // defined(VIDEO_HOLE) |
141 IPC_MESSAGE_UNHANDLED(handled = false) | 144 IPC_MESSAGE_UNHANDLED(handled = false) |
142 IPC_END_MESSAGE_MAP() | 145 IPC_END_MESSAGE_MAP() |
143 return handled; | 146 return handled; |
144 } | 147 } |
145 | 148 |
146 void BrowserMediaPlayerManager::FullscreenPlayerPlay() { | 149 void BrowserMediaPlayerManager::FullscreenPlayerPlay() { |
147 MediaPlayerAndroid* player = GetFullscreenPlayer(); | 150 MediaPlayerAndroid* player = GetFullscreenPlayer(); |
148 if (player) { | 151 if (player) { |
149 if (fullscreen_player_is_released_) { | |
150 video_view_->OpenVideo(); | |
151 fullscreen_player_is_released_ = false; | |
152 } | |
153 player->Start(); | 152 player->Start(); |
154 Send(new MediaPlayerMsg_DidMediaPlayerPlay( | 153 Send(new MediaPlayerMsg_DidMediaPlayerPlay( |
155 routing_id(), fullscreen_player_id_)); | 154 routing_id(), fullscreen_player_id_)); |
156 } | 155 } |
157 } | 156 } |
158 | 157 |
159 void BrowserMediaPlayerManager::FullscreenPlayerPause() { | 158 void BrowserMediaPlayerManager::FullscreenPlayerPause() { |
160 MediaPlayerAndroid* player = GetFullscreenPlayer(); | 159 MediaPlayerAndroid* player = GetFullscreenPlayer(); |
161 if (player) { | 160 if (player) { |
162 player->Pause(true); | 161 player->Pause(true); |
(...skipping 20 matching lines...) Expand all Loading... |
183 MediaPlayerAndroid* player = GetFullscreenPlayer(); | 182 MediaPlayerAndroid* player = GetFullscreenPlayer(); |
184 fullscreen_player_id_ = -1; | 183 fullscreen_player_id_ = -1; |
185 if (!player) | 184 if (!player) |
186 return; | 185 return; |
187 if (release_media_player) | 186 if (release_media_player) |
188 player->Release(); | 187 player->Release(); |
189 else | 188 else |
190 player->SetVideoSurface(gfx::ScopedJavaSurface()); | 189 player->SetVideoSurface(gfx::ScopedJavaSurface()); |
191 } | 190 } |
192 | 191 |
| 192 void BrowserMediaPlayerManager::SuspendFullscreen() { |
| 193 MediaPlayerAndroid* player = GetFullscreenPlayer(); |
| 194 if (player) |
| 195 player->SetVideoSurface(gfx::ScopedJavaSurface()); |
| 196 } |
| 197 |
| 198 void BrowserMediaPlayerManager::ResumeFullscreen( |
| 199 gfx::ScopedJavaSurface surface) { |
| 200 MediaPlayerAndroid* player = GetFullscreenPlayer(); |
| 201 if (player) |
| 202 player->SetVideoSurface(surface.Pass()); |
| 203 } |
| 204 |
193 void BrowserMediaPlayerManager::OnTimeUpdate(int player_id, | 205 void BrowserMediaPlayerManager::OnTimeUpdate(int player_id, |
194 base::TimeDelta current_time) { | 206 base::TimeDelta current_time) { |
195 Send(new MediaPlayerMsg_MediaTimeUpdate( | 207 Send(new MediaPlayerMsg_MediaTimeUpdate( |
196 routing_id(), player_id, current_time)); | 208 routing_id(), player_id, current_time)); |
197 } | 209 } |
198 | 210 |
199 void BrowserMediaPlayerManager::SetVideoSurface( | 211 void BrowserMediaPlayerManager::SetVideoSurface( |
200 gfx::ScopedJavaSurface surface) { | 212 gfx::ScopedJavaSurface surface) { |
201 MediaPlayerAndroid* player = GetFullscreenPlayer(); | 213 MediaPlayerAndroid* player = GetFullscreenPlayer(); |
202 if (!player) | 214 if (!player) |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 void BrowserMediaPlayerManager::OnEnterFullscreen(int player_id) { | 466 void BrowserMediaPlayerManager::OnEnterFullscreen(int player_id) { |
455 DCHECK_EQ(fullscreen_player_id_, -1); | 467 DCHECK_EQ(fullscreen_player_id_, -1); |
456 if (media_keys_ids_pending_approval_.find(player_id) != | 468 if (media_keys_ids_pending_approval_.find(player_id) != |
457 media_keys_ids_pending_approval_.end()) { | 469 media_keys_ids_pending_approval_.end()) { |
458 return; | 470 return; |
459 } | 471 } |
460 | 472 |
461 if (video_view_.get()) { | 473 if (video_view_.get()) { |
462 fullscreen_player_id_ = player_id; | 474 fullscreen_player_id_ = player_id; |
463 video_view_->OpenVideo(); | 475 video_view_->OpenVideo(); |
464 } else if (!ContentVideoView::HasContentVideoView()) { | 476 } else if (!ContentVideoView::GetInstance()) { |
465 // In Android WebView, two ContentViewCores could both try to enter | 477 // In Android WebView, two ContentViewCores could both try to enter |
466 // fullscreen video, we just ignore the second one. | 478 // fullscreen video, we just ignore the second one. |
467 fullscreen_player_id_ = player_id; | 479 fullscreen_player_id_ = player_id; |
468 ContentViewCoreImpl* content_view_core_impl = | 480 video_view_.reset(new ContentVideoView(this)); |
469 ContentViewCoreImpl::FromWebContents(web_contents()); | |
470 video_view_.reset(new ContentVideoView(content_view_core_impl->GetContext(), | |
471 content_view_core_impl->GetContentVideoViewClient(), this)); | |
472 } | 481 } |
473 } | 482 } |
474 | 483 |
475 void BrowserMediaPlayerManager::OnExitFullscreen(int player_id) { | 484 void BrowserMediaPlayerManager::OnExitFullscreen(int player_id) { |
476 if (fullscreen_player_id_ == player_id) { | 485 if (fullscreen_player_id_ == player_id) { |
477 MediaPlayerAndroid* player = GetPlayer(player_id); | 486 MediaPlayerAndroid* player = GetPlayer(player_id); |
478 if (player) | 487 if (player) |
479 player->SetVideoSurface(gfx::ScopedJavaSurface()); | 488 player->SetVideoSurface(gfx::ScopedJavaSurface()); |
480 video_view_->OnExitFullscreen(); | 489 video_view_->OnExitFullscreen(); |
481 } | 490 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 void BrowserMediaPlayerManager::OnSetVolume(int player_id, double volume) { | 535 void BrowserMediaPlayerManager::OnSetVolume(int player_id, double volume) { |
527 MediaPlayerAndroid* player = GetPlayer(player_id); | 536 MediaPlayerAndroid* player = GetPlayer(player_id); |
528 if (player) | 537 if (player) |
529 player->SetVolume(volume); | 538 player->SetVolume(volume); |
530 } | 539 } |
531 | 540 |
532 void BrowserMediaPlayerManager::OnReleaseResources(int player_id) { | 541 void BrowserMediaPlayerManager::OnReleaseResources(int player_id) { |
533 MediaPlayerAndroid* player = GetPlayer(player_id); | 542 MediaPlayerAndroid* player = GetPlayer(player_id); |
534 if (player) | 543 if (player) |
535 player->Release(); | 544 player->Release(); |
536 if (player_id == fullscreen_player_id_) | |
537 fullscreen_player_is_released_ = true; | |
538 | 545 |
539 #if defined(VIDEO_HOLE) | 546 #if defined(VIDEO_HOLE) |
540 WebContentsViewAndroid* view = | 547 WebContentsViewAndroid* view = |
541 static_cast<WebContentsViewAndroid*>(web_contents_->GetView()); | 548 static_cast<WebContentsViewAndroid*>(web_contents_->GetView()); |
542 if (view) | 549 if (view) |
543 view->NotifyExternalSurface(player_id, false, gfx::RectF()); | 550 view->NotifyExternalSurface(player_id, false, gfx::RectF()); |
544 #endif // defined(VIDEO_HOLE) | 551 #endif // defined(VIDEO_HOLE) |
545 } | 552 } |
546 | 553 |
547 void BrowserMediaPlayerManager::OnDestroyPlayer(int player_id) { | 554 void BrowserMediaPlayerManager::OnDestroyPlayer(int player_id) { |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 if (pending_fullscreen_player_id_ != media_keys_id) | 778 if (pending_fullscreen_player_id_ != media_keys_id) |
772 return; | 779 return; |
773 | 780 |
774 pending_fullscreen_player_id_ = -1; | 781 pending_fullscreen_player_id_ = -1; |
775 MediaPlayerAndroid* player = GetPlayer(media_keys_id); | 782 MediaPlayerAndroid* player = GetPlayer(media_keys_id); |
776 if (player->IsPlaying()) | 783 if (player->IsPlaying()) |
777 OnProtectedSurfaceRequested(media_keys_id); | 784 OnProtectedSurfaceRequested(media_keys_id); |
778 } | 785 } |
779 | 786 |
780 } // namespace content | 787 } // namespace content |
OLD | NEW |