Cleanup: Update the path to insets and point headers.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / handoff_active_url_observer.h
bloba46ed98ce6c71a01f1f4ed79ae10ffa910840ece
1 // Copyright 2014 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_UI_COCOA_HANDOFF_ACTIVE_URL_OBSERVER_H_
6 #define CHROME_BROWSER_UI_COCOA_HANDOFF_ACTIVE_URL_OBSERVER_H_
8 #include "chrome/browser/ui/browser_list_observer.h"
9 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
10 #include "content/public/browser/web_contents_observer.h"
12 namespace content {
13 class WebContents;
16 class Browser;
17 class HandoffActiveURLObserverDelegate;
18 class TabStripModel;
20 // This class observes changes to the "active URL". This is defined as the
21 // visible URL of the WebContents of the selected tab of the most recently
22 // focused browser window.
23 class HandoffActiveURLObserver : public chrome::BrowserListObserver,
24 public TabStripModelObserver,
25 public content::WebContentsObserver {
26 public:
27 explicit HandoffActiveURLObserver(HandoffActiveURLObserverDelegate* delegate);
28 ~HandoffActiveURLObserver() override;
30 private:
31 // chrome::BrowserListObserver
32 void OnBrowserSetLastActive(Browser* browser) override;
33 void OnBrowserRemoved(Browser* browser) override;
35 // TabStripModelObserver
36 void ActiveTabChanged(content::WebContents* old_contents,
37 content::WebContents* new_contents,
38 int index,
39 int reason) override;
40 void TabStripModelDeleted() override;
42 // content::WebContentsObserver
43 void DidNavigateMainFrame(
44 const content::LoadCommittedDetails& details,
45 const content::FrameNavigateParams& params) override;
46 void WebContentsDestroyed() override;
48 // This method ensures that the instance is registered as an observer of the
49 // correct TabStripModel and WebContents for |active_browser_|.
50 void UpdateObservations();
52 // Makes this object start observing the TabStripModel, if it is not already
53 // doing so. This method is idempotent.
54 void StartObservingTabStripModel(TabStripModel* tab_strip_model);
56 // Makes this object stop observing the TabStripModel.
57 void StopObservingTabStripModel();
59 // Makes this object start observing the WebContents, if it is not already
60 // doing so. This method is idempotent.
61 void StartObservingWebContents(content::WebContents* web_contents);
63 // Makes this object stop observing the WebContents.
64 void StopObservingWebContents();
66 // Returns the active WebContents. May return nullptr.
67 content::WebContents* GetActiveWebContents();
69 // Instances of this class should be owned by their |delegate_|.
70 HandoffActiveURLObserverDelegate* delegate_;
72 // When this pointer is not nullptr, this object is registered as an observer
73 // of the TabStripModel.
74 TabStripModel* active_tab_strip_model_;
76 // This pointer is always up to date, and points to the most recently
77 // activated browser, or nullptr if no browsers exist.
78 Browser* active_browser_;
80 DISALLOW_COPY_AND_ASSIGN(HandoffActiveURLObserver);
83 #endif // CHROME_BROWSER_UI_COCOA_HANDOFF_ACTIVE_URL_OBSERVER_H_