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

Unified 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: Address Mark and Jennifer's comments 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 side-by-side diff with in-line comments
Download patch
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 67d43a3280846e406484955230cfa8b30adb6c65..c2603932ed1cb2c39e6f980431b14ade27930caf 100644
--- a/chrome/browser/media/router/presentation_service_delegate_impl.cc
+++ b/chrome/browser/media/router/presentation_service_delegate_impl.cc
@@ -32,6 +32,12 @@
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
+#if !defined(OS_ANDROID)
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/pref_names.h"
+#include "components/prefs/pref_service.h"
+#endif
+
DEFINE_WEB_CONTENTS_USER_DATA_KEY(
media_router::PresentationServiceDelegateImpl);
@@ -828,6 +834,19 @@ void PresentationServiceDelegateImpl::JoinSession(
return;
}
+ const url::Origin& origin = url::Origin(GetLastCommittedURLForFrame(
+ 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];
bool incognito = web_contents_->GetBrowserContext()->IsOffTheRecord();
@@ -836,12 +855,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 +993,16 @@ bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest(
render_frame_host_id, source_id);
}
+#if !defined(OS_ANDROID)
+bool PresentationServiceDelegateImpl::ShouldCancelAutoJoinForOrigin(
+ const url::Origin& origin) const {
+ const base::ListValue* origins =
+ Profile::FromBrowserContext(web_contents_->GetBrowserContext())
+ ->GetPrefs()
+ ->GetList(prefs::kMediaRouterTabMirroringSources);
+ return origins &&
+ origins->Find(base::StringValue(origin.Serialize())) != origins->end();
+}
+#endif // !defined(OS_ANDROID)
+
} // namespace media_router

Powered by Google App Engine
This is Rietveld 408576698