Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 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/autofill/save_card_bubble_controller_impl.h" | |
| 6 | |
| 7 #include "chrome/browser/ui/browser.h" | |
| 8 #include "chrome/browser/ui/browser_finder.h" | |
| 9 #include "chrome/browser/ui/browser_window.h" | |
| 10 #include "chrome/browser/ui/location_bar/location_bar.h" | |
| 11 #include "components/autofill/core/browser/ui/save_card_bubble_view.h" | |
| 12 #include "content/public/browser/navigation_details.h" | |
| 13 | |
| 14 DEFINE_WEB_CONTENTS_USER_DATA_KEY(autofill::SaveCardBubbleControllerImpl); | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 // Minimal time span the bubble should survive implicit navigations. | |
|
Evan Stade
2015/10/22 23:02:43
you should note what unit this is in, particularly
bondd
2015/10/23 03:32:34
Done.
| |
| 19 // TODO(bondd): Share with ManagePasswordsUIController. | |
| 20 const int kBubbleMinTime = 5; | |
| 21 | |
| 22 } // namespace | |
| 23 | |
| 24 namespace autofill { | |
| 25 | |
| 26 SaveCardBubbleControllerImpl::SaveCardBubbleControllerImpl( | |
| 27 content::WebContents* web_contents) | |
| 28 : content::WebContentsObserver(web_contents), | |
| 29 web_contents_(web_contents), | |
| 30 save_card_bubble_view_(nullptr) { | |
| 31 DCHECK(web_contents); | |
| 32 } | |
| 33 | |
| 34 SaveCardBubbleControllerImpl::~SaveCardBubbleControllerImpl() { | |
| 35 if (save_card_bubble_view_) | |
| 36 save_card_bubble_view_->ControllerGone(); | |
| 37 } | |
| 38 | |
| 39 void SaveCardBubbleControllerImpl::SetCallback( | |
| 40 const base::Closure& save_card_callback) { | |
| 41 save_card_callback_ = save_card_callback; | |
| 42 } | |
| 43 | |
| 44 void SaveCardBubbleControllerImpl::ShowBubble() { | |
| 45 DCHECK_EQ(save_card_callback_.is_null(), false); | |
|
Evan Stade
2015/10/22 23:02:43
DCHECK(!bla.is_null());
bondd
2015/10/23 03:32:34
Done.
| |
| 46 | |
| 47 // Need to create location bar icon before bubble, otherwise bubble will be | |
| 48 // unanchored. | |
| 49 UpdateIcon(); | |
| 50 | |
| 51 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); | |
| 52 save_card_bubble_view_ = | |
| 53 browser->window()->ShowSaveCreditCardBubble(web_contents_, this); | |
| 54 DCHECK(save_card_bubble_view_); | |
| 55 | |
| 56 // Update icon after creating |save_card_bubble_view_| so that icon will show | |
| 57 // its "toggled on" state. | |
| 58 UpdateIcon(); | |
| 59 | |
| 60 timer_.reset(new base::ElapsedTimer()); | |
| 61 } | |
| 62 | |
| 63 bool SaveCardBubbleControllerImpl::IsIconVisible() const { | |
| 64 return !save_card_callback_.is_null(); | |
| 65 } | |
| 66 | |
| 67 bool SaveCardBubbleControllerImpl::IsIconToggled() const { | |
| 68 return save_card_bubble_view_; | |
|
Evan Stade
2015/10/22 23:02:43
I don't like this implicit cast, I'm used to seein
bondd
2015/10/23 03:32:34
Done. Windows compile didn't like the implicit cas
| |
| 69 } | |
| 70 | |
| 71 SaveCardBubbleView* SaveCardBubbleControllerImpl::save_card_bubble_view() | |
| 72 const { | |
| 73 return save_card_bubble_view_; | |
| 74 } | |
| 75 | |
| 76 void SaveCardBubbleControllerImpl::OnSaveButton() { | |
| 77 save_card_callback_.Run(); | |
| 78 save_card_callback_.Reset(); | |
| 79 } | |
| 80 | |
| 81 void SaveCardBubbleControllerImpl::OnCancelButton() { | |
| 82 save_card_callback_.Reset(); | |
| 83 } | |
| 84 | |
| 85 void SaveCardBubbleControllerImpl::OnBubbleClosed() { | |
| 86 save_card_bubble_view_ = nullptr; | |
| 87 UpdateIcon(); | |
| 88 } | |
| 89 | |
| 90 void SaveCardBubbleControllerImpl::UpdateIcon() { | |
| 91 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); | |
| 92 LocationBar* location_bar = browser->window()->GetLocationBar(); | |
| 93 DCHECK(location_bar); | |
|
Evan Stade
2015/10/22 23:02:43
no need to DCHECK since you're derefing on the nex
bondd
2015/10/23 03:32:34
Done.
| |
| 94 location_bar->UpdateSaveCreditCardIcon(); | |
| 95 } | |
| 96 | |
| 97 void SaveCardBubbleControllerImpl::DidNavigateMainFrame( | |
| 98 const content::LoadCommittedDetails& details, | |
| 99 const content::FrameNavigateParams& params) { | |
| 100 // Nothing to do if there's no bubble available. | |
| 101 if (save_card_callback_.is_null()) | |
| 102 return; | |
| 103 | |
| 104 // Don't react to in-page (fragment) navigations. | |
| 105 if (details.is_in_page) | |
| 106 return; | |
| 107 | |
| 108 // Don't do anything if a navigation occurs before a user could reasonably | |
| 109 // interact with the bubble. | |
| 110 if (timer_->Elapsed() < base::TimeDelta::FromSeconds(kBubbleMinTime)) | |
| 111 return; | |
| 112 | |
| 113 // Otherwise, get rid of the bubble and icon. | |
| 114 if (save_card_bubble_view_) { | |
| 115 save_card_bubble_view_->Close(); | |
| 116 save_card_bubble_view_ = nullptr; | |
| 117 } | |
| 118 save_card_callback_.Reset(); | |
| 119 UpdateIcon(); | |
| 120 } | |
| 121 | |
| 122 } // namespace autofill | |
| OLD | NEW |