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

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

Issue 319013002: Reland Fix Views web-modal dialog widget creation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Revert MediaGalleriesScanResultDialogViews::AcceptDialogForTesting. Created 6 years, 6 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/pdf/pdf_tab_helper.h" 5 #include "chrome/browser/ui/pdf/pdf_tab_helper.h"
6 6
7 #include "components/web_modal/web_contents_modal_dialog_host.h" 7 #include "chrome/browser/ui/views/constrained_window_views.h"
8 #include "components/web_modal/web_contents_modal_dialog_manager.h"
9 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h"
10 #include "content/public/browser/web_contents.h" 8 #include "content/public/browser/web_contents.h"
11 #include "grit/generated_resources.h" 9 #include "grit/generated_resources.h"
12 #include "ui/base/l10n/l10n_util.h" 10 #include "ui/base/l10n/l10n_util.h"
13 #include "ui/views/controls/message_box_view.h" 11 #include "ui/views/controls/message_box_view.h"
14 #include "ui/views/controls/textfield/textfield.h" 12 #include "ui/views/controls/textfield/textfield.h"
15 #include "ui/views/layout/layout_constants.h" 13 #include "ui/views/layout/layout_constants.h"
16 #include "ui/views/widget/widget.h" 14 #include "ui/views/widget/widget.h"
17 #include "ui/views/window/dialog_delegate.h" 15 #include "ui/views/window/dialog_delegate.h"
18 16
19 namespace { 17 namespace {
20 18
21 // PDFPasswordDialogViews runs a tab-modal dialog that asks the user for a 19 // Runs a tab-modal dialog that asks the user for a password.
22 // password.
23 class PDFPasswordDialogViews : public views::DialogDelegate { 20 class PDFPasswordDialogViews : public views::DialogDelegate {
24 public: 21 public:
25 PDFPasswordDialogViews(content::WebContents* web_contents, 22 PDFPasswordDialogViews(content::WebContents* web_contents,
26 const base::string16& prompt, 23 const base::string16& prompt,
27 const PasswordDialogClosedCallback& callback); 24 const PasswordDialogClosedCallback& callback);
28 virtual ~PDFPasswordDialogViews(); 25 virtual ~PDFPasswordDialogViews();
29 26
30 // views::DialogDelegate: 27 // views::DialogDelegate:
31 virtual base::string16 GetWindowTitle() const OVERRIDE; 28 virtual base::string16 GetWindowTitle() const OVERRIDE;
32 virtual base::string16 GetDialogButtonLabel( 29 virtual base::string16 GetDialogButtonLabel(
33 ui::DialogButton button) const OVERRIDE; 30 ui::DialogButton button) const OVERRIDE;
34 virtual bool Cancel() OVERRIDE; 31 virtual bool Cancel() OVERRIDE;
35 virtual bool Accept() OVERRIDE; 32 virtual bool Accept() OVERRIDE;
36 33
37 // views::WidgetDelegate: 34 // views::WidgetDelegate:
38 virtual views::View* GetInitiallyFocusedView() OVERRIDE; 35 virtual views::View* GetInitiallyFocusedView() OVERRIDE;
39 virtual views::View* GetContentsView() OVERRIDE; 36 virtual views::View* GetContentsView() OVERRIDE;
40 virtual views::Widget* GetWidget() OVERRIDE; 37 virtual views::Widget* GetWidget() OVERRIDE;
41 virtual const views::Widget* GetWidget() const OVERRIDE; 38 virtual const views::Widget* GetWidget() const OVERRIDE;
42 virtual void DeleteDelegate() OVERRIDE; 39 virtual void DeleteDelegate() OVERRIDE;
43 virtual ui::ModalType GetModalType() const OVERRIDE; 40 virtual ui::ModalType GetModalType() const OVERRIDE;
44 41
45 private: 42 private:
46 // The message box view whose commands we handle. 43 // The message box view whose commands we handle.
47 views::MessageBoxView* message_box_view_; 44 views::MessageBoxView* message_box_view_;
48 45
49 views::Widget* dialog_;
50
51 PasswordDialogClosedCallback callback_; 46 PasswordDialogClosedCallback callback_;
52 47
53 DISALLOW_COPY_AND_ASSIGN(PDFPasswordDialogViews); 48 DISALLOW_COPY_AND_ASSIGN(PDFPasswordDialogViews);
54 }; 49 };
55 50
56 PDFPasswordDialogViews::PDFPasswordDialogViews( 51 PDFPasswordDialogViews::PDFPasswordDialogViews(
57 content::WebContents* web_contents, 52 content::WebContents* web_contents,
58 const base::string16& prompt, 53 const base::string16& prompt,
59 const PasswordDialogClosedCallback& callback) 54 const PasswordDialogClosedCallback& callback)
60 : message_box_view_(NULL), 55 : message_box_view_(NULL),
61 dialog_(NULL),
62 callback_(callback) { 56 callback_(callback) {
63 views::MessageBoxView::InitParams init_params(prompt); 57 views::MessageBoxView::InitParams init_params(prompt);
64 init_params.options = views::MessageBoxView::HAS_PROMPT_FIELD; 58 init_params.options = views::MessageBoxView::HAS_PROMPT_FIELD;
65 init_params.inter_row_vertical_spacing = 59 init_params.inter_row_vertical_spacing =
66 views::kUnrelatedControlVerticalSpacing; 60 views::kUnrelatedControlVerticalSpacing;
67 message_box_view_ = new views::MessageBoxView(init_params); 61 message_box_view_ = new views::MessageBoxView(init_params);
68 message_box_view_->text_box()->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); 62 message_box_view_->text_box()->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
69 63 ShowWebModalDialogViews(this, web_contents);
70 web_modal::WebContentsModalDialogManager* web_contents_modal_dialog_manager =
71 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents);
72 web_modal::WebContentsModalDialogManagerDelegate* modal_delegate =
73 web_contents_modal_dialog_manager->delegate();
74 DCHECK(modal_delegate);
75 dialog_ = views::Widget::CreateWindowAsFramelessChild(
76 this, modal_delegate->GetWebContentsModalDialogHost()->GetHostView());
77 web_contents_modal_dialog_manager->ShowModalDialog(
78 dialog_->GetNativeView());
79 } 64 }
80 65
81 PDFPasswordDialogViews::~PDFPasswordDialogViews() { 66 PDFPasswordDialogViews::~PDFPasswordDialogViews() {
82 if (!callback_.is_null()) { 67 if (!callback_.is_null()) {
83 // This dialog was torn down without either OK or cancel being clicked; be 68 // This dialog was torn down without either OK or cancel being clicked; be
84 // considerate and at least do the callback. 69 // considerate and at least do the callback.
85 callback_.Run(false, base::string16()); 70 callback_.Run(false, base::string16());
86 } 71 }
87 } 72 }
88 73
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 116
132 const views::Widget* PDFPasswordDialogViews::GetWidget() const { 117 const views::Widget* PDFPasswordDialogViews::GetWidget() const {
133 return message_box_view_->GetWidget(); 118 return message_box_view_->GetWidget();
134 } 119 }
135 120
136 void PDFPasswordDialogViews::DeleteDelegate() { 121 void PDFPasswordDialogViews::DeleteDelegate() {
137 delete this; 122 delete this;
138 } 123 }
139 124
140 ui::ModalType PDFPasswordDialogViews::GetModalType() const { 125 ui::ModalType PDFPasswordDialogViews::GetModalType() const {
141 #if defined(USE_ASH)
142 return ui::MODAL_TYPE_CHILD; 126 return ui::MODAL_TYPE_CHILD;
143 #else
144 return views::WidgetDelegate::GetModalType();
145 #endif
146 } 127 }
147 128
148 } // namespace 129 } // namespace
149 130
150 void ShowPDFPasswordDialog(content::WebContents* web_contents, 131 void ShowPDFPasswordDialog(content::WebContents* web_contents,
151 const base::string16& prompt, 132 const base::string16& prompt,
152 const PasswordDialogClosedCallback& callback) { 133 const PasswordDialogClosedCallback& callback) {
153 new PDFPasswordDialogViews(web_contents, prompt, callback); 134 new PDFPasswordDialogViews(web_contents, prompt, callback);
154 } 135 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/login_prompt_views.cc ('k') | chrome/browser/ui/views/signed_certificate_timestamps_views.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698