Avi Drissman | 4a8573c | 2022-09-09 19:35:54 | [diff] [blame] | 1 | // Copyright 2021 The Chromium Authors |
Mohamed Amir Yosef | e62de00f | 2021-01-30 04:18:13 | [diff] [blame] | 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/autofill_bubble_controller_base.h" |
| 6 | |
| 7 | #include "chrome/browser/ui/autofill/autofill_bubble_base.h" |
| 8 | #include "chrome/browser/ui/browser_finder.h" |
Mohamed Amir Yosef | e62de00f | 2021-01-30 04:18:13 | [diff] [blame] | 9 | #include "components/autofill/core/common/autofill_clock.h" |
| 10 | #include "components/autofill/core/common/autofill_payments_features.h" |
| 11 | |
Vishwas Uppoor | 93470c6 | 2022-02-22 17:30:13 | [diff] [blame] | 12 | #if !BUILDFLAG(IS_ANDROID) |
| 13 | #include "chrome/browser/ui/browser_window.h" |
| 14 | #endif // !BUILDFLAG(IS_ANDROID) |
| 15 | |
Mohamed Amir Yosef | e62de00f | 2021-01-30 04:18:13 | [diff] [blame] | 16 | namespace autofill { |
| 17 | |
| 18 | AutofillBubbleControllerBase::AutofillBubbleControllerBase( |
| 19 | content::WebContents* web_contents) |
| 20 | : content::WebContentsObserver(web_contents) {} |
| 21 | |
| 22 | AutofillBubbleControllerBase::~AutofillBubbleControllerBase() { |
| 23 | HideBubble(); |
| 24 | } |
| 25 | void AutofillBubbleControllerBase::Show() { |
| 26 | UpdatePageActionIcon(); |
| 27 | DoShowBubble(); |
| 28 | UpdatePageActionIcon(); |
Mohamed Amir Yosef | e62de00f | 2021-01-30 04:18:13 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | void AutofillBubbleControllerBase::OnVisibilityChanged( |
| 32 | content::Visibility visibility) { |
Peter Kasting | a486324 | 2024-12-23 00:19:43 | [diff] [blame] | 33 | if (visibility == content::Visibility::HIDDEN) { |
Mohamed Amir Yosef | e62de00f | 2021-01-30 04:18:13 | [diff] [blame] | 34 | HideBubble(); |
Peter Kasting | a486324 | 2024-12-23 00:19:43 | [diff] [blame] | 35 | } |
Mohamed Amir Yosef | e62de00f | 2021-01-30 04:18:13 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | void AutofillBubbleControllerBase::WebContentsDestroyed() { |
| 39 | HideBubble(); |
| 40 | } |
| 41 | |
| 42 | void AutofillBubbleControllerBase::UpdatePageActionIcon() { |
Vishwas Uppoor | 93470c6 | 2022-02-22 17:30:13 | [diff] [blame] | 43 | // Page action icons do not exist for Android. |
| 44 | #if !BUILDFLAG(IS_ANDROID) |
Avi Drissman | 82d9bb0 | 2023-10-09 21:05:45 | [diff] [blame] | 45 | Browser* browser = chrome::FindBrowserWithTab(web_contents()); |
Peter Kasting | a486324 | 2024-12-23 00:19:43 | [diff] [blame] | 46 | if (browser) { |
Mohamed Amir Yosef | e62de00f | 2021-01-30 04:18:13 | [diff] [blame] | 47 | browser->window()->UpdatePageActionIcon(GetPageActionIconType()); |
Peter Kasting | a486324 | 2024-12-23 00:19:43 | [diff] [blame] | 48 | } |
Vishwas Uppoor | 93470c6 | 2022-02-22 17:30:13 | [diff] [blame] | 49 | #endif // !BUILDFLAG(IS_ANDROID) |
Mohamed Amir Yosef | e62de00f | 2021-01-30 04:18:13 | [diff] [blame] | 50 | } |
| 51 | |
Mohamed Amir Yosef | e62de00f | 2021-01-30 04:18:13 | [diff] [blame] | 52 | void AutofillBubbleControllerBase::HideBubble() { |
| 53 | if (bubble_view_) { |
| 54 | bubble_view_->Hide(); |
| 55 | bubble_view_ = nullptr; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | } // namespace autofill |