OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @type {number} | 6 * @type {number} |
7 * @const | 7 * @const |
8 */ | 8 */ |
9 var FEEDBACK_WIDTH = 500; | 9 var FEEDBACK_WIDTH = 500; |
10 /** | 10 /** |
11 * @type {number} | 11 * @type {number} |
12 * @const | 12 * @const |
13 */ | 13 */ |
14 var FEEDBACK_HEIGHT = 585; | 14 var FEEDBACK_HEIGHT = 585; |
15 | 15 |
16 var initialFeedbackInfo = null; | 16 var initialFeedbackInfo = null; |
17 | 17 |
18 // To generate a hashed extension ID, use a sha-256 hash, all in lower case. | |
19 // Example: | |
20 // echo -n 'abcdefghijklmnopqrstuvwxyzabcdef' | sha1sum | \ | |
21 // awk '{print toupper($1)}' | |
18 var whitelistedExtensionIds = [ | 22 var whitelistedExtensionIds = [ |
19 'bpmcpldpdmajfigpchkicefoigmkfalc', // QuickOffice | 23 '12E618C3C6E97495AAECF2AC12DEB082353241C6', // QuickOffice |
20 'ehibbfinohgbchlgdbfpikodjaojhccn', // QuickOffice | 24 '3727DD3E564B6055387425027AD74C58784ACC15', // QuickOffice |
21 'gbkeegbaiigmenfmjfclcdgdpimamgkj', // QuickOffice | 25 '2FC374607C2DF285634B67C64A2E356C607091C3', // QuickOffice |
22 'efjnaogkjbogokcnohkmnjdojkikgobo', // G+ Photos | 26 '2843C1E82A9B6C6FB49308FDDF4E157B6B44BC2B', // G+ Photos |
23 'ebpbnabdhheoknfklmpddcdijjkmklkp', // G+ Photos | 27 '5B5DA6D054D10DB917AF7D9EAE3C56044D1B0B03', // G+ Photos |
24 'endkpmfloggdajndjpoekmkjnkolfdbf', // Feedback Extension | 28 '986913085E3E3C3AFDE9B7A943149C4D3F4C937B', // Feedback Extension |
25 'mlocfejafidcakdddnndjdngfmncfbeg', // Connectivity Diagnostics | 29 '7AE714FFD394E073F0294CFA134C9F91DB5FBAA4', // Connectivity Diagnostics |
26 'ganomidahfnpdchomfgdoppjmmedlhia', // Connectivity Diagnostics | 30 'C7DA3A55C2355F994D3FDDAD120B426A0DF63843', // Connectivity Diagnostics |
27 'eemlkeanncmjljgehlbplemhmdmalhdc', // Connectivity Diagnostics | 31 '75E3CFFFC530582C583E4690EF97C70B9C8423B7', // Connectivity Diagnostics |
28 'kodldpbjkkmmnilagfdheibampofhaom', // Connectivity Diagnostics | 32 '32A1BA997F8AB8DE29ED1BA94AAF00CF2A3FEFA7', // Connectivity Diagnostics |
29 'kkebgepbbgbcmghedmmdfcbdcodlkngh', // Chrome OS Recovery Tool | 33 'A291B26E088FA6BA53FFD72F0916F06EBA7C585A', // Chrome OS Recovery Tool |
30 'jndclpdbaamdhonoechobihbbiimdgai', // Chrome OS Recovery Tool | 34 'D7986543275120831B39EF28D1327552FC343960', // Chrome OS Recovery Tool |
31 'ljoammodoonkhnehlncldjelhidljdpi', // GetHelp app. | 35 '8EBDF73405D0B84CEABB8C7513C9B9FA9F1DC2CE', // GetHelp app. |
32 'ljacajndfccfgnfohlgkdphmbnpkjflk', // Chrome Remote Desktop Dev | 36 '97B23E01B2AA064E8332EE43A7A85C628AADC3F2', // Chrome Remote Desktop Dev |
33 'gbchcmhmhahfdphkhkmpfmihenigjmpp', // Chrome Remote Desktop Stable | 37 '9E527CDA9D7C50844E8A5DB964A54A640AE48F98', // Chrome Remote Desktop Stable |
34 'odkaodonbgfohohmklejpjiejmcipmib', // Chrome Remote Desktop QA | 38 'DF52618D0B040D8A054D8348D2E84DDEEE5974E7', // Chrome Remote Desktop QA |
35 'dokpleeekgeeiehdhmdkeimnkmoifgdd', // Chrome Remote Desktop QA backup | 39 '269D721F163E587BC53C6F83553BF9CE2BB143CD', // Chrome Remote Desktop QA backup |
36 'ajoainacpilcemgiakehflpbkbfipojk', // Chrome Remote Desktop Apps V2 | 40 'C449A798C495E6CF7D6AF10162113D564E67AD12', // Chrome Remote Desktop Apps V2 |
37 'llohocloplkbhgcfnplnoficdkiechcn', // Play Movies Dev | 41 '981974CD1832B87BE6B21BE78F7249BB501E0DE6', // Play Movies Dev |
38 'icljpnebmoleodmchaaajbkpoipfoahp', // Play Movies Nightly | 42 '32FD7A816E47392C92D447707A89EB07EEDE6FF7', // Play Movies Nightly |
39 'mjekoljodoiapgkggnlmbecndfpbbcch', // Play Movies Beta | 43 '3F3CEC4B9B2B5DC2F820CE917AABDF97DB2F5B49', // Play Movies Beta |
40 'gdijeikdkaembjbdobgfkoidjkpbmlkd', // Play Movies Stable | 44 'F92FAC70AB68E1778BF62D9194C25979596AA0E6', // Play Movies Stable |
41 'andfmajejfpjojledngpdaibbhkffipo', // Hangouts Extension | 45 '0F585FB1D0FDFBEBCE1FEB5E9DFFB6DA476B8C9B', // Hangouts Extension |
42 'jfjjdfefebklmdbmenmlehlopoocnoeh', // Hangouts Extension | 46 '2D22CDB6583FD0A13758AEBE8B15E45208B4E9A7', // Hangouts Extension |
43 'dhcmpocobclokhifdkgcjbnfdaneoojd', // Hangouts Extension | 47 '49DA0B9CCEEA299186C6E7226FD66922D57543DC', // Hangouts Extension |
44 'ppleadejekpmccmnpjdimmlfljlkdfej', // Hangouts Extension | 48 'E7E2461CE072DF036CF9592740196159E2D7C089', // Hangouts Extension |
45 'eggnbpckecmjlblplehfpjjdhhidfdoj', // Hangouts Extension | 49 'A74A4D44C7CFCD8844830E6140C8D763E12DD8F3', // Hangouts Extension |
46 'ljclpkphhpbpinifbeabbhlfddcpfdde', // Hangouts Extension | 50 '312745D9BF916161191143F6490085EEA0434997', // Hangouts Extension |
47 'nckgahadagoaajjgafhacjanaoiihapd', // Hangouts Extension | 51 '53041A2FA309EECED01FFC751E7399186E860B2C', // Hangouts Extension |
48 'knipolnnllmklapflnccelgolnpehhpl', // Hangouts Extension | 52 '0F42756099D914A026DADFA182871C015735DD95', // Hangouts Extension |
49 'dogkdgiahcdchbabhdmpbhlfoddjined', // GLS nightly | 53 '1B7734733E207CCE5C33BFAA544CA89634BF881F', // GLS nightly |
50 'khkjfddibboofomnlkndfedpoccieiee', // GLS stable | 54 'E2ACA3D943A3C96310523BCDFD8C3AF68387E6B7', // GLS stable |
51 ]; | 55 ]; |
52 | 56 |
57 | |
53 /** | 58 /** |
54 * Function to determine whether or not a given extension id is whitelisted to | 59 * Function to determine whether or not a given extension id is whitelisted to |
55 * invoke the feedback UI. | 60 * invoke the feedback UI. If the extension is whitelisted, the callback to |
61 * start the Feedback UI will be called. | |
56 * @param {string} id the id of the sender extension. | 62 * @param {string} id the id of the sender extension. |
57 * @return {boolean} Whether or not this sender is whitelisted. | 63 * @param {Function} startFeedbackCallback The callback function that will |
64 * will start the feedback UI. | |
65 * @param {Object} feedbackInfo The feedback info object to pass to the | |
66 * start feedback UI callback. | |
58 */ | 67 */ |
59 function senderWhitelisted(id) { | 68 function senderWhitelisted(id, startFeedbackCallback, feedbackInfo) { |
60 return id && whitelistedExtensionIds.indexOf(id) != -1; | 69 crypto.subtle.digest('SHA-1', (new TextEncoder).encode(id)).then( |
arv (Not doing code reviews)
2015/02/23 20:25:11
crypto.subtle.digest('SHA-1', new TextEncoder().en
rkc
2015/02/23 20:37:34
Hmm, not sure what I was doing wrong before, but i
| |
70 function(hashBuffer) { | |
71 var hashString = ''; | |
72 var hashView = new Uint8Array(hashBuffer); | |
73 for (var i = 0; i < hashView.length; ++i) { | |
74 var n = hashView[i]; | |
75 hashString += n < 0x10 ? '0' : ''; | |
76 hashString += n.toString(16); | |
77 } | |
78 if (whitelistedExtensionIds.indexOf(hashString.toUpperCase()) != -1) | |
79 startFeedbackCallback(feedbackInfo); | |
80 }); | |
61 } | 81 } |
62 | 82 |
63 /** | 83 /** |
64 * Callback which gets notified once our feedback UI has loaded and is ready to | 84 * Callback which gets notified once our feedback UI has loaded and is ready to |
65 * receive its initial feedback info object. | 85 * receive its initial feedback info object. |
66 * @param {Object} request The message request object. | 86 * @param {Object} request The message request object. |
67 * @param {Object} sender The sender of the message. | 87 * @param {Object} sender The sender of the message. |
68 * @param {function(Object)} sendResponse Callback for sending a response. | 88 * @param {function(Object)} sendResponse Callback for sending a response. |
69 */ | 89 */ |
70 function feedbackReadyHandler(request, sender, sendResponse) { | 90 function feedbackReadyHandler(request, sender, sendResponse) { |
71 if (request.ready) { | 91 if (request.ready) { |
72 chrome.runtime.sendMessage( | 92 chrome.runtime.sendMessage( |
73 {sentFromEventPage: true, data: initialFeedbackInfo}); | 93 {sentFromEventPage: true, data: initialFeedbackInfo}); |
74 } | 94 } |
75 } | 95 } |
76 | 96 |
77 | 97 |
78 /** | 98 /** |
79 * Callback which gets notified if another extension is requesting feedback. | 99 * Callback which gets notified if another extension is requesting feedback. |
80 * @param {Object} request The message request object. | 100 * @param {Object} request The message request object. |
81 * @param {Object} sender The sender of the message. | 101 * @param {Object} sender The sender of the message. |
82 * @param {function(Object)} sendResponse Callback for sending a response. | 102 * @param {function(Object)} sendResponse Callback for sending a response. |
83 */ | 103 */ |
84 function requestFeedbackHandler(request, sender, sendResponse) { | 104 function requestFeedbackHandler(request, sender, sendResponse) { |
85 if (request.requestFeedback && senderWhitelisted(sender.id)) | 105 if (request.requestFeedback) |
86 startFeedbackUI(request.feedbackInfo); | 106 senderWhitelisted(sender.id, startFeedbackUI, request.feedbackInfo); |
87 } | 107 } |
88 | 108 |
89 /** | 109 /** |
90 * Callback which starts up the feedback UI. | 110 * Callback which starts up the feedback UI. |
91 * @param {Object} feedbackInfo Object containing any initial feedback info. | 111 * @param {Object} feedbackInfo Object containing any initial feedback info. |
92 */ | 112 */ |
93 function startFeedbackUI(feedbackInfo) { | 113 function startFeedbackUI(feedbackInfo) { |
94 initialFeedbackInfo = feedbackInfo; | 114 initialFeedbackInfo = feedbackInfo; |
95 chrome.app.window.create('html/default.html', { | 115 chrome.app.window.create('html/default.html', { |
96 frame: 'none', | 116 frame: 'none', |
97 id: 'default_window', | 117 id: 'default_window', |
98 width: FEEDBACK_WIDTH, | 118 width: FEEDBACK_WIDTH, |
99 height: FEEDBACK_HEIGHT, | 119 height: FEEDBACK_HEIGHT, |
100 hidden: true, | 120 hidden: true, |
101 resizable: false }, | 121 resizable: false }, |
102 function(appWindow) {}); | 122 function(appWindow) {}); |
103 } | 123 } |
104 | 124 |
105 chrome.runtime.onMessage.addListener(feedbackReadyHandler); | 125 chrome.runtime.onMessage.addListener(feedbackReadyHandler); |
106 chrome.runtime.onMessageExternal.addListener(requestFeedbackHandler); | 126 chrome.runtime.onMessageExternal.addListener(requestFeedbackHandler); |
107 chrome.feedbackPrivate.onFeedbackRequested.addListener(startFeedbackUI); | 127 chrome.feedbackPrivate.onFeedbackRequested.addListener(startFeedbackUI); |
OLD | NEW |