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

Side by Side Diff: chrome/browser/ui/webui/media_router/media_router_dialog_controller_impl.cc

Issue 2410553002: Show Media Router toolbar icon ephemerally for MR dialogs (Closed)
Patch Set: Address Mark's comments Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/media_router/media_router_dialog_controller_im pl.h" 5 #include "chrome/browser/ui/webui/media_router/media_router_dialog_controller_im pl.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/trace_event/trace_event.h" 13 #include "base/trace_event/trace_event.h"
14 #include "build/build_config.h" 14 #include "build/build_config.h"
15 #include "chrome/browser/media/router/media_router_ui_service.h"
15 #include "chrome/browser/media/router/presentation_service_delegate_impl.h" 16 #include "chrome/browser/media/router/presentation_service_delegate_impl.h"
16 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/ui/browser_finder.h" 18 #include "chrome/browser/ui/browser_finder.h"
18 #include "chrome/browser/ui/browser_window.h" 19 #include "chrome/browser/ui/browser_window.h"
19 #include "chrome/browser/ui/toolbar/media_router_action.h" 20 #include "chrome/browser/ui/toolbar/media_router_action.h"
20 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h" 21 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h"
21 #include "chrome/browser/ui/webui/media_router/media_router_ui.h" 22 #include "chrome/browser/ui/webui/media_router/media_router_ui.h"
22 #include "chrome/common/url_constants.h" 23 #include "chrome/common/url_constants.h"
23 #include "components/guest_view/browser/guest_view_base.h" 24 #include "components/guest_view/browser/guest_view_base.h"
24 #include "components/web_modal/web_contents_modal_dialog_host.h" 25 #include "components/web_modal/web_contents_modal_dialog_host.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 return false; 104 return false;
104 } 105 }
105 106
106 private: 107 private:
107 base::WeakPtr<MediaRouterAction> action_; 108 base::WeakPtr<MediaRouterAction> action_;
108 base::WeakPtr<MediaRouterDialogControllerImpl> controller_; 109 base::WeakPtr<MediaRouterDialogControllerImpl> controller_;
109 110
110 DISALLOW_COPY_AND_ASSIGN(MediaRouterDialogDelegate); 111 DISALLOW_COPY_AND_ASSIGN(MediaRouterDialogDelegate);
111 }; 112 };
112 113
114 MediaRouterActionController* GetActionController(WebContents* web_contents) {
115 Profile* profile =
116 Profile::FromBrowserContext(web_contents->GetBrowserContext());
117 return MediaRouterUIService::Get(profile)->action_controller();
118 }
119
113 } // namespace 120 } // namespace
114 121
115 // static 122 // static
116 MediaRouterDialogControllerImpl* 123 MediaRouterDialogControllerImpl*
117 MediaRouterDialogControllerImpl::GetOrCreateForWebContents( 124 MediaRouterDialogControllerImpl::GetOrCreateForWebContents(
118 WebContents* web_contents) { 125 WebContents* web_contents) {
119 DCHECK(web_contents); 126 DCHECK(web_contents);
120 // This call does nothing if the controller already exists. 127 // This call does nothing if the controller already exists.
121 MediaRouterDialogControllerImpl::CreateForWebContents(web_contents); 128 MediaRouterDialogControllerImpl::CreateForWebContents(web_contents);
122 return MediaRouterDialogControllerImpl::FromWebContents(web_contents); 129 return MediaRouterDialogControllerImpl::FromWebContents(web_contents);
(...skipping 26 matching lines...) Expand all
149 dialog_controller_->CloseMediaRouterDialog(); 156 dialog_controller_->CloseMediaRouterDialog();
150 } 157 }
151 158
152 MediaRouterDialogControllerImpl* const dialog_controller_; 159 MediaRouterDialogControllerImpl* const dialog_controller_;
153 }; 160 };
154 161
155 MediaRouterDialogControllerImpl::MediaRouterDialogControllerImpl( 162 MediaRouterDialogControllerImpl::MediaRouterDialogControllerImpl(
156 WebContents* web_contents) 163 WebContents* web_contents)
157 : MediaRouterDialogController(web_contents), 164 : MediaRouterDialogController(web_contents),
158 media_router_dialog_pending_(false), 165 media_router_dialog_pending_(false),
166 action_controller_(GetActionController(web_contents)),
159 weak_ptr_factory_(this) { 167 weak_ptr_factory_(this) {
168 DCHECK(action_controller_);
160 } 169 }
161 170
162 MediaRouterDialogControllerImpl::~MediaRouterDialogControllerImpl() { 171 MediaRouterDialogControllerImpl::~MediaRouterDialogControllerImpl() {
172 Reset();
163 } 173 }
164 174
165 WebContents* MediaRouterDialogControllerImpl::GetMediaRouterDialog() const { 175 WebContents* MediaRouterDialogControllerImpl::GetMediaRouterDialog() const {
166 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 176 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
167 return dialog_observer_.get() ? dialog_observer_->web_contents() : nullptr; 177 return dialog_observer_.get() ? dialog_observer_->web_contents() : nullptr;
168 } 178 }
169 179
170 void MediaRouterDialogControllerImpl::SetMediaRouterAction( 180 void MediaRouterDialogControllerImpl::SetMediaRouterAction(
171 const base::WeakPtr<MediaRouterAction>& action) { 181 const base::WeakPtr<MediaRouterAction>& action) {
172 action_ = action; 182 action_ = action;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 media_router_dialog->GetWebUI()->GetController()); 265 media_router_dialog->GetWebUI()->GetController());
256 DCHECK(media_router_ui); 266 DCHECK(media_router_ui);
257 media_router_ui->SetUIInitializationTimer(dialog_creation_time); 267 media_router_ui->SetUIInitializationTimer(dialog_creation_time);
258 } 268 }
259 269
260 media_router_dialog_pending_ = true; 270 media_router_dialog_pending_ = true;
261 271
262 dialog_observer_.reset(new DialogWebContentsObserver( 272 dialog_observer_.reset(new DialogWebContentsObserver(
263 media_router_dialog, this)); 273 media_router_dialog, this));
264 274
275 // The |action_controller_| must be notified after |action_| to avoid a UI
msw 2016/11/04 00:07:16 nit: Maybe override OnDialogShown in the impl to c
takumif 2016/11/09 04:37:27 Sorry, I don't quite understand this comment. (The
msw 2016/11/09 20:32:33 hmm, it's odd that the *dialog* controller tracks
276 // bug in which the drop shadow is drawn in an incorrect position.
265 if (action_) 277 if (action_)
266 action_->OnDialogShown(); 278 action_->OnDialogShown();
279 action_controller_->OnDialogShown();
267 } 280 }
268 281
269 void MediaRouterDialogControllerImpl::Reset() { 282 void MediaRouterDialogControllerImpl::Reset() {
283 if (IsShowingMediaRouterDialog()) {
msw 2016/11/04 00:07:16 Is it possible that multiple dialogs are showing w
takumif 2016/11/09 04:37:27 Each MediaRouterDialogControllerImpl can have at m
msw 2016/11/09 20:32:34 Acknowledged.
284 if (action_)
285 action_->OnDialogHidden();
286 action_controller_->OnDialogHidden();
287 }
270 MediaRouterDialogController::Reset(); 288 MediaRouterDialogController::Reset();
271 dialog_observer_.reset(); 289 dialog_observer_.reset();
272 if (action_)
273 action_->OnDialogHidden();
274 } 290 }
275 291
276 void MediaRouterDialogControllerImpl::OnDialogNavigated( 292 void MediaRouterDialogControllerImpl::OnDialogNavigated(
277 const content::LoadCommittedDetails& details) { 293 const content::LoadCommittedDetails& details) {
278 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 294 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
279 WebContents* media_router_dialog = GetMediaRouterDialog(); 295 WebContents* media_router_dialog = GetMediaRouterDialog();
280 CHECK(media_router_dialog); 296 CHECK(media_router_dialog);
281 ui::PageTransition transition_type = details.entry->GetTransitionType(); 297 ui::PageTransition transition_type = details.entry->GetTransitionType();
282 content::NavigationType nav_type = details.type; 298 content::NavigationType nav_type = details.type;
283 299
(...skipping 29 matching lines...) Expand all
313 PresentationServiceDelegateImpl::FromWebContents(initiator()); 329 PresentationServiceDelegateImpl::FromWebContents(initiator());
314 if (!create_connection_request.get()) { 330 if (!create_connection_request.get()) {
315 media_router_ui->InitWithDefaultMediaSource(initiator(), delegate); 331 media_router_ui->InitWithDefaultMediaSource(initiator(), delegate);
316 } else { 332 } else {
317 media_router_ui->InitWithPresentationSessionRequest( 333 media_router_ui->InitWithPresentationSessionRequest(
318 initiator(), delegate, std::move(create_connection_request)); 334 initiator(), delegate, std::move(create_connection_request));
319 } 335 }
320 } 336 }
321 337
322 } // namespace media_router 338 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698