| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_TABS_TAB_FINDER_H_ | 5 #ifndef CHROME_BROWSER_TABS_TAB_FINDER_H_ |
| 6 #define CHROME_BROWSER_TABS_TAB_FINDER_H_ | 6 #define CHROME_BROWSER_TABS_TAB_FINDER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
| 14 #include "chrome/browser/history/history_types.h" | 14 #include "chrome/browser/history/history_types.h" |
| 15 #include "content/browser/cancelable_request.h" | 15 #include "content/browser/cancelable_request.h" |
| 16 #include "content/public/browser/notification_observer.h" | 16 #include "content/public/browser/notification_observer.h" |
| 17 #include "content/public/browser/notification_registrar.h" | 17 #include "content/public/browser/notification_registrar.h" |
| 18 | 18 |
| 19 class Browser; | 19 class Browser; |
| 20 class GURL; | 20 class GURL; |
| 21 class TabContents; | 21 class TabContents; |
| 22 | 22 |
| 23 namespace content { | 23 namespace content { |
| 24 class WebContents; |
| 24 struct FrameNavigateParams; | 25 struct FrameNavigateParams; |
| 25 struct LoadCommittedDetails; | 26 struct LoadCommittedDetails; |
| 26 } | 27 } |
| 27 | 28 |
| 28 // TabFinder is used to locate a tab by URL. TabFinder matches tabs based | 29 // TabFinder is used to locate a tab by URL. TabFinder matches tabs based |
| 29 // on the tabs current url, or the start of the redirect chain. | 30 // on the tabs current url, or the start of the redirect chain. |
| 30 // | 31 // |
| 31 // TODO: if we end up keeping this (moving it out of about:flags) then we | 32 // TODO: if we end up keeping this (moving it out of about:flags) then we |
| 32 // should persist the start of the redirect chain in the navigation entry. | 33 // should persist the start of the redirect chain in the navigation entry. |
| 33 class TabFinder : public content::NotificationObserver { | 34 class TabFinder : public content::NotificationObserver { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 48 // content::NotificationObserver overrides: | 49 // content::NotificationObserver overrides: |
| 49 virtual void Observe(int type, | 50 virtual void Observe(int type, |
| 50 const content::NotificationSource& source, | 51 const content::NotificationSource& source, |
| 51 const content::NotificationDetails& details) OVERRIDE; | 52 const content::NotificationDetails& details) OVERRIDE; |
| 52 | 53 |
| 53 private: | 54 private: |
| 54 friend struct DefaultSingletonTraits<TabFinder>; | 55 friend struct DefaultSingletonTraits<TabFinder>; |
| 55 | 56 |
| 56 class WebContentsObserverImpl; | 57 class WebContentsObserverImpl; |
| 57 | 58 |
| 58 typedef std::map<TabContents*, GURL> TabContentsToURLMap; | 59 typedef std::map<content::WebContents*, GURL> WebContentsToURLMap; |
| 59 typedef std::set<WebContentsObserverImpl*> WebContentsObservers; | 60 typedef std::set<WebContentsObserverImpl*> WebContentsObservers; |
| 60 | 61 |
| 61 TabFinder(); | 62 TabFinder(); |
| 62 virtual ~TabFinder(); | 63 virtual ~TabFinder(); |
| 63 | 64 |
| 64 // Forwarded from WebContentsObserverImpl. | 65 // Forwarded from WebContentsObserverImpl. |
| 65 void DidNavigateAnyFrame( | 66 void DidNavigateAnyFrame( |
| 66 TabContents* source, | 67 content::WebContents* source, |
| 67 const content::LoadCommittedDetails& details, | 68 const content::LoadCommittedDetails& details, |
| 68 const content::FrameNavigateParams& params); | 69 const content::FrameNavigateParams& params); |
| 69 | 70 |
| 70 // Returns true if the tab's current url is |url|, or the start of the | 71 // Returns true if the tab's current url is |url|, or the start of the |
| 71 // redirect chain for the tab is |url|. | 72 // redirect chain for the tab is |url|. |
| 72 bool TabMatchesURL(TabContents* tab_contents, const GURL& url); | 73 bool TabMatchesURL(content::WebContents* web_contents, const GURL& url); |
| 73 | 74 |
| 74 // Returns the first tab in the specified browser that matches the specified | 75 // Returns the first tab in the specified browser that matches the specified |
| 75 // url. Returns NULL if there are no tabs matching the specified url. | 76 // url. Returns NULL if there are no tabs matching the specified url. |
| 76 TabContents* FindTabInBrowser(Browser* browser, const GURL& url); | 77 TabContents* FindTabInBrowser(Browser* browser, const GURL& url); |
| 77 | 78 |
| 78 // If we're not currently tracking |tab| this creates a | 79 // If we're not currently tracking |tab| this creates a |
| 79 // WebContentsObserverImpl to listen for navigations. | 80 // WebContentsObserverImpl to listen for navigations. |
| 80 void TrackTab(TabContents* tab); | 81 void TrackTab(content::WebContents* tab); |
| 81 | 82 |
| 82 // Invoked when a TabContents is being destroyed. | 83 // Invoked when a TabContents is being destroyed. |
| 83 void TabDestroyed(WebContentsObserverImpl* observer); | 84 void TabDestroyed(WebContentsObserverImpl* observer); |
| 84 | 85 |
| 85 // Cancels any pending requests for the specified tabs redirect chain. | 86 // Cancels any pending requests for the specified tabs redirect chain. |
| 86 void CancelRequestsFor(TabContents* tab_contents); | 87 void CancelRequestsFor(content::WebContents* web_contents); |
| 87 | 88 |
| 88 // Starts the fetch for the redirect chain of the specified TabContents. | 89 // Starts the fetch for the redirect chain of the specified WebContents. |
| 89 // QueryRedirectsToComplete is invoked when the redirect chain is retrieved. | 90 // QueryRedirectsToComplete is invoked when the redirect chain is retrieved. |
| 90 void FetchRedirectStart(TabContents* tab); | 91 void FetchRedirectStart(content::WebContents* tab); |
| 91 | 92 |
| 92 // Callback when we get the redirect list for a tab. | 93 // Callback when we get the redirect list for a tab. |
| 93 void QueryRedirectsToComplete(CancelableRequestProvider::Handle handle, | 94 void QueryRedirectsToComplete(CancelableRequestProvider::Handle handle, |
| 94 GURL url, | 95 GURL url, |
| 95 bool success, | 96 bool success, |
| 96 history::RedirectList* redirects); | 97 history::RedirectList* redirects); |
| 97 | 98 |
| 98 // Maps from TabContents to the start of the redirect chain. | 99 // Maps from WebContents to the start of the redirect chain. |
| 99 TabContentsToURLMap tab_contents_to_url_; | 100 WebContentsToURLMap web_contents_to_url_; |
| 100 | 101 |
| 101 CancelableRequestConsumerTSimple<TabContents*> callback_consumer_; | 102 CancelableRequestConsumerTSimple<content::WebContents*> callback_consumer_; |
| 102 | 103 |
| 103 content::NotificationRegistrar registrar_; | 104 content::NotificationRegistrar registrar_; |
| 104 | 105 |
| 105 WebContentsObservers tab_contents_observers_; | 106 WebContentsObservers tab_contents_observers_; |
| 106 | 107 |
| 107 DISALLOW_COPY_AND_ASSIGN(TabFinder); | 108 DISALLOW_COPY_AND_ASSIGN(TabFinder); |
| 108 }; | 109 }; |
| 109 | 110 |
| 110 #endif // CHROME_BROWSER_TABS_TAB_FINDER_H_ | 111 #endif // CHROME_BROWSER_TABS_TAB_FINDER_H_ |
| OLD | NEW |