| 1 | // Copyright (c) 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 int mNativePtr; |
| 17 | |
| 18 | /** |
| 19 | * Constructs an interstitial with the given HTML content. |
| 20 | * |
| 21 | * @param htmlContent The HTML content for the interstitial. |
| 22 | */ |
| 23 | public InterstitialPageDelegateAndroid(String htmlContent) { |
| 24 | mNativePtr = nativeInit(htmlContent); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * @return The pointer to the underlying native counterpart. |
| 29 | */ |
| 30 | public int getNative() { |
| 31 | return mNativePtr; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Called when "proceed" is triggered on the interstitial. |
| 36 | */ |
| 37 | @CalledByNative |
| 38 | protected void onProceed() { |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Called when "dont' proceed" is triggered on the interstitial. |
| 43 | */ |
| 44 | @CalledByNative |
| 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 |
| 54 | protected void commandReceived(String command) { |
| 55 | } |
| 56 | |
| 57 | @CalledByNative |
| 58 | private void onNativeDestroyed() { |
| 59 | mNativePtr = 0; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Notifies the native interstitial to proceed. |
| 64 | */ |
| 65 | protected void proceed() { |
| 66 | if (mNativePtr != 0) nativeProceed(mNativePtr); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Notifies the native interstitial to not proceed. |
| 71 | */ |
| 72 | protected void dontProceed() { |
| 73 | if (mNativePtr != 0) nativeDontProceed(mNativePtr); |
| 74 | } |
| 75 | |
| 76 | private native int nativeInit(String htmlContent); |
| 77 | private native void nativeProceed(int nativeInterstitialPageDelegateAndroid); |
| 78 | private native void nativeDontProceed(int nativeInterstitialPageDelegateAndroid); |
| 79 | } |