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

Side by Side Diff: chrome/browser/ui/views/simple_message_box_views.cc

Issue 23291003: Don't try to use compositor to display dialog before compositor is initialized (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: refactor to avoid copying Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/ui/views/simple_message_box_win.h » ('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) 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/simple_message_box.h" 5 #include "chrome/browser/ui/simple_message_box.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/ui/views/constrained_window_views.h" 13 #include "chrome/browser/ui/views/constrained_window_views.h"
14 #include "grit/generated_resources.h" 14 #include "grit/generated_resources.h"
15 #include "ui/base/l10n/l10n_util.h" 15 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/gfx/native_widget_types.h" 16 #include "ui/gfx/native_widget_types.h"
17 #include "ui/views/controls/message_box_view.h" 17 #include "ui/views/controls/message_box_view.h"
18 #include "ui/views/widget/widget.h" 18 #include "ui/views/widget/widget.h"
19 #include "ui/views/window/dialog_delegate.h" 19 #include "ui/views/window/dialog_delegate.h"
20 20
21 #if defined(USE_AURA) 21 #if defined(USE_AURA)
22 #include "ui/aura/client/dispatcher_client.h" 22 #include "ui/aura/client/dispatcher_client.h"
23 #include "ui/aura/env.h" 23 #include "ui/aura/env.h"
24 #include "ui/aura/root_window.h" 24 #include "ui/aura/root_window.h"
25 #if defined(OS_WIN)
26 #include "chrome/browser/ui/views/simple_message_box_win.h"
27 #endif
25 #endif 28 #endif
26 29
27 namespace chrome { 30 namespace chrome {
28 31
29 namespace { 32 namespace {
30 33
31 // Multiple SimpleMessageBoxViews can show up at the same time. Each of these 34 // Multiple SimpleMessageBoxViews can show up at the same time. Each of these
32 // start a nested message-loop. However, these SimpleMessageBoxViews can be 35 // start a nested message-loop. However, these SimpleMessageBoxViews can be
33 // deleted in any order. This creates problems if a box in an inner-loop gets 36 // deleted in any order. This creates problems if a box in an inner-loop gets
34 // destroyed before a box in an outer-loop. So to avoid this, ref-counting is 37 // destroyed before a box in an outer-loop. So to avoid this, ref-counting is
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 170
168 SimpleMessageBoxViews::~SimpleMessageBoxViews() { 171 SimpleMessageBoxViews::~SimpleMessageBoxViews() {
169 } 172 }
170 173
171 } // namespace 174 } // namespace
172 175
173 MessageBoxResult ShowMessageBox(gfx::NativeWindow parent, 176 MessageBoxResult ShowMessageBox(gfx::NativeWindow parent,
174 const string16& title, 177 const string16& title,
175 const string16& message, 178 const string16& message,
176 MessageBoxType type) { 179 MessageBoxType type) {
180 #if defined(USE_AURA) && defined(OS_WIN)
181 // If we're very early, we can't show a GPU-based dialog, so fallback to
182 // plain Windows MessageBox.
183 if (!ui::ContextFactory::GetInstance())
184 return NativeShowMessageBox(NULL, title, message, type);
185 #endif
186
177 scoped_refptr<SimpleMessageBoxViews> dialog( 187 scoped_refptr<SimpleMessageBoxViews> dialog(
178 new SimpleMessageBoxViews(title, message, type)); 188 new SimpleMessageBoxViews(title, message, type));
179 CreateBrowserModalDialogViews(dialog.get(), parent)->Show(); 189 CreateBrowserModalDialogViews(dialog.get(), parent)->Show();
180 190
181 #if defined(USE_AURA) 191 #if defined(USE_AURA)
182 // Use the widget's window itself so that the message loop 192 // Use the widget's window itself so that the message loop
183 // exists when the dialog is closed by some other means than 193 // exists when the dialog is closed by some other means than
184 // |Cancel| or |Accept|. 194 // |Cancel| or |Accept|.
185 aura::Window* anchor = parent ? 195 aura::Window* anchor = parent ?
186 parent : dialog->GetWidget()->GetNativeWindow(); 196 parent : dialog->GetWidget()->GetNativeWindow();
187 aura::client::GetDispatcherClient(anchor->GetRootWindow()) 197 aura::client::GetDispatcherClient(anchor->GetRootWindow())
188 ->RunWithDispatcher(dialog.get(), anchor, true); 198 ->RunWithDispatcher(dialog.get(), anchor, true);
189 #else 199 #else
190 { 200 {
191 base::MessageLoop::ScopedNestableTaskAllower allow( 201 base::MessageLoop::ScopedNestableTaskAllower allow(
192 base::MessageLoopForUI::current()); 202 base::MessageLoopForUI::current());
193 base::RunLoop run_loop(dialog); 203 base::RunLoop run_loop(dialog);
194 run_loop.Run(); 204 run_loop.Run();
195 } 205 }
196 #endif 206 #endif
197 return dialog->result(); 207 return dialog->result();
198 } 208 }
199 209
200 } // namespace chrome 210 } // namespace chrome
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/views/simple_message_box_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698