Use special domain with standard http(s) instead of custom protocol

(Avoids warning about insecure content when using https)
This commit is contained in:
fkloft 2014-01-04 23:13:37 +01:00
parent 7d10231aa4
commit b1bed90997
2 changed files with 35 additions and 26 deletions

View File

@ -27,6 +27,8 @@ public class IITC_FileManager {
"script.appendChild(document.createTextNode('('+ wrapper +')('+JSON.stringify(info)+');'));\n" "script.appendChild(document.createTextNode('('+ wrapper +')('+JSON.stringify(info)+');'));\n"
+ "(document.body || document.head || document.documentElement).appendChild(script);"; + "(document.body || document.head || document.documentElement).appendChild(script);";
public static final String DOMAIN = ".iitcm.localhost";
public static HashMap<String, String> getScriptInfo(String js) { public static HashMap<String, String> getScriptInfo(String js) {
HashMap<String, String> map = new HashMap<String, String>(); HashMap<String, String> map = new HashMap<String, String>();
String header = ""; String header = "";
@ -183,16 +185,19 @@ public class IITC_FileManager {
return getScriptInfo(stream).get("version"); return getScriptInfo(stream).get("version");
} }
public WebResourceResponse getResponse(String url) { public WebResourceResponse getResponse(Uri uri) {
Uri uri = Uri.parse(url);
String host = uri.getHost(); String host = uri.getHost();
if (!host.endsWith(DOMAIN))
return EMPTY;
host = host.substring(0, host.length() - DOMAIN.length());
if ("script".equals(host)) if ("script".equals(host))
return getScript(uri); return getScript(uri);
if ("user-plugin".equals(host)) if ("user-plugin".equals(host))
return getUserPlugin(uri); return getUserPlugin(uri);
Log.e("could not generate response for url: " + url); Log.e("could not generate response for url: " + uri);
return EMPTY; return EMPTY;
} }
} }

View File

