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.
5 #ifndef CHROME_BROWSER_HISTORY_HISTORY_TAB_HELPER_H_
6 #define CHROME_BROWSER_HISTORY_HISTORY_TAB_HELPER_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/time/time.h"
10 #include "content/public/browser/web_contents_observer.h"
11 #include "content/public/browser/web_contents_user_data.h"
16 struct HistoryAddPageArgs;
19 class HistoryTabHelper : public content::WebContentsObserver,
20 public content::WebContentsUserData<HistoryTabHelper> {
22 virtual ~HistoryTabHelper();
24 // Updates history with the specified navigation. This is called by
25 // OnMsgNavigate to update history state.
26 void UpdateHistoryForNavigation(
27 const history::HistoryAddPageArgs& add_page_args);
29 // Sends the page title to the history service. This is called when we receive
30 // the page title and we know we want to update history.
31 void UpdateHistoryPageTitle(const content::NavigationEntry& entry);
33 // Returns the history::HistoryAddPageArgs to use for adding a page to
35 history::HistoryAddPageArgs CreateHistoryAddPageArgs(
36 const GURL& virtual_url,
38 bool did_replace_entry,
39 const content::FrameNavigateParams& params);
42 explicit HistoryTabHelper(content::WebContents* web_contents);
43 friend class content::WebContentsUserData<HistoryTabHelper>;
45 // content::WebContentsObserver implementation.
46 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
47 virtual void DidNavigateMainFrame(
48 const content::LoadCommittedDetails& details,
49 const content::FrameNavigateParams& params) OVERRIDE;
50 virtual void DidNavigateAnyFrame(
51 const content::LoadCommittedDetails& details,
52 const content::FrameNavigateParams& params) OVERRIDE;
53 virtual void TitleWasSet(content::NavigationEntry* entry,
54 bool explicit_set) OVERRIDE;
55 virtual void WebContentsDestroyed(content::WebContents* tab) OVERRIDE;
57 void OnPageContents(const GURL& url, const string16& contents);
59 // Helper function to return the history service. May return NULL.
60 HistoryService* GetHistoryService();
62 // Whether we have a (non-empty) title for the current page.
63 // Used to prevent subsequent title updates from affecting history. This
64 // prevents some weirdness because some AJAXy apps use titles for status
66 bool received_page_title_;
68 DISALLOW_COPY_AND_ASSIGN(HistoryTabHelper);
71 #endif // CHROME_BROWSER_HISTORY_HISTORY_TAB_HELPER_H_