org.apache.cordova.CordovaResourceApi Java Examples

The following examples show how to use org.apache.cordova.CordovaResourceApi. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CordovaGeckoViewEngine.java    From cordova-mozillaview-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void init(CordovaWebView parentWebView, CordovaInterface cordova, Client client, CordovaResourceApi resourceApi, PluginManager pluginManager, NativeToJsMessageQueue nativeToJsMessageQueue) {
    this.parentWebView = parentWebView;
    this.cordova = cordova;
    this.client = client;
    this.resourceApi = resourceApi;
    this.pluginManager = pluginManager;
    this.nativeToJsMessageQueue = nativeToJsMessageQueue;

    chrome = new CordovaGeckoViewChrome(this, cordova);

    // We set the delegate on the Engine first.

    webView.setChromeDelegate(chrome);
    webView.loadConfiguration();
    webView.init(this, cordova);
}
 
Example #2
Source File: SystemWebViewClient.java    From ultimate-cordova-webview-app with MIT License 6 votes vote down vote up
private static boolean needsSpecialsInAssetUrlFix(Uri uri) {
    if (CordovaResourceApi.getUriType(uri) != CordovaResourceApi.URI_TYPE_ASSET) {
        return false;
    }
    if (uri.getQuery() != null || uri.getFragment() != null) {
        return true;
    }

    if (!uri.toString().contains("%")) {
        return false;
    }

    switch(android.os.Build.VERSION.SDK_INT){
        case android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH:
        case android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1:
            return true;
    }
    return false;
}
 
Example #3
Source File: X5WebViewClient.java    From cordova-plugin-x5-webview with Apache License 2.0 6 votes vote down vote up
private static boolean needsSpecialsInAssetUrlFix(Uri uri) {
    if (CordovaResourceApi.getUriType(uri) != CordovaResourceApi.URI_TYPE_ASSET) {
        return false;
    }
    if (uri.getQuery() != null || uri.getFragment() != null) {
        return true;
    }

    if (!uri.toString().contains("%")) {
        return false;
    }

    switch(Build.VERSION.SDK_INT){
        case Build.VERSION_CODES.ICE_CREAM_SANDWICH:
        case Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1:
            return true;
    }
    return false;
}
 
Example #4
Source File: SystemWebViewClient.java    From xmall with MIT License 6 votes vote down vote up
private static boolean needsSpecialsInAssetUrlFix(Uri uri) {
    if (CordovaResourceApi.getUriType(uri) != CordovaResourceApi.URI_TYPE_ASSET) {
        return false;
    }
    if (uri.getQuery() != null || uri.getFragment() != null) {
        return true;
    }

    if (!uri.toString().contains("%")) {
        return false;
    }

    switch(android.os.Build.VERSION.SDK_INT){
        case android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH:
        case android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1:
            return true;
    }
    return false;
}
 
Example #5
Source File: X5WebViewClient.java    From x5webview-cordova-plugin with Apache License 2.0 6 votes vote down vote up
private static boolean needsSpecialsInAssetUrlFix(Uri uri) {
    if (CordovaResourceApi.getUriType(uri) != CordovaResourceApi.URI_TYPE_ASSET) {
        return false;
    }
    if (uri.getQuery() != null || uri.getFragment() != null) {
        return true;
    }

    if (!uri.toString().contains("%")) {
        return false;
    }

    switch(Build.VERSION.SDK_INT){
        case Build.VERSION_CODES.ICE_CREAM_SANDWICH:
        case Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1:
            return true;
    }
    return false;
}
 
