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

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: Address Mark's comment, trybot failures, rebase Created 4 years, 4 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..a8ff8a1c1813494797c0692fcaa9f9fc3705f956 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,
+ explicit MediaRouterDialogDelegate(
const base::WeakPtr<MediaRouterDialogControllerImpl>& controller)
- : action_(action),
- controller_(controller) {}
+ : controller_(controller) {}
~MediaRouterDialogDelegate() override {}
// WebDialogDelegate implementation.
@@ -77,7 +78,13 @@ class MediaRouterDialogDelegate : public WebDialogDelegate {
// MediaRouterUI adds its own message handlers.
}
- void GetDialogSize(gfx::Size* size) const override;
+ void GetDialogSize(gfx::Size* size) const override {
+ DCHECK(size);
+ // GetDialogSize() is called when the browser window resizes. We may want to
+ // update the maximum height of the dialog and scale the WebUI to the new
+ // height. |size| is not set because the dialog is auto-resizeable.
+ controller_->UpdateMaxDialogSize();
+ }
std::string GetDialogArgs() const override {
return std::string();
@@ -86,8 +93,6 @@ 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();
}
void OnCloseContents(WebContents* source, bool* out_close_dialog) override {
@@ -100,20 +105,11 @@ class MediaRouterDialogDelegate : public WebDialogDelegate {
}
private:
- base::WeakPtr<MediaRouterAction> action_;
base::WeakPtr<MediaRouterDialogControllerImpl> controller_;
DISALLOW_COPY_AND_ASSIGN(MediaRouterDialogDelegate);
};
-void MediaRouterDialogDelegate::GetDialogSize(gfx::Size* size) const {
- DCHECK(size);
- // GetDialogSize() is called when the browser window resizes. We may want to
- // update the maximum height of the dialog and scale the WebUI to the new
- // height. |size| is not set because the dialog is auto-resizeable.
- controller_->UpdateMaxDialogSize();
-}
-
} // namespace
// static
@@ -160,7 +156,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,12 +172,7 @@ WebContents* MediaRouterDialogControllerImpl::GetMediaRouterDialog() const {
void MediaRouterDialogControllerImpl::SetMediaRouterAction(
const base::WeakPtr<MediaRouterAction>& action) {
- if (!action_)
- action_ = action;
-}
-
-bool MediaRouterDialogControllerImpl::IsShowingMediaRouterDialog() const {
- return GetMediaRouterDialog() != nullptr;
+ action_ = action;
}
void MediaRouterDialogControllerImpl::UpdateMaxDialogSize() {
@@ -208,6 +202,25 @@ void MediaRouterDialogControllerImpl::UpdateMaxDialogSize() {
}
}
+bool MediaRouterDialogControllerImpl::IsShowingMediaRouterDialog() const {
+ return GetMediaRouterDialog() != nullptr;
+}
+
+bool MediaRouterDialogControllerImpl::ShowMediaRouterDialog() {
+ if (!action_)
+ ShowMediaRouterAction();
+ return MediaRouterDialogController::ShowMediaRouterDialog();
+}
+
+void MediaRouterDialogControllerImpl::ActiveTabChanged(
+ content::WebContents* old_contents,
+ content::WebContents* new_contents,
+ int index,
+ int reason) {
+ if (IsShowingMediaRouterDialog() && !action_)
+ ShowMediaRouterAction();
+}
+
void MediaRouterDialogControllerImpl::CloseMediaRouterDialog() {
WebContents* media_router_dialog = GetMediaRouterDialog();
if (!media_router_dialog)
@@ -235,7 +248,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,14 +279,15 @@ void MediaRouterDialogControllerImpl::CreateMediaRouterDialog() {
dialog_observer_.reset(new DialogWebContentsObserver(
media_router_dialog, this));
-
- if (action_)
- action_->OnPopupShown();
}
void MediaRouterDialogControllerImpl::Reset() {
MediaRouterDialogController::Reset();
dialog_observer_.reset();
+ if (action_) {
+ action_->OnDialogHidden();
+ action_->MaybeRemoveAction();
+ }
}
void MediaRouterDialogControllerImpl::OnDialogNavigated(
@@ -295,6 +309,9 @@ void MediaRouterDialogControllerImpl::OnDialogNavigated(
media_router_dialog_pending_ = false;
PopulateDialog(media_router_dialog);
+
+ if (action_)
+ action_->OnDialogShown();
}
void MediaRouterDialogControllerImpl::PopulateDialog(
@@ -325,4 +342,19 @@ void MediaRouterDialogControllerImpl::PopulateDialog(
}
}
+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
« no previous file with comments | « chrome/browser/ui/webui/media_router/media_router_dialog_controller_impl.h ('k') | chrome/common/pref_names.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698