Add a permissions model to the Chrome NPAPI plugin.
Permissions are stored in localstorage of the background page.
They can be changed by navigating to the extension's options page.
A page action indicates if the plugin permissions are good or bad for the current host.
Review at http://gwt-code-reviews.appspot.com/1084801
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@9283 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/plugins/npapi/prebuilt/gwt-dev-plugin/background.html b/plugins/npapi/prebuilt/gwt-dev-plugin/background.html
index 0bca1a5..2569678 100644
--- a/plugins/npapi/prebuilt/gwt-dev-plugin/background.html
+++ b/plugins/npapi/prebuilt/gwt-dev-plugin/background.html
@@ -1,10 +1,65 @@
<html>
<head>
-<script>
- chrome.extension.onConnect.addListener(function(port) {
- // Tell my caller his tabId
- port.postMessage( { name:"tabId", tabId:port.tab.id } );
- });
-</script>
</head>
+
+<embed id="pluginEmbed" type="application/x-gwt-hosted-mode" width="10"
+height="10">
+</embed>
+
+
+<script>
+var plugin = document.getElementById('pluginEmbed');
+var disabledIcon = 'gwt32-gray.png';
+var enabledIcon = 'gwt32.png';
+
+
+function getHostFromUrl(url) {
+ var hostname = '';
+ var idx = url.indexOf('://');
+ if (idx >= 0) {
+ idx += 3;
+ hostname = url.substring(idx);
+ }
+ idx = hostname.indexOf('/');
+ if (idx >= 0) {
+ hostname = hostname.split('/')[0];
+ }
+ idx = hostname.indexOf(':');
+ if (idx >= 0) {
+ hostname = hostname.split(':')[0];
+ }
+ return hostname;
+}
+
+function devModeTabListener(tabId, changeInfo, tab) {
+ var search = tab.url.slice(tab.url.indexOf('?'));
+ if (search.indexOf('gwt.codesvr=') >= 0 || search.indexOf('gwt.hosted=') >= 0) {
+ var permission = plugin.getHostPermission(tab.url);
+ var host = getHostFromUrl(tab.url);
+ var popup = 'page_action.html';
+ var icon = null;
+ console.log("got permission " + permission + " for host " + host);
+
+ if (permission == 'include') {
+ icon = enabledIcon;
+ } else if (permission == 'exclude') {
+ icon = disabledIcon;
+ } else if (permission == 'unknown') {
+ icon = disabledIcon;
+ }
+ popup += "?permission=" + permission + "&host=" + host;
+ chrome.pageAction.setIcon({'tabId' : tabId, 'path' : icon});
+ chrome.pageAction.setPopup({'tabId' : tabId, 'popup' : popup});
+ chrome.pageAction.show(tabId);
+
+ var hostEntries = window.localStorage.getItem('GWT_DEV_HOSTENTRY') || [];
+ console.log("loading hostentries: " + hostEntries);
+ plugin.loadHostEntries.apply(plugin, JSON.parse(hostEntries));
+ } else {
+ chrome.pageAction.hide(tabId);
+ }
+};
+
+chrome.tabs.onUpdated.addListener(devModeTabListener);
+</script>
</html>