Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6827)

Unified Diff: chrome/browser/ui/autofill/save_card_bubble_controller_impl.cc

Issue 1396923003: Autofill: Replace "save credit card" infobar with a bubble (Views only). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Replace browser tests with unit tests. Address reviewer comments. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/autofill/save_card_bubble_controller_impl.cc
diff --git a/chrome/browser/ui/autofill/save_card_bubble_controller_impl.cc b/chrome/browser/ui/autofill/save_card_bubble_controller_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..769499e77a5c55567a05fdf42f465afa0274f880
--- /dev/null
+++ b/chrome/browser/ui/autofill/save_card_bubble_controller_impl.cc
@@ -0,0 +1,122 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/autofill/save_card_bubble_controller_impl.h"
+
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_finder.h"
+#include "chrome/browser/ui/browser_window.h"
+#include "chrome/browser/ui/location_bar/location_bar.h"
+#include "components/autofill/core/browser/ui/save_card_bubble_view.h"
+#include "content/public/browser/navigation_details.h"
+
+DEFINE_WEB_CONTENTS_USER_DATA_KEY(autofill::SaveCardBubbleControllerImpl);
+
+namespace {
+
+// 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.
+// TODO(bondd): Share with ManagePasswordsUIController.
+const int kBubbleMinTime = 5;
+
+} // namespace
+
+namespace autofill {
+
+SaveCardBubbleControllerImpl::SaveCardBubbleControllerImpl(
+ content::WebContents* web_contents)
+ : content::WebContentsObserver(web_contents),
+ web_contents_(web_contents),
+ save_card_bubble_view_(nullptr) {
+ DCHECK(web_contents);
+}
+
+SaveCardBubbleControllerImpl::~SaveCardBubbleControllerImpl() {
+ if (save_card_bubble_view_)
+ save_card_bubble_view_->ControllerGone();
+}
+
+void SaveCardBubbleControllerImpl::SetCallback(
+ const base::Closure& save_card_callback) {
+ save_card_callback_ = save_card_callback;
+}
+
+void SaveCardBubbleControllerImpl::ShowBubble() {
+ 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.
+
+ // Need to create location bar icon before bubble, otherwise bubble will be
+ // unanchored.
+ UpdateIcon();
+
+ Browser* browser = chrome::FindBrowserWithWebContents(web_contents_);
+ save_card_bubble_view_ =
+ browser->window()->ShowSaveCreditCardBubble(web_contents_, this);
+ DCHECK(save_card_bubble_view_);
+
+ // Update icon after creating |save_card_bubble_view_| so that icon will show
+ // its "toggled on" state.
+ UpdateIcon();
+
+ timer_.reset(new base::ElapsedTimer());
+}
+
+bool SaveCardBubbleControllerImpl::IsIconVisible() const {
+ return !save_card_callback_.is_null();
+}
+
+bool SaveCardBubbleControllerImpl::IsIconToggled() const {
+ 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
+}
+
+SaveCardBubbleView* SaveCardBubbleControllerImpl::save_card_bubble_view()
+ const {
+ return save_card_bubble_view_;
+}
+
+void SaveCardBubbleControllerImpl::OnSaveButton() {
+ save_card_callback_.Run();
+ save_card_callback_.Reset();
+}
+
+void SaveCardBubbleControllerImpl::OnCancelButton() {
+ save_card_callback_.Reset();
+}
+
+void SaveCardBubbleControllerImpl::OnBubbleClosed() {
+ save_card_bubble_view_ = nullptr;
+ UpdateIcon();
+}
+
+void SaveCardBubbleControllerImpl::UpdateIcon() {
+ Browser* browser = chrome::FindBrowserWithWebContents(web_contents_);
+ LocationBar* location_bar = browser->window()->GetLocationBar();
+ 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.
+ location_bar->UpdateSaveCreditCardIcon();
+}
+
+void SaveCardBubbleControllerImpl::DidNavigateMainFrame(
+ const content::LoadCommittedDetails& details,
+ const content::FrameNavigateParams& params) {
+ // Nothing to do if there's no bubble available.
+ if (save_card_callback_.is_null())
+ return;
+
+ // Don't react to in-page (fragment) navigations.
+ if (details.is_in_page)
+ return;
+
+ // Don't do anything if a navigation occurs before a user could reasonably
+ // interact with the bubble.
+ if (timer_->Elapsed() < base::TimeDelta::FromSeconds(kBubbleMinTime))
+ return;
+
+ // Otherwise, get rid of the bubble and icon.
+ if (save_card_bubble_view_) {
+ save_card_bubble_view_->Close();
+ save_card_bubble_view_ = nullptr;
+ }
+ save_card_callback_.Reset();
+ UpdateIcon();
+}
+
+} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698