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/alternate_nav_url_fetcher.h" | 5 #include "chrome/browser/alternate_nav_url_fetcher.h" |
6 | 6 |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/intranet_redirect_detector.h" | 8 #include "chrome/browser/intranet_redirect_detector.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 10 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
11 #include "content/browser/tab_contents/navigation_controller.h" | 11 #include "content/browser/tab_contents/navigation_controller.h" |
12 #include "content/browser/tab_contents/navigation_entry.h" | 12 #include "content/browser/tab_contents/navigation_entry.h" |
13 #include "content/common/notification_service.h" | 13 #include "content/common/notification_service.h" |
14 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
15 #include "grit/theme_resources_standard.h" | 15 #include "grit/theme_resources_standard.h" |
16 #include "net/base/registry_controlled_domain.h" | 16 #include "net/base/registry_controlled_domain.h" |
17 #include "net/url_request/url_request.h" | 17 #include "net/url_request/url_request.h" |
18 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
19 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
20 | 20 |
21 AlternateNavURLFetcher::AlternateNavURLFetcher( | 21 AlternateNavURLFetcher::AlternateNavURLFetcher( |
22 const GURL& alternate_nav_url) | 22 const GURL& alternate_nav_url) |
23 : LinkInfoBarDelegate(NULL), | 23 : LinkInfoBarDelegate(NULL), |
24 alternate_nav_url_(alternate_nav_url), | 24 alternate_nav_url_(alternate_nav_url), |
25 controller_(NULL), | 25 controller_(NULL), |
26 state_(NOT_STARTED), | 26 state_(NOT_STARTED), |
27 navigated_to_entry_(false), | 27 navigated_to_entry_(false), |
28 infobar_contents_(NULL) { | 28 infobar_contents_(NULL) { |
29 registrar_.Add(this, NotificationType::NAV_ENTRY_PENDING, | 29 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING, |
30 NotificationService::AllSources()); | 30 NotificationService::AllSources()); |
31 } | 31 } |
32 | 32 |
33 AlternateNavURLFetcher::~AlternateNavURLFetcher() {} | 33 AlternateNavURLFetcher::~AlternateNavURLFetcher() {} |
34 | 34 |
35 void AlternateNavURLFetcher::Observe(NotificationType type, | 35 void AlternateNavURLFetcher::Observe(int type, |
36 const NotificationSource& source, | 36 const NotificationSource& source, |
37 const NotificationDetails& details) { | 37 const NotificationDetails& details) { |
38 switch (type.value) { | 38 switch (type) { |
39 case NotificationType::NAV_ENTRY_PENDING: | 39 case content::NOTIFICATION_NAV_ENTRY_PENDING: |
40 // If we've already received a notification for the same controller, we | 40 // If we've already received a notification for the same controller, we |
41 // should delete ourselves as that indicates that the page is being | 41 // should delete ourselves as that indicates that the page is being |
42 // re-loaded so this instance is now stale. | 42 // re-loaded so this instance is now stale. |
43 // http://crbug.com/43378 | 43 // http://crbug.com/43378 |
44 if (!infobar_contents_ && | 44 if (!infobar_contents_ && |
45 controller_ == Source<NavigationController>(source).ptr()) { | 45 controller_ == Source<NavigationController>(source).ptr()) { |
46 delete this; | 46 delete this; |
47 } else if (!controller_) { | 47 } else if (!controller_) { |
48 controller_ = Source<NavigationController>(source).ptr(); | 48 controller_ = Source<NavigationController>(source).ptr(); |
49 DCHECK(controller_->pending_entry()); | 49 DCHECK(controller_->pending_entry()); |
50 | 50 |
51 // Start listening for the commit notification. We also need to listen | 51 // Start listening for the commit notification. We also need to listen |
52 // for the tab close command since that means the load will never | 52 // for the tab close command since that means the load will never |
53 // commit! | 53 // commit! |
54 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, | 54 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
55 Source<NavigationController>(controller_)); | 55 Source<NavigationController>(controller_)); |
56 registrar_.Add(this, NotificationType::TAB_CLOSED, | 56 registrar_.Add(this, content::NOTIFICATION_TAB_CLOSED, |
57 Source<NavigationController>(controller_)); | 57 Source<NavigationController>(controller_)); |
58 | 58 |
59 DCHECK_EQ(NOT_STARTED, state_); | 59 DCHECK_EQ(NOT_STARTED, state_); |
60 state_ = IN_PROGRESS; | 60 state_ = IN_PROGRESS; |
61 fetcher_.reset(new URLFetcher(GURL(alternate_nav_url_), | 61 fetcher_.reset(new URLFetcher(GURL(alternate_nav_url_), |
62 URLFetcher::HEAD, this)); | 62 URLFetcher::HEAD, this)); |
63 fetcher_->set_request_context( | 63 fetcher_->set_request_context( |
64 controller_->profile()->GetRequestContext()); | 64 controller_->profile()->GetRequestContext()); |
65 fetcher_->Start(); | 65 fetcher_->Start(); |
66 } | 66 } |
67 break; | 67 break; |
68 | 68 |
69 case NotificationType::NAV_ENTRY_COMMITTED: | 69 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: |
70 // The page was navigated, we can show the infobar now if necessary. | 70 // The page was navigated, we can show the infobar now if necessary. |
71 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED, | 71 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
72 Source<NavigationController>(controller_)); | 72 Source<NavigationController>(controller_)); |
73 navigated_to_entry_ = true; | 73 navigated_to_entry_ = true; |
74 ShowInfobarIfPossible(); | 74 ShowInfobarIfPossible(); |
75 break; | 75 break; |
76 | 76 |
77 case NotificationType::TAB_CLOSED: | 77 case content::NOTIFICATION_TAB_CLOSED: |
78 // We have been closed. In order to prevent the URLFetcher from trying to | 78 // We have been closed. In order to prevent the URLFetcher from trying to |
79 // access the controller that will be invalid, we delete ourselves. | 79 // access the controller that will be invalid, we delete ourselves. |
80 // This deletes the URLFetcher and insures its callback won't be called. | 80 // This deletes the URLFetcher and insures its callback won't be called. |
81 delete this; | 81 delete this; |
82 break; | 82 break; |
83 | 83 |
84 default: | 84 default: |
85 NOTREACHED(); | 85 NOTREACHED(); |
86 } | 86 } |
87 } | 87 } |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 if (state_ == FAILED) | 161 if (state_ == FAILED) |
162 delete this; | 162 delete this; |
163 return; | 163 return; |
164 } | 164 } |
165 | 165 |
166 infobar_contents_ = controller_->tab_contents(); | 166 infobar_contents_ = controller_->tab_contents(); |
167 StoreActiveEntryUniqueID(infobar_contents_); | 167 StoreActiveEntryUniqueID(infobar_contents_); |
168 TabContentsWrapper::GetCurrentWrapperForContents(infobar_contents_)-> | 168 TabContentsWrapper::GetCurrentWrapperForContents(infobar_contents_)-> |
169 AddInfoBar(this); | 169 AddInfoBar(this); |
170 } | 170 } |
OLD | NEW |