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/media/router/media_router_dialog_controller.h" | 5 #include "chrome/browser/media/router/media_router_dialog_controller.h" |
| 6 | 6 |
| 7 #include "content/public/browser/web_contents.h" | |
| 8 #include "content/public/browser/web_contents_delegate.h" | |
| 9 | |
| 7 #if defined(OS_ANDROID) | 10 #if defined(OS_ANDROID) |
| 8 #include "chrome/browser/media/android/router/media_router_dialog_controller_and roid.h" | 11 #include "chrome/browser/media/android/router/media_router_dialog_controller_and roid.h" |
| 9 #else | 12 #else |
| 10 #include "chrome/browser/ui/webui/media_router/media_router_dialog_controller_im pl.h" | 13 #include "chrome/browser/ui/webui/media_router/media_router_dialog_controller_im pl.h" |
| 11 #endif | 14 #endif |
| 12 | 15 |
| 13 namespace media_router { | 16 namespace media_router { |
| 14 | 17 |
| 15 // static | 18 // static |
| 16 MediaRouterDialogController* | 19 MediaRouterDialogController* |
| 17 MediaRouterDialogController::GetOrCreateForWebContents( | 20 MediaRouterDialogController::GetOrCreateForWebContents( |
| 18 content::WebContents* contents) { | 21 content::WebContents* contents) { |
| 19 #if defined(OS_ANDROID) | 22 #if defined(OS_ANDROID) |
| 20 return MediaRouterDialogControllerAndroid::GetOrCreateForWebContents( | 23 return MediaRouterDialogControllerAndroid::GetOrCreateForWebContents( |
| 21 contents); | 24 contents); |
| 22 #else | 25 #else |
| 23 return MediaRouterDialogControllerImpl::GetOrCreateForWebContents(contents); | 26 return MediaRouterDialogControllerImpl::GetOrCreateForWebContents(contents); |
| 24 #endif | 27 #endif |
| 25 } | 28 } |
| 26 | 29 |
| 30 class MediaRouterDialogController::InitiatorWebContentsObserver | |
| 31 : public content::WebContentsObserver { | |
| 32 public: | |
| 33 InitiatorWebContentsObserver( | |
| 34 content::WebContents* web_contents, | |
| 35 MediaRouterDialogController* dialog_controller) | |
| 36 : content::WebContentsObserver(web_contents), | |
| 37 dialog_controller_(dialog_controller) { | |
| 38 } | |
|
imcheng
2015/07/23 00:41:14
DCHECK(dialog_controller_);
whywhat
2015/07/23 21:20:09
Done.
| |
| 39 | |
| 40 private: | |
| 41 void WebContentsDestroyed() override { | |
| 42 // NOTE: |this| is deleted after CloseMediaRouterDialog() returns. | |
| 43 dialog_controller_->CloseMediaRouterDialog(); | |
| 44 } | |
| 45 | |
| 46 void NavigationEntryCommitted( | |
| 47 const content::LoadCommittedDetails& load_details) override { | |
| 48 // NOTE: |this| is deleted after CloseMediaRouterDialog() returns. | |
| 49 dialog_controller_->CloseMediaRouterDialog(); | |
| 50 } | |
| 51 | |
| 52 void RenderProcessGone(base::TerminationStatus status) override { | |
| 53 // NOTE: |this| is deleted after CloseMediaRouterDialog() returns. | |
| 54 dialog_controller_->CloseMediaRouterDialog(); | |
| 55 } | |
| 56 | |
| 57 MediaRouterDialogController* const dialog_controller_; | |
| 58 }; | |
| 59 | |
| 60 MediaRouterDialogController::MediaRouterDialogController( | |
| 61 content::WebContents* initiator) | |
| 62 : initiator_(initiator) { | |
| 63 DCHECK(initiator_); | |
| 64 } | |
| 65 | |
| 66 MediaRouterDialogController::~MediaRouterDialogController() { | |
| 67 } | |
| 68 | |
| 69 void MediaRouterDialogController::ActivateInitiatorWebContents() { | |
| 70 DCHECK(initiator_); | |
|
imcheng
2015/07/23 00:41:14
DCHECK not needed as it is already done in ctor.
whywhat
2015/07/23 21:20:09
Done.
| |
| 71 initiator_->GetDelegate()->ActivateContents(initiator_); | |
| 72 } | |
| 73 | |
| 74 void MediaRouterDialogController::CloseMediaRouterDialog() { | |
|
imcheng
2015/07/23 00:41:14
isn't this function pure virtual?
whywhat
2015/07/23 21:20:09
Yep, changed that.
| |
| 75 DCHECK(initiator_observer_.get()); | |
| 76 Reset(); | |
| 77 } | |
| 78 | |
| 79 void MediaRouterDialogController::CreateMediaRouterDialog() { | |
| 80 DCHECK(!initiator_observer_.get()); | |
| 81 initiator_observer_.reset(new InitiatorWebContentsObserver( | |
|
imcheng
2015/07/23 00:41:13
This function doesn't create the dialog - how abou
whywhat
2015/07/23 21:20:09
Done.
| |
| 82 initiator_, this)); | |
| 83 } | |
| 84 | |
| 85 void MediaRouterDialogController::SetPresentationRequest( | |
|
imcheng
2015/07/23 00:41:14
nit: TakePresentationRequest ?
whywhat
2015/07/23 21:20:09
Done.
| |
| 86 scoped_ptr<CreatePresentationSessionRequest> request) { | |
| 87 presentation_request_ = request.Pass(); | |
| 88 } | |
| 89 | |
| 90 scoped_ptr<CreatePresentationSessionRequest> | |
| 91 MediaRouterDialogController::PassPresentationRequest() { | |
| 92 return presentation_request_.Pass(); | |
| 93 } | |
| 94 | |
| 95 void MediaRouterDialogController::Reset() { | |
| 96 DCHECK(initiator_observer_.get()); | |
| 97 initiator_observer_.reset(); | |
| 98 presentation_request_.reset(); | |
| 99 } | |
| 100 | |
| 27 } // namespace media_router | 101 } // namespace media_router |
| OLD | NEW |