| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 #ifndef COMPONENTS_WEB_MODAL_WEB_CONTENTS_MODAL_DIALOG_MANAGER_H_ | 5 #ifndef COMPONENTS_WEB_MODAL_WEB_CONTENTS_MODAL_DIALOG_MANAGER_H_ |
| 6 #define COMPONENTS_WEB_MODAL_WEB_CONTENTS_MODAL_DIALOG_MANAGER_H_ | 6 #define COMPONENTS_WEB_MODAL_WEB_CONTENTS_MODAL_DIALOG_MANAGER_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "components/web_modal/single_web_contents_dialog_manager.h" | 11 #include "components/web_modal/single_web_contents_dialog_manager.h" |
| 12 #include "content/public/browser/web_contents_observer.h" | 12 #include "content/public/browser/web_contents_observer.h" |
| 13 #include "content/public/browser/web_contents_user_data.h" | 13 #include "content/public/browser/web_contents_user_data.h" |
| 14 #include "ui/gfx/native_widget_types.h" | 14 #include "ui/gfx/native_widget_types.h" |
| 15 | 15 |
| 16 namespace web_modal { | 16 namespace web_modal { |
| 17 | 17 |
| 18 class WebContentsModalDialogManagerDelegate; | 18 class WebContentsModalDialogManagerDelegate; |
| 19 | 19 |
| 20 // Per-WebContents class to manage WebContents-modal dialogs. | 20 // Per-WebContents class to manage WebContents-modal dialogs. |
| 21 class WebContentsModalDialogManager | 21 class WebContentsModalDialogManager |
| 22 : public SingleWebContentsDialogManagerDelegate, | 22 : public SingleWebContentsDialogManagerDelegate, |
| 23 public content::WebContentsObserver, | 23 public content::WebContentsObserver, |
| 24 public content::WebContentsUserData<WebContentsModalDialogManager> { | 24 public content::WebContentsUserData<WebContentsModalDialogManager> { |
| 25 public: | 25 public: |
| 26 virtual ~WebContentsModalDialogManager(); | 26 ~WebContentsModalDialogManager() override; |
| 27 | 27 |
| 28 WebContentsModalDialogManagerDelegate* delegate() const { return delegate_; } | 28 WebContentsModalDialogManagerDelegate* delegate() const { return delegate_; } |
| 29 void SetDelegate(WebContentsModalDialogManagerDelegate* d); | 29 void SetDelegate(WebContentsModalDialogManagerDelegate* d); |
| 30 | 30 |
| 31 static SingleWebContentsDialogManager* CreateNativeWebModalManager( | 31 static SingleWebContentsDialogManager* CreateNativeWebModalManager( |
| 32 NativeWebContentsModalDialog dialog, | 32 NativeWebContentsModalDialog dialog, |
| 33 SingleWebContentsDialogManagerDelegate* native_delegate); | 33 SingleWebContentsDialogManagerDelegate* native_delegate); |
| 34 | 34 |
| 35 // Shows the dialog as a web contents modal dialog. The dialog will notify via | 35 // Shows the dialog as a web contents modal dialog. The dialog will notify via |
| 36 // WillClose() when it is being destroyed. | 36 // WillClose() when it is being destroyed. |
| 37 void ShowModalDialog(NativeWebContentsModalDialog dialog); | 37 void ShowModalDialog(NativeWebContentsModalDialog dialog); |
| 38 | 38 |
| 39 // Allow clients to supply their own native dialog manager. Suitable for | 39 // Allow clients to supply their own native dialog manager. Suitable for |
| 40 // bubble clients. | 40 // bubble clients. |
| 41 void ShowDialogWithManager( | 41 void ShowDialogWithManager( |
| 42 NativeWebContentsModalDialog dialog, | 42 NativeWebContentsModalDialog dialog, |
| 43 scoped_ptr<SingleWebContentsDialogManager> manager); | 43 scoped_ptr<SingleWebContentsDialogManager> manager); |
| 44 | 44 |
| 45 // Returns true if any dialogs are active and not closed. | 45 // Returns true if any dialogs are active and not closed. |
| 46 bool IsDialogActive() const; | 46 bool IsDialogActive() const; |
| 47 | 47 |
| 48 // Focus the topmost modal dialog. IsDialogActive() must be true when calling | 48 // Focus the topmost modal dialog. IsDialogActive() must be true when calling |
| 49 // this function. | 49 // this function. |
| 50 void FocusTopmostDialog() const; | 50 void FocusTopmostDialog() const; |
| 51 | 51 |
| 52 // SingleWebContentsDialogManagerDelegate: | 52 // SingleWebContentsDialogManagerDelegate: |
| 53 virtual content::WebContents* GetWebContents() const override; | 53 content::WebContents* GetWebContents() const override; |
| 54 virtual void WillClose(NativeWebContentsModalDialog dialog) override; | 54 void WillClose(NativeWebContentsModalDialog dialog) override; |
| 55 | 55 |
| 56 // For testing. | 56 // For testing. |
| 57 class TestApi { | 57 class TestApi { |
| 58 public: | 58 public: |
| 59 explicit TestApi(WebContentsModalDialogManager* manager) | 59 explicit TestApi(WebContentsModalDialogManager* manager) |
| 60 : manager_(manager) {} | 60 : manager_(manager) {} |
| 61 | 61 |
| 62 void CloseAllDialogs() { manager_->CloseAllDialogs(); } | 62 void CloseAllDialogs() { manager_->CloseAllDialogs(); } |
| 63 void DidAttachInterstitialPage() { manager_->DidAttachInterstitialPage(); } | 63 void DidAttachInterstitialPage() { manager_->DidAttachInterstitialPage(); } |
| 64 void WebContentsWasShown() { manager_->WasShown(); } | 64 void WebContentsWasShown() { manager_->WasShown(); } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 92 | 92 |
| 93 // Blocks/unblocks interaction with renderer process. | 93 // Blocks/unblocks interaction with renderer process. |
| 94 void BlockWebContentsInteraction(bool blocked); | 94 void BlockWebContentsInteraction(bool blocked); |
| 95 | 95 |
| 96 bool IsWebContentsVisible() const; | 96 bool IsWebContentsVisible() const; |
| 97 | 97 |
| 98 // Closes all WebContentsModalDialogs. | 98 // Closes all WebContentsModalDialogs. |
| 99 void CloseAllDialogs(); | 99 void CloseAllDialogs(); |
| 100 | 100 |
| 101 // Overridden from content::WebContentsObserver: | 101 // Overridden from content::WebContentsObserver: |
| 102 virtual void DidNavigateMainFrame( | 102 void DidNavigateMainFrame( |
| 103 const content::LoadCommittedDetails& details, | 103 const content::LoadCommittedDetails& details, |
| 104 const content::FrameNavigateParams& params) override; | 104 const content::FrameNavigateParams& params) override; |
| 105 virtual void DidGetIgnoredUIEvent() override; | 105 void DidGetIgnoredUIEvent() override; |
| 106 virtual void WasShown() override; | 106 void WasShown() override; |
| 107 virtual void WasHidden() override; | 107 void WasHidden() override; |
| 108 virtual void WebContentsDestroyed() override; | 108 void WebContentsDestroyed() override; |
| 109 virtual void DidAttachInterstitialPage() override; | 109 void DidAttachInterstitialPage() override; |
| 110 | 110 |
| 111 // Delegate for notifying our owner about stuff. Not owned by us. | 111 // Delegate for notifying our owner about stuff. Not owned by us. |
| 112 WebContentsModalDialogManagerDelegate* delegate_; | 112 WebContentsModalDialogManagerDelegate* delegate_; |
| 113 | 113 |
| 114 // All active dialogs. | 114 // All active dialogs. |
| 115 WebContentsModalDialogList child_dialogs_; | 115 WebContentsModalDialogList child_dialogs_; |
| 116 | 116 |
| 117 // True while closing the dialogs on WebContents close. | 117 // True while closing the dialogs on WebContents close. |
| 118 bool closing_all_dialogs_; | 118 bool closing_all_dialogs_; |
| 119 | 119 |
| 120 DISALLOW_COPY_AND_ASSIGN(WebContentsModalDialogManager); | 120 DISALLOW_COPY_AND_ASSIGN(WebContentsModalDialogManager); |
| 121 }; | 121 }; |
| 122 | 122 |
| 123 } // namespace web_modal | 123 } // namespace web_modal |
| 124 | 124 |
| 125 #endif // COMPONENTS_WEB_MODAL_WEB_CONTENTS_MODAL_DIALOG_MANAGER_H_ | 125 #endif // COMPONENTS_WEB_MODAL_WEB_CONTENTS_MODAL_DIALOG_MANAGER_H_ |
| OLD | NEW |