gwt.mirrorbot@gmail.com | d54a4bd | 2010-06-07 19:20:31 +0000 | [diff] [blame] | 1 | <html> |
| 2 | <head> |
gwt.mirrorbot@gmail.com | d54a4bd | 2010-06-07 19:20:31 +0000 | [diff] [blame] | 3 | </head> |
conroy@google.com | 8806978 | 2010-11-23 13:51:12 +0000 | [diff] [blame] | 4 | |
| 5 | <embed id="pluginEmbed" type="application/x-gwt-hosted-mode" width="10" |
| 6 | height="10"> |
| 7 | </embed> |
| 8 | |
| 9 | |
| 10 | <script> |
| 11 | var plugin = document.getElementById('pluginEmbed'); |
| 12 | var disabledIcon = 'gwt32-gray.png'; |
| 13 | var enabledIcon = 'gwt32.png'; |
| 14 | |
| 15 | |
| 16 | function getHostFromUrl(url) { |
| 17 | var hostname = ''; |
| 18 | var idx = url.indexOf('://'); |
| 19 | if (idx >= 0) { |
| 20 | idx += 3; |
| 21 | hostname = url.substring(idx); |
| 22 | } |
| 23 | idx = hostname.indexOf('/'); |
| 24 | if (idx >= 0) { |
codefu@google.com | 977045b | 2011-05-31 17:15:12 +0000 | [diff] [blame] | 25 | hostname = hostname.substring(0,idx); |
| 26 | } |
| 27 | idx = hostname.indexOf('@'); |
| 28 | if( idx >= 0) |
| 29 | { |
| 30 | hostname = hostname.substring(idx+1); |
conroy@google.com | 8806978 | 2010-11-23 13:51:12 +0000 | [diff] [blame] | 31 | } |
| 32 | idx = hostname.indexOf(':'); |
| 33 | if (idx >= 0) { |
codefu@google.com | 977045b | 2011-05-31 17:15:12 +0000 | [diff] [blame] | 34 | hostname = hostname.substring(0,idx); |
conroy@google.com | 8806978 | 2010-11-23 13:51:12 +0000 | [diff] [blame] | 35 | } |
| 36 | return hostname; |
| 37 | } |
| 38 | |
codefu@google.com | 977045b | 2011-05-31 17:15:12 +0000 | [diff] [blame] | 39 | function getCodeServerFromUrl(url) { |
| 40 | var idx = url.indexOf('?'); |
| 41 | if (idx < 0) { |
| 42 | return ''; |
| 43 | } |
| 44 | url = url.substring(idx+1); |
| 45 | idx = url.indexOf('gwt.codesvr='); |
| 46 | if( idx < 0 ) { |
| 47 | return ''; |
| 48 | } |
| 49 | url = url.substring(idx+12); |
| 50 | var colon = url.indexOf(':'); |
| 51 | var amp = url.indexOf('&'); |
| 52 | if( amp < 0 || colon < amp ) { |
| 53 | amp = colon; |
| 54 | } |
| 55 | return amp < 0 ? url : url.substring(0,amp); |
| 56 | } |
| 57 | |
conroy@google.com | 8806978 | 2010-11-23 13:51:12 +0000 | [diff] [blame] | 58 | function devModeTabListener(tabId, changeInfo, tab) { |
| 59 | var search = tab.url.slice(tab.url.indexOf('?')); |
| 60 | if (search.indexOf('gwt.codesvr=') >= 0 || search.indexOf('gwt.hosted=') >= 0) { |
| 61 | var permission = plugin.getHostPermission(tab.url); |
| 62 | var host = getHostFromUrl(tab.url); |
codefu@google.com | 977045b | 2011-05-31 17:15:12 +0000 | [diff] [blame] | 63 | var code = getCodeServerFromUrl(tab.url); |
conroy@google.com | 8806978 | 2010-11-23 13:51:12 +0000 | [diff] [blame] | 64 | var popup = 'page_action.html'; |
| 65 | var icon = null; |
codefu@google.com | 977045b | 2011-05-31 17:15:12 +0000 | [diff] [blame] | 66 | console.log("got permission " + permission + " for host " + host + '/ code ' + code); |
conroy@google.com | 8806978 | 2010-11-23 13:51:12 +0000 | [diff] [blame] | 67 | |
codefu@google.com | bab5c0e | 2011-07-07 15:33:00 +0000 | [diff] [blame^] | 68 | var idObject = {}; |
| 69 | plugin.testJsIdentity( idObject, idObject ); |
| 70 | |
conroy@google.com | 8806978 | 2010-11-23 13:51:12 +0000 | [diff] [blame] | 71 | if (permission == 'include') { |
| 72 | icon = enabledIcon; |
| 73 | } else if (permission == 'exclude') { |
| 74 | icon = disabledIcon; |
| 75 | } else if (permission == 'unknown') { |
| 76 | icon = disabledIcon; |
| 77 | } |
codefu@google.com | 977045b | 2011-05-31 17:15:12 +0000 | [diff] [blame] | 78 | popup += "?permission=" + permission + "&host=" + host + "&codeserver=" + code; |
conroy@google.com | 8806978 | 2010-11-23 13:51:12 +0000 | [diff] [blame] | 79 | chrome.pageAction.setIcon({'tabId' : tabId, 'path' : icon}); |
| 80 | chrome.pageAction.setPopup({'tabId' : tabId, 'popup' : popup}); |
| 81 | chrome.pageAction.show(tabId); |
| 82 | |
| 83 | var hostEntries = window.localStorage.getItem('GWT_DEV_HOSTENTRY') || []; |
| 84 | console.log("loading hostentries: " + hostEntries); |
| 85 | plugin.loadHostEntries.apply(plugin, JSON.parse(hostEntries)); |
| 86 | } else { |
| 87 | chrome.pageAction.hide(tabId); |
| 88 | } |
| 89 | }; |
| 90 | |
| 91 | chrome.tabs.onUpdated.addListener(devModeTabListener); |
| 92 | </script> |
gwt.mirrorbot@gmail.com | d54a4bd | 2010-06-07 19:20:31 +0000 | [diff] [blame] | 93 | </html> |