OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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.h" | 5 #include "chrome/browser/ui/webui/constrained_html_ui.h" |
6 | 6 |
7 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
8 #include "chrome/browser/ui/gtk/constrained_window_gtk.h" | 8 #include "chrome/browser/ui/gtk/constrained_window_gtk.h" |
9 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 9 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
10 #include "chrome/browser/ui/views/tab_contents/tab_contents_container.h" | 10 #include "chrome/browser/ui/views/tab_contents/tab_contents_container.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 public ConstrainedWindowGtkDelegate, | 22 public ConstrainedWindowGtkDelegate, |
23 public HtmlDialogTabContentsDelegate { | 23 public HtmlDialogTabContentsDelegate { |
24 public: | 24 public: |
25 ConstrainedHtmlDelegateGtk(Profile* profile, | 25 ConstrainedHtmlDelegateGtk(Profile* profile, |
26 HtmlDialogUIDelegate* delegate); | 26 HtmlDialogUIDelegate* delegate); |
27 ~ConstrainedHtmlDelegateGtk(); | 27 ~ConstrainedHtmlDelegateGtk(); |
28 | 28 |
29 // ConstrainedHtmlUIDelegate interface. | 29 // ConstrainedHtmlUIDelegate interface. |
30 virtual HtmlDialogUIDelegate* GetHtmlDialogUIDelegate() OVERRIDE; | 30 virtual HtmlDialogUIDelegate* GetHtmlDialogUIDelegate() OVERRIDE; |
31 virtual void OnDialogCloseFromWebUI() OVERRIDE; | 31 virtual void OnDialogCloseFromWebUI() OVERRIDE; |
32 virtual bool GetBackgroundColor(GdkColor* color) OVERRIDE { | 32 virtual void ReleaseTabContentsOnDialogClose() OVERRIDE { |
33 *color = ui::kGdkWhite; | 33 release_tab_on_close_ = true; |
34 return true; | |
35 } | 34 } |
| 35 virtual ConstrainedWindow* window() OVERRIDE { |
| 36 return window_; |
| 37 } |
| 38 virtual TabContentsWrapper* tab() OVERRIDE { |
| 39 return html_tab_contents_.get(); |
| 40 } |
| 41 |
36 | 42 |
37 // ConstrainedWindowGtkDelegate implementation. | 43 // ConstrainedWindowGtkDelegate implementation. |
38 virtual GtkWidget* GetWidgetRoot() OVERRIDE { | 44 virtual GtkWidget* GetWidgetRoot() OVERRIDE { |
39 return GetNativeView(); | 45 return GetNativeView(); |
40 } | 46 } |
41 virtual GtkWidget* GetFocusWidget() OVERRIDE { | 47 virtual GtkWidget* GetFocusWidget() OVERRIDE { |
42 return html_tab_contents_.GetContentNativeView(); | 48 return html_tab_contents_->tab_contents()->GetContentNativeView(); |
43 } | 49 } |
44 virtual void DeleteDelegate() OVERRIDE { | 50 virtual void DeleteDelegate() OVERRIDE { |
45 if (!closed_via_webui_) | 51 if (!closed_via_webui_) |
46 html_delegate_->OnDialogClosed(""); | 52 html_delegate_->OnDialogClosed(""); |
47 tab_container_->ChangeTabContents(NULL); | 53 tab_container_->ChangeTabContents(NULL); |
48 } | 54 } |
| 55 virtual bool GetBackgroundColor(GdkColor* color) OVERRIDE { |
| 56 *color = ui::kGdkWhite; |
| 57 return true; |
| 58 } |
49 virtual bool ShouldHaveBorderPadding() const OVERRIDE { | 59 virtual bool ShouldHaveBorderPadding() const OVERRIDE { |
50 return false; | 60 return false; |
51 } | 61 } |
52 | 62 |
53 // HtmlDialogTabContentsDelegate interface. | 63 // HtmlDialogTabContentsDelegate interface. |
54 void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) OVERRIDE {} | 64 void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) OVERRIDE {} |
55 | 65 |
56 void set_window(ConstrainedWindow* window) { | 66 void set_window(ConstrainedWindow* window) { |
57 window_ = window; | 67 window_ = window; |
58 } | 68 } |
59 | 69 |
60 private: | 70 private: |
61 TabContents html_tab_contents_; | 71 scoped_ptr<TabContentsWrapper> html_tab_contents_; |
62 TabContentsContainer* tab_container_; | 72 TabContentsContainer* tab_container_; |
63 | 73 |
64 HtmlDialogUIDelegate* html_delegate_; | 74 HtmlDialogUIDelegate* html_delegate_; |
65 | 75 |
66 // The constrained window that owns |this|. Saved so we can close it later. | 76 // The constrained window that owns |this|. Saved so we can close it later. |
67 ConstrainedWindow* window_; | 77 ConstrainedWindow* window_; |
68 | 78 |
69 // Was the dialog closed from WebUI (in which case |html_delegate_|'s | 79 // Was the dialog closed from WebUI (in which case |html_delegate_|'s |
70 // OnDialogClosed() method has already been called)? | 80 // OnDialogClosed() method has already been called)? |
71 bool closed_via_webui_; | 81 bool closed_via_webui_; |
| 82 |
| 83 // If true, release |tab_| on close instead of destroying it. |
| 84 bool release_tab_on_close_; |
72 }; | 85 }; |
73 | 86 |
74 ConstrainedHtmlDelegateGtk::ConstrainedHtmlDelegateGtk( | 87 ConstrainedHtmlDelegateGtk::ConstrainedHtmlDelegateGtk( |
75 Profile* profile, | 88 Profile* profile, |
76 HtmlDialogUIDelegate* delegate) | 89 HtmlDialogUIDelegate* delegate) |
77 : views::NativeWidgetGtk(new views::Widget), | 90 : views::NativeWidgetGtk(new views::Widget), |
78 HtmlDialogTabContentsDelegate(profile), | 91 HtmlDialogTabContentsDelegate(profile), |
79 html_tab_contents_(profile, NULL, MSG_ROUTING_NONE, NULL, NULL), | |
80 tab_container_(NULL), | 92 tab_container_(NULL), |
81 html_delegate_(delegate), | 93 html_delegate_(delegate), |
82 window_(NULL), | 94 window_(NULL), |
83 closed_via_webui_(false) { | 95 closed_via_webui_(false) { |
84 CHECK(delegate); | 96 CHECK(delegate); |
85 html_tab_contents_.set_delegate(this); | 97 TabContents* tab_contents = |
| 98 new TabContents(profile, NULL, MSG_ROUTING_NONE, NULL, NULL); |
| 99 html_tab_contents_.reset(new TabContentsWrapper(tab_contents)); |
| 100 tab_contents->set_delegate(this); |
86 | 101 |
87 // Set |this| as a property so the ConstrainedHtmlUI can retrieve it. | 102 // Set |this| as a property so the ConstrainedHtmlUI can retrieve it. |
88 ConstrainedHtmlUI::GetPropertyAccessor().SetProperty( | 103 ConstrainedHtmlUI::GetPropertyAccessor().SetProperty( |
89 html_tab_contents_.property_bag(), this); | 104 tab_contents->property_bag(), this); |
90 html_tab_contents_.controller().LoadURL(delegate->GetDialogContentURL(), | 105 tab_contents->controller().LoadURL(delegate->GetDialogContentURL(), GURL(), |
91 GURL(), | 106 content::PAGE_TRANSITION_START_PAGE, |
92 content::PAGE_TRANSITION_START_PAGE, | 107 std::string()); |
93 std::string()); | |
94 | 108 |
95 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); | 109 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); |
96 params.native_widget = this; | 110 params.native_widget = this; |
97 GetWidget()->Init(params); | 111 GetWidget()->Init(params); |
98 | 112 |
99 tab_container_ = new TabContentsContainer; | 113 tab_container_ = new TabContentsContainer; |
100 GetWidget()->SetContentsView(tab_container_); | 114 GetWidget()->SetContentsView(tab_container_); |
101 tab_container_->ChangeTabContents(&html_tab_contents_); | 115 tab_container_->ChangeTabContents(html_tab_contents_->tab_contents()); |
102 | 116 |
103 gfx::Size dialog_size; | 117 gfx::Size dialog_size; |
104 html_delegate_->GetDialogSize(&dialog_size); | 118 html_delegate_->GetDialogSize(&dialog_size); |
105 gtk_widget_set_size_request(GetWidgetRoot(), | 119 gtk_widget_set_size_request(GetWidgetRoot(), |
106 dialog_size.width(), | 120 dialog_size.width(), |
107 dialog_size.height()); | 121 dialog_size.height()); |
108 } | 122 } |
109 | 123 |
110 ConstrainedHtmlDelegateGtk::~ConstrainedHtmlDelegateGtk() { | 124 ConstrainedHtmlDelegateGtk::~ConstrainedHtmlDelegateGtk() { |
111 } | 125 } |
112 | 126 |
113 HtmlDialogUIDelegate* ConstrainedHtmlDelegateGtk::GetHtmlDialogUIDelegate() { | 127 HtmlDialogUIDelegate* ConstrainedHtmlDelegateGtk::GetHtmlDialogUIDelegate() { |
114 return html_delegate_; | 128 return html_delegate_; |
115 } | 129 } |
116 | 130 |
117 void ConstrainedHtmlDelegateGtk::OnDialogCloseFromWebUI() { | 131 void ConstrainedHtmlDelegateGtk::OnDialogCloseFromWebUI() { |
118 closed_via_webui_ = true; | 132 closed_via_webui_ = true; |
119 window_->CloseConstrainedWindow(); | 133 window_->CloseConstrainedWindow(); |
120 } | 134 } |
121 | 135 |
122 // static | 136 // static |
123 ConstrainedWindow* ConstrainedHtmlUI::CreateConstrainedHtmlDialog( | 137 ConstrainedHtmlUIDelegate* ConstrainedHtmlUI::CreateConstrainedHtmlDialog( |
124 Profile* profile, | 138 Profile* profile, |
125 HtmlDialogUIDelegate* delegate, | 139 HtmlDialogUIDelegate* delegate, |
126 TabContentsWrapper* wrapper) { | 140 TabContentsWrapper* wrapper) { |
127 ConstrainedHtmlDelegateGtk* constrained_delegate = | 141 ConstrainedHtmlDelegateGtk* constrained_delegate = |
128 new ConstrainedHtmlDelegateGtk(profile, delegate); | 142 new ConstrainedHtmlDelegateGtk(profile, delegate); |
129 ConstrainedWindow* constrained_window = | 143 ConstrainedWindow* constrained_window = |
130 new ConstrainedWindowGtk(wrapper, constrained_delegate); | 144 new ConstrainedWindowGtk(wrapper, constrained_delegate); |
131 constrained_delegate->set_window(constrained_window); | 145 constrained_delegate->set_window(constrained_window); |
132 return constrained_window; | 146 return constrained_delegate; |
133 } | 147 } |
OLD | NEW |