OLD | NEW |
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" | |
6 | |
7 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
8 | 6 |
9 #include "base/mac/scoped_nsobject.h" | 7 #include "base/mac/scoped_nsobject.h" |
10 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
11 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
12 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
13 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_alert.h" | 11 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_alert.h" |
14 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sh
eet.h" | 12 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sh
eet.h" |
15 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.h" | 13 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.h" |
16 #import "chrome/browser/ui/cocoa/key_equivalent_constants.h" | 14 #import "chrome/browser/ui/cocoa/key_equivalent_constants.h" |
| 15 #include "components/pdf/browser/pdf_tab_helper_delegate.h" |
17 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
18 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
19 | 18 |
20 @class PDFPasswordDialogMac; | 19 @class PDFPasswordDialogMac; |
21 | 20 |
22 namespace { | 21 namespace { |
23 | 22 |
24 class PDFPasswordDialogMacBridge : public ConstrainedWindowMacDelegate { | 23 class PDFPasswordDialogMacBridge : public ConstrainedWindowMacDelegate { |
25 public: | 24 public: |
26 explicit PDFPasswordDialogMacBridge(PDFPasswordDialogMac* dialog); | 25 explicit PDFPasswordDialogMacBridge(PDFPasswordDialogMac* dialog); |
27 virtual ~PDFPasswordDialogMacBridge(); | 26 virtual ~PDFPasswordDialogMacBridge(); |
28 virtual void OnConstrainedWindowClosed(ConstrainedWindowMac* window) OVERRIDE; | 27 virtual void OnConstrainedWindowClosed(ConstrainedWindowMac* window) OVERRIDE; |
29 | 28 |
30 private: | 29 private: |
31 PDFPasswordDialogMac* dialog_; // weak | 30 PDFPasswordDialogMac* dialog_; // weak |
32 | 31 |
33 DISALLOW_COPY_AND_ASSIGN(PDFPasswordDialogMacBridge); | 32 DISALLOW_COPY_AND_ASSIGN(PDFPasswordDialogMacBridge); |
34 }; | 33 }; |
35 | 34 |
36 } // namespace | 35 } // namespace |
37 | 36 |
38 @interface PDFPasswordDialogMac : NSObject { | 37 @interface PDFPasswordDialogMac : NSObject { |
39 @private | 38 @private |
40 content::WebContents* webContents_; | 39 content::WebContents* webContents_; |
41 base::string16 prompt_; | 40 base::string16 prompt_; |
42 PasswordDialogClosedCallback callback_; | 41 pdf::PasswordDialogClosedCallback callback_; |
43 | 42 |
44 base::scoped_nsobject<NSSecureTextField> passwordField_; | 43 base::scoped_nsobject<NSSecureTextField> passwordField_; |
45 | 44 |
46 base::scoped_nsobject<ConstrainedWindowAlert> alert_; | 45 base::scoped_nsobject<ConstrainedWindowAlert> alert_; |
47 scoped_ptr<PDFPasswordDialogMacBridge> bridge_; | 46 scoped_ptr<PDFPasswordDialogMacBridge> bridge_; |
48 scoped_ptr<ConstrainedWindowMac> window_; | 47 scoped_ptr<ConstrainedWindowMac> window_; |
49 } | 48 } |
50 - (id)initWithWebContents:(content::WebContents*)webContents | 49 - (id)initWithWebContents:(content::WebContents*)webContents |
51 prompt:(base::string16)prompt | 50 prompt:(base::string16)prompt |
52 callback:(PasswordDialogClosedCallback)callback; | 51 callback:(pdf::PasswordDialogClosedCallback)callback; |
53 - (void)onOKButton:(id)sender; | 52 - (void)onOKButton:(id)sender; |
54 - (void)onCancelButton:(id)sender; | 53 - (void)onCancelButton:(id)sender; |
55 @end | 54 @end |
56 | 55 |
57 namespace { | 56 namespace { |
58 | 57 |
59 PDFPasswordDialogMacBridge::PDFPasswordDialogMacBridge( | 58 PDFPasswordDialogMacBridge::PDFPasswordDialogMacBridge( |
60 PDFPasswordDialogMac* dialog) : dialog_(dialog) { | 59 PDFPasswordDialogMac* dialog) : dialog_(dialog) { |
61 } | 60 } |
62 | 61 |
63 PDFPasswordDialogMacBridge::~PDFPasswordDialogMacBridge() { | 62 PDFPasswordDialogMacBridge::~PDFPasswordDialogMacBridge() { |
64 } | 63 } |
65 | 64 |
66 void PDFPasswordDialogMacBridge::OnConstrainedWindowClosed( | 65 void PDFPasswordDialogMacBridge::OnConstrainedWindowClosed( |
67 ConstrainedWindowMac* window) { | 66 ConstrainedWindowMac* window) { |
68 [dialog_ release]; | 67 [dialog_ release]; |
69 } | 68 } |
70 | 69 |
71 } // namespace | 70 } // namespace |
72 | 71 |
73 @implementation PDFPasswordDialogMac | 72 @implementation PDFPasswordDialogMac |
74 | 73 |
75 - (id)initWithWebContents:(content::WebContents*)webContents | 74 - (id)initWithWebContents:(content::WebContents*)webContents |
76 prompt:(base::string16)prompt | 75 prompt:(base::string16)prompt |
77 callback:(PasswordDialogClosedCallback)callback { | 76 callback:(pdf::PasswordDialogClosedCallback)callback { |
78 if ((self = [super init])) { | 77 if ((self = [super init])) { |
79 webContents_ = webContents; | 78 webContents_ = webContents; |
80 prompt_ = prompt; | 79 prompt_ = prompt; |
81 callback_ = callback; | 80 callback_ = callback; |
82 | 81 |
83 alert_.reset([[ConstrainedWindowAlert alloc] init]); | 82 alert_.reset([[ConstrainedWindowAlert alloc] init]); |
84 [alert_ setMessageText: | 83 [alert_ setMessageText: |
85 l10n_util::GetNSString(IDS_PDF_PASSWORD_DIALOG_TITLE)]; | 84 l10n_util::GetNSString(IDS_PDF_PASSWORD_DIALOG_TITLE)]; |
86 [alert_ setInformativeText:base::SysUTF16ToNSString(prompt)]; | 85 [alert_ setInformativeText:base::SysUTF16ToNSString(prompt)]; |
87 [alert_ addButtonWithTitle:l10n_util::GetNSString(IDS_OK) | 86 [alert_ addButtonWithTitle:l10n_util::GetNSString(IDS_OK) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 - (void)onCancelButton:(id)sender { | 127 - (void)onCancelButton:(id)sender { |
129 callback_.Run(false, base::string16()); | 128 callback_.Run(false, base::string16()); |
130 callback_.Reset(); | 129 callback_.Reset(); |
131 window_->CloseWebContentsModalDialog(); | 130 window_->CloseWebContentsModalDialog(); |
132 } | 131 } |
133 | 132 |
134 @end | 133 @end |
135 | 134 |
136 void ShowPDFPasswordDialog(content::WebContents* web_contents, | 135 void ShowPDFPasswordDialog(content::WebContents* web_contents, |
137 const base::string16& prompt, | 136 const base::string16& prompt, |
138 const PasswordDialogClosedCallback& callback) { | 137 const pdf::PasswordDialogClosedCallback& callback) { |
139 [[PDFPasswordDialogMac alloc] initWithWebContents:web_contents | 138 [[PDFPasswordDialogMac alloc] initWithWebContents:web_contents |
140 prompt:prompt | 139 prompt:prompt |
141 callback:callback]; | 140 callback:callback]; |
142 } | 141 } |
OLD | NEW |