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 #ifndef CHROME_BROWSER_UI_AUTOFILL_SAVE_CARD_BUBBLE_CONTROLLER_IMPL_H_ | |
| 6 #define CHROME_BROWSER_UI_AUTOFILL_SAVE_CARD_BUBBLE_CONTROLLER_IMPL_H_ | |
| 7 | |
| 8 #include "base/memory/scoped_ptr.h" | |
| 9 #include "base/timer/elapsed_timer.h" | |
| 10 #include "components/autofill/core/browser/ui/save_card_bubble_controller.h" | |
| 11 #include "content/public/browser/web_contents_observer.h" | |
| 12 #include "content/public/browser/web_contents_user_data.h" | |
| 13 | |
| 14 namespace autofill { | |
| 15 | |
| 16 // Implementation of per-tab class to control the save credit card bubble and | |
| 17 // Omnibox icon. | |
| 18 // | |
| 19 // TODO(bondd): Add text strings so different dialog contents can be shown | |
| 20 // depending upon whether upstreaming is available. | |
| 21 class SaveCardBubbleControllerImpl | |
| 22 : public SaveCardBubbleController, | |
| 23 public content::WebContentsObserver, | |
| 24 public content::WebContentsUserData<SaveCardBubbleControllerImpl> { | |
| 25 public: | |
| 26 // SaveCardBubbleController | |
| 27 void CreateBubble(const base::Closure& save_card_callback) override; | |
| 28 void ShowBubble() override; | |
| 29 | |
| 30 void OnSaveButton() override; | |
| 31 void OnCancelButton() override; | |
| 32 void OnBubbleClosed() override; | |
| 33 | |
| 34 bool IsIconVisible() const override; | |
| 35 bool IsIconToggled() const override; | |
| 36 | |
| 37 SaveCardBubbleView* save_card_bubble_view() const override; | |
| 38 | |
| 39 private: | |
| 40 friend class content::WebContentsUserData<SaveCardBubbleControllerImpl>; | |
| 41 | |
| 42 enum State { | |
| 43 // There is no save card bubble or icon for the current site. | |
| 44 INACTIVE_STATE, | |
| 45 | |
| 46 // Save card bubble is available for the current site but not visible. | |
| 47 BUBBLE_AVAILABLE_STATE, | |
| 48 | |
| 49 // Save card bubble is visible. | |
| 50 BUBBLE_VISIBLE_STATE, | |
| 51 }; | |
| 52 | |
| 53 explicit SaveCardBubbleControllerImpl(content::WebContents* web_contents); | |
| 54 ~SaveCardBubbleControllerImpl() override; | |
| 55 | |
| 56 // Update the visibility and toggled state of the Omnibox save card icon. | |
| 57 void UpdateIcon(); | |
| 58 | |
| 59 // Reset back to INACTIVE_STATE. Gets rid of any existing bubble and hides | |
| 60 // the icon. | |
| 61 void Deactivate(); | |
| 62 | |
| 63 // Returns the time elapsed since |timer_| was initialized, | |
| 64 // or base::TimeDelta::Max() if |timer_| was not initialized. | |
| 65 base::TimeDelta Elapsed() const; | |
| 66 | |
| 67 // content::WebContentsObserver: | |
| 68 void DidNavigateMainFrame( | |
| 69 const content::LoadCommittedDetails& details, | |
| 70 const content::FrameNavigateParams& params) override; | |
| 71 | |
| 72 content::WebContents* web_contents_; | |
| 73 | |
| 74 // Will be nullptr if no bubble is currently shown. | |
| 75 SaveCardBubbleView* save_card_bubble_view_; | |
| 76 | |
| 77 // Callback to run if user presses Save button in the bubble. Not valid in | |
| 78 // INACTIVE_STATE. | |
| 79 base::Closure save_card_callback_; | |
| 80 | |
| 81 // Used to measure the amount of time on a page; if it's less than some | |
| 82 // reasonable limit, then don't close the bubble upon navigation. | |
| 83 scoped_ptr<base::ElapsedTimer> timer_; | |
| 84 | |
| 85 State state_; | |
|
Evan Stade
2015/10/16 01:20:44
instead of having this redundant information, chec
Evan Stade
2015/10/16 01:20:44
probably don't need this var, can just check other
bondd
2015/10/22 02:15:17
Done.
| |
| 86 | |
| 87 DISALLOW_COPY_AND_ASSIGN(SaveCardBubbleControllerImpl); | |
| 88 }; | |
| 89 | |
| 90 } // namespace autofill | |
| 91 | |
| 92 #endif // CHROME_BROWSER_UI_AUTOFILL_SAVE_CARD_BUBBLE_CONTROLLER_IMPL_H_ | |
| OLD | NEW |