org.apache.cordova.CordovaResourceApi.OpenForReadResult Java Examples
The following examples show how to use
org.apache.cordova.CordovaResourceApi.OpenForReadResult.
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: IceCreamCordovaWebViewClient.java From L.TileLayer.Cordova with MIT License | 5 votes |
@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 (isUrlHarmful(url)) { LOG.w(TAG, "URL blocked by whitelist: " + url); // Results in a 404. return new WebResourceResponse("text/plain", "UTF-8", null); } CordovaResourceApi resourceApi = appView.getResourceApi(); Uri origUri = Uri.parse(url); // Allow plugins to intercept WebView requests. Uri remappedUri = resourceApi.remapUri(origUri); if (!origUri.equals(remappedUri) || needsSpecialsInAssetUrlFix(origUri) || needsKitKatContentUrlFix(origUri)) { 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("IceCreamCordovaWebViewClient", "Error occurred while loading a file (returning a 404).", e); } // Results in a 404. return new WebResourceResponse("text/plain", "UTF-8", null); } }
Example #2
Source File: IceCreamCordovaWebViewClient.java From IoTgo_Android_App with MIT License | 5 votes |
@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 (isUrlHarmful(url)) { LOG.w(TAG, "URL blocked by whitelist: " + url); // Results in a 404. return new WebResourceResponse("text/plain", "UTF-8", null); } CordovaResourceApi resourceApi = appView.getResourceApi(); Uri origUri = Uri.parse(url); // Allow plugins to intercept WebView requests. Uri remappedUri = resourceApi.remapUri(origUri); if (!origUri.equals(remappedUri) || needsSpecialsInAssetUrlFix(origUri) || needsKitKatContentUrlFix(origUri)) { 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("IceCreamCordovaWebViewClient", "Error occurred while loading a file (returning a 404).", e); } // Results in a 404. return new WebResourceResponse("text/plain", "UTF-8", null); } }
Example #3
Source File: IceCreamCordovaWebViewClient.java From bluemix-parking-meter with MIT License | 5 votes |
@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 (isUrlHarmful(url)) { LOG.w(TAG, "URL blocked by whitelist: " + url); // Results in a 404. return new WebResourceResponse("text/plain", "UTF-8", null); } CordovaResourceApi resourceApi = appView.getResourceApi(); Uri origUri = Uri.parse(url); // Allow plugins to intercept WebView requests. Uri remappedUri = resourceApi.remapUri(origUri); if (!origUri.equals(remappedUri) || needsSpecialsInAssetUrlFix(origUri) || needsKitKatContentUrlFix(origUri)) { 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("IceCreamCordovaWebViewClient", "Error occurred while loading a file (returning a 404).", e); } // Results in a 404. return new WebResourceResponse("text/plain", "UTF-8", null); } }
Example #4
Source File: XWalkCordovaResourceClient.java From cordova-crosswalk-engine with Apache License 2.0 | 5 votes |
@Override public WebResourceResponse shouldInterceptLoadRequest(XWalkView view, String url) { try { // Check the against the white-list. 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)) { 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 #5
Source File: IceCreamCordovaWebViewClient.java From reader with MIT License | 5 votes |
@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 (isUrlHarmful(url)) { LOG.w(TAG, "URL blocked by whitelist: " + url); // Results in a 404. return new WebResourceResponse("text/plain", "UTF-8", null); } CordovaResourceApi resourceApi = appView.getResourceApi(); Uri origUri = Uri.parse(url); // Allow plugins to intercept WebView requests. Uri remappedUri = resourceApi.remapUri(origUri); if (!origUri.equals(remappedUri) || needsSpecialsInAssetUrlFix(origUri) || needsKitKatContentUrlFix(origUri)) { 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("IceCreamCordovaWebViewClient", "Error occurred while loading a file (returning a 404).", e); } // Results in a 404. return new WebResourceResponse("text/plain", "UTF-8", null); } }
Example #6
Source File: IceCreamCordovaWebViewClient.java From reader with MIT License | 5 votes |
@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 (isUrlHarmful(url)) { LOG.w(TAG, "URL blocked by whitelist: " + url); // Results in a 404. return new WebResourceResponse("text/plain", "UTF-8", null); } CordovaResourceApi resourceApi = appView.getResourceApi(); Uri origUri = Uri.parse(url); // Allow plugins to intercept WebView requests. Uri remappedUri = resourceApi.remapUri(origUri); if (!origUri.equals(remappedUri) || needsSpecialsInAssetUrlFix(origUri) || needsKitKatContentUrlFix(origUri)) { 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("IceCreamCordovaWebViewClient", "Error occurred while loading a file (returning a 404).", e); } // Results in a 404. return new WebResourceResponse("text/plain", "UTF-8", null); } }
Example #7
Source File: CordovaResourceApiTest.java From cordova-amazon-fireos with Apache License 2.0 | 5 votes |
public void testDataUriPlain() throws IOException { Uri uri = Uri.parse("data:text/plain;charset=utf-8,pa%20ss"); OpenForReadResult readResult = resourceApi.openForRead(uri); assertEquals("text/plain", readResult.mimeType); String data = new Scanner(readResult.inputStream, "UTF-8").useDelimiter("\\A").next(); assertEquals("pa ss", data); }
Example #8
Source File: CordovaResourceApiTest.java From cordova-amazon-fireos with Apache License 2.0 | 5 votes |
public void testDataUriBase64() throws IOException { Uri uri = Uri.parse("data:text/js;charset=utf-8;base64,cGFzcw=="); OpenForReadResult readResult = resourceApi.openForRead(uri); assertEquals("text/js", readResult.mimeType); String data = new Scanner(readResult.inputStream, "UTF-8").useDelimiter("\\A").next(); assertEquals("pass", data); }
Example #9
Source File: IceCreamCordovaWebViewClient.java From cordova-amazon-fireos with Apache License 2.0 | 5 votes |
@Override public AmazonWebResourceResponse shouldInterceptRequest(AmazonWebView 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 (isUrlHarmful(url)) { LOG.w(TAG, "URL blocked by whitelist: " + url); // Results in a 404. return new AmazonWebResourceResponse("text/plain", "UTF-8", null); } CordovaResourceApi resourceApi = appView.getResourceApi(); Uri origUri = Uri.parse(url); // Allow plugins to intercept AmazonWebView requests. Uri remappedUri = resourceApi.remapUri(origUri); if (!origUri.equals(remappedUri) || needsSpecialsInAssetUrlFix(origUri) || needsKitKatContentUrlFix(origUri)) { OpenForReadResult result = resourceApi.openForRead(remappedUri, true); return new AmazonWebResourceResponse(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("IceCreamCordovaWebViewClient", "Error occurred while loading a file (returning a 404).", e); } // Results in a 404. return new AmazonWebResourceResponse("text/plain", "UTF-8", null); } }
Example #10
Source File: IceCreamCordovaWebViewClient.java From phonegapbootcampsite with MIT License | 5 votes |
@Override public WebResourceResponse shouldInterceptRequest(WebView view, String url) { try { // Check the against the white-list. if ((url.startsWith("http:") || url.startsWith("https:")) && !Config.isUrlWhiteListed(url)) { LOG.w(TAG, "URL blocked by whitelist: " + url); // Results in a 404. return new WebResourceResponse("text/plain", "UTF-8", null); } CordovaResourceApi resourceApi = appView.getResourceApi(); Uri origUri = Uri.parse(url); // Allow plugins to intercept WebView requests. Uri remappedUri = resourceApi.remapUri(origUri); if (!origUri.equals(remappedUri) || needsSpecialsInAssetUrlFix(origUri)) { 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("IceCreamCordovaWebViewClient", "Error occurred while loading a file (returning a 404).", e); } // Results in a 404. return new WebResourceResponse("text/plain", "UTF-8", null); } }
Example #11
Source File: IceCreamCordovaWebViewClient.java From CordovaYoutubeVideoPlayer with MIT License | 5 votes |
@Override public WebResourceResponse shouldInterceptRequest(WebView view, String url) { try { // Check the against the white-list. if ((url.startsWith("http:") || url.startsWith("https:")) && !Config.isUrlWhiteListed(url)) { LOG.w(TAG, "URL blocked by whitelist: " + url); // Results in a 404. return new WebResourceResponse("text/plain", "UTF-8", null); } CordovaResourceApi resourceApi = appView.getResourceApi(); Uri origUri = Uri.parse(url); // Allow plugins to intercept WebView requests. Uri remappedUri = resourceApi.remapUri(origUri); if (!origUri.equals(remappedUri) || needsSpecialsInAssetUrlFix(origUri) || needsKitKatContentUrlFix(origUri)) { 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("IceCreamCordovaWebViewClient", "Error occurred while loading a file (returning a 404).", e); } // Results in a 404. return new WebResourceResponse("text/plain", "UTF-8", null); } }
Example #12
Source File: IceCreamCordovaWebViewClient.java From wildfly-samples with MIT License | 5 votes |
@Override public WebResourceResponse shouldInterceptRequest(WebView view, String url) { try { // Check the against the white-list. if ((url.startsWith("http:") || url.startsWith("https:")) && !Config.isUrlWhiteListed(url)) { LOG.w(TAG, "URL blocked by whitelist: " + url); // Results in a 404. return new WebResourceResponse("text/plain", "UTF-8", null); } CordovaResourceApi resourceApi = appView.getResourceApi(); Uri origUri = Uri.parse(url); // Allow plugins to intercept WebView requests. Uri remappedUri = resourceApi.remapUri(origUri); if (!origUri.equals(remappedUri) || needsSpecialsInAssetUrlFix(origUri)) { 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("IceCreamCordovaWebViewClient", "Error occurred while loading a file (returning a 404).", e); } // Results in a 404. return new WebResourceResponse("text/plain", "UTF-8", null); } }
Example #13
Source File: IceCreamCordovaWebViewClient.java From phonegap-plugin-loading-spinner with Apache License 2.0 | 5 votes |
@Override public WebResourceResponse shouldInterceptRequest(WebView view, String url) { try { // Check the against the white-list. if ((url.startsWith("http:") || url.startsWith("https:")) && !Config.isUrlWhiteListed(url)) { LOG.w(TAG, "URL blocked by whitelist: " + url); // Results in a 404. return new WebResourceResponse("text/plain", "UTF-8", null); } CordovaResourceApi resourceApi = appView.getResourceApi(); Uri origUri = Uri.parse(url); // Allow plugins to intercept WebView requests. Uri remappedUri = resourceApi.remapUri(origUri); if (!origUri.equals(remappedUri) || needsSpecialsInAssetUrlFix(origUri)) { 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("IceCreamCordovaWebViewClient", "Error occurred while loading a file (returning a 404).", e); } // Results in a 404. return new WebResourceResponse("text/plain", "UTF-8", null); } }
Example #14
Source File: CordovaResourceApiTest.java From crosswalk-cordova-android with Apache License 2.0 | 5 votes |
public void testDataUriPlain() throws IOException { Uri uri = Uri.parse("data:text/plain;charset=utf-8,pa%20ss"); OpenForReadResult readResult = resourceApi.openForRead(uri); assertEquals("text/plain", readResult.mimeType); String data = new Scanner(readResult.inputStream, "UTF-8").useDelimiter("\\A").next(); assertEquals("pa ss", data); }
Example #15
Source File: CordovaResourceApiTest.java From crosswalk-cordova-android with Apache License 2.0 | 5 votes |
public void testDataUriBase64() throws IOException { Uri uri = Uri.parse("data:text/js;charset=utf-8;base64,cGFzcw=="); OpenForReadResult readResult = resourceApi.openForRead(uri); assertEquals("text/js", readResult.mimeType); String data = new Scanner(readResult.inputStream, "UTF-8").useDelimiter("\\A").next(); assertEquals("pass", data); }
Example #16
Source File: IceCreamCordovaWebViewClient.java From crosswalk-cordova-android with Apache License 2.0 | 5 votes |
@Override public WebResourceResponse shouldInterceptLoadRequest(XWalkView 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 (isUrlHarmful(url)) { LOG.w(TAG, "URL blocked by whitelist: " + url); // Results in a 404. return new WebResourceResponse("text/plain", "UTF-8", null); } CordovaResourceApi resourceApi = appView.getResourceApi(); Uri origUri = Uri.parse(url); // Allow plugins to intercept WebView requests. Uri remappedUri = resourceApi.remapUri(origUri); if (!origUri.equals(remappedUri) || needsSpecialsInAssetUrlFix(origUri) || needsKitKatContentUrlFix(origUri)) { 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("IceCreamCordovaWebViewClient", "Error occurred while loading a file (returning a 404).", e); } // Results in a 404. return new WebResourceResponse("text/plain", "UTF-8", null); } }