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_sheet.h" 15 16namespace autofill { 17 18// static 19AutofillDialogView* AutofillDialogView::Create( 20 AutofillDialogViewDelegate* delegate) { 21 return new AutofillDialogCocoa(delegate); 22} 23 24AutofillDialogCocoa::AutofillDialogCocoa(AutofillDialogViewDelegate* delegate) 25 : delegate_(delegate), 26 close_weak_ptr_factory_(this) { 27} 28 29AutofillDialogCocoa::~AutofillDialogCocoa() { 30} 31 32void 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_.reset( 42 new ConstrainedWindowMac(this, delegate_->GetWebContents(), sheet)); 43 [sheet_delegate_ show]; 44} 45 46void AutofillDialogCocoa::Hide() { 47 [sheet_delegate_ hide]; 48} 49 50void 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 59void AutofillDialogCocoa::CloseNow() { 60 constrained_window_->CloseWebContentsModalDialog(); 61} 62 63void AutofillDialogCocoa::UpdatesStarted() { 64} 65 66void AutofillDialogCocoa::UpdatesFinished() { 67} 68 69void AutofillDialogCocoa::UpdateAccountChooser() { 70 [sheet_delegate_ updateAccountChooser]; 71} 72 73void AutofillDialogCocoa::UpdateButtonStrip() { 74 [sheet_delegate_ updateButtonStrip]; 75} 76 77void AutofillDialogCocoa::UpdateOverlay() { 78 // TODO(estade): only update the overlay. 79 UpdateButtonStrip(); 80} 81 82void AutofillDialogCocoa::UpdateDetailArea() { 83} 84 85void AutofillDialogCocoa::UpdateForErrors() { 86 [sheet_delegate_ updateForErrors]; 87} 88 89void AutofillDialogCocoa::UpdateNotificationArea() { 90 [sheet_delegate_ updateNotificationArea]; 91} 92 93void AutofillDialogCocoa::UpdateSection(DialogSection section) { 94 [sheet_delegate_ updateSection:section]; 95} 96 97void AutofillDialogCocoa::FillSection(DialogSection section, 98 ServerFieldType originating_type) { 99 [sheet_delegate_ fillSection:section forType:originating_type]; 100} 101 102void AutofillDialogCocoa::GetUserInput(DialogSection section, 103 FieldValueMap* output) { 104 [sheet_delegate_ getInputs:output forSection:section]; 105} 106 107base::string16 AutofillDialogCocoa::GetCvc() { 108 return base::SysNSStringToUTF16([sheet_delegate_ getCvc]); 109} 110 111bool AutofillDialogCocoa::SaveDetailsLocally() { 112 return [sheet_delegate_ saveDetailsLocally]; 113} 114 115const content::NavigationController* AutofillDialogCocoa::ShowSignIn() { 116 return [sheet_delegate_ showSignIn]; 117} 118 119void AutofillDialogCocoa::HideSignIn() { 120 [sheet_delegate_ hideSignIn]; 121} 122 123void AutofillDialogCocoa::ModelChanged() { 124 [sheet_delegate_ modelChanged]; 125} 126 127void AutofillDialogCocoa::UpdateErrorBubble() { 128 [sheet_delegate_ updateErrorBubble]; 129} 130 131void AutofillDialogCocoa::OnSignInResize(const gfx::Size& pref_size) { 132 [sheet_delegate_ onSignInResize: 133 NSMakeSize(pref_size.width(), pref_size.height())]; 134} 135 136void AutofillDialogCocoa::ValidateSection(DialogSection section) { 137 [sheet_delegate_ validateSection:section]; 138} 139 140void AutofillDialogCocoa::OnConstrainedWindowClosed( 141 ConstrainedWindowMac* window) { 142 constrained_window_.reset(); 143 // |this| belongs to |delegate_|, so no self-destruction here. 144 delegate_->ViewClosed(); 145} 146 147} // autofill 148