| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_UI_COCOA_HANDOFF_ACTIVE_URL_OBSERVER_H_ | |
| 6 #define CHROME_BROWSER_UI_COCOA_HANDOFF_ACTIVE_URL_OBSERVER_H_ | |
| 7 | |
| 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" | |
| 11 | |
| 12 namespace content { | |
| 13 class WebContents; | |
| 14 } | |
| 15 | |
| 16 class Browser; | |
| 17 class HandoffActiveURLObserverDelegate; | |
| 18 class TabStripModel; | |
| 19 | |
| 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; | |
| 29 | |
| 30 private: | |
| 31 // chrome::BrowserListObserver | |
| 32 void OnBrowserSetLastActive(Browser* browser) override; | |
| 33 void OnBrowserRemoved(Browser* browser) override; | |
| 34 | |
| 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; | |
| 41 | |
| 42 // content::WebContentsObserver | |
| 43 void DidNavigateMainFrame( | |
| 44 const content::LoadCommittedDetails& details, | |
| 45 const content::FrameNavigateParams& params) override; | |
| 46 void WebContentsDestroyed() override; | |
| 47 | |
| 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(); | |
| 51 | |
| 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); | |
| 55 | |
| 56 // Makes this object stop observing the TabStripModel. | |
| 57 void StopObservingTabStripModel(); | |
| 58 | |
| 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); | |
| 62 | |
| 63 // Makes this object stop observing the WebContents. | |
| 64 void StopObservingWebContents(); | |
| 65 | |
| 66 // Returns the active WebContents. May return nullptr. | |
| 67 content::WebContents* GetActiveWebContents(); | |
| 68 | |
| 69 // Instances of this class should be owned by their |delegate_|. | |
| 70 HandoffActiveURLObserverDelegate* delegate_; | |
| 71 | |
| 72 // When this pointer is not nullptr, this object is registered as an observer | |
| 73 // of the TabStripModel. | |
| 74 TabStripModel* active_tab_strip_model_; | |
| 75 | |
| 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_; | |
| 79 | |
| 80 DISALLOW_COPY_AND_ASSIGN(HandoffActiveURLObserver); | |
| 81 }; | |
| 82 | |
| 83 #endif // CHROME_BROWSER_UI_COCOA_HANDOFF_ACTIVE_URL_OBSERVER_H_ | |
| OLD | NEW |