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 3 // found in the LICENSE file. 4 5 #include "chrome/browser/ui/views/location_bar/generated_credit_card_view.h" 6 7 #include "chrome/browser/ui/autofill/generated_credit_card_bubble_controller.h" 8 #include "chrome/browser/ui/toolbar/toolbar_model.h" 9 #include "ui/gfx/image/image.h" 10 11 GeneratedCreditCardView::GeneratedCreditCardView( 12 ToolbarModel* toolbar_model, 13 LocationBarView::Delegate* delegate) 14 : toolbar_model_(toolbar_model), 15 delegate_(delegate) { 16 Update(); 17 } 18 19 GeneratedCreditCardView::~GeneratedCreditCardView() {} 20 21 void GeneratedCreditCardView::Update() { 22 autofill::GeneratedCreditCardBubbleController* controller = GetController(); 23 if (controller && !controller->AnchorIcon().IsEmpty()) { 24 SetVisible(true); 25 SetImage(controller->AnchorIcon().AsImageSkia()); 26 } else { 27 SetVisible(false); 28 SetImage(NULL); 29 } 30 } 31 32 // TODO(dbeam): figure out what to do for a tooltip and accessibility. 33 34 bool GeneratedCreditCardView::CanHandleClick() const { 35 autofill::GeneratedCreditCardBubbleController* controller = GetController(); 36 return controller && !controller->IsHiding(); 37 } 38 39 void GeneratedCreditCardView::OnClick() { 40 autofill::GeneratedCreditCardBubbleController* controller = GetController(); 41 if (controller) 42 controller->OnAnchorClicked(); 43 } 44 45 autofill::GeneratedCreditCardBubbleController* GeneratedCreditCardView:: 46 GetController() const { 47 content::WebContents* wc = delegate_->GetWebContents(); 48 if (!wc || toolbar_model_->GetInputInProgress()) 49 return NULL; 50 51 return autofill::GeneratedCreditCardBubbleController::FromWebContents(wc); 52 } 53