1 // Copyright 2013 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/frame_host/interstitial_page_impl.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/frame_host/interstitial_page_navigator_impl.h"
18 #include "content/browser/frame_host/navigation_controller_impl.h"
19 #include "content/browser/frame_host/navigation_entry_impl.h"
20 #include "content/browser/loader/resource_dispatcher_host_impl.h"
21 #include "content/browser/renderer_host/render_process_host_impl.h"
22 #include "content/browser/renderer_host/render_view_host_factory.h"
23 #include "content/browser/renderer_host/render_view_host_impl.h"
24 #include "content/browser/site_instance_impl.h"
25 #include "content/browser/web_contents/web_contents_impl.h"
26 #include "content/common/view_messages.h"
27 #include "content/port/browser/render_view_host_delegate_view.h"
28 #include "content/port/browser/render_widget_host_view_port.h"
29 #include "content/port/browser/web_contents_view_port.h"
30 #include "content/public/browser/browser_context.h"
31 #include "content/public/browser/browser_thread.h"
32 #include "content/public/browser/content_browser_client.h"
33 #include "content/public/browser/dom_operation_notification_details.h"
34 #include "content/public/browser/interstitial_page_delegate.h"
35 #include "content/public/browser/invalidate_type.h"
36 #include "content/public/browser/notification_service.h"
37 #include "content/public/browser/notification_source.h"
38 #include "content/public/browser/storage_partition.h"
39 #include "content/public/browser/web_contents_delegate.h"
40 #include "content/public/common/bindings_policy.h"
41 #include "content/public/common/page_transition_types.h"
42 #include "net/base/escape.h"
43 #include "net/url_request/url_request_context_getter.h"
45 using blink::WebDragOperation
;
46 using blink::WebDragOperationsMask
;
51 void ResourceRequestHelper(ResourceDispatcherHostImpl
* rdh
,
53 int render_view_host_id
,
54 ResourceRequestAction action
) {
57 rdh
->BlockRequestsForRoute(process_id
, render_view_host_id
);
60 rdh
->ResumeBlockedRequestsForRoute(process_id
, render_view_host_id
);
63 rdh
->CancelBlockedRequestsForRoute(process_id
, render_view_host_id
);
72 class InterstitialPageImpl::InterstitialPageRVHDelegateView
73 : public RenderViewHostDelegateView
{
75 explicit InterstitialPageRVHDelegateView(InterstitialPageImpl
* page
);
77 // RenderViewHostDelegateView implementation:
78 virtual void ShowPopupMenu(const gfx::Rect
& bounds
,
80 double item_font_size
,
82 const std::vector
<MenuItem
>& items
,
84 bool allow_multiple_selection
) OVERRIDE
;
85 virtual void StartDragging(const DropData
& drop_data
,
86 WebDragOperationsMask operations_allowed
,
87 const gfx::ImageSkia
& image
,
88 const gfx::Vector2d
& image_offset
,
89 const DragEventSourceInfo
& event_info
) OVERRIDE
;
90 virtual void UpdateDragCursor(WebDragOperation operation
) OVERRIDE
;
91 virtual void GotFocus() OVERRIDE
;
92 virtual void TakeFocus(bool reverse
) OVERRIDE
;
93 virtual void OnFindReply(int request_id
,
94 int number_of_matches
,
95 const gfx::Rect
& selection_rect
,
96 int active_match_ordinal
,
100 InterstitialPageImpl
* interstitial_page_
;
102 DISALLOW_COPY_AND_ASSIGN(InterstitialPageRVHDelegateView
);
106 // We keep a map of the various blocking pages shown as the UI tests need to
107 // be able to retrieve them.
108 typedef std::map
<WebContents
*, InterstitialPageImpl
*> InterstitialPageMap
;
109 static InterstitialPageMap
* g_web_contents_to_interstitial_page
;
111 // Initializes g_web_contents_to_interstitial_page in a thread-safe manner.
112 // Should be called before accessing g_web_contents_to_interstitial_page.
113 static void InitInterstitialPageMap() {
114 if (!g_web_contents_to_interstitial_page
)
115 g_web_contents_to_interstitial_page
= new InterstitialPageMap
;
118 InterstitialPage
* InterstitialPage::Create(WebContents
* web_contents
,
121 InterstitialPageDelegate
* delegate
) {
122 return new InterstitialPageImpl(
124 static_cast<RenderWidgetHostDelegate
*>(
125 static_cast<WebContentsImpl
*>(web_contents
)),
126 new_navigation
, url
, delegate
);
129 InterstitialPage
* InterstitialPage::GetInterstitialPage(
130 WebContents
* web_contents
) {
131 InitInterstitialPageMap();
132 InterstitialPageMap::const_iterator iter
=
133 g_web_contents_to_interstitial_page
->find(web_contents
);
134 if (iter
== g_web_contents_to_interstitial_page
->end())
140 InterstitialPageImpl::InterstitialPageImpl(
141 WebContents
* web_contents
,
142 RenderWidgetHostDelegate
* render_widget_host_delegate
,
145 InterstitialPageDelegate
* delegate
)
146 : WebContentsObserver(web_contents
),
147 web_contents_(web_contents
),
148 controller_(static_cast<NavigationControllerImpl
*>(
149 &web_contents
->GetController())),
150 render_widget_host_delegate_(render_widget_host_delegate
),
152 new_navigation_(new_navigation
),
153 should_discard_pending_nav_entry_(new_navigation
),
154 reload_on_dont_proceed_(false),
156 action_taken_(NO_ACTION
),
157 render_view_host_(NULL
),
158 // TODO(nasko): The InterstitialPageImpl will need to provide its own
159 // NavigationControllerImpl to the Navigator, which is separate from
160 // the WebContents one, so we can enforce no navigation policy here.
161 // While we get the code to a point to do this, pass NULL for it.
162 // TODO(creis): We will also need to pass delegates for the RVHM as we
164 frame_tree_(new InterstitialPageNavigatorImpl(this, controller_
),
166 static_cast<WebContentsImpl
*>(web_contents
)),
167 original_child_id_(web_contents
->GetRenderProcessHost()->GetID()),
168 original_rvh_id_(web_contents
->GetRenderViewHost()->GetRoutingID()),
169 should_revert_web_contents_title_(false),
170 web_contents_was_loading_(false),
171 resource_dispatcher_host_notified_(false),
172 rvh_delegate_view_(new InterstitialPageRVHDelegateView(this)),
175 weak_ptr_factory_(this) {
176 InitInterstitialPageMap();
177 // It would be inconsistent to create an interstitial with no new navigation
178 // (which is the case when the interstitial was triggered by a sub-resource on
179 // a page) when we have a pending entry (in the process of loading a new top
181 DCHECK(new_navigation
|| !web_contents
->GetController().GetPendingEntry());
184 InterstitialPageImpl::~InterstitialPageImpl() {
187 void InterstitialPageImpl::Show() {
191 // If an interstitial is already showing or about to be shown, close it before
192 // showing the new one.
193 // Be careful not to take an action on the old interstitial more than once.
194 InterstitialPageMap::const_iterator iter
=
195 g_web_contents_to_interstitial_page
->find(web_contents_
);
196 if (iter
!= g_web_contents_to_interstitial_page
->end()) {
197 InterstitialPageImpl
* interstitial
= iter
->second
;
198 if (interstitial
->action_taken_
!= NO_ACTION
) {
199 interstitial
->Hide();
201 // If we are currently showing an interstitial page for which we created
202 // a transient entry and a new interstitial is shown as the result of a
203 // new browser initiated navigation, then that transient entry has already
204 // been discarded and a new pending navigation entry created.
205 // So we should not discard that new pending navigation entry.
206 // See http://crbug.com/9791
207 if (new_navigation_
&& interstitial
->new_navigation_
)
208 interstitial
->should_discard_pending_nav_entry_
= false;
209 interstitial
->DontProceed();
213 // Block the resource requests for the render view host while it is hidden.
214 TakeActionOnResourceDispatcher(BLOCK
);
215 // We need to be notified when the RenderViewHost is destroyed so we can
216 // cancel the blocked requests. We cannot do that on
217 // NOTIFY_WEB_CONTENTS_DESTROYED as at that point the RenderViewHost has
218 // already been destroyed.
219 notification_registrar_
.Add(
220 this, NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED
,
221 Source
<RenderWidgetHost
>(controller_
->delegate()->GetRenderViewHost()));
223 // Update the g_web_contents_to_interstitial_page map.
224 iter
= g_web_contents_to_interstitial_page
->find(web_contents_
);
225 DCHECK(iter
== g_web_contents_to_interstitial_page
->end());
226 (*g_web_contents_to_interstitial_page
)[web_contents_
] = this;
228 if (new_navigation_
) {
229 NavigationEntryImpl
* entry
= new NavigationEntryImpl
;
231 entry
->SetVirtualURL(url_
);
232 entry
->set_page_type(PAGE_TYPE_INTERSTITIAL
);
234 // Give delegates a chance to set some states on the navigation entry.
235 delegate_
->OverrideEntry(entry
);
237 controller_
->SetTransientEntry(entry
);
240 DCHECK(!render_view_host_
);
241 render_view_host_
= static_cast<RenderViewHostImpl
*>(CreateRenderViewHost());
242 render_view_host_
->AttachToFrameTree();
243 CreateWebContentsView();
245 std::string data_url
= "data:text/html;charset=utf-8," +
246 net::EscapePath(delegate_
->GetHTMLContents());
247 render_view_host_
->NavigateToURL(GURL(data_url
));
249 notification_registrar_
.Add(this, NOTIFICATION_NAV_ENTRY_PENDING
,
250 Source
<NavigationController
>(controller_
));
251 notification_registrar_
.Add(
252 this, NOTIFICATION_DOM_OPERATION_RESPONSE
,
253 Source
<RenderViewHost
>(render_view_host_
));
256 void InterstitialPageImpl::Hide() {
257 // We may have already been hidden, and are just waiting to be deleted.
258 // We can't check for enabled() here, because some callers have already
260 if (!render_view_host_
)
265 RenderWidgetHostView
* old_view
=
266 controller_
->delegate()->GetRenderViewHost()->GetView();
267 if (controller_
->delegate()->GetInterstitialPage() == this &&
269 !old_view
->IsShowing() &&
270 !controller_
->delegate()->IsHidden()) {
271 // Show the original RVH since we're going away. Note it might not exist if
272 // the renderer crashed while the interstitial was showing.
273 // Note that it is important that we don't call Show() if the view is
274 // already showing. That would result in bad things (unparented HWND on
275 // Windows for example) happening.
279 // If the focus was on the interstitial, let's keep it to the page.
280 // (Note that in unit-tests the RVH may not have a view).
281 if (render_view_host_
->GetView() &&
282 render_view_host_
->GetView()->HasFocus() &&
283 controller_
->delegate()->GetRenderViewHost()->GetView()) {
284 RenderWidgetHostViewPort::FromRWHV(
285 controller_
->delegate()->GetRenderViewHost()->GetView())->Focus();
288 // Delete this and call Shutdown on the RVH asynchronously, as we may have
289 // been called from a RVH delegate method, and we can't delete the RVH out
290 // from under itself.
291 base::MessageLoop::current()->PostNonNestableTask(
293 base::Bind(&InterstitialPageImpl::Shutdown
,
294 weak_ptr_factory_
.GetWeakPtr()));
295 render_view_host_
= NULL
;
296 frame_tree_
.ResetForMainFrameSwap();
297 controller_
->delegate()->DetachInterstitialPage();
298 // Let's revert to the original title if necessary.
299 NavigationEntry
* entry
= controller_
->GetVisibleEntry();
300 if (!new_navigation_
&& should_revert_web_contents_title_
) {
301 entry
->SetTitle(original_web_contents_title_
);
302 controller_
->delegate()->NotifyNavigationStateChanged(
303 INVALIDATE_TYPE_TITLE
);
306 InterstitialPageMap::iterator iter
=
307 g_web_contents_to_interstitial_page
->find(web_contents_
);
308 DCHECK(iter
!= g_web_contents_to_interstitial_page
->end());
309 if (iter
!= g_web_contents_to_interstitial_page
->end())
310 g_web_contents_to_interstitial_page
->erase(iter
);
312 // Clear the WebContents pointer, because it may now be deleted.
313 // This signifies that we are in the process of shutting down.
314 web_contents_
= NULL
;
317 void InterstitialPageImpl::Observe(
319 const NotificationSource
& source
,
320 const NotificationDetails
& details
) {
322 case NOTIFICATION_NAV_ENTRY_PENDING
:
323 // We are navigating away from the interstitial (the user has typed a URL
324 // in the location bar or clicked a bookmark). Make sure clicking on the
325 // interstitial will have no effect. Also cancel any blocked requests
326 // on the ResourceDispatcherHost. Note that when we get this notification
327 // the RenderViewHost has not yet navigated so we'll unblock the
328 // RenderViewHost before the resource request for the new page we are
329 // navigating arrives in the ResourceDispatcherHost. This ensures that
330 // request won't be blocked if the same RenderViewHost was used for the
333 TakeActionOnResourceDispatcher(CANCEL
);
335 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED
:
336 if (action_taken_
== NO_ACTION
) {
337 // The RenderViewHost is being destroyed (as part of the tab being
338 // closed); make sure we clear the blocked requests.
339 RenderViewHost
* rvh
= static_cast<RenderViewHost
*>(
340 static_cast<RenderViewHostImpl
*>(
341 RenderWidgetHostImpl::From(
342 Source
<RenderWidgetHost
>(source
).ptr())));
343 DCHECK(rvh
->GetProcess()->GetID() == original_child_id_
&&
344 rvh
->GetRoutingID() == original_rvh_id_
);
345 TakeActionOnResourceDispatcher(CANCEL
);
348 case NOTIFICATION_DOM_OPERATION_RESPONSE
:
350 Details
<DomOperationNotificationDetails
> dom_op_details(
352 delegate_
->CommandReceived(dom_op_details
->json
);
360 void InterstitialPageImpl::NavigationEntryCommitted(
361 const LoadCommittedDetails
& load_details
) {
362 OnNavigatingAwayOrTabClosing();
365 void InterstitialPageImpl::WebContentsDestroyed(WebContents
* web_contents
) {
366 OnNavigatingAwayOrTabClosing();
369 void InterstitialPageImpl::RenderFrameCreated(
370 RenderFrameHost
* render_frame_host
) {
371 // Note this is only for subframes in the interstitial, the notification for
372 // the main frame happens in RenderViewCreated.
373 controller_
->delegate()->RenderFrameForInterstitialPageCreated(
377 RenderViewHostDelegateView
* InterstitialPageImpl::GetDelegateView() {
378 return rvh_delegate_view_
.get();
381 const GURL
& InterstitialPageImpl::GetURL() const {
385 void InterstitialPageImpl::RenderViewTerminated(
386 RenderViewHost
* render_view_host
,
387 base::TerminationStatus status
,
389 // Our renderer died. This should not happen in normal cases.
390 // If we haven't already started shutdown, just dismiss the interstitial.
391 // We cannot check for enabled() here, because we may have called Disable
392 // without calling Hide.
393 if (render_view_host_
)
397 void InterstitialPageImpl::DidNavigate(
398 RenderViewHost
* render_view_host
,
399 const ViewHostMsg_FrameNavigate_Params
& params
) {
400 // A fast user could have navigated away from the page that triggered the
401 // interstitial while the interstitial was loading, that would have disabled
402 // us. In that case we can dismiss ourselves.
407 if (PageTransitionCoreTypeIs(params
.transition
,
408 PAGE_TRANSITION_AUTO_SUBFRAME
)) {
409 // No need to handle navigate message from iframe in the interstitial page.
413 // The RenderViewHost has loaded its contents, we can show it now.
414 if (!controller_
->delegate()->IsHidden())
415 render_view_host_
->GetView()->Show();
416 controller_
->delegate()->AttachInterstitialPage(this);
418 RenderWidgetHostView
* rwh_view
=
419 controller_
->delegate()->GetRenderViewHost()->GetView();
421 // The RenderViewHost may already have crashed before we even get here.
423 // If the page has focus, focus the interstitial.
424 if (rwh_view
->HasFocus())
427 // Hide the original RVH since we're showing the interstitial instead.
431 // Notify the tab we are not loading so the throbber is stopped. It also
432 // causes a WebContentsObserver::DidStopLoading callback that the
433 // AutomationProvider (used by the UI tests) expects to consider a navigation
434 // as complete. Without this, navigating in a UI test to a URL that triggers
435 // an interstitial would hang.
436 web_contents_was_loading_
= controller_
->delegate()->IsLoading();
437 controller_
->delegate()->SetIsLoading(
438 controller_
->delegate()->GetRenderViewHost(), false, NULL
);
441 void InterstitialPageImpl::UpdateTitle(
442 RenderViewHost
* render_view_host
,
444 const base::string16
& title
,
445 base::i18n::TextDirection title_direction
) {
449 DCHECK(render_view_host
== render_view_host_
);
450 NavigationEntry
* entry
= controller_
->GetVisibleEntry();
452 // Crash reports from the field indicate this can be NULL.
453 // This is unexpected as InterstitialPages constructed with the
454 // new_navigation flag set to true create a transient navigation entry
455 // (that is returned as the active entry). And the only case so far of
456 // interstitial created with that flag set to false is with the
457 // SafeBrowsingBlockingPage, when the resource triggering the interstitial
458 // is a sub-resource, meaning the main page has already been loaded and a
459 // navigation entry should have been created.
464 // If this interstitial is shown on an existing navigation entry, we'll need
465 // to remember its title so we can revert to it when hidden.
466 if (!new_navigation_
&& !should_revert_web_contents_title_
) {
467 original_web_contents_title_
= entry
->GetTitle();
468 should_revert_web_contents_title_
= true;
470 // TODO(evan): make use of title_direction.
471 // http://code.google.com/p/chromium/issues/detail?id=27094
472 entry
->SetTitle(title
);
473 controller_
->delegate()->NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE
);
476 RendererPreferences
InterstitialPageImpl::GetRendererPrefs(
477 BrowserContext
* browser_context
) const {
478 delegate_
->OverrideRendererPrefs(&renderer_preferences_
);
479 return renderer_preferences_
;
482 WebPreferences
InterstitialPageImpl::GetWebkitPrefs() {
484 return WebPreferences();
486 return render_view_host_
->GetWebkitPrefs(url_
);
489 void InterstitialPageImpl::RenderWidgetDeleted(
490 RenderWidgetHostImpl
* render_widget_host
) {
491 // TODO(creis): Remove this method once we verify the shutdown path is sane.
492 CHECK(!web_contents_
);
495 bool InterstitialPageImpl::PreHandleKeyboardEvent(
496 const NativeWebKeyboardEvent
& event
,
497 bool* is_keyboard_shortcut
) {
500 return render_widget_host_delegate_
->PreHandleKeyboardEvent(
501 event
, is_keyboard_shortcut
);
504 void InterstitialPageImpl::HandleKeyboardEvent(
505 const NativeWebKeyboardEvent
& event
) {
507 render_widget_host_delegate_
->HandleKeyboardEvent(event
);
510 #if defined(OS_WIN) && defined(USE_AURA)
511 gfx::NativeViewAccessible
512 InterstitialPageImpl::GetParentNativeViewAccessible() {
513 return render_widget_host_delegate_
->GetParentNativeViewAccessible();
517 WebContents
* InterstitialPageImpl::web_contents() const {
518 return web_contents_
;
521 RenderViewHost
* InterstitialPageImpl::CreateRenderViewHost() {
525 // Interstitial pages don't want to share the session storage so we mint a
527 BrowserContext
* browser_context
= web_contents()->GetBrowserContext();
528 scoped_refptr
<SiteInstance
> site_instance
=
529 SiteInstance::Create(browser_context
);
530 DOMStorageContextWrapper
* dom_storage_context
=
531 static_cast<DOMStorageContextWrapper
*>(
532 BrowserContext::GetStoragePartition(
533 browser_context
, site_instance
.get())->GetDOMStorageContext());
534 session_storage_namespace_
=
535 new SessionStorageNamespaceImpl(dom_storage_context
);
537 // Use the RenderViewHost from our FrameTree.
538 frame_tree_
.root()->render_manager()->Init(
539 browser_context
, site_instance
.get(), MSG_ROUTING_NONE
, MSG_ROUTING_NONE
);
540 return frame_tree_
.root()->current_frame_host()->render_view_host();
543 WebContentsView
* InterstitialPageImpl::CreateWebContentsView() {
544 if (!enabled() || !create_view_
)
546 WebContentsView
* web_contents_view
= web_contents()->GetView();
547 WebContentsViewPort
* web_contents_view_port
=
548 static_cast<WebContentsViewPort
*>(web_contents_view
);
549 RenderWidgetHostView
* view
=
550 web_contents_view_port
->CreateViewForWidget(render_view_host_
);
551 render_view_host_
->SetView(view
);
552 render_view_host_
->AllowBindings(BINDINGS_POLICY_DOM_AUTOMATION
);
554 int32 max_page_id
= web_contents()->
555 GetMaxPageIDForSiteInstance(render_view_host_
->GetSiteInstance());
556 render_view_host_
->CreateRenderView(base::string16(),
559 controller_
->delegate()->RenderFrameForInterstitialPageCreated(
560 frame_tree_
.root()->current_frame_host());
561 view
->SetSize(web_contents_view
->GetContainerSize());
562 // Don't show the interstitial until we have navigated to it.
564 return web_contents_view
;
567 void InterstitialPageImpl::Proceed() {
568 // Don't repeat this if we are already shutting down. We cannot check for
569 // enabled() here, because we may have called Disable without calling Hide.
570 if (!render_view_host_
)
573 if (action_taken_
!= NO_ACTION
) {
578 action_taken_
= PROCEED_ACTION
;
580 // Resumes the throbber, if applicable.
581 if (web_contents_was_loading_
)
582 controller_
->delegate()->SetIsLoading(
583 controller_
->delegate()->GetRenderViewHost(), true, NULL
);
585 // If this is a new navigation, the old page is going away, so we cancel any
586 // blocked requests for it. If it is not a new navigation, then it means the
587 // interstitial was shown as a result of a resource loading in the page.
588 // Since the user wants to proceed, we'll let any blocked request go through.
590 TakeActionOnResourceDispatcher(CANCEL
);
592 TakeActionOnResourceDispatcher(RESUME
);
594 // No need to hide if we are a new navigation, we'll get hidden when the
595 // navigation is committed.
596 if (!new_navigation_
) {
598 delegate_
->OnProceed();
602 delegate_
->OnProceed();
605 void InterstitialPageImpl::DontProceed() {
606 // Don't repeat this if we are already shutting down. We cannot check for
607 // enabled() here, because we may have called Disable without calling Hide.
608 if (!render_view_host_
)
610 DCHECK(action_taken_
!= DONT_PROCEED_ACTION
);
613 action_taken_
= DONT_PROCEED_ACTION
;
615 // If this is a new navigation, we are returning to the original page, so we
616 // resume blocked requests for it. If it is not a new navigation, then it
617 // means the interstitial was shown as a result of a resource loading in the
618 // page and we won't return to the original page, so we cancel blocked
619 // requests in that case.
621 TakeActionOnResourceDispatcher(RESUME
);
623 TakeActionOnResourceDispatcher(CANCEL
);
625 if (should_discard_pending_nav_entry_
) {
626 // Since no navigation happens we have to discard the transient entry
627 // explicitely. Note that by calling DiscardNonCommittedEntries() we also
628 // discard the pending entry, which is what we want, since the navigation is
630 controller_
->DiscardNonCommittedEntries();
633 if (reload_on_dont_proceed_
)
634 controller_
->Reload(true);
637 delegate_
->OnDontProceed();
640 void InterstitialPageImpl::CancelForNavigation() {
641 // The user is trying to navigate away. We should unblock the renderer and
642 // disable the interstitial, but keep it visible until the navigation
645 // If this interstitial was shown for a new navigation, allow any navigations
646 // on the original page to resume (e.g., subresource requests, XHRs, etc).
647 // Otherwise, cancel the pending, possibly dangerous navigations.
649 TakeActionOnResourceDispatcher(RESUME
);
651 TakeActionOnResourceDispatcher(CANCEL
);
654 void InterstitialPageImpl::SetSize(const gfx::Size
& size
) {
657 #if !defined(OS_MACOSX)
658 // When a tab is closed, we might be resized after our view was NULLed
659 // (typically if there was an info-bar).
660 if (render_view_host_
->GetView())
661 render_view_host_
->GetView()->SetSize(size
);
663 // TODO(port): Does Mac need to SetSize?
668 void InterstitialPageImpl::Focus() {
669 // Focus the native window.
672 RenderWidgetHostViewPort::FromRWHV(render_view_host_
->GetView())->Focus();
675 void InterstitialPageImpl::FocusThroughTabTraversal(bool reverse
) {
678 render_view_host_
->SetInitialFocus(reverse
);
681 RenderWidgetHostView
* InterstitialPageImpl::GetView() {
682 return render_view_host_
->GetView();
685 RenderViewHost
* InterstitialPageImpl::GetRenderViewHostForTesting() const {
686 return render_view_host_
;
689 #if defined(OS_ANDROID)
690 RenderViewHost
* InterstitialPageImpl::GetRenderViewHost() const {
691 return render_view_host_
;
695 InterstitialPageDelegate
* InterstitialPageImpl::GetDelegateForTesting() {
696 return delegate_
.get();
699 void InterstitialPageImpl::DontCreateViewForTesting() {
700 create_view_
= false;
703 gfx::Rect
InterstitialPageImpl::GetRootWindowResizerRect() const {
707 void InterstitialPageImpl::CreateNewWindow(
708 int render_process_id
,
710 int main_frame_route_id
,
711 const ViewHostMsg_CreateWindow_Params
& params
,
712 SessionStorageNamespace
* session_storage_namespace
) {
713 NOTREACHED() << "InterstitialPage does not support showing popups yet.";
716 void InterstitialPageImpl::CreateNewWidget(int render_process_id
,
718 blink::WebPopupType popup_type
) {
719 NOTREACHED() << "InterstitialPage does not support showing drop-downs yet.";
722 void InterstitialPageImpl::CreateNewFullscreenWidget(int render_process_id
,
725 << "InterstitialPage does not support showing full screen popups.";
728 void InterstitialPageImpl::ShowCreatedWindow(int route_id
,
729 WindowOpenDisposition disposition
,
730 const gfx::Rect
& initial_pos
,
732 NOTREACHED() << "InterstitialPage does not support showing popups yet.";
735 void InterstitialPageImpl::ShowCreatedWidget(int route_id
,
736 const gfx::Rect
& initial_pos
) {
737 NOTREACHED() << "InterstitialPage does not support showing drop-downs yet.";
740 void InterstitialPageImpl::ShowCreatedFullscreenWidget(int route_id
) {
742 << "InterstitialPage does not support showing full screen popups.";
745 SessionStorageNamespace
* InterstitialPageImpl::GetSessionStorageNamespace(
746 SiteInstance
* instance
) {
747 return session_storage_namespace_
.get();
750 FrameTree
* InterstitialPageImpl::GetFrameTree() {
754 void InterstitialPageImpl::Disable() {
758 void InterstitialPageImpl::Shutdown() {
762 void InterstitialPageImpl::OnNavigatingAwayOrTabClosing() {
763 if (action_taken_
== NO_ACTION
) {
764 // We are navigating away from the interstitial or closing a tab with an
765 // interstitial. Default to DontProceed(). We don't just call Hide as
766 // subclasses will almost certainly override DontProceed to do some work
767 // (ex: close pending connections).
770 // User decided to proceed and either the navigation was committed or
771 // the tab was closed before that.
776 void InterstitialPageImpl::TakeActionOnResourceDispatcher(
777 ResourceRequestAction action
) {
778 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
)) <<
779 "TakeActionOnResourceDispatcher should be called on the main thread.";
781 if (action
== CANCEL
|| action
== RESUME
) {
782 if (resource_dispatcher_host_notified_
)
784 resource_dispatcher_host_notified_
= true;
787 // The tab might not have a render_view_host if it was closed (in which case,
788 // we have taken care of the blocked requests when processing
789 // NOTIFY_RENDER_WIDGET_HOST_DESTROYED.
790 // Also we need to test there is a ResourceDispatcherHostImpl, as when unit-
791 // tests we don't have one.
792 RenderViewHostImpl
* rvh
= RenderViewHostImpl::FromID(original_child_id_
,
794 if (!rvh
|| !ResourceDispatcherHostImpl::Get())
797 BrowserThread::PostTask(
801 &ResourceRequestHelper
,
802 ResourceDispatcherHostImpl::Get(),
808 InterstitialPageImpl::InterstitialPageRVHDelegateView::
809 InterstitialPageRVHDelegateView(InterstitialPageImpl
* page
)
810 : interstitial_page_(page
) {
813 void InterstitialPageImpl::InterstitialPageRVHDelegateView::ShowPopupMenu(
814 const gfx::Rect
& bounds
,
816 double item_font_size
,
818 const std::vector
<MenuItem
>& items
,
820 bool allow_multiple_selection
) {
821 NOTREACHED() << "InterstitialPage does not support showing popup menus.";
824 void InterstitialPageImpl::InterstitialPageRVHDelegateView::StartDragging(
825 const DropData
& drop_data
,
826 WebDragOperationsMask allowed_operations
,
827 const gfx::ImageSkia
& image
,
828 const gfx::Vector2d
& image_offset
,
829 const DragEventSourceInfo
& event_info
) {
830 NOTREACHED() << "InterstitialPage does not support dragging yet.";
833 void InterstitialPageImpl::InterstitialPageRVHDelegateView::UpdateDragCursor(
835 NOTREACHED() << "InterstitialPage does not support dragging yet.";
838 void InterstitialPageImpl::InterstitialPageRVHDelegateView::GotFocus() {
839 WebContents
* web_contents
= interstitial_page_
->web_contents();
840 if (web_contents
&& web_contents
->GetDelegate())
841 web_contents
->GetDelegate()->WebContentsFocused(web_contents
);
844 void InterstitialPageImpl::InterstitialPageRVHDelegateView::TakeFocus(
846 if (!interstitial_page_
->web_contents())
848 WebContentsImpl
* web_contents
=
849 static_cast<WebContentsImpl
*>(interstitial_page_
->web_contents());
850 if (!web_contents
->GetDelegateView())
853 web_contents
->GetDelegateView()->TakeFocus(reverse
);
856 void InterstitialPageImpl::InterstitialPageRVHDelegateView::OnFindReply(
857 int request_id
, int number_of_matches
, const gfx::Rect
& selection_rect
,
858 int active_match_ordinal
, bool final_update
) {
861 } // namespace content