Example #6
Source File: LocalFilesystem.java    From keemob with MIT License 6 votes vote down vote up
private void copyFile(Filesystem srcFs, LocalFilesystemURL srcURL, File destFile, boolean move) throws IOException, InvalidModificationException, NoModificationAllowedException {
    if (move) {
        String realSrcPath = srcFs.filesystemPathForURL(srcURL);
        if (realSrcPath != null) {
            File srcFile = new File(realSrcPath);
            if (srcFile.renameTo(destFile)) {
                return;
            }
            // Trying to rename the file failed.  Possibly because we moved across file system on the device.
        }
    }

    CordovaResourceApi.OpenForReadResult offr = resourceApi.openForRead(srcFs.toNativeUri(srcURL));
    copyResource(offr, new FileOutputStream(destFile));

    if (move) {
        srcFs.removeFileAtLocalURL(srcURL);
    }
}
 
Example #7
Source File: Filesystem.java    From keemob with MIT License 6 votes vote down vote up
public JSONObject copyFileToURL(LocalFilesystemURL destURL, String newName,
        Filesystem srcFs, LocalFilesystemURL srcURL, boolean move) throws IOException, InvalidModificationException, JSONException, NoModificationAllowedException, FileExistsException {
    // First, check to see that we can do it
    if (move && !srcFs.canRemoveFileAtLocalURL(srcURL)) {
        throw new NoModificationAllowedException("Cannot move file at source URL");
    }
    final LocalFilesystemURL destination = makeDestinationURL(newName, srcURL, destURL, srcURL.isDirectory);

    Uri srcNativeUri = srcFs.toNativeUri(srcURL);

    CordovaResourceApi.OpenForReadResult ofrr = resourceApi.openForRead(srcNativeUri);
    OutputStream os = null;
    try {
        os = getOutputStreamForURL(destination);
    } catch (IOException e) {
        ofrr.inputStream.close();
        throw e;
    }
    // Closes streams.
    resourceApi.copyResource(ofrr, os);

    if (move) {
        srcFs.removeFileAtLocalURL(srcURL);
    }
    return getEntryForLocalURL(destination);
}
 
Example #8
Source File: SystemWebViewClient.java    From keemob with MIT License 6 votes vote down vote up
@Override
@SuppressWarnings("deprecation")
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
    try {
        // Check the against the whitelist and lock out access to the WebView directory
        // Changing this will cause problems for your application
        if (!parentEngine.pluginManager.shouldAllowRequest(url)) {
            LOG.w(TAG, "URL blocked by whitelist: " + url);
            // Results in a 404.
            return new WebResourceResponse("text/plain", "UTF-8", null);
        }

        CordovaResourceApi resourceApi = parentEngine.resourceApi;
        Uri origUri = Uri.parse(url);
        // Allow plugins to intercept WebView requests.
        Uri remappedUri = resourceApi.remapUri(origUri);

        if (!origUri.equals(remappedUri) || needsSpecialsInAssetUrlFix(origUri) || needsKitKatContentUrlFix(origUri)) {
            CordovaResourceApi.OpenForReadResult result = resourceApi.openForRead(remappedUri, true);
            return new WebResourceResponse(result.mimeType, "UTF-8", result.inputStream);
        }
        // If we don't need to special-case the request, let the browser load it.
        return null;
    } catch (IOException e) {
        if (!(e instanceof FileNotFoundException)) {
            LOG.e(TAG, "Error occurred while loading a file (returning a 404).", e);
        }
        // Results in a 404.
        return new WebResourceResponse("text/plain", "UTF-8", null);
    }
}
 
Example #9
Source File: LocalFilesystem.java    From keemob with MIT License 6 votes vote down vote up
private void copyFile(Filesystem srcFs, LocalFilesystemURL srcURL, File destFile, boolean move) throws IOException, InvalidModificationException, NoModificationAllowedException {
    if (move) {
        String realSrcPath = srcFs.filesystemPathForURL(srcURL);
        if (realSrcPath != null) {
            File srcFile = new File(realSrcPath);
            if (srcFile.renameTo(destFile)) {
                return;
            }
            // Trying to rename the file failed.  Possibly because we moved across file system on the device.
        }
    }

    CordovaResourceApi.OpenForReadResult offr = resourceApi.openForRead(srcFs.toNativeUri(srcURL));
    copyResource(offr, new FileOutputStream(destFile));

    if (move) {
        srcFs.removeFileAtLocalURL(srcURL);
    }
}
 
