WebContentsImpl.java revision 116680a4aac90f2aa7413d9095a592090648e557
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. 4 5package org.chromium.content.browser.webcontents; 6 7import org.chromium.base.CalledByNative; 8import org.chromium.base.JNINamespace; 9import org.chromium.content_public.browser.NavigationController; 10import org.chromium.content_public.browser.WebContents; 11 12/** 13 * The WebContentsImpl Java wrapper to allow communicating with the native WebContentsImpl 14 * object. 15 */ 16@JNINamespace("content") 17//TODO(tedchoc): Remove the package restriction once this class moves to a non-public content 18// package whose visibility will be enforced via DEPS. 19/* package */ class WebContentsImpl implements WebContents { 20 21 private long mNativeWebContentsAndroid; 22 private NavigationController mNavigationController; 23 24 private WebContentsImpl( 25 long nativeWebContentsAndroid, NavigationController navigationController) { 26 mNativeWebContentsAndroid = nativeWebContentsAndroid; 27 mNavigationController = navigationController; 28 } 29 30 @CalledByNative 31 private static WebContentsImpl create( 32 long nativeWebContentsAndroid, NavigationController navigationController) { 33 return new WebContentsImpl(nativeWebContentsAndroid, navigationController); 34 } 35 36 @CalledByNative 37 private void destroy() { 38 mNativeWebContentsAndroid = 0; 39 mNavigationController = null; 40 } 41 42 @CalledByNative 43 private long getNativePointer() { 44 return mNativeWebContentsAndroid; 45 } 46 47 @Override 48 public NavigationController getNavigationController() { 49 return mNavigationController; 50 } 51 52 @Override 53 public String getTitle() { 54 return nativeGetTitle(mNativeWebContentsAndroid); 55 } 56 57 @Override 58 public String getVisibleUrl() { 59 return nativeGetVisibleURL(mNativeWebContentsAndroid); 60 } 61 62 @Override 63 public void stop() { 64 nativeStop(mNativeWebContentsAndroid); 65 } 66 67 @Override 68 public void insertCSS(String css) { 69 if (mNativeWebContentsAndroid == 0) return; 70 nativeInsertCSS(mNativeWebContentsAndroid, css); 71 } 72 73 private native String nativeGetTitle(long nativeWebContentsAndroid); 74 private native String nativeGetVisibleURL(long nativeWebContentsAndroid); 75 private native void nativeStop(long nativeWebContentsAndroid); 76 private native void nativeInsertCSS(long nativeWebContentsAndroid, String css); 77} 78