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

Unified Diff: chrome/browser/ui/webui/media_router/media_router_dialog_controller_impl.cc

Issue 2155293002: Show the Cast toolbar icon ephemerally when Cast is in use (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 5 months 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/ui/webui/media_router/media_router_dialog_controller_impl.cc
diff --git a/chrome/browser/ui/webui/media_router/media_router_dialog_controller_impl.cc b/chrome/browser/ui/webui/media_router/media_router_dialog_controller_impl.cc
index ad69808749ce7dd72bfd8aedcdc801c2c8f82e9b..3ae9fada4a6bfeb13226509c5d9f9322d7dd85ac 100644
--- a/chrome/browser/ui/webui/media_router/media_router_dialog_controller_impl.cc
+++ b/chrome/browser/ui/webui/media_router/media_router_dialog_controller_impl.cc
@@ -15,6 +15,8 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h"
+#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h"
#include "chrome/browser/ui/toolbar/media_router_action.h"
#include "chrome/browser/ui/webui/constrained_web_dialog_ui.h"
#include "chrome/browser/ui/webui/media_router/media_router_ui.h"
@@ -52,10 +54,9 @@ constexpr const int kWidth = 340;
// will look like.
class MediaRouterDialogDelegate : public WebDialogDelegate {
public:
- MediaRouterDialogDelegate(base::WeakPtr<MediaRouterAction> action,
+ MediaRouterDialogDelegate(
msw 2016/07/26 19:59:32 nit: explicit.
takumif 2016/07/28 20:04:11 Done.
const base::WeakPtr<MediaRouterDialogControllerImpl>& controller)
- : action_(action),
- controller_(controller) {}
+ : controller_(controller) {}
~MediaRouterDialogDelegate() override {}
// WebDialogDelegate implementation.
@@ -86,8 +87,7 @@ class MediaRouterDialogDelegate : public WebDialogDelegate {
void OnDialogClosed(const std::string& json_retval) override {
// We don't delete |this| here because this class is owned
// by ConstrainedWebDialogDelegate.
- if (action_)
- action_->OnPopupHidden();
+ controller_.get()->OnDialogClosed();
}
void OnCloseContents(WebContents* source, bool* out_close_dialog) override {
@@ -100,7 +100,6 @@ class MediaRouterDialogDelegate : public WebDialogDelegate {
}
private:
- base::WeakPtr<MediaRouterAction> action_;
base::WeakPtr<MediaRouterDialogControllerImpl> controller_;
DISALLOW_COPY_AND_ASSIGN(MediaRouterDialogDelegate);
@@ -160,7 +159,10 @@ MediaRouterDialogControllerImpl::MediaRouterDialogControllerImpl(
WebContents* web_contents)
: MediaRouterDialogController(web_contents),
media_router_dialog_pending_(false),
+ tab_strip_model_observer_(this),
weak_ptr_factory_(this) {
+ tab_strip_model_observer_.Add(
+ chrome::FindBrowserWithWebContents(initiator())->tab_strip_model());
}
MediaRouterDialogControllerImpl::~MediaRouterDialogControllerImpl() {
@@ -173,8 +175,7 @@ WebContents* MediaRouterDialogControllerImpl::GetMediaRouterDialog() const {
void MediaRouterDialogControllerImpl::SetMediaRouterAction(
const base::WeakPtr<MediaRouterAction>& action) {
- if (!action_)
- action_ = action;
+ action_ = action;
}
bool MediaRouterDialogControllerImpl::IsShowingMediaRouterDialog() const {
@@ -235,7 +236,7 @@ void MediaRouterDialogControllerImpl::CreateMediaRouterDialog() {
// |web_dialog_delegate|'s owner is |constrained_delegate|.
// |constrained_delegate| is owned by the parent |views::View|.
WebDialogDelegate* web_dialog_delegate =
- new MediaRouterDialogDelegate(action_, weak_ptr_factory_.GetWeakPtr());
+ new MediaRouterDialogDelegate(weak_ptr_factory_.GetWeakPtr());
// |ShowConstrainedWebDialogWithAutoResize()| will end up creating
// ConstrainedWebDialogDelegateViewViews containing a WebContents containing
@@ -266,9 +267,11 @@ void MediaRouterDialogControllerImpl::CreateMediaRouterDialog() {
dialog_observer_.reset(new DialogWebContentsObserver(
media_router_dialog, this));
+}
+void MediaRouterDialogControllerImpl::OnDialogClosed() {
if (action_)
- action_->OnPopupShown();
msw 2016/07/26 19:59:32 Why doesn't CreateMediaRouterDialog still call OnP
takumif 2016/07/28 20:04:11 The only thing MediaRouterAction::OnPopupShown doe
+ action_->OnPopupHidden();
}
void MediaRouterDialogControllerImpl::Reset() {
@@ -295,6 +298,9 @@ void MediaRouterDialogControllerImpl::OnDialogNavigated(
media_router_dialog_pending_ = false;
PopulateDialog(media_router_dialog);
+
+ if (action_)
+ action_->OnPopupShown();
}
void MediaRouterDialogControllerImpl::PopulateDialog(
@@ -325,4 +331,33 @@ void MediaRouterDialogControllerImpl::PopulateDialog(
}
}
+bool MediaRouterDialogControllerImpl::ShowMediaRouterDialog() {
+ if (!action_)
+ ShowMediaRouterAction();
msw 2016/07/26 19:59:32 Why doesn't the MediaRouterDialogController base c
takumif 2016/07/28 20:04:12 The base class contains logic that's shared across
+ return MediaRouterDialogController::ShowMediaRouterDialog();
+}
+
+void MediaRouterDialogControllerImpl::ActiveTabChanged(
+ content::WebContents* old_contents,
+ content::WebContents* new_contents,
+ int index,
+ int reason) {
+ if (IsShowingMediaRouterDialog() && !action_)
msw 2016/07/26 19:59:32 Can the user actually change tabs while the dialog
takumif 2016/07/28 20:04:11 Yes, the user can switch tabs while the dialog is
+ ShowMediaRouterAction();
+}
+
+void MediaRouterDialogControllerImpl::ShowMediaRouterAction() {
+ Profile* profile =
+ Profile::FromBrowserContext(initiator()->GetBrowserContext());
+ if (!profile)
+ return;
+
+ ToolbarActionsModel* model = ToolbarActionsModel::Get(profile);
+ if (model && !model->HasComponentAction(
+ ComponentToolbarActionsFactory::kMediaRouterActionId)) {
+ model->AddComponentAction(
+ ComponentToolbarActionsFactory::kMediaRouterActionId);
+ }
+}
+
} // namespace media_router

Powered by Google App Engine
This is Rietveld 408576698