Example #10
Source File: Filesystem.java    From keemob with MIT License 6 votes vote down vote up
public JSONObject copyFileToURL(LocalFilesystemURL destURL, String newName,
        Filesystem srcFs, LocalFilesystemURL srcURL, boolean move) throws IOException, InvalidModificationException, JSONException, NoModificationAllowedException, FileExistsException {
    // First, check to see that we can do it
    if (move && !srcFs.canRemoveFileAtLocalURL(srcURL)) {
        throw new NoModificationAllowedException("Cannot move file at source URL");
    }
    final LocalFilesystemURL destination = makeDestinationURL(newName, srcURL, destURL, srcURL.isDirectory);

    Uri srcNativeUri = srcFs.toNativeUri(srcURL);

    CordovaResourceApi.OpenForReadResult ofrr = resourceApi.openForRead(srcNativeUri);
    OutputStream os = null;
    try {
        os = getOutputStreamForURL(destination);
    } catch (IOException e) {
        ofrr.inputStream.close();
        throw e;
    }
    // Closes streams.
    resourceApi.copyResource(ofrr, os);

    if (move) {
        srcFs.removeFileAtLocalURL(srcURL);
    }
    return getEntryForLocalURL(destination);
}
 
Example #11
Source File: LocalFilesystem.java    From keemob with MIT License 6 votes vote down vote up
private void copyFile(Filesystem srcFs, LocalFilesystemURL srcURL, File destFile, boolean move) throws IOException, InvalidModificationException, NoModificationAllowedException {
    if (move) {
        String realSrcPath = srcFs.filesystemPathForURL(srcURL);
        if (realSrcPath != null) {
            File srcFile = new File(realSrcPath);
            if (srcFile.renameTo(destFile)) {
                return;
            }
            // Trying to rename the file failed.  Possibly because we moved across file system on the device.
        }
    }

    CordovaResourceApi.OpenForReadResult offr = resourceApi.openForRead(srcFs.toNativeUri(srcURL));
    copyResource(offr, new FileOutputStream(destFile));

    if (move) {
        srcFs.removeFileAtLocalURL(srcURL);
    }
}
 
Example #12
Source File: SystemWebViewClient.java    From app-icon with MIT License 6 votes vote down vote up
private static boolean needsSpecialsInAssetUrlFix(Uri uri) {
    if (CordovaResourceApi.getUriType(uri) != CordovaResourceApi.URI_TYPE_ASSET) {
        return false;
    }
    if (uri.getQuery() != null || uri.getFragment() != null) {
        return true;
    }

    if (!uri.toString().contains("%")) {
        return false;
    }

    switch(android.os.Build.VERSION.SDK_INT){
        case android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH:
        case android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1:
            return true;
    }
    return false;
}
 
Example #13
Source File: SystemWebViewClient.java    From BigDataPlatform with GNU General Public License v3.0 6 votes vote down vote up
private static boolean needsSpecialsInAssetUrlFix(Uri uri) {
    if (CordovaResourceApi.getUriType(uri) != CordovaResourceApi.URI_TYPE_ASSET) {
        return false;
    }
    if (uri.getQuery() != null || uri.getFragment() != null) {
        return true;
    }

    if (!uri.toString().contains("%")) {
        return false;
    }

    switch(android.os.Build.VERSION.SDK_INT){
        case android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH:
        case android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1:
            return true;
    }
    return false;
}
 
Example #14
Source File: SystemWebViewClient.java    From chappiecast with Mozilla Public License 2.0 6 votes vote down vote up
private static boolean needsSpecialsInAssetUrlFix(Uri uri) {
    if (CordovaResourceApi.getUriType(uri) != CordovaResourceApi.URI_TYPE_ASSET) {
        return false;
    }
    if (uri.getQuery() != null || uri.getFragment() != null) {
        return true;
    }

    if (!uri.toString().contains("%")) {
        return false;
    }

    switch(android.os.Build.VERSION.SDK_INT){
        case android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH:
        case android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1:
            return true;
    }
    return false;
}
 
