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 3 // found in the LICENSE file. 4 5 /** 6 * @type {number} 7 * @const 8 */ 9 var FEEDBACK_WIDTH = 500; 10 /** 11 * @type {number} 12 * @const 13 */ 14 var FEEDBACK_HEIGHT = 585; 15 16 var initialFeedbackInfo = null; 17 18 var whitelistedExtensionIds = [ 19 'bpmcpldpdmajfigpchkicefoigmkfalc', // QuickOffice 20 'ehibbfinohgbchlgdbfpikodjaojhccn', // QuickOffice 21 'gbkeegbaiigmenfmjfclcdgdpimamgkj', // QuickOffice 22 'efjnaogkjbogokcnohkmnjdojkikgobo', // G+ Photos 23 'ebpbnabdhheoknfklmpddcdijjkmklkp', // G+ Photos 24 'endkpmfloggdajndjpoekmkjnkolfdbf', // Feedback Extension 25 'mlocfejafidcakdddnndjdngfmncfbeg', // Connectivity Diagnostics 26 'ganomidahfnpdchomfgdoppjmmedlhia', // Connectivity Diagnostics 27 'eemlkeanncmjljgehlbplemhmdmalhdc', // Connectivity Diagnostics 28 'kodldpbjkkmmnilagfdheibampofhaom', // Connectivity Diagnostics 29 'kkebgepbbgbcmghedmmdfcbdcodlkngh', // Chrome OS Recovery Tool 30 'jndclpdbaamdhonoechobihbbiimdgai', // Chrome OS Recovery Tool 31 'ljoammodoonkhnehlncldjelhidljdpi', // GetHelp app. 32 'ljacajndfccfgnfohlgkdphmbnpkjflk', // Chrome Remote Desktop Dev 33 'gbchcmhmhahfdphkhkmpfmihenigjmpp', // Chrome Remote Desktop Stable 34 'odkaodonbgfohohmklejpjiejmcipmib', // Chrome Remote Desktop QA 35 'dokpleeekgeeiehdhmdkeimnkmoifgdd', // Chrome Remote Desktop QA backup 36 'ajoainacpilcemgiakehflpbkbfipojk', // Chrome Remote Desktop Apps V2 37 'llohocloplkbhgcfnplnoficdkiechcn', // Play Movies Dev 38 'icljpnebmoleodmchaaajbkpoipfoahp', // Play Movies Nightly 39 'mjekoljodoiapgkggnlmbecndfpbbcch', // Play Movies Beta 40 'gdijeikdkaembjbdobgfkoidjkpbmlkd', // Play Movies Stable 41 'knipolnnllmklapflnccelgolnpehhpl', // Hangouts Extension 42 ]; 43 44 /** 45 * Function to determine whether or not a given extension id is whitelisted to 46 * invoke the feedback UI. 47 * @param {string} id the id of the sender extension. 48 * @return {boolean} Whether or not this sender is whitelisted. 49 */ 50 function senderWhitelisted(id) { 51 return id && whitelistedExtensionIds.indexOf(id) != -1; 52 } 53 54 /** 55 * Callback which gets notified once our feedback UI has loaded and is ready to 56 * receive its initial feedback info object. 57 * @param {Object} request The message request object. 58 * @param {Object} sender The sender of the message. 59 * @param {function(Object)} sendResponse Callback for sending a response. 60 */ 61 function feedbackReadyHandler(request, sender, sendResponse) { 62 if (request.ready) { 63 // TODO(rkc): Remove logging once crbug.com/284662 is closed. 64 console.log('FEEDBACK_DEBUG: FeedbackUI Ready. Sending feedbackInfo.'); 65 chrome.runtime.sendMessage( 66 {sentFromEventPage: true, data: initialFeedbackInfo}); 67 } 68 } 69 70 71 /** 72 * Callback which gets notified if another extension is requesting feedback. 73 * @param {Object} request The message request object. 74 * @param {Object} sender The sender of the message. 75 * @param {function(Object)} sendResponse Callback for sending a response. 76 */ 77 function requestFeedbackHandler(request, sender, sendResponse) { 78 if (request.requestFeedback && senderWhitelisted(sender.id)) 79 startFeedbackUI(request.feedbackInfo); 80 } 81 82 /** 83 * Callback which starts up the feedback UI. 84 * @param {Object} feedbackInfo Object containing any initial feedback info. 85 */ 86 function startFeedbackUI(feedbackInfo) { 87 initialFeedbackInfo = feedbackInfo; 88 // TODO(rkc): Remove logging once crbug.com/284662 is closed. 89 console.log('FEEDBACK_DEBUG: Received onFeedbackRequested. Creating Window.'); 90 chrome.app.window.create('html/default.html', { 91 frame: 'none', 92 id: 'default_window', 93 width: FEEDBACK_WIDTH, 94 height: FEEDBACK_HEIGHT, 95 hidden: true, 96 resizable: false }, 97 function(appWindow) {}); 98 } 99 100 chrome.runtime.onMessage.addListener(feedbackReadyHandler); 101 chrome.runtime.onMessageExternal.addListener(requestFeedbackHandler); 102 chrome.feedbackPrivate.onFeedbackRequested.addListener(startFeedbackUI); 103