Search in sources :

Example 21 with CalledByNative

use of org.chromium.base.CalledByNative in project chromeview by pwnall.

the class AndroidNetworkLibrary method storeCertificate.

/**
 * Adds a cryptographic file (User certificate, a CA certificate or
 * PKCS#12 keychain) through the system's CertInstaller activity.
 *
 * @param context: current application context.
 * @param cert_type: cryptographic file type. E.g. CertificateMimeType.X509_USER_CERT
 * @param data: certificate/keychain data bytes.
 * @return true on success, false on failure.
 *
 * Note that failure only indicates that the function couldn't launch the
 * CertInstaller activity, not that the certificate/keychain was properly
 * installed to the keystore.
 */
@CalledByNative
public static boolean storeCertificate(Context context, int cert_type, byte[] data) {
    try {
        Intent intent = KeyChain.createInstallIntent();
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        switch(cert_type) {
            case CertificateMimeType.X509_USER_CERT:
            case CertificateMimeType.X509_CA_CERT:
                intent.putExtra(KeyChain.EXTRA_CERTIFICATE, data);
                break;
            case CertificateMimeType.PKCS12_ARCHIVE:
                intent.putExtra(KeyChain.EXTRA_PKCS12, data);
                break;
            default:
                Log.w(TAG, "invalid certificate type: " + cert_type);
                return false;
        }
        context.startActivity(intent);
        return true;
    } catch (ActivityNotFoundException e) {
        Log.w(TAG, "could not store crypto file: " + e);
    }
    return false;
}
Also used : ActivityNotFoundException(android.content.ActivityNotFoundException) Intent(android.content.Intent) CalledByNative(org.chromium.base.CalledByNative)

Example 22 with CalledByNative

use of org.chromium.base.CalledByNative in project chromeview by pwnall.

the class LocalizationUtils method getDefaultLocale.

/**
 * @return the default locale, translating Android deprecated
 * language codes into the modern ones used by Chromium.
 */
@CalledByNative
public static String getDefaultLocale() {
    Locale locale = Locale.getDefault();
    String language = locale.getLanguage();
    String country = locale.getCountry();
    // See http://developer.android.com/reference/java/util/Locale.html
    if ("iw".equals(language)) {
        language = "he";
    } else if ("in".equals(language)) {
        language = "id";
    } else if ("tl".equals(language)) {
        language = "fil";
    }
    return country.isEmpty() ? language : language + "-" + country;
}
Also used : Locale(java.util.Locale) CalledByNative(org.chromium.base.CalledByNative)

Example 23 with CalledByNative

use of org.chromium.base.CalledByNative in project chromeview by pwnall.

the class JavaBrowserViewRendererHelper method recordBitmapIntoPicture.

/**
 * Creates a new Picture that records drawing a provided bitmap.
 * Will return an empty Picture if the Bitmap is null.
 */
@CalledByNative
private static Picture recordBitmapIntoPicture(Bitmap bitmap) {
    Picture picture = new Picture();
    if (bitmap != null) {
        Canvas recordingCanvas = picture.beginRecording(bitmap.getWidth(), bitmap.getHeight());
        drawBitmapIntoCanvas(bitmap, recordingCanvas);
        picture.endRecording();
    }
    return picture;
}
Also used : Picture(android.graphics.Picture) Canvas(android.graphics.Canvas) CalledByNative(org.chromium.base.CalledByNative)

Example 24 with CalledByNative

use of org.chromium.base.CalledByNative in project chromeview by pwnall.

the class ChildProcessService method establishSurfaceTexturePeer.

/**
 * Called from native code to share a surface texture with another child process.
 * Through using the callback object the browser is used as a proxy to route the
 * call to the correct process.
 *
 * @param pid Process handle of the child process to share the SurfaceTexture with.
 * @param surfaceObject The Surface or SurfaceTexture to share with the other child process.
 * @param primaryID Used to route the call to the correct client instance.
 * @param secondaryID Used to route the call to the correct client instance.
 */
@SuppressWarnings("unused")
@CalledByNative
private void establishSurfaceTexturePeer(int pid, Object surfaceObject, int primaryID, int secondaryID) {
    if (mCallback == null) {
        Log.e(TAG, "No callback interface has been provided.");
        return;
    }
    Surface surface = null;
    boolean needRelease = false;
    if (surfaceObject instanceof Surface) {
        surface = (Surface) surfaceObject;
    } else if (surfaceObject instanceof SurfaceTexture) {
        surface = new Surface((SurfaceTexture) surfaceObject);
        needRelease = true;
    } else {
        Log.e(TAG, "Not a valid surfaceObject: " + surfaceObject);
        return;
    }
    try {
        mCallback.establishSurfacePeer(pid, surface, primaryID, secondaryID);
    } catch (RemoteException e) {
        Log.e(TAG, "Unable to call establishSurfaceTexturePeer: " + e);
        return;
    } finally {
        if (needRelease) {
            surface.release();
        }
    }
}
Also used : SurfaceTexture(android.graphics.SurfaceTexture) RemoteException(android.os.RemoteException) Surface(android.view.Surface) CalledByNative(org.chromium.base.CalledByNative)

Aggregations

CalledByNative (org.chromium.base.CalledByNative)24 Intent (android.content.Intent)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 PackageManager (android.content.pm.PackageManager)3 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)3 ActivityNotFoundException (android.content.ActivityNotFoundException)2 PackageInfo (android.content.pm.PackageInfo)2 SurfaceTexture (android.graphics.SurfaceTexture)2 Uri (android.net.Uri)2 Method (java.lang.reflect.Method)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 RSAPrivateKey (java.security.interfaces.RSAPrivateKey)2 HashMap (java.util.HashMap)2 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 IntentFilter (android.content.IntentFilter)1 ApplicationInfo (android.content.pm.ApplicationInfo)1 Resources (android.content.res.Resources)1 Canvas (android.graphics.Canvas)1 Picture (android.graphics.Picture)1