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 */ 9var FEEDBACK_WIDTH = 500; 10/** 11 * @type {number} 12 * @const 13 */ 14var FEEDBACK_HEIGHT = 585; 15 16var initialFeedbackInfo = null; 17 18var 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 'andfmajejfpjojledngpdaibbhkffipo', // Hangouts Extension 42 'jfjjdfefebklmdbmenmlehlopoocnoeh', // Hangouts Extension 43 'dhcmpocobclokhifdkgcjbnfdaneoojd', // Hangouts Extension 44 'ppleadejekpmccmnpjdimmlfljlkdfej', // Hangouts Extension 45 'eggnbpckecmjlblplehfpjjdhhidfdoj', // Hangouts Extension 46 'ljclpkphhpbpinifbeabbhlfddcpfdde', // Hangouts Extension 47 'nckgahadagoaajjgafhacjanaoiihapd', // Hangouts Extension 48 'knipolnnllmklapflnccelgolnpehhpl', // Hangouts Extension 49]; 50 51/** 52 * Function to determine whether or not a given extension id is whitelisted to 53 * invoke the feedback UI. 54 * @param {string} id the id of the sender extension. 55 * @return {boolean} Whether or not this sender is whitelisted. 56 */ 57function senderWhitelisted(id) { 58 return id && whitelistedExtensionIds.indexOf(id) != -1; 59} 60 61/** 62 * Callback which gets notified once our feedback UI has loaded and is ready to 63 * receive its initial feedback info object. 64 * @param {Object} request The message request object. 65 * @param {Object} sender The sender of the message. 66 * @param {function(Object)} sendResponse Callback for sending a response. 67 */ 68function feedbackReadyHandler(request, sender, sendResponse) { 69 if (request.ready) { 70 chrome.runtime.sendMessage( 71 {sentFromEventPage: true, data: initialFeedbackInfo}); 72 } 73} 74 75 76/** 77 * Callback which gets notified if another extension is requesting feedback. 78 * @param {Object} request The message request object. 79 * @param {Object} sender The sender of the message. 80 * @param {function(Object)} sendResponse Callback for sending a response. 81 */ 82function requestFeedbackHandler(request, sender, sendResponse) { 83 if (request.requestFeedback && senderWhitelisted(sender.id)) 84 startFeedbackUI(request.feedbackInfo); 85} 86 87/** 88 * Callback which starts up the feedback UI. 89 * @param {Object} feedbackInfo Object containing any initial feedback info. 90 */ 91function startFeedbackUI(feedbackInfo) { 92 initialFeedbackInfo = feedbackInfo; 93 chrome.app.window.create('html/default.html', { 94 frame: 'none', 95 id: 'default_window', 96 width: FEEDBACK_WIDTH, 97 height: FEEDBACK_HEIGHT, 98 hidden: true, 99 resizable: false }, 100 function(appWindow) {}); 101} 102 103chrome.runtime.onMessage.addListener(feedbackReadyHandler); 104chrome.runtime.onMessageExternal.addListener(requestFeedbackHandler); 105chrome.feedbackPrivate.onFeedbackRequested.addListener(startFeedbackUI); 106