OLD | NEW |
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 <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 23 matching lines...) Loading... |
34 DEFINE_WEB_CONTENTS_USER_DATA_KEY( | 34 DEFINE_WEB_CONTENTS_USER_DATA_KEY( |
35 media_router::MediaRouterDialogControllerImpl); | 35 media_router::MediaRouterDialogControllerImpl); |
36 | 36 |
37 using content::LoadCommittedDetails; | 37 using content::LoadCommittedDetails; |
38 using content::NavigationController; | 38 using content::NavigationController; |
39 using content::WebContents; | 39 using content::WebContents; |
40 using content::WebUIMessageHandler; | 40 using content::WebUIMessageHandler; |
41 using ui::WebDialogDelegate; | 41 using ui::WebDialogDelegate; |
42 | 42 |
43 namespace { | 43 namespace { |
44 #if defined(OS_MACOSX) | |
45 const int kFixedHeight = 350; | |
46 #else | |
47 const int kMaxHeight = 2000; | 44 const int kMaxHeight = 2000; |
48 const int kMinHeight = 80; | 45 const int kMinHeight = 80; |
49 #endif | |
50 const int kWidth = 340; | 46 const int kWidth = 340; |
51 } | 47 } |
52 | 48 |
53 namespace media_router { | 49 namespace media_router { |
54 | 50 |
55 namespace { | 51 namespace { |
56 | 52 |
57 // WebDialogDelegate that specifies what the Media Router dialog | 53 // WebDialogDelegate that specifies what the Media Router dialog |
58 // will look like. | 54 // will look like. |
59 class MediaRouterDialogDelegate : public WebDialogDelegate { | 55 class MediaRouterDialogDelegate : public WebDialogDelegate { |
(...skipping 47 matching lines...) Loading... |
107 | 103 |
108 private: | 104 private: |
109 base::WeakPtr<MediaRouterAction> action_; | 105 base::WeakPtr<MediaRouterAction> action_; |
110 base::WeakPtr<MediaRouterDialogControllerImpl> controller_; | 106 base::WeakPtr<MediaRouterDialogControllerImpl> controller_; |
111 | 107 |
112 DISALLOW_COPY_AND_ASSIGN(MediaRouterDialogDelegate); | 108 DISALLOW_COPY_AND_ASSIGN(MediaRouterDialogDelegate); |
113 }; | 109 }; |
114 | 110 |
115 void MediaRouterDialogDelegate::GetDialogSize(gfx::Size* size) const { | 111 void MediaRouterDialogDelegate::GetDialogSize(gfx::Size* size) const { |
116 DCHECK(size); | 112 DCHECK(size); |
117 // TODO(apacible): Remove after autoresizing is implemented for OSX. | |
118 #if defined(OS_MACOSX) | |
119 *size = gfx::Size(kWidth, kFixedHeight); | |
120 #else | |
121 // GetDialogSize() is called when the browser window resizes. We may want to | 113 // GetDialogSize() is called when the browser window resizes. We may want to |
122 // update the maximum height of the dialog and scale the WebUI to the new | 114 // update the maximum height of the dialog and scale the WebUI to the new |
123 // height. |size| is not set because the dialog is auto-resizeable. | 115 // height. |size| is not set because the dialog is auto-resizeable. |
124 controller_->UpdateMaxDialogSize(); | 116 controller_->UpdateMaxDialogSize(); |
125 #endif | |
126 } | 117 } |
127 | 118 |
128 } // namespace | 119 } // namespace |
129 | 120 |
130 // static | 121 // static |
131 MediaRouterDialogControllerImpl* | 122 MediaRouterDialogControllerImpl* |
132 MediaRouterDialogControllerImpl::GetOrCreateForWebContents( | 123 MediaRouterDialogControllerImpl::GetOrCreateForWebContents( |
133 WebContents* web_contents) { | 124 WebContents* web_contents) { |
134 DCHECK(web_contents); | 125 DCHECK(web_contents); |
135 // This call does nothing if the controller already exists. | 126 // This call does nothing if the controller already exists. |
(...skipping 100 matching lines...) Loading... |
236 void MediaRouterDialogControllerImpl::CreateMediaRouterDialog() { | 227 void MediaRouterDialogControllerImpl::CreateMediaRouterDialog() { |
237 DCHECK(!dialog_observer_.get()); | 228 DCHECK(!dialog_observer_.get()); |
238 | 229 |
239 base::Time dialog_creation_time = base::Time::Now(); | 230 base::Time dialog_creation_time = base::Time::Now(); |
240 TRACE_EVENT_NESTABLE_ASYNC_BEGIN0("media_router", "UI", initiator()); | 231 TRACE_EVENT_NESTABLE_ASYNC_BEGIN0("media_router", "UI", initiator()); |
241 | 232 |
242 Profile* profile = | 233 Profile* profile = |
243 Profile::FromBrowserContext(initiator()->GetBrowserContext()); | 234 Profile::FromBrowserContext(initiator()->GetBrowserContext()); |
244 DCHECK(profile); | 235 DCHECK(profile); |
245 | 236 |
| 237 // |web_dialog_delegate|'s owner is |constrained_delegate|. |
| 238 // |constrained_delegate| is owned by the parent |views::View|. |
246 WebDialogDelegate* web_dialog_delegate = | 239 WebDialogDelegate* web_dialog_delegate = |
247 new MediaRouterDialogDelegate(action_, weak_ptr_factory_.GetWeakPtr()); | 240 new MediaRouterDialogDelegate(action_, weak_ptr_factory_.GetWeakPtr()); |
248 // |web_dialog_delegate|'s owner is |constrained_delegate|. | |
249 // |constrained_delegate| is owned by the parent |views::View|. | |
250 // TODO(apacible): Remove after autoresizing is implemented for OSX. | |
251 #if defined(OS_MACOSX) | |
252 ConstrainedWebDialogDelegate* constrained_delegate = | |
253 ShowConstrainedWebDialog(profile, web_dialog_delegate, initiator()); | |
254 #else | |
255 // TODO(apacible): Adjust min and max sizes based on new WebUI design. | |
256 gfx::Size min_size = gfx::Size(kWidth, kMinHeight); | |
257 gfx::Size max_size = gfx::Size(kWidth, kMaxHeight); | |
258 | 241 |
259 // |ShowConstrainedWebDialogWithAutoResize()| will end up creating | 242 // |ShowConstrainedWebDialogWithAutoResize()| will end up creating |
260 // ConstrainedWebDialogDelegateViewViews containing a WebContents containing | 243 // ConstrainedWebDialogDelegateViewViews containing a WebContents containing |
261 // the MediaRouterUI, using the provided |web_dialog_delegate|. Then, the | 244 // the MediaRouterUI, using the provided |web_dialog_delegate|. Then, the |
262 // view is shown as a modal dialog constrained to the |initiator| WebContents. | 245 // view is shown as a modal dialog constrained to the |initiator| WebContents. |
263 // The dialog will resize between the |min_size| and |max_size| bounds based | 246 // The dialog will resize between the given minimum and maximum size bounds |
264 // on the currently rendered contents. | 247 // based on the currently rendered contents. |
265 ConstrainedWebDialogDelegate* constrained_delegate = | 248 ConstrainedWebDialogDelegate* constrained_delegate = |
266 ShowConstrainedWebDialogWithAutoResize( | 249 ShowConstrainedWebDialogWithAutoResize( |
267 profile, web_dialog_delegate, initiator(), min_size, max_size); | 250 profile, web_dialog_delegate, initiator(), |
268 #endif | 251 gfx::Size(kWidth, kMinHeight), gfx::Size(kWidth, kMaxHeight)); |
269 | 252 |
270 WebContents* media_router_dialog = constrained_delegate->GetWebContents(); | 253 WebContents* media_router_dialog = constrained_delegate->GetWebContents(); |
271 TRACE_EVENT_NESTABLE_ASYNC_INSTANT1("media_router", "UI", initiator(), | 254 TRACE_EVENT_NESTABLE_ASYNC_INSTANT1("media_router", "UI", initiator(), |
272 "WebContents created", | 255 "WebContents created", |
273 media_router_dialog); | 256 media_router_dialog); |
274 | 257 |
275 // |media_router_ui| is created when |constrained_delegate| is created. | 258 // |media_router_ui| is created when |constrained_delegate| is created. |
276 // For tests, GetWebUI() returns a nullptr. | 259 // For tests, GetWebUI() returns a nullptr. |
277 if (media_router_dialog->GetWebUI()) { | 260 if (media_router_dialog->GetWebUI()) { |
278 MediaRouterUI* media_router_ui = static_cast<MediaRouterUI*>( | 261 MediaRouterUI* media_router_ui = static_cast<MediaRouterUI*>( |
(...skipping 58 matching lines...) Loading... |
337 ->GetWeakPtr(); | 320 ->GetWeakPtr(); |
338 if (!create_connection_request.get()) { | 321 if (!create_connection_request.get()) { |
339 media_router_ui->InitWithDefaultMediaSource(delegate); | 322 media_router_ui->InitWithDefaultMediaSource(delegate); |
340 } else { | 323 } else { |
341 media_router_ui->InitWithPresentationSessionRequest( | 324 media_router_ui->InitWithPresentationSessionRequest( |
342 initiator(), delegate, std::move(create_connection_request)); | 325 initiator(), delegate, std::move(create_connection_request)); |
343 } | 326 } |
344 } | 327 } |
345 | 328 |
346 } // namespace media_router | 329 } // namespace media_router |
OLD | NEW |