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/Darwin-gcc3/gwtDev.plugin/Contents/MacOS/libGwtDevPlugin.dylib b/plugins/npapi/prebuilt/gwt-dev-plugin/Darwin-gcc3/gwtDev.plugin/Contents/MacOS/libGwtDevPlugin.dylib
index 6e17d7b..3523020 100755
--- a/plugins/npapi/prebuilt/gwt-dev-plugin/Darwin-gcc3/gwtDev.plugin/Contents/MacOS/libGwtDevPlugin.dylib
+++ b/plugins/npapi/prebuilt/gwt-dev-plugin/Darwin-gcc3/gwtDev.plugin/Contents/MacOS/libGwtDevPlugin.dylib
Binary files differ
diff --git a/plugins/npapi/prebuilt/gwt-dev-plugin/Darwin-gcc3/libGwtDevPlugin.dylib b/plugins/npapi/prebuilt/gwt-dev-plugin/Darwin-gcc3/libGwtDevPlugin.dylib
deleted file mode 100755
index 98f3d3f..0000000
--- a/plugins/npapi/prebuilt/gwt-dev-plugin/Darwin-gcc3/libGwtDevPlugin.dylib
+++ /dev/null
Binary files differ
diff --git a/plugins/npapi/prebuilt/gwt-dev-plugin/Linux_x86-gcc3/libGwtDevPlugin.so b/plugins/npapi/prebuilt/gwt-dev-plugin/Linux_x86-gcc3/libGwtDevPlugin.so
index 2aec960..1294ca9 100755
--- a/plugins/npapi/prebuilt/gwt-dev-plugin/Linux_x86-gcc3/libGwtDevPlugin.so
+++ b/plugins/npapi/prebuilt/gwt-dev-plugin/Linux_x86-gcc3/libGwtDevPlugin.so
Binary files differ
diff --git a/plugins/npapi/prebuilt/gwt-dev-plugin/Linux_x86_64-gcc3/libGwtDevPlugin.so b/plugins/npapi/prebuilt/gwt-dev-plugin/Linux_x86_64-gcc3/libGwtDevPlugin.so
index 1f7949b..ce762bb 100755
--- a/plugins/npapi/prebuilt/gwt-dev-plugin/Linux_x86_64-gcc3/libGwtDevPlugin.so
+++ b/plugins/npapi/prebuilt/gwt-dev-plugin/Linux_x86_64-gcc3/libGwtDevPlugin.so
Binary files differ
diff --git a/plugins/npapi/prebuilt/gwt-dev-plugin/WINNT_x86-msvc/npGwtDevPlugin.dll b/plugins/npapi/prebuilt/gwt-dev-plugin/WINNT_x86-msvc/npGwtDevPlugin.dll
index 2631415..dd1522a 100755
--- a/plugins/npapi/prebuilt/gwt-dev-plugin/WINNT_x86-msvc/npGwtDevPlugin.dll
+++ b/plugins/npapi/prebuilt/gwt-dev-plugin/WINNT_x86-msvc/npGwtDevPlugin.dll
Binary files differ
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>
diff --git a/plugins/npapi/prebuilt/gwt-dev-plugin/gwt32-gray.png b/plugins/npapi/prebuilt/gwt-dev-plugin/gwt32-gray.png
new file mode 100644
index 0000000..d02689e
--- /dev/null
+++ b/plugins/npapi/prebuilt/gwt-dev-plugin/gwt32-gray.png
Binary files differ
diff --git a/plugins/npapi/prebuilt/gwt-dev-plugin/manifest.json b/plugins/npapi/prebuilt/gwt-dev-plugin/manifest.json
index 0f1cdf0..f425fc2 100644
--- a/plugins/npapi/prebuilt/gwt-dev-plugin/manifest.json
+++ b/plugins/npapi/prebuilt/gwt-dev-plugin/manifest.json
@@ -1,6 +1,6 @@
 {
   "name": "GWT Developer Plugin",
-  "version": "1.0.9119",
+  "version": "1.0.9274",
   "description": "A plugin to enable debugging with GWT's Development Mode",
   "update_url": "https://dl-ssl.google.com/gwt/plugins/chrome/updates.xml",
   "icons": {
@@ -10,12 +10,16 @@
     "64": "gwt64.png",
     "128": "gwt128.png"
   },
+  "key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDi6RrEy9YllRLM8bGBcIEk5ECAG2z+8ngTz7wwzRAQJpOzDp1Alq8fQFjH0+dzxok4RFLrWKHjxGqvXzWyWyTEo2nY3ScHLN/RoANMs8pl9X6TygRyO+3naqZOtLCrYHfV49JKXnYoFVbY5eBVYxHYY3BHAOKJj9onyAM4UPmMzQIDAQAB",
   "background_page": "background.html",
-  "content_scripts": [
-    {
-      "matches": ["http://*/*", "https://*/*", "file:///*"],
-      "js": ["record_tab_id.js"]
-    }
+  "options_page" : "DevModeOptions.html",
+  "page_action" : {
+    "default_icon" : "gwt32.png",
+    "default_title" : "GWT Development Mode",
+    "default_popup" : "page_action.html"
+  },
+  "permissions" : [
+    "tabs"
   ],
   "plugins": [
     { "path": "WINNT_x86-msvc/npGwtDevPlugin.dll", "public": true },
diff --git a/plugins/npapi/prebuilt/gwt-dev-plugin/page_action.html b/plugins/npapi/prebuilt/gwt-dev-plugin/page_action.html
new file mode 100644
index 0000000..f891515
--- /dev/null
+++ b/plugins/npapi/prebuilt/gwt-dev-plugin/page_action.html
@@ -0,0 +1,47 @@
+<head>
+  <style>
+    body {
+      width: 20em;
+    }
+  </style>
+  <script>
+    function getParam(key) {
+      var idx = window.location.search.indexOf(key + "=");
+      var value = '';
+      if (idx >= 0) {
+        idx += key.length + 1;
+        value = window.location.search.substring(idx).split('&')[0];
+      }
+      return value;
+    }
+
+    function init() {
+      var permission = getParam('permission');
+      var host = getParam('host');
+      var message='';
+
+      if (permission == 'include') {
+        message = 'The host at ' + host + ' is allowed to use the plugin';
+      } else if (permission == 'exclude') {
+        message = 'The host at ' + host + ' has been been blacklisted.';
+      } else if (permission == 'unknown') {
+        message = 'The host at ' + host + ' is unknown to the plugin.';
+      }
+
+      document.getElementById('message').innerText = message;
+    }
+
+    function updateConfiguration() {
+      var url = 'DevModeOptions.html?host=' + getParam('host');
+      url = chrome.extension.getURL(url);
+      chrome.tabs.create({'url' : url});
+    }
+  </script>
+</head>
+<body onload='javascript:init()'>
+  <h3>GWT Developer Plugin</h3>
+  <div id='message'></div>
+  <br/>
+  <button onclick= "updateConfiguration()">Update Your Configuration</button>
+  </p>
+</body>
diff --git a/plugins/npapi/prebuilt/gwt-dev-plugin/record_tab_id.js b/plugins/npapi/prebuilt/gwt-dev-plugin/record_tab_id.js
deleted file mode 100644
index 78c9e73..0000000
--- a/plugins/npapi/prebuilt/gwt-dev-plugin/record_tab_id.js
+++ /dev/null
@@ -1,13 +0,0 @@
-if (window != top && location.href.indexOf("hosted.html") >= 0) {
-  var port = chrome.extension.connect();
-  port.onMessage.addListener(function(msg) {
-    if (msg.name == "tabId") {
-      var doc = window.document;
-      var div = document.createElement("div");
-      div.id = "$__gwt_tab_id";
-      div.textContent = "" + msg.tabId;
-      doc.body.appendChild(div);
-      // console.log("record_tab_id.js " + msg.tabId);
-    }
-  });
-}
diff --git a/plugins/npapi/prebuilt/gwt-dev-plugin/warning.png b/plugins/npapi/prebuilt/gwt-dev-plugin/warning.png
new file mode 100644
index 0000000..55a203b
--- /dev/null
+++ b/plugins/npapi/prebuilt/gwt-dev-plugin/warning.png
Binary files differ