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

Side by Side Diff: chrome/browser/media/router/presentation_service_delegate_impl.cc

Issue 2517833004: [MR] Cancel auto-switching from tab mirroring to Cast SDK at page navigation based on user pref (Closed)
Patch Set: Rebase Created 4 years 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/media/router/presentation_service_delegate_impl.h" 5 #include "chrome/browser/media/router/presentation_service_delegate_impl.h"
6 6
7 #include <string> 7 #include <string>
8 #include <unordered_map> 8 #include <unordered_map>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 14 matching lines...) Expand all
25 #include "chrome/browser/media/router/route_message.h" 25 #include "chrome/browser/media/router/route_message.h"
26 #include "chrome/browser/media/router/route_message_observer.h" 26 #include "chrome/browser/media/router/route_message_observer.h"
27 #include "chrome/browser/media/router/route_request_result.h" 27 #include "chrome/browser/media/router/route_request_result.h"
28 #include "chrome/browser/sessions/session_tab_helper.h" 28 #include "chrome/browser/sessions/session_tab_helper.h"
29 #include "content/public/browser/browser_context.h" 29 #include "content/public/browser/browser_context.h"
30 #include "content/public/browser/presentation_screen_availability_listener.h" 30 #include "content/public/browser/presentation_screen_availability_listener.h"
31 #include "content/public/browser/presentation_session.h" 31 #include "content/public/browser/presentation_session.h"
32 #include "content/public/browser/render_frame_host.h" 32 #include "content/public/browser/render_frame_host.h"
33 #include "content/public/browser/render_process_host.h" 33 #include "content/public/browser/render_process_host.h"
34 34
35 #if !defined(OS_ANDROID)
36 #include "chrome/browser/profiles/profile.h"
37 #include "chrome/common/pref_names.h"
38 #include "components/prefs/pref_service.h"
39 #endif
40
35 DEFINE_WEB_CONTENTS_USER_DATA_KEY( 41 DEFINE_WEB_CONTENTS_USER_DATA_KEY(
36 media_router::PresentationServiceDelegateImpl); 42 media_router::PresentationServiceDelegateImpl);
37 43
38 using content::RenderFrameHost; 44 using content::RenderFrameHost;
39 45
40 namespace media_router { 46 namespace media_router {
41 47
42 namespace { 48 namespace {
43 49
44 using DelegateObserver = content::PresentationServiceDelegate::Observer; 50 using DelegateObserver = content::PresentationServiceDelegate::Observer;
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 const content::PresentationSessionStartedCallback& success_cb, 827 const content::PresentationSessionStartedCallback& success_cb,
822 const content::PresentationSessionErrorCallback& error_cb) { 828 const content::PresentationSessionErrorCallback& error_cb) {
823 DVLOG(2) << "PresentationServiceDelegateImpl::JoinSession"; 829 DVLOG(2) << "PresentationServiceDelegateImpl::JoinSession";
824 if (presentation_urls.empty()) { 830 if (presentation_urls.empty()) {
825 error_cb.Run(content::PresentationError( 831 error_cb.Run(content::PresentationError(
826 content::PRESENTATION_ERROR_NO_PRESENTATION_FOUND, 832 content::PRESENTATION_ERROR_NO_PRESENTATION_FOUND,
827 "Invalid presentation arguments.")); 833 "Invalid presentation arguments."));
828 return; 834 return;
829 } 835 }
830 836
837 const url::Origin& origin = url::Origin(GetLastCommittedURLForFrame(
838 RenderFrameHostId(render_process_id, render_frame_id), web_contents_));
mark a. foltz 2016/12/09 04:07:42 There might be a slight issue with this approach:
takumif 2016/12/09 19:18:12 Acknowledged.
839
840 #if !defined(OS_ANDROID)
841 if (IsAutoJoinPresentationId(presentation_id) &&
842 ShouldCancelAutoJoinForOrigin(origin)) {
843 error_cb.Run(content::PresentationError(
844 content::PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED,
845 "Auto-join request cancelled by user preferences."));
846 return;
847 }
848 #endif // !defined(OS_ANDROID)
849
831 // TODO(crbug.com/627655): Handle multiple URLs. 850 // TODO(crbug.com/627655): Handle multiple URLs.
832 const GURL& presentation_url = presentation_urls[0]; 851 const GURL& presentation_url = presentation_urls[0];
833 bool incognito = web_contents_->GetBrowserContext()->IsOffTheRecord(); 852 bool incognito = web_contents_->GetBrowserContext()->IsOffTheRecord();
834 std::vector<MediaRouteResponseCallback> route_response_callbacks; 853 std::vector<MediaRouteResponseCallback> route_response_callbacks;
835 route_response_callbacks.push_back( 854 route_response_callbacks.push_back(
836 base::Bind(&PresentationServiceDelegateImpl::OnJoinRouteResponse, 855 base::Bind(&PresentationServiceDelegateImpl::OnJoinRouteResponse,
837 weak_factory_.GetWeakPtr(), render_process_id, render_frame_id, 856 weak_factory_.GetWeakPtr(), render_process_id, render_frame_id,
838 presentation_url, presentation_id, success_cb, error_cb)); 857 presentation_url, presentation_id, success_cb, error_cb));
839 router_->JoinRoute( 858 router_->JoinRoute(MediaSourceForPresentationUrl(presentation_url).id(),
840 MediaSourceForPresentationUrl(presentation_url).id(), presentation_id, 859 presentation_id, origin.GetURL(), web_contents_,
841 GetLastCommittedURLForFrame( 860 route_response_callbacks, base::TimeDelta(), incognito);
842 RenderFrameHostId(render_process_id, render_frame_id), web_contents_)
843 .GetOrigin(),
844 web_contents_, route_response_callbacks, base::TimeDelta(), incognito);
845 } 861 }
846 862
847 void PresentationServiceDelegateImpl::CloseConnection( 863 void PresentationServiceDelegateImpl::CloseConnection(
848 int render_process_id, 864 int render_process_id,
849 int render_frame_id, 865 int render_frame_id,
850 const std::string& presentation_id) { 866 const std::string& presentation_id) {
851 const RenderFrameHostId rfh_id(render_process_id, render_frame_id); 867 const RenderFrameHostId rfh_id(render_process_id, render_frame_id);
852 const MediaRoute::Id& route_id = 868 const MediaRoute::Id& route_id =
853 frame_manager_->GetRouteId(rfh_id, presentation_id); 869 frame_manager_->GetRouteId(rfh_id, presentation_id);
854 if (route_id.empty()) { 870 if (route_id.empty()) {
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 986
971 bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest( 987 bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest(
972 int render_process_id, 988 int render_process_id,
973 int render_frame_id, 989 int render_frame_id,
974 const MediaSource::Id& source_id) const { 990 const MediaSource::Id& source_id) const {
975 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); 991 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id);
976 return frame_manager_->HasScreenAvailabilityListenerForTest( 992 return frame_manager_->HasScreenAvailabilityListenerForTest(
977 render_frame_host_id, source_id); 993 render_frame_host_id, source_id);
978 } 994 }
979 995
996 #if !defined(OS_ANDROID)
997 bool PresentationServiceDelegateImpl::ShouldCancelAutoJoinForOrigin(
998 const url::Origin& origin) const {
999 const base::ListValue* origins =
1000 Profile::FromBrowserContext(web_contents_->GetBrowserContext())
1001 ->GetPrefs()
1002 ->GetList(prefs::kMediaRouterTabMirroringSources);
1003 return origins &&
1004 origins->Find(base::StringValue(origin.Serialize())) != origins->end();
1005 }
1006 #endif // !defined(OS_ANDROID)
1007
980 } // namespace media_router 1008 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698