OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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. |
| 4 |
| 5 package org.chromium.content.browser.framehost; |
| 6 |
| 7 import org.chromium.base.ThreadUtils; |
| 8 import org.chromium.base.annotations.CalledByNative; |
| 9 import org.chromium.base.annotations.JNINamespace; |
| 10 import org.chromium.content_public.browser.RenderFrameHost; |
| 11 import org.chromium.content_public.browser.WebContents; |
| 12 |
| 13 /** |
| 14 * The RenderFrameHostImpl Java wrapper to allow communicating with the native R
enderFrameHost |
| 15 * object. |
| 16 */ |
| 17 @JNINamespace("content") |
| 18 // TODO(tedchoc): Remove the package restriction once this class moves to a non-
public content |
| 19 // package whose visibility will be enforced via DEPS. |
| 20 /* package */ class RenderFrameHostImpl implements RenderFrameHost { |
| 21 private long mNativeRenderFrameHostAndroid; |
| 22 private final WebContents mWebContents; |
| 23 |
| 24 private RenderFrameHostImpl(long nativeRenderFrameHostAndroid, WebContents w
ebContents) { |
| 25 mNativeRenderFrameHostAndroid = nativeRenderFrameHostAndroid; |
| 26 mWebContents = webContents; |
| 27 } |
| 28 |
| 29 @CalledByNative |
| 30 private static RenderFrameHostImpl create( |
| 31 long nativeRenderFrameHostAndroid, WebContents webContents) { |
| 32 return new RenderFrameHostImpl(nativeRenderFrameHostAndroid, webContents
); |
| 33 } |
| 34 |
| 35 @CalledByNative |
| 36 private void clearNativePtr() { |
| 37 mNativeRenderFrameHostAndroid = 0; |
| 38 } |
| 39 |
| 40 @Override |
| 41 public void destroy() { |
| 42 if (!ThreadUtils.runningOnUiThread()) { |
| 43 throw new IllegalStateException("Attempting to destroy WebContents o
n non-UI thread"); |
| 44 } |
| 45 if (mNativeRenderFrameHostAndroid != 0) { |
| 46 nativeDestroyRenderFrameHost(mNativeRenderFrameHostAndroid); |
| 47 } |
| 48 } |
| 49 |
| 50 @Override |
| 51 public boolean isDestroyed() { |
| 52 return mNativeRenderFrameHostAndroid == 0; |
| 53 } |
| 54 |
| 55 @Override |
| 56 public WebContents getWebContents() { |
| 57 return mWebContents; |
| 58 } |
| 59 |
| 60 @Override |
| 61 public String getLastCommittedURL() { |
| 62 return nativeGetLastCommittedURL(mNativeRenderFrameHostAndroid); |
| 63 } |
| 64 |
| 65 private static native void nativeDestroyRenderFrameHost(long renderFrameHost
Android); |
| 66 |
| 67 private native String nativeGetLastCommittedURL(long nativeRenderFrameHostAn
droid); |
| 68 } |
OLD | NEW |