Commit fa3afad3 authored by Anna Maria's avatar Anna Maria Committed by Commit Bot

[Local media Casting] Correcting issue where local media cast files will not...

[Local media Casting] Correcting issue where local media cast files will not work with media remoting.

This is because tab:0 is an invalid source, so we correct that to use the actual tab number in the source. This requires a different create route flow because it seems up to now that there has been an assumption that sources do not change, but for the local file case this is not so because the tab must be opened.

Bug: 721802
Change-Id: I69ec9d1dd981e7d445a1bb823f301911cd37058c
Reviewed-on: https://chromium-review.googlesource.com/596607Reviewed-by: default avatarDerek Cheng <imcheng@chromium.org>
Commit-Queue: Anna Maria <paezagon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491392}
parent c7ad64f1
...@@ -134,16 +134,17 @@ Browser* MediaRouterUI::GetBrowser() { ...@@ -134,16 +134,17 @@ Browser* MediaRouterUI::GetBrowser() {
return chrome::FindBrowserWithWebContents(initiator()); return chrome::FindBrowserWithWebContents(initiator());
} }
void MediaRouterUI::OpenTabWithUrl(const GURL url) { content::WebContents* MediaRouterUI::OpenTabWithUrl(const GURL url) {
// Check if the current page is a new tab. If so open file in current page. // Check if the current page is a new tab. If so open file in current page.
// If not then open a new page. // If not then open a new page.
if (initiator_->GetVisibleURL() == chrome::kChromeUINewTabURL) { if (initiator_->GetVisibleURL() == chrome::kChromeUINewTabURL) {
content::NavigationController::LoadURLParams load_params(url); content::NavigationController::LoadURLParams load_params(url);
load_params.transition_type = ui::PAGE_TRANSITION_GENERATED; load_params.transition_type = ui::PAGE_TRANSITION_GENERATED;
initiator_->GetController().LoadURLWithParams(load_params); initiator_->GetController().LoadURLWithParams(load_params);
return initiator_;
} else { } else {
initiator_ = chrome::AddSelectedTabWithURL(GetBrowser(), url, return chrome::AddSelectedTabWithURL(GetBrowser(), url,
ui::PAGE_TRANSITION_LINK); ui::PAGE_TRANSITION_LINK);
} }
} }
...@@ -488,18 +489,27 @@ bool MediaRouterUI::CreateRoute(const MediaSink::Id& sink_id, ...@@ -488,18 +489,27 @@ bool MediaRouterUI::CreateRoute(const MediaSink::Id& sink_id,
base::TimeDelta timeout; base::TimeDelta timeout;
bool incognito; bool incognito;
// Default the tab casting the content to the initiator, and change if
// necessary.
content::WebContents* tab_contents = initiator_;
if (cast_mode == MediaCastMode::LOCAL_FILE) { if (cast_mode == MediaCastMode::LOCAL_FILE) {
GURL url = media_router_file_dialog_->GetLastSelectedFileUrl(); GURL url = media_router_file_dialog_->GetLastSelectedFileUrl();
OpenTabWithUrl(url); tab_contents = OpenTabWithUrl(url);
}
if (!SetRouteParameters(sink_id, cast_mode, &source_id, &origin, SessionID::id_type tab_id = SessionTabHelper::IdForTab(tab_contents);
&route_response_callbacks, &timeout, &incognito)) { source_id = MediaSourceForTab(tab_id).id();
SetLocalFileRouteParameters(sink_id, &origin, &route_response_callbacks,
&timeout, &incognito);
} else if (!SetRouteParameters(sink_id, cast_mode, &source_id, &origin,
&route_response_callbacks, &timeout,
&incognito)) {
SendIssueForUnableToCast(cast_mode); SendIssueForUnableToCast(cast_mode);
return false; return false;
} }
router_->CreateRoute(source_id, sink_id, origin, initiator_, router_->CreateRoute(source_id, sink_id, origin, tab_contents,
std::move(route_response_callbacks), timeout, incognito); std::move(route_response_callbacks), timeout, incognito);
return true; return true;
} }
...@@ -583,18 +593,43 @@ bool MediaRouterUI::SetRouteParameters( ...@@ -583,18 +593,43 @@ bool MediaRouterUI::SetRouteParameters(
base::BindOnce(&MediaRouterUI::MaybeReportCastingSource, base::BindOnce(&MediaRouterUI::MaybeReportCastingSource,
weak_factory_.GetWeakPtr(), cast_mode)); weak_factory_.GetWeakPtr(), cast_mode));
if (cast_mode == MediaCastMode::LOCAL_FILE) {
route_response_callbacks->push_back(
base::BindOnce(&MediaRouterUI::MaybeReportFileInformation,
weak_factory_.GetWeakPtr()));
}
*timeout = GetRouteRequestTimeout(cast_mode); *timeout = GetRouteRequestTimeout(cast_mode);
*incognito = Profile::FromWebUI(web_ui())->IsOffTheRecord(); *incognito = Profile::FromWebUI(web_ui())->IsOffTheRecord();
return true; return true;
} }
// TODO(Issue 751317) This function and the above function are messy, this code
// would be much neater if the route params were combined in a single struct,
// which will require mojo changes as well.
bool MediaRouterUI::SetLocalFileRouteParameters(
const MediaSink::Id& sink_id,
url::Origin* origin,
std::vector<MediaRouteResponseCallback>* route_response_callbacks,
base::TimeDelta* timeout,
bool* incognito) {
// Use a placeholder URL as origin for local file casting, which is
// essentially mirroring.
*origin = url::Origin(GURL(chrome::kChromeUIMediaRouterURL));
route_response_callbacks->push_back(base::BindOnce(
&MediaRouterUI::OnRouteResponseReceived, weak_factory_.GetWeakPtr(),
current_route_request_id_, sink_id, MediaCastMode::LOCAL_FILE,
base::UTF8ToUTF16(GetTruncatedPresentationRequestSourceName())));
route_response_callbacks->push_back(
base::BindOnce(&MediaRouterUI::MaybeReportCastingSource,
weak_factory_.GetWeakPtr(), MediaCastMode::LOCAL_FILE));
route_response_callbacks->push_back(base::BindOnce(
&MediaRouterUI::MaybeReportFileInformation, weak_factory_.GetWeakPtr()));
*timeout = GetRouteRequestTimeout(MediaCastMode::LOCAL_FILE);
*incognito = Profile::FromWebUI(web_ui())->IsOffTheRecord();
return true;
}
bool MediaRouterUI::ConnectRoute(const MediaSink::Id& sink_id, bool MediaRouterUI::ConnectRoute(const MediaSink::Id& sink_id,
const MediaRoute::Id& route_id) { const MediaRoute::Id& route_id) {
MediaSource::Id source_id; MediaSource::Id source_id;
......
...@@ -267,8 +267,8 @@ class MediaRouterUI ...@@ -267,8 +267,8 @@ class MediaRouterUI
// Retrieves the browser associated with this UI. // Retrieves the browser associated with this UI.
Browser* GetBrowser(); Browser* GetBrowser();
// Opens the URL in a tab which is then |initator_|. // Opens the URL in a tab, returns the tab it was opened in.
void OpenTabWithUrl(const GURL url); content::WebContents* OpenTabWithUrl(const GURL url);
// Methods for MediaRouterFileDialogDelegate // Methods for MediaRouterFileDialogDelegate
void FileDialogFileSelected(const ui::SelectedFileInfo& file_info) override; void FileDialogFileSelected(const ui::SelectedFileInfo& file_info) override;
...@@ -341,6 +341,15 @@ class MediaRouterUI ...@@ -341,6 +341,15 @@ class MediaRouterUI
base::TimeDelta* timeout, base::TimeDelta* timeout,
bool* incognito); bool* incognito);
// Populates route-related parameters for CreateRoute() when doing file
// casting.
bool SetLocalFileRouteParameters(
const MediaSink::Id& sink_id,
url::Origin* origin,
std::vector<MediaRouteResponseCallback>* route_response_callbacks,
base::TimeDelta* timeout,
bool* incognito);
// Updates the set of supported cast modes and sends the updated set to // Updates the set of supported cast modes and sends the updated set to
// |handler_|. // |handler_|.
void UpdateCastModes(); void UpdateCastModes();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment