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.
5 #include "chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.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_sheet.h"
19 AutofillDialogView* AutofillDialogView::Create(
20 AutofillDialogViewDelegate* delegate) {
21 return new AutofillDialogCocoa(delegate);
24 AutofillDialogCocoa::AutofillDialogCocoa(AutofillDialogViewDelegate* delegate)
25 : delegate_(delegate),
26 close_weak_ptr_factory_(this) {
29 AutofillDialogCocoa::~AutofillDialogCocoa() {
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()
38 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet(
39 [[CustomConstrainedWindowSheet alloc]
40 initWithCustomWindow:[sheet_delegate_ window]]);
41 constrained_window_.reset(
42 new ConstrainedWindowMac(this, delegate_->GetWebContents(), sheet));
43 [sheet_delegate_ show];
46 void AutofillDialogCocoa::Hide() {
47 [sheet_delegate_ hide];
50 void AutofillDialogCocoa::PerformClose() {
51 if (!close_weak_ptr_factory_.HasWeakPtrs()) {
52 base::MessageLoop::current()->PostTask(
54 base::Bind(&AutofillDialogCocoa::CloseNow,
55 close_weak_ptr_factory_.GetWeakPtr()));
59 void AutofillDialogCocoa::CloseNow() {
60 constrained_window_->CloseWebContentsModalDialog();
63 void AutofillDialogCocoa::UpdatesStarted() {
66 void AutofillDialogCocoa::UpdatesFinished() {
69 void AutofillDialogCocoa::UpdateButtonStrip() {
72 void AutofillDialogCocoa::UpdateDetailArea() {
75 void AutofillDialogCocoa::UpdateForErrors() {
76 [sheet_delegate_ updateForErrors];
79 void AutofillDialogCocoa::UpdateNotificationArea() {
80 [sheet_delegate_ updateNotificationArea];
83 void AutofillDialogCocoa::UpdateSection(DialogSection section) {
84 [sheet_delegate_ updateSection:section];
87 void AutofillDialogCocoa::FillSection(DialogSection section,
88 ServerFieldType originating_type) {
89 [sheet_delegate_ fillSection:section forType:originating_type];
92 void AutofillDialogCocoa::GetUserInput(DialogSection section,
93 FieldValueMap* output) {
94 [sheet_delegate_ getInputs:output forSection:section];
97 base::string16 AutofillDialogCocoa::GetCvc() {
98 return base::SysNSStringToUTF16([sheet_delegate_ getCvc]);
101 bool AutofillDialogCocoa::SaveDetailsLocally() {
102 return [sheet_delegate_ saveDetailsLocally];
105 void AutofillDialogCocoa::ModelChanged() {
106 [sheet_delegate_ modelChanged];
109 void AutofillDialogCocoa::UpdateErrorBubble() {
110 [sheet_delegate_ updateErrorBubble];
113 void AutofillDialogCocoa::ValidateSection(DialogSection section) {
114 [sheet_delegate_ validateSection:section];
117 void AutofillDialogCocoa::OnConstrainedWindowClosed(
118 ConstrainedWindowMac* window) {
119 constrained_window_.reset();
120 // |this| belongs to |delegate_|, so no self-destruction here.
121 delegate_->ViewClosed();