Chromium Code Reviews| Index: chrome/browser/media/router/presentation_service_delegate_impl.cc |
| diff --git a/chrome/browser/media/router/presentation_service_delegate_impl.cc b/chrome/browser/media/router/presentation_service_delegate_impl.cc |
| index d0d1a196c72cee8927de24a58b59776342306123..eb75f8b742fd85d39481a5f3f47048d344f4560a 100644 |
| --- a/chrome/browser/media/router/presentation_service_delegate_impl.cc |
| +++ b/chrome/browser/media/router/presentation_service_delegate_impl.cc |
| @@ -25,7 +25,14 @@ |
| #include "chrome/browser/media/router/route_message.h" |
| #include "chrome/browser/media/router/route_message_observer.h" |
| #include "chrome/browser/media/router/route_request_result.h" |
| +#if !defined(OS_ANDROID) |
|
apacible
2016/12/07 00:53:09
nit: move all #if !defined(OS_ANDROID) includes to
takumif
2016/12/08 00:01:30
Done.
|
| +#include "chrome/browser/profiles/profile.h" |
| +#endif |
| #include "chrome/browser/sessions/session_tab_helper.h" |
| +#if !defined(OS_ANDROID) |
| +#include "chrome/common/pref_names.h" |
| +#include "components/prefs/pref_service.h" |
| +#endif |
| #include "content/public/browser/browser_context.h" |
| #include "content/public/browser/presentation_screen_availability_listener.h" |
| #include "content/public/browser/presentation_session.h" |
| @@ -829,7 +836,21 @@ void PresentationServiceDelegateImpl::JoinSession( |
| error_cb.Run(content::PresentationError( |
| content::PRESENTATION_ERROR_NO_PRESENTATION_FOUND, |
| "Invalid presentation arguments.")); |
| + return; |
| + } |
| + |
| + url::Origin origin = url::Origin(GetLastCommittedURLForFrame( |
|
mark a. foltz
2016/12/07 04:19:01
Use a const ref
takumif
2016/12/08 00:01:30
Done.
|
| + RenderFrameHostId(render_process_id, render_frame_id), web_contents_)); |
| + |
| +#if !defined(OS_ANDROID) |
| + if (IsAutoJoinPresentationId(presentation_id) && |
| + ShouldCancelAutoJoinForOrigin(origin)) { |
| + error_cb.Run(content::PresentationError( |
| + content::PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED, |
| + "Auto-join request cancelled by user preferences.")); |
| + return; |
| } |
| +#endif // !defined(OS_ANDROID) |
| // TODO(crbug.com/627655): Handle multiple URLs. |
| const GURL& presentation_url = presentation_urls[0]; |
| @@ -839,12 +860,9 @@ void PresentationServiceDelegateImpl::JoinSession( |
| base::Bind(&PresentationServiceDelegateImpl::OnJoinRouteResponse, |
| weak_factory_.GetWeakPtr(), render_process_id, render_frame_id, |
| presentation_url, presentation_id, success_cb, error_cb)); |
| - router_->JoinRoute( |
| - MediaSourceForPresentationUrl(presentation_url).id(), presentation_id, |
| - GetLastCommittedURLForFrame( |
| - RenderFrameHostId(render_process_id, render_frame_id), web_contents_) |
| - .GetOrigin(), |
| - web_contents_, route_response_callbacks, base::TimeDelta(), incognito); |
| + router_->JoinRoute(MediaSourceForPresentationUrl(presentation_url).id(), |
| + presentation_id, origin.GetURL(), web_contents_, |
| + route_response_callbacks, base::TimeDelta(), incognito); |
| } |
| void PresentationServiceDelegateImpl::CloseConnection( |
| @@ -977,4 +995,20 @@ bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest( |
| render_frame_host_id, source_id); |
| } |
| +#if !defined(OS_ANDROID) |
| +bool PresentationServiceDelegateImpl::ShouldCancelAutoJoinForOrigin( |
| + const url::Origin& origin) const { |
| + Profile* profile = |
| + Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
| + // If this is a guest or incognito profile, ignore the preferences. |
|
mark a. foltz
2016/12/07 04:19:01
The design doc describes how to override prefs in
takumif
2016/12/08 00:01:30
We are using user_prefs (checked by calling PrefSe
|
| + if (profile->IsOffTheRecord()) |
| + return false; |
| + |
| + const base::ListValue* origins = |
| + profile->GetPrefs()->GetList(prefs::kMediaRouterTabMirroringSources); |
| + return origins && |
| + origins->Find(base::StringValue(origin.Serialize())) != origins->end(); |
| +} |
| +#endif // !defined(OS_ANDROID) |
| + |
| } // namespace media_router |