OLD | NEW |
| (Empty) |
1 // Copyright (c) 2013 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. | |
4 | |
5 #include "chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/mac/scoped_nsobject.h" | |
9 #include "base/message_loop/message_loop.h" | |
10 #include "base/strings/sys_string_conversions.h" | |
11 #include "chrome/browser/ui/autofill/autofill_dialog_view_delegate.h" | |
12 #import "chrome/browser/ui/cocoa/autofill/autofill_details_container.h" | |
13 #import "chrome/browser/ui/cocoa/autofill/autofill_dialog_window_controller.h" | |
14 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sh
eet.h" | |
15 | |
16 namespace autofill { | |
17 | |
18 // static | |
19 AutofillDialogView* AutofillDialogView::Create( | |
20 AutofillDialogViewDelegate* delegate) { | |
21 return new AutofillDialogCocoa(delegate); | |
22 } | |
23 | |
24 AutofillDialogCocoa::AutofillDialogCocoa(AutofillDialogViewDelegate* delegate) | |
25 : delegate_(delegate), | |
26 close_weak_ptr_factory_(this) { | |
27 } | |
28 | |
29 AutofillDialogCocoa::~AutofillDialogCocoa() { | |
30 } | |
31 | |
32 void AutofillDialogCocoa::Show() { | |
33 // This should only be called once. | |
34 DCHECK(!sheet_delegate_.get()); | |
35 sheet_delegate_.reset([[AutofillDialogWindowController alloc] | |
36 initWithWebContents:delegate_->GetWebContents() | |
37 dialog:this]); | |
38 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet( | |
39 [[CustomConstrainedWindowSheet alloc] | |
40 initWithCustomWindow:[sheet_delegate_ window]]); | |
41 constrained_window_ = | |
42 CreateAndShowWebModalDialogMac(this, delegate_->GetWebContents(), sheet); | |
43 [sheet_delegate_ show]; | |
44 } | |
45 | |
46 void AutofillDialogCocoa::Hide() { | |
47 [sheet_delegate_ hide]; | |
48 } | |
49 | |
50 void AutofillDialogCocoa::PerformClose() { | |
51 if (!close_weak_ptr_factory_.HasWeakPtrs()) { | |
52 base::MessageLoop::current()->PostTask( | |
53 FROM_HERE, | |
54 base::Bind(&AutofillDialogCocoa::CloseNow, | |
55 close_weak_ptr_factory_.GetWeakPtr())); | |
56 } | |
57 } | |
58 | |
59 void AutofillDialogCocoa::CloseNow() { | |
60 constrained_window_->CloseWebContentsModalDialog(); | |
61 } | |
62 | |
63 void AutofillDialogCocoa::UpdatesStarted() { | |
64 } | |
65 | |
66 void AutofillDialogCocoa::UpdatesFinished() { | |
67 } | |
68 | |
69 void AutofillDialogCocoa::UpdateButtonStrip() { | |
70 } | |
71 | |
72 void AutofillDialogCocoa::UpdateDetailArea() { | |
73 } | |
74 | |
75 void AutofillDialogCocoa::UpdateForErrors() { | |
76 [sheet_delegate_ updateForErrors]; | |
77 } | |
78 | |
79 void AutofillDialogCocoa::UpdateNotificationArea() { | |
80 [sheet_delegate_ updateNotificationArea]; | |
81 } | |
82 | |
83 void AutofillDialogCocoa::UpdateSection(DialogSection section) { | |
84 [sheet_delegate_ updateSection:section]; | |
85 } | |
86 | |
87 void AutofillDialogCocoa::FillSection(DialogSection section, | |
88 ServerFieldType originating_type) { | |
89 [sheet_delegate_ fillSection:section forType:originating_type]; | |
90 } | |
91 | |
92 void AutofillDialogCocoa::GetUserInput(DialogSection section, | |
93 FieldValueMap* output) { | |
94 [sheet_delegate_ getInputs:output forSection:section]; | |
95 } | |
96 | |
97 base::string16 AutofillDialogCocoa::GetCvc() { | |
98 return base::SysNSStringToUTF16([sheet_delegate_ getCvc]); | |
99 } | |
100 | |
101 bool AutofillDialogCocoa::SaveDetailsLocally() { | |
102 return [sheet_delegate_ saveDetailsLocally]; | |
103 } | |
104 | |
105 void AutofillDialogCocoa::ModelChanged() { | |
106 [sheet_delegate_ modelChanged]; | |
107 } | |
108 | |
109 void AutofillDialogCocoa::UpdateErrorBubble() { | |
110 [sheet_delegate_ updateErrorBubble]; | |
111 } | |
112 | |
113 void AutofillDialogCocoa::ValidateSection(DialogSection section) { | |
114 [sheet_delegate_ validateSection:section]; | |
115 } | |
116 | |
117 void AutofillDialogCocoa::OnConstrainedWindowClosed( | |
118 ConstrainedWindowMac* window) { | |
119 constrained_window_.reset(); | |
120 // |this| belongs to |delegate_|, so no self-destruction here. | |
121 delegate_->ViewClosed(); | |
122 } | |
123 | |
124 } // autofill | |
OLD | NEW |