Revert 223982 "Remove GetActiveEntry usage from content."
[chromium-blink-merge.git] / content / browser / web_contents / interstitial_page_impl.cc
blobc12d01c37d7ec42b31b8b908b5a0147e21642cab
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
3 // found in the LICENSE file.
5 #include "content/browser/web_contents/interstitial_page_impl.h"
7 #include <vector>
9 #include "base/bind.h"
10 #include "base/compiler_specific.h"
11 #include "base/message_loop/message_loop.h"
12 #include "base/strings/string_util.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "base/threading/thread.h"
15 #include "content/browser/dom_storage/dom_storage_context_wrapper.h"
16 #include "content/browser/dom_storage/session_storage_namespace_impl.h"
17 #include "content/browser/loader/resource_dispatcher_host_impl.h"
18 #include "content/browser/renderer_host/render_process_host_impl.h"
19 #include "content/browser/renderer_host/render_view_host_impl.h"
20 #include "content/browser/site_instance_impl.h"
21 #include "content/browser/web_contents/navigation_controller_impl.h"
22 #include "content/browser/web_contents/navigation_entry_impl.h"
23 #include "content/browser/web_contents/web_contents_impl.h"
24 #include "content/common/view_messages.h"
25 #include "content/port/browser/render_view_host_delegate_view.h"
26 #include "content/port/browser/render_widget_host_view_port.h"
27 #include "content/port/browser/web_contents_view_port.h"
28 #include "content/public/browser/browser_context.h"
29 #include "content/public/browser/browser_thread.h"
30 #include "content/public/browser/content_browser_client.h"
31 #include "content/public/browser/dom_operation_notification_details.h"
32 #include "content/public/browser/interstitial_page_delegate.h"
33 #include "content/public/browser/invalidate_type.h"
34 #include "content/public/browser/notification_service.h"
35 #include "content/public/browser/notification_source.h"
36 #include "content/public/browser/storage_partition.h"
37 #include "content/public/browser/web_contents_delegate.h"
38 #include "content/public/common/bindings_policy.h"
39 #include "content/public/common/page_transition_types.h"
40 #include "net/base/escape.h"
41 #include "net/url_request/url_request_context_getter.h"
43 using WebKit::WebDragOperation;
44 using WebKit::WebDragOperationsMask;
46 namespace content {
47 namespace {
49 void ResourceRequestHelper(ResourceDispatcherHostImpl* rdh,
50 int process_id,
51 int render_view_host_id,
52 ResourceRequestAction action) {
53 switch (action) {
54 case BLOCK:
55 rdh->BlockRequestsForRoute(process_id, render_view_host_id);
56 break;
57 case RESUME:
58 rdh->ResumeBlockedRequestsForRoute(process_id, render_view_host_id);
59 break;
60 case CANCEL:
61 rdh->CancelBlockedRequestsForRoute(process_id, render_view_host_id);
62 break;
63 default:
64 NOTREACHED();
68 } // namespace
70 class InterstitialPageImpl::InterstitialPageRVHDelegateView
71 : public RenderViewHostDelegateView {
72 public:
73 explicit InterstitialPageRVHDelegateView(InterstitialPageImpl* page);
75 // RenderViewHostDelegateView implementation:
76 virtual void ShowPopupMenu(const gfx::Rect& bounds,
77 int item_height,
78 double item_font_size,
79 int selected_item,
80 const std::vector<MenuItem>& items,
81 bool right_aligned,
82 bool allow_multiple_selection) OVERRIDE;
83 virtual void StartDragging(const DropData& drop_data,
84 WebDragOperationsMask operations_allowed,
85 const gfx::ImageSkia& image,
86 const gfx::Vector2d& image_offset,
87 const DragEventSourceInfo& event_info) OVERRIDE;
88 virtual void UpdateDragCursor(WebDragOperation operation) OVERRIDE;
89 virtual void GotFocus() OVERRIDE;
90 virtual void TakeFocus(bool reverse) OVERRIDE;
91 virtual void OnFindReply(int request_id,
92 int number_of_matches,
93 const gfx::Rect& selection_rect,
94 int active_match_ordinal,
95 bool final_update);
97 private:
98 InterstitialPageImpl* interstitial_page_;
100 DISALLOW_COPY_AND_ASSIGN(InterstitialPageRVHDelegateView);
104 // We keep a map of the various blocking pages shown as the UI tests need to
105 // be able to retrieve them.
106 typedef std::map<WebContents*, InterstitialPageImpl*> InterstitialPageMap;
107 static InterstitialPageMap* g_web_contents_to_interstitial_page;
109 // Initializes g_web_contents_to_interstitial_page in a thread-safe manner.
110 // Should be called before accessing g_web_contents_to_interstitial_page.
111 static void InitInterstitialPageMap() {
112 if (!g_web_contents_to_interstitial_page)
113 g_web_contents_to_interstitial_page = new InterstitialPageMap;
116 InterstitialPage* InterstitialPage::Create(WebContents* web_contents,
117 bool new_navigation,
118 const GURL& url,
119 InterstitialPageDelegate* delegate) {
120 return new InterstitialPageImpl(web_contents, new_navigation, url, delegate);
123 InterstitialPage* InterstitialPage::GetInterstitialPage(
124 WebContents* web_contents) {
125 InitInterstitialPageMap();
126 InterstitialPageMap::const_iterator iter =
127 g_web_contents_to_interstitial_page->find(web_contents);
128 if (iter == g_web_contents_to_interstitial_page->end())
129 return NULL;
131 return iter->second;
134 InterstitialPageImpl::InterstitialPageImpl(WebContents* web_contents,
135 bool new_navigation,
136 const GURL& url,
137 InterstitialPageDelegate* delegate)
138 : WebContentsObserver(web_contents),
139 web_contents_(static_cast<WebContentsImpl*>(web_contents)),
140 url_(url),
141 new_navigation_(new_navigation),
142 should_discard_pending_nav_entry_(new_navigation),
143 reload_on_dont_proceed_(false),
144 enabled_(true),
145 action_taken_(NO_ACTION),
146 render_view_host_(NULL),
147 original_child_id_(web_contents->GetRenderProcessHost()->GetID()),
148 original_rvh_id_(web_contents->GetRenderViewHost()->GetRoutingID()),
149 should_revert_web_contents_title_(false),
150 web_contents_was_loading_(false),
151 resource_dispatcher_host_notified_(false),
152 rvh_delegate_view_(new InterstitialPageRVHDelegateView(this)),
153 create_view_(true),
154 delegate_(delegate),
155 weak_ptr_factory_(this) {
156 InitInterstitialPageMap();
157 // It would be inconsistent to create an interstitial with no new navigation
158 // (which is the case when the interstitial was triggered by a sub-resource on
159 // a page) when we have a pending entry (in the process of loading a new top
160 // frame).
161 DCHECK(new_navigation || !web_contents->GetController().GetPendingEntry());
164 InterstitialPageImpl::~InterstitialPageImpl() {
167 void InterstitialPageImpl::Show() {
168 if (!enabled())
169 return;
171 // If an interstitial is already showing or about to be shown, close it before
172 // showing the new one.
173 // Be careful not to take an action on the old interstitial more than once.
174 InterstitialPageMap::const_iterator iter =
175 g_web_contents_to_interstitial_page->find(web_contents_);
176 if (iter != g_web_contents_to_interstitial_page->end()) {
177 InterstitialPageImpl* interstitial = iter->second;
178 if (interstitial->action_taken_ != NO_ACTION) {
179 interstitial->Hide();
180 } else {
181 // If we are currently showing an interstitial page for which we created
182 // a transient entry and a new interstitial is shown as the result of a
183 // new browser initiated navigation, then that transient entry has already
184 // been discarded and a new pending navigation entry created.
185 // So we should not discard that new pending navigation entry.
186 // See http://crbug.com/9791
187 if (new_navigation_ && interstitial->new_navigation_)
188 interstitial->should_discard_pending_nav_entry_= false;
189 interstitial->DontProceed();
193 // Block the resource requests for the render view host while it is hidden.
194 TakeActionOnResourceDispatcher(BLOCK);
195 // We need to be notified when the RenderViewHost is destroyed so we can
196 // cancel the blocked requests. We cannot do that on
197 // NOTIFY_WEB_CONTENTS_DESTROYED as at that point the RenderViewHost has
198 // already been destroyed.
199 notification_registrar_.Add(
200 this, NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
201 Source<RenderWidgetHost>(web_contents_->GetRenderViewHost()));
203 // Update the g_web_contents_to_interstitial_page map.
204 iter = g_web_contents_to_interstitial_page->find(web_contents_);
205 DCHECK(iter == g_web_contents_to_interstitial_page->end());
206 (*g_web_contents_to_interstitial_page)[web_contents_] = this;
208 if (new_navigation_) {
209 NavigationEntryImpl* entry = new NavigationEntryImpl;
210 entry->SetURL(url_);
211 entry->SetVirtualURL(url_);
212 entry->set_page_type(PAGE_TYPE_INTERSTITIAL);
214 // Give delegates a chance to set some states on the navigation entry.
215 delegate_->OverrideEntry(entry);
217 web_contents_->GetController().SetTransientEntry(entry);
220 DCHECK(!render_view_host_);
221 render_view_host_ = static_cast<RenderViewHostImpl*>(CreateRenderViewHost());
222 CreateWebContentsView();
224 std::string data_url = "data:text/html;charset=utf-8," +
225 net::EscapePath(delegate_->GetHTMLContents());
226 render_view_host_->NavigateToURL(GURL(data_url));
228 notification_registrar_.Add(this, NOTIFICATION_NAV_ENTRY_PENDING,
229 Source<NavigationController>(&web_contents_->GetController()));
230 notification_registrar_.Add(
231 this, NOTIFICATION_DOM_OPERATION_RESPONSE,
232 Source<RenderViewHost>(render_view_host_));
235 void InterstitialPageImpl::Hide() {
236 // We may have already been hidden, and are just waiting to be deleted.
237 // We can't check for enabled() here, because some callers have already
238 // called Disable.
239 if (!render_view_host_)
240 return;
242 Disable();
244 RenderWidgetHostView* old_view =
245 web_contents_->GetRenderViewHost()->GetView();
246 if (web_contents_->GetInterstitialPage() == this &&
247 old_view && !old_view->IsShowing()) {
248 // Show the original RVH since we're going away. Note it might not exist if
249 // the renderer crashed while the interstitial was showing.
250 // Note that it is important that we don't call Show() if the view is
251 // already showing. That would result in bad things (unparented HWND on
252 // Windows for example) happening.
253 old_view->Show();
256 // If the focus was on the interstitial, let's keep it to the page.
257 // (Note that in unit-tests the RVH may not have a view).
258 if (render_view_host_->GetView() &&
259 render_view_host_->GetView()->HasFocus() &&
260 web_contents_->GetRenderViewHost()->GetView()) {
261 RenderWidgetHostViewPort::FromRWHV(
262 web_contents_->GetRenderViewHost()->GetView())->Focus();
265 // Shutdown the RVH asynchronously, as we may have been called from a RVH
266 // delegate method, and we can't delete the RVH out from under itself.
267 base::MessageLoop::current()->PostNonNestableTask(
268 FROM_HERE,
269 base::Bind(&InterstitialPageImpl::Shutdown,
270 weak_ptr_factory_.GetWeakPtr(),
271 render_view_host_));
272 render_view_host_ = NULL;
273 web_contents_->DetachInterstitialPage();
274 // Let's revert to the original title if necessary.
275 NavigationEntry* entry = web_contents_->GetController().GetActiveEntry();
276 if (!new_navigation_ && should_revert_web_contents_title_) {
277 entry->SetTitle(original_web_contents_title_);
278 web_contents_->NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
281 InterstitialPageMap::iterator iter =
282 g_web_contents_to_interstitial_page->find(web_contents_);
283 DCHECK(iter != g_web_contents_to_interstitial_page->end());
284 if (iter != g_web_contents_to_interstitial_page->end())
285 g_web_contents_to_interstitial_page->erase(iter);
287 // Clear the WebContents pointer, because it may now be deleted.
288 // This signifies that we are in the process of shutting down.
289 web_contents_ = NULL;
292 void InterstitialPageImpl::Observe(
293 int type,
294 const NotificationSource& source,
295 const NotificationDetails& details) {
296 switch (type) {
297 case NOTIFICATION_NAV_ENTRY_PENDING:
298 // We are navigating away from the interstitial (the user has typed a URL
299 // in the location bar or clicked a bookmark). Make sure clicking on the
300 // interstitial will have no effect. Also cancel any blocked requests
301 // on the ResourceDispatcherHost. Note that when we get this notification
302 // the RenderViewHost has not yet navigated so we'll unblock the
303 // RenderViewHost before the resource request for the new page we are
304 // navigating arrives in the ResourceDispatcherHost. This ensures that
305 // request won't be blocked if the same RenderViewHost was used for the
306 // new navigation.
307 Disable();
308 TakeActionOnResourceDispatcher(CANCEL);
309 break;
310 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED:
311 if (action_taken_ == NO_ACTION) {
312 // The RenderViewHost is being destroyed (as part of the tab being
313 // closed); make sure we clear the blocked requests.
314 RenderViewHost* rvh = static_cast<RenderViewHost*>(
315 static_cast<RenderViewHostImpl*>(
316 RenderWidgetHostImpl::From(
317 Source<RenderWidgetHost>(source).ptr())));
318 DCHECK(rvh->GetProcess()->GetID() == original_child_id_ &&
319 rvh->GetRoutingID() == original_rvh_id_);
320 TakeActionOnResourceDispatcher(CANCEL);
322 break;
323 case NOTIFICATION_DOM_OPERATION_RESPONSE:
324 if (enabled()) {
325 Details<DomOperationNotificationDetails> dom_op_details(
326 details);
327 delegate_->CommandReceived(dom_op_details->json);
329 break;
330 default:
331 NOTREACHED();
335 void InterstitialPageImpl::NavigationEntryCommitted(
336 const LoadCommittedDetails& load_details) {
337 OnNavigatingAwayOrTabClosing();
340 void InterstitialPageImpl::WebContentsDestroyed(WebContents* web_contents) {
341 OnNavigatingAwayOrTabClosing();
344 RenderViewHostDelegateView* InterstitialPageImpl::GetDelegateView() {
345 return rvh_delegate_view_.get();
348 const GURL& InterstitialPageImpl::GetURL() const {
349 return url_;
352 void InterstitialPageImpl::RenderViewTerminated(
353 RenderViewHost* render_view_host,
354 base::TerminationStatus status,
355 int error_code) {
356 // Our renderer died. This should not happen in normal cases.
357 // If we haven't already started shutdown, just dismiss the interstitial.
358 // We cannot check for enabled() here, because we may have called Disable
359 // without calling Hide.
360 if (render_view_host_)
361 DontProceed();
364 void InterstitialPageImpl::DidNavigate(
365 RenderViewHost* render_view_host,
366 const ViewHostMsg_FrameNavigate_Params& params) {
367 // A fast user could have navigated away from the page that triggered the
368 // interstitial while the interstitial was loading, that would have disabled
369 // us. In that case we can dismiss ourselves.
370 if (!enabled()) {
371 DontProceed();
372 return;
374 if (PageTransitionCoreTypeIs(params.transition,
375 PAGE_TRANSITION_AUTO_SUBFRAME)) {
376 // No need to handle navigate message from iframe in the interstitial page.
377 return;
380 // The RenderViewHost has loaded its contents, we can show it now.
381 render_view_host_->GetView()->Show();
382 web_contents_->AttachInterstitialPage(this);
384 RenderWidgetHostView* rwh_view =
385 web_contents_->GetRenderViewHost()->GetView();
387 // The RenderViewHost may already have crashed before we even get here.
388 if (rwh_view) {
389 // If the page has focus, focus the interstitial.
390 if (rwh_view->HasFocus())
391 Focus();
393 // Hide the original RVH since we're showing the interstitial instead.
394 rwh_view->Hide();
397 // Notify the tab we are not loading so the throbber is stopped. It also
398 // causes a NOTIFY_LOAD_STOP notification, that the AutomationProvider (used
399 // by the UI tests) expects to consider a navigation as complete. Without
400 // this, navigating in a UI test to a URL that triggers an interstitial would
401 // hang.
402 web_contents_was_loading_ = web_contents_->IsLoading();
403 web_contents_->SetIsLoading(false, NULL);
406 void InterstitialPageImpl::UpdateTitle(
407 RenderViewHost* render_view_host,
408 int32 page_id,
409 const string16& title,
410 base::i18n::TextDirection title_direction) {
411 if (!enabled())
412 return;
414 DCHECK(render_view_host == render_view_host_);
415 NavigationEntry* entry = web_contents_->GetController().GetActiveEntry();
416 if (!entry) {
417 // Crash reports from the field indicate this can be NULL.
418 // This is unexpected as InterstitialPages constructed with the
419 // new_navigation flag set to true create a transient navigation entry
420 // (that is returned as the active entry). And the only case so far of
421 // interstitial created with that flag set to false is with the
422 // SafeBrowsingBlockingPage, when the resource triggering the interstitial
423 // is a sub-resource, meaning the main page has already been loaded and a
424 // navigation entry should have been created.
425 NOTREACHED();
426 return;
429 // If this interstitial is shown on an existing navigation entry, we'll need
430 // to remember its title so we can revert to it when hidden.
431 if (!new_navigation_ && !should_revert_web_contents_title_) {
432 original_web_contents_title_ = entry->GetTitle();
433 should_revert_web_contents_title_ = true;
435 // TODO(evan): make use of title_direction.
436 // http://code.google.com/p/chromium/issues/detail?id=27094
437 entry->SetTitle(title);
438 web_contents_->NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
441 RendererPreferences InterstitialPageImpl::GetRendererPrefs(
442 BrowserContext* browser_context) const {
443 delegate_->OverrideRendererPrefs(&renderer_preferences_);
444 return renderer_preferences_;
447 WebPreferences InterstitialPageImpl::GetWebkitPrefs() {
448 if (!enabled())
449 return WebPreferences();
451 return WebContentsImpl::GetWebkitPrefs(render_view_host_, url_);
454 void InterstitialPageImpl::RenderWidgetDeleted(
455 RenderWidgetHostImpl* render_widget_host) {
456 delete this;
459 bool InterstitialPageImpl::PreHandleKeyboardEvent(
460 const NativeWebKeyboardEvent& event,
461 bool* is_keyboard_shortcut) {
462 if (!enabled())
463 return false;
464 return web_contents_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
467 void InterstitialPageImpl::HandleKeyboardEvent(
468 const NativeWebKeyboardEvent& event) {
469 if (enabled())
470 web_contents_->HandleKeyboardEvent(event);
473 #if defined(OS_WIN) && defined(USE_AURA)
474 gfx::NativeViewAccessible
475 InterstitialPageImpl::GetParentNativeViewAccessible() {
476 return web_contents_->GetParentNativeViewAccessible();
478 #endif
480 WebContents* InterstitialPageImpl::web_contents() const {
481 return web_contents_;
484 RenderViewHost* InterstitialPageImpl::CreateRenderViewHost() {
485 if (!enabled())
486 return NULL;
488 // Interstitial pages don't want to share the session storage so we mint a
489 // new one.
490 BrowserContext* browser_context = web_contents()->GetBrowserContext();
491 scoped_refptr<SiteInstance> site_instance =
492 SiteInstance::Create(browser_context);
493 DOMStorageContextWrapper* dom_storage_context =
494 static_cast<DOMStorageContextWrapper*>(
495 BrowserContext::GetStoragePartition(
496 browser_context, site_instance.get())->GetDOMStorageContext());
497 session_storage_namespace_ =
498 new SessionStorageNamespaceImpl(dom_storage_context);
500 RenderViewHostImpl* render_view_host =
501 new RenderViewHostImpl(site_instance.get(),
502 this,
503 this,
504 MSG_ROUTING_NONE,
505 MSG_ROUTING_NONE,
506 false,
507 false);
508 web_contents_->RenderViewForInterstitialPageCreated(render_view_host);
509 return render_view_host;
512 WebContentsView* InterstitialPageImpl::CreateWebContentsView() {
513 if (!enabled() || !create_view_)
514 return NULL;
515 WebContentsView* web_contents_view = web_contents()->GetView();
516 WebContentsViewPort* web_contents_view_port =
517 static_cast<WebContentsViewPort*>(web_contents_view);
518 RenderWidgetHostView* view =
519 web_contents_view_port->CreateViewForWidget(render_view_host_);
520 render_view_host_->SetView(view);
521 render_view_host_->AllowBindings(BINDINGS_POLICY_DOM_AUTOMATION);
523 int32 max_page_id = web_contents()->
524 GetMaxPageIDForSiteInstance(render_view_host_->GetSiteInstance());
525 render_view_host_->CreateRenderView(string16(),
526 MSG_ROUTING_NONE,
527 max_page_id);
528 view->SetSize(web_contents_view->GetContainerSize());
529 // Don't show the interstitial until we have navigated to it.
530 view->Hide();
531 return web_contents_view;
534 void InterstitialPageImpl::Proceed() {
535 // Don't repeat this if we are already shutting down. We cannot check for
536 // enabled() here, because we may have called Disable without calling Hide.
537 if (!render_view_host_)
538 return;
540 if (action_taken_ != NO_ACTION) {
541 NOTREACHED();
542 return;
544 Disable();
545 action_taken_ = PROCEED_ACTION;
547 // Resumes the throbber, if applicable.
548 if (web_contents_was_loading_)
549 web_contents_->SetIsLoading(true, NULL);
551 // If this is a new navigation, the old page is going away, so we cancel any
552 // blocked requests for it. If it is not a new navigation, then it means the
553 // interstitial was shown as a result of a resource loading in the page.
554 // Since the user wants to proceed, we'll let any blocked request go through.
555 if (new_navigation_)
556 TakeActionOnResourceDispatcher(CANCEL);
557 else
558 TakeActionOnResourceDispatcher(RESUME);
560 // No need to hide if we are a new navigation, we'll get hidden when the
561 // navigation is committed.
562 if (!new_navigation_) {
563 Hide();
564 delegate_->OnProceed();
565 return;
568 delegate_->OnProceed();
571 void InterstitialPageImpl::DontProceed() {
572 // Don't repeat this if we are already shutting down. We cannot check for
573 // enabled() here, because we may have called Disable without calling Hide.
574 if (!render_view_host_)
575 return;
576 DCHECK(action_taken_ != DONT_PROCEED_ACTION);
578 Disable();
579 action_taken_ = DONT_PROCEED_ACTION;
581 // If this is a new navigation, we are returning to the original page, so we
582 // resume blocked requests for it. If it is not a new navigation, then it
583 // means the interstitial was shown as a result of a resource loading in the
584 // page and we won't return to the original page, so we cancel blocked
585 // requests in that case.
586 if (new_navigation_)
587 TakeActionOnResourceDispatcher(RESUME);
588 else
589 TakeActionOnResourceDispatcher(CANCEL);
591 if (should_discard_pending_nav_entry_) {
592 // Since no navigation happens we have to discard the transient entry
593 // explicitely. Note that by calling DiscardNonCommittedEntries() we also
594 // discard the pending entry, which is what we want, since the navigation is
595 // cancelled.
596 web_contents_->GetController().DiscardNonCommittedEntries();
599 if (reload_on_dont_proceed_)
600 web_contents_->GetController().Reload(true);
602 Hide();
603 delegate_->OnDontProceed();
606 void InterstitialPageImpl::CancelForNavigation() {
607 // The user is trying to navigate away. We should unblock the renderer and
608 // disable the interstitial, but keep it visible until the navigation
609 // completes.
610 Disable();
611 // If this interstitial was shown for a new navigation, allow any navigations
612 // on the original page to resume (e.g., subresource requests, XHRs, etc).
613 // Otherwise, cancel the pending, possibly dangerous navigations.
614 if (new_navigation_)
615 TakeActionOnResourceDispatcher(RESUME);
616 else
617 TakeActionOnResourceDispatcher(CANCEL);
620 void InterstitialPageImpl::SetSize(const gfx::Size& size) {
621 if (!enabled())
622 return;
623 #if !defined(OS_MACOSX)
624 // When a tab is closed, we might be resized after our view was NULLed
625 // (typically if there was an info-bar).
626 if (render_view_host_->GetView())
627 render_view_host_->GetView()->SetSize(size);
628 #else
629 // TODO(port): Does Mac need to SetSize?
630 NOTIMPLEMENTED();
631 #endif
634 void InterstitialPageImpl::Focus() {
635 // Focus the native window.
636 if (!enabled())
637 return;
638 RenderWidgetHostViewPort::FromRWHV(render_view_host_->GetView())->Focus();
641 void InterstitialPageImpl::FocusThroughTabTraversal(bool reverse) {
642 if (!enabled())
643 return;
644 render_view_host_->SetInitialFocus(reverse);
647 RenderWidgetHostView* InterstitialPageImpl::GetView() {
648 return render_view_host_->GetView();
651 RenderViewHost* InterstitialPageImpl::GetRenderViewHostForTesting() const {
652 return render_view_host_;
655 #if defined(OS_ANDROID)
656 RenderViewHost* InterstitialPageImpl::GetRenderViewHost() const {
657 return render_view_host_;
659 #endif
661 InterstitialPageDelegate* InterstitialPageImpl::GetDelegateForTesting() {
662 return delegate_.get();
665 void InterstitialPageImpl::DontCreateViewForTesting() {
666 create_view_ = false;
669 gfx::Rect InterstitialPageImpl::GetRootWindowResizerRect() const {
670 return gfx::Rect();
673 void InterstitialPageImpl::CreateNewWindow(
674 int route_id,
675 int main_frame_route_id,
676 const ViewHostMsg_CreateWindow_Params& params,
677 SessionStorageNamespace* session_storage_namespace) {
678 NOTREACHED() << "InterstitialPage does not support showing popups yet.";
681 void InterstitialPageImpl::CreateNewWidget(int route_id,
682 WebKit::WebPopupType popup_type) {
683 NOTREACHED() << "InterstitialPage does not support showing drop-downs yet.";
686 void InterstitialPageImpl::CreateNewFullscreenWidget(int route_id) {
687 NOTREACHED()
688 << "InterstitialPage does not support showing full screen popups.";
691 void InterstitialPageImpl::ShowCreatedWindow(int route_id,
692 WindowOpenDisposition disposition,
693 const gfx::Rect& initial_pos,
694 bool user_gesture) {
695 NOTREACHED() << "InterstitialPage does not support showing popups yet.";
698 void InterstitialPageImpl::ShowCreatedWidget(int route_id,
699 const gfx::Rect& initial_pos) {
700 NOTREACHED() << "InterstitialPage does not support showing drop-downs yet.";
703 void InterstitialPageImpl::ShowCreatedFullscreenWidget(int route_id) {
704 NOTREACHED()
705 << "InterstitialPage does not support showing full screen popups.";
708 SessionStorageNamespace* InterstitialPageImpl::GetSessionStorageNamespace(
709 SiteInstance* instance) {
710 return session_storage_namespace_.get();
713 void InterstitialPageImpl::Disable() {
714 enabled_ = false;
717 void InterstitialPageImpl::Shutdown(RenderViewHostImpl* render_view_host) {
718 render_view_host->Shutdown();
719 // We are deleted now.
722 void InterstitialPageImpl::OnNavigatingAwayOrTabClosing() {
723 if (action_taken_ == NO_ACTION) {
724 // We are navigating away from the interstitial or closing a tab with an
725 // interstitial. Default to DontProceed(). We don't just call Hide as
726 // subclasses will almost certainly override DontProceed to do some work
727 // (ex: close pending connections).
728 DontProceed();
729 } else {
730 // User decided to proceed and either the navigation was committed or
731 // the tab was closed before that.
732 Hide();
736 void InterstitialPageImpl::TakeActionOnResourceDispatcher(
737 ResourceRequestAction action) {
738 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)) <<
739 "TakeActionOnResourceDispatcher should be called on the main thread.";
741 if (action == CANCEL || action == RESUME) {
742 if (resource_dispatcher_host_notified_)
743 return;
744 resource_dispatcher_host_notified_ = true;
747 // The tab might not have a render_view_host if it was closed (in which case,
748 // we have taken care of the blocked requests when processing
749 // NOTIFY_RENDER_WIDGET_HOST_DESTROYED.
750 // Also we need to test there is a ResourceDispatcherHostImpl, as when unit-
751 // tests we don't have one.
752 RenderViewHostImpl* rvh = RenderViewHostImpl::FromID(original_child_id_,
753 original_rvh_id_);
754 if (!rvh || !ResourceDispatcherHostImpl::Get())
755 return;
757 BrowserThread::PostTask(
758 BrowserThread::IO,
759 FROM_HERE,
760 base::Bind(
761 &ResourceRequestHelper,
762 ResourceDispatcherHostImpl::Get(),
763 original_child_id_,
764 original_rvh_id_,
765 action));
768 InterstitialPageImpl::InterstitialPageRVHDelegateView::
769 InterstitialPageRVHDelegateView(InterstitialPageImpl* page)
770 : interstitial_page_(page) {
773 void InterstitialPageImpl::InterstitialPageRVHDelegateView::ShowPopupMenu(
774 const gfx::Rect& bounds,
775 int item_height,
776 double item_font_size,
777 int selected_item,
778 const std::vector<MenuItem>& items,
779 bool right_aligned,
780 bool allow_multiple_selection) {
781 NOTREACHED() << "InterstitialPage does not support showing popup menus.";
784 void InterstitialPageImpl::InterstitialPageRVHDelegateView::StartDragging(
785 const DropData& drop_data,
786 WebDragOperationsMask allowed_operations,
787 const gfx::ImageSkia& image,
788 const gfx::Vector2d& image_offset,
789 const DragEventSourceInfo& event_info) {
790 NOTREACHED() << "InterstitialPage does not support dragging yet.";
793 void InterstitialPageImpl::InterstitialPageRVHDelegateView::UpdateDragCursor(
794 WebDragOperation) {
795 NOTREACHED() << "InterstitialPage does not support dragging yet.";
798 void InterstitialPageImpl::InterstitialPageRVHDelegateView::GotFocus() {
799 WebContents* web_contents = interstitial_page_->web_contents();
800 if (web_contents && web_contents->GetDelegate())
801 web_contents->GetDelegate()->WebContentsFocused(web_contents);
804 void InterstitialPageImpl::InterstitialPageRVHDelegateView::TakeFocus(
805 bool reverse) {
806 if (!interstitial_page_->web_contents())
807 return;
808 WebContentsImpl* web_contents =
809 static_cast<WebContentsImpl*>(interstitial_page_->web_contents());
810 if (!web_contents->GetDelegateView())
811 return;
813 web_contents->GetDelegateView()->TakeFocus(reverse);
816 void InterstitialPageImpl::InterstitialPageRVHDelegateView::OnFindReply(
817 int request_id, int number_of_matches, const gfx::Rect& selection_rect,
818 int active_match_ordinal, bool final_update) {
821 } // namespace content