Example #15
Source File: SystemWebViewClient.java    From cordova-plugin-intent with MIT License 6 votes vote down vote up
private static boolean needsSpecialsInAssetUrlFix(Uri uri) {
    if (CordovaResourceApi.getUriType(uri) != CordovaResourceApi.URI_TYPE_ASSET) {
        return false;
    }
    if (uri.getQuery() != null || uri.getFragment() != null) {
        return true;
    }

    if (!uri.toString().contains("%")) {
        return false;
    }

    switch(android.os.Build.VERSION.SDK_INT){
        case android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH:
        case android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1:
            return true;
    }
    return false;
}
 
Example #16
Source File: SystemWebViewClient.java    From a2cardboard with Apache License 2.0 6 votes vote down vote up
private static boolean needsSpecialsInAssetUrlFix(Uri uri) {
    if (CordovaResourceApi.getUriType(uri) != CordovaResourceApi.URI_TYPE_ASSET) {
        return false;
    }
    if (uri.getQuery() != null || uri.getFragment() != null) {
        return true;
    }

    if (!uri.toString().contains("%")) {
        return false;
    }

    switch(android.os.Build.VERSION.SDK_INT){
        case android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH:
        case android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1:
            return true;
    }
    return false;
}
 
Example #17
Source File: Filesystem.java    From reacteu-app with MIT License 6 votes vote down vote up
public JSONObject copyFileToURL(LocalFilesystemURL destURL, String newName,
        Filesystem srcFs, LocalFilesystemURL srcURL, boolean move) throws IOException, InvalidModificationException, JSONException, NoModificationAllowedException, FileExistsException {
    // First, check to see that we can do it
    if (move && !srcFs.canRemoveFileAtLocalURL(srcURL)) {
        throw new NoModificationAllowedException("Cannot move file at source URL");
    }
    final LocalFilesystemURL destination = makeDestinationURL(newName, srcURL, destURL, srcURL.isDirectory);

    Uri srcNativeUri = srcFs.toNativeUri(srcURL);

    CordovaResourceApi.OpenForReadResult ofrr = resourceApi.openForRead(srcNativeUri);
    OutputStream os = null;
    try {
        os = getOutputStreamForURL(destination);
    } catch (IOException e) {
        ofrr.inputStream.close();
        throw e;
    }
    // Closes streams.
    resourceApi.copyResource(ofrr, os);

    if (move) {
        srcFs.removeFileAtLocalURL(srcURL);
    }
    return getEntryForLocalURL(destination);
}
 
Example #18
Source File: LocalFilesystem.java    From reacteu-app with MIT License 6 votes vote down vote up
private void copyFile(Filesystem srcFs, LocalFilesystemURL srcURL, File destFile, boolean move) throws IOException, InvalidModificationException, NoModificationAllowedException {
    if (move) {
        String realSrcPath = srcFs.filesystemPathForURL(srcURL);
        if (realSrcPath != null) {
            File srcFile = new File(realSrcPath);
            if (srcFile.renameTo(destFile)) {
                return;
            }
            // Trying to rename the file failed.  Possibly because we moved across file system on the device.
        }
    }

    CordovaResourceApi.OpenForReadResult offr = resourceApi.openForRead(srcFs.toNativeUri(srcURL));
    copyResource(offr, new FileOutputStream(destFile));

    if (move) {
        srcFs.removeFileAtLocalURL(srcURL);
    }
}
 
