Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: chrome/browser/views/html_dialog_view.cc

Issue 441011: Created HtmlDialogTabContentsDelegate, which encapsulates the (Closed)
Patch Set: Synced to head. Created 11 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/views/html_dialog_view.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/views/html_dialog_view.h" 5 #include "chrome/browser/views/html_dialog_view.h"
6 6
7 #include "base/keyboard_codes.h" 7 #include "base/keyboard_codes.h"
8 #include "chrome/browser/browser.h" 8 #include "chrome/browser/browser.h"
9 #include "chrome/browser/tab_contents/tab_contents.h" 9 #include "chrome/browser/tab_contents/tab_contents.h"
10 #include "views/widget/root_view.h" 10 #include "views/widget/root_view.h"
11 #include "views/widget/widget.h" 11 #include "views/widget/widget.h"
12 #include "views/window/window.h" 12 #include "views/window/window.h"
13 13
14 namespace browser { 14 namespace browser {
15 15
16 // Declared in browser_dialogs.h so that others don't need to depend on our .h. 16 // Declared in browser_dialogs.h so that others don't need to depend on our .h.
17 void ShowHtmlDialogView(gfx::NativeWindow parent, Browser* browser, 17 void ShowHtmlDialogView(gfx::NativeWindow parent, Browser* browser,
18 HtmlDialogUIDelegate* delegate) { 18 HtmlDialogUIDelegate* delegate) {
19 HtmlDialogView* html_view = new HtmlDialogView(browser, delegate); 19 HtmlDialogView* html_view =
20 new HtmlDialogView(browser->profile(), delegate);
20 views::Window::CreateChromeWindow(parent, gfx::Rect(), html_view); 21 views::Window::CreateChromeWindow(parent, gfx::Rect(), html_view);
21 html_view->InitDialog(); 22 html_view->InitDialog();
22 html_view->window()->Show(); 23 html_view->window()->Show();
23 } 24 }
24 25
25 } // namespace browser 26 } // namespace browser
26 27
27 //////////////////////////////////////////////////////////////////////////////// 28 ////////////////////////////////////////////////////////////////////////////////
28 // HtmlDialogView, public: 29 // HtmlDialogView, public:
29 30
30 HtmlDialogView::HtmlDialogView(Browser* parent_browser, 31 HtmlDialogView::HtmlDialogView(Profile* profile,
31 HtmlDialogUIDelegate* delegate) 32 HtmlDialogUIDelegate* delegate)
32 : DOMView(), 33 : DOMView(),
33 parent_browser_(parent_browser), 34 HtmlDialogTabContentsDelegate(profile),
34 profile_(parent_browser->profile()),
35 delegate_(delegate) { 35 delegate_(delegate) {
36 DCHECK(profile_);
37 } 36 }
38 37
39 HtmlDialogView::~HtmlDialogView() { 38 HtmlDialogView::~HtmlDialogView() {
40 } 39 }
41 40
42 //////////////////////////////////////////////////////////////////////////////// 41 ////////////////////////////////////////////////////////////////////////////////
43 // HtmlDialogView, views::View implementation: 42 // HtmlDialogView, views::View implementation:
44 43
45 gfx::Size HtmlDialogView::GetPreferredSize() { 44 gfx::Size HtmlDialogView::GetPreferredSize() {
46 gfx::Size out; 45 gfx::Size out;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 std::string HtmlDialogView::GetDialogArgs() const { 124 std::string HtmlDialogView::GetDialogArgs() const {
126 if (delegate_) 125 if (delegate_)
127 return delegate_->GetDialogArgs(); 126 return delegate_->GetDialogArgs();
128 else 127 else
129 return std::string(); 128 return std::string();
130 } 129 }
131 130
132 void HtmlDialogView::OnDialogClosed(const std::string& json_retval) { 131 void HtmlDialogView::OnDialogClosed(const std::string& json_retval) {
133 HtmlDialogUIDelegate* dialog_delegate = delegate_; 132 HtmlDialogUIDelegate* dialog_delegate = delegate_;
134 delegate_ = NULL; // We will not communicate further with the delegate. 133 delegate_ = NULL; // We will not communicate further with the delegate.
134 HtmlDialogTabContentsDelegate::Detach();
135 dialog_delegate->OnDialogClosed(json_retval); 135 dialog_delegate->OnDialogClosed(json_retval);
136 window()->Close(); 136 window()->Close();
137 } 137 }
138 138
139 //////////////////////////////////////////////////////////////////////////////// 139 ////////////////////////////////////////////////////////////////////////////////
140 // TabContentsDelegate implementation: 140 // TabContentsDelegate implementation:
141 141
142 void HtmlDialogView::OpenURLFromTab(TabContents* source,
143 const GURL& url,
144 const GURL& referrer,
145 WindowOpenDisposition disposition,
146 PageTransition::Type transition) {
147 // Force all links to open in a new window, ignoring the incoming
148 // disposition. This is a tabless, modal dialog so we can't just
149 // open it in the current frame.
150 static_cast<TabContentsDelegate*>(parent_browser_)->OpenURLFromTab(
151 source, url, referrer, NEW_WINDOW, transition);
152 }
153
154 void HtmlDialogView::NavigationStateChanged(const TabContents* source,
155 unsigned changed_flags) {
156 // We shouldn't receive any NavigationStateChanged except the first
157 // one, which we ignore because we're a dialog box.
158 }
159
160 void HtmlDialogView::ReplaceContents(TabContents* source,
161 TabContents* new_contents) {
162 }
163
164 void HtmlDialogView::AddNewContents(TabContents* source,
165 TabContents* new_contents,
166 WindowOpenDisposition disposition,
167 const gfx::Rect& initial_pos,
168 bool user_gesture) {
169 static_cast<TabContentsDelegate*>(parent_browser_)->AddNewContents(
170 source, new_contents, NEW_WINDOW, initial_pos, user_gesture);
171 }
172
173 void HtmlDialogView::ActivateContents(TabContents* contents) {
174 // We don't do anything here because there's only one TabContents in
175 // this frame and we don't have a TabStripModel.
176 }
177
178 void HtmlDialogView::LoadingStateChanged(TabContents* source) {
179 // We don't care about this notification.
180 }
181
182 void HtmlDialogView::CloseContents(TabContents* source) {
183 // We receive this message but don't handle it because we really do the
184 // cleanup in OnDialogClosed().
185 }
186
187 void HtmlDialogView::MoveContents(TabContents* source, const gfx::Rect& pos) { 142 void HtmlDialogView::MoveContents(TabContents* source, const gfx::Rect& pos) {
188 // The contained web page wishes to resize itself. We let it do this because 143 // The contained web page wishes to resize itself. We let it do this because
189 // if it's a dialog we know about, we trust it not to be mean to the user. 144 // if it's a dialog we know about, we trust it not to be mean to the user.
190 GetWidget()->SetBounds(pos); 145 GetWidget()->SetBounds(pos);
191 } 146 }
192 147
193 bool HtmlDialogView::IsPopup(TabContents* source) {
194 // This needs to return true so that we are allowed to be resized by our
195 // contents.
196 return true;
197 }
198
199 void HtmlDialogView::ToolbarSizeChanged(TabContents* source, 148 void HtmlDialogView::ToolbarSizeChanged(TabContents* source,
200 bool is_animating) { 149 bool is_animating) {
201 Layout(); 150 Layout();
202 } 151 }
203 152
204 void HtmlDialogView::URLStarredChanged(TabContents* source, bool starred) {
205 // We don't have a visible star to click in the window.
206 NOTREACHED();
207 }
208
209 void HtmlDialogView::UpdateTargetURL(TabContents* source, const GURL& url) {
210 // Ignored.
211 }
212
213 //////////////////////////////////////////////////////////////////////////////// 153 ////////////////////////////////////////////////////////////////////////////////
214 // HtmlDialogView: 154 // HtmlDialogView:
215 155
216 void HtmlDialogView::InitDialog() { 156 void HtmlDialogView::InitDialog() {
217 // Now Init the DOMView. This view runs in its own process to render the html. 157 // Now Init the DOMView. This view runs in its own process to render the html.
218 DOMView::Init(profile_, NULL); 158 DOMView::Init(profile(), NULL);
219 159
220 tab_contents_->set_delegate(this); 160 tab_contents_->set_delegate(this);
221 161
222 // Set the delegate. This must be done before loading the page. See 162 // Set the delegate. This must be done before loading the page. See
223 // the comment above HtmlDialogUI in its header file for why. 163 // the comment above HtmlDialogUI in its header file for why.
224 HtmlDialogUI::GetPropertyAccessor().SetProperty(tab_contents_->property_bag(), 164 HtmlDialogUI::GetPropertyAccessor().SetProperty(tab_contents_->property_bag(),
225 this); 165 this);
226 166
227 // Pressing the ESC key will close the dialog. 167 // Pressing the ESC key will close the dialog.
228 AddAccelerator(views::Accelerator(base::VKEY_ESCAPE, false, false, false)); 168 AddAccelerator(views::Accelerator(base::VKEY_ESCAPE, false, false, false));
229 169
230 DOMView::LoadURL(delegate_->GetDialogContentURL()); 170 DOMView::LoadURL(delegate_->GetDialogContentURL());
231 } 171 }
OLDNEW
« no previous file with comments | « chrome/browser/views/html_dialog_view.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698