@ -22,8 +22,8 @@ public class IITC_WebViewClient extends WebViewClient {
private static final ByteArrayInputStream STYLE = new ByteArrayInputStream( private static final ByteArrayInputStream STYLE = new ByteArrayInputStream(
"body, #dashboard_container, #map_canvas { background: #000 !important; }" "body, #dashboard_container, #map_canvas { background: #000 !important; }"
.getBytes()); .getBytes());
private static final ByteArrayInputStream EMPTY = new ByteArrayInputStream( private static final ByteArrayInputStream EMPTY = new ByteArrayInputStream("".getBytes());
"".getBytes()); private static final String DOMAIN = IITC_FileManager.DOMAIN;
private String mIitcPath; private String mIitcPath;
private boolean mIitcInjected = false; private boolean mIitcInjected = false;
@ -63,7 +63,7 @@ public class IITC_WebViewClient extends WebViewClient {
private void loadScripts(IITC_WebView view) { private void loadScripts(IITC_WebView view) {
List<String> scripts = new LinkedList<String>(); List<String> scripts = new LinkedList<String>();
scripts.add("script/total-conversion-build.user.js"); scripts.add("script" + DOMAIN + "/total-conversion-build.user.js");
// get the plugin preferences // get the plugin preferences
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(mIitc); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(mIitc);
@ -74,9 +74,9 @@ public class IITC_WebViewClient extends WebViewClient {
String plugin = entry.getKey(); String plugin = entry.getKey();
if (plugin.endsWith(".user.js") && entry.getValue().toString().equals("true")) { if (plugin.endsWith(".user.js") && entry.getValue().toString().equals("true")) {
if (plugin.startsWith(mIitcPath)) { if (plugin.startsWith(mIitcPath)) {
scripts.add("user-plugin" + plugin); scripts.add("user-plugin" + DOMAIN + plugin);
} else { } else {
scripts.add("script/plugins/" + plugin); scripts.add("script" + DOMAIN + "/plugins/" + plugin);
} }
} }
} }
@ -87,7 +87,7 @@ public class IITC_WebViewClient extends WebViewClient {
} }
String js = "(function(){['" + TextUtils.join("','", scripts) + "'].forEach(function(src) {" + String js = "(function(){['" + TextUtils.join("','", scripts) + "'].forEach(function(src) {" +
"var script = document.createElement('script');script.src = 'iitcm://'+src;" + "var script = document.createElement('script');script.src = '//'+src;" +
"(document.body || document.head || document.documentElement).appendChild(script);" + "(document.body || document.head || document.documentElement).appendChild(script);" +
"});})();"; "});})();";
@ -104,11 +104,11 @@ public class IITC_WebViewClient extends WebViewClient {
// ((IITC_Mobile) mContext).onReceivedLoginRequest(this, view, realm, account, args); // ((IITC_Mobile) mContext).onReceivedLoginRequest(this, view, realm, account, args);
} }
// Check every external resource if its okay to load it and maybe replace /**
// it * Check every external resource if it's okay to load it and maybe replace it with our own content.
// with our own content. This is used to block loading Niantic resources * This is used to block loading Niantic resources which arent required and to inject IITC early into the site.
// which arent required and to inject IITC early into the site. * via http://stackoverflow.com/a/8274881/1684530
// via http://stackoverflow.com/a/8274881/1684530 */
@Override @Override
public WebResourceResponse shouldInterceptRequest(final WebView view, String url) { public WebResourceResponse shouldInterceptRequest(final WebView view, String url) {
// if any tiles are requested, handle it with IITC_TileManager // if any tiles are requested, handle it with IITC_TileManager
@ -125,14 +125,14 @@ public class IITC_WebViewClient extends WebViewClient {
e.printStackTrace(); e.printStackTrace();
return super.shouldInterceptRequest(view, url); return super.shouldInterceptRequest(view, url);
} }
} else if (url.contains("/css/common.css")) { }
if (url.contains("/css/common.css")) {
// return custom stylesheet
return new WebResourceResponse("text/css", "UTF-8", STYLE); return new WebResourceResponse("text/css", "UTF-8", STYLE);
// } else if (url.contains("gen_dashboard.js")) { }
// // define initialize function to get rid of JS ReferenceError on intel page's 'onLoad'
// String gen_dashboard_replacement = "window.initialize = function() {}"; if (url.contains("/css/ap_icons.css")
// return new WebResourceResponse("text/javascript", "UTF-8",
// new ByteArrayInputStream(gen_dashboard_replacement.getBytes()));
} else if (url.contains("/css/ap_icons.css")
|| url.contains("/css/map_icons.css") || url.contains("/css/map_icons.css")
|| url.contains("/css/common.css") || url.contains("/css/common.css")
|| url.contains("/css/misc_icons.css") || url.contains("/css/misc_icons.css")
@ -142,12 +142,16 @@ public class IITC_WebViewClient extends WebViewClient {
|| url.contains("/css/portalrender_mobile.css") || url.contains("/css/portalrender_mobile.css")
|| url.contains("js/analytics.js") || url.contains("js/analytics.js")
|| url.contains("google-analytics.com/ga.js")) { || url.contains("google-analytics.com/ga.js")) {
// don't load stylesheets
return new WebResourceResponse("text/plain", "UTF-8", EMPTY); return new WebResourceResponse("text/plain", "UTF-8", EMPTY);
} else if (url.startsWith("iitcm:")) {
return mIitc.getFileManager().getResponse(url);
} else {
return super.shouldInterceptRequest(view, url);
} }
Uri uri = Uri.parse(url);
if (uri.getHost().endsWith(DOMAIN) &&
("http".equals(uri.getScheme()) || "https".equals(uri.getScheme())))
return mIitc.getFileManager().getResponse(uri);
return super.shouldInterceptRequest(view, url);
} }
// start non-ingress-intel-urls in another app... // start non-ingress-intel-urls in another app...