blob: 73f674d5a2d5f8e2f26d5da588deabb88fce1659 [file] [log] [blame]
gwt.mirrorbot@gmail.comd54a4bd2010-06-07 19:20:31 +00001<html>
2<head>
gwt.mirrorbot@gmail.comd54a4bd2010-06-07 19:20:31 +00003</head>
conroy@google.com88069782010-11-23 13:51:12 +00004
5<embed id="pluginEmbed" type="application/x-gwt-hosted-mode" width="10"
6height="10">
7</embed>
8
9
10<script>
11var plugin = document.getElementById('pluginEmbed');
12var disabledIcon = 'gwt32-gray.png';
13var enabledIcon = 'gwt32.png';
14
15
16function 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.com977045b2011-05-31 17:15:12 +000025 hostname = hostname.substring(0,idx);
26 }
27 idx = hostname.indexOf('@');
28 if( idx >= 0)
29 {
30 hostname = hostname.substring(idx+1);
conroy@google.com88069782010-11-23 13:51:12 +000031 }
32 idx = hostname.indexOf(':');
33 if (idx >= 0) {
codefu@google.com977045b2011-05-31 17:15:12 +000034 hostname = hostname.substring(0,idx);
conroy@google.com88069782010-11-23 13:51:12 +000035 }
36 return hostname;
37}
38
codefu@google.com977045b2011-05-31 17:15:12 +000039function 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.com88069782010-11-23 13:51:12 +000058function 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.com977045b2011-05-31 17:15:12 +000063 var code = getCodeServerFromUrl(tab.url);
conroy@google.com88069782010-11-23 13:51:12 +000064 var popup = 'page_action.html';
65 var icon = null;
codefu@google.com977045b2011-05-31 17:15:12 +000066 console.log("got permission " + permission + " for host " + host + '/ code ' + code);
conroy@google.com88069782010-11-23 13:51:12 +000067
codefu@google.combab5c0e2011-07-07 15:33:00 +000068 var idObject = {};
69 plugin.testJsIdentity( idObject, idObject );
70
conroy@google.com88069782010-11-23 13:51:12 +000071 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.com977045b2011-05-31 17:15:12 +000078 popup += "?permission=" + permission + "&host=" + host + "&codeserver=" + code;
conroy@google.com88069782010-11-23 13:51:12 +000079 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
91chrome.tabs.onUpdated.addListener(devModeTabListener);
92</script>
gwt.mirrorbot@gmail.comd54a4bd2010-06-07 19:20:31 +000093</html>