Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / views / user_data_dir_dialog_view.cc
blob6effe52b3d105250cd4877cb144ffa784521bdfd
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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/views/user_data_dir_dialog_view.h"
7 #include "base/logging.h"
8 #include "base/run_loop.h"
9 #include "chrome/browser/ui/chrome_select_file_policy.h"
10 #include "chrome/browser/ui/user_data_dir_dialog.h"
11 #include "grit/chromium_strings.h"
12 #include "grit/generated_resources.h"
13 #include "ui/base/l10n/l10n_util.h"
14 #include "ui/views/controls/message_box_view.h"
15 #include "ui/views/widget/widget.h"
17 UserDataDirDialogView::UserDataDirDialogView(
18 const base::FilePath& user_data_dir)
19 : select_file_dialog_(ui::SelectFileDialog::Create(
20 this, new ChromeSelectFilePolicy(NULL))),
21 is_blocking_(true) {
22 const int kDialogWidth = 400;
23 views::MessageBoxView::InitParams params(
24 l10n_util::GetStringFUTF16(IDS_CANT_WRITE_USER_DIRECTORY_SUMMARY,
25 user_data_dir.LossyDisplayName()));
26 params.message_width = kDialogWidth;
27 message_box_view_ = new views::MessageBoxView(params);
30 UserDataDirDialogView::~UserDataDirDialogView() {
31 select_file_dialog_->ListenerDestroyed();
34 base::string16 UserDataDirDialogView::GetDialogButtonLabel(
35 ui::DialogButton button) const {
36 switch (button) {
37 case ui::DIALOG_BUTTON_OK:
38 return l10n_util::GetStringUTF16(
39 IDS_CANT_WRITE_USER_DIRECTORY_CHOOSE_DIRECTORY_BUTTON);
40 case ui::DIALOG_BUTTON_CANCEL:
41 return l10n_util::GetStringUTF16(
42 IDS_CANT_WRITE_USER_DIRECTORY_EXIT_BUTTON);
43 default:
44 NOTREACHED();
46 return base::string16();
49 base::string16 UserDataDirDialogView::GetWindowTitle() const {
50 return l10n_util::GetStringUTF16(IDS_CANT_WRITE_USER_DIRECTORY_TITLE);
53 void UserDataDirDialogView::DeleteDelegate() {
54 delete this;
57 bool UserDataDirDialogView::Accept() {
58 // Directory picker.
59 HWND owning_hwnd =
60 GetAncestor(message_box_view_->GetWidget()->GetNativeView(), GA_ROOT);
61 select_file_dialog_->SelectFile(
62 ui::SelectFileDialog::SELECT_FOLDER,
63 l10n_util::GetStringUTF16(
64 IDS_CANT_WRITE_USER_DIRECTORY_CHOOSE_DIRECTORY_BUTTON),
65 base::FilePath(), NULL, 0, base::FilePath::StringType(), owning_hwnd,
66 NULL);
67 return false;
70 bool UserDataDirDialogView::Cancel() {
71 is_blocking_ = false;
72 return true;
75 views::View* UserDataDirDialogView::GetContentsView() {
76 return message_box_view_;
79 views::Widget* UserDataDirDialogView::GetWidget() {
80 return message_box_view_->GetWidget();
83 const views::Widget* UserDataDirDialogView::GetWidget() const {
84 return message_box_view_->GetWidget();
87 bool UserDataDirDialogView::Dispatch(const base::NativeEvent& msg) {
88 TranslateMessage(&msg);
89 DispatchMessage(&msg);
90 return is_blocking_;
93 void UserDataDirDialogView::FileSelected(const base::FilePath& path,
94 int index,
95 void* params) {
96 user_data_dir_ = path;
97 is_blocking_ = false;
100 void UserDataDirDialogView::FileSelectionCanceled(void* params) {
103 namespace chrome {
105 base::FilePath ShowUserDataDirDialog(const base::FilePath& user_data_dir) {
106 DCHECK(base::MessageLoopForUI::IsCurrent());
107 // When the window closes, it will delete itself.
108 UserDataDirDialogView* dialog = new UserDataDirDialogView(user_data_dir);
109 views::DialogDelegate::CreateDialogWidget(dialog, NULL, NULL)->Show();
110 base::RunLoop run_loop(dialog);
111 run_loop.Run();
112 return dialog->user_data_dir();
115 } // namespace chrome