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/location.h"
12 #include "base/single_thread_task_runner.h"
13 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h"
15 #include "base/thread_task_runner_handle.h"
16 #include "base/threading/thread.h"
17 #include "content/browser/dom_storage/dom_storage_context_wrapper.h"
18 #include "content/browser/dom_storage/session_storage_namespace_impl.h"
19 #include "content/browser/frame_host/interstitial_page_navigator_impl.h"
20 #include "content/browser/frame_host/navigation_controller_impl.h"
21 #include "content/browser/frame_host/navigation_entry_impl.h"
22 #include "content/browser/loader/resource_dispatcher_host_impl.h"
23 #include "content/browser/renderer_host/render_process_host_impl.h"
24 #include "content/browser/renderer_host/render_view_host_delegate_view.h"
25 #include "content/browser/renderer_host/render_view_host_factory.h"
26 #include "content/browser/renderer_host/render_view_host_impl.h"
27 #include "content/browser/renderer_host/render_widget_host_view_base.h"
28 #include "content/browser/site_instance_impl.h"
29 #include "content/browser/web_contents/web_contents_impl.h"
30 #include "content/browser/web_contents/web_contents_view.h"
31 #include "content/common/frame_messages.h"
32 #include "content/common/input_messages.h"
33 #include "content/common/view_messages.h"
34 #include "content/public/browser/browser_context.h"
35 #include "content/public/browser/browser_thread.h"
36 #include "content/public/browser/content_browser_client.h"
37 #include "content/public/browser/dom_operation_notification_details.h"
38 #include "content/public/browser/interstitial_page_delegate.h"
39 #include "content/public/browser/invalidate_type.h"
40 #include "content/public/browser/notification_service.h"
41 #include "content/public/browser/notification_source.h"
42 #include "content/public/browser/storage_partition.h"
43 #include "content/public/browser/user_metrics.h"
44 #include "content/public/browser/web_contents_delegate.h"
45 #include "content/public/common/bindings_policy.h"
46 #include "net/base/escape.h"
47 #include "net/url_request/url_request_context_getter.h"
48 #include "ui/base/page_transition_types.h"
50 using blink::WebDragOperation
;
51 using blink::WebDragOperationsMask
;
56 void ResourceRequestHelper(ResourceDispatcherHostImpl
* rdh
,
58 int render_view_host_id
,
59 ResourceRequestAction action
) {
62 rdh
->BlockRequestsForRoute(process_id
, render_view_host_id
);
65 rdh
->ResumeBlockedRequestsForRoute(process_id
, render_view_host_id
);
68 rdh
->CancelBlockedRequestsForRoute(process_id
, render_view_host_id
);
77 class InterstitialPageImpl::InterstitialPageRVHDelegateView
78 : public RenderViewHostDelegateView
{
80 explicit InterstitialPageRVHDelegateView(InterstitialPageImpl
* page
);
82 // RenderViewHostDelegateView implementation:
83 #if defined(OS_MACOSX) || defined(OS_ANDROID)
84 void ShowPopupMenu(RenderFrameHost
* render_frame_host
,
85 const gfx::Rect
& bounds
,
87 double item_font_size
,
89 const std::vector
<MenuItem
>& items
,
91 bool allow_multiple_selection
) override
;
92 void HidePopupMenu() override
;
94 void StartDragging(const DropData
& drop_data
,
95 WebDragOperationsMask operations_allowed
,
96 const gfx::ImageSkia
& image
,
97 const gfx::Vector2d
& image_offset
,
98 const DragEventSourceInfo
& event_info
) override
;
99 void UpdateDragCursor(WebDragOperation operation
) override
;
100 void GotFocus() override
;
101 void TakeFocus(bool reverse
) override
;
102 virtual void OnFindReply(int request_id
,
103 int number_of_matches
,
104 const gfx::Rect
& selection_rect
,
105 int active_match_ordinal
,
109 InterstitialPageImpl
* interstitial_page_
;
111 DISALLOW_COPY_AND_ASSIGN(InterstitialPageRVHDelegateView
);
115 // We keep a map of the various blocking pages shown as the UI tests need to
116 // be able to retrieve them.
117 typedef std::map
<WebContents
*, InterstitialPageImpl
*> InterstitialPageMap
;
118 static InterstitialPageMap
* g_web_contents_to_interstitial_page
;
120 // Initializes g_web_contents_to_interstitial_page in a thread-safe manner.
121 // Should be called before accessing g_web_contents_to_interstitial_page.
122 static void InitInterstitialPageMap() {
123 if (!g_web_contents_to_interstitial_page
)
124 g_web_contents_to_interstitial_page
= new InterstitialPageMap
;
127 InterstitialPage
* InterstitialPage::Create(WebContents
* web_contents
,
130 InterstitialPageDelegate
* delegate
) {
131 return new InterstitialPageImpl(
133 static_cast<RenderWidgetHostDelegate
*>(
134 static_cast<WebContentsImpl
*>(web_contents
)),
135 new_navigation
, url
, delegate
);
138 InterstitialPage
* InterstitialPage::GetInterstitialPage(
139 WebContents
* web_contents
) {
140 InitInterstitialPageMap();
141 InterstitialPageMap::const_iterator iter
=
142 g_web_contents_to_interstitial_page
->find(web_contents
);
143 if (iter
== g_web_contents_to_interstitial_page
->end())
149 InterstitialPageImpl::InterstitialPageImpl(
150 WebContents
* web_contents
,
151 RenderWidgetHostDelegate
* render_widget_host_delegate
,
154 InterstitialPageDelegate
* delegate
)
155 : underlying_content_observer_(web_contents
, this),
156 web_contents_(web_contents
),
157 controller_(static_cast<NavigationControllerImpl
*>(
158 &web_contents
->GetController())),
159 render_widget_host_delegate_(render_widget_host_delegate
),
161 new_navigation_(new_navigation
),
162 should_discard_pending_nav_entry_(new_navigation
),
163 reload_on_dont_proceed_(false),
165 action_taken_(NO_ACTION
),
166 render_view_host_(NULL
),
167 // TODO(nasko): The InterstitialPageImpl will need to provide its own
168 // NavigationControllerImpl to the Navigator, which is separate from
169 // the WebContents one, so we can enforce no navigation policy here.
170 // While we get the code to a point to do this, pass NULL for it.
171 // TODO(creis): We will also need to pass delegates for the RVHM as we
173 frame_tree_(new InterstitialPageNavigatorImpl(this, controller_
),
175 static_cast<WebContentsImpl
*>(web_contents
)),
176 original_child_id_(web_contents
->GetRenderProcessHost()->GetID()),
177 original_rvh_id_(web_contents
->GetRenderViewHost()->GetRoutingID()),
178 should_revert_web_contents_title_(false),
179 web_contents_was_loading_(false),
180 resource_dispatcher_host_notified_(false),
181 rvh_delegate_view_(new InterstitialPageRVHDelegateView(this)),
184 weak_ptr_factory_(this) {
185 InitInterstitialPageMap();
186 // It would be inconsistent to create an interstitial with no new navigation
187 // (which is the case when the interstitial was triggered by a sub-resource on
188 // a page) when we have a pending entry (in the process of loading a new top
190 DCHECK(new_navigation
|| !web_contents
->GetController().GetPendingEntry());
193 InterstitialPageImpl::~InterstitialPageImpl() {
196 void InterstitialPageImpl::Show() {
200 // If an interstitial is already showing or about to be shown, close it before
201 // showing the new one.
202 // Be careful not to take an action on the old interstitial more than once.
203 InterstitialPageMap::const_iterator iter
=
204 g_web_contents_to_interstitial_page
->find(web_contents_
);
205 if (iter
!= g_web_contents_to_interstitial_page
->end()) {
206 InterstitialPageImpl
* interstitial
= iter
->second
;
207 if (interstitial
->action_taken_
!= NO_ACTION
) {
208 interstitial
->Hide();
210 // If we are currently showing an interstitial page for which we created
211 // a transient entry and a new interstitial is shown as the result of a
212 // new browser initiated navigation, then that transient entry has already
213 // been discarded and a new pending navigation entry created.
214 // So we should not discard that new pending navigation entry.
215 // See http://crbug.com/9791
216 if (new_navigation_
&& interstitial
->new_navigation_
)
217 interstitial
->should_discard_pending_nav_entry_
= false;
218 interstitial
->DontProceed();
222 // Block the resource requests for the render view host while it is hidden.
223 TakeActionOnResourceDispatcher(BLOCK
);
224 // We need to be notified when the RenderViewHost is destroyed so we can
225 // cancel the blocked requests. We cannot do that on
226 // NOTIFY_WEB_CONTENTS_DESTROYED as at that point the RenderViewHost has
227 // already been destroyed.
228 notification_registrar_
.Add(
229 this, NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED
,
230 Source
<RenderWidgetHost
>(controller_
->delegate()->GetRenderViewHost()));
232 // Update the g_web_contents_to_interstitial_page map.
233 iter
= g_web_contents_to_interstitial_page
->find(web_contents_
);
234 DCHECK(iter
== g_web_contents_to_interstitial_page
->end());
235 (*g_web_contents_to_interstitial_page
)[web_contents_
] = this;
237 if (new_navigation_
) {
238 scoped_ptr
<NavigationEntryImpl
> entry
=
239 make_scoped_ptr(new NavigationEntryImpl
);
241 entry
->SetVirtualURL(url_
);
242 entry
->set_page_type(PAGE_TYPE_INTERSTITIAL
);
244 // Give delegates a chance to set some states on the navigation entry.
245 delegate_
->OverrideEntry(entry
.get());
247 controller_
->SetTransientEntry(entry
.Pass());
249 static_cast<WebContentsImpl
*>(web_contents_
)->DidChangeVisibleSSLState();
252 DCHECK(!render_view_host_
);
253 render_view_host_
= CreateRenderViewHost();
254 CreateWebContentsView();
256 GURL data_url
= GURL("data:text/html;charset=utf-8," +
257 net::EscapePath(delegate_
->GetHTMLContents()));
258 frame_tree_
.root()->current_frame_host()->NavigateToInterstitialURL(data_url
);
259 frame_tree_
.root()->current_frame_host()->SetAccessibilityMode(
260 GetAccessibilityMode());
262 notification_registrar_
.Add(this, NOTIFICATION_NAV_ENTRY_PENDING
,
263 Source
<NavigationController
>(controller_
));
266 void InterstitialPageImpl::Hide() {
267 // We may have already been hidden, and are just waiting to be deleted.
268 // We can't check for enabled() here, because some callers have already
270 if (!render_view_host_
)
275 RenderWidgetHostView
* old_view
=
276 controller_
->delegate()->GetRenderViewHost()->GetView();
277 if (controller_
->delegate()->GetInterstitialPage() == this &&
279 !old_view
->IsShowing() &&
280 !controller_
->delegate()->IsHidden()) {
281 // Show the original RVH since we're going away. Note it might not exist if
282 // the renderer crashed while the interstitial was showing.
283 // Note that it is important that we don't call Show() if the view is
284 // already showing. That would result in bad things (unparented HWND on
285 // Windows for example) happening.
289 // If the focus was on the interstitial, let's keep it to the page.
290 // (Note that in unit-tests the RVH may not have a view).
291 if (render_view_host_
->GetView() &&
292 render_view_host_
->GetView()->HasFocus() &&
293 controller_
->delegate()->GetRenderViewHost()->GetView()) {
294 controller_
->delegate()->GetRenderViewHost()->GetView()->Focus();
297 // Delete this and call Shutdown on the RVH asynchronously, as we may have
298 // been called from a RVH delegate method, and we can't delete the RVH out
299 // from under itself.
300 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
301 FROM_HERE
, base::Bind(&InterstitialPageImpl::Shutdown
,
302 weak_ptr_factory_
.GetWeakPtr()));
303 render_view_host_
= NULL
;
304 frame_tree_
.root()->ResetForNewProcess();
305 controller_
->delegate()->DetachInterstitialPage();
306 // Let's revert to the original title if necessary.
307 NavigationEntry
* entry
= controller_
->GetVisibleEntry();
308 if (entry
&& !new_navigation_
&& should_revert_web_contents_title_
) {
309 entry
->SetTitle(original_web_contents_title_
);
310 controller_
->delegate()->NotifyNavigationStateChanged(
311 INVALIDATE_TYPE_TITLE
);
314 static_cast<WebContentsImpl
*>(web_contents_
)->DidChangeVisibleSSLState();
316 InterstitialPageMap::iterator iter
=
317 g_web_contents_to_interstitial_page
->find(web_contents_
);
318 DCHECK(iter
!= g_web_contents_to_interstitial_page
->end());
319 if (iter
!= g_web_contents_to_interstitial_page
->end())
320 g_web_contents_to_interstitial_page
->erase(iter
);
322 // Clear the WebContents pointer, because it may now be deleted.
323 // This signifies that we are in the process of shutting down.
324 web_contents_
= NULL
;
327 void InterstitialPageImpl::Observe(
329 const NotificationSource
& source
,
330 const NotificationDetails
& details
) {
332 case NOTIFICATION_NAV_ENTRY_PENDING
:
333 // We are navigating away from the interstitial (the user has typed a URL
334 // in the location bar or clicked a bookmark). Make sure clicking on the
335 // interstitial will have no effect. Also cancel any blocked requests
336 // on the ResourceDispatcherHost. Note that when we get this notification
337 // the RenderViewHost has not yet navigated so we'll unblock the
338 // RenderViewHost before the resource request for the new page we are
339 // navigating arrives in the ResourceDispatcherHost. This ensures that
340 // request won't be blocked if the same RenderViewHost was used for the
343 TakeActionOnResourceDispatcher(CANCEL
);
345 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED
:
346 if (action_taken_
== NO_ACTION
) {
347 // The RenderViewHost is being destroyed (as part of the tab being
348 // closed); make sure we clear the blocked requests.
349 RenderViewHost
* rvh
= static_cast<RenderViewHost
*>(
350 static_cast<RenderViewHostImpl
*>(
351 RenderWidgetHostImpl::From(
352 Source
<RenderWidgetHost
>(source
).ptr())));
353 DCHECK(rvh
->GetProcess()->GetID() == original_child_id_
&&
354 rvh
->GetRoutingID() == original_rvh_id_
);
355 TakeActionOnResourceDispatcher(CANCEL
);
363 bool InterstitialPageImpl::OnMessageReceived(RenderFrameHost
* render_frame_host
,
364 const IPC::Message
& message
) {
365 if (render_frame_host
->GetRenderViewHost() != render_view_host_
) {
366 DCHECK(!render_view_host_
)
367 << "We expect an interstitial page to have only a single RVH";
372 IPC_BEGIN_MESSAGE_MAP(InterstitialPageImpl
, message
)
373 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse
,
374 OnDomOperationResponse
)
375 IPC_MESSAGE_UNHANDLED(handled
= false)
376 IPC_END_MESSAGE_MAP()
381 bool InterstitialPageImpl::OnMessageReceived(RenderViewHost
* render_view_host
,
382 const IPC::Message
& message
) {
386 void InterstitialPageImpl::RenderFrameCreated(
387 RenderFrameHost
* render_frame_host
) {
388 // Note this is only for subframes in the interstitial, the notification for
389 // the main frame happens in RenderViewCreated.
390 controller_
->delegate()->RenderFrameForInterstitialPageCreated(
394 void InterstitialPageImpl::UpdateTitle(
395 RenderFrameHost
* render_frame_host
,
397 const base::string16
& title
,
398 base::i18n::TextDirection title_direction
) {
402 RenderViewHost
* render_view_host
= render_frame_host
->GetRenderViewHost();
403 DCHECK(render_view_host
== render_view_host_
);
404 NavigationEntry
* entry
= controller_
->GetVisibleEntry();
406 // There may be no visible entry if no URL has committed (e.g., after
407 // window.open("")). InterstitialPages with the new_navigation flag create
408 // a transient NavigationEntry and thus have a visible entry. However,
409 // interstitials can still be created when there is no visible entry. For
410 // example, the opener window may inject content into the initial blank
411 // page, which might trigger a SafeBrowsingBlockingPage.
415 // If this interstitial is shown on an existing navigation entry, we'll need
416 // to remember its title so we can revert to it when hidden.
417 if (!new_navigation_
&& !should_revert_web_contents_title_
) {
418 original_web_contents_title_
= entry
->GetTitle();
419 should_revert_web_contents_title_
= true;
421 // TODO(evan): make use of title_direction.
422 // http://code.google.com/p/chromium/issues/detail?id=27094
423 entry
->SetTitle(title
);
424 controller_
->delegate()->NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE
);
427 AccessibilityMode
InterstitialPageImpl::GetAccessibilityMode() const {
429 return static_cast<WebContentsImpl
*>(web_contents_
)->GetAccessibilityMode();
431 return AccessibilityModeOff
;
434 void InterstitialPageImpl::Cut() {
435 FrameTreeNode
* focused_node
= frame_tree_
.GetFocusedFrame();
439 focused_node
->current_frame_host()->Send(
440 new InputMsg_Cut(focused_node
->current_frame_host()->GetRoutingID()));
441 RecordAction(base::UserMetricsAction("Cut"));
444 void InterstitialPageImpl::Copy() {
445 FrameTreeNode
* focused_node
= frame_tree_
.GetFocusedFrame();
449 focused_node
->current_frame_host()->Send(
450 new InputMsg_Copy(focused_node
->current_frame_host()->GetRoutingID()));
451 RecordAction(base::UserMetricsAction("Copy"));
454 void InterstitialPageImpl::Paste() {
455 FrameTreeNode
* focused_node
= frame_tree_
.GetFocusedFrame();
459 focused_node
->current_frame_host()->Send(
460 new InputMsg_Paste(focused_node
->current_frame_host()->GetRoutingID()));
461 RecordAction(base::UserMetricsAction("Paste"));
464 void InterstitialPageImpl::SelectAll() {
465 FrameTreeNode
* focused_node
= frame_tree_
.GetFocusedFrame();
469 focused_node
->current_frame_host()->Send(new InputMsg_SelectAll(
470 focused_node
->current_frame_host()->GetRoutingID()));
471 RecordAction(base::UserMetricsAction("SelectAll"));
474 RenderViewHostDelegateView
* InterstitialPageImpl::GetDelegateView() {
475 return rvh_delegate_view_
.get();
478 const GURL
& InterstitialPageImpl::GetMainFrameLastCommittedURL() const {
482 void InterstitialPageImpl::RenderViewTerminated(
483 RenderViewHost
* render_view_host
,
484 base::TerminationStatus status
,
486 // Our renderer died. This should not happen in normal cases.
487 // If we haven't already started shutdown, just dismiss the interstitial.
488 // We cannot check for enabled() here, because we may have called Disable
489 // without calling Hide.
490 if (render_view_host_
)
494 void InterstitialPageImpl::DidNavigate(
495 RenderViewHost
* render_view_host
,
496 const FrameHostMsg_DidCommitProvisionalLoad_Params
& params
) {
497 // A fast user could have navigated away from the page that triggered the
498 // interstitial while the interstitial was loading, that would have disabled
499 // us. In that case we can dismiss ourselves.
504 if (ui::PageTransitionCoreTypeIs(params
.transition
,
505 ui::PAGE_TRANSITION_AUTO_SUBFRAME
)) {
506 // No need to handle navigate message from iframe in the interstitial page.
510 // The RenderViewHost has loaded its contents, we can show it now.
511 if (!controller_
->delegate()->IsHidden())
512 render_view_host_
->GetView()->Show();
513 controller_
->delegate()->AttachInterstitialPage(this);
515 RenderWidgetHostView
* rwh_view
=
516 controller_
->delegate()->GetRenderViewHost()->GetView();
518 // The RenderViewHost may already have crashed before we even get here.
520 // If the page has focus, focus the interstitial.
521 if (rwh_view
->HasFocus())
524 // Hide the original RVH since we're showing the interstitial instead.
528 // Notify the tab we are not loading so the throbber is stopped. It also
529 // causes a WebContentsObserver::DidStopLoading callback that the
530 // AutomationProvider (used by the UI tests) expects to consider a navigation
531 // as complete. Without this, navigating in a UI test to a URL that triggers
532 // an interstitial would hang.
533 web_contents_was_loading_
= controller_
->delegate()->IsLoading();
534 controller_
->delegate()->SetIsLoading(false, true, NULL
);
537 RendererPreferences
InterstitialPageImpl::GetRendererPrefs(
538 BrowserContext
* browser_context
) const {
539 delegate_
->OverrideRendererPrefs(&renderer_preferences_
);
540 return renderer_preferences_
;
543 void InterstitialPageImpl::RenderWidgetDeleted(
544 RenderWidgetHostImpl
* render_widget_host
) {
545 // TODO(creis): Remove this method once we verify the shutdown path is sane.
546 CHECK(!web_contents_
);
549 bool InterstitialPageImpl::PreHandleKeyboardEvent(
550 const NativeWebKeyboardEvent
& event
,
551 bool* is_keyboard_shortcut
) {
554 return render_widget_host_delegate_
->PreHandleKeyboardEvent(
555 event
, is_keyboard_shortcut
);
558 void InterstitialPageImpl::HandleKeyboardEvent(
559 const NativeWebKeyboardEvent
& event
) {
561 render_widget_host_delegate_
->HandleKeyboardEvent(event
);
565 gfx::NativeViewAccessible
566 InterstitialPageImpl::GetParentNativeViewAccessible() {
568 WebContentsImpl
* wci
= static_cast<WebContentsImpl
*>(web_contents_
);
569 return wci
->GetParentNativeViewAccessible();
575 WebContents
* InterstitialPageImpl::web_contents() const {
576 return web_contents_
;
579 RenderViewHostImpl
* InterstitialPageImpl::CreateRenderViewHost() {
583 // Interstitial pages don't want to share the session storage so we mint a
585 BrowserContext
* browser_context
= web_contents()->GetBrowserContext();
586 scoped_refptr
<SiteInstance
> site_instance
=
587 SiteInstance::Create(browser_context
);
588 DOMStorageContextWrapper
* dom_storage_context
=
589 static_cast<DOMStorageContextWrapper
*>(
590 BrowserContext::GetStoragePartition(
591 browser_context
, site_instance
.get())->GetDOMStorageContext());
592 session_storage_namespace_
=
593 new SessionStorageNamespaceImpl(dom_storage_context
);
595 // Use the RenderViewHost from our FrameTree.
596 frame_tree_
.root()->render_manager()->Init(
597 browser_context
, site_instance
.get(), MSG_ROUTING_NONE
, MSG_ROUTING_NONE
,
598 MSG_ROUTING_NONE
, 0 /* surface_id */);
599 return frame_tree_
.root()->current_frame_host()->render_view_host();
602 WebContentsView
* InterstitialPageImpl::CreateWebContentsView() {
603 if (!enabled() || !create_view_
)
605 WebContentsView
* wcv
=
606 static_cast<WebContentsImpl
*>(web_contents())->GetView();
607 RenderWidgetHostViewBase
* view
=
608 wcv
->CreateViewForWidget(render_view_host_
, false);
609 render_view_host_
->SetView(view
);
610 render_view_host_
->AllowBindings(BINDINGS_POLICY_DOM_AUTOMATION
);
612 int32 max_page_id
= web_contents()->
613 GetMaxPageIDForSiteInstance(render_view_host_
->GetSiteInstance());
614 render_view_host_
->CreateRenderView(MSG_ROUTING_NONE
,
617 FrameReplicationState(),
619 controller_
->delegate()->RenderFrameForInterstitialPageCreated(
620 frame_tree_
.root()->current_frame_host());
621 view
->SetSize(web_contents()->GetContainerBounds().size());
622 // Don't show the interstitial until we have navigated to it.
627 void InterstitialPageImpl::Proceed() {
628 // Don't repeat this if we are already shutting down. We cannot check for
629 // enabled() here, because we may have called Disable without calling Hide.
630 if (!render_view_host_
)
633 if (action_taken_
!= NO_ACTION
) {
638 action_taken_
= PROCEED_ACTION
;
640 // Resumes the throbber, if applicable.
641 if (web_contents_was_loading_
)
642 controller_
->delegate()->SetIsLoading(true, true, NULL
);
644 // If this is a new navigation, the old page is going away, so we cancel any
645 // blocked requests for it. If it is not a new navigation, then it means the
646 // interstitial was shown as a result of a resource loading in the page.
647 // Since the user wants to proceed, we'll let any blocked request go through.
649 TakeActionOnResourceDispatcher(CANCEL
);
651 TakeActionOnResourceDispatcher(RESUME
);
653 // No need to hide if we are a new navigation, we'll get hidden when the
654 // navigation is committed.
655 if (!new_navigation_
) {
657 delegate_
->OnProceed();
661 delegate_
->OnProceed();
664 void InterstitialPageImpl::DontProceed() {
665 // Don't repeat this if we are already shutting down. We cannot check for
666 // enabled() here, because we may have called Disable without calling Hide.
667 if (!render_view_host_
)
669 DCHECK(action_taken_
!= DONT_PROCEED_ACTION
);
672 action_taken_
= DONT_PROCEED_ACTION
;
674 // If this is a new navigation, we are returning to the original page, so we
675 // resume blocked requests for it. If it is not a new navigation, then it
676 // means the interstitial was shown as a result of a resource loading in the
677 // page and we won't return to the original page, so we cancel blocked
678 // requests in that case.
680 TakeActionOnResourceDispatcher(RESUME
);
682 TakeActionOnResourceDispatcher(CANCEL
);
684 if (should_discard_pending_nav_entry_
) {
685 // Since no navigation happens we have to discard the transient entry
686 // explicitely. Note that by calling DiscardNonCommittedEntries() we also
687 // discard the pending entry, which is what we want, since the navigation is
689 controller_
->DiscardNonCommittedEntries();
692 if (reload_on_dont_proceed_
)
693 controller_
->Reload(true);
696 delegate_
->OnDontProceed();
699 void InterstitialPageImpl::CancelForNavigation() {
700 // The user is trying to navigate away. We should unblock the renderer and
701 // disable the interstitial, but keep it visible until the navigation
704 // If this interstitial was shown for a new navigation, allow any navigations
705 // on the original page to resume (e.g., subresource requests, XHRs, etc).
706 // Otherwise, cancel the pending, possibly dangerous navigations.
708 TakeActionOnResourceDispatcher(RESUME
);
710 TakeActionOnResourceDispatcher(CANCEL
);
713 void InterstitialPageImpl::SetSize(const gfx::Size
& size
) {
716 #if !defined(OS_MACOSX)
717 // When a tab is closed, we might be resized after our view was NULLed
718 // (typically if there was an info-bar).
719 if (render_view_host_
->GetView())
720 render_view_host_
->GetView()->SetSize(size
);
722 // TODO(port): Does Mac need to SetSize?
727 void InterstitialPageImpl::Focus() {
728 // Focus the native window.
731 render_view_host_
->GetView()->Focus();
734 void InterstitialPageImpl::FocusThroughTabTraversal(bool reverse
) {
737 render_view_host_
->SetInitialFocus(reverse
);
740 RenderWidgetHostView
* InterstitialPageImpl::GetView() {
741 return render_view_host_
->GetView();
744 RenderFrameHost
* InterstitialPageImpl::GetMainFrame() const {
745 return render_view_host_
->GetMainFrame();
748 InterstitialPageDelegate
* InterstitialPageImpl::GetDelegateForTesting() {
749 return delegate_
.get();
752 void InterstitialPageImpl::DontCreateViewForTesting() {
753 create_view_
= false;
756 gfx::Rect
InterstitialPageImpl::GetRootWindowResizerRect() const {
760 void InterstitialPageImpl::CreateNewWindow(
761 SiteInstance
* source_site_instance
,
763 int main_frame_route_id
,
764 const ViewHostMsg_CreateWindow_Params
& params
,
765 SessionStorageNamespace
* session_storage_namespace
) {
766 NOTREACHED() << "InterstitialPage does not support showing popups yet.";
769 void InterstitialPageImpl::CreateNewWidget(int32 render_process_id
,
772 blink::WebPopupType popup_type
) {
773 NOTREACHED() << "InterstitialPage does not support showing drop-downs yet.";
776 void InterstitialPageImpl::CreateNewFullscreenWidget(int32 render_process_id
,
780 << "InterstitialPage does not support showing full screen popups.";
783 void InterstitialPageImpl::ShowCreatedWindow(int route_id
,
784 WindowOpenDisposition disposition
,
785 const gfx::Rect
& initial_rect
,
787 NOTREACHED() << "InterstitialPage does not support showing popups yet.";
790 void InterstitialPageImpl::ShowCreatedWidget(int route_id
,
791 const gfx::Rect
& initial_rect
) {
792 NOTREACHED() << "InterstitialPage does not support showing drop-downs yet.";
795 void InterstitialPageImpl::ShowCreatedFullscreenWidget(int route_id
) {
797 << "InterstitialPage does not support showing full screen popups.";
800 SessionStorageNamespace
* InterstitialPageImpl::GetSessionStorageNamespace(
801 SiteInstance
* instance
) {
802 return session_storage_namespace_
.get();
805 FrameTree
* InterstitialPageImpl::GetFrameTree() {
809 void InterstitialPageImpl::Disable() {
813 void InterstitialPageImpl::Shutdown() {
817 void InterstitialPageImpl::OnNavigatingAwayOrTabClosing() {
818 if (action_taken_
== NO_ACTION
) {
819 // We are navigating away from the interstitial or closing a tab with an
820 // interstitial. Default to DontProceed(). We don't just call Hide as
821 // subclasses will almost certainly override DontProceed to do some work
822 // (ex: close pending connections).
825 // User decided to proceed and either the navigation was committed or
826 // the tab was closed before that.
831 void InterstitialPageImpl::TakeActionOnResourceDispatcher(
832 ResourceRequestAction action
) {
833 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
835 if (action
== CANCEL
|| action
== RESUME
) {
836 if (resource_dispatcher_host_notified_
)
838 resource_dispatcher_host_notified_
= true;
841 // The tab might not have a render_view_host if it was closed (in which case,
842 // we have taken care of the blocked requests when processing
843 // NOTIFY_RENDER_WIDGET_HOST_DESTROYED.
844 // Also we need to test there is a ResourceDispatcherHostImpl, as when unit-
845 // tests we don't have one.
846 RenderViewHostImpl
* rvh
= RenderViewHostImpl::FromID(original_child_id_
,
848 if (!rvh
|| !ResourceDispatcherHostImpl::Get())
851 BrowserThread::PostTask(
855 &ResourceRequestHelper
,
856 ResourceDispatcherHostImpl::Get(),
862 void InterstitialPageImpl::OnDomOperationResponse(
863 const std::string
& json_string
,
865 // Needed by test code.
866 DomOperationNotificationDetails
details(json_string
, automation_id
);
867 NotificationService::current()->Notify(
868 NOTIFICATION_DOM_OPERATION_RESPONSE
,
869 Source
<WebContents
>(web_contents()),
870 Details
<DomOperationNotificationDetails
>(&details
));
874 delegate_
->CommandReceived(details
.json
);
878 InterstitialPageImpl::InterstitialPageRVHDelegateView::
879 InterstitialPageRVHDelegateView(InterstitialPageImpl
* page
)
880 : interstitial_page_(page
) {
883 #if defined(OS_MACOSX) || defined(OS_ANDROID)
884 void InterstitialPageImpl::InterstitialPageRVHDelegateView::ShowPopupMenu(
885 RenderFrameHost
* render_frame_host
,
886 const gfx::Rect
& bounds
,
888 double item_font_size
,
890 const std::vector
<MenuItem
>& items
,
892 bool allow_multiple_selection
) {
893 NOTREACHED() << "InterstitialPage does not support showing popup menus.";
896 void InterstitialPageImpl::InterstitialPageRVHDelegateView::HidePopupMenu() {
897 NOTREACHED() << "InterstitialPage does not support showing popup menus.";
901 void InterstitialPageImpl::InterstitialPageRVHDelegateView::StartDragging(
902 const DropData
& drop_data
,
903 WebDragOperationsMask allowed_operations
,
904 const gfx::ImageSkia
& image
,
905 const gfx::Vector2d
& image_offset
,
906 const DragEventSourceInfo
& event_info
) {
907 interstitial_page_
->render_view_host_
->DragSourceSystemDragEnded();
908 DVLOG(1) << "InterstitialPage does not support dragging yet.";
911 void InterstitialPageImpl::InterstitialPageRVHDelegateView::UpdateDragCursor(
913 NOTREACHED() << "InterstitialPage does not support dragging yet.";
916 void InterstitialPageImpl::InterstitialPageRVHDelegateView::GotFocus() {
917 WebContents
* web_contents
= interstitial_page_
->web_contents();
919 static_cast<WebContentsImpl
*>(web_contents
)->NotifyWebContentsFocused();
922 void InterstitialPageImpl::InterstitialPageRVHDelegateView::TakeFocus(
924 if (!interstitial_page_
->web_contents())
926 WebContentsImpl
* web_contents
=
927 static_cast<WebContentsImpl
*>(interstitial_page_
->web_contents());
928 if (!web_contents
->GetDelegateView())
931 web_contents
->GetDelegateView()->TakeFocus(reverse
);
934 void InterstitialPageImpl::InterstitialPageRVHDelegateView::OnFindReply(
935 int request_id
, int number_of_matches
, const gfx::Rect
& selection_rect
,
936 int active_match_ordinal
, bool final_update
) {
939 InterstitialPageImpl::UnderlyingContentObserver::UnderlyingContentObserver(
940 WebContents
* web_contents
,
941 InterstitialPageImpl
* interstitial
)
942 : WebContentsObserver(web_contents
), interstitial_(interstitial
) {
945 void InterstitialPageImpl::UnderlyingContentObserver::NavigationEntryCommitted(
946 const LoadCommittedDetails
& load_details
) {
947 interstitial_
->OnNavigatingAwayOrTabClosing();
950 void InterstitialPageImpl::UnderlyingContentObserver::WebContentsDestroyed() {
951 interstitial_
->OnNavigatingAwayOrTabClosing();
954 } // namespace content