org.apache.cordova.PluginEntry Java Examples

The following examples show how to use org.apache.cordova.PluginEntry. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CordovaResourceApiTest.java    From cordova-amazon-fireos with Apache License 2.0 6 votes vote down vote up
protected void setUp() throws Exception {
    super.setUp();
    activity = this.getActivity();
    cordovaWebView = activity.cordovaWebView;
    resourceApi = cordovaWebView.getResourceApi();
    resourceApi.setThreadCheckingEnabled(false);
    cordovaWebView.pluginManager.addService(new PluginEntry("CordovaResourceApiTestPlugin1", new CordovaPlugin() {
        @Override
        public Uri remapUri(Uri uri) {
            if (uri.getQuery() != null && uri.getQuery().contains("pluginRewrite")) {
                return cordovaWebView.getResourceApi().remapUri(
                        Uri.parse("data:text/plain;charset=utf-8,pass"));
            }
            return null;
        }
        public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
            synchronized (CordovaResourceApiTest.this) {
                execPayload = args.getString(0);
                execStatus = args.getInt(1);
                CordovaResourceApiTest.this.notify();
            }
            return true;
        }
    }));
}
 
Example #2
Source File: PluginManager.java    From crosswalk-cordova-android with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #3
Source File: PluginManager.java    From L.TileLayer.Cordova with MIT License 6 votes vote down vote up
/**
 * 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;
}
 
Example #4
Source File: PluginManager.java    From phonegap-plugin-loading-spinner with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #5
Source File: PluginManager.java    From CordovaYoutubeVideoPlayer with MIT License 6 votes vote down vote up
/**
 * 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;
}
 
Example #6
Source File: PluginManager.java    From CordovaYoutubeVideoPlayer with MIT License 6 votes vote down vote up
/**
 * 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;
}
 
Example #7
Source File: PluginManager.java    From IoTgo_Android_App with MIT License 6 votes vote down vote up
/**
 * 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;
}
 
Example #8
Source File: CordovaResourceApiTest.java    From crosswalk-cordova-android with Apache License 2.0 6 votes vote down vote up
protected void setUp() throws Exception {
    super.setUp();
    activity = this.getActivity();
    cordovaWebView = activity.cordovaWebView;
    resourceApi = cordovaWebView.getResourceApi();
    resourceApi.setThreadCheckingEnabled(false);
    cordovaWebView.pluginManager.addService(new PluginEntry("CordovaResourceApiTestPlugin1", new CordovaPlugin() {
        @Override
        public Uri remapUri(Uri uri) {
            if (uri.getQuery() != null && uri.getQuery().contains("pluginRewrite")) {
                return cordovaWebView.getResourceApi().remapUri(
                        Uri.parse("data:text/plain;charset=utf-8,pass"));
            }
            return null;
        }
        public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
            synchronized (CordovaResourceApiTest.this) {
                execPayload = args.getString(0);
                execStatus = args.getInt(1);
                CordovaResourceApiTest.this.notify();
            }
            return true;
        }
    }));
}
 
Example #9
Source File: PluginManager.java    From bluemix-parking-meter with MIT License 6 votes vote down vote up
/**
 * 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;
}
 
Example #10
Source File: PluginManager.java    From phonegapbootcampsite with MIT License 6 votes vote down vote up
/**
 * 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;
}
 
Example #11
Source File: PluginManager.java    From reader with MIT License 6 votes vote down vote up
/**
 * 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;
}
 
Example #12
Source File: PluginManager.java    From reader with MIT License 6 votes vote down vote up
/**
 * 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;
}
 
Example #13
Source File: PluginManager.java    From phonegapbootcampsite with MIT License 6 votes vote down vote up
/**
 * 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;
}
 
Example #14
Source File: PluginManager.java    From wildfly-samples with MIT License 6 votes vote down vote up
/**
 * 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;
}
 
Example #15
Source File: PluginManager.java    From phonegapbootcampsite with MIT License 6 votes vote down vote up
/**
 * 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();
}
 
Example #16
Source File: PluginManager.java    From reader with MIT License 6 votes vote down vote up
/**
 * 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;
}
 
Example #17
Source File: PluginManager.java    From cordova-amazon-fireos with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #18
Source File: PluginManager.java    From CordovaYoutubeVideoPlayer with MIT License 5 votes vote down vote up
/**
 * Called when the system is about to start resuming a previous activity.
 *
 * @param multitasking      Flag indicating if multitasking is turned on for app
 */
public void onPause(boolean multitasking) {
    for (PluginEntry entry : this.entries.values()) {
        if (entry.plugin != null) {
            entry.plugin.onPause(multitasking);
        }
    }
}
 
Example #19
Source File: PluginManager.java    From phonegapbootcampsite with MIT License 5 votes vote down vote up
/**
 * Called when the activity will start interacting with the user.
 *
 * @param multitasking      Flag indicating if multitasking is turned on for app
 */
public void onResume(boolean multitasking) {
    for (PluginEntry entry : this.entries.values()) {
        if (entry.plugin != null) {
            entry.plugin.onResume(multitasking);
        }
    }
}
 
Example #20
Source File: PluginManager.java    From phonegapbootcampsite with MIT License 5 votes vote down vote up
/**
 * Called when the system is about to start resuming a previous activity.
 *
 * @param multitasking      Flag indicating if multitasking is turned on for app
 */
public void onPause(boolean multitasking) {
    for (PluginEntry entry : this.entries.values()) {
        if (entry.plugin != null) {
            entry.plugin.onPause(multitasking);
        }
    }
}
 
