| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 // Implements the Chrome Extensions WebNavigation API. | 5 // Implements the Chrome Extensions WebNavigation API. |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h" | 7 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h" |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 const GURL& target_url) | 67 const GURL& target_url) |
| 68 : source_web_contents(source_web_contents), | 68 : source_web_contents(source_web_contents), |
| 69 source_frame_host(source_frame_host), | 69 source_frame_host(source_frame_host), |
| 70 target_web_contents(target_web_contents), | 70 target_web_contents(target_web_contents), |
| 71 target_url(target_url) { | 71 target_url(target_url) { |
| 72 } | 72 } |
| 73 | 73 |
| 74 WebNavigationEventRouter::PendingWebContents::~PendingWebContents() {} | 74 WebNavigationEventRouter::PendingWebContents::~PendingWebContents() {} |
| 75 | 75 |
| 76 WebNavigationEventRouter::WebNavigationEventRouter(Profile* profile) | 76 WebNavigationEventRouter::WebNavigationEventRouter(Profile* profile) |
| 77 : profile_(profile) { | 77 : profile_(profile), browser_tab_strip_tracker_(this, this, nullptr) { |
| 78 CHECK(registrar_.IsEmpty()); | 78 CHECK(registrar_.IsEmpty()); |
| 79 registrar_.Add(this, | 79 registrar_.Add(this, |
| 80 chrome::NOTIFICATION_RETARGETING, | 80 chrome::NOTIFICATION_RETARGETING, |
| 81 content::NotificationService::AllSources()); | 81 content::NotificationService::AllSources()); |
| 82 registrar_.Add(this, | 82 registrar_.Add(this, |
| 83 chrome::NOTIFICATION_TAB_ADDED, | 83 chrome::NOTIFICATION_TAB_ADDED, |
| 84 content::NotificationService::AllSources()); | 84 content::NotificationService::AllSources()); |
| 85 registrar_.Add(this, | 85 registrar_.Add(this, |
| 86 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 86 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 87 content::NotificationService::AllSources()); | 87 content::NotificationService::AllSources()); |
| 88 | 88 |
| 89 BrowserList::AddObserver(this); | 89 browser_tab_strip_tracker_.Init( |
| 90 for (chrome::BrowserIterator it; !it.done(); it.Next()) | 90 BrowserTabStripTracker::InitWith::ALL_BROWERS); |
| 91 OnBrowserAdded(*it); | |
| 92 } | 91 } |
| 93 | 92 |
| 94 WebNavigationEventRouter::~WebNavigationEventRouter() { | 93 WebNavigationEventRouter::~WebNavigationEventRouter() { |
| 95 for (chrome::BrowserIterator it; !it.done(); it.Next()) | |
| 96 OnBrowserRemoved(*it); | |
| 97 BrowserList::RemoveObserver(this); | |
| 98 } | 94 } |
| 99 | 95 |
| 100 void WebNavigationEventRouter::OnBrowserAdded(Browser* browser) { | 96 bool WebNavigationEventRouter::ShouldTrackBrowser(Browser* browser) { |
| 101 if (!profile_->IsSameProfile(browser->profile())) | 97 return profile_->IsSameProfile(browser->profile()); |
| 102 return; | |
| 103 browser->tab_strip_model()->AddObserver(this); | |
| 104 } | |
| 105 | |
| 106 void WebNavigationEventRouter::OnBrowserRemoved(Browser* browser) { | |
| 107 if (!profile_->IsSameProfile(browser->profile())) | |
| 108 return; | |
| 109 browser->tab_strip_model()->RemoveObserver(this); | |
| 110 } | 98 } |
| 111 | 99 |
| 112 void WebNavigationEventRouter::TabReplacedAt( | 100 void WebNavigationEventRouter::TabReplacedAt( |
| 113 TabStripModel* tab_strip_model, | 101 TabStripModel* tab_strip_model, |
| 114 content::WebContents* old_contents, | 102 content::WebContents* old_contents, |
| 115 content::WebContents* new_contents, | 103 content::WebContents* new_contents, |
| 116 int index) { | 104 int index) { |
| 117 WebNavigationTabObserver* tab_observer = | 105 WebNavigationTabObserver* tab_observer = |
| 118 WebNavigationTabObserver::Get(old_contents); | 106 WebNavigationTabObserver::Get(old_contents); |
| 119 if (!tab_observer) { | 107 if (!tab_observer) { |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 return g_factory.Pointer(); | 613 return g_factory.Pointer(); |
| 626 } | 614 } |
| 627 | 615 |
| 628 void WebNavigationAPI::OnListenerAdded(const EventListenerInfo& details) { | 616 void WebNavigationAPI::OnListenerAdded(const EventListenerInfo& details) { |
| 629 web_navigation_event_router_.reset(new WebNavigationEventRouter( | 617 web_navigation_event_router_.reset(new WebNavigationEventRouter( |
| 630 Profile::FromBrowserContext(browser_context_))); | 618 Profile::FromBrowserContext(browser_context_))); |
| 631 EventRouter::Get(browser_context_)->UnregisterObserver(this); | 619 EventRouter::Get(browser_context_)->UnregisterObserver(this); |
| 632 } | 620 } |
| 633 | 621 |
| 634 } // namespace extensions | 622 } // namespace extensions |
| OLD | NEW |