Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/intranet_redirect_detector.h" | 10 #include "chrome/browser/intranet_redirect_detector.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 infobar_contents_(NULL) { | 28 infobar_contents_(NULL) { |
| 29 registrar_.Add(this, NotificationType::NAV_ENTRY_PENDING, | 29 registrar_.Add(this, NotificationType::NAV_ENTRY_PENDING, |
| 30 NotificationService::AllSources()); | 30 NotificationService::AllSources()); |
| 31 } | 31 } |
| 32 | 32 |
| 33 void AlternateNavURLFetcher::Observe(NotificationType type, | 33 void AlternateNavURLFetcher::Observe(NotificationType type, |
| 34 const NotificationSource& source, | 34 const NotificationSource& source, |
| 35 const NotificationDetails& details) { | 35 const NotificationDetails& details) { |
| 36 switch (type.value) { | 36 switch (type.value) { |
| 37 case NotificationType::NAV_ENTRY_PENDING: | 37 case NotificationType::NAV_ENTRY_PENDING: |
| 38 controller_ = Source<NavigationController>(source).ptr(); | 38 // If we've already received a notification for the same controller, we |
| 39 DCHECK(controller_->pending_entry()); | 39 // should delete ourselves as that indicates that the page is being |
| 40 // re-loaded so this instance is now stale. | |
| 41 // http://crbug.com/43378 | |
| 42 if (!infobar_contents_ && | |
| 43 controller_ == Source<NavigationController>(source).ptr()) { | |
| 44 delete this; | |
| 45 } else if (!controller_) { | |
|
Evan Stade
2010/06/09 19:46:11
can the hypothetical else be reached (where contro
csilv
2010/06/09 20:09:22
Yes, that can happen if some other tab sends a NAV
| |
| 46 controller_ = Source<NavigationController>(source).ptr(); | |
| 47 DCHECK(controller_->pending_entry()); | |
| 40 | 48 |
| 41 // Unregister for this notification now that we're pending, and start | 49 // Start listening for the commit notification. We also need to listen |
| 42 // listening for the corresponding commit. We also need to listen for the | 50 // for the tab close command since that means the load will never |
| 43 // tab close command since that means the load will never commit! | 51 // commit! |
| 44 registrar_.Remove(this, NotificationType::NAV_ENTRY_PENDING, | 52 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, |
| 45 NotificationService::AllSources()); | 53 Source<NavigationController>(controller_)); |
| 46 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, | 54 registrar_.Add(this, NotificationType::TAB_CLOSED, |
| 47 Source<NavigationController>(controller_)); | 55 Source<NavigationController>(controller_)); |
| 48 registrar_.Add(this, NotificationType::TAB_CLOSED, | |
| 49 Source<NavigationController>(controller_)); | |
| 50 | 56 |
| 51 DCHECK_EQ(NOT_STARTED, state_); | 57 DCHECK_EQ(NOT_STARTED, state_); |
| 52 state_ = IN_PROGRESS; | 58 state_ = IN_PROGRESS; |
| 53 fetcher_.reset(new URLFetcher(GURL(alternate_nav_url_), URLFetcher::HEAD, | 59 fetcher_.reset(new URLFetcher(GURL(alternate_nav_url_), |
| 54 this)); | 60 URLFetcher::HEAD, this)); |
| 55 fetcher_->set_request_context( | 61 fetcher_->set_request_context( |
| 56 controller_->profile()->GetRequestContext()); | 62 controller_->profile()->GetRequestContext()); |
| 57 fetcher_->Start(); | 63 fetcher_->Start(); |
| 64 } | |
| 58 break; | 65 break; |
| 59 | 66 |
| 60 case NotificationType::NAV_ENTRY_COMMITTED: | 67 case NotificationType::NAV_ENTRY_COMMITTED: |
| 61 // The page was navigated, we can show the infobar now if necessary. | 68 // The page was navigated, we can show the infobar now if necessary. |
| 62 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED, | 69 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED, |
| 63 Source<NavigationController>(controller_)); | 70 Source<NavigationController>(controller_)); |
| 64 navigated_to_entry_ = true; | 71 navigated_to_entry_ = true; |
| 65 ShowInfobarIfPossible(); | 72 ShowInfobarIfPossible(); |
| 66 break; | 73 break; |
| 67 | 74 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 168 if (state_ == FAILED) | 175 if (state_ == FAILED) |
| 169 delete this; | 176 delete this; |
| 170 return; | 177 return; |
| 171 } | 178 } |
| 172 | 179 |
| 173 infobar_contents_ = controller_->tab_contents(); | 180 infobar_contents_ = controller_->tab_contents(); |
| 174 StoreActiveEntryUniqueID(infobar_contents_); | 181 StoreActiveEntryUniqueID(infobar_contents_); |
| 175 // We will be deleted when the InfoBar is destroyed. (See InfoBarClosed). | 182 // We will be deleted when the InfoBar is destroyed. (See InfoBarClosed). |
| 176 infobar_contents_->AddInfoBar(this); | 183 infobar_contents_->AddInfoBar(this); |
| 177 } | 184 } |
| OLD | NEW |