1 // Copyright (c) 2012 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_HISTORY_HISTORY_TAB_HELPER_H_ 6 #define CHROME_BROWSER_HISTORY_HISTORY_TAB_HELPER_H_ 7 8 #include "base/macros.h" 9 #include "base/memory/ref_counted.h" 10 #include "base/time/time.h" 11 #include "content/public/browser/web_contents_observer.h" 12 #include "content/public/browser/web_contents_user_data.h" 13 14 namespace history { 15 struct HistoryAddPageArgs; 16 class HistoryService; 17 } 18 19 class HistoryTabHelper : public content::WebContentsObserver, 20 public content::WebContentsUserData<HistoryTabHelper> { 21 public: 22 ~HistoryTabHelper() override; 23 24 // If true, visits that do not increment the typed count (see 25 // HistoryBackend::IsTypedIncrement()) are marked as hidden. More 26 // specifically, this does two things: 27 // 28 // . |HistoryAddPageArgs::hidden| supplied to HistoryService::AddPage() is set 29 // to true. 30 // . The transition type PAGE_TRANSITION_FROM_API_3 is added. 31 // 32 // This results in the visit not directly influencing the omnibox and not 33 // being shown in history ui. set_hide_all_navigations(bool value)34 void set_hide_all_navigations(bool value) { hide_all_navigations_ = value; } 35 36 // Updates history with the specified navigation. This is called by 37 // DidFinishNavigation to update history state. 38 void UpdateHistoryForNavigation( 39 const history::HistoryAddPageArgs& add_page_args); 40 41 // Returns the history::HistoryAddPageArgs to use for adding a page to 42 // history. 43 history::HistoryAddPageArgs CreateHistoryAddPageArgs( 44 const GURL& virtual_url, 45 base::Time timestamp, 46 int nav_entry_id, 47 content::NavigationHandle* navigation_handle); 48 49 private: 50 explicit HistoryTabHelper(content::WebContents* web_contents); 51 friend class content::WebContentsUserData<HistoryTabHelper>; 52 53 // content::WebContentsObserver implementation. 54 void DidFinishNavigation( 55 content::NavigationHandle* navigation_handle) override; 56 void DidActivatePortal(content::WebContents* predecessor_contents, 57 base::TimeTicks activation_time) override; 58 void DidFinishLoad(content::RenderFrameHost* render_frame_host, 59 const GURL& validated_url) override; 60 void TitleWasSet(content::NavigationEntry* entry) override; 61 void WebContentsDestroyed() override; 62 63 // Helper function to return the history service. May return null. 64 history::HistoryService* GetHistoryService(); 65 66 // True after navigation to a page is complete and the page is currently 67 // loading. Only applies to the main frame of the page. 68 bool is_loading_ = false; 69 70 // Number of title changes since the loading of the navigation started. 71 int num_title_changes_ = 0; 72 73 // The time that the current page finished loading. Only title changes within 74 // a certain time period after the page load is complete will be saved to the 75 // history system. Only applies to the main frame of the page. 76 base::TimeTicks last_load_completion_; 77 78 // See comment above setter for details. 79 bool hide_all_navigations_ = false; 80 81 WEB_CONTENTS_USER_DATA_KEY_DECL(); 82 83 DISALLOW_COPY_AND_ASSIGN(HistoryTabHelper); 84 }; 85 86 #endif // CHROME_BROWSER_HISTORY_HISTORY_TAB_HELPER_H_ 87