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

Side by Side Diff: chrome/browser/jsmessage_box_handler_win.cc

Issue 27080: AppModalDialogQueue shouldn't depend on views. (Closed) Base URL: svn://chrome-svn.corp.google.com/chrome/trunk/src/
Patch Set: '' Created 11 years, 10 months 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/jsmessage_box_handler_win.h ('k') | chrome/test/unit/unittests.vcproj » ('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/jsmessage_box_handler_win.h" 5 #include "chrome/browser/jsmessage_box_handler_win.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "chrome/browser/app_modal_dialog_queue.h" 8 #include "chrome/browser/app_modal_dialog_queue.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/profile.h" 10 #include "chrome/browser/profile.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, 59 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
60 NotificationService::AllSources()); 60 NotificationService::AllSources());
61 registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED, 61 registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED,
62 NotificationService::AllSources()); 62 NotificationService::AllSources());
63 } 63 }
64 64
65 JavascriptMessageBoxHandler::~JavascriptMessageBoxHandler() { 65 JavascriptMessageBoxHandler::~JavascriptMessageBoxHandler() {
66 } 66 }
67 67
68 ////////////////////////////////////////////////////////////////////////////// 68 //////////////////////////////////////////////////////////////////////////////
69 // JavascriptMessageBoxHandler, views::AppModalDialogDelegate
70 // implementation:
71
72 void JavascriptMessageBoxHandler::ShowModalDialog() {
73 // If the WebContents that created this dialog navigated away before this
74 // dialog became visible, simply show the next dialog if any.
75 if (!web_contents_) {
76 AppModalDialogQueue::ShowNextDialog();
77 delete this;
78 return;
79 }
80
81 web_contents_->Activate();
82 HWND root_hwnd = GetAncestor(web_contents_->GetNativeView(), GA_ROOT);
83 dialog_ = views::Window::CreateChromeWindow(root_hwnd, gfx::Rect(), this);
84 dialog_->Show();
85 }
86
87 void JavascriptMessageBoxHandler::ActivateModalDialog() {
88 // Ensure that the dialog is visible and at the top of the z-order. These
89 // conditions may not be true if the dialog was opened on a different virtual
90 // desktop to the one the browser window is on.
91 dialog_->Show();
92 dialog_->Activate();
93 }
94
95 AppModalDialogDelegateTesting*
96 JavascriptMessageBoxHandler::GetTestingInterface() {
97 return this;
98 }
99
100 ///////////////////////////////////////////////////////////////////////////////
101 // JavascriptMessageBoxHandler, AppModalDialogDelegateTesting implementation:
102
103 views::DialogDelegate* JavascriptMessageBoxHandler::GetDialogDelegate() {
104 return this;
105 }
106
107 //////////////////////////////////////////////////////////////////////////////
69 // JavascriptMessageBoxHandler, views::DialogDelegate implementation: 108 // JavascriptMessageBoxHandler, views::DialogDelegate implementation:
70 109
71 int JavascriptMessageBoxHandler::GetDialogButtons() const { 110 int JavascriptMessageBoxHandler::GetDialogButtons() const {
72 int dialog_buttons = 0; 111 int dialog_buttons = 0;
73 if (dialog_flags_ & MessageBoxView::kFlagHasOKButton) 112 if (dialog_flags_ & MessageBoxView::kFlagHasOKButton)
74 dialog_buttons = DIALOGBUTTON_OK; 113 dialog_buttons = DIALOGBUTTON_OK;
75 114
76 if (dialog_flags_ & MessageBoxView::kFlagHasCancelButton) 115 if (dialog_flags_ & MessageBoxView::kFlagHasCancelButton)
77 dialog_buttons |= DIALOGBUTTON_CANCEL; 116 dialog_buttons |= DIALOGBUTTON_CANCEL;
78 117
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 bool JavascriptMessageBoxHandler::Accept() { 173 bool JavascriptMessageBoxHandler::Accept() {
135 AppModalDialogQueue::ShowNextDialog(); 174 AppModalDialogQueue::ShowNextDialog();
136 175
137 if (web_contents_) { 176 if (web_contents_) {
138 web_contents_->OnJavaScriptMessageBoxClosed( 177 web_contents_->OnJavaScriptMessageBoxClosed(
139 reply_msg_, true, message_box_view_->GetInputText()); 178 reply_msg_, true, message_box_view_->GetInputText());
140 } 179 }
141 return true; 180 return true;
142 } 181 }
143 182
144 //////////////////////////////////////////////////////////////////////////////
145 // JavascriptMessageBoxHandler, views::AppModalDialogDelegate
146 // implementation:
147
148 void JavascriptMessageBoxHandler::ShowModalDialog() {
149 // If the WebContents that created this dialog navigated away before this
150 // dialog became visible, simply show the next dialog if any.
151 if (!web_contents_) {
152 AppModalDialogQueue::ShowNextDialog();
153 delete this;
154 return;
155 }
156
157 web_contents_->Activate();
158 HWND root_hwnd = GetAncestor(web_contents_->GetNativeView(), GA_ROOT);
159 dialog_ = views::Window::CreateChromeWindow(root_hwnd, gfx::Rect(), this);
160 dialog_->Show();
161 }
162
163 void JavascriptMessageBoxHandler::ActivateModalDialog() {
164 // Ensure that the dialog is visible and at the top of the z-order. These
165 // conditions may not be true if the dialog was opened on a different virtual
166 // desktop to the one the browser window is on.
167 dialog_->Show();
168 dialog_->Activate();
169 }
170
171 /////////////////////////////////////////////////////////////////////////////// 183 ///////////////////////////////////////////////////////////////////////////////
172 // JavascriptMessageBoxHandler, views::WindowDelegate implementation: 184 // JavascriptMessageBoxHandler, views::WindowDelegate implementation:
173 185
174 views::View* JavascriptMessageBoxHandler::GetContentsView() { 186 views::View* JavascriptMessageBoxHandler::GetContentsView() {
175 return message_box_view_; 187 return message_box_view_;
176 } 188 }
177 189
178 views::View* JavascriptMessageBoxHandler::GetInitiallyFocusedView() { 190 views::View* JavascriptMessageBoxHandler::GetInitiallyFocusedView() {
179 if (message_box_view_->text_box()) 191 if (message_box_view_->text_box())
180 return message_box_view_->text_box(); 192 return message_box_view_->text_box();
181 return views::AppModalDialogDelegate::GetInitiallyFocusedView(); 193 return views::DialogDelegate::GetInitiallyFocusedView();
182 } 194 }
183 195
184 /////////////////////////////////////////////////////////////////////////////// 196 ///////////////////////////////////////////////////////////////////////////////
185 // JavascriptMessageBoxHandler, private: 197 // JavascriptMessageBoxHandler, private:
186 198
187 void JavascriptMessageBoxHandler::Observe(NotificationType type, 199 void JavascriptMessageBoxHandler::Observe(NotificationType type,
188 const NotificationSource& source, 200 const NotificationSource& source,
189 const NotificationDetails& details) { 201 const NotificationDetails& details) {
190 bool web_contents_gone = false; 202 bool web_contents_gone = false;
191 if (!web_contents_) 203 if (!web_contents_)
192 return; 204 return;
193 205
194 if (type == NotificationType::NAV_ENTRY_COMMITTED && 206 if (type == NotificationType::NAV_ENTRY_COMMITTED &&
195 Source<NavigationController>(source).ptr() == web_contents_->controller()) 207 Source<NavigationController>(source).ptr() == web_contents_->controller())
196 web_contents_gone = true; 208 web_contents_gone = true;
197 209
198 if (type == NotificationType::TAB_CONTENTS_DESTROYED && 210 if (type == NotificationType::TAB_CONTENTS_DESTROYED &&
199 Source<TabContents>(source).ptr() == 211 Source<TabContents>(source).ptr() ==
200 static_cast<TabContents*>(web_contents_)) 212 static_cast<TabContents*>(web_contents_))
201 web_contents_gone = true; 213 web_contents_gone = true;
202 214
203 if (web_contents_gone) { 215 if (web_contents_gone) {
204 web_contents_ = NULL; 216 web_contents_ = NULL;
205 217
206 // If the dialog is visible close it. 218 // If the dialog is visible close it.
207 if (dialog_) 219 if (dialog_)
208 dialog_->Close(); 220 dialog_->Close();
209 } 221 }
210 } 222 }
OLDNEW
« no previous file with comments | « chrome/browser/jsmessage_box_handler_win.h ('k') | chrome/test/unit/unittests.vcproj » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698