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
  137
  138
  139
  140
  141
  142
  143
  144
  145
  146
  147
  148
  149
  150
  151
  152
  153
  154
  155
  156
  157
  158
  159
  160
  161
  162
  163
  164
  165
  166
  167
  168
  169
  170
  171
  172
  173
  174
  175
  176
  177
  178
  179
  180
  181
  182
  183
  184
  185
  186
  187
  188
  189
  190
  191
  192
  193
  194
  195
  196
  197
  198
  199
  200
  201
  202
  203
  204
  205
  206
  207
  208
  209
  210
  211
  212
  213
  214
  215
  216
  217
  218
  219
  220
  221
  222
  223
  224
  225
  226
  227
  228
  229
  230
  231
  232
  233
  234
  235
  236
  237
  238
  239
  240

content / public / android / java / src / org / chromium / content_public / browser / RenderFrameHost.java [blame]

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

package org.chromium.content_public.browser;

import androidx.annotation.Nullable;

import org.chromium.base.Callback;
import org.chromium.blink.mojom.AuthenticatorStatus;
import org.chromium.mojo.bindings.Interface;
import org.chromium.url.GURL;
import org.chromium.url.Origin;

import java.util.List;

/**
 * The RenderFrameHost Java wrapper to allow communicating with the native RenderFrameHost object.
 */
public interface RenderFrameHost {
    /** The results of {@link #GetAssertionWebAuthSecurityChecks}. */
    final class WebAuthSecurityChecksResults {
        public final boolean isCrossOrigin;
        public final @AuthenticatorStatus.EnumType int securityCheckResult;

        /**
         * Creates an instance of this class.
         * @param securityCheckResult The status code indicating the result of the GetAssertion
         *        request security checks.
         * @param isCrossOrigin Whether the given origin is cross-origin with any frame in the
         *        current frame's ancestor chain.
         */
        public WebAuthSecurityChecksResults(
                @AuthenticatorStatus.EnumType int securityCheckResult, boolean isCrossOrigin) {
            this.securityCheckResult = securityCheckResult;
            this.isCrossOrigin = isCrossOrigin;
        }
    }

    /**
     * Get the last committed URL of the frame.
     *
     * @return The last committed URL of the frame or null when being destroyed.
     */
    @Nullable
    GURL getLastCommittedURL();

    /**
     * Get the last committed Origin of the frame. This is not always the same as scheme/host/port
     * of getLastCommittedURL(), since it can be an "opaque" origin in such cases as, for example,
     * sandboxed frame.
     *
     * @return The last committed Origin of the frame or null when being destroyed.
     */
    @Nullable
    Origin getLastCommittedOrigin();

    /**
     * Returns the eldest parent of this RenderFrameHost.
     *
     * <p>Will only be {@code null} if this (callee) {@code RenderFrameHost} is no longer associated
     * with a native object, due to it being or having been destroyed. Note that if this method
     * returns {@code null}, this does not necessarily mean that any original parent frame or frames
     * have been destroyed.
     *
     * <p>If the callee frame is the eldest in the frame ancestry, it will return itself (if it has
     * not been destroyed).
     *
     * @see
     *     https://crsrc.org/c/content/public/browser/render_frame_host.h?q=symbol:%5Cbcontent::RenderFrameHost::GetMainFrame%5Cb%20case:yes
     * @return The eldest parent frame or null when this frame is being destroyed.
     */
    @Nullable
    RenderFrameHost getMainFrame();

    /**
     * Fetch the canonical URL associated with the fame.
     *
     * @param callback The callback to be notified once the canonical URL has been fetched.
     */
    void getCanonicalUrlForSharing(Callback<GURL> callback);

    /**
     * Fetch all RenderFramesHosts from the current frame.
     *
     * @return A list of RenderFramesHosts including the current frame and all descendents.
     */
    public List<RenderFrameHost> getAllRenderFrameHosts();

    /**
     * Returns whether the feature policy allows the feature in this frame.
     *
     * @param feature A feature controlled by feature policy.
     *
     * @return Whether the feature policy allows the feature in this frame.
     */
    boolean isFeatureEnabled(@PermissionsPolicyFeature int feature);

    /**
     * Returns an interface by name to the Frame in the renderer process. This
     * provides access to interfaces implemented in the renderer to Java code in
     * the browser process.
     *
     * Callers are responsible to ensure that the renderer Frame exists before
     * trying to make a mojo connection to it. This can be done via
     * isRenderFrameLive() if the caller is not inside the call-stack of an
     * IPC form the renderer (which would guarantee its existence at that time).
     */
    <I extends Interface, P extends Interface.Proxy> P getInterfaceToRendererFrame(
            Interface.Manager<I, P> manager);

    /**
     * Kills the renderer process when it is detected to be misbehaving and has
     * made a bad request.
     *
     * @param reason The BadMessageReason code from content::bad_message::BadMessageReason.
     */
    void terminateRendererDueToBadMessage(int reason);

