| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 CHROME_BROWSER_UI_WEBUI_CONSTRAINED_WEB_DIALOG_DELEGATE_BASE_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_CONSTRAINED_WEB_DIALOG_DELEGATE_BASE_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_CONSTRAINED_WEB_DIALOG_DELEGATE_BASE_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_CONSTRAINED_WEB_DIALOG_DELEGATE_BASE_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.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 "content/public/browser/web_contents_observer.h" |
| 12 #include "ui/web_dialogs/web_dialog_ui.h" | 13 #include "ui/web_dialogs/web_dialog_ui.h" |
| 13 #include "ui/web_dialogs/web_dialog_web_contents_delegate.h" | 14 #include "ui/web_dialogs/web_dialog_web_contents_delegate.h" |
| 14 | 15 |
| 15 namespace content { | 16 namespace content { |
| 16 class BrowserContext; | 17 class BrowserContext; |
| 17 } | 18 } |
| 18 | 19 |
| 19 namespace ui { | 20 namespace ui { |
| 20 class WebDialogDelegate; | 21 class WebDialogDelegate; |
| 21 } | 22 } |
| 22 | 23 |
| 23 // Platform-agnostic base implementation of ConstrainedWebDialogDelegate. | 24 // Platform-agnostic base implementation of ConstrainedWebDialogDelegate. |
| 24 class ConstrainedWebDialogDelegateBase | 25 class ConstrainedWebDialogDelegateBase |
| 25 : public ConstrainedWebDialogDelegate, | 26 : public ConstrainedWebDialogDelegate, |
| 27 public content::WebContentsObserver, |
| 26 public ui::WebDialogWebContentsDelegate { | 28 public ui::WebDialogWebContentsDelegate { |
| 27 public: | 29 public: |
| 28 // |browser_context| and |delegate| must outlive |this| instance, whereas | 30 // |browser_context| and |delegate| must outlive |this| instance, whereas |
| 29 // |this| will take ownership of |tab_delegate|. | 31 // |this| will take ownership of |tab_delegate|. |
| 30 ConstrainedWebDialogDelegateBase(content::BrowserContext* browser_context, | 32 ConstrainedWebDialogDelegateBase(content::BrowserContext* browser_context, |
| 31 ui::WebDialogDelegate* delegate, | 33 ui::WebDialogDelegate* delegate, |
| 32 WebDialogWebContentsDelegate* tab_delegate); | 34 WebDialogWebContentsDelegate* tab_delegate); |
| 33 ~ConstrainedWebDialogDelegateBase() override; | 35 ~ConstrainedWebDialogDelegateBase() override; |
| 34 | 36 |
| 35 bool closed_via_webui() const; | 37 bool closed_via_webui() const; |
| 36 | 38 |
| 37 // ConstrainedWebDialogDelegate interface. | 39 // ConstrainedWebDialogDelegate interface. |
| 38 const ui::WebDialogDelegate* GetWebDialogDelegate() const override; | 40 const ui::WebDialogDelegate* GetWebDialogDelegate() const override; |
| 39 ui::WebDialogDelegate* GetWebDialogDelegate() override; | 41 ui::WebDialogDelegate* GetWebDialogDelegate() override; |
| 40 void OnDialogCloseFromWebUI() override; | 42 void OnDialogCloseFromWebUI() override; |
| 41 void ReleaseWebContentsOnDialogClose() override; | 43 std::unique_ptr<content::WebContents> ReleaseWebContents() override; |
| 42 content::WebContents* GetWebContents() override; | 44 content::WebContents* GetWebContents() override; |
| 43 gfx::NativeWindow GetNativeDialog() override; | 45 gfx::NativeWindow GetNativeDialog() override; |
| 44 gfx::Size GetMinimumSize() const override; | 46 gfx::Size GetMinimumSize() const override; |
| 45 gfx::Size GetMaximumSize() const override; | 47 gfx::Size GetMaximumSize() const override; |
| 46 gfx::Size GetPreferredSize() const override; | 48 gfx::Size GetPreferredSize() const override; |
| 47 | 49 |
| 50 // WebContentsObserver interface |
| 51 void WebContentsDestroyed() override; |
| 52 |
| 48 // WebDialogWebContentsDelegate interface. | 53 // WebDialogWebContentsDelegate interface. |
| 49 void HandleKeyboardEvent( | 54 void HandleKeyboardEvent( |
| 50 content::WebContents* source, | 55 content::WebContents* source, |
| 51 const content::NativeWebKeyboardEvent& event) override; | 56 const content::NativeWebKeyboardEvent& event) override; |
| 52 | 57 |
| 53 // Resize the dialog to the given size. | 58 // Resize the dialog to the given size. |
| 54 virtual void ResizeToGivenSize(const gfx::Size size); | 59 virtual void ResizeToGivenSize(const gfx::Size size); |
| 55 | 60 |
| 56 private: | 61 private: |
| 57 std::unique_ptr<ui::WebDialogDelegate> web_dialog_delegate_; | 62 std::unique_ptr<ui::WebDialogDelegate> web_dialog_delegate_; |
| 58 | 63 |
| 59 // Holds the HTML to display in the constrained dialog. | 64 // Holds the HTML to display in the constrained dialog. |
| 60 std::unique_ptr<content::WebContents> web_contents_; | 65 std::unique_ptr<content::WebContents> web_contents_holder_; |
| 66 |
| 67 // Pointer to |web_contents_| that remains valid until it is destroyed. |
| 68 content::WebContents* web_contents_; |
| 61 | 69 |
| 62 // Was the dialog closed from WebUI (in which case |web_dialog_delegate_|'s | 70 // Was the dialog closed from WebUI (in which case |web_dialog_delegate_|'s |
| 63 // OnDialogClosed() method has already been called)? | 71 // OnDialogClosed() method has already been called)? |
| 64 bool closed_via_webui_; | 72 bool closed_via_webui_; |
| 65 | 73 |
| 66 // If true, release |web_contents_| on close instead of destroying it. | |
| 67 bool release_contents_on_close_; | |
| 68 | |
| 69 std::unique_ptr<WebDialogWebContentsDelegate> override_tab_delegate_; | 74 std::unique_ptr<WebDialogWebContentsDelegate> override_tab_delegate_; |
| 70 | 75 |
| 71 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateBase); | 76 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateBase); |
| 72 }; | 77 }; |
| 73 | 78 |
| 74 #endif // CHROME_BROWSER_UI_WEBUI_CONSTRAINED_WEB_DIALOG_DELEGATE_BASE_H_ | 79 #endif // CHROME_BROWSER_UI_WEBUI_CONSTRAINED_WEB_DIALOG_DELEGATE_BASE_H_ |
| OLD | NEW |