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

Side by Side Diff: ash/display/display_error_dialog.cc

Issue 12209026: Fix the crash of DisplayErrorDialog. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
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 "ash/display/display_error_dialog.h" 5 #include "ash/display/display_error_dialog.h"
6 6
7 #include "ash/screen_ash.h" 7 #include "ash/screen_ash.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "grit/ash_strings.h" 9 #include "grit/ash_strings.h"
10 #include "ui/aura/root_window.h"
10 #include "ui/aura/window.h" 11 #include "ui/aura/window.h"
11 #include "ui/base/l10n/l10n_util.h" 12 #include "ui/base/l10n/l10n_util.h"
12 #include "ui/base/ui_base_types.h" 13 #include "ui/base/ui_base_types.h"
13 #include "ui/gfx/display.h" 14 #include "ui/gfx/display.h"
14 #include "ui/gfx/screen.h" 15 #include "ui/gfx/screen.h"
15 #include "ui/views/border.h" 16 #include "ui/views/border.h"
16 #include "ui/views/controls/label.h" 17 #include "ui/views/controls/label.h"
17 #include "ui/views/widget/widget.h" 18 #include "ui/views/widget/widget.h"
18 19
19 namespace ash { 20 namespace ash {
(...skipping 12 matching lines...) Expand all
32 33
33 // static 34 // static
34 void DisplayErrorDialog::ShowDialog() { 35 void DisplayErrorDialog::ShowDialog() {
35 if (g_instance) { 36 if (g_instance) {
36 DCHECK(g_instance->GetWidget()); 37 DCHECK(g_instance->GetWidget());
37 g_instance->GetWidget()->StackAtTop(); 38 g_instance->GetWidget()->StackAtTop();
38 g_instance->GetWidget()->Activate(); 39 g_instance->GetWidget()->Activate();
39 return; 40 return;
40 } 41 }
41 42
42 const gfx::Display& secondary_display = ash::ScreenAsh::GetSecondaryDisplay(); 43 gfx::Screen* screen = Shell::GetScreen();
44 const gfx::Display& target_display =
45 (screen->GetNumDisplays() > 1) ?
46 ScreenAsh::GetSecondaryDisplay() : screen->GetPrimaryDisplay();
43 47
44 g_instance = new DisplayErrorDialog(); 48 g_instance = new DisplayErrorDialog();
45 views::Widget* widget = new views::Widget; 49 views::Widget* widget = new views::Widget;
46 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); 50 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
47 params.delegate = g_instance; 51 params.delegate = g_instance;
48 // Makes |widget| belong to the secondary display. Size and location are 52 // Makes |widget| belong to the target display. Size and location are
49 // fixed by CenterWindow() below. 53 // fixed by CenterWindow() below.
50 params.bounds = secondary_display.bounds(); 54 params.bounds = target_display.bounds();
55 DisplayController* display_controller =
56 Shell::GetInstance()->display_controller();
57 params.context =
58 display_controller->GetRootWindowForDisplayId(target_display.id());
51 params.keep_on_top = true; 59 params.keep_on_top = true;
52 widget->Init(params); 60 widget->Init(params);
53 61
54 widget->GetNativeView()->SetName("DisplayErrorDialog"); 62 widget->GetNativeView()->SetName("DisplayErrorDialog");
55 widget->CenterWindow(widget->GetRootView()->GetPreferredSize()); 63 widget->CenterWindow(widget->GetRootView()->GetPreferredSize());
56 widget->Show(); 64 widget->Show();
57 } 65 }
58 66
59 DisplayErrorDialog::DisplayErrorDialog() { 67 DisplayErrorDialog::DisplayErrorDialog() {
60 Shell::GetInstance()->display_controller()->AddObserver(this); 68 Shell::GetInstance()->display_controller()->AddObserver(this);
(...skipping 25 matching lines...) Expand all
86 } 94 }
87 95
88 gfx::Size DisplayErrorDialog::GetPreferredSize() { 96 gfx::Size DisplayErrorDialog::GetPreferredSize() {
89 return label_->GetPreferredSize(); 97 return label_->GetPreferredSize();
90 } 98 }
91 99
92 void DisplayErrorDialog::OnDisplayConfigurationChanging() { 100 void DisplayErrorDialog::OnDisplayConfigurationChanging() {
93 GetWidget()->Close(); 101 GetWidget()->Close();
94 } 102 }
95 103
104 // static
105 DisplayErrorDialog* DisplayErrorDialog::GetInstanceForTest() {
oshima 2013/02/06 00:17:28 DCHECK(g_instance);
Jun Mukai 2013/02/06 00:37:18 g_instance can be NULL in case the dialog is gone
106 return g_instance;
107 }
108
96 } // namespace internal 109 } // namespace internal
97 } // namespace ash 110 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698