@Override public Uri remapChromeUri(Uri uri) { Uri ret = Uri.parse(replacePatternsInLine(uri.toString())); if (ret.getPath().endsWith(".css") || uri.getPath().equals("manifest.json")) { Uri fileUri = Uri.parse("file:///android_asset/www" + uri.getPath()); fileUri = webView.getResourceApi().remapUri(fileUri); try { OpenForReadResult readResult = webView.getResourceApi().openForRead(fileUri, true); try { byte[] newData = replaceI18nPlaceholders(readResult.inputStream); return Uri.parse("data:text/css;charset=utf-8;base64," + Base64.encode(newData)); } finally { if (readResult != null) { readResult.inputStream.close(); } } } catch (IOException e) { e.printStackTrace(); } } return ret; }
private JSONObject getStorage(String namespace) throws IOException, JSONException { JSONObject oldMap = new JSONObject(); CordovaResourceApi resourceApi = webView.getResourceApi(); try { OpenForReadResult readResult = resourceApi.openForRead(getStorageFile(namespace)); ByteArrayOutputStream readBytes = new ByteArrayOutputStream((int)readResult.length); resourceApi.copyResource(readResult, readBytes); byte[] bytes = readBytes.toByteArray(); String content = (new String(bytes)).trim(); if (content.length() > 0) { oldMap = new JSONObject(content); } } catch (FileNotFoundException e) { //Suppress the file not found exception } return oldMap; }
@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); } }
@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); } }
@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); } }
@Override public WebResourceResponse shouldInterceptLoadRequest(XWalkView view, String url) { try { // Check the against the white-list. if ((url.startsWith("http:") || url.startsWith("https:")) && !appView.getWhitelist().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); } }
@Override public WebResourceResponse shouldInterceptLoadRequest(XWalkView 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); } }
@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); } }
@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); } }
@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); } }