| 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 a8ff8a1c1813494797c0692fcaa9f9fc3705f956..ad69808749ce7dd72bfd8aedcdc801c2c8f82e9b 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,8 +15,6 @@
|
| #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"
|
| @@ -54,9 +52,10 @@
|
| // will look like.
|
| class MediaRouterDialogDelegate : public WebDialogDelegate {
|
| public:
|
| - explicit MediaRouterDialogDelegate(
|
| + MediaRouterDialogDelegate(base::WeakPtr<MediaRouterAction> action,
|
| const base::WeakPtr<MediaRouterDialogControllerImpl>& controller)
|
| - : controller_(controller) {}
|
| + : action_(action),
|
| + controller_(controller) {}
|
| ~MediaRouterDialogDelegate() override {}
|
|
|
| // WebDialogDelegate implementation.
|
| @@ -78,13 +77,7 @@
|
| // MediaRouterUI adds its own message handlers.
|
| }
|
|
|
| - 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();
|
| - }
|
| + void GetDialogSize(gfx::Size* size) const override;
|
|
|
| std::string GetDialogArgs() const override {
|
| return std::string();
|
| @@ -93,6 +86,8 @@
|
| 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 {
|
| @@ -105,10 +100,19 @@
|
| }
|
|
|
| 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
|
|
|
| @@ -156,10 +160,7 @@
|
| 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() {
|
| @@ -172,7 +173,12 @@
|
|
|
| void MediaRouterDialogControllerImpl::SetMediaRouterAction(
|
| const base::WeakPtr<MediaRouterAction>& action) {
|
| - action_ = action;
|
| + if (!action_)
|
| + action_ = action;
|
| +}
|
| +
|
| +bool MediaRouterDialogControllerImpl::IsShowingMediaRouterDialog() const {
|
| + return GetMediaRouterDialog() != nullptr;
|
| }
|
|
|
| void MediaRouterDialogControllerImpl::UpdateMaxDialogSize() {
|
| @@ -202,25 +208,6 @@
|
| }
|
| }
|
|
|
| -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)
|
| @@ -248,7 +235,7 @@
|
| // |web_dialog_delegate|'s owner is |constrained_delegate|.
|
| // |constrained_delegate| is owned by the parent |views::View|.
|
| WebDialogDelegate* web_dialog_delegate =
|
| - new MediaRouterDialogDelegate(weak_ptr_factory_.GetWeakPtr());
|
| + new MediaRouterDialogDelegate(action_, weak_ptr_factory_.GetWeakPtr());
|
|
|
| // |ShowConstrainedWebDialogWithAutoResize()| will end up creating
|
| // ConstrainedWebDialogDelegateViewViews containing a WebContents containing
|
| @@ -279,15 +266,14 @@
|
|
|
| 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(
|
| @@ -309,9 +295,6 @@
|
| media_router_dialog_pending_ = false;
|
|
|
| PopulateDialog(media_router_dialog);
|
| -
|
| - if (action_)
|
| - action_->OnDialogShown();
|
| }
|
|
|
| void MediaRouterDialogControllerImpl::PopulateDialog(
|
| @@ -342,19 +325,4 @@
|
| }
|
| }
|
|
|
| -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
|
|
|