| 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 /** |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 } | 193 } |
| 194 | 194 |
| 195 chrome.feedbackPrivate.sendFeedback(finalFeedbackInfo, function(result) {}); | 195 chrome.feedbackPrivate.sendFeedback(finalFeedbackInfo, function(result) {}); |
| 196 } | 196 } |
| 197 | 197 |
| 198 /** | 198 /** |
| 199 * Callback which starts up the feedback UI. | 199 * Callback which starts up the feedback UI. |
| 200 * @param {Object} feedbackInfo Object containing any initial feedback info. | 200 * @param {Object} feedbackInfo Object containing any initial feedback info. |
| 201 */ | 201 */ |
| 202 function startFeedbackUI(feedbackInfo) { | 202 function startFeedbackUI(feedbackInfo) { |
| 203 initialFeedbackInfo = feedbackInfo; | |
| 204 finalFeedbackInfo = null; | |
| 205 systemInfo = null; | |
| 206 isSystemInfoReady = false; | |
| 207 onSystemInfoReadyCallback = null; | |
| 208 | |
| 209 chrome.feedbackPrivate.getSystemInformation(getSystemInformationCallback); | |
| 210 | |
| 211 var win = chrome.app.window.get(FEEDBACK_DEFAULT_WINDOW_ID); | 203 var win = chrome.app.window.get(FEEDBACK_DEFAULT_WINDOW_ID); |
| 212 if (win) { | 204 if (win) { |
| 213 win.show(); | 205 win.show(); |
| 214 return; | 206 return; |
| 215 } | 207 } |
| 216 chrome.app.window.create('html/default.html', { | 208 chrome.app.window.create('html/default.html', { |
| 217 frame: 'none', | 209 frame: 'none', |
| 218 id: FEEDBACK_DEFAULT_WINDOW_ID, | 210 id: FEEDBACK_DEFAULT_WINDOW_ID, |
| 219 width: FEEDBACK_WIDTH, | 211 width: FEEDBACK_WIDTH, |
| 220 height: FEEDBACK_HEIGHT, | 212 height: FEEDBACK_HEIGHT, |
| 221 hidden: true, | 213 hidden: true, |
| 222 resizable: false }, | 214 resizable: false }, |
| 223 function(appWindow) { | 215 function(appWindow) { |
| 216 // Initialize the state of the app only once upon the creation of the |
| 217 // feedback UI window. |
| 218 initialFeedbackInfo = feedbackInfo; |
| 219 finalFeedbackInfo = null; |
| 220 systemInfo = null; |
| 221 isSystemInfoReady = false; |
| 222 onSystemInfoReadyCallback = null; |
| 223 |
| 224 // Define some functions for the new window so that it can call back | 224 // Define some functions for the new window so that it can call back |
| 225 // into here. | 225 // into here. |
| 226 | 226 |
| 227 // Define a function for the new window to get the system information. | 227 // Define a function for the new window to get the system information. |
| 228 // Returns null if the system information is not ready yet. | 228 appWindow.contentWindow.getSystemInformation = function(callback) { |
| 229 appWindow.contentWindow.getSystemInformation = function() { | 229 if (!isSystemInfoReady) { |
| 230 return systemInfo; | 230 onSystemInfoReadyCallback = callback; |
| 231 chrome.feedbackPrivate.getSystemInformation( |
| 232 getSystemInformationCallback); |
| 233 return; |
| 234 } |
| 235 |
| 236 callback(systemInfo); |
| 231 }; | 237 }; |
| 232 | 238 |
| 233 // Define a function to be called by the new window when the report is | 239 // Define a function to be called by the new window when the report is |
| 234 // not ready yet, and has to be sent later when the system information | 240 // not ready yet, and has to be sent later when the system information |
| 235 // is received. | 241 // is received. |
| 236 appWindow.contentWindow.sendReportLater = function(feedbackInfo) { | 242 appWindow.contentWindow.sendReportLater = function(feedbackInfo) { |
| 237 finalFeedbackInfo = feedbackInfo; | 243 finalFeedbackInfo = feedbackInfo; |
| 238 if (!isSystemInfoReady) { | 244 if (!isSystemInfoReady) { |
| 239 onSystemInfoReadyCallback = onSysInfoReadyForSend; | 245 onSystemInfoReadyCallback = onSysInfoReadyForSend; |
| 240 return; | 246 return; |
| 241 } | 247 } |
| 242 | 248 |
| 243 onSysInfoReadyForSend(systemInfo); | 249 onSysInfoReadyForSend(systemInfo); |
| 244 }; | 250 }; |
| 245 | 251 |
| 246 // Returns whether the system information has been received or not. | 252 // Returns whether the system information has been received or not. |
| 247 appWindow.contentWindow.isSystemInfoReady = function() { | 253 appWindow.contentWindow.isSystemInfoReady = function() { |
| 248 return isSystemInfoReady; | 254 return isSystemInfoReady; |
| 249 }; | 255 }; |
| 250 | |
| 251 // Registers a callback that will be invoked when the system information | |
| 252 // is received. | |
| 253 appWindow.contentWindow.setOnSystemInfoReadyCallback = | |
| 254 function(callback) { | |
| 255 onSystemInfoReadyCallback = callback; | |
| 256 }; | |
| 257 }); | 256 }); |
| 258 } | 257 } |
| 259 | 258 |
| 260 chrome.runtime.onMessage.addListener(feedbackReadyHandler); | 259 chrome.runtime.onMessage.addListener(feedbackReadyHandler); |
| 261 chrome.runtime.onMessageExternal.addListener(requestFeedbackHandler); | 260 chrome.runtime.onMessageExternal.addListener(requestFeedbackHandler); |
| 262 chrome.feedbackPrivate.onFeedbackRequested.addListener(startFeedbackUI); | 261 chrome.feedbackPrivate.onFeedbackRequested.addListener(startFeedbackUI); |
| OLD | NEW |