Home | History | Annotate | Download | only in js
      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 = 625;
     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 ];
     32 
     33 /**
     34  * Function to determine whether or not a given extension id is whitelisted to
     35  * invoke the feedback UI.
     36  * @param {string} id the id of the sender extension.
     37  * @return {boolean} Whether or not this sender is whitelisted.
     38  */
     39 function senderWhitelisted(id) {
     40   return id && whitelistedExtensionIds.indexOf(id) != -1;
     41 }
     42 
     43 /**
     44  * Callback which gets notified once our feedback UI has loaded and is ready to
     45  * receive its initial feedback info object.
     46  * @param {Object} request The message request object.
     47  * @param {Object} sender The sender of the message.
     48  * @param {function(Object)} sendResponse Callback for sending a response.
     49  */
     50 function feedbackReadyHandler(request, sender, sendResponse) {
     51   if (request.ready) {
     52     // TODO(rkc):  Remove logging once crbug.com/284662 is closed.
     53     console.log('FEEDBACK_DEBUG: FeedbackUI Ready. Sending feedbackInfo.');
     54     chrome.runtime.sendMessage(
     55         {sentFromEventPage: true, data: initialFeedbackInfo});
     56   }
     57 }
     58 
     59 
     60 /**
     61  * Callback which gets notified if another extension is requesting feedback.
     62  * @param {Object} request The message request object.
     63  * @param {Object} sender The sender of the message.
     64  * @param {function(Object)} sendResponse Callback for sending a response.
     65  */
     66 function requestFeedbackHandler(request, sender, sendResponse) {
     67   if (request.requestFeedback && senderWhitelisted(sender.id))
     68     startFeedbackUI(request.feedbackInfo);
     69 }
     70 
     71 /**
     72  * Callback which starts up the feedback UI.
     73  * @param {Object} feedbackInfo Object containing any initial feedback info.
     74  */
     75 function startFeedbackUI(feedbackInfo) {
     76   initialFeedbackInfo = feedbackInfo;
     77   // TODO(rkc):  Remove logging once crbug.com/284662 is closed.
     78   console.log('FEEDBACK_DEBUG: Received onFeedbackRequested. Creating Window.');
     79   chrome.app.window.create('html/default.html', {
     80       frame: 'none',
     81       id: 'default_window',
     82       width: FEEDBACK_WIDTH,
     83       height: FEEDBACK_HEIGHT,
     84       hidden: true,
     85       resizable: false },
     86       function(appWindow) {});
     87 }
     88 
     89 chrome.runtime.onMessage.addListener(feedbackReadyHandler);
     90 chrome.runtime.onMessageExternal.addListener(requestFeedbackHandler);
     91 chrome.feedbackPrivate.onFeedbackRequested.addListener(startFeedbackUI);
     92