1 // Copyright 2021 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_FONT_PREWARMER_TAB_HELPER_H_
6 #define CHROME_BROWSER_FONT_PREWARMER_TAB_HELPER_H_
11 #include "content/public/browser/web_contents_observer.h"
12 #include "content/public/browser/web_contents_user_data.h"
16 namespace user_prefs {
17 class PrefRegistrySyncable;
20 // FontPrewarmerTabHelper is responsible for tracking navigations to the search
21 // results page of the default search engine and prewarming the fonts that were
22 // previously used the last time a search results page of the default search
23 // engine was visited.
24 class FontPrewarmerTabHelper
25 : public content::WebContentsObserver,
26 public content::WebContentsUserData<FontPrewarmerTabHelper> {
28 FontPrewarmerTabHelper(const FontPrewarmerTabHelper&) = delete;
29 FontPrewarmerTabHelper& operator=(const FontPrewarmerTabHelper&) = delete;
30 ~FontPrewarmerTabHelper() override;
32 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
35 friend class content::WebContentsUserData<FontPrewarmerTabHelper>;
36 friend class FontPrewarmerTabHelperTest;
38 explicit FontPrewarmerTabHelper(content::WebContents* web_contents);
41 static std::string GetSearchResultsPagePrimaryFontsPref();
42 static std::vector<std::string> GetPrimaryFontNames(Profile* profile);
44 Profile* GetProfile();
46 // Returns true if the url of `navigation_handle` is a search results page of
47 // the default search provider.
48 bool IsSearchResultsPageNavigation(
49 content::NavigationHandle* navigation_handle);
51 // content::WebContentsObserver implementation.
52 void DidStartNavigation(
53 content::NavigationHandle* navigation_handle) override;
54 void ReadyToCommitNavigation(
55 content::NavigationHandle* navigation_handle) override;
57 absl::optional<int> expected_render_process_host_id_;
59 WEB_CONTENTS_USER_DATA_KEY_DECL();
62 #endif // CHROME_BROWSER_FONT_PREWARMER_TAB_HELPER_H_