| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/web_contents/interstitial_page_impl.h" | 5 #include "content/browser/web_contents/interstitial_page_impl.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "content/public/browser/invalidate_type.h" | 32 #include "content/public/browser/invalidate_type.h" |
| 33 #include "content/public/browser/notification_service.h" | 33 #include "content/public/browser/notification_service.h" |
| 34 #include "content/public/browser/notification_source.h" | 34 #include "content/public/browser/notification_source.h" |
| 35 #include "content/public/browser/storage_partition.h" | 35 #include "content/public/browser/storage_partition.h" |
| 36 #include "content/public/browser/web_contents_view.h" | 36 #include "content/public/browser/web_contents_view.h" |
| 37 #include "content/public/common/bindings_policy.h" | 37 #include "content/public/common/bindings_policy.h" |
| 38 #include "content/public/common/page_transition_types.h" | 38 #include "content/public/common/page_transition_types.h" |
| 39 #include "net/base/escape.h" | 39 #include "net/base/escape.h" |
| 40 #include "net/url_request/url_request_context_getter.h" | 40 #include "net/url_request/url_request_context_getter.h" |
| 41 | 41 |
| 42 using content::BrowserThread; | |
| 43 using content::DomOperationNotificationDetails; | |
| 44 using content::InterstitialPageDelegate; | |
| 45 using content::NativeWebKeyboardEvent; | |
| 46 using content::NavigationController; | |
| 47 using content::NavigationEntry; | |
| 48 using content::NavigationEntryImpl; | |
| 49 using content::RenderViewHost; | |
| 50 using content::RenderViewHostImpl; | |
| 51 using content::RenderViewHostDelegate; | |
| 52 using content::RenderViewHostDelegateView; | |
| 53 using content::RenderWidgetHost; | |
| 54 using content::RenderWidgetHostImpl; | |
| 55 using content::RenderWidgetHostView; | |
| 56 using content::RenderWidgetHostViewPort; | |
| 57 using content::ResourceDispatcherHostImpl; | |
| 58 using content::SessionStorageNamespace; | |
| 59 using content::SiteInstance; | |
| 60 using content::WebContents; | |
| 61 using content::WebContentsView; | |
| 62 using WebKit::WebDragOperation; | 42 using WebKit::WebDragOperation; |
| 63 using WebKit::WebDragOperationsMask; | 43 using WebKit::WebDragOperationsMask; |
| 64 | 44 |
| 45 namespace content { |
| 65 namespace { | 46 namespace { |
| 66 | 47 |
| 67 void ResourceRequestHelper(ResourceDispatcherHostImpl* rdh, | 48 void ResourceRequestHelper(ResourceDispatcherHostImpl* rdh, |
| 68 int process_id, | 49 int process_id, |
| 69 int render_view_host_id, | 50 int render_view_host_id, |
| 70 ResourceRequestAction action) { | 51 ResourceRequestAction action) { |
| 71 switch (action) { | 52 switch (action) { |
| 72 case BLOCK: | 53 case BLOCK: |
| 73 rdh->BlockRequestsForRoute(process_id, render_view_host_id); | 54 rdh->BlockRequestsForRoute(process_id, render_view_host_id); |
| 74 break; | 55 break; |
| 75 case RESUME: | 56 case RESUME: |
| 76 rdh->ResumeBlockedRequestsForRoute(process_id, render_view_host_id); | 57 rdh->ResumeBlockedRequestsForRoute(process_id, render_view_host_id); |
| 77 break; | 58 break; |
| 78 case CANCEL: | 59 case CANCEL: |
| 79 rdh->CancelBlockedRequestsForRoute(process_id, render_view_host_id); | 60 rdh->CancelBlockedRequestsForRoute(process_id, render_view_host_id); |
| 80 break; | 61 break; |
| 81 default: | 62 default: |
| 82 NOTREACHED(); | 63 NOTREACHED(); |
| 83 } | 64 } |
| 84 } | 65 } |
| 85 | 66 |
| 86 } // namespace | 67 } // namespace |
| 87 | 68 |
| 88 class InterstitialPageImpl::InterstitialPageRVHDelegateView | 69 class InterstitialPageImpl::InterstitialPageRVHDelegateView |
| 89 : public content::RenderViewHostDelegateView { | 70 : public RenderViewHostDelegateView { |
| 90 public: | 71 public: |
| 91 explicit InterstitialPageRVHDelegateView(InterstitialPageImpl* page); | 72 explicit InterstitialPageRVHDelegateView(InterstitialPageImpl* page); |
| 92 | 73 |
| 93 // RenderViewHostDelegateView implementation: | 74 // RenderViewHostDelegateView implementation: |
| 94 virtual void ShowPopupMenu(const gfx::Rect& bounds, | 75 virtual void ShowPopupMenu(const gfx::Rect& bounds, |
| 95 int item_height, | 76 int item_height, |
| 96 double item_font_size, | 77 double item_font_size, |
| 97 int selected_item, | 78 int selected_item, |
| 98 const std::vector<WebMenuItem>& items, | 79 const std::vector<WebMenuItem>& items, |
| 99 bool right_aligned, | 80 bool right_aligned, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 123 typedef std::map<WebContents*, InterstitialPageImpl*> InterstitialPageMap; | 104 typedef std::map<WebContents*, InterstitialPageImpl*> InterstitialPageMap; |
| 124 static InterstitialPageMap* g_web_contents_to_interstitial_page; | 105 static InterstitialPageMap* g_web_contents_to_interstitial_page; |
| 125 | 106 |
| 126 // Initializes g_web_contents_to_interstitial_page in a thread-safe manner. | 107 // Initializes g_web_contents_to_interstitial_page in a thread-safe manner. |
| 127 // Should be called before accessing g_web_contents_to_interstitial_page. | 108 // Should be called before accessing g_web_contents_to_interstitial_page. |
| 128 static void InitInterstitialPageMap() { | 109 static void InitInterstitialPageMap() { |
| 129 if (!g_web_contents_to_interstitial_page) | 110 if (!g_web_contents_to_interstitial_page) |
| 130 g_web_contents_to_interstitial_page = new InterstitialPageMap; | 111 g_web_contents_to_interstitial_page = new InterstitialPageMap; |
| 131 } | 112 } |
| 132 | 113 |
| 133 namespace content { | |
| 134 | |
| 135 InterstitialPage* InterstitialPage::Create(WebContents* web_contents, | 114 InterstitialPage* InterstitialPage::Create(WebContents* web_contents, |
| 136 bool new_navigation, | 115 bool new_navigation, |
| 137 const GURL& url, | 116 const GURL& url, |
| 138 InterstitialPageDelegate* delegate) { | 117 InterstitialPageDelegate* delegate) { |
| 139 return new InterstitialPageImpl(web_contents, new_navigation, url, delegate); | 118 return new InterstitialPageImpl(web_contents, new_navigation, url, delegate); |
| 140 } | 119 } |
| 141 | 120 |
| 142 InterstitialPage* InterstitialPage::GetInterstitialPage( | 121 InterstitialPage* InterstitialPage::GetInterstitialPage( |
| 143 WebContents* web_contents) { | 122 WebContents* web_contents) { |
| 144 InitInterstitialPageMap(); | 123 InitInterstitialPageMap(); |
| 145 InterstitialPageMap::const_iterator iter = | 124 InterstitialPageMap::const_iterator iter = |
| 146 g_web_contents_to_interstitial_page->find(web_contents); | 125 g_web_contents_to_interstitial_page->find(web_contents); |
| 147 if (iter == g_web_contents_to_interstitial_page->end()) | 126 if (iter == g_web_contents_to_interstitial_page->end()) |
| 148 return NULL; | 127 return NULL; |
| 149 | 128 |
| 150 return iter->second; | 129 return iter->second; |
| 151 } | 130 } |
| 152 | 131 |
| 153 } // namespace content | |
| 154 | |
| 155 InterstitialPageImpl::InterstitialPageImpl(WebContents* web_contents, | 132 InterstitialPageImpl::InterstitialPageImpl(WebContents* web_contents, |
| 156 bool new_navigation, | 133 bool new_navigation, |
| 157 const GURL& url, | 134 const GURL& url, |
| 158 InterstitialPageDelegate* delegate) | 135 InterstitialPageDelegate* delegate) |
| 159 : web_contents_(static_cast<WebContentsImpl*>(web_contents)), | 136 : web_contents_(static_cast<WebContentsImpl*>(web_contents)), |
| 160 url_(url), | 137 url_(url), |
| 161 new_navigation_(new_navigation), | 138 new_navigation_(new_navigation), |
| 162 should_discard_pending_nav_entry_(new_navigation), | 139 should_discard_pending_nav_entry_(new_navigation), |
| 163 reload_on_dont_proceed_(false), | 140 reload_on_dont_proceed_(false), |
| 164 enabled_(true), | 141 enabled_(true), |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 } | 185 } |
| 209 } | 186 } |
| 210 | 187 |
| 211 // Block the resource requests for the render view host while it is hidden. | 188 // Block the resource requests for the render view host while it is hidden. |
| 212 TakeActionOnResourceDispatcher(BLOCK); | 189 TakeActionOnResourceDispatcher(BLOCK); |
| 213 // We need to be notified when the RenderViewHost is destroyed so we can | 190 // We need to be notified when the RenderViewHost is destroyed so we can |
| 214 // cancel the blocked requests. We cannot do that on | 191 // cancel the blocked requests. We cannot do that on |
| 215 // NOTIFY_WEB_CONTENTS_DESTROYED as at that point the RenderViewHost has | 192 // NOTIFY_WEB_CONTENTS_DESTROYED as at that point the RenderViewHost has |
| 216 // already been destroyed. | 193 // already been destroyed. |
| 217 notification_registrar_.Add( | 194 notification_registrar_.Add( |
| 218 this, content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, | 195 this, NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
| 219 content::Source<RenderWidgetHost>(web_contents_->GetRenderViewHost())); | 196 Source<RenderWidgetHost>(web_contents_->GetRenderViewHost())); |
| 220 | 197 |
| 221 // Update the g_web_contents_to_interstitial_page map. | 198 // Update the g_web_contents_to_interstitial_page map. |
| 222 iter = g_web_contents_to_interstitial_page->find(web_contents_); | 199 iter = g_web_contents_to_interstitial_page->find(web_contents_); |
| 223 DCHECK(iter == g_web_contents_to_interstitial_page->end()); | 200 DCHECK(iter == g_web_contents_to_interstitial_page->end()); |
| 224 (*g_web_contents_to_interstitial_page)[web_contents_] = this; | 201 (*g_web_contents_to_interstitial_page)[web_contents_] = this; |
| 225 | 202 |
| 226 if (new_navigation_) { | 203 if (new_navigation_) { |
| 227 NavigationEntryImpl* entry = new NavigationEntryImpl; | 204 NavigationEntryImpl* entry = new NavigationEntryImpl; |
| 228 entry->SetURL(url_); | 205 entry->SetURL(url_); |
| 229 entry->SetVirtualURL(url_); | 206 entry->SetVirtualURL(url_); |
| 230 entry->set_page_type(content::PAGE_TYPE_INTERSTITIAL); | 207 entry->set_page_type(PAGE_TYPE_INTERSTITIAL); |
| 231 | 208 |
| 232 // Give delegates a chance to set some states on the navigation entry. | 209 // Give delegates a chance to set some states on the navigation entry. |
| 233 delegate_->OverrideEntry(entry); | 210 delegate_->OverrideEntry(entry); |
| 234 | 211 |
| 235 web_contents_->GetController().AddTransientEntry(entry); | 212 web_contents_->GetController().AddTransientEntry(entry); |
| 236 } | 213 } |
| 237 | 214 |
| 238 DCHECK(!render_view_host_); | 215 DCHECK(!render_view_host_); |
| 239 render_view_host_ = static_cast<RenderViewHostImpl*>(CreateRenderViewHost()); | 216 render_view_host_ = static_cast<RenderViewHostImpl*>(CreateRenderViewHost()); |
| 240 CreateWebContentsView(); | 217 CreateWebContentsView(); |
| 241 | 218 |
| 242 std::string data_url = "data:text/html;charset=utf-8," + | 219 std::string data_url = "data:text/html;charset=utf-8," + |
| 243 net::EscapePath(delegate_->GetHTMLContents()); | 220 net::EscapePath(delegate_->GetHTMLContents()); |
| 244 render_view_host_->NavigateToURL(GURL(data_url)); | 221 render_view_host_->NavigateToURL(GURL(data_url)); |
| 245 | 222 |
| 246 notification_registrar_.Add(this, | 223 notification_registrar_.Add(this, |
| 247 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 224 NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 248 content::Source<WebContents>(web_contents_)); | 225 Source<WebContents>(web_contents_)); |
| 249 notification_registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 226 notification_registrar_.Add(this, NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 250 content::Source<NavigationController>(&web_contents_->GetController())); | 227 Source<NavigationController>(&web_contents_->GetController())); |
| 251 notification_registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING, | 228 notification_registrar_.Add(this, NOTIFICATION_NAV_ENTRY_PENDING, |
| 252 content::Source<NavigationController>(&web_contents_->GetController())); | 229 Source<NavigationController>(&web_contents_->GetController())); |
| 253 notification_registrar_.Add( | 230 notification_registrar_.Add( |
| 254 this, content::NOTIFICATION_DOM_OPERATION_RESPONSE, | 231 this, NOTIFICATION_DOM_OPERATION_RESPONSE, |
| 255 content::Source<RenderViewHost>(render_view_host_)); | 232 Source<RenderViewHost>(render_view_host_)); |
| 256 } | 233 } |
| 257 | 234 |
| 258 void InterstitialPageImpl::Hide() { | 235 void InterstitialPageImpl::Hide() { |
| 259 RenderWidgetHostView* old_view = | 236 RenderWidgetHostView* old_view = |
| 260 web_contents_->GetRenderViewHost()->GetView(); | 237 web_contents_->GetRenderViewHost()->GetView(); |
| 261 if (web_contents_->GetInterstitialPage() == this && | 238 if (web_contents_->GetInterstitialPage() == this && |
| 262 old_view && !old_view->IsShowing()) { | 239 old_view && !old_view->IsShowing()) { |
| 263 // Show the original RVH since we're going away. Note it might not exist if | 240 // Show the original RVH since we're going away. Note it might not exist if |
| 264 // the renderer crashed while the interstitial was showing. | 241 // the renderer crashed while the interstitial was showing. |
| 265 // Note that it is important that we don't call Show() if the view is | 242 // Note that it is important that we don't call Show() if the view is |
| (...skipping 12 matching lines...) Expand all Loading... |
| 278 } | 255 } |
| 279 | 256 |
| 280 render_view_host_->Shutdown(); | 257 render_view_host_->Shutdown(); |
| 281 render_view_host_ = NULL; | 258 render_view_host_ = NULL; |
| 282 if (web_contents_->GetInterstitialPage()) | 259 if (web_contents_->GetInterstitialPage()) |
| 283 web_contents_->remove_interstitial_page(); | 260 web_contents_->remove_interstitial_page(); |
| 284 // Let's revert to the original title if necessary. | 261 // Let's revert to the original title if necessary. |
| 285 NavigationEntry* entry = web_contents_->GetController().GetActiveEntry(); | 262 NavigationEntry* entry = web_contents_->GetController().GetActiveEntry(); |
| 286 if (!new_navigation_ && should_revert_web_contents_title_) { | 263 if (!new_navigation_ && should_revert_web_contents_title_) { |
| 287 entry->SetTitle(original_web_contents_title_); | 264 entry->SetTitle(original_web_contents_title_); |
| 288 web_contents_->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE); | 265 web_contents_->NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE); |
| 289 } | 266 } |
| 290 | 267 |
| 291 content::NotificationService::current()->Notify( | 268 NotificationService::current()->Notify( |
| 292 content::NOTIFICATION_INTERSTITIAL_DETACHED, | 269 NOTIFICATION_INTERSTITIAL_DETACHED, |
| 293 content::Source<WebContents>(web_contents_), | 270 Source<WebContents>(web_contents_), |
| 294 content::NotificationService::NoDetails()); | 271 NotificationService::NoDetails()); |
| 295 | 272 |
| 296 InterstitialPageMap::iterator iter = | 273 InterstitialPageMap::iterator iter = |
| 297 g_web_contents_to_interstitial_page->find(web_contents_); | 274 g_web_contents_to_interstitial_page->find(web_contents_); |
| 298 DCHECK(iter != g_web_contents_to_interstitial_page->end()); | 275 DCHECK(iter != g_web_contents_to_interstitial_page->end()); |
| 299 if (iter != g_web_contents_to_interstitial_page->end()) | 276 if (iter != g_web_contents_to_interstitial_page->end()) |
| 300 g_web_contents_to_interstitial_page->erase(iter); | 277 g_web_contents_to_interstitial_page->erase(iter); |
| 301 } | 278 } |
| 302 | 279 |
| 303 void InterstitialPageImpl::Observe( | 280 void InterstitialPageImpl::Observe( |
| 304 int type, | 281 int type, |
| 305 const content::NotificationSource& source, | 282 const NotificationSource& source, |
| 306 const content::NotificationDetails& details) { | 283 const NotificationDetails& details) { |
| 307 switch (type) { | 284 switch (type) { |
| 308 case content::NOTIFICATION_NAV_ENTRY_PENDING: | 285 case NOTIFICATION_NAV_ENTRY_PENDING: |
| 309 // We are navigating away from the interstitial (the user has typed a URL | 286 // We are navigating away from the interstitial (the user has typed a URL |
| 310 // in the location bar or clicked a bookmark). Make sure clicking on the | 287 // in the location bar or clicked a bookmark). Make sure clicking on the |
| 311 // interstitial will have no effect. Also cancel any blocked requests | 288 // interstitial will have no effect. Also cancel any blocked requests |
| 312 // on the ResourceDispatcherHost. Note that when we get this notification | 289 // on the ResourceDispatcherHost. Note that when we get this notification |
| 313 // the RenderViewHost has not yet navigated so we'll unblock the | 290 // the RenderViewHost has not yet navigated so we'll unblock the |
| 314 // RenderViewHost before the resource request for the new page we are | 291 // RenderViewHost before the resource request for the new page we are |
| 315 // navigating arrives in the ResourceDispatcherHost. This ensures that | 292 // navigating arrives in the ResourceDispatcherHost. This ensures that |
| 316 // request won't be blocked if the same RenderViewHost was used for the | 293 // request won't be blocked if the same RenderViewHost was used for the |
| 317 // new navigation. | 294 // new navigation. |
| 318 Disable(); | 295 Disable(); |
| 319 TakeActionOnResourceDispatcher(CANCEL); | 296 TakeActionOnResourceDispatcher(CANCEL); |
| 320 break; | 297 break; |
| 321 case content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: | 298 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: |
| 322 if (action_taken_ == NO_ACTION) { | 299 if (action_taken_ == NO_ACTION) { |
| 323 // The RenderViewHost is being destroyed (as part of the tab being | 300 // The RenderViewHost is being destroyed (as part of the tab being |
| 324 // closed); make sure we clear the blocked requests. | 301 // closed); make sure we clear the blocked requests. |
| 325 RenderViewHost* rvh = static_cast<RenderViewHost*>( | 302 RenderViewHost* rvh = static_cast<RenderViewHost*>( |
| 326 static_cast<RenderViewHostImpl*>( | 303 static_cast<RenderViewHostImpl*>( |
| 327 RenderWidgetHostImpl::From( | 304 RenderWidgetHostImpl::From( |
| 328 content::Source<RenderWidgetHost>(source).ptr()))); | 305 Source<RenderWidgetHost>(source).ptr()))); |
| 329 DCHECK(rvh->GetProcess()->GetID() == original_child_id_ && | 306 DCHECK(rvh->GetProcess()->GetID() == original_child_id_ && |
| 330 rvh->GetRoutingID() == original_rvh_id_); | 307 rvh->GetRoutingID() == original_rvh_id_); |
| 331 TakeActionOnResourceDispatcher(CANCEL); | 308 TakeActionOnResourceDispatcher(CANCEL); |
| 332 } | 309 } |
| 333 break; | 310 break; |
| 334 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED: | 311 case NOTIFICATION_WEB_CONTENTS_DESTROYED: |
| 335 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: | 312 case NOTIFICATION_NAV_ENTRY_COMMITTED: |
| 336 if (action_taken_ == NO_ACTION) { | 313 if (action_taken_ == NO_ACTION) { |
| 337 // We are navigating away from the interstitial or closing a tab with an | 314 // We are navigating away from the interstitial or closing a tab with an |
| 338 // interstitial. Default to DontProceed(). We don't just call Hide as | 315 // interstitial. Default to DontProceed(). We don't just call Hide as |
| 339 // subclasses will almost certainly override DontProceed to do some work | 316 // subclasses will almost certainly override DontProceed to do some work |
| 340 // (ex: close pending connections). | 317 // (ex: close pending connections). |
| 341 DontProceed(); | 318 DontProceed(); |
| 342 } else { | 319 } else { |
| 343 // User decided to proceed and either the navigation was committed or | 320 // User decided to proceed and either the navigation was committed or |
| 344 // the tab was closed before that. | 321 // the tab was closed before that. |
| 345 Hide(); | 322 Hide(); |
| 346 delete this; | 323 delete this; |
| 347 } | 324 } |
| 348 break; | 325 break; |
| 349 case content::NOTIFICATION_DOM_OPERATION_RESPONSE: | 326 case NOTIFICATION_DOM_OPERATION_RESPONSE: |
| 350 if (enabled()) { | 327 if (enabled()) { |
| 351 content::Details<DomOperationNotificationDetails> dom_op_details( | 328 Details<DomOperationNotificationDetails> dom_op_details( |
| 352 details); | 329 details); |
| 353 delegate_->CommandReceived(dom_op_details->json); | 330 delegate_->CommandReceived(dom_op_details->json); |
| 354 } | 331 } |
| 355 break; | 332 break; |
| 356 default: | 333 default: |
| 357 NOTREACHED(); | 334 NOTREACHED(); |
| 358 } | 335 } |
| 359 } | 336 } |
| 360 | 337 |
| 361 RenderViewHostDelegateView* InterstitialPageImpl::GetDelegateView() { | 338 RenderViewHostDelegateView* InterstitialPageImpl::GetDelegateView() { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 377 void InterstitialPageImpl::DidNavigate( | 354 void InterstitialPageImpl::DidNavigate( |
| 378 RenderViewHost* render_view_host, | 355 RenderViewHost* render_view_host, |
| 379 const ViewHostMsg_FrameNavigate_Params& params) { | 356 const ViewHostMsg_FrameNavigate_Params& params) { |
| 380 // A fast user could have navigated away from the page that triggered the | 357 // A fast user could have navigated away from the page that triggered the |
| 381 // interstitial while the interstitial was loading, that would have disabled | 358 // interstitial while the interstitial was loading, that would have disabled |
| 382 // us. In that case we can dismiss ourselves. | 359 // us. In that case we can dismiss ourselves. |
| 383 if (!enabled_) { | 360 if (!enabled_) { |
| 384 DontProceed(); | 361 DontProceed(); |
| 385 return; | 362 return; |
| 386 } | 363 } |
| 387 if (params.transition == content::PAGE_TRANSITION_AUTO_SUBFRAME) { | 364 if (params.transition == PAGE_TRANSITION_AUTO_SUBFRAME) { |
| 388 // No need to handle navigate message from iframe in the interstitial page. | 365 // No need to handle navigate message from iframe in the interstitial page. |
| 389 return; | 366 return; |
| 390 } | 367 } |
| 391 | 368 |
| 392 // The RenderViewHost has loaded its contents, we can show it now. | 369 // The RenderViewHost has loaded its contents, we can show it now. |
| 393 render_view_host_->GetView()->Show(); | 370 render_view_host_->GetView()->Show(); |
| 394 web_contents_->set_interstitial_page(this); | 371 web_contents_->set_interstitial_page(this); |
| 395 | 372 |
| 396 // This notification hides the bookmark bar. Note that this has to happen | 373 // This notification hides the bookmark bar. Note that this has to happen |
| 397 // after the interstitial page was registered with |web_contents_|, since | 374 // after the interstitial page was registered with |web_contents_|, since |
| 398 // there will be a callback to |web_contents_| testing if an interstitial page | 375 // there will be a callback to |web_contents_| testing if an interstitial page |
| 399 // is showing before hiding the bookmark bar. | 376 // is showing before hiding the bookmark bar. |
| 400 content::NotificationService::current()->Notify( | 377 NotificationService::current()->Notify( |
| 401 content::NOTIFICATION_INTERSTITIAL_ATTACHED, | 378 NOTIFICATION_INTERSTITIAL_ATTACHED, |
| 402 content::Source<WebContents>(web_contents_), | 379 Source<WebContents>(web_contents_), |
| 403 content::NotificationService::NoDetails()); | 380 NotificationService::NoDetails()); |
| 404 | 381 |
| 405 RenderWidgetHostView* rwh_view = | 382 RenderWidgetHostView* rwh_view = |
| 406 web_contents_->GetRenderViewHost()->GetView(); | 383 web_contents_->GetRenderViewHost()->GetView(); |
| 407 | 384 |
| 408 // The RenderViewHost may already have crashed before we even get here. | 385 // The RenderViewHost may already have crashed before we even get here. |
| 409 if (rwh_view) { | 386 if (rwh_view) { |
| 410 // If the page has focus, focus the interstitial. | 387 // If the page has focus, focus the interstitial. |
| 411 if (rwh_view->HasFocus()) | 388 if (rwh_view->HasFocus()) |
| 412 Focus(); | 389 Focus(); |
| 413 | 390 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 | 423 |
| 447 // If this interstitial is shown on an existing navigation entry, we'll need | 424 // If this interstitial is shown on an existing navigation entry, we'll need |
| 448 // to remember its title so we can revert to it when hidden. | 425 // to remember its title so we can revert to it when hidden. |
| 449 if (!new_navigation_ && !should_revert_web_contents_title_) { | 426 if (!new_navigation_ && !should_revert_web_contents_title_) { |
| 450 original_web_contents_title_ = entry->GetTitle(); | 427 original_web_contents_title_ = entry->GetTitle(); |
| 451 should_revert_web_contents_title_ = true; | 428 should_revert_web_contents_title_ = true; |
| 452 } | 429 } |
| 453 // TODO(evan): make use of title_direction. | 430 // TODO(evan): make use of title_direction. |
| 454 // http://code.google.com/p/chromium/issues/detail?id=27094 | 431 // http://code.google.com/p/chromium/issues/detail?id=27094 |
| 455 entry->SetTitle(title); | 432 entry->SetTitle(title); |
| 456 web_contents_->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE); | 433 web_contents_->NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE); |
| 457 } | 434 } |
| 458 | 435 |
| 459 content::RendererPreferences InterstitialPageImpl::GetRendererPrefs( | 436 RendererPreferences InterstitialPageImpl::GetRendererPrefs( |
| 460 content::BrowserContext* browser_context) const { | 437 BrowserContext* browser_context) const { |
| 461 delegate_->OverrideRendererPrefs(&renderer_preferences_); | 438 delegate_->OverrideRendererPrefs(&renderer_preferences_); |
| 462 return renderer_preferences_; | 439 return renderer_preferences_; |
| 463 } | 440 } |
| 464 | 441 |
| 465 webkit_glue::WebPreferences InterstitialPageImpl::GetWebkitPrefs() { | 442 webkit_glue::WebPreferences InterstitialPageImpl::GetWebkitPrefs() { |
| 466 return WebContentsImpl::GetWebkitPrefs(render_view_host_, url_); | 443 return WebContentsImpl::GetWebkitPrefs(render_view_host_, url_); |
| 467 } | 444 } |
| 468 | 445 |
| 469 bool InterstitialPageImpl::PreHandleKeyboardEvent( | 446 bool InterstitialPageImpl::PreHandleKeyboardEvent( |
| 470 const NativeWebKeyboardEvent& event, | 447 const NativeWebKeyboardEvent& event, |
| 471 bool* is_keyboard_shortcut) { | 448 bool* is_keyboard_shortcut) { |
| 472 return web_contents_->PreHandleKeyboardEvent(event, is_keyboard_shortcut); | 449 return web_contents_->PreHandleKeyboardEvent(event, is_keyboard_shortcut); |
| 473 } | 450 } |
| 474 | 451 |
| 475 void InterstitialPageImpl::HandleKeyboardEvent( | 452 void InterstitialPageImpl::HandleKeyboardEvent( |
| 476 const NativeWebKeyboardEvent& event) { | 453 const NativeWebKeyboardEvent& event) { |
| 477 return web_contents_->HandleKeyboardEvent(event); | 454 return web_contents_->HandleKeyboardEvent(event); |
| 478 } | 455 } |
| 479 | 456 |
| 480 WebContents* InterstitialPageImpl::web_contents() const { | 457 WebContents* InterstitialPageImpl::web_contents() const { |
| 481 return web_contents_; | 458 return web_contents_; |
| 482 } | 459 } |
| 483 | 460 |
| 484 RenderViewHost* InterstitialPageImpl::CreateRenderViewHost() { | 461 RenderViewHost* InterstitialPageImpl::CreateRenderViewHost() { |
| 485 // Interstitial pages don't want to share the session storage so we mint a | 462 // Interstitial pages don't want to share the session storage so we mint a |
| 486 // new one. | 463 // new one. |
| 487 using content::BrowserContext; | |
| 488 BrowserContext* browser_context = web_contents()->GetBrowserContext(); | 464 BrowserContext* browser_context = web_contents()->GetBrowserContext(); |
| 489 scoped_refptr<SiteInstance> site_instance = | 465 scoped_refptr<SiteInstance> site_instance = |
| 490 SiteInstance::Create(browser_context); | 466 SiteInstance::Create(browser_context); |
| 491 DOMStorageContextImpl* dom_storage_context = | 467 DOMStorageContextImpl* dom_storage_context = |
| 492 static_cast<DOMStorageContextImpl*>( | 468 static_cast<DOMStorageContextImpl*>( |
| 493 BrowserContext::GetStoragePartition( | 469 BrowserContext::GetStoragePartition( |
| 494 browser_context, site_instance)->GetDOMStorageContext()); | 470 browser_context, site_instance)->GetDOMStorageContext()); |
| 495 SessionStorageNamespaceImpl* session_storage_namespace_impl = | 471 SessionStorageNamespaceImpl* session_storage_namespace_impl = |
| 496 new SessionStorageNamespaceImpl(dom_storage_context); | 472 new SessionStorageNamespaceImpl(dom_storage_context); |
| 497 | 473 |
| 498 RenderViewHostImpl* render_view_host = new RenderViewHostImpl( | 474 RenderViewHostImpl* render_view_host = new RenderViewHostImpl( |
| 499 site_instance, this, this, MSG_ROUTING_NONE, false, | 475 site_instance, this, this, MSG_ROUTING_NONE, false, |
| 500 session_storage_namespace_impl); | 476 session_storage_namespace_impl); |
| 501 web_contents_->RenderViewForInterstitialPageCreated(render_view_host); | 477 web_contents_->RenderViewForInterstitialPageCreated(render_view_host); |
| 502 return render_view_host; | 478 return render_view_host; |
| 503 } | 479 } |
| 504 | 480 |
| 505 WebContentsView* InterstitialPageImpl::CreateWebContentsView() { | 481 WebContentsView* InterstitialPageImpl::CreateWebContentsView() { |
| 506 if (!create_view_) | 482 if (!create_view_) |
| 507 return NULL; | 483 return NULL; |
| 508 WebContentsView* web_contents_view = web_contents()->GetView(); | 484 WebContentsView* web_contents_view = web_contents()->GetView(); |
| 509 RenderWidgetHostView* view = | 485 RenderWidgetHostView* view = |
| 510 web_contents_view->CreateViewForWidget(render_view_host_); | 486 web_contents_view->CreateViewForWidget(render_view_host_); |
| 511 render_view_host_->SetView(view); | 487 render_view_host_->SetView(view); |
| 512 render_view_host_->AllowBindings(content::BINDINGS_POLICY_DOM_AUTOMATION); | 488 render_view_host_->AllowBindings(BINDINGS_POLICY_DOM_AUTOMATION); |
| 513 | 489 |
| 514 int32 max_page_id = web_contents()-> | 490 int32 max_page_id = web_contents()-> |
| 515 GetMaxPageIDForSiteInstance(render_view_host_->GetSiteInstance()); | 491 GetMaxPageIDForSiteInstance(render_view_host_->GetSiteInstance()); |
| 516 render_view_host_->CreateRenderView(string16(), | 492 render_view_host_->CreateRenderView(string16(), |
| 517 MSG_ROUTING_NONE, | 493 MSG_ROUTING_NONE, |
| 518 max_page_id, | 494 max_page_id, |
| 519 std::string(), | 495 std::string(), |
| 520 -1); | 496 -1); |
| 521 view->SetSize(web_contents_view->GetContainerSize()); | 497 view->SetSize(web_contents_view->GetContainerSize()); |
| 522 // Don't show the interstitial until we have navigated to it. | 498 // Don't show the interstitial until we have navigated to it. |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 const gfx::Rect& initial_pos) { | 644 const gfx::Rect& initial_pos) { |
| 669 NOTREACHED() << "InterstitialPage does not support showing drop-downs yet."; | 645 NOTREACHED() << "InterstitialPage does not support showing drop-downs yet."; |
| 670 } | 646 } |
| 671 | 647 |
| 672 void InterstitialPageImpl::ShowCreatedFullscreenWidget(int route_id) { | 648 void InterstitialPageImpl::ShowCreatedFullscreenWidget(int route_id) { |
| 673 NOTREACHED() | 649 NOTREACHED() |
| 674 << "InterstitialPage does not support showing full screen popups."; | 650 << "InterstitialPage does not support showing full screen popups."; |
| 675 } | 651 } |
| 676 | 652 |
| 677 void InterstitialPageImpl::ShowContextMenu( | 653 void InterstitialPageImpl::ShowContextMenu( |
| 678 const content::ContextMenuParams& params, | 654 const ContextMenuParams& params, |
| 679 content::ContextMenuSourceType type) { | 655 ContextMenuSourceType type) { |
| 680 } | 656 } |
| 681 | 657 |
| 682 void InterstitialPageImpl::Disable() { | 658 void InterstitialPageImpl::Disable() { |
| 683 enabled_ = false; | 659 enabled_ = false; |
| 684 } | 660 } |
| 685 | 661 |
| 686 void InterstitialPageImpl::TakeActionOnResourceDispatcher( | 662 void InterstitialPageImpl::TakeActionOnResourceDispatcher( |
| 687 ResourceRequestAction action) { | 663 ResourceRequestAction action) { |
| 688 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)) << | 664 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)) << |
| 689 "TakeActionOnResourceDispatcher should be called on the main thread."; | 665 "TakeActionOnResourceDispatcher should be called on the main thread."; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 if (!web_contents->GetDelegateView()) | 732 if (!web_contents->GetDelegateView()) |
| 757 return; | 733 return; |
| 758 | 734 |
| 759 web_contents->GetDelegateView()->TakeFocus(reverse); | 735 web_contents->GetDelegateView()->TakeFocus(reverse); |
| 760 } | 736 } |
| 761 | 737 |
| 762 void InterstitialPageImpl::InterstitialPageRVHDelegateView::OnFindReply( | 738 void InterstitialPageImpl::InterstitialPageRVHDelegateView::OnFindReply( |
| 763 int request_id, int number_of_matches, const gfx::Rect& selection_rect, | 739 int request_id, int number_of_matches, const gfx::Rect& selection_rect, |
| 764 int active_match_ordinal, bool final_update) { | 740 int active_match_ordinal, bool final_update) { |
| 765 } | 741 } |
| 742 |
| 743 } // namespace content |
| OLD | NEW |