| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/cocoa/handoff_active_url_observer.h" | 5 #include "chrome/browser/ui/cocoa/handoff_active_url_observer.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/ui/browser_finder.h" | 8 #include "chrome/browser/ui/browser_finder.h" |
| 9 #include "chrome/browser/ui/browser_list.h" | 9 #include "chrome/browser/ui/browser_list.h" |
| 10 #include "chrome/browser/ui/cocoa/handoff_active_url_observer_delegate.h" | 10 #include "chrome/browser/ui/cocoa/handoff_active_url_observer_delegate.h" |
| 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
| 13 | 13 |
| 14 HandoffActiveURLObserver::HandoffActiveURLObserver( | 14 HandoffActiveURLObserver::HandoffActiveURLObserver( |
| 15 HandoffActiveURLObserverDelegate* delegate) | 15 HandoffActiveURLObserverDelegate* delegate) |
| 16 : delegate_(delegate), | 16 : delegate_(delegate), |
| 17 active_browser_(nullptr) { | 17 active_browser_(nullptr) { |
| 18 DCHECK(delegate_); | 18 DCHECK(delegate_); |
| 19 | 19 |
| 20 BrowserList::AddObserver(this); | 20 BrowserList::AddObserver(this); |
| 21 SetActiveBrowser(chrome::FindLastActiveWithHostDesktopType( | 21 SetActiveBrowser(chrome::FindLastActive()); |
| 22 chrome::HOST_DESKTOP_TYPE_NATIVE)); | |
| 23 } | 22 } |
| 24 | 23 |
| 25 HandoffActiveURLObserver::~HandoffActiveURLObserver() { | 24 HandoffActiveURLObserver::~HandoffActiveURLObserver() { |
| 26 BrowserList::RemoveObserver(this); | 25 BrowserList::RemoveObserver(this); |
| 27 SetActiveBrowser(nullptr); | 26 SetActiveBrowser(nullptr); |
| 28 } | 27 } |
| 29 | 28 |
| 30 void HandoffActiveURLObserver::OnBrowserSetLastActive(Browser* browser) { | 29 void HandoffActiveURLObserver::OnBrowserSetLastActive(Browser* browser) { |
| 31 SetActiveBrowser(browser); | 30 SetActiveBrowser(browser); |
| 32 delegate_->HandoffActiveURLChanged(GetActiveWebContents()); | 31 delegate_->HandoffActiveURLChanged(GetActiveWebContents()); |
| 33 } | 32 } |
| 34 | 33 |
| 35 void HandoffActiveURLObserver::OnBrowserRemoved(Browser* removed_browser) { | 34 void HandoffActiveURLObserver::OnBrowserRemoved(Browser* removed_browser) { |
| 36 if (active_browser_ != removed_browser) | 35 if (active_browser_ != removed_browser) |
| 37 return; | 36 return; |
| 38 | 37 |
| 39 SetActiveBrowser(chrome::FindLastActiveWithHostDesktopType( | 38 SetActiveBrowser(chrome::FindLastActive()); |
| 40 chrome::HOST_DESKTOP_TYPE_NATIVE)); | |
| 41 delegate_->HandoffActiveURLChanged(GetActiveWebContents()); | 39 delegate_->HandoffActiveURLChanged(GetActiveWebContents()); |
| 42 } | 40 } |
| 43 | 41 |
| 44 void HandoffActiveURLObserver::ActiveTabChanged( | 42 void HandoffActiveURLObserver::ActiveTabChanged( |
| 45 content::WebContents* old_contents, | 43 content::WebContents* old_contents, |
| 46 content::WebContents* new_contents, | 44 content::WebContents* new_contents, |
| 47 int index, | 45 int index, |
| 48 int reason) { | 46 int reason) { |
| 49 StartObservingWebContents(new_contents); | 47 StartObservingWebContents(new_contents); |
| 50 delegate_->HandoffActiveURLChanged(new_contents); | 48 delegate_->HandoffActiveURLChanged(new_contents); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 void HandoffActiveURLObserver::StopObservingWebContents() { | 82 void HandoffActiveURLObserver::StopObservingWebContents() { |
| 85 Observe(nullptr); | 83 Observe(nullptr); |
| 86 } | 84 } |
| 87 | 85 |
| 88 content::WebContents* HandoffActiveURLObserver::GetActiveWebContents() { | 86 content::WebContents* HandoffActiveURLObserver::GetActiveWebContents() { |
| 89 if (!active_browser_) | 87 if (!active_browser_) |
| 90 return nullptr; | 88 return nullptr; |
| 91 | 89 |
| 92 return active_browser_->tab_strip_model()->GetActiveWebContents(); | 90 return active_browser_->tab_strip_model()->GetActiveWebContents(); |
| 93 } | 91 } |
| OLD | NEW |