OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_PREVIEWS_PREVIEWS_INFOBAR_TAB_HELPER_H_ | 5 #ifndef CHROME_BROWSER_PREVIEWS_PREVIEWS_INFOBAR_TAB_HELPER_H_ |
6 #define CHROME_BROWSER_PREVIEWS_PREVIEWS_INFOBAR_TAB_HELPER_H_ | 6 #define CHROME_BROWSER_PREVIEWS_PREVIEWS_INFOBAR_TAB_HELPER_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/optional.h" | 9 #include "base/optional.h" |
10 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_ping
back_client.h" | 10 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_ping
back_client.h" |
| 11 #include "components/ukm/ukm_source.h" |
11 #include "content/public/browser/web_contents_observer.h" | 12 #include "content/public/browser/web_contents_observer.h" |
12 #include "content/public/browser/web_contents_user_data.h" | 13 #include "content/public/browser/web_contents_user_data.h" |
13 | 14 |
14 // Tracks whether a previews infobar has been shown for a page. Handles showing | 15 // Tracks whether a previews infobar has been shown for a page. Handles showing |
15 // the infobar when the main frame response indicates a Lite Page. | 16 // the infobar when the main frame response indicates a Lite Page. |
16 class PreviewsInfoBarTabHelper | 17 class PreviewsInfoBarTabHelper |
17 : public content::WebContentsObserver, | 18 : public content::WebContentsObserver, |
18 public content::WebContentsUserData<PreviewsInfoBarTabHelper> { | 19 public content::WebContentsUserData<PreviewsInfoBarTabHelper> { |
19 public: | 20 public: |
20 ~PreviewsInfoBarTabHelper() override; | 21 ~PreviewsInfoBarTabHelper() override; |
21 | 22 |
22 // Indicates whether the InfoBar for a preview has been shown for the page. | 23 // Indicates whether the InfoBar for a preview has been shown for the page. |
23 bool displayed_preview_infobar() const { | 24 bool displayed_preview_infobar() const { |
24 return displayed_preview_infobar_; | 25 return displayed_preview_infobar_; |
25 } | 26 } |
26 | 27 |
27 // Sets whether the InfoBar for a preview has been shown for the page. | 28 // Sets whether the InfoBar for a preview has been shown for the page. |
28 // |displayed_preview_infobar_| is reset to false on | 29 // |displayed_preview_infobar_| is reset to false on |
29 // DidStartProvisionalLoadForFrame for the main frame. | 30 // DidStartProvisionalLoadForFrame for the main frame. |
30 void set_displayed_preview_infobar(bool displayed) { | 31 void set_displayed_preview_infobar(bool displayed) { |
31 displayed_preview_infobar_ = displayed; | 32 displayed_preview_infobar_ = displayed; |
32 } | 33 } |
33 | 34 |
34 // The data saver page identifier of the current page load. | 35 // The data saver page identifier of the current page load. |
35 const base::Optional<data_reduction_proxy::NavigationID>& | 36 const base::Optional<data_reduction_proxy::NavigationID>& |
36 committed_data_saver_navigation_id() { | 37 committed_data_saver_navigation_id() { |
37 return committed_data_saver_navigation_id_; | 38 return committed_data_saver_navigation_id_; |
38 } | 39 } |
39 | 40 |
| 41 // Source ID for the last main frame navigation. |
| 42 base::Optional<ukm::SourceId> source_id() const { return source_id_; } |
| 43 |
40 private: | 44 private: |
41 friend class content::WebContentsUserData<PreviewsInfoBarTabHelper>; | 45 friend class content::WebContentsUserData<PreviewsInfoBarTabHelper>; |
42 friend class PreviewsInfoBarTabHelperUnitTest; | 46 friend class PreviewsInfoBarTabHelperUnitTest; |
43 | 47 |
44 explicit PreviewsInfoBarTabHelper(content::WebContents* web_contents); | 48 explicit PreviewsInfoBarTabHelper(content::WebContents* web_contents); |
45 | 49 |
46 // Clears the last navigation from this tab in the pingback client. | 50 // Clears the last navigation from this tab in the pingback client. |
47 void ClearLastNavigationAsync() const; | 51 void ClearLastNavigationAsync() const; |
48 | 52 |
49 // Overridden from content::WebContentsObserver: | 53 // Overridden from content::WebContentsObserver: |
50 void DidFinishNavigation( | 54 void DidFinishNavigation( |
51 content::NavigationHandle* navigation_handle) override; | 55 content::NavigationHandle* navigation_handle) override; |
52 | 56 |
53 // Stored for use in the destructor. | 57 // Stored for use in the destructor. |
54 content::BrowserContext* browser_context_; | 58 content::BrowserContext* browser_context_; |
55 | 59 |
56 // True if the InfoBar for a preview has been shown for the page. | 60 // True if the InfoBar for a preview has been shown for the page. |
57 bool displayed_preview_infobar_; | 61 bool displayed_preview_infobar_; |
58 | 62 |
59 // The data saver page identifier of the current page load. | 63 // The data saver page identifier of the current page load. |
60 base::Optional<data_reduction_proxy::NavigationID> | 64 base::Optional<data_reduction_proxy::NavigationID> |
61 committed_data_saver_navigation_id_; | 65 committed_data_saver_navigation_id_; |
62 | 66 |
| 67 // Source ID for the last main frame navigation. |
| 68 base::Optional<ukm::SourceId> source_id_; |
| 69 |
63 DISALLOW_COPY_AND_ASSIGN(PreviewsInfoBarTabHelper); | 70 DISALLOW_COPY_AND_ASSIGN(PreviewsInfoBarTabHelper); |
64 }; | 71 }; |
65 | 72 |
66 #endif // CHROME_BROWSER_PREVIEWS_PREVIEWS_INFOBAR_TAB_HELPER_H_ | 73 #endif // CHROME_BROWSER_PREVIEWS_PREVIEWS_INFOBAR_TAB_HELPER_H_ |
OLD | NEW |