| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/gtk/html_dialog_gtk.h" | 5 #include "chrome/browser/gtk/html_dialog_gtk.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 | 8 |
| 9 #include "chrome/browser/browser.h" |
| 9 #include "chrome/browser/browser_window.h" | 10 #include "chrome/browser/browser_window.h" |
| 10 #include "chrome/browser/dom_ui/html_dialog_ui.h" | 11 #include "chrome/browser/dom_ui/html_dialog_ui.h" |
| 11 #include "chrome/browser/gtk/tab_contents_container_gtk.h" | 12 #include "chrome/browser/gtk/tab_contents_container_gtk.h" |
| 12 #include "chrome/browser/tab_contents/tab_contents.h" | 13 #include "chrome/browser/tab_contents/tab_contents.h" |
| 13 #include "chrome/common/gtk_util.h" | 14 #include "chrome/common/gtk_util.h" |
| 14 | 15 |
| 15 // static | 16 // static |
| 16 void HtmlDialogGtk::ShowHtmlDialogGtk(Browser* browser, | 17 void HtmlDialogGtk::ShowHtmlDialogGtk(Browser* browser, |
| 17 HtmlDialogUIDelegate* delegate) { | 18 HtmlDialogUIDelegate* delegate, |
| 18 HtmlDialogGtk* html_dialog = new HtmlDialogGtk(browser, delegate); | 19 gfx::NativeWindow parent_window) { |
| 20 HtmlDialogGtk* html_dialog = |
| 21 new HtmlDialogGtk(browser->profile(), delegate, parent_window); |
| 19 html_dialog->InitDialog(); | 22 html_dialog->InitDialog(); |
| 20 } | 23 } |
| 21 | 24 |
| 22 //////////////////////////////////////////////////////////////////////////////// | 25 //////////////////////////////////////////////////////////////////////////////// |
| 23 // HtmlDialogGtk, public: | 26 // HtmlDialogGtk, public: |
| 24 | 27 |
| 25 HtmlDialogGtk::HtmlDialogGtk(Browser* parent_browser, | 28 HtmlDialogGtk::HtmlDialogGtk(Profile* profile, |
| 26 HtmlDialogUIDelegate* delegate) | 29 HtmlDialogUIDelegate* delegate, |
| 27 : parent_browser_(parent_browser), | 30 gfx::NativeWindow parent_window) |
| 31 : HtmlDialogTabContentsDelegate(profile), |
| 28 delegate_(delegate), | 32 delegate_(delegate), |
| 33 parent_window_(parent_window), |
| 29 dialog_(NULL) { | 34 dialog_(NULL) { |
| 30 } | 35 } |
| 31 | 36 |
| 32 HtmlDialogGtk::~HtmlDialogGtk() { | 37 HtmlDialogGtk::~HtmlDialogGtk() { |
| 33 } | 38 } |
| 34 | 39 |
| 35 //////////////////////////////////////////////////////////////////////////////// | 40 //////////////////////////////////////////////////////////////////////////////// |
| 36 // HtmlDialogUIDelegate implementation: | 41 // HtmlDialogUIDelegate implementation: |
| 37 | 42 |
| 38 bool HtmlDialogGtk::IsDialogModal() const { | 43 bool HtmlDialogGtk::IsDialogModal() const { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 else | 76 else |
| 72 return std::string(); | 77 return std::string(); |
| 73 } | 78 } |
| 74 | 79 |
| 75 void HtmlDialogGtk::OnDialogClosed(const std::string& json_retval) { | 80 void HtmlDialogGtk::OnDialogClosed(const std::string& json_retval) { |
| 76 DCHECK(delegate_); | 81 DCHECK(delegate_); |
| 77 DCHECK(dialog_); | 82 DCHECK(dialog_); |
| 78 | 83 |
| 79 HtmlDialogUIDelegate* dialog_delegate = delegate_; | 84 HtmlDialogUIDelegate* dialog_delegate = delegate_; |
| 80 delegate_ = NULL; // We will not communicate further with the delegate. | 85 delegate_ = NULL; // We will not communicate further with the delegate. |
| 86 Detach(); |
| 81 dialog_delegate->OnDialogClosed(json_retval); | 87 dialog_delegate->OnDialogClosed(json_retval); |
| 82 gtk_widget_destroy(dialog_); | 88 gtk_widget_destroy(dialog_); |
| 83 delete this; | 89 delete this; |
| 84 } | 90 } |
| 85 | 91 |
| 86 //////////////////////////////////////////////////////////////////////////////// | 92 //////////////////////////////////////////////////////////////////////////////// |
| 87 // TabContentsDelegate implementation: | 93 // TabContentsDelegate implementation: |
| 88 | 94 |
| 89 void HtmlDialogGtk::OpenURLFromTab(TabContents* source, | |
| 90 const GURL& url, | |
| 91 const GURL& referrer, | |
| 92 WindowOpenDisposition disposition, | |
| 93 PageTransition::Type transition) { | |
| 94 // Force all links to open in a new window, ignoring the incoming | |
| 95 // disposition. This is a tabless, modal dialog so we can't just | |
| 96 // open it in the current frame. | |
| 97 static_cast<TabContentsDelegate*>(parent_browser_)->OpenURLFromTab( | |
| 98 source, url, referrer, NEW_WINDOW, transition); | |
| 99 } | |
| 100 | |
| 101 void HtmlDialogGtk::NavigationStateChanged(const TabContents* source, | |
| 102 unsigned changed_flags) { | |
| 103 // We shouldn't receive any NavigationStateChanged except the first | |
| 104 // one, which we ignore because we're a dialog box. | |
| 105 } | |
| 106 | |
| 107 void HtmlDialogGtk::ReplaceContents(TabContents* source, | |
| 108 TabContents* new_contents) { | |
| 109 } | |
| 110 | |
| 111 void HtmlDialogGtk::AddNewContents(TabContents* source, | |
| 112 TabContents* new_contents, | |
| 113 WindowOpenDisposition disposition, | |
| 114 const gfx::Rect& initial_pos, | |
| 115 bool user_gesture) { | |
| 116 static_cast<TabContentsDelegate*>(parent_browser_)->AddNewContents( | |
| 117 source, new_contents, NEW_WINDOW, initial_pos, user_gesture); | |
| 118 } | |
| 119 | |
| 120 void HtmlDialogGtk::ActivateContents(TabContents* contents) { | |
| 121 // We don't do anything here because there's only one TabContents in | |
| 122 // this frame and we don't have a TabStripModel. | |
| 123 } | |
| 124 | |
| 125 void HtmlDialogGtk::LoadingStateChanged(TabContents* source) { | |
| 126 // We don't care about this notification. | |
| 127 } | |
| 128 | |
| 129 void HtmlDialogGtk::CloseContents(TabContents* source) { | |
| 130 // We receive this message but don't handle it because we really do the | |
| 131 // cleanup in OnDialogClosed(). | |
| 132 } | |
| 133 | |
| 134 void HtmlDialogGtk::MoveContents(TabContents* source, const gfx::Rect& pos) { | 95 void HtmlDialogGtk::MoveContents(TabContents* source, const gfx::Rect& pos) { |
| 135 // The contained web page wishes to resize itself. We let it do this because | 96 // The contained web page wishes to resize itself. We let it do this because |
| 136 // if it's a dialog we know about, we trust it not to be mean to the user. | 97 // if it's a dialog we know about, we trust it not to be mean to the user. |
| 137 } | 98 } |
| 138 | 99 |
| 139 bool HtmlDialogGtk::IsPopup(TabContents* source) { | |
| 140 // This needs to return true so that we are allowed to be resized by our | |
| 141 // contents. | |
| 142 return true; | |
| 143 } | |
| 144 | |
| 145 void HtmlDialogGtk::ToolbarSizeChanged(TabContents* source, | 100 void HtmlDialogGtk::ToolbarSizeChanged(TabContents* source, |
| 146 bool is_animating) { | 101 bool is_animating) { |
| 147 // Ignored. | 102 // Ignored. |
| 148 } | 103 } |
| 149 | 104 |
| 150 void HtmlDialogGtk::URLStarredChanged(TabContents* source, bool starred) { | |
| 151 // We don't have a visible star to click in the window. | |
| 152 NOTREACHED(); | |
| 153 } | |
| 154 | |
| 155 void HtmlDialogGtk::UpdateTargetURL(TabContents* source, const GURL& url) { | |
| 156 // Ignored. | |
| 157 } | |
| 158 | |
| 159 //////////////////////////////////////////////////////////////////////////////// | 105 //////////////////////////////////////////////////////////////////////////////// |
| 160 // HtmlDialogGtk: | 106 // HtmlDialogGtk: |
| 161 | 107 |
| 162 void HtmlDialogGtk::InitDialog() { | 108 void HtmlDialogGtk::InitDialog() { |
| 163 Profile* profile = parent_browser_->profile(); | 109 tab_contents_.reset( |
| 164 tab_contents_.reset(new TabContents(profile, NULL, MSG_ROUTING_NONE, NULL)); | 110 new TabContents(profile(), NULL, MSG_ROUTING_NONE, NULL)); |
| 165 tab_contents_->set_delegate(this); | 111 tab_contents_->set_delegate(this); |
| 166 | 112 |
| 167 // This must be done before loading the page; see the comments in | 113 // This must be done before loading the page; see the comments in |
| 168 // HtmlDialogUI. | 114 // HtmlDialogUI. |
| 169 HtmlDialogUI::GetPropertyAccessor().SetProperty(tab_contents_->property_bag(), | 115 HtmlDialogUI::GetPropertyAccessor().SetProperty(tab_contents_->property_bag(), |
| 170 this); | 116 this); |
| 171 | 117 |
| 172 tab_contents_->controller().LoadURL(GetDialogContentURL(), | 118 tab_contents_->controller().LoadURL(GetDialogContentURL(), |
| 173 GURL(), PageTransition::START_PAGE); | 119 GURL(), PageTransition::START_PAGE); |
| 174 GtkDialogFlags flags = GTK_DIALOG_NO_SEPARATOR; | 120 GtkDialogFlags flags = GTK_DIALOG_NO_SEPARATOR; |
| 175 if (delegate_->IsDialogModal()) | 121 if (delegate_->IsDialogModal()) |
| 176 flags = static_cast<GtkDialogFlags>(flags | GTK_DIALOG_MODAL); | 122 flags = static_cast<GtkDialogFlags>(flags | GTK_DIALOG_MODAL); |
| 177 | 123 |
| 178 dialog_ = gtk_dialog_new_with_buttons( | 124 dialog_ = gtk_dialog_new_with_buttons( |
| 179 WideToUTF8(delegate_->GetDialogTitle()).c_str(), | 125 WideToUTF8(delegate_->GetDialogTitle()).c_str(), |
| 180 parent_browser_->window()->GetNativeHandle(), | 126 parent_window_, |
| 181 flags, | 127 flags, |
| 182 NULL); | 128 NULL); |
| 183 | 129 |
| 184 g_signal_connect(dialog_, "response", G_CALLBACK(OnResponse), this); | 130 g_signal_connect(dialog_, "response", G_CALLBACK(OnResponse), this); |
| 185 | 131 |
| 186 tab_contents_container_.reset(new TabContentsContainerGtk(NULL)); | 132 tab_contents_container_.reset(new TabContentsContainerGtk(NULL)); |
| 187 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog_)->vbox), | 133 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog_)->vbox), |
| 188 tab_contents_container_->widget(), TRUE, TRUE, 0); | 134 tab_contents_container_->widget(), TRUE, TRUE, 0); |
| 189 | 135 |
| 190 tab_contents_container_->SetTabContents(tab_contents_.get()); | 136 tab_contents_container_->SetTabContents(tab_contents_.get()); |
| 191 | 137 |
| 192 gfx::Size dialog_size; | 138 gfx::Size dialog_size; |
| 193 delegate_->GetDialogSize(&dialog_size); | 139 delegate_->GetDialogSize(&dialog_size); |
| 194 | 140 |
| 195 gtk_window_set_default_size(GTK_WINDOW(dialog_), | 141 gtk_window_set_default_size(GTK_WINDOW(dialog_), |
| 196 dialog_size.width(), | 142 dialog_size.width(), |
| 197 dialog_size.height()); | 143 dialog_size.height()); |
| 198 gtk_widget_show_all(dialog_); | 144 gtk_widget_show_all(dialog_); |
| 199 } | 145 } |
| 200 | 146 |
| 201 // static | 147 // static |
| 202 void HtmlDialogGtk::OnResponse(GtkWidget* widget, int response, | 148 void HtmlDialogGtk::OnResponse(GtkWidget* widget, int response, |
| 203 HtmlDialogGtk* dialog) { | 149 HtmlDialogGtk* dialog) { |
| 204 dialog->OnDialogClosed(std::string()); | 150 dialog->OnDialogClosed(std::string()); |
| 205 } | 151 } |
| OLD | NEW |