| 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 #include "chrome/browser/tabs/tab_finder.h" | 5 #include "chrome/browser/tabs/tab_finder.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "chrome/browser/history/history.h" | 11 #include "chrome/browser/history/history.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/browser_list.h" | 14 #include "chrome/browser/ui/browser_list.h" |
| 15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 17 #include "content/browser/tab_contents/tab_contents.h" | 17 #include "content/browser/tab_contents/tab_contents.h" |
| 18 #include "content/public/browser/navigation_details.h" | 18 #include "content/public/browser/navigation_details.h" |
| 19 #include "content/public/browser/navigation_entry.h" | 19 #include "content/public/browser/navigation_entry.h" |
| 20 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
| 21 #include "content/public/browser/notification_source.h" | 21 #include "content/public/browser/notification_source.h" |
| 22 #include "content/public/browser/notification_types.h" | 22 #include "content/public/browser/notification_types.h" |
| 23 #include "content/public/browser/web_contents_observer.h" | 23 #include "content/public/browser/web_contents_observer.h" |
| 24 #include "content/public/common/frame_navigate_params.h" | 24 #include "content/public/common/frame_navigate_params.h" |
| 25 #include "content/public/common/page_transition_types.h" | 25 #include "content/public/common/page_transition_types.h" |
| 26 | 26 |
| 27 using content::NavigationEntry; |
| 27 using content::WebContents; | 28 using content::WebContents; |
| 28 | 29 |
| 29 class TabFinder::WebContentsObserverImpl : public content::WebContentsObserver { | 30 class TabFinder::WebContentsObserverImpl : public content::WebContentsObserver { |
| 30 public: | 31 public: |
| 31 WebContentsObserverImpl(WebContents* tab, TabFinder* finder); | 32 WebContentsObserverImpl(WebContents* tab, TabFinder* finder); |
| 32 virtual ~WebContentsObserverImpl(); | 33 virtual ~WebContentsObserverImpl(); |
| 33 | 34 |
| 34 WebContents* web_contents() { | 35 WebContents* web_contents() { |
| 35 return content::WebContentsObserver::web_contents(); | 36 return content::WebContentsObserver::web_contents(); |
| 36 } | 37 } |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 history->CancelRequest(request_handle); | 205 history->CancelRequest(request_handle); |
| 205 } | 206 } |
| 206 } | 207 } |
| 207 } | 208 } |
| 208 | 209 |
| 209 void TabFinder::FetchRedirectStart(WebContents* tab) { | 210 void TabFinder::FetchRedirectStart(WebContents* tab) { |
| 210 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); | 211 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); |
| 211 if (profile->IsOffTheRecord()) | 212 if (profile->IsOffTheRecord()) |
| 212 return; | 213 return; |
| 213 | 214 |
| 214 content::NavigationEntry* committed_entry = | 215 NavigationEntry* committed_entry = |
| 215 tab->GetController().GetLastCommittedEntry(); | 216 tab->GetController().GetLastCommittedEntry(); |
| 216 if (!committed_entry || committed_entry->GetURL().is_empty()) | 217 if (!committed_entry || committed_entry->GetURL().is_empty()) |
| 217 return; | 218 return; |
| 218 | 219 |
| 219 HistoryService* history = profile->GetHistoryService( | 220 HistoryService* history = profile->GetHistoryService( |
| 220 Profile::EXPLICIT_ACCESS); | 221 Profile::EXPLICIT_ACCESS); |
| 221 if (history) { | 222 if (history) { |
| 222 CancelableRequestProvider::Handle request_handle = | 223 CancelableRequestProvider::Handle request_handle = |
| 223 history->QueryRedirectsTo( | 224 history->QueryRedirectsTo( |
| 224 committed_entry->GetURL(), | 225 committed_entry->GetURL(), |
| 225 &callback_consumer_, | 226 &callback_consumer_, |
| 226 base::Bind(&TabFinder::QueryRedirectsToComplete, | 227 base::Bind(&TabFinder::QueryRedirectsToComplete, |
| 227 base::Unretained(this))); | 228 base::Unretained(this))); |
| 228 callback_consumer_.SetClientData(history, request_handle, tab); | 229 callback_consumer_.SetClientData(history, request_handle, tab); |
| 229 } | 230 } |
| 230 } | 231 } |
| 231 | 232 |
| 232 void TabFinder::QueryRedirectsToComplete(HistoryService::Handle handle, | 233 void TabFinder::QueryRedirectsToComplete(HistoryService::Handle handle, |
| 233 GURL url, | 234 GURL url, |
| 234 bool success, | 235 bool success, |
| 235 history::RedirectList* redirects) { | 236 history::RedirectList* redirects) { |
| 236 if (success && !redirects->empty()) { | 237 if (success && !redirects->empty()) { |
| 237 WebContents* web_contents = | 238 WebContents* web_contents = |
| 238 callback_consumer_.GetClientDataForCurrentRequest(); | 239 callback_consumer_.GetClientDataForCurrentRequest(); |
| 239 DCHECK(web_contents); | 240 DCHECK(web_contents); |
| 240 web_contents_to_url_[web_contents] = redirects->back(); | 241 web_contents_to_url_[web_contents] = redirects->back(); |
| 241 } | 242 } |
| 242 } | 243 } |
| OLD | NEW |