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

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: Change object lifecycles + add interface classes. 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..cb94fcdb0d6fbd3abea7c73d810ec2f8f6333ca1
--- /dev/null
+++ b/chrome/browser/ui/autofill/save_card_bubble_controller_impl.cc
@@ -0,0 +1,133 @@
+// 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.
+// 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),
+ state_(INACTIVE_STATE) {
+ DCHECK(web_contents);
+}
+
+SaveCardBubbleControllerImpl::~SaveCardBubbleControllerImpl() {
+ if (save_card_bubble_view_)
+ save_card_bubble_view_->ControllerGone();
+}
+
+void SaveCardBubbleControllerImpl::CreateBubble(
Evan Stade 2015/10/16 01:20:44 CreateAndShow, and Show below, since you should ne
Justin Donnelly 2015/10/19 17:39:08 At the risk of going full bikeshed, I think you're
Evan Stade 2015/10/19 17:58:31 Sure, in fact my final suggestion did not include
bondd 2015/10/22 02:15:17 Done.
+ const base::Closure& save_card_callback) {
+ save_card_callback_ = save_card_callback;
+ state_ = BUBBLE_AVAILABLE_STATE;
+}
+
+void SaveCardBubbleControllerImpl::ShowBubble() {
+ DCHECK_EQ(state_, BUBBLE_AVAILABLE_STATE);
+
+ // Need to create location bar icon before bubble, otherwise bubble will be
hcarmona 2015/10/16 21:16:35 What happens if the location bar isn't visible? Li
bondd 2015/10/22 02:15:17 In fullscreen the arrow points up toward where the
+ // unanchored.
+ state_ = BUBBLE_VISIBLE_STATE;
+ UpdateIcon();
+
+ Browser* browser = chrome::FindBrowserWithWebContents(web_contents_);
+ save_card_bubble_view_ =
+ browser->window()->ShowSaveCreditCardBubble(web_contents_, this);
+ DCHECK(save_card_bubble_view_);
+
+ timer_.reset(new base::ElapsedTimer());
+}
+
+void SaveCardBubbleControllerImpl::OnSaveButton() {
+ save_card_callback_.Run();
+ Deactivate();
+}
+
+void SaveCardBubbleControllerImpl::OnCancelButton() {
+ Deactivate();
+}
+
+void SaveCardBubbleControllerImpl::OnBubbleClosed() {
+ // Do nothing if bubble has already been closed because of a button press.
+ if (state_ == INACTIVE_STATE)
+ return;
+
+ state_ = BUBBLE_AVAILABLE_STATE;
+ save_card_bubble_view_ = nullptr;
+ UpdateIcon();
+}
+
+bool SaveCardBubbleControllerImpl::IsIconVisible() const {
+ return state_ != INACTIVE_STATE;
+}
+
+bool SaveCardBubbleControllerImpl::IsIconToggled() const {
+ return state_ == BUBBLE_VISIBLE_STATE;
+}
+
+SaveCardBubbleView* SaveCardBubbleControllerImpl::save_card_bubble_view()
+ const {
+ return save_card_bubble_view_;
+}
+
+void SaveCardBubbleControllerImpl::UpdateIcon() {
+ Browser* browser = chrome::FindBrowserWithWebContents(web_contents_);
+ LocationBar* location_bar = browser->window()->GetLocationBar();
+ DCHECK(location_bar);
+ location_bar->UpdateSaveCreditCardIcon();
+}
+
+void SaveCardBubbleControllerImpl::Deactivate() {
+ save_card_callback_.Reset();
+ state_ = INACTIVE_STATE;
+ save_card_bubble_view_ = nullptr;
+ UpdateIcon();
+}
+
+base::TimeDelta SaveCardBubbleControllerImpl::Elapsed() const {
+ return timer_ ? timer_->Elapsed() : base::TimeDelta::Max();
Evan Stade 2015/10/16 01:20:44 not a particularly useful method IMO. I expect you
bondd 2015/10/22 02:15:17 Done.
+}
+
+void SaveCardBubbleControllerImpl::DidNavigateMainFrame(
+ const content::LoadCommittedDetails& details,
+ const content::FrameNavigateParams& params) {
+ if (state_ == INACTIVE_STATE)
+ 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 (Elapsed() < base::TimeDelta::FromSeconds(kBubbleMinTime))
Evan Stade 2015/10/16 01:20:43 can just be if (timer_ && timer_->Elapsed() < ...
bondd 2015/10/22 02:15:17 Done.
+ return;
+
+ // Otherwise, make the bubble and icon inactive.
+ if (save_card_bubble_view_)
+ save_card_bubble_view_->Close();
+ Deactivate();
+}
+
+} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698