/** * Get the plugin object that implements the service. * If the plugin object does not already exist, then create it. * If the service doesn't exist, then return null. * * @param service The name of the service. * @return CordovaPlugin or null */ public CordovaPlugin getPlugin(String service) { CordovaPlugin ret = pluginMap.get(service); if (ret == null) { PluginEntry pe = entryMap.get(service); if (pe == null) { return null; } if (pe.plugin != null) { ret = pe.plugin; } else { ret = instantiatePlugin(pe.pluginClass); } ret.privateInitialize(ctx, app, app.getPreferences()); pluginMap.put(service, ret); } return ret; }
/** * Called when the URL of the webview changes. * * @param url The URL that is being changed to. * @return Return false to allow the URL to load, return true to prevent the URL from loading. */ public boolean onOverrideUrlLoading(String url) { // Deprecated way to intercept URLs. (process <url-filter> tags). // Instead, plugins should not include <url-filter> and instead ensure // that they are loaded before this function is called (either by setting // the onload <param> or by making an exec() call to them) for (PluginEntry entry : this.entryMap.values()) { List<String> urlFilters = urlMap.get(entry.service); if (urlFilters != null) { for (String s : urlFilters) { if (url.startsWith(s)) { return getPlugin(entry.service).onOverrideUrlLoading(url); } } } else { CordovaPlugin plugin = pluginMap.get(entry.service); if (plugin != null && plugin.onOverrideUrlLoading(url)) { return true; } } } return false; }
@Override public void loadUrl(String url, boolean clearNavigationStack) { if (!activityDelegate.isXWalkReady()) { startUrl = url; CordovaPlugin initPlugin = new CordovaPlugin() { @Override public void onResume(boolean multitasking) { activityDelegate.onResume(); } }; pluginManager.addService(new PluginEntry("XWalkInit", initPlugin)); return; } webView.load(url, null); }
/** * Called when the URL of the webview changes. * * @param url The URL that is being changed to. * @return Return false to allow the URL to load, return true to prevent the URL from loading. */ public boolean onOverrideUrlLoading(String url) { // Deprecated way to intercept URLs. (process <url-filter> tags). // Instead, plugins should not include <url-filter> and instead ensure // that they are loaded before this function is called (either by setting // the onload <param> or by making an exec() call to them) for (PluginEntry entry : this.entryMap.values()) { List<String> urlFilters = urlMap.get(entry.service); if (urlFilters != null) { for (String s : urlFilters) { if (url.startsWith(s)) { Log.d(TAG,"onOverrideUrlLoading()"); return getPlugin(entry.service).onOverrideUrlLoading(url); } } } else { CordovaPlugin plugin = pluginMap.get(entry.service); if (plugin != null && plugin.onOverrideUrlLoading(url)) { return true; } } } return false; }
/** * Clear all markups * @param args * @param callbackContext * @throws JSONException */ @SuppressWarnings("unused") private void clear(JSONArray args, CallbackContext callbackContext) throws JSONException { Set<String> pluginNames = plugins.keySet(); Iterator<String> iterator = pluginNames.iterator(); String pluginName; PluginEntry pluginEntry; while(iterator.hasNext()) { pluginName = iterator.next(); if ("Map".equals(pluginName) == false) { pluginEntry = plugins.get(pluginName); ((MyPlugin) pluginEntry.plugin).clear(); } } this.map.clear(); this.sendNoResult(callbackContext); }
@Override public boolean onMarkerClick(Marker marker) { this.onMarkerEvent("click", marker); JSONObject properties = null; String propertyId = "marker_property_" + marker.getId(); PluginEntry pluginEntry = this.plugins.get("Marker"); PluginMarker pluginMarker = (PluginMarker)pluginEntry.plugin; if (pluginMarker.objects.containsKey(propertyId)) { properties = (JSONObject) pluginMarker.objects.get(propertyId); if (properties.has("disableAutoPan")) { boolean disableAutoPan = false; try { disableAutoPan = properties.getBoolean("disableAutoPan"); } catch (JSONException e) {} if (disableAutoPan) { //marker.showInfoWindow(); return true; } } } //marker.showInfoWindow(); return true; //return false; }
/** * Send a message to all plugins. * * @param id The message id * @param data The message data * @return Object to stop propagation or null */ public Object postMessage(String id, Object data) { Object obj = this.ctx.onMessage(id, data); if (obj != null) { return obj; } for (PluginEntry entry : this.entries.values()) { if (entry.plugin != null) { obj = entry.plugin.onMessage(id, data); if (obj != null) { return obj; } } } return null; }
/** * Called when the URL of the webview changes. * * @param url The URL that is being changed to. * @return Return false to allow the URL to load, return true to prevent the URL from loading. */ public boolean onOverrideUrlLoading(String url) { // Deprecated way to intercept URLs. (process <url-filter> tags). // Instead, plugins should not include <url-filter> and instead ensure // that they are loaded before this function is called (either by setting // the onload <param> or by making an exec() call to them) for (PluginEntry entry : this.entries.values()) { List<String> urlFilters = urlMap.get(entry.service); if (urlFilters != null) { for (String s : urlFilters) { if (url.startsWith(s)) { return getPlugin(entry.service).onOverrideUrlLoading(url); } } } else if (entry.plugin != null) { if (entry.plugin.onOverrideUrlLoading(url)) { return true; } } } return false; }
/** * Init when loading a new HTML page into webview. */ public void init() { LOG.d(TAG, "init()"); // If first time, then load plugins from config.xml file if (this.firstRun) { this.loadPlugins(); this.firstRun = false; } // Stop plugins on current HTML page and discard plugin objects else { this.onPause(false); this.onDestroy(); this.clearPluginObjects(); } // Insert PluginManager service this.addService(new PluginEntry("PluginManager", new PluginManagerService())); // Start up all plugins that have onload specified this.startupPlugins(); }
@Override public void init(CordovaInterface cordova, List<PluginEntry> pluginEntries, Whitelist whitelist, CordovaPreferences preferences) { if (this.cordova != null) { throw new IllegalStateException(); } this.cordova = cordova; this.whitelist = whitelist; this.preferences = preferences; pluginManager = new PluginManager(this, this.cordova, pluginEntries); resourceApi = new CordovaResourceApi(webview.getContext(), pluginManager); bridge = new CordovaBridge(pluginManager, new NativeToJsMessageQueue(this, cordova)); pluginManager.addService("App", "org.apache.cordova.CoreAndroid"); initWebViewSettings(); webview.init(this); exposeJsInterface(); }