Chromium Code Reviews| 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.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 <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h" | 11 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h" |
| 12 #include "chrome/browser/ui/webui/media_router/media_router_ui.h" | 12 #include "chrome/browser/ui/webui/media_router/media_router_ui.h" |
| 13 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.h" |
| 14 #include "components/web_modal/web_contents_modal_dialog_host.h" | 14 #include "components/web_modal/web_contents_modal_dialog_host.h" |
| 15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/navigation_controller.h" | 16 #include "content/public/browser/navigation_controller.h" |
| 17 #include "content/public/browser/navigation_details.h" | 17 #include "content/public/browser/navigation_details.h" |
| 18 #include "content/public/browser/navigation_entry.h" | 18 #include "content/public/browser/navigation_entry.h" |
| 19 #include "content/public/browser/render_frame_host.h" | 19 #include "content/public/browser/render_frame_host.h" |
| 20 #include "content/public/browser/render_process_host.h" | 20 #include "content/public/browser/render_process_host.h" |
| 21 #include "content/public/browser/render_view_host.h" | 21 #include "content/public/browser/render_view_host.h" |
| 22 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 23 #include "content/public/browser/web_contents_delegate.h" | 23 #include "content/public/browser/web_contents_delegate.h" |
| 24 #include "ui/web_dialogs/web_dialog_delegate.h" | 24 #include "ui/web_dialogs/web_dialog_delegate.h" |
| 25 #include "ui/web_dialogs/web_dialog_web_contents_delegate.h" | 25 #include "ui/web_dialogs/web_dialog_web_contents_delegate.h" |
| 26 #include "url/gurl.h" | 26 #include "url/gurl.h" |
| 27 | 27 |
| 28 DEFINE_WEB_CONTENTS_USER_DATA_KEY(media_router::MediaRouterDialogController); | 28 DEFINE_WEB_CONTENTS_USER_DATA_KEY( |
| 29 media_router::MediaRouterDialogControllerImpl); | |
| 29 | 30 |
| 30 using content::LoadCommittedDetails; | 31 using content::LoadCommittedDetails; |
| 31 using content::NavigationController; | 32 using content::NavigationController; |
| 32 using content::WebContents; | 33 using content::WebContents; |
| 33 using content::WebUIMessageHandler; | 34 using content::WebUIMessageHandler; |
| 34 using ui::WebDialogDelegate; | 35 using ui::WebDialogDelegate; |
| 35 | 36 |
| 36 namespace media_router { | 37 namespace media_router { |
| 37 | 38 |
| 38 namespace { | 39 namespace { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 #if defined(OS_MACOSX) | 94 #if defined(OS_MACOSX) |
| 94 *size = gfx::Size(330, 400); | 95 *size = gfx::Size(330, 400); |
| 95 #else | 96 #else |
| 96 // size is not used because the dialog is auto-resizeable. | 97 // size is not used because the dialog is auto-resizeable. |
| 97 *size = gfx::Size(); | 98 *size = gfx::Size(); |
| 98 #endif | 99 #endif |
| 99 } | 100 } |
| 100 | 101 |
| 101 } // namespace | 102 } // namespace |
| 102 | 103 |
| 103 // static | 104 // static |
|
apacible
2015/07/20 14:10:32
nit: No indentation
whywhat
2015/07/20 14:27:47
Done.
| |
| 104 MediaRouterDialogController* | 105 MediaRouterDialogControllerImpl* |
| 105 MediaRouterDialogController::GetOrCreateForWebContents( | 106 MediaRouterDialogControllerImpl::GetOrCreateForWebContents( |
| 106 WebContents* web_contents) { | 107 WebContents* web_contents) { |
| 107 DCHECK(web_contents); | 108 DCHECK(web_contents); |
| 108 // This call does nothing if the controller already exists. | 109 // This call does nothing if the controller already exists. |
| 109 MediaRouterDialogController::CreateForWebContents(web_contents); | 110 MediaRouterDialogControllerImpl::CreateForWebContents(web_contents); |
| 110 return MediaRouterDialogController::FromWebContents(web_contents); | 111 return MediaRouterDialogControllerImpl::FromWebContents(web_contents); |
| 111 } | 112 } |
| 112 | 113 |
| 113 class MediaRouterDialogController::DialogWebContentsObserver | 114 class MediaRouterDialogControllerImpl::DialogWebContentsObserver |
| 114 : public content::WebContentsObserver { | 115 : public content::WebContentsObserver { |
| 115 public: | 116 public: |
| 116 DialogWebContentsObserver( | 117 DialogWebContentsObserver( |
| 117 WebContents* web_contents, | 118 WebContents* web_contents, |
| 118 MediaRouterDialogController* dialog_controller) | 119 MediaRouterDialogControllerImpl* dialog_controller) |
| 119 : content::WebContentsObserver(web_contents), | 120 : content::WebContentsObserver(web_contents), |
| 120 dialog_controller_(dialog_controller) { | 121 dialog_controller_(dialog_controller) { |
| 121 } | 122 } |
| 122 | 123 |
| 123 private: | 124 private: |
| 124 void WebContentsDestroyed() override { | 125 void WebContentsDestroyed() override { |
| 125 // The dialog is already closed. No need to call Close() again. | 126 // The dialog is already closed. No need to call Close() again. |
| 126 // NOTE: |this| is deleted after Reset() returns. | 127 // NOTE: |this| is deleted after Reset() returns. |
| 127 dialog_controller_->Reset(); | 128 dialog_controller_->Reset(); |
| 128 } | 129 } |
| 129 | 130 |
| 130 void NavigationEntryCommitted(const LoadCommittedDetails& load_details) | 131 void NavigationEntryCommitted(const LoadCommittedDetails& load_details) |
| 131 override { | 132 override { |
| 132 dialog_controller_->OnDialogNavigated(load_details); | 133 dialog_controller_->OnDialogNavigated(load_details); |
| 133 } | 134 } |
| 134 | 135 |
| 135 void RenderProcessGone(base::TerminationStatus status) override { | 136 void RenderProcessGone(base::TerminationStatus status) override { |
| 136 // NOTE: |this| is deleted after CloseMediaRouterDialog() returns. | 137 // NOTE: |this| is deleted after CloseMediaRouterDialog() returns. |
| 137 dialog_controller_->CloseMediaRouterDialog(); | 138 dialog_controller_->CloseMediaRouterDialog(); |
| 138 } | 139 } |
| 139 | 140 |
| 140 MediaRouterDialogController* const dialog_controller_; | 141 MediaRouterDialogControllerImpl* const dialog_controller_; |
| 141 }; | 142 }; |
| 142 | 143 |
| 143 class MediaRouterDialogController::InitiatorWebContentsObserver | 144 class MediaRouterDialogControllerImpl::InitiatorWebContentsObserver |
| 144 : public content::WebContentsObserver { | 145 : public content::WebContentsObserver { |
| 145 public: | 146 public: |
| 146 InitiatorWebContentsObserver( | 147 InitiatorWebContentsObserver( |
| 147 WebContents* web_contents, | 148 WebContents* web_contents, |
| 148 MediaRouterDialogController* dialog_controller) | 149 MediaRouterDialogControllerImpl* dialog_controller) |
| 149 : content::WebContentsObserver(web_contents), | 150 : content::WebContentsObserver(web_contents), |
| 150 dialog_controller_(dialog_controller) { | 151 dialog_controller_(dialog_controller) { |
| 151 } | 152 } |
| 152 | 153 |
| 153 private: | 154 private: |
| 154 void WebContentsDestroyed() override { | 155 void WebContentsDestroyed() override { |
| 155 // NOTE: |this| is deleted after CloseMediaRouterDialog() returns. | 156 // NOTE: |this| is deleted after CloseMediaRouterDialog() returns. |
| 156 dialog_controller_->CloseMediaRouterDialog(); | 157 dialog_controller_->CloseMediaRouterDialog(); |
| 157 } | 158 } |
| 158 | 159 |
| 159 void NavigationEntryCommitted(const LoadCommittedDetails& load_details) | 160 void NavigationEntryCommitted(const LoadCommittedDetails& load_details) |
| 160 override { | 161 override { |
| 161 // NOTE: |this| is deleted after CloseMediaRouterDialog() returns. | 162 // NOTE: |this| is deleted after CloseMediaRouterDialog() returns. |
| 162 dialog_controller_->CloseMediaRouterDialog(); | 163 dialog_controller_->CloseMediaRouterDialog(); |
| 163 } | 164 } |
| 164 | 165 |
| 165 void RenderProcessGone(base::TerminationStatus status) override { | 166 void RenderProcessGone(base::TerminationStatus status) override { |
| 166 // NOTE: |this| is deleted after CloseMediaRouterDialog() returns. | 167 // NOTE: |this| is deleted after CloseMediaRouterDialog() returns. |
| 167 dialog_controller_->CloseMediaRouterDialog(); | 168 dialog_controller_->CloseMediaRouterDialog(); |
| 168 } | 169 } |
| 169 | 170 |
| 170 MediaRouterDialogController* const dialog_controller_; | 171 MediaRouterDialogControllerImpl* const dialog_controller_; |
| 171 }; | 172 }; |
| 172 | 173 |
| 173 MediaRouterDialogController::MediaRouterDialogController( | 174 MediaRouterDialogControllerImpl::MediaRouterDialogControllerImpl( |
| 174 WebContents* web_contents) | 175 WebContents* web_contents) |
| 175 : initiator_(web_contents), | 176 : initiator_(web_contents), |
| 176 media_router_dialog_pending_(false) { | 177 media_router_dialog_pending_(false) { |
| 177 DCHECK(initiator_); | 178 DCHECK(initiator_); |
| 178 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 179 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 179 } | 180 } |
| 180 | 181 |
| 181 MediaRouterDialogController::~MediaRouterDialogController() { | 182 MediaRouterDialogControllerImpl::~MediaRouterDialogControllerImpl() { |
| 182 DCHECK(thread_checker_.CalledOnValidThread()); | 183 DCHECK(thread_checker_.CalledOnValidThread()); |
| 183 } | 184 } |
| 184 | 185 |
| 185 WebContents* MediaRouterDialogController::ShowMediaRouterDialog() { | 186 WebContents* MediaRouterDialogControllerImpl::ShowMediaRouterDialog() { |
| 186 DCHECK(thread_checker_.CalledOnValidThread()); | 187 DCHECK(thread_checker_.CalledOnValidThread()); |
| 187 | 188 |
| 188 // Get the media router dialog for |initiator|, or create a new dialog | 189 // Get the media router dialog for |initiator|, or create a new dialog |
| 189 // if not found. | 190 // if not found. |
| 190 WebContents* media_router_dialog = GetMediaRouterDialog(); | 191 WebContents* media_router_dialog = GetMediaRouterDialog(); |
| 191 if (!media_router_dialog) { | 192 if (!media_router_dialog) { |
| 192 CreateMediaRouterDialog(); | 193 CreateMediaRouterDialog(); |
| 193 return GetMediaRouterDialog(); | 194 return GetMediaRouterDialog(); |
| 194 } | 195 } |
| 195 | 196 |
| 196 // Show the initiator holding the existing media router dialog. | 197 // Show the initiator holding the existing media router dialog. |
| 197 initiator_->GetDelegate()->ActivateContents(initiator_); | 198 initiator_->GetDelegate()->ActivateContents(initiator_); |
| 198 return media_router_dialog; | 199 return media_router_dialog; |
| 199 } | 200 } |
| 200 | 201 |
| 201 WebContents* MediaRouterDialogController::ShowMediaRouterDialogForPresentation( | 202 bool MediaRouterDialogControllerImpl::ShowMediaRouterDialogForPresentation( |
| 202 scoped_ptr<CreateSessionRequest> request) { | 203 scoped_ptr<CreateSessionRequest> request) { |
| 203 DCHECK(thread_checker_.CalledOnValidThread()); | 204 DCHECK(thread_checker_.CalledOnValidThread()); |
| 204 | 205 |
| 205 // Get the media router dialog for |initiator|, or create a new dialog | 206 // Get the media router dialog for |initiator|, or create a new dialog |
| 206 // if not found. | 207 // if not found. |
| 207 WebContents* media_router_dialog = GetMediaRouterDialog(); | 208 WebContents* media_router_dialog = GetMediaRouterDialog(); |
| 208 if (!media_router_dialog) { | 209 if (!media_router_dialog) { |
| 209 CreateMediaRouterDialog(); | 210 CreateMediaRouterDialog(); |
| 210 media_router_dialog = GetMediaRouterDialog(); | 211 media_router_dialog = GetMediaRouterDialog(); |
| 211 presentation_request_ = request.Pass(); | 212 presentation_request_ = request.Pass(); |
| 212 return media_router_dialog; | 213 return true; |
| 213 } | 214 } |
| 214 | 215 |
| 215 // Show the initiator holding the existing media router dialog. | 216 // Show the initiator holding the existing media router dialog. |
| 216 initiator_->GetDelegate()->ActivateContents(initiator_); | 217 initiator_->GetDelegate()->ActivateContents(initiator_); |
| 217 return nullptr; | 218 return false; |
| 218 } | 219 } |
| 219 | 220 |
| 220 WebContents* MediaRouterDialogController::GetMediaRouterDialog() const { | 221 WebContents* MediaRouterDialogControllerImpl::GetMediaRouterDialog() const { |
| 221 DCHECK(thread_checker_.CalledOnValidThread()); | 222 DCHECK(thread_checker_.CalledOnValidThread()); |
| 222 return dialog_observer_.get() ? dialog_observer_->web_contents() : nullptr; | 223 return dialog_observer_.get() ? dialog_observer_->web_contents() : nullptr; |
| 223 } | 224 } |
| 224 | 225 |
| 225 void MediaRouterDialogController::CloseMediaRouterDialog() { | 226 void MediaRouterDialogControllerImpl::CloseMediaRouterDialog() { |
| 226 DCHECK(thread_checker_.CalledOnValidThread()); | 227 DCHECK(thread_checker_.CalledOnValidThread()); |
| 227 DCHECK(initiator_observer_.get()); | 228 DCHECK(initiator_observer_.get()); |
| 228 WebContents* media_router_dialog = GetMediaRouterDialog(); | 229 WebContents* media_router_dialog = GetMediaRouterDialog(); |
| 229 CHECK(media_router_dialog); | 230 CHECK(media_router_dialog); |
| 230 Reset(); | 231 Reset(); |
| 231 | 232 |
| 232 content::WebUI* web_ui = media_router_dialog->GetWebUI(); | 233 content::WebUI* web_ui = media_router_dialog->GetWebUI(); |
| 233 if (web_ui) { | 234 if (web_ui) { |
| 234 MediaRouterUI* media_router_ui = | 235 MediaRouterUI* media_router_ui = |
| 235 static_cast<MediaRouterUI*>(web_ui->GetController()); | 236 static_cast<MediaRouterUI*>(web_ui->GetController()); |
| 236 if (media_router_ui) | 237 if (media_router_ui) |
| 237 media_router_ui->Close(); | 238 media_router_ui->Close(); |
| 238 } | 239 } |
| 239 } | 240 } |
| 240 | 241 |
| 241 void MediaRouterDialogController::CreateMediaRouterDialog() { | 242 void MediaRouterDialogControllerImpl::CreateMediaRouterDialog() { |
| 242 DCHECK(!initiator_observer_.get()); | 243 DCHECK(!initiator_observer_.get()); |
| 243 DCHECK(!dialog_observer_.get()); | 244 DCHECK(!dialog_observer_.get()); |
| 244 | 245 |
| 245 Profile* profile = | 246 Profile* profile = |
| 246 Profile::FromBrowserContext(initiator_->GetBrowserContext()); | 247 Profile::FromBrowserContext(initiator_->GetBrowserContext()); |
| 247 DCHECK(profile); | 248 DCHECK(profile); |
| 248 | 249 |
| 249 WebDialogDelegate* web_dialog_delegate = new MediaRouterDialogDelegate; | 250 WebDialogDelegate* web_dialog_delegate = new MediaRouterDialogDelegate; |
| 250 | 251 |
| 251 // |web_dialog_delegate|'s owner is |constrained_delegate|. | 252 // |web_dialog_delegate|'s owner is |constrained_delegate|. |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 272 WebContents* media_router_dialog = constrained_delegate->GetWebContents(); | 273 WebContents* media_router_dialog = constrained_delegate->GetWebContents(); |
| 273 | 274 |
| 274 media_router_dialog_pending_ = true; | 275 media_router_dialog_pending_ = true; |
| 275 | 276 |
| 276 initiator_observer_.reset(new InitiatorWebContentsObserver( | 277 initiator_observer_.reset(new InitiatorWebContentsObserver( |
| 277 initiator_, this)); | 278 initiator_, this)); |
| 278 dialog_observer_.reset(new DialogWebContentsObserver( | 279 dialog_observer_.reset(new DialogWebContentsObserver( |
| 279 media_router_dialog, this)); | 280 media_router_dialog, this)); |
| 280 } | 281 } |
| 281 | 282 |
| 282 void MediaRouterDialogController::Reset() { | 283 void MediaRouterDialogControllerImpl::Reset() { |
| 283 DCHECK(thread_checker_.CalledOnValidThread()); | 284 DCHECK(thread_checker_.CalledOnValidThread()); |
| 284 DCHECK(initiator_observer_.get()); | 285 DCHECK(initiator_observer_.get()); |
| 285 DCHECK(dialog_observer_.get()); | 286 DCHECK(dialog_observer_.get()); |
| 286 initiator_observer_.reset(); | 287 initiator_observer_.reset(); |
| 287 dialog_observer_.reset(); | 288 dialog_observer_.reset(); |
| 288 presentation_request_.reset(); | 289 presentation_request_.reset(); |
| 289 } | 290 } |
| 290 | 291 |
| 291 void MediaRouterDialogController::OnDialogNavigated( | 292 void MediaRouterDialogControllerImpl::OnDialogNavigated( |
| 292 const content::LoadCommittedDetails& details) { | 293 const content::LoadCommittedDetails& details) { |
| 293 DCHECK(thread_checker_.CalledOnValidThread()); | 294 DCHECK(thread_checker_.CalledOnValidThread()); |
| 294 WebContents* media_router_dialog = GetMediaRouterDialog(); | 295 WebContents* media_router_dialog = GetMediaRouterDialog(); |
| 295 CHECK(media_router_dialog); | 296 CHECK(media_router_dialog); |
| 296 ui::PageTransition transition_type = details.entry->GetTransitionType(); | 297 ui::PageTransition transition_type = details.entry->GetTransitionType(); |
| 297 content::NavigationType nav_type = details.type; | 298 content::NavigationType nav_type = details.type; |
| 298 | 299 |
| 299 // New |media_router_dialog| is created. | 300 // New |media_router_dialog| is created. |
| 300 DCHECK(media_router_dialog_pending_); | 301 DCHECK(media_router_dialog_pending_); |
| 301 DCHECK(transition_type == ui::PAGE_TRANSITION_AUTO_TOPLEVEL && | 302 DCHECK(transition_type == ui::PAGE_TRANSITION_AUTO_TOPLEVEL && |
| 302 nav_type == content::NAVIGATION_TYPE_NEW_PAGE) | 303 nav_type == content::NAVIGATION_TYPE_NEW_PAGE) |
| 303 << "transition_type: " << transition_type << ", " | 304 << "transition_type: " << transition_type << ", " |
| 304 << "nav_type: " << nav_type; | 305 << "nav_type: " << nav_type; |
| 305 | 306 |
| 306 media_router_dialog_pending_ = false; | 307 media_router_dialog_pending_ = false; |
| 307 | 308 |
| 308 PopulateDialog(media_router_dialog); | 309 PopulateDialog(media_router_dialog); |
| 309 } | 310 } |
| 310 | 311 |
| 311 void MediaRouterDialogController::PopulateDialog( | 312 void MediaRouterDialogControllerImpl::PopulateDialog( |
| 312 content::WebContents* media_router_dialog) { | 313 content::WebContents* media_router_dialog) { |
| 313 DCHECK(media_router_dialog); | 314 DCHECK(media_router_dialog); |
| 314 DCHECK(initiator_observer_); | 315 DCHECK(initiator_observer_); |
| 315 if (!initiator_observer_) { | 316 if (!initiator_observer_) { |
| 316 Reset(); | 317 Reset(); |
| 317 return; | 318 return; |
| 318 } | 319 } |
| 319 content::WebContents* initiator = initiator_observer_->web_contents(); | 320 content::WebContents* initiator = initiator_observer_->web_contents(); |
| 320 DCHECK(initiator); | 321 DCHECK(initiator); |
| 321 if (!initiator || !media_router_dialog->GetWebUI()) { | 322 if (!initiator || !media_router_dialog->GetWebUI()) { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 338 CHECK(delegate); | 339 CHECK(delegate); |
| 339 media_router_ui->InitWithDefaultMediaSource(delegate); | 340 media_router_ui->InitWithDefaultMediaSource(delegate); |
| 340 } else { | 341 } else { |
| 341 media_router_ui->InitWithPresentationSessionRequest( | 342 media_router_ui->InitWithPresentationSessionRequest( |
| 342 initiator, presentation_request_.Pass()); | 343 initiator, presentation_request_.Pass()); |
| 343 } | 344 } |
| 344 } | 345 } |
| 345 | 346 |
| 346 } // namespace media_router | 347 } // namespace media_router |
| 347 | 348 |
| OLD | NEW |