OLD | NEW |
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/views/uninstall_view.h" | 5 #include "chrome/browser/ui/views/uninstall_view.h" |
6 | 6 |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/process/launch.h" | 8 #include "base/process/launch.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
11 #include "chrome/browser/shell_integration.h" | 11 #include "chrome/browser/shell_integration.h" |
12 #include "chrome/browser/ui/uninstall_browser_prompt.h" | 12 #include "chrome/browser/ui/uninstall_browser_prompt.h" |
13 #include "chrome/common/chrome_result_codes.h" | 13 #include "chrome/common/chrome_result_codes.h" |
14 #include "chrome/installer/util/browser_distribution.h" | 14 #include "chrome/installer/util/browser_distribution.h" |
15 #include "chrome/installer/util/shell_util.h" | 15 #include "chrome/installer/util/shell_util.h" |
16 #include "grit/chromium_strings.h" | 16 #include "grit/chromium_strings.h" |
17 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
18 #include "ui/views/controls/button/checkbox.h" | 18 #include "ui/views/controls/button/checkbox.h" |
19 #include "ui/views/controls/combobox/combobox.h" | 19 #include "ui/views/controls/combobox/combobox.h" |
20 #include "ui/views/controls/label.h" | 20 #include "ui/views/controls/label.h" |
21 #include "ui/views/layout/grid_layout.h" | 21 #include "ui/views/layout/grid_layout.h" |
22 #include "ui/views/layout/layout_constants.h" | 22 #include "ui/views/layout/layout_constants.h" |
23 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
24 | 24 |
25 UninstallView::UninstallView(int* user_selection, | 25 UninstallView::UninstallView(int* user_selection, |
26 const base::Closure& quit_closure, | 26 const base::Closure& quit_closure) |
27 bool show_delete_profile) | |
28 : confirm_label_(NULL), | 27 : confirm_label_(NULL), |
29 show_delete_profile_(show_delete_profile), | |
30 delete_profile_(NULL), | 28 delete_profile_(NULL), |
31 change_default_browser_(NULL), | 29 change_default_browser_(NULL), |
32 browsers_combo_(NULL), | 30 browsers_combo_(NULL), |
33 user_selection_(*user_selection), | 31 user_selection_(*user_selection), |
34 quit_closure_(quit_closure) { | 32 quit_closure_(quit_closure) { |
35 SetupControls(); | 33 SetupControls(); |
36 } | 34 } |
37 | 35 |
38 UninstallView::~UninstallView() { | 36 UninstallView::~UninstallView() { |
39 // Exit the message loop we were started with so that uninstall can continue. | 37 // Exit the message loop we were started with so that uninstall can continue. |
(...skipping 17 matching lines...) Expand all Loading... |
57 GridLayout::USE_PREF, 0, 0); | 55 GridLayout::USE_PREF, 0, 0); |
58 layout->StartRow(0, column_set_id); | 56 layout->StartRow(0, column_set_id); |
59 confirm_label_ = new views::Label( | 57 confirm_label_ = new views::Label( |
60 l10n_util::GetStringUTF16(IDS_UNINSTALL_VERIFY)); | 58 l10n_util::GetStringUTF16(IDS_UNINSTALL_VERIFY)); |
61 confirm_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 59 confirm_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
62 layout->AddView(confirm_label_); | 60 layout->AddView(confirm_label_); |
63 | 61 |
64 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); | 62 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); |
65 | 63 |
66 // The "delete profile" check box. | 64 // The "delete profile" check box. |
67 if (show_delete_profile_) { | 65 ++column_set_id; |
68 ++column_set_id; | 66 column_set = layout->AddColumnSet(column_set_id); |
69 column_set = layout->AddColumnSet(column_set_id); | 67 column_set->AddPaddingColumn(0, views::kPanelHorizIndentation); |
70 column_set->AddPaddingColumn(0, views::kPanelHorizIndentation); | 68 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, |
71 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, | 69 GridLayout::USE_PREF, 0, 0); |
72 GridLayout::USE_PREF, 0, 0); | 70 layout->StartRow(0, column_set_id); |
73 layout->StartRow(0, column_set_id); | 71 delete_profile_ = new views::Checkbox( |
74 delete_profile_ = new views::Checkbox( | 72 l10n_util::GetStringUTF16(IDS_UNINSTALL_DELETE_PROFILE)); |
75 l10n_util::GetStringUTF16(IDS_UNINSTALL_DELETE_PROFILE)); | 73 layout->AddView(delete_profile_); |
76 layout->AddView(delete_profile_); | |
77 } | |
78 | 74 |
79 // Set default browser combo box. If the default should not or cannot be | 75 // Set default browser combo box. If the default should not or cannot be |
80 // changed, widgets are not shown. We assume here that if Chrome cannot | 76 // changed, widgets are not shown. We assume here that if Chrome cannot |
81 // be set programatically as default, neither can any other browser (for | 77 // be set programatically as default, neither can any other browser (for |
82 // instance because the OS doesn't permit that). | 78 // instance because the OS doesn't permit that). |
83 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 79 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
84 if (dist->GetDefaultBrowserControlPolicy() != | 80 if (dist->GetDefaultBrowserControlPolicy() != |
85 BrowserDistribution::DEFAULT_BROWSER_UNSUPPORTED && | 81 BrowserDistribution::DEFAULT_BROWSER_UNSUPPORTED && |
86 ShellIntegration::GetDefaultBrowser() == ShellIntegration::IS_DEFAULT && | 82 ShellIntegration::GetDefaultBrowser() == ShellIntegration::IS_DEFAULT && |
87 (ShellIntegration::CanSetAsDefaultBrowser() != | 83 (ShellIntegration::CanSetAsDefaultBrowser() != |
(...skipping 20 matching lines...) Expand all Loading... |
108 layout->AddView(browsers_combo_); | 104 layout->AddView(browsers_combo_); |
109 browsers_combo_->SetEnabled(false); | 105 browsers_combo_->SetEnabled(false); |
110 } | 106 } |
111 } | 107 } |
112 | 108 |
113 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); | 109 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); |
114 } | 110 } |
115 | 111 |
116 bool UninstallView::Accept() { | 112 bool UninstallView::Accept() { |
117 user_selection_ = content::RESULT_CODE_NORMAL_EXIT; | 113 user_selection_ = content::RESULT_CODE_NORMAL_EXIT; |
118 if (show_delete_profile_ && delete_profile_->checked()) | 114 if (delete_profile_->checked()) |
119 user_selection_ = chrome::RESULT_CODE_UNINSTALL_DELETE_PROFILE; | 115 user_selection_ = chrome::RESULT_CODE_UNINSTALL_DELETE_PROFILE; |
120 if (change_default_browser_ && change_default_browser_->checked()) { | 116 if (change_default_browser_ && change_default_browser_->checked()) { |
121 BrowsersMap::const_iterator i = browsers_->begin(); | 117 BrowsersMap::const_iterator i = browsers_->begin(); |
122 std::advance(i, browsers_combo_->selected_index()); | 118 std::advance(i, browsers_combo_->selected_index()); |
123 base::LaunchOptions options; | 119 base::LaunchOptions options; |
124 options.start_hidden = true; | 120 options.start_hidden = true; |
125 base::LaunchProcess(i->second, options, NULL); | 121 base::LaunchProcess(i->second, options, NULL); |
126 } | 122 } |
127 return true; | 123 return true; |
128 } | 124 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 | 156 |
161 base::string16 UninstallView::GetItemAt(int index) { | 157 base::string16 UninstallView::GetItemAt(int index) { |
162 DCHECK_LT(index, static_cast<int>(browsers_->size())); | 158 DCHECK_LT(index, static_cast<int>(browsers_->size())); |
163 BrowsersMap::const_iterator i = browsers_->begin(); | 159 BrowsersMap::const_iterator i = browsers_->begin(); |
164 std::advance(i, index); | 160 std::advance(i, index); |
165 return i->first; | 161 return i->first; |
166 } | 162 } |
167 | 163 |
168 namespace chrome { | 164 namespace chrome { |
169 | 165 |
170 int ShowUninstallBrowserPrompt(bool show_delete_profile) { | 166 int ShowUninstallBrowserPrompt() { |
171 DCHECK(base::MessageLoopForUI::IsCurrent()); | 167 DCHECK(base::MessageLoopForUI::IsCurrent()); |
172 int result = content::RESULT_CODE_NORMAL_EXIT; | 168 int result = content::RESULT_CODE_NORMAL_EXIT; |
173 | 169 |
174 // Take a reference on g_browser_process while showing the dialog. This is | 170 // Take a reference on g_browser_process while showing the dialog. This is |
175 // done because the dialog uses the views framework which may increment | 171 // done because the dialog uses the views framework which may increment |
176 // and decrement the module ref count during the course of displaying UI and | 172 // and decrement the module ref count during the course of displaying UI and |
177 // this code can be called while the module refcount is still at 0. | 173 // this code can be called while the module refcount is still at 0. |
178 // Note that this reference is never released, as this code is shown on a path | 174 // Note that this reference is never released, as this code is shown on a path |
179 // that immediately exits Chrome anyway. | 175 // that immediately exits Chrome anyway. |
180 // See http://crbug.com/241366 for details. | 176 // See http://crbug.com/241366 for details. |
181 g_browser_process->AddRefModule(); | 177 g_browser_process->AddRefModule(); |
182 | 178 |
183 base::RunLoop run_loop; | 179 base::RunLoop run_loop; |
184 UninstallView* view = new UninstallView(&result, | 180 UninstallView* view = new UninstallView(&result, |
185 run_loop.QuitClosure(), | 181 run_loop.QuitClosure()); |
186 show_delete_profile); | |
187 views::DialogDelegate::CreateDialogWidget(view, NULL, NULL)->Show(); | 182 views::DialogDelegate::CreateDialogWidget(view, NULL, NULL)->Show(); |
188 run_loop.Run(); | 183 run_loop.Run(); |
189 return result; | 184 return result; |
190 } | 185 } |
191 | 186 |
192 } // namespace chrome | 187 } // namespace chrome |
OLD | NEW |