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/cancelable_request.h" | 14 #include "chrome/browser/cancelable_request.h" |
15 #include "chrome/browser/history/history_types.h" | 15 #include "chrome/browser/history/history_types.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; | |
22 | 21 |
23 namespace content { | 22 namespace content { |
24 class WebContents; | 23 class WebContents; |
25 struct FrameNavigateParams; | 24 struct FrameNavigateParams; |
26 struct LoadCommittedDetails; | 25 struct LoadCommittedDetails; |
27 } | 26 } |
28 | 27 |
29 // TabFinder is used to locate a tab by URL. TabFinder matches tabs based | 28 // TabFinder is used to locate a tab by URL. TabFinder matches tabs based |
30 // on the tabs current url, or the start of the redirect chain. | 29 // on the tabs current url, or the start of the redirect chain. |
31 // | 30 // |
32 // TODO: if we end up keeping this (moving it out of about:flags) then we | 31 // TODO: if we end up keeping this (moving it out of about:flags) then we |
33 // should persist the start of the redirect chain in the navigation entry. | 32 // should persist the start of the redirect chain in the navigation entry. |
34 class TabFinder : public content::NotificationObserver { | 33 class TabFinder : public content::NotificationObserver { |
35 public: | 34 public: |
36 // Returns the TabFinder, or NULL if TabFinder is not enabled. | 35 // Returns the TabFinder, or NULL if TabFinder is not enabled. |
37 static TabFinder* GetInstance(); | 36 static TabFinder* GetInstance(); |
38 | 37 |
39 // Returns true if TabFinder is enabled. | 38 // Returns true if TabFinder is enabled. |
40 static bool IsEnabled(); | 39 static bool IsEnabled(); |
41 | 40 |
42 // Returns the tab that matches the specified url. If a tab is found the | 41 // Returns the tab that matches the specified url. If a tab is found the |
43 // browser containing the tab is set in |existing_browser|. This searches | 42 // browser containing the tab is set in |existing_browser|. This searches |
44 // in |browser| first before checking any other browsers. | 43 // in |browser| first before checking any other browsers. |
45 TabContents* FindTab(Browser* browser, | 44 content::WebContents* FindTab(Browser* browser, |
46 const GURL& url, | 45 const GURL& url, |
47 Browser** existing_browser); | 46 Browser** existing_browser); |
48 | 47 |
49 // content::NotificationObserver overrides: | 48 // content::NotificationObserver overrides: |
50 virtual void Observe(int type, | 49 virtual void Observe(int type, |
51 const content::NotificationSource& source, | 50 const content::NotificationSource& source, |
52 const content::NotificationDetails& details) OVERRIDE; | 51 const content::NotificationDetails& details) OVERRIDE; |
53 | 52 |
54 private: | 53 private: |
55 friend struct DefaultSingletonTraits<TabFinder>; | 54 friend struct DefaultSingletonTraits<TabFinder>; |
56 | 55 |
57 class WebContentsObserverImpl; | 56 class WebContentsObserverImpl; |
58 | 57 |
59 typedef std::map<content::WebContents*, GURL> WebContentsToURLMap; | 58 typedef std::map<content::WebContents*, GURL> WebContentsToURLMap; |
60 typedef std::set<WebContentsObserverImpl*> WebContentsObservers; | 59 typedef std::set<WebContentsObserverImpl*> WebContentsObservers; |
61 | 60 |
62 TabFinder(); | 61 TabFinder(); |
63 virtual ~TabFinder(); | 62 virtual ~TabFinder(); |
64 | 63 |
65 // Forwarded from WebContentsObserverImpl. | 64 // Forwarded from WebContentsObserverImpl. |
66 void DidNavigateAnyFrame( | 65 void DidNavigateAnyFrame( |
67 content::WebContents* source, | 66 content::WebContents* source, |
68 const content::LoadCommittedDetails& details, | 67 const content::LoadCommittedDetails& details, |
69 const content::FrameNavigateParams& params); | 68 const content::FrameNavigateParams& params); |
70 | 69 |
71 // Returns true if the tab's current url is |url|, or the start of the | 70 // Returns true if the tab's current url is |url|, or the start of the |
72 // redirect chain for the tab is |url|. | 71 // redirect chain for the tab is |url|. |
73 bool TabMatchesURL(content::WebContents* web_contents, const GURL& url); | 72 bool TabMatchesURL(content::WebContents* web_contents, const GURL& url); |
74 | 73 |
75 // Returns the first tab in the specified browser that matches the specified | 74 // Returns the first tab in the specified browser that matches the specified |
76 // url. Returns NULL if there are no tabs matching the specified url. | 75 // url. Returns NULL if there are no tabs matching the specified url. |
77 TabContents* FindTabInBrowser(Browser* browser, const GURL& url); | 76 content::WebContents* FindTabInBrowser(Browser* browser, const GURL& url); |
78 | 77 |
79 // If we're not currently tracking |tab| this creates a | 78 // If we're not currently tracking |tab| this creates a |
80 // WebContentsObserverImpl to listen for navigations. | 79 // WebContentsObserverImpl to listen for navigations. |
81 void TrackTab(content::WebContents* tab); | 80 void TrackTab(content::WebContents* tab); |
82 | 81 |
83 // Invoked when a TabContents is being destroyed. | 82 // Invoked when a WebContents is being destroyed. |
84 void TabDestroyed(WebContentsObserverImpl* observer); | 83 void TabDestroyed(WebContentsObserverImpl* observer); |
85 | 84 |
86 // Cancels any pending requests for the specified tabs redirect chain. | 85 // Cancels any pending requests for the specified tabs redirect chain. |
87 void CancelRequestsFor(content::WebContents* web_contents); | 86 void CancelRequestsFor(content::WebContents* web_contents); |
88 | 87 |
89 // Starts the fetch for the redirect chain of the specified WebContents. | 88 // Starts the fetch for the redirect chain of the specified WebContents. |
90 // QueryRedirectsToComplete is invoked when the redirect chain is retrieved. | 89 // QueryRedirectsToComplete is invoked when the redirect chain is retrieved. |
91 void FetchRedirectStart(content::WebContents* tab); | 90 void FetchRedirectStart(content::WebContents* tab); |
92 | 91 |
93 // Callback when we get the redirect list for a tab. | 92 // Callback when we get the redirect list for a tab. |
94 void QueryRedirectsToComplete(CancelableRequestProvider::Handle handle, | 93 void QueryRedirectsToComplete(CancelableRequestProvider::Handle handle, |
95 GURL url, | 94 GURL url, |
96 bool success, | 95 bool success, |
97 history::RedirectList* redirects); | 96 history::RedirectList* redirects); |
98 | 97 |
99 // Maps from WebContents to the start of the redirect chain. | 98 // Maps from WebContents to the start of the redirect chain. |
100 WebContentsToURLMap web_contents_to_url_; | 99 WebContentsToURLMap web_contents_to_url_; |
101 | 100 |
102 CancelableRequestConsumerTSimple<content::WebContents*> callback_consumer_; | 101 CancelableRequestConsumerTSimple<content::WebContents*> callback_consumer_; |
103 | 102 |
104 content::NotificationRegistrar registrar_; | 103 content::NotificationRegistrar registrar_; |
105 | 104 |
106 WebContentsObservers tab_contents_observers_; | 105 WebContentsObservers tab_contents_observers_; |
107 | 106 |
108 DISALLOW_COPY_AND_ASSIGN(TabFinder); | 107 DISALLOW_COPY_AND_ASSIGN(TabFinder); |
109 }; | 108 }; |
110 | 109 |
111 #endif // CHROME_BROWSER_TABS_TAB_FINDER_H_ | 110 #endif // CHROME_BROWSER_TABS_TAB_FINDER_H_ |
OLD | NEW |