1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133
  134
  135
  136

content / public / browser / prerender_web_contents_delegate.cc [blame]

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/public/browser/prerender_web_contents_delegate.h"

#include "content/browser/preloading/prerender/prerender_final_status.h"
#include "content/browser/preloading/prerender/prerender_host_registry.h"
#include "content/browser/web_contents/web_contents_impl.h"

namespace content {

WebContents* PrerenderWebContentsDelegate::OpenURLFromTab(
    WebContents* source,
    const OpenURLParams& params,
    base::OnceCallback<void(NavigationHandle&)> navigation_handle_callback) {
  NOTREACHED();
}

WebContents* PrerenderWebContentsDelegate::AddNewContents(
    WebContents* source,
    std::unique_ptr<WebContents> new_contents,
    const GURL& target_url,
    WindowOpenDisposition disposition,
    const blink::mojom::WindowFeatures& window_features,
    bool user_gesture,
    bool* was_blocked) {
  // A prerendered page cannot open a new window.
  NOTREACHED();
}

void PrerenderWebContentsDelegate::ActivateContents(WebContents* contents) {
  // WebContents should not be activated with this delegate.
  NOTREACHED();
}

void PrerenderWebContentsDelegate::LoadingStateChanged(
    WebContents* source,
    bool should_show_loading_ui) {
  // Loading events should be deferred until prerender activation.
  NOTREACHED();
}

void PrerenderWebContentsDelegate::CloseContents(WebContents* source) {
  // Cancelling prerendering will eventually destroy `this` and `source`.
  static_cast<WebContentsImpl*>(source)
      ->GetPrerenderHostRegistry()
      ->CancelAllHosts(PrerenderFinalStatus::kTabClosedWithoutUserGesture);
}

bool PrerenderWebContentsDelegate::ShouldSuppressDialogs(WebContents* source) {
  // Dialogs (JS dialogs and BeforeUnload confirm) should not be shown on a
  // prerendered page.
  NOTREACHED();
}

bool PrerenderWebContentsDelegate::ShouldFocusPageAfterCrash(
    WebContents* source) {
  // A prerendered page cannot be focused.
  return false;
}

bool PrerenderWebContentsDelegate::TakeFocus(WebContents* source,
                                             bool reverse) {
  // A prerendered page cannot be focused.
  return false;
}

void PrerenderWebContentsDelegate::WebContentsCreated(
    WebContents* source_contents,
    int opener_render_process_id,
    int opener_render_frame_id,
    const std::string& frame_name,
    const GURL& target_url,
    WebContents* new_contents) {
  // A prerendered page should not create a new WebContents.
  NOTREACHED();
}

bool PrerenderWebContentsDelegate::CanEnterFullscreenModeForTab(
    RenderFrameHost* requesting_frame) {
  // This should not be called for a prerendered page.
  NOTREACHED();
}

void PrerenderWebContentsDelegate::EnterFullscreenModeForTab(
    RenderFrameHost* requesting_frame,
    const blink::mojom::FullscreenOptions& options) {
  // This should not be called for a prerendered page.
  NOTREACHED();
}

void PrerenderWebContentsDelegate::FullscreenStateChangedForTab(
    RenderFrameHost* requesting_frame,
    const blink::mojom::FullscreenOptions& options) {
  // This should not be called for a prerendered page.
  NOTREACHED();
}

void PrerenderWebContentsDelegate::ExitFullscreenModeForTab(WebContents*) {
  // This should not be called for a prerendered page.
  NOTREACHED();
}

bool PrerenderWebContentsDelegate::IsFullscreenForTabOrPending(
    const WebContents* web_contents) {
  return false;
}

void PrerenderWebContentsDelegate::OnDidBlockNavigation(
    WebContents* web_contents,
    const GURL& blocked_url,
    const GURL& initiator_url,
    blink::mojom::NavigationBlockedReason reason) {
  // DCHECK against LifecycleState in RenderFrameHostImpl::DidBlockNavigation()
  // ensures this is never called during prerendering.
  NOTREACHED();
}

bool PrerenderWebContentsDelegate::ShouldAllowRunningInsecureContent(
    WebContents* web_contents,
    bool allowed_per_prefs,
    const url::Origin& origin,
    const GURL& resource_url) {
  // MixedContentChecker::ShouldBlockNavigation() should cancel prerendering
  // for mixed contents before this is called.
  NOTREACHED();
}

PreloadingEligibility PrerenderWebContentsDelegate::IsPrerender2Supported(
    WebContents& web_contents) {
  // This should be checked in the initiator's WebContents.
  NOTREACHED();
}

}  // namespace content