@@ -41,6 +41,12 @@ Licensed to the Apache Software Foundation (ASF) under one
4141 */
4242public class PluginManager {
4343 private static String TAG = "PluginManager" ;
44+
45+ // @todo same as ConfigXmlParser. Research centralizing ideas, maybe create CordovaConstants
46+ private static String SCHEME_HTTPS = "https" ;
47+ // @todo same as ConfigXmlParser. Research centralizing ideas, maybe create CordovaConstants
48+ private static String DEFAULT_HOSTNAME = "localhost" ;
49+
4450 private static final int SLOW_EXEC_WARNING_THRESHOLD = Debug .isDebuggerConnected () ? 60 : 16 ;
4551
4652 // List of service entries
@@ -366,6 +372,24 @@ public void onNewIntent(Intent intent) {
366372 }
367373 }
368374
375+ /**
376+ * @todo should we move this somewhere public and accessible by all plugins?
377+ * For now, it is placed where it is used and kept private so we can decide later and move without causing a breaking change.
378+ * An ideal location might be in the "ConfigXmlParser" at the time it generates the "launchUrl".
379+ *
380+ * @todo should we be restrictive on the "file://" return? e.g. "file:///android_asset/www/"
381+ * Would be considered as a breaking change if we apply a more granular check.
382+ */
383+ private String getLaunchUrlPrefix () {
384+ if (!app .getPreferences ().getBoolean ("AndroidInsecureFileModeEnabled" , false )) {
385+ String scheme = app .getPreferences ().getString ("scheme" , SCHEME_HTTPS ).toLowerCase ();
386+ String hostname = app .getPreferences ().getString ("hostname" , DEFAULT_HOSTNAME );
387+ return scheme + "://" + hostname + '/' ;
388+ }
389+
390+ return "file://" ;
391+ }
392+
369393 /**
370394 * Called when the webview is going to request an external resource.
371395 *
@@ -452,7 +476,7 @@ public boolean shouldAllowBridgeAccess(String url) {
452476 }
453477
454478 // Default policy:
455- return url .startsWith ("file://" );
479+ return url .startsWith (getLaunchUrlPrefix () );
456480 }
457481
458482 /**
0 commit comments