| 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 #include "chrome/browser/ui/webui/constrained_html_ui_delegate_impl.h" | 5 #include "chrome/browser/ui/webui/constrained_web_dialog_delegate_base.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 8 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 9 #include "chrome/browser/ui/views/constrained_window_views.h" | 9 #include "chrome/browser/ui/views/constrained_window_views.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/ui/webui/html_dialog_ui.h" | 11 #include "chrome/browser/ui/webui/web_dialog_ui.h" |
| 12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
| 13 #include "ui/gfx/size.h" | 13 #include "ui/gfx/size.h" |
| 14 #include "ui/views/controls/webview/webview.h" | 14 #include "ui/views/controls/webview/webview.h" |
| 15 #include "ui/views/view.h" | 15 #include "ui/views/view.h" |
| 16 #include "ui/views/widget/widget_delegate.h" | 16 #include "ui/views/widget/widget_delegate.h" |
| 17 | 17 |
| 18 using content::WebContents; | 18 using content::WebContents; |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 class ConstrainedHtmlUIDelegateImplViews | 22 class ConstrainedWebDialogDelegateViews |
| 23 : public ConstrainedHtmlUIDelegateImpl { | 23 : public ConstrainedWebDialogDelegateBase { |
| 24 public: | 24 public: |
| 25 ConstrainedHtmlUIDelegateImplViews( | 25 ConstrainedWebDialogDelegateViews( |
| 26 Profile* profile, | 26 Profile* profile, |
| 27 HtmlDialogUIDelegate* delegate, | 27 WebDialogDelegate* delegate, |
| 28 HtmlDialogTabContentsDelegate* tab_delegate) | 28 WebDialogWebContentsDelegate* tab_delegate) |
| 29 : ConstrainedHtmlUIDelegateImpl(profile, delegate, tab_delegate) { | 29 : ConstrainedWebDialogDelegateBase(profile, delegate, tab_delegate) { |
| 30 WebContents* web_contents = tab()->web_contents(); | 30 WebContents* web_contents = tab()->web_contents(); |
| 31 if (tab_delegate) { | 31 if (tab_delegate) { |
| 32 set_override_tab_delegate(tab_delegate); | 32 set_override_tab_delegate(tab_delegate); |
| 33 web_contents->SetDelegate(tab_delegate); | 33 web_contents->SetDelegate(tab_delegate); |
| 34 } else { | 34 } else { |
| 35 web_contents->SetDelegate(this); | 35 web_contents->SetDelegate(this); |
| 36 } | 36 } |
| 37 } | 37 } |
| 38 | 38 |
| 39 virtual ~ConstrainedHtmlUIDelegateImplViews() {} | 39 virtual ~ConstrainedWebDialogDelegateViews() {} |
| 40 | 40 |
| 41 // HtmlDialogTabContentsDelegate interface. | 41 // WebDialogWebContentsDelegate interface. |
| 42 virtual void CloseContents(WebContents* source) OVERRIDE { | 42 virtual void CloseContents(WebContents* source) OVERRIDE { |
| 43 window()->CloseConstrainedWindow(); | 43 window()->CloseConstrainedWindow(); |
| 44 } | 44 } |
| 45 | 45 |
| 46 private: | 46 private: |
| 47 DISALLOW_COPY_AND_ASSIGN(ConstrainedHtmlUIDelegateImplViews); | 47 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViews); |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 } // namespace | 50 } // namespace |
| 51 | 51 |
| 52 class ConstrainedHtmlDelegateViews : public views::WebView, | 52 class ConstrainedWebDialogDelegateViewViews |
| 53 public ConstrainedHtmlUIDelegate, | 53 : public views::WebView, |
| 54 public views::WidgetDelegate { | 54 public ConstrainedWebDialogDelegate, |
| 55 public views::WidgetDelegate { |
| 55 public: | 56 public: |
| 56 ConstrainedHtmlDelegateViews(Profile* profile, | 57 ConstrainedWebDialogDelegateViewViews( |
| 57 HtmlDialogUIDelegate* delegate, | 58 Profile* profile, |
| 58 HtmlDialogTabContentsDelegate* tab_delegate); | 59 WebDialogDelegate* delegate, |
| 59 virtual ~ConstrainedHtmlDelegateViews(); | 60 WebDialogWebContentsDelegate* tab_delegate); |
| 61 virtual ~ConstrainedWebDialogDelegateViewViews(); |
| 60 | 62 |
| 61 void set_window(ConstrainedWindow* window) { | 63 void set_window(ConstrainedWindow* window) { |
| 62 return impl_->set_window(window); | 64 return impl_->set_window(window); |
| 63 } | 65 } |
| 64 | 66 |
| 65 // ConstrainedHtmlUIDelegate interface | 67 // ConstrainedWebDialogDelegate interface |
| 66 virtual const HtmlDialogUIDelegate* GetHtmlDialogUIDelegate() const OVERRIDE { | 68 virtual const WebDialogDelegate* |
| 67 return impl_->GetHtmlDialogUIDelegate(); | 69 GetWebDialogDelegate() const OVERRIDE { |
| 70 return impl_->GetWebDialogDelegate(); |
| 68 } | 71 } |
| 69 virtual HtmlDialogUIDelegate* GetHtmlDialogUIDelegate() OVERRIDE { | 72 virtual WebDialogDelegate* GetWebDialogDelegate() OVERRIDE { |
| 70 return impl_->GetHtmlDialogUIDelegate(); | 73 return impl_->GetWebDialogDelegate(); |
| 71 } | 74 } |
| 72 virtual void OnDialogCloseFromWebUI() OVERRIDE { | 75 virtual void OnDialogCloseFromWebUI() OVERRIDE { |
| 73 return impl_->OnDialogCloseFromWebUI(); | 76 return impl_->OnDialogCloseFromWebUI(); |
| 74 } | 77 } |
| 75 virtual void ReleaseTabContentsOnDialogClose() OVERRIDE { | 78 virtual void ReleaseTabContentsOnDialogClose() OVERRIDE { |
| 76 return impl_->ReleaseTabContentsOnDialogClose(); | 79 return impl_->ReleaseTabContentsOnDialogClose(); |
| 77 } | 80 } |
| 78 virtual ConstrainedWindow* window() OVERRIDE { | 81 virtual ConstrainedWindow* window() OVERRIDE { |
| 79 return impl_->window(); | 82 return impl_->window(); |
| 80 } | 83 } |
| 81 virtual TabContentsWrapper* tab() OVERRIDE { | 84 virtual TabContentsWrapper* tab() OVERRIDE { |
| 82 return impl_->tab(); | 85 return impl_->tab(); |
| 83 } | 86 } |
| 84 | 87 |
| 85 // views::WidgetDelegate interface. | 88 // views::WidgetDelegate interface. |
| 86 virtual views::View* GetInitiallyFocusedView() OVERRIDE { | 89 virtual views::View* GetInitiallyFocusedView() OVERRIDE { |
| 87 return this; | 90 return this; |
| 88 } | 91 } |
| 89 virtual bool CanResize() const OVERRIDE { return true; } | 92 virtual bool CanResize() const OVERRIDE { return true; } |
| 90 virtual void WindowClosing() OVERRIDE { | 93 virtual void WindowClosing() OVERRIDE { |
| 91 if (!impl_->closed_via_webui()) | 94 if (!impl_->closed_via_webui()) |
| 92 GetHtmlDialogUIDelegate()->OnDialogClosed(std::string()); | 95 GetWebDialogDelegate()->OnDialogClosed(std::string()); |
| 93 } | 96 } |
| 94 virtual views::Widget* GetWidget() OVERRIDE { | 97 virtual views::Widget* GetWidget() OVERRIDE { |
| 95 return View::GetWidget(); | 98 return View::GetWidget(); |
| 96 } | 99 } |
| 97 virtual const views::Widget* GetWidget() const OVERRIDE { | 100 virtual const views::Widget* GetWidget() const OVERRIDE { |
| 98 return View::GetWidget(); | 101 return View::GetWidget(); |
| 99 } | 102 } |
| 100 virtual string16 GetWindowTitle() const OVERRIDE { | 103 virtual string16 GetWindowTitle() const OVERRIDE { |
| 101 return GetHtmlDialogUIDelegate()->GetDialogTitle(); | 104 return GetWebDialogDelegate()->GetDialogTitle(); |
| 102 } | 105 } |
| 103 virtual views::View* GetContentsView() OVERRIDE { | 106 virtual views::View* GetContentsView() OVERRIDE { |
| 104 return this; | 107 return this; |
| 105 } | 108 } |
| 106 | 109 |
| 107 // views::WebView overrides. | 110 // views::WebView overrides. |
| 108 virtual gfx::Size GetPreferredSize() OVERRIDE { | 111 virtual gfx::Size GetPreferredSize() OVERRIDE { |
| 109 gfx::Size size; | 112 gfx::Size size; |
| 110 GetHtmlDialogUIDelegate()->GetDialogSize(&size); | 113 GetWebDialogDelegate()->GetDialogSize(&size); |
| 111 return size; | 114 return size; |
| 112 } | 115 } |
| 113 | 116 |
| 114 private: | 117 private: |
| 115 scoped_ptr<ConstrainedHtmlUIDelegateImplViews> impl_; | 118 scoped_ptr<ConstrainedWebDialogDelegateViews> impl_; |
| 116 | 119 |
| 117 DISALLOW_COPY_AND_ASSIGN(ConstrainedHtmlDelegateViews); | 120 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViewViews); |
| 118 }; | 121 }; |
| 119 | 122 |
| 120 ConstrainedHtmlDelegateViews::ConstrainedHtmlDelegateViews( | 123 ConstrainedWebDialogDelegateViewViews::ConstrainedWebDialogDelegateViewViews( |
| 121 Profile* profile, | 124 Profile* profile, |
| 122 HtmlDialogUIDelegate* delegate, | 125 WebDialogDelegate* delegate, |
| 123 HtmlDialogTabContentsDelegate* tab_delegate) | 126 WebDialogWebContentsDelegate* tab_delegate) |
| 124 : views::WebView(profile), | 127 : views::WebView(profile), |
| 125 impl_(new ConstrainedHtmlUIDelegateImplViews(profile, | 128 impl_(new ConstrainedWebDialogDelegateViews(profile, |
| 126 delegate, | 129 delegate, |
| 127 tab_delegate)) { | 130 tab_delegate)) { |
| 128 SetWebContents(tab()->web_contents()); | 131 SetWebContents(tab()->web_contents()); |
| 129 } | 132 } |
| 130 | 133 |
| 131 ConstrainedHtmlDelegateViews::~ConstrainedHtmlDelegateViews() { | 134 ConstrainedWebDialogDelegateViewViews::~ConstrainedWebDialogDelegateViewViews()
{ |
| 132 } | 135 } |
| 133 | 136 |
| 134 // static | 137 // static |
| 135 ConstrainedHtmlUIDelegate* ConstrainedHtmlUI::CreateConstrainedHtmlDialog( | 138 ConstrainedWebDialogDelegate* |
| 136 Profile* profile, | 139 ConstrainedWebDialogUI::CreateConstrainedWebDialog( |
| 137 HtmlDialogUIDelegate* delegate, | 140 Profile* profile, |
| 138 HtmlDialogTabContentsDelegate* tab_delegate, | 141 WebDialogDelegate* delegate, |
| 139 TabContentsWrapper* container) { | 142 WebDialogWebContentsDelegate* tab_delegate, |
| 140 ConstrainedHtmlDelegateViews* constrained_delegate = | 143 TabContentsWrapper* container) { |
| 141 new ConstrainedHtmlDelegateViews(profile, delegate, tab_delegate); | 144 ConstrainedWebDialogDelegateViewViews* constrained_delegate = |
| 145 new ConstrainedWebDialogDelegateViewViews(profile, delegate, tab_delegate)
; |
| 142 ConstrainedWindow* constrained_window = | 146 ConstrainedWindow* constrained_window = |
| 143 new ConstrainedWindowViews(container, constrained_delegate); | 147 new ConstrainedWindowViews(container, constrained_delegate); |
| 144 constrained_delegate->set_window(constrained_window); | 148 constrained_delegate->set_window(constrained_window); |
| 145 return constrained_delegate; | 149 return constrained_delegate; |
| 146 } | 150 } |
| OLD | NEW |