Example #21
Source File: PluginManager.java    From phonegap-plugin-loading-spinner with Apache License 2.0 5 votes vote down vote up
/**
 * 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) {
    PluginEntry entry = this.entries.get(service);
    if (entry == null) {
        return null;
    }
    CordovaPlugin plugin = entry.plugin;
    if (plugin == null) {
        plugin = entry.createPlugin(this.app, this.ctx);
    }
    return plugin;
}
 
Example #22
Source File: PluginManager.java    From phonegapbootcampsite with MIT License 5 votes vote down vote up
/**
 * 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) {
    PluginEntry entry = this.entries.get(service);
    if (entry == null) {
        return null;
    }
    CordovaPlugin plugin = entry.plugin;
    if (plugin == null) {
        plugin = entry.createPlugin(this.app, this.ctx);
    }
    return plugin;
}
 
Example #23
Source File: PluginManager.java    From phonegapbootcampsite with MIT License 5 votes vote down vote up
/**
 * Create plugins objects that have onload set.
 */
public void startupPlugins() {
    for (PluginEntry entry : this.entries.values()) {
        if (entry.onload) {
            entry.createPlugin(this.app, this.ctx);
        }
    }
}
 
Example #24
Source File: PluginManager.java    From wildfly-samples with MIT License 5 votes vote down vote up
/**
 * Called when the activity receives a new intent.
 */
public void onNewIntent(Intent intent) {
    for (PluginEntry entry : this.entries.values()) {
        if (entry.plugin != null) {
            entry.plugin.onNewIntent(intent);
        }
    }
}
 
Example #25
Source File: PluginManager.java    From cordova-amazon-fireos with Apache License 2.0 5 votes vote down vote up
/**
 * Add a plugin class that implements a service to the service entry table.
 * This does not create the plugin object instance.
 *
 * @param entry
 *            The plugin entry
 */
public void addService(PluginEntry entry) {
	/*
	 * When adding a new plugin we must reconstruct and sort the list of
	 * PluginEntries (which reside in a LinkedHashMap) to maintain its
	 * order. Although this may not be entirely desirable, it prevents us
	 * from having to maintain a separate sorted data structure while still
	 * keeping the benefits of storing the objects in a HashMap.
	 * Furthermore, this function is currently only called once during the
	 * initialization; and so by default is a total of only two overall
	 * sorts (one for initial config.xml parse, and another for the
	 * PluginManager service).
	 *
	 * Note: this method is not thread-safe, and is planned to be improved
	 * in future commits (along with some other thread-unsafe areas)
	 */

	// create list from existing set of plugin entries, then add new item to list
	List<PluginEntry> pluginEntries = new ArrayList<PluginEntry>(entryMap.values());
	pluginEntries.add(entry);

       //Update PluginMap as well
       if (entry.plugin != null) {
           entry.plugin.privateInitialize(ctx, app, app.getPreferences());
           pluginMap.put(entry.service, entry.plugin);
       }
	// recreate final set entries in priority order
	this.addServices(pluginEntries);
       
       List<String> urlFilters = entry.getUrlFilters();
       if (urlFilters != null) {
           urlMap.put(entry.service, urlFilters);
       }
}
 
Example #26
Source File: PluginManager.java    From wildfly-samples with MIT License 5 votes vote down vote up
/**
 * Called when the activity will start interacting with the user.
 *
 * @param multitasking      Flag indicating if multitasking is turned on for app
 */
public void onResume(boolean multitasking) {
    for (PluginEntry entry : this.entries.values()) {
        if (entry.plugin != null) {
            entry.plugin.onResume(multitasking);
        }
    }
}
 
Example #27
Source File: PluginManager.java    From wildfly-samples with MIT License 5 votes vote down vote up
/**
 * 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) {
    PluginEntry entry = this.entries.get(service);
    if (entry == null) {
        return null;
    }
    CordovaPlugin plugin = entry.plugin;
    if (plugin == null) {
        plugin = entry.createPlugin(this.app, this.ctx);
    }
    return plugin;
}
 
Example #28
Source File: PluginManager.java    From cordova-amazon-fireos with Apache License 2.0 5 votes vote down vote up
public void setPluginEntries(List<PluginEntry> pluginEntries) {
    this.onPause(false);
    this.onDestroy();
    pluginMap.clear();
    urlMap.clear();
    for (PluginEntry entry : pluginEntries) {
        addService(entry);
    }
}
 
Example #29
Source File: MockCordovaWebViewImpl.java    From OsmGo with MIT License 5 votes vote down vote up
public void init(CordovaInterface cordova, List<PluginEntry> pluginEntries, CordovaPreferences preferences, WebView webView) {
  this.cordova = cordova;
  this.webView = webView;
  this.preferences = preferences;
  this.pluginManager = new PluginManager(this, this.cordova, pluginEntries);
  this.resourceApi = new CordovaResourceApi(this.context, this.pluginManager);
  nativeToJsMessageQueue = new NativeToJsMessageQueue();
  nativeToJsMessageQueue.addBridgeMode(new CapacitorEvalBridgeMode(webView, this.cordova));
  nativeToJsMessageQueue.setBridgeMode(0);
  this.cookieManager = new CapacitorCordovaCookieManager(webView);
  this.pluginManager.init();
}
 
Example #30
Source File: PluginManager.java    From phonegapbootcampsite with MIT License 5 votes vote down vote up
/**
 * The final call you receive before your activity is destroyed.
 */
public void onDestroy() {
    for (PluginEntry entry : this.entries.values()) {
        if (entry.plugin != null) {
            entry.plugin.onDestroy();
        }
    }
}