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 "content/browser/tab_contents/interstitial_page.h" | 5 #include "content/browser/tab_contents/interstitial_page.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 } | 197 } |
198 } | 198 } |
199 | 199 |
200 // Block the resource requests for the render view host while it is hidden. | 200 // Block the resource requests for the render view host while it is hidden. |
201 TakeActionOnResourceDispatcher(BLOCK); | 201 TakeActionOnResourceDispatcher(BLOCK); |
202 // We need to be notified when the RenderViewHost is destroyed so we can | 202 // We need to be notified when the RenderViewHost is destroyed so we can |
203 // cancel the blocked requests. We cannot do that on | 203 // cancel the blocked requests. We cannot do that on |
204 // NOTIFY_TAB_CONTENTS_DESTROYED as at that point the RenderViewHost has | 204 // NOTIFY_TAB_CONTENTS_DESTROYED as at that point the RenderViewHost has |
205 // already been destroyed. | 205 // already been destroyed. |
206 notification_registrar_.Add( | 206 notification_registrar_.Add( |
207 this, NotificationType::RENDER_WIDGET_HOST_DESTROYED, | 207 this, content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
208 Source<RenderWidgetHost>(tab_->render_view_host())); | 208 Source<RenderWidgetHost>(tab_->render_view_host())); |
209 | 209 |
210 // Update the tab_to_interstitial_page_ map. | 210 // Update the tab_to_interstitial_page_ map. |
211 iter = tab_to_interstitial_page_->find(tab_); | 211 iter = tab_to_interstitial_page_->find(tab_); |
212 DCHECK(iter == tab_to_interstitial_page_->end()); | 212 DCHECK(iter == tab_to_interstitial_page_->end()); |
213 (*tab_to_interstitial_page_)[tab_] = this; | 213 (*tab_to_interstitial_page_)[tab_] = this; |
214 | 214 |
215 if (new_navigation_) { | 215 if (new_navigation_) { |
216 NavigationEntry* entry = new NavigationEntry; | 216 NavigationEntry* entry = new NavigationEntry; |
217 entry->set_url(url_); | 217 entry->set_url(url_); |
218 entry->set_virtual_url(url_); | 218 entry->set_virtual_url(url_); |
219 entry->set_page_type(INTERSTITIAL_PAGE); | 219 entry->set_page_type(INTERSTITIAL_PAGE); |
220 | 220 |
221 // Give sub-classes a chance to set some states on the navigation entry. | 221 // Give sub-classes a chance to set some states on the navigation entry. |
222 UpdateEntry(entry); | 222 UpdateEntry(entry); |
223 | 223 |
224 tab_->controller().AddTransientEntry(entry); | 224 tab_->controller().AddTransientEntry(entry); |
225 } | 225 } |
226 | 226 |
227 DCHECK(!render_view_host_); | 227 DCHECK(!render_view_host_); |
228 render_view_host_ = CreateRenderViewHost(); | 228 render_view_host_ = CreateRenderViewHost(); |
229 CreateTabContentsView(); | 229 CreateTabContentsView(); |
230 | 230 |
231 std::string data_url = "data:text/html;charset=utf-8," + | 231 std::string data_url = "data:text/html;charset=utf-8," + |
232 EscapePath(GetHTMLContents()); | 232 EscapePath(GetHTMLContents()); |
233 render_view_host_->NavigateToURL(GURL(data_url)); | 233 render_view_host_->NavigateToURL(GURL(data_url)); |
234 | 234 |
235 notification_registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED, | 235 notification_registrar_.Add(this, |
| 236 content::NOTIFICATION_TAB_CONTENTS_DESTROYED, |
236 Source<TabContents>(tab_)); | 237 Source<TabContents>(tab_)); |
237 notification_registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, | 238 notification_registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
238 Source<NavigationController>(&tab_->controller())); | 239 Source<NavigationController>(&tab_->controller())); |
239 notification_registrar_.Add(this, NotificationType::NAV_ENTRY_PENDING, | 240 notification_registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING, |
240 Source<NavigationController>(&tab_->controller())); | 241 Source<NavigationController>(&tab_->controller())); |
241 } | 242 } |
242 | 243 |
243 void InterstitialPage::Hide() { | 244 void InterstitialPage::Hide() { |
244 RenderWidgetHostView* old_view = tab_->render_view_host()->view(); | 245 RenderWidgetHostView* old_view = tab_->render_view_host()->view(); |
245 if (tab_->interstitial_page() == this && old_view && !old_view->IsShowing()) { | 246 if (tab_->interstitial_page() == this && old_view && !old_view->IsShowing()) { |
246 // Show the original RVH since we're going away. Note it might not exist if | 247 // Show the original RVH since we're going away. Note it might not exist if |
247 // the renderer crashed while the interstitial was showing. | 248 // the renderer crashed while the interstitial was showing. |
248 // Note that it is important that we don't call Show() if the view is | 249 // Note that it is important that we don't call Show() if the view is |
249 // already showing. That would result in bad things (unparented HWND on | 250 // already showing. That would result in bad things (unparented HWND on |
(...skipping 14 matching lines...) Expand all Loading... |
264 tab_->remove_interstitial_page(); | 265 tab_->remove_interstitial_page(); |
265 // Let's revert to the original title if necessary. | 266 // Let's revert to the original title if necessary. |
266 NavigationEntry* entry = tab_->controller().GetActiveEntry(); | 267 NavigationEntry* entry = tab_->controller().GetActiveEntry(); |
267 if (!new_navigation_ && should_revert_tab_title_) { | 268 if (!new_navigation_ && should_revert_tab_title_) { |
268 entry->set_title(WideToUTF16Hack(original_tab_title_)); | 269 entry->set_title(WideToUTF16Hack(original_tab_title_)); |
269 tab_->NotifyNavigationStateChanged(TabContents::INVALIDATE_TITLE); | 270 tab_->NotifyNavigationStateChanged(TabContents::INVALIDATE_TITLE); |
270 } | 271 } |
271 delete this; | 272 delete this; |
272 } | 273 } |
273 | 274 |
274 void InterstitialPage::Observe(NotificationType type, | 275 void InterstitialPage::Observe(int type, |
275 const NotificationSource& source, | 276 const NotificationSource& source, |
276 const NotificationDetails& details) { | 277 const NotificationDetails& details) { |
277 switch (type.value) { | 278 switch (type) { |
278 case NotificationType::NAV_ENTRY_PENDING: | 279 case content::NOTIFICATION_NAV_ENTRY_PENDING: |
279 // We are navigating away from the interstitial (the user has typed a URL | 280 // We are navigating away from the interstitial (the user has typed a URL |
280 // in the location bar or clicked a bookmark). Make sure clicking on the | 281 // in the location bar or clicked a bookmark). Make sure clicking on the |
281 // interstitial will have no effect. Also cancel any blocked requests | 282 // interstitial will have no effect. Also cancel any blocked requests |
282 // on the ResourceDispatcherHost. Note that when we get this notification | 283 // on the ResourceDispatcherHost. Note that when we get this notification |
283 // the RenderViewHost has not yet navigated so we'll unblock the | 284 // the RenderViewHost has not yet navigated so we'll unblock the |
284 // RenderViewHost before the resource request for the new page we are | 285 // RenderViewHost before the resource request for the new page we are |
285 // navigating arrives in the ResourceDispatcherHost. This ensures that | 286 // navigating arrives in the ResourceDispatcherHost. This ensures that |
286 // request won't be blocked if the same RenderViewHost was used for the | 287 // request won't be blocked if the same RenderViewHost was used for the |
287 // new navigation. | 288 // new navigation. |
288 Disable(); | 289 Disable(); |
289 TakeActionOnResourceDispatcher(CANCEL); | 290 TakeActionOnResourceDispatcher(CANCEL); |
290 break; | 291 break; |
291 case NotificationType::RENDER_WIDGET_HOST_DESTROYED: | 292 case content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: |
292 if (action_taken_ == NO_ACTION) { | 293 if (action_taken_ == NO_ACTION) { |
293 // The RenderViewHost is being destroyed (as part of the tab being | 294 // The RenderViewHost is being destroyed (as part of the tab being |
294 // closed), make sure we clear the blocked requests. | 295 // closed), make sure we clear the blocked requests. |
295 RenderViewHost* rvh = Source<RenderViewHost>(source).ptr(); | 296 RenderViewHost* rvh = Source<RenderViewHost>(source).ptr(); |
296 DCHECK(rvh->process()->id() == original_child_id_ && | 297 DCHECK(rvh->process()->id() == original_child_id_ && |
297 rvh->routing_id() == original_rvh_id_); | 298 rvh->routing_id() == original_rvh_id_); |
298 TakeActionOnResourceDispatcher(CANCEL); | 299 TakeActionOnResourceDispatcher(CANCEL); |
299 } | 300 } |
300 break; | 301 break; |
301 case NotificationType::TAB_CONTENTS_DESTROYED: | 302 case content::NOTIFICATION_TAB_CONTENTS_DESTROYED: |
302 case NotificationType::NAV_ENTRY_COMMITTED: | 303 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: |
303 if (action_taken_ == NO_ACTION) { | 304 if (action_taken_ == NO_ACTION) { |
304 // We are navigating away from the interstitial or closing a tab with an | 305 // We are navigating away from the interstitial or closing a tab with an |
305 // interstitial. Default to DontProceed(). We don't just call Hide as | 306 // interstitial. Default to DontProceed(). We don't just call Hide as |
306 // subclasses will almost certainly override DontProceed to do some work | 307 // subclasses will almost certainly override DontProceed to do some work |
307 // (ex: close pending connections). | 308 // (ex: close pending connections). |
308 DontProceed(); | 309 DontProceed(); |
309 } else { | 310 } else { |
310 // User decided to proceed and either the navigation was committed or | 311 // User decided to proceed and either the navigation was committed or |
311 // the tab was closed before that. | 312 // the tab was closed before that. |
312 Hide(); | 313 Hide(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 | 352 |
352 // The RenderViewHost has loaded its contents, we can show it now. | 353 // The RenderViewHost has loaded its contents, we can show it now. |
353 render_view_host_->view()->Show(); | 354 render_view_host_->view()->Show(); |
354 tab_->set_interstitial_page(this); | 355 tab_->set_interstitial_page(this); |
355 | 356 |
356 // This notification hides the bookmark bar. Note that this has to happen | 357 // This notification hides the bookmark bar. Note that this has to happen |
357 // after the interstitial page was registered with |tab_|, since there will be | 358 // after the interstitial page was registered with |tab_|, since there will be |
358 // a callback to |tab_| testing if an interstitial page is showing before | 359 // a callback to |tab_| testing if an interstitial page is showing before |
359 // hiding the bookmark bar. | 360 // hiding the bookmark bar. |
360 NotificationService::current()->Notify( | 361 NotificationService::current()->Notify( |
361 NotificationType::INTERSTITIAL_ATTACHED, | 362 content::NOTIFICATION_INTERSTITIAL_ATTACHED, |
362 Source<TabContents>(tab_), | 363 Source<TabContents>(tab_), |
363 NotificationService::NoDetails()); | 364 NotificationService::NoDetails()); |
364 | 365 |
365 RenderWidgetHostView* rwh_view = tab_->render_view_host()->view(); | 366 RenderWidgetHostView* rwh_view = tab_->render_view_host()->view(); |
366 | 367 |
367 // The RenderViewHost may already have crashed before we even get here. | 368 // The RenderViewHost may already have crashed before we even get here. |
368 if (rwh_view) { | 369 if (rwh_view) { |
369 // If the page has focus, focus the interstitial. | 370 // If the page has focus, focus the interstitial. |
370 if (rwh_view->HasFocus()) | 371 if (rwh_view->HasFocus()) |
371 Focus(); | 372 Focus(); |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 | 725 |
725 void InterstitialPage::UpdateInspectorSetting(const std::string& key, | 726 void InterstitialPage::UpdateInspectorSetting(const std::string& key, |
726 const std::string& value) { | 727 const std::string& value) { |
727 RenderViewHostDelegateHelper::UpdateInspectorSetting( | 728 RenderViewHostDelegateHelper::UpdateInspectorSetting( |
728 tab_->profile(), key, value); | 729 tab_->profile(), key, value); |
729 } | 730 } |
730 | 731 |
731 void InterstitialPage::ClearInspectorSettings() { | 732 void InterstitialPage::ClearInspectorSettings() { |
732 RenderViewHostDelegateHelper::ClearInspectorSettings(tab_->profile()); | 733 RenderViewHostDelegateHelper::ClearInspectorSettings(tab_->profile()); |
733 } | 734 } |
OLD | NEW |