Home | History | Annotate | Download | only in history
      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/memory/ref_counted.h"
      9 #include "base/time/time.h"
     10 #include "content/public/browser/notification_observer.h"
     11 #include "content/public/browser/notification_registrar.h"
     12 #include "content/public/browser/web_contents_observer.h"
     13 #include "content/public/browser/web_contents_user_data.h"
     14 
     15 class HistoryService;
     16 
     17 namespace history {
     18 struct HistoryAddPageArgs;
     19 }
     20 
     21 class HistoryTabHelper : public content::WebContentsObserver,
     22                          public content::NotificationObserver,
     23                          public content::WebContentsUserData<HistoryTabHelper> {
     24  public:
     25   virtual ~HistoryTabHelper();
     26 
     27   // Updates history with the specified navigation. This is called by
     28   // OnMsgNavigate to update history state.
     29   void UpdateHistoryForNavigation(
     30       const history::HistoryAddPageArgs& add_page_args);
     31 
     32   // Sends the page title to the history service. This is called when we receive
     33   // the page title and we know we want to update history.
     34   void UpdateHistoryPageTitle(const content::NavigationEntry& entry);
     35 
     36   // Returns the history::HistoryAddPageArgs to use for adding a page to
     37   // history.
     38   history::HistoryAddPageArgs CreateHistoryAddPageArgs(
     39       const GURL& virtual_url,
     40       base::Time timestamp,
     41       bool did_replace_entry,
     42       const content::FrameNavigateParams& params);
     43 
     44  private:
     45   explicit HistoryTabHelper(content::WebContents* web_contents);
     46   friend class content::WebContentsUserData<HistoryTabHelper>;
     47 
     48   // content::WebContentsObserver implementation.
     49   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
     50   virtual void DidNavigateMainFrame(
     51       const content::LoadCommittedDetails& details,
     52       const content::FrameNavigateParams& params) OVERRIDE;
     53   virtual void DidNavigateAnyFrame(
     54       const content::LoadCommittedDetails& details,
     55       const content::FrameNavigateParams& params) OVERRIDE;
     56   virtual void WebContentsDestroyed(content::WebContents* tab) OVERRIDE;
     57 
     58   // content::NotificationObserver implementation.
     59   virtual void Observe(int type,
     60                        const content::NotificationSource& source,
     61                        const content::NotificationDetails& details) OVERRIDE;
     62 
     63   void OnPageContents(const GURL& url, const string16& contents);
     64 
     65   // Helper function to return the history service.  May return NULL.
     66   HistoryService* GetHistoryService();
     67 
     68   // Whether we have a (non-empty) title for the current page.
     69   // Used to prevent subsequent title updates from affecting history. This
     70   // prevents some weirdness because some AJAXy apps use titles for status
     71   // messages.
     72   bool received_page_title_;
     73 
     74   content::NotificationRegistrar registrar_;
     75 
     76   DISALLOW_COPY_AND_ASSIGN(HistoryTabHelper);
     77 };
     78 
     79 #endif  // CHROME_BROWSER_HISTORY_HISTORY_TAB_HELPER_H_
     80