Example #19
Source File: SystemWebViewClient.java    From cordova-plugin-app-update-demo with MIT License 6 votes vote down vote up
private static boolean needsSpecialsInAssetUrlFix(Uri uri) {
    if (CordovaResourceApi.getUriType(uri) != CordovaResourceApi.URI_TYPE_ASSET) {
        return false;
    }
    if (uri.getQuery() != null || uri.getFragment() != null) {
        return true;
    }

    if (!uri.toString().contains("%")) {
        return false;
    }

    switch(android.os.Build.VERSION.SDK_INT){
        case android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH:
        case android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1:
            return true;
    }
    return false;
}
 
Example #20
Source File: X5WebViewClient.java    From cordova-plugin-x5engine-webview with Apache License 2.0 6 votes vote down vote up
private static boolean needsSpecialsInAssetUrlFix(Uri uri) {
    if (CordovaResourceApi.getUriType(uri) != CordovaResourceApi.URI_TYPE_ASSET) {
        return false;
    }
    if (uri.getQuery() != null || uri.getFragment() != null) {
        return true;
    }

    if (!uri.toString().contains("%")) {
        return false;
    }

    switch(Build.VERSION.SDK_INT){
        case Build.VERSION_CODES.ICE_CREAM_SANDWICH:
        case Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1:
            return true;
    }
    return false;
}
 
Example #21
Source File: Filesystem.java    From keemob with MIT License 6 votes vote down vote up
public JSONObject copyFileToURL(LocalFilesystemURL destURL, String newName,
        Filesystem srcFs, LocalFilesystemURL srcURL, boolean move) throws IOException, InvalidModificationException, JSONException, NoModificationAllowedException, FileExistsException {
    // First, check to see that we can do it
    if (move && !srcFs.canRemoveFileAtLocalURL(srcURL)) {
        throw new NoModificationAllowedException("Cannot move file at source URL");
    }
    final LocalFilesystemURL destination = makeDestinationURL(newName, srcURL, destURL, srcURL.isDirectory);

    Uri srcNativeUri = srcFs.toNativeUri(srcURL);

    CordovaResourceApi.OpenForReadResult ofrr = resourceApi.openForRead(srcNativeUri);
    OutputStream os = null;
    try {
        os = getOutputStreamForURL(destination);
    } catch (IOException e) {
        ofrr.inputStream.close();
        throw e;
    }
    // Closes streams.
    resourceApi.copyResource(ofrr, os);

    if (move) {
        srcFs.removeFileAtLocalURL(srcURL);
    }
    return getEntryForLocalURL(destination);
}
 
Example #22
Source File: LocalFilesystem.java    From reacteu-app with MIT License 5 votes vote down vote up
private static void copyResource(CordovaResourceApi.OpenForReadResult input, OutputStream outputStream) throws IOException {
    try {
        InputStream inputStream = input.inputStream;
        if (inputStream instanceof FileInputStream && outputStream instanceof FileOutputStream) {
            FileChannel inChannel = ((FileInputStream)input.inputStream).getChannel();
            FileChannel outChannel = ((FileOutputStream)outputStream).getChannel();
            long offset = 0;
            long length = input.length;
            if (input.assetFd != null) {
                offset = input.assetFd.getStartOffset();
            }
            // transferFrom()'s 2nd arg is a relative position. Need to set the absolute
            // position first.
            inChannel.position(offset);
            outChannel.transferFrom(inChannel, 0, length);
        } else {
            final int BUFFER_SIZE = 8192;
            byte[] buffer = new byte[BUFFER_SIZE];

            for (;;) {
                int bytesRead = inputStream.read(buffer, 0, BUFFER_SIZE);

                if (bytesRead <= 0) {
                    break;
                }
                outputStream.write(buffer, 0, bytesRead);
            }
        }
    } finally {
        input.inputStream.close();
        if (outputStream != null) {
            outputStream.close();
        }
    }
}
 
