OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/ssl_blocking_page.h" | 5 #include "chrome/browser/ssl_blocking_page.h" |
6 | 6 |
7 #include "base/string_piece.h" | 7 #include "base/string_piece.h" |
8 #include "chrome/browser/browser.h" | 8 #include "chrome/browser/browser.h" |
9 #include "chrome/browser/browser_resources.h" | 9 #include "chrome/browser/browser_resources.h" |
10 #include "chrome/browser/cert_store.h" | 10 #include "chrome/browser/cert_store.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 // If there's already an interstitial in this tab, then we're about to | 44 // If there's already an interstitial in this tab, then we're about to |
45 // replace it. We should be ok with just deleting the previous | 45 // replace it. We should be ok with just deleting the previous |
46 // SSLBlockingPage (not hiding it first), since we're about to be shown. | 46 // SSLBlockingPage (not hiding it first), since we're about to be shown. |
47 SSLBlockingPageMap::const_iterator iter = tab_to_blocking_page_->find(tab_); | 47 SSLBlockingPageMap::const_iterator iter = tab_to_blocking_page_->find(tab_); |
48 if (iter != tab_to_blocking_page_->end()) { | 48 if (iter != tab_to_blocking_page_->end()) { |
49 // Deleting the SSLBlockingPage will also remove it from the map. | 49 // Deleting the SSLBlockingPage will also remove it from the map. |
50 delete iter->second; | 50 delete iter->second; |
51 | 51 |
52 // Since WebContents::InterstitialPageGone won't be called, we need | 52 // Since WebContents::InterstitialPageGone won't be called, we need |
53 // to clear the last NavigationEntry manually. | 53 // to clear the last NavigationEntry manually. |
54 tab_->controller()->RemoveLastEntry(); | 54 tab_->controller()->RemoveLastEntryForInterstitial(); |
55 } | 55 } |
56 (*tab_to_blocking_page_)[tab_] = this; | 56 (*tab_to_blocking_page_)[tab_] = this; |
57 | 57 |
58 // Register notifications so we can delete ourself if the tab is closed. | 58 // Register notifications so we can delete ourself if the tab is closed. |
59 NotificationService::current()->AddObserver(this, | 59 NotificationService::current()->AddObserver(this, |
60 NOTIFY_TAB_CLOSING, | 60 NOTIFY_TAB_CLOSING, |
61 Source<NavigationController>(tab_->controller())); | 61 Source<NavigationController>(tab_->controller())); |
62 | 62 |
63 NotificationService::current()->AddObserver(this, | 63 NotificationService::current()->AddObserver(this, |
64 NOTIFY_INTERSTITIAL_PAGE_CLOSED, | 64 NOTIFY_INTERSTITIAL_PAGE_CLOSED, |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 std::string html_text(jstemplate_builder::GetTemplateHtml(html, | 125 std::string html_text(jstemplate_builder::GetTemplateHtml(html, |
126 &strings, | 126 &strings, |
127 "template_root")); | 127 "template_root")); |
128 | 128 |
129 DCHECK(tab_->type() == TAB_CONTENTS_WEB); | 129 DCHECK(tab_->type() == TAB_CONTENTS_WEB); |
130 WebContents* tab = tab_->AsWebContents(); | 130 WebContents* tab = tab_->AsWebContents(); |
131 const net::SSLInfo& ssl_info = error_->ssl_info(); | 131 const net::SSLInfo& ssl_info = error_->ssl_info(); |
132 int cert_id = CertStore::GetSharedInstance()->StoreCert( | 132 int cert_id = CertStore::GetSharedInstance()->StoreCert( |
133 ssl_info.cert, tab->render_view_host()->process()->host_id()); | 133 ssl_info.cert, tab->render_view_host()->process()->host_id()); |
134 | 134 |
135 NavigationEntry* nav_entry = new NavigationEntry(TAB_CONTENTS_WEB); | |
136 if (tab_->controller()->GetPendingEntryIndex() == -1) { | 135 if (tab_->controller()->GetPendingEntryIndex() == -1) { |
137 // New navigation. | 136 // For new navigations, we just create a new navigation entry. |
138 // We set the page ID to max page id so to ensure the controller considers | 137 NavigationEntry new_entry(TAB_CONTENTS_WEB); |
139 // this dummy entry a new one. Because we'll remove the entry when the | 138 new_entry.set_url(error_->request_url()); |
140 // interstitial is going away, it will not conflict with any future | 139 tab_->controller()->AddDummyEntryForInterstitial(new_entry); |
141 // navigations. | |
142 created_nav_entry_ = true; | 140 created_nav_entry_ = true; |
143 nav_entry->set_page_id(tab_->GetMaxPageID() + 1); | |
144 nav_entry->set_url(error_->request_url()); | |
145 } else { | 141 } else { |
146 // Make sure to update the current entry ssl state to reflect the error. | 142 // When there is a pending entry index, that means we're doing a |
147 *nav_entry = *(tab_->controller()->GetPendingEntry()); | 143 // back/forward navigation. Clone that entry instead. |
| 144 tab_->controller()->AddDummyEntryForInterstitial( |
| 145 *tab_->controller()->GetPendingEntry()); |
148 } | 146 } |
149 nav_entry->set_page_type(NavigationEntry::INTERSTITIAL_PAGE); | |
150 | 147 |
151 nav_entry->ssl().set_security_style(SECURITY_STYLE_AUTHENTICATION_BROKEN); | 148 NavigationEntry* entry = tab_->controller()->GetActiveEntry(); |
152 nav_entry->ssl().set_cert_id(cert_id); | 149 entry->set_page_type(NavigationEntry::INTERSTITIAL_PAGE); |
153 nav_entry->ssl().set_cert_status(ssl_info.cert_status); | |
154 nav_entry->ssl().set_security_bits(ssl_info.security_bits); | |
155 // The controller will own the entry. | |
156 | 150 |
157 // The default details is "new navigation", and that's OK with us. | 151 entry->ssl().set_security_style(SECURITY_STYLE_AUTHENTICATION_BROKEN); |
158 NavigationController::LoadCommittedDetails details; | 152 entry->ssl().set_cert_id(cert_id); |
159 tab_->controller()->DidNavigateToEntry(nav_entry, &details); | 153 entry->ssl().set_cert_status(ssl_info.cert_status); |
| 154 entry->ssl().set_security_bits(ssl_info.security_bits); |
| 155 NotificationService::current()->Notify( |
| 156 NOTIFY_SSL_STATE_CHANGED, |
| 157 Source<NavigationController>(tab_->controller()), |
| 158 NotificationService::NoDetails()); |
| 159 |
160 tab->ShowInterstitialPage(html_text, NULL); | 160 tab->ShowInterstitialPage(html_text, NULL); |
161 } | 161 } |
162 | 162 |
163 void SSLBlockingPage::Observe(NotificationType type, | 163 void SSLBlockingPage::Observe(NotificationType type, |
164 const NotificationSource& source, | 164 const NotificationSource& source, |
165 const NotificationDetails& details) { | 165 const NotificationDetails& details) { |
166 switch (type) { | 166 switch (type) { |
167 case NOTIFY_TAB_CLOSING: | 167 case NOTIFY_TAB_CLOSING: |
168 case NOTIFY_INTERSTITIAL_PAGE_CLOSED: { | 168 case NOTIFY_INTERSTITIAL_PAGE_CLOSED: { |
169 // We created a navigation entry for the interstitial, remove it. | 169 // We created a navigation entry for the interstitial, remove it. |
170 // Note that we don't remove the entry if we are closing all tabs so that | 170 // Note that we don't remove the entry if we are closing all tabs so that |
171 // the last entry is kept for the restoring on next start-up. | 171 // the last entry is kept for the restoring on next start-up. |
172 Browser* browser = Browser::GetBrowserForController(tab_->controller(), | 172 Browser* browser = Browser::GetBrowserForController(tab_->controller(), |
173 NULL); | 173 NULL); |
174 if (remove_last_entry_ && | 174 if (remove_last_entry_ && |
175 !browser->tabstrip_model()->closing_all()) { | 175 !browser->tabstrip_model()->closing_all()) { |
176 tab_->controller()->RemoveLastEntry(); | 176 tab_->controller()->RemoveLastEntryForInterstitial(); |
177 } | 177 } |
178 delete this; | 178 delete this; |
179 break; | 179 break; |
180 } | 180 } |
181 case NOTIFY_DOM_OPERATION_RESPONSE: { | 181 case NOTIFY_DOM_OPERATION_RESPONSE: { |
182 std::string json = | 182 std::string json = |
183 Details<DomOperationNotificationDetails>(details)->json(); | 183 Details<DomOperationNotificationDetails>(details)->json(); |
184 if (json == "1") { | 184 if (json == "1") { |
185 Proceed(); | 185 Proceed(); |
186 } else { | 186 } else { |
(...skipping 23 matching lines...) Expand all Loading... |
210 // entry on navigation since the page id is less than max page id. | 210 // entry on navigation since the page id is less than max page id. |
211 if (!created_nav_entry_) | 211 if (!created_nav_entry_) |
212 remove_last_entry_ = false; | 212 remove_last_entry_ = false; |
213 } | 213 } |
214 | 214 |
215 void SSLBlockingPage::DontProceed() { | 215 void SSLBlockingPage::DontProceed() { |
216 NotifyDenyCertificate(); | 216 NotifyDenyCertificate(); |
217 | 217 |
218 // We are navigating, remove the current entry before we mess with it. | 218 // We are navigating, remove the current entry before we mess with it. |
219 remove_last_entry_ = false; | 219 remove_last_entry_ = false; |
220 tab_->controller()->RemoveLastEntry(); | 220 tab_->controller()->RemoveLastEntryForInterstitial(); |
221 | 221 |
222 NavigationEntry* entry = tab_->controller()->GetActiveEntry(); | 222 NavigationEntry* entry = tab_->controller()->GetActiveEntry(); |
223 if (!entry) { | 223 if (!entry) { |
224 // Nothing to go to, default to about:blank. Navigating will cause the | 224 // Nothing to go to, default to about:blank. Navigating will cause the |
225 // interstitial to hide which will trigger "this" to be deleted. | 225 // interstitial to hide which will trigger "this" to be deleted. |
226 tab_->controller()->LoadURL(GURL("about:blank"), | 226 tab_->controller()->LoadURL(GURL("about:blank"), |
227 PageTransition::AUTO_BOOKMARK); | 227 PageTransition::AUTO_BOOKMARK); |
228 } else if (entry->tab_type() != TAB_CONTENTS_WEB) { | 228 } else if (entry->tab_type() != TAB_CONTENTS_WEB) { |
229 // Not a WebContent, reload it so to recreate the TabContents for it. | 229 // Not a WebContent, reload it so to recreate the TabContents for it. |
230 tab_->controller()->Reload(); | 230 tab_->controller()->Reload(); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 }; | 283 }; |
284 int i; | 284 int i; |
285 for (i = 0; i < static_cast<int>(extra_info.size()); i++) { | 285 for (i = 0; i < static_cast<int>(extra_info.size()); i++) { |
286 strings->SetString(keys[i], extra_info[i]); | 286 strings->SetString(keys[i], extra_info[i]); |
287 } | 287 } |
288 for (;i < 5; i++) { | 288 for (;i < 5; i++) { |
289 strings->SetString(keys[i], L""); | 289 strings->SetString(keys[i], L""); |
290 } | 290 } |
291 } | 291 } |
292 | 292 |
OLD | NEW |