1 // Copyright 2012 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; 6 7 import org.chromium.base.CalledByNative; 8 import org.chromium.base.JNINamespace; 9 10 /** 11 * Allows the specification and handling of Interstitial pages in java. 12 */ 13 @JNINamespace("content") 14 public class InterstitialPageDelegateAndroid { 15 16 private long mNativePtr; 17 18 /** 19 * Constructs an interstitial with the given HTML content. 20 * 21 * @param htmlContent The HTML content for the interstitial. 22 */ InterstitialPageDelegateAndroid(String htmlContent)23 public InterstitialPageDelegateAndroid(String htmlContent) { 24 mNativePtr = nativeInit(htmlContent); 25 } 26 27 /** 28 * @return The pointer to the underlying native counterpart. 29 */ getNative()30 public long getNative() { 31 return mNativePtr; 32 } 33 34 /** 35 * Called when "proceed" is triggered on the interstitial. 36 */ 37 @CalledByNative onProceed()38 protected void onProceed() { 39 } 40 41 /** 42 * Called when "dont' proceed" is triggered on the interstitial. 43 */ 44 @CalledByNative onDontProceed()45 protected void onDontProceed() { 46 } 47 48 /** 49 * Called when a command has been received from the interstitial. 50 * 51 * @param command The command that was received. 52 */ 53 @CalledByNative commandReceived(String command)54 protected void commandReceived(String command) { 55 } 56 57 @CalledByNative onNativeDestroyed()58 private void onNativeDestroyed() { 59 mNativePtr = 0; 60 } 61 62 /** 63 * Notifies the native interstitial to proceed. 64 */ proceed()65 protected void proceed() { 66 if (mNativePtr != 0) nativeProceed(mNativePtr); 67 } 68 69 /** 70 * Notifies the native interstitial to not proceed. 71 */ dontProceed()72 protected void dontProceed() { 73 if (mNativePtr != 0) nativeDontProceed(mNativePtr); 74 } 75 nativeInit(String htmlContent)76 private native long nativeInit(String htmlContent); nativeProceed(long nativeInterstitialPageDelegateAndroid)77 private native void nativeProceed(long nativeInterstitialPageDelegateAndroid); nativeDontProceed(long nativeInterstitialPageDelegateAndroid)78 private native void nativeDontProceed(long nativeInterstitialPageDelegateAndroid); 79 } 80