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

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: Deleted the first patch set on accident, responded to Mark's comments inline below Created 4 years, 2 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 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 }; 106 };
106 107
107 void MediaRouterDialogDelegate::GetDialogSize(gfx::Size* size) const { 108 void MediaRouterDialogDelegate::GetDialogSize(gfx::Size* size) const {
108 DCHECK(size); 109 DCHECK(size);
109 // GetDialogSize() is called when the browser window resizes. We may want to 110 // GetDialogSize() is called when the browser window resizes. We may want to
110 // update the maximum height of the dialog and scale the WebUI to the new 111 // update the maximum height of the dialog and scale the WebUI to the new
111 // height. |size| is not set because the dialog is auto-resizeable. 112 // height. |size| is not set because the dialog is auto-resizeable.
112 controller_->UpdateMaxDialogSize(); 113 controller_->UpdateMaxDialogSize();
113 } 114 }
114 115
116 MediaRouterActionController* GetActionController(WebContents* web_contents) {
117 Profile* profile =
118 Profile::FromBrowserContext(web_contents->GetBrowserContext());
119 return MediaRouterUIService::Get(profile)->action_controller();
120 }
121
115 } // namespace 122 } // namespace
116 123
117 // static 124 // static
118 MediaRouterDialogControllerImpl* 125 MediaRouterDialogControllerImpl*
119 MediaRouterDialogControllerImpl::GetOrCreateForWebContents( 126 MediaRouterDialogControllerImpl::GetOrCreateForWebContents(
120 WebContents* web_contents) { 127 WebContents* web_contents) {
121 DCHECK(web_contents); 128 DCHECK(web_contents);
122 // This call does nothing if the controller already exists. 129 // This call does nothing if the controller already exists.
123 MediaRouterDialogControllerImpl::CreateForWebContents(web_contents); 130 MediaRouterDialogControllerImpl::CreateForWebContents(web_contents);
124 return MediaRouterDialogControllerImpl::FromWebContents(web_contents); 131 return MediaRouterDialogControllerImpl::FromWebContents(web_contents);
(...skipping 26 matching lines...) Expand all
151 dialog_controller_->CloseMediaRouterDialog(); 158 dialog_controller_->CloseMediaRouterDialog();
152 } 159 }
153 160
154 MediaRouterDialogControllerImpl* const dialog_controller_; 161 MediaRouterDialogControllerImpl* const dialog_controller_;
155 }; 162 };
156 163
157 MediaRouterDialogControllerImpl::MediaRouterDialogControllerImpl( 164 MediaRouterDialogControllerImpl::MediaRouterDialogControllerImpl(
158 WebContents* web_contents) 165 WebContents* web_contents)
159 : MediaRouterDialogController(web_contents), 166 : MediaRouterDialogController(web_contents),
160 media_router_dialog_pending_(false), 167 media_router_dialog_pending_(false),
161 weak_ptr_factory_(this) { 168 action_controller_(GetActionController(web_contents)),
162 } 169 weak_ptr_factory_(this) {}
mark a. foltz 2016/10/17 18:57:40 Can you DCHECK(action_controller_) here?
takumif 2016/10/27 23:06:38 Done.
163 170
164 MediaRouterDialogControllerImpl::~MediaRouterDialogControllerImpl() { 171 MediaRouterDialogControllerImpl::~MediaRouterDialogControllerImpl() {
172 Reset();
165 } 173 }
166 174
167 WebContents* MediaRouterDialogControllerImpl::GetMediaRouterDialog() const { 175 WebContents* MediaRouterDialogControllerImpl::GetMediaRouterDialog() const {
168 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 176 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
169 return dialog_observer_.get() ? dialog_observer_->web_contents() : nullptr; 177 return dialog_observer_.get() ? dialog_observer_->web_contents() : nullptr;
170 } 178 }
171 179
172 void MediaRouterDialogControllerImpl::SetMediaRouterAction( 180 void MediaRouterDialogControllerImpl::SetMediaRouterAction(
173 const base::WeakPtr<MediaRouterAction>& action) { 181 const base::WeakPtr<MediaRouterAction>& action) {
174 action_ = action; 182 action_ = action;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 media_router_dialog->GetWebUI()->GetController()); 265 media_router_dialog->GetWebUI()->GetController());
258 DCHECK(media_router_ui); 266 DCHECK(media_router_ui);
259 media_router_ui->SetUIInitializationTimer(dialog_creation_time); 267 media_router_ui->SetUIInitializationTimer(dialog_creation_time);
260 } 268 }
261 269
262 media_router_dialog_pending_ = true; 270 media_router_dialog_pending_ = true;
263 271
264 dialog_observer_.reset(new DialogWebContentsObserver( 272 dialog_observer_.reset(new DialogWebContentsObserver(
265 media_router_dialog, this)); 273 media_router_dialog, this));
266 274
275 // The |action_controller_| must be notified after |action_| to avoid a UI
276 // bug in which the drop shadow is drawn in an incorrect position.
267 if (action_) 277 if (action_)
268 action_->OnDialogShown(); 278 action_->OnDialogShown();
279 action_controller_->OnDialogShown();
269 } 280 }
270 281
271 void MediaRouterDialogControllerImpl::Reset() { 282 void MediaRouterDialogControllerImpl::Reset() {
283 if (IsShowingMediaRouterDialog()) {
284 if (action_)
285 action_->OnDialogHidden();
286 action_controller_->OnDialogHidden();
287 }
272 MediaRouterDialogController::Reset(); 288 MediaRouterDialogController::Reset();
273 dialog_observer_.reset(); 289 dialog_observer_.reset();
274 if (action_)
275 action_->OnDialogHidden();
276 } 290 }
277 291
278 void MediaRouterDialogControllerImpl::OnDialogNavigated( 292 void MediaRouterDialogControllerImpl::OnDialogNavigated(
279 const content::LoadCommittedDetails& details) { 293 const content::LoadCommittedDetails& details) {
280 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 294 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
281 WebContents* media_router_dialog = GetMediaRouterDialog(); 295 WebContents* media_router_dialog = GetMediaRouterDialog();
282 CHECK(media_router_dialog); 296 CHECK(media_router_dialog);
283 ui::PageTransition transition_type = details.entry->GetTransitionType(); 297 ui::PageTransition transition_type = details.entry->GetTransitionType();
284 content::NavigationType nav_type = details.type; 298 content::NavigationType nav_type = details.type;
285 299
(...skipping 29 matching lines...) Expand all
315 PresentationServiceDelegateImpl::FromWebContents(initiator()); 329 PresentationServiceDelegateImpl::FromWebContents(initiator());
316 if (!create_connection_request.get()) { 330 if (!create_connection_request.get()) {
317 media_router_ui->InitWithDefaultMediaSource(initiator(), delegate); 331 media_router_ui->InitWithDefaultMediaSource(initiator(), delegate);
318 } else { 332 } else {
319 media_router_ui->InitWithPresentationSessionRequest( 333 media_router_ui->InitWithPresentationSessionRequest(
320 initiator(), delegate, std::move(create_connection_request)); 334 initiator(), delegate, std::move(create_connection_request));
321 } 335 }
322 } 336 }
323 337
324 } // namespace media_router 338 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698