Example #23
Source File: SystemWebViewEngine.java    From xmall with MIT License 5 votes vote down vote up
@Override
   public void init(CordovaWebView parentWebView, CordovaInterface cordova, CordovaWebViewEngine.Client client,
             CordovaResourceApi resourceApi, PluginManager pluginManager,
             NativeToJsMessageQueue nativeToJsMessageQueue) {
       if (this.cordova != null) {
           throw new IllegalStateException();
       }
       // Needed when prefs are not passed by the constructor
       if (preferences == null) {
           preferences = parentWebView.getPreferences();
       }
       this.parentWebView = parentWebView;
       this.cordova = cordova;
       this.client = client;
       this.resourceApi = resourceApi;
       this.pluginManager = pluginManager;
       this.nativeToJsMessageQueue = nativeToJsMessageQueue;
       webView.init(this, cordova);

       initWebViewSettings();

       nativeToJsMessageQueue.addBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode.OnlineEventsBridgeModeDelegate() {
           @Override
           public void setNetworkAvailable(boolean value) {
               //sometimes this can be called after calling webview.destroy() on destroy()
               //thus resulting in a NullPointerException
               if(webView!=null) {
                  webView.setNetworkAvailable(value); 
               }
           }
           @Override
           public void runOnUiThread(Runnable r) {
               SystemWebViewEngine.this.cordova.getActivity().runOnUiThread(r);
           }
       }));
       if(Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2)
           nativeToJsMessageQueue.addBridgeMode(new NativeToJsMessageQueue.EvalBridgeMode(this, cordova));
bridge = new CordovaBridge(pluginManager, nativeToJsMessageQueue);
       exposeJsInterface(webView, bridge);
   }
 
Example #24
Source File: SystemWebViewClient.java    From ultimate-cordova-webview-app with MIT License 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
    try {
        // Check the against the whitelist and lock out access to the WebView directory
        // Changing this will cause problems for your application
        if (!parentEngine.pluginManager.shouldAllowRequest(url)) {
            LOG.w(TAG, "URL blocked by whitelist: " + url);
            // Results in a 404.
            return new WebResourceResponse("text/plain", "UTF-8", null);
        }

        CordovaResourceApi resourceApi = parentEngine.resourceApi;
        Uri origUri = Uri.parse(url);
        // Allow plugins to intercept WebView requests.
        Uri remappedUri = resourceApi.remapUri(origUri);

        if (!origUri.equals(remappedUri) || needsSpecialsInAssetUrlFix(origUri) || needsKitKatContentUrlFix(origUri)) {
            CordovaResourceApi.OpenForReadResult result = resourceApi.openForRead(remappedUri, true);
            return new WebResourceResponse(result.mimeType, "UTF-8", result.inputStream);
        }
        // If we don't need to special-case the request, let the browser load it.
        return null;
    } catch (IOException e) {
        if (!(e instanceof FileNotFoundException)) {
            LOG.e(TAG, "Error occurred while loading a file (returning a 404).", e);
        }
        // Results in a 404.
        return new WebResourceResponse("text/plain", "UTF-8", null);
    }
}
 
Example #25
Source File: XWalkWebViewEngine.java    From cordova-crosswalk-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void init(CordovaWebView parentWebView, CordovaInterface cordova, CordovaWebViewEngine.Client client,
                 CordovaResourceApi resourceApi, PluginManager pluginManager,
                 NativeToJsMessageQueue nativeToJsMessageQueue) {
    if (this.cordova != null) {
        throw new IllegalStateException();
    }
    this.parentWebView = parentWebView;
    this.cordova = cordova;
    this.client = client;
    this.resourceApi = resourceApi;
    this.pluginManager = pluginManager;
    this.nativeToJsMessageQueue = nativeToJsMessageQueue;

    CordovaPlugin activityDelegatePlugin = new CordovaPlugin() {
        @Override
        public void onResume(boolean multitasking) {
            activityDelegate.onResume();
        }
    };
    pluginManager.addService(new PluginEntry("XWalkActivityDelegate", activityDelegatePlugin));

    webView.init(this);

    nativeToJsMessageQueue.addBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode(
            new NativeToJsMessageQueue.OnlineEventsBridgeMode.OnlineEventsBridgeModeDelegate() {
        @Override
        public void setNetworkAvailable(boolean value) {
            webView.setNetworkAvailable(value);
        }
        @Override
        public void runOnUiThread(Runnable r) {
            XWalkWebViewEngine.this.cordova.getActivity().runOnUiThread(r);
        }
    }));
    nativeToJsMessageQueue.addBridgeMode(new NativeToJsMessageQueue.EvalBridgeMode(this, cordova));
    bridge = new CordovaBridge(pluginManager, nativeToJsMessageQueue);
}
 