    /** Notifies the native RenderFrameHost about a user activation from the browser side. */
    void notifyUserActivation();

    /** Notifies the native RenderFrameHost about a successful WebAuthn assertion request. */
    void notifyWebAuthnAssertionRequestSucceeded();

    /**
     * @return Whether this frame has an active CloseWatcher in javascript.
     */
    boolean isCloseWatcherActive();

    /**
     * If a CloseWatcher is active in this RenderFrameHost, signal it to close.
     * @return Whether a close signal was sent.
     */
    boolean signalCloseWatcherIfActive();

    /**
     * Returns whether we're in incognito mode.
     *
     * @return {@code true} if we're in incognito mode.
     */
    boolean isIncognito();

    /**
     * See native RenderFrameHost::IsRenderFrameLive().
     *
     * @return {@code true} if render frame is created.
     */
    boolean isRenderFrameLive();

    /**
     * @return Whether input events from the renderer are ignored on the browser side.
     */
    boolean areInputEventsIgnored();

    /**
     * Runs security checks associated with a Web Authentication GetAssertion request for the given
     * relying party ID and an effective origin. If the request originated from a render process,
     * then the effective origin is the same as the last committed origin. However, if the request
     * originated from an internal request from the browser process (e.g. Payments Autofill), then
     * the relying party ID would not match the renderer's origin, and will therefore have to
     * provide its own effective origin. `isPaymentCredentialGetAssertion` indicates whether the
     * security check is done for getting an assertion for Secure Payment Confirmation (SPC).
     *
     * <p>This operation may trigger network fetches and thus it takes a `Callback`. The argument to
     * the callback is an object containing (1) the status code indicating the result of the
     * GetAssertion request security checks, and (2) whether the effectiveOrigin is a cross-origin
     * with any frame in this frame's ancestor chain.
     */
    void performGetAssertionWebAuthSecurityChecks(
            String relyingPartyId,
            Origin effectiveOrigin,
            boolean isPaymentCredentialGetAssertion,
            Callback<WebAuthSecurityChecksResults> callback);

    /**
     * Runs security checks associated with a Web Authentication MakeCredential request for the the
     * given relying party ID, an effective origin and whether MakeCredential is making the payment
     * credential. See performGetAssertionWebAuthSecurityChecks for more on |effectiveOrigin|.
     *
     * <p>This operation may trigger network fetches and thus it takes a `Callback`. The argument to
     * the callback is an object containing (1) the status code indicating the result of the
     * GetAssertion request security checks, and (2) whether the effectiveOrigin is a cross-origin
     * with any frame in this frame's ancestor chain.
     */
    void performMakeCredentialWebAuthSecurityChecks(
            String relyingPartyId,
            Origin effectiveOrigin,
            boolean isPaymentCredentialCreation,
            Callback<WebAuthSecurityChecksResults> callback);

    /**
     * @return An identifier for this RenderFrameHost.
     */
    GlobalRenderFrameHostId getGlobalRenderFrameHostId();

    /**
     * Returns the LifecycleState associated with this RenderFrameHost.
     * Features that display UI to the user (or cross document/tab boundary in
     * general, e.g. when using WebContents::FromRenderFrameHost) should first
     * check whether the RenderFrameHost is in the appropriate lifecycle state.
     *
     * @return The LifecycleState associated with this RenderFrameHost.
     */
    @LifecycleState
    int getLifecycleState();

    /**
     * Inserts a VisualStateCallback that's resolved once a visual update has been processed.
     *
     * The VisualStateCallback will be inserted in Blink and will be invoked when the contents of
     * the DOM tree at the moment that the callback was inserted (or later) are submitted to the
     * compositor in a CompositorFrame. In other words, the following events need to happen before
     * the callback is invoked:
     * 1. The DOM tree is committed becoming the pending tree - see ThreadProxy::BeginMainFrame
     * 2. The pending tree is activated becoming the active tree
     * 3. The compositor calls Draw and submits a new CompositorFrame to the Viz process.
     * The callback is synchronously invoked if this is called while being destroyed.
     *
     * @param callback the callback to be inserted. The callback takes a single Boolean parameter
     *     which will be true if the visual state update was successful or false if it was aborted.
     */
    void insertVisualStateCallback(Callback<Boolean> callback);

    /**
     * Injects the passed Javascript code in the current page and evaluates it in an
     * isolated world. If a result is required, pass in a callback.
     * The caller should ensure the frame host hasn't been destroyed on the native side
     * before calling this method.
     *
     * @param script   The Javascript to execute.
     * @param worldId  Id of the isolated world.
     * @param callback The callback to be fired off when a result is ready. The
     *                 script's result will be json encoded and passed as the
     *                 parameter, and the call will be made on the main thread.
     *                 If no result is required, pass null.
     */
    void executeJavaScriptInIsolatedWorld(
            String script, int worldId, @Nullable JavaScriptCallback callback);
}