Chromium Code Reviews| Index: chrome/browser/ui/autofill/save_card_bubble_controller.h |
| diff --git a/chrome/browser/ui/autofill/save_card_bubble_controller.h b/chrome/browser/ui/autofill/save_card_bubble_controller.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..aac531407670ab1ea7673058e3823f94c787120c |
| --- /dev/null |
| +++ b/chrome/browser/ui/autofill/save_card_bubble_controller.h |
| @@ -0,0 +1,88 @@ |
| +// 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. |
| + |
| +#ifndef CHROME_BROWSER_UI_AUTOFILL_SAVE_CARD_BUBBLE_CONTROLLER_H_ |
| +#define CHROME_BROWSER_UI_AUTOFILL_SAVE_CARD_BUBBLE_CONTROLLER_H_ |
| + |
| +#include "base/callback.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/timer/elapsed_timer.h" |
| +#include "content/public/browser/web_contents_observer.h" |
| + |
| +namespace autofill { |
| + |
| +// Per-tab class to control the save credit card bubble and Omnibox icon. |
| +// |
| +// TODO(bondd): Add text strings so different dialog contents can be shown |
| +// depending upon whether upstreaming is available. |
| +class SaveCardBubbleController : public content::WebContentsObserver { |
| + public: |
| + explicit SaveCardBubbleController(content::WebContents* web_contents); |
| + ~SaveCardBubbleController() override; |
| + |
| + // |save_card_callback| will be invoked if/when the Save button is pressed. |
| + void ShowBubble(const base::Closure& save_card_callback); |
| + |
| + // Re-shows bubble that was already created with ShowBubble and then |
| + // dismissed, for example by clicking outside of the bubble or changing tabs. |
| + void ReshowBubble(); |
| + |
| + // Functions called by SaveCardBubbleView. |
| + void OnSaveButton(); |
|
Evan Stade
2015/10/09 18:54:44
I like separating these out into another interface
bondd
2015/10/13 02:03:16
Sounds good. I'll do that.
|
| + void OnCancelButton(); |
| + void OnBubbleClosed(); |
| + |
| + // Returns true if Omnibox save credit card icon should be visible. |
| + bool WantIconVisible() const; |
| + |
| + // Returns true if Omnibox save credit card should be shown in its "toggled |
| + // on" state. |
| + bool WantIconToggled() const; |
| + |
| + private: |
| + enum State { |
| + // There is no save card bubble or icon for the current site. |
| + INACTIVE_STATE, |
| + |
| + // Save card bubble is available for the current site but not visible. |
| + BUBBLE_AVAILABLE_STATE, |
| + |
| + // Save card bubble is visible. |
| + BUBBLE_VISIBLE_STATE, |
| + }; |
| + |
| + // Update the visibility and toggled state of the Omnibox save card icon. |
| + void UpdateIcon(); |
| + |
| + // Reset back to INACTIVE_STATE. Gets rid of any existing bubble and hides |
| + // the icon. |
| + void Deactivate(); |
| + |
| + // Returns the time elapsed since |timer_| was initialized, |
| + // or base::TimeDelta::Max() if |timer_| was not initialized. |
| + base::TimeDelta Elapsed() const; |
| + |
| + // content::WebContentsObserver: |
| + void DidNavigateMainFrame( |
| + const content::LoadCommittedDetails& details, |
| + const content::FrameNavigateParams& params) override; |
| + |
| + content::WebContents* web_contents_; |
| + |
| + // Callback to run if user presses Save button in the bubble. Not valid in |
| + // INACTIVE_STATE. |
| + base::Closure save_card_callback_; |
| + |
| + // Used to measure the amount of time on a page; if it's less than some |
| + // reasonable limit, then don't close the bubble upon navigation. |
| + scoped_ptr<base::ElapsedTimer> timer_; |
| + |
| + State state_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(SaveCardBubbleController); |
| +}; |
| + |
| +} // namespace autofill |
| + |
| +#endif // CHROME_BROWSER_UI_AUTOFILL_SAVE_CARD_BUBBLE_CONTROLLER_H_ |