Commit 1924f747 authored by jdufault's avatar jdufault Committed by Commit bot

Allow the cast tray to function as expected when the installed extension is missing API methods.

BUG=489445

Review URL: https://codereview.chromium.org/1145833003

Cr-Commit-Position: refs/heads/master@{#330663}
parent 04192cf9
...@@ -278,6 +278,12 @@ Press Ctrl+Alt+Z to disable. ...@@ -278,6 +278,12 @@ Press Ctrl+Alt+Z to disable.
<message name="IDS_ASH_STATUS_TRAY_CAST_STOP" desc="The label used in the tray popup to stop casting."> <message name="IDS_ASH_STATUS_TRAY_CAST_STOP" desc="The label used in the tray popup to stop casting.">
Stop Stop
</message> </message>
<message name="IDS_ASH_STATUS_TRAY_CAST_UNKNOWN_CAST_TYPE" desc="The label used when we have detected we are casting but do not know if we are casting a tab or the desktop.">
Casting
</message>
<message name="IDS_ASH_STATUS_TRAY_CAST_UNKNOWN_RECEIVER" desc="The label used when we have detected we are casting but do not know the name of the receiver.">
Unknown receiver
</message>
<message name="IDS_ASH_STATUS_TRAY_BLUETOOTH" desc="The label used as the header in the bluetooth popup."> <message name="IDS_ASH_STATUS_TRAY_BLUETOOTH" desc="The label used as the header in the bluetooth popup.">
Bluetooth Bluetooth
......
...@@ -83,13 +83,8 @@ class CastConfigDelegate { ...@@ -83,13 +83,8 @@ class CastConfigDelegate {
// Cast to a receiver specified by |receiver_id|. // Cast to a receiver specified by |receiver_id|.
virtual void CastToReceiver(const std::string& receiver_id) = 0; virtual void CastToReceiver(const std::string& receiver_id) = 0;
// Stop ongoing cast. The |activity_id| is the unique identifier associated // Stop an ongoing cast.
// with the ongoing cast. Each receiver has only one possible activity virtual void StopCasting() = 0;
// associated with it. The |activity_id| is available by invoking
// GetReceiversAndActivities(); if the receiver is currently casting, then the
// associated activity data will have an id. This id can be used to stop the
// cast in this method.
virtual void StopCasting(const std::string& activity_id) = 0;
// Opens Options page for cast. // Opens Options page for cast.
virtual void LaunchCastOptions() = 0; virtual void LaunchCastOptions() = 0;
......
...@@ -38,28 +38,6 @@ namespace ash { ...@@ -38,28 +38,6 @@ namespace ash {
namespace { namespace {
const int kStopButtonRightPadding = 18; const int kStopButtonRightPadding = 18;
// Callback helper for StopCast().
void StopCastCallback(
CastConfigDelegate* cast_config,
const CastConfigDelegate::ReceiversAndActivites& receivers_activities) {
for (auto& item : receivers_activities) {
CastConfigDelegate::Activity activity = item.second.activity;
if (activity.allow_stop && activity.id.empty() == false)
cast_config->StopCasting(activity.id);
}
}
// Stops currently casting device.
void StopCast() {
CastConfigDelegate* cast_config =
Shell::GetInstance()->system_tray_delegate()->GetCastConfigDelegate();
if (cast_config && cast_config->HasCastExtension()) {
cast_config->GetReceiversAndActivities(
base::Bind(&StopCastCallback, cast_config));
}
}
} // namespace } // namespace
namespace tray { namespace tray {
...@@ -182,12 +160,16 @@ CastCastView::CastCastView(CastConfigDelegate* cast_config_delegate) ...@@ -182,12 +160,16 @@ CastCastView::CastCastView(CastConfigDelegate* cast_config_delegate)
title_ = new views::Label; title_ = new views::Label;
title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); title_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
title_->SetFontList(bundle.GetFontList(ui::ResourceBundle::BoldFont)); title_->SetFontList(bundle.GetFontList(ui::ResourceBundle::BoldFont));
title_->SetText(
bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_CAST_UNKNOWN_CAST_TYPE));
label_container_->AddChildView(title_); label_container_->AddChildView(title_);
details_ = new views::Label; details_ = new views::Label;
details_->SetHorizontalAlignment(gfx::ALIGN_LEFT); details_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
details_->SetMultiLine(false); details_->SetMultiLine(false);
details_->SetEnabledColor(kHeaderTextColorNormal); details_->SetEnabledColor(kHeaderTextColorNormal);
details_->SetText(
bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_CAST_UNKNOWN_RECEIVER));
label_container_->AddChildView(details_); label_container_->AddChildView(details_);
AddChildView(label_container_); AddChildView(label_container_);
...@@ -270,7 +252,7 @@ void CastCastView::UpdateLabelCallback( ...@@ -270,7 +252,7 @@ void CastCastView::UpdateLabelCallback(
void CastCastView::ButtonPressed(views::Button* sender, void CastCastView::ButtonPressed(views::Button* sender,
const ui::Event& event) { const ui::Event& event) {
DCHECK(sender == stop_button_); DCHECK(sender == stop_button_);
StopCast(); cast_config_delegate_->StopCasting();
} }
// This view by itself does very little. It acts as a front-end for managing // This view by itself does very little. It acts as a front-end for managing
......
...@@ -138,8 +138,14 @@ void CastConfigDelegateChromeos::CastToReceiver( ...@@ -138,8 +138,14 @@ void CastConfigDelegateChromeos::CastToReceiver(
"');"); "');");
} }
void CastConfigDelegateChromeos::StopCasting(const std::string& activity_id) { void CastConfigDelegateChromeos::StopCasting() {
ExecuteJavaScript("backgroundSetup.stopCastMirroring('user-stop');"); ExecuteJavaScript("backgroundSetup.stopCastMirroring('user-stop');");
// TODO(jdufault): Remove this after stopCastMirroring is properly exported.
// The current beta/release versions of the cast extension do not export
// stopCastMirroring, so we will also try to call the minified version.
// See crbug.com/489929.
ExecuteJavaScript("backgroundSetup.Qu('user-stop');");
} }
void CastConfigDelegateChromeos::LaunchCastOptions() { void CastConfigDelegateChromeos::LaunchCastOptions() {
......
...@@ -27,7 +27,7 @@ class CastConfigDelegateChromeos : public ash::CastConfigDelegate { ...@@ -27,7 +27,7 @@ class CastConfigDelegateChromeos : public ash::CastConfigDelegate {
void GetReceiversAndActivities( void GetReceiversAndActivities(
const ReceiversAndActivitesCallback& callback) override; const ReceiversAndActivitesCallback& callback) override;
void CastToReceiver(const std::string& receiver_id) override; void CastToReceiver(const std::string& receiver_id) override;
void StopCasting(const std::string& activity_id) override; void StopCasting() override;
void LaunchCastOptions() override; void LaunchCastOptions() override;
DISALLOW_COPY_AND_ASSIGN(CastConfigDelegateChromeos); DISALLOW_COPY_AND_ASSIGN(CastConfigDelegateChromeos);
......
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