Example #26
Source File: ContentFilesystem.java    From reader with MIT License 5 votes vote down vote up
@Override
public JSONObject copyFileToURL(LocalFilesystemURL destURL, String newName,
		Filesystem srcFs, LocalFilesystemURL srcURL, boolean move)
                   throws IOException, InvalidModificationException, JSONException,
                   NoModificationAllowedException, FileExistsException {
       if (LocalFilesystem.class.isInstance(srcFs)) {
           /* Same FS, we can shortcut with CordovaResourceApi operations */
           // Figure out where we should be copying to
           final LocalFilesystemURL destinationURL = makeDestinationURL(newName, srcURL, destURL);

           OutputStream os = resourceApi.openOutputStream(destURL.URL);
           CordovaResourceApi.OpenForReadResult ofrr = resourceApi.openForRead(srcURL.URL);
           if (move && !srcFs.canRemoveFileAtLocalURL(srcURL)) {
               throw new NoModificationAllowedException("Cannot move file at source URL");
           }
           try {
               resourceApi.copyResource(ofrr, os);
           } catch (IOException e) {
               throw new IOException("Cannot read file at source URL");
           }
           if (move) {
               srcFs.removeFileAtLocalURL(srcURL);
           }
           return makeEntryForURL(destinationURL, false, destinationURL.URL.toString());
       } else {
           // Need to copy the hard way
           return super.copyFileToURL(destURL, newName, srcFs, srcURL, move);
	}
}
 
Example #27
Source File: SystemWebViewEngine.java    From app-icon with MIT License 5 votes vote down vote up
@Override
   public void init(CordovaWebView parentWebView, CordovaInterface cordova, CordovaWebViewEngine.Client client,
             CordovaResourceApi resourceApi, PluginManager pluginManager,
             NativeToJsMessageQueue nativeToJsMessageQueue) {
       if (this.cordova != null) {
           throw new IllegalStateException();
       }
       // Needed when prefs are not passed by the constructor
       if (preferences == null) {
           preferences = parentWebView.getPreferences();
       }
       this.parentWebView = parentWebView;
       this.cordova = cordova;
       this.client = client;
       this.resourceApi = resourceApi;
       this.pluginManager = pluginManager;
       this.nativeToJsMessageQueue = nativeToJsMessageQueue;
       webView.init(this, cordova);

       initWebViewSettings();

       nativeToJsMessageQueue.addBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode.OnlineEventsBridgeModeDelegate() {
           @Override
           public void setNetworkAvailable(boolean value) {
               webView.setNetworkAvailable(value);
           }
           @Override
           public void runOnUiThread(Runnable r) {
               SystemWebViewEngine.this.cordova.getActivity().runOnUiThread(r);
           }
       }));
       if(Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2)
           nativeToJsMessageQueue.addBridgeMode(new NativeToJsMessageQueue.EvalBridgeMode(this, cordova));
bridge = new CordovaBridge(pluginManager, nativeToJsMessageQueue);
       exposeJsInterface(webView, bridge);
   }
 
Example #28
Source File: X5WebViewEngine.java    From cordova-plugin-x5engine-webview with Apache License 2.0 5 votes vote down vote up
@Override
public void init(CordovaWebView parentWebView, CordovaInterface cordova, Client client,
          CordovaResourceApi resourceApi, PluginManager pluginManager,
          NativeToJsMessageQueue nativeToJsMessageQueue) {
    if (this.cordova != null) {
        throw new IllegalStateException();
    }
    // Needed when prefs are not passed by the constructor
    if (preferences == null) {
        preferences = parentWebView.getPreferences();
    }
    this.parentWebView = parentWebView;
    this.cordova = cordova;
    this.client = client;
    this.resourceApi = resourceApi;
    this.pluginManager = pluginManager;
    this.nativeToJsMessageQueue = nativeToJsMessageQueue;
    webView.init(this, cordova);

    initWebViewSettings();

    nativeToJsMessageQueue.addBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode.OnlineEventsBridgeModeDelegate() {
        @Override
        public void setNetworkAvailable(boolean value) {
            webView.setNetworkAvailable(value);
        }
        @Override
        public void runOnUiThread(Runnable r) {
            X5WebViewEngine.this.cordova.getActivity().runOnUiThread(r);
        }
    }));
    bridge = new CordovaBridge(pluginManager, nativeToJsMessageQueue);
    exposeJsInterface(webView, bridge);
}
 
Example #29
Source File: ContentFilesystem.java    From jpHolo with MIT License 5 votes vote down vote up
@Override
public JSONObject copyFileToURL(LocalFilesystemURL destURL, String newName,
		Filesystem srcFs, LocalFilesystemURL srcURL, boolean move)
                   throws IOException, InvalidModificationException, JSONException,
                   NoModificationAllowedException, FileExistsException {
       if (LocalFilesystem.class.isInstance(srcFs)) {
           /* Same FS, we can shortcut with CordovaResourceApi operations */
           // Figure out where we should be copying to
           final LocalFilesystemURL destinationURL = makeDestinationURL(newName, srcURL, destURL);

           OutputStream os = resourceApi.openOutputStream(destURL.URL);
           CordovaResourceApi.OpenForReadResult ofrr = resourceApi.openForRead(srcURL.URL);
           if (move && !srcFs.canRemoveFileAtLocalURL(srcURL)) {
               throw new NoModificationAllowedException("Cannot move file at source URL");
           }
           try {
               resourceApi.copyResource(ofrr, os);
           } catch (IOException e) {
               throw new IOException("Cannot read file at source URL");
           }
           if (move) {
               srcFs.removeFileAtLocalURL(srcURL);
           }
           return makeEntryForURL(destinationURL, false, destinationURL.URL.toString());
       } else {
           // Need to copy the hard way
           return super.copyFileToURL(destURL, newName, srcFs, srcURL, move);
	}
}
 
Example #30
Source File: X5WebViewEngine.java    From x5webview-cordova-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void init(CordovaWebView parentWebView, CordovaInterface cordova, Client client,
          CordovaResourceApi resourceApi, PluginManager pluginManager,
          NativeToJsMessageQueue nativeToJsMessageQueue) {
    if (this.cordova != null) {
        throw new IllegalStateException();
    }
    // Needed when prefs are not passed by the constructor
    if (preferences == null) {
        preferences = parentWebView.getPreferences();
    }
    this.parentWebView = parentWebView;
    this.cordova = cordova;
    this.client = client;
    this.resourceApi = resourceApi;
    this.pluginManager = pluginManager;
    this.nativeToJsMessageQueue = nativeToJsMessageQueue;
    webView.init(this, cordova);

    initWebViewSettings();

    nativeToJsMessageQueue.addBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode.OnlineEventsBridgeModeDelegate() {
        @Override
        public void setNetworkAvailable(boolean value) {
            webView.setNetworkAvailable(value);
        }
        @Override
        public void runOnUiThread(Runnable r) {
            X5WebViewEngine.this.cordova.getActivity().runOnUiThread(r);
        }
    }));
    bridge = new CordovaBridge(pluginManager, nativeToJsMessageQueue);
    exposeJsInterface(webView, bridge);
}