List of usage examples for org.apache.cordova FileHelper getMimeType
public static String getMimeType(String uriString, CordovaInterface cordova)
From source file:com.google.cordova.ChromeExtensionURLs.java
License:Open Source License
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override/*from w ww .j a v a 2s . c o m*/ public WebResourceResponse shouldInterceptRequest(String url) { NavigableSet<Integer> pluginPrioritySet = registeredPlugins.navigableKeySet(); for (Integer pluginPriority : pluginPrioritySet) { RequestModifyInterface plugin = registeredPlugins.get(pluginPriority); if (plugin != null) { url = plugin.modifyNewRequestUrl(url); } } String mimetype = FileHelper.getMimeType(url, this.cordova); String encoding = null; if (mimetype != null && mimetype.startsWith("text/")) { encoding = "UTF-8"; } InputStream is = null; String filePath = Uri.parse(url).getPath(); if ("/chrome-content-loaded".equals(filePath)) { is = new ByteArrayInputStream( "Object.defineProperty(document, 'readyState', {get: function() { return 'loading'}, configurable: true });" .getBytes()); } else { try { is = this.cordova.getActivity().getAssets().open("www" + filePath); } catch (IOException ioe) { return null; } } for (Integer pluginPriority : pluginPrioritySet) { RequestModifyInterface plugin = registeredPlugins.get(pluginPriority); if (plugin != null) { is = plugin.modifyResponseInputStream(url, is); } } return new WebResourceResponse(mimetype, encoding, is); }