| 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 IPC_MESSAGE_HANDLER(MediaPlayerHostMsg_SetVolume, OnSetVolume) | 130 IPC_MESSAGE_HANDLER(MediaPlayerHostMsg_SetVolume, OnSetVolume) |
| 131 IPC_MESSAGE_HANDLER(MediaPlayerHostMsg_Release, OnReleaseResources) | 131 IPC_MESSAGE_HANDLER(MediaPlayerHostMsg_Release, OnReleaseResources) |
| 132 IPC_MESSAGE_HANDLER(MediaPlayerHostMsg_DestroyMediaPlayer, OnDestroyPlayer) | 132 IPC_MESSAGE_HANDLER(MediaPlayerHostMsg_DestroyMediaPlayer, OnDestroyPlayer) |
| 133 IPC_MESSAGE_HANDLER(MediaPlayerHostMsg_DestroyAllMediaPlayers, | 133 IPC_MESSAGE_HANDLER(MediaPlayerHostMsg_DestroyAllMediaPlayers, |
| 134 DestroyAllMediaPlayers) | 134 DestroyAllMediaPlayers) |
| 135 IPC_MESSAGE_HANDLER(MediaKeysHostMsg_InitializeCDM, | 135 IPC_MESSAGE_HANDLER(MediaKeysHostMsg_InitializeCDM, |
| 136 OnInitializeCDM) | 136 OnInitializeCDM) |
| 137 IPC_MESSAGE_HANDLER(MediaKeysHostMsg_CreateSession, OnCreateSession) | 137 IPC_MESSAGE_HANDLER(MediaKeysHostMsg_CreateSession, OnCreateSession) |
| 138 IPC_MESSAGE_HANDLER(MediaKeysHostMsg_UpdateSession, OnUpdateSession) | 138 IPC_MESSAGE_HANDLER(MediaKeysHostMsg_UpdateSession, OnUpdateSession) |
| 139 IPC_MESSAGE_HANDLER(MediaKeysHostMsg_ReleaseSession, OnReleaseSession) | 139 IPC_MESSAGE_HANDLER(MediaKeysHostMsg_ReleaseSession, OnReleaseSession) |
| 140 IPC_MESSAGE_HANDLER(MediaKeysHostMsg_CancelAllPendingSessionCreations, |
| 141 OnCancelAllPendingSessionCreations) |
| 140 #if defined(VIDEO_HOLE) | 142 #if defined(VIDEO_HOLE) |
| 141 IPC_MESSAGE_HANDLER(MediaPlayerHostMsg_NotifyExternalSurface, | 143 IPC_MESSAGE_HANDLER(MediaPlayerHostMsg_NotifyExternalSurface, |
| 142 OnNotifyExternalSurface) | 144 OnNotifyExternalSurface) |
| 143 #endif // defined(VIDEO_HOLE) | 145 #endif // defined(VIDEO_HOLE) |
| 144 IPC_MESSAGE_UNHANDLED(handled = false) | 146 IPC_MESSAGE_UNHANDLED(handled = false) |
| 145 IPC_END_MESSAGE_MAP() | 147 IPC_END_MESSAGE_MAP() |
| 146 return handled; | 148 return handled; |
| 147 } | 149 } |
| 148 | 150 |
| 149 void BrowserMediaPlayerManager::FullscreenPlayerPlay() { | 151 void BrowserMediaPlayerManager::FullscreenPlayerPlay() { |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 return; | 587 return; |
| 586 } | 588 } |
| 587 if (init_data.size() > kEmeInitDataMaximum) { | 589 if (init_data.size() > kEmeInitDataMaximum) { |
| 588 OnSessionError( | 590 OnSessionError( |
| 589 media_keys_id, session_id, media::MediaKeys::kUnknownError, 0); | 591 media_keys_id, session_id, media::MediaKeys::kUnknownError, 0); |
| 590 return; | 592 return; |
| 591 } | 593 } |
| 592 | 594 |
| 593 if (CommandLine::ForCurrentProcess() | 595 if (CommandLine::ForCurrentProcess() |
| 594 ->HasSwitch(switches::kDisableInfobarForProtectedMediaIdentifier)) { | 596 ->HasSwitch(switches::kDisableInfobarForProtectedMediaIdentifier)) { |
| 595 GenerateKeyIfAllowed(media_keys_id, session_id, type, init_data, true); | 597 CreateSessionIfPermitted(media_keys_id, session_id, type, init_data, true); |
| 596 return; | 598 return; |
| 597 } | 599 } |
| 598 | 600 |
| 599 MediaDrmBridge* drm_bridge = GetDrmBridge(media_keys_id); | 601 MediaDrmBridge* drm_bridge = GetDrmBridge(media_keys_id); |
| 600 if (!drm_bridge) { | 602 if (!drm_bridge) { |
| 601 DLOG(WARNING) << "No MediaDrmBridge for ID: " << media_keys_id << " found"; | 603 DLOG(WARNING) << "No MediaDrmBridge for ID: " << media_keys_id << " found"; |
| 602 OnSessionError( | 604 OnSessionError( |
| 603 media_keys_id, session_id, media::MediaKeys::kUnknownError, 0); | 605 media_keys_id, session_id, media::MediaKeys::kUnknownError, 0); |
| 604 return; | 606 return; |
| 605 } | 607 } |
| 606 | 608 |
| 607 if (media_keys_ids_approved_.find(media_keys_id) == | 609 if (media_keys_ids_approved_.find(media_keys_id) == |
| 608 media_keys_ids_approved_.end()) { | 610 media_keys_ids_approved_.end()) { |
| 609 media_keys_ids_pending_approval_.insert(media_keys_id); | 611 media_keys_ids_pending_approval_.insert(media_keys_id); |
| 610 } | 612 } |
| 611 web_contents()->GetDelegate()->RequestProtectedMediaIdentifierPermission( | 613 |
| 612 web_contents(), | 614 BrowserContext* context = |
| 615 web_contents()->GetRenderProcessHost()->GetBrowserContext(); |
| 616 |
| 617 context->RequestProtectedMediaIdentifierPermission( |
| 618 web_contents()->GetRenderProcessHost()->GetID(), |
| 619 web_contents()->GetRenderViewHost()->GetRoutingID(), |
| 620 static_cast<int>(session_id), |
| 621 media_keys_id, |
| 613 drm_bridge->frame_url(), | 622 drm_bridge->frame_url(), |
| 614 base::Bind(&BrowserMediaPlayerManager::GenerateKeyIfAllowed, | 623 base::Bind(&BrowserMediaPlayerManager::CreateSessionIfPermitted, |
| 615 weak_ptr_factory_.GetWeakPtr(), | 624 weak_ptr_factory_.GetWeakPtr(), |
| 616 media_keys_id, | 625 media_keys_id, |
| 617 session_id, | 626 session_id, |
| 618 type, | 627 type, |
| 619 init_data)); | 628 init_data)); |
| 620 } | 629 } |
| 621 | 630 |
| 622 void BrowserMediaPlayerManager::OnUpdateSession( | 631 void BrowserMediaPlayerManager::OnUpdateSession( |
| 623 int media_keys_id, | 632 int media_keys_id, |
| 624 uint32 session_id, | 633 uint32 session_id, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 654 if (!drm_bridge) { | 663 if (!drm_bridge) { |
| 655 DLOG(WARNING) << "No MediaDrmBridge for ID: " << media_keys_id << " found"; | 664 DLOG(WARNING) << "No MediaDrmBridge for ID: " << media_keys_id << " found"; |
| 656 OnSessionError( | 665 OnSessionError( |
| 657 media_keys_id, session_id, media::MediaKeys::kUnknownError, 0); | 666 media_keys_id, session_id, media::MediaKeys::kUnknownError, 0); |
| 658 return; | 667 return; |
| 659 } | 668 } |
| 660 | 669 |
| 661 drm_bridge->ReleaseSession(session_id); | 670 drm_bridge->ReleaseSession(session_id); |
| 662 } | 671 } |
| 663 | 672 |
| 673 void BrowserMediaPlayerManager::OnCancelAllPendingSessionCreations( |
| 674 int media_keys_id) { |
| 675 MediaDrmBridge* drm_bridge = GetDrmBridge(media_keys_id); |
| 676 if (!drm_bridge) return; |
| 677 |
| 678 BrowserContext* context = |
| 679 web_contents()->GetRenderProcessHost()->GetBrowserContext(); |
| 680 context->CancelProtectedMediaIdentifierPermissionRequests(media_keys_id); |
| 681 } |
| 682 |
| 664 void BrowserMediaPlayerManager::AddPlayer(MediaPlayerAndroid* player) { | 683 void BrowserMediaPlayerManager::AddPlayer(MediaPlayerAndroid* player) { |
| 665 DCHECK(!GetPlayer(player->player_id())); | 684 DCHECK(!GetPlayer(player->player_id())); |
| 666 players_.push_back(player); | 685 players_.push_back(player); |
| 667 if (player->IsRemote()) { | 686 if (player->IsRemote()) { |
| 668 Send(new MediaPlayerMsg_ConnectedToRemoteDevice(routing_id(), | 687 Send(new MediaPlayerMsg_ConnectedToRemoteDevice(routing_id(), |
| 669 player->player_id())); | 688 player->player_id())); |
| 670 } | 689 } |
| 671 } | 690 } |
| 672 | 691 |
| 673 void BrowserMediaPlayerManager::RemovePlayer(int player_id) { | 692 void BrowserMediaPlayerManager::RemovePlayer(int player_id) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 MediaDrmBridge* drm_bridge = GetDrmBridge(media_keys_id); | 771 MediaDrmBridge* drm_bridge = GetDrmBridge(media_keys_id); |
| 753 if (!player || !drm_bridge) { | 772 if (!player || !drm_bridge) { |
| 754 DVLOG(1) << "OnSetMediaKeys(): Player and MediaKeys must be present."; | 773 DVLOG(1) << "OnSetMediaKeys(): Player and MediaKeys must be present."; |
| 755 return; | 774 return; |
| 756 } | 775 } |
| 757 // TODO(qinmin): add the logic to decide whether we should create the | 776 // TODO(qinmin): add the logic to decide whether we should create the |
| 758 // fullscreen surface for EME lv1. | 777 // fullscreen surface for EME lv1. |
| 759 player->SetDrmBridge(drm_bridge); | 778 player->SetDrmBridge(drm_bridge); |
| 760 } | 779 } |
| 761 | 780 |
| 762 void BrowserMediaPlayerManager::GenerateKeyIfAllowed( | 781 void BrowserMediaPlayerManager::CreateSessionIfPermitted( |
| 763 int media_keys_id, | 782 int media_keys_id, |
| 764 uint32 session_id, | 783 uint32 session_id, |
| 765 const std::string& type, | 784 const std::string& type, |
| 766 const std::vector<uint8>& init_data, | 785 const std::vector<uint8>& init_data, |
| 767 bool allowed) { | 786 bool permitted) { |
| 768 if (!allowed) | 787 if (!permitted) { |
| 788 OnSessionError( |
| 789 media_keys_id, session_id, media::MediaKeys::kUnknownError, 0); |
| 769 return; | 790 return; |
| 791 } |
| 770 | 792 |
| 771 MediaDrmBridge* drm_bridge = GetDrmBridge(media_keys_id); | 793 MediaDrmBridge* drm_bridge = GetDrmBridge(media_keys_id); |
| 772 if (!drm_bridge) { | 794 if (!drm_bridge) { |
| 773 DLOG(WARNING) << "No MediaDrmBridge for ID: " << media_keys_id << " found"; | 795 DLOG(WARNING) << "No MediaDrmBridge for ID: " << media_keys_id << " found"; |
| 774 OnSessionError( | 796 OnSessionError( |
| 775 media_keys_id, session_id, media::MediaKeys::kUnknownError, 0); | 797 media_keys_id, session_id, media::MediaKeys::kUnknownError, 0); |
| 776 return; | 798 return; |
| 777 } | 799 } |
| 778 media_keys_ids_pending_approval_.erase(media_keys_id); | 800 media_keys_ids_pending_approval_.erase(media_keys_id); |
| 779 media_keys_ids_approved_.insert(media_keys_id); | 801 media_keys_ids_approved_.insert(media_keys_id); |
| 780 drm_bridge->CreateSession(session_id, type, &init_data[0], init_data.size()); | 802 drm_bridge->CreateSession(session_id, type, &init_data[0], init_data.size()); |
| 781 | 803 |
| 782 // TODO(qinmin): currently |media_keys_id| and player ID are identical. | 804 // TODO(qinmin): currently |media_keys_id| and player ID are identical. |
| 783 // This might not be true in the future. | 805 // This might not be true in the future. |
| 784 if (pending_fullscreen_player_id_ != media_keys_id) | 806 if (pending_fullscreen_player_id_ != media_keys_id) |
| 785 return; | 807 return; |
| 786 | 808 |
| 787 pending_fullscreen_player_id_ = -1; | 809 pending_fullscreen_player_id_ = -1; |
| 788 MediaPlayerAndroid* player = GetPlayer(media_keys_id); | 810 MediaPlayerAndroid* player = GetPlayer(media_keys_id); |
| 789 if (player->IsPlaying()) | 811 if (player->IsPlaying()) |
| 790 OnProtectedSurfaceRequested(media_keys_id); | 812 OnProtectedSurfaceRequested(media_keys_id); |
| 791 } | 813 } |
| 792 | 814 |
| 793 } // namespace content | 815 } // namespace content |
| OLD | NEW |