OLD | NEW |
1 // Copyright (c) 2009 The chrome Authors. All rights reserved. | 1 // Copyright (c) 2009 The chrome 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 // This script contains privileged chrome extension related javascript APIs. | 5 // This script contains privileged chrome extension related javascript APIs. |
6 // It is loaded by pages whose URL has the chrome-extension protocol. | 6 // It is loaded by pages whose URL has the chrome-extension protocol. |
7 | 7 |
8 var chrome = chrome || {}; | 8 var chrome = chrome || {}; |
9 (function() { | 9 (function() { |
10 native function GetExtensionAPIDefinition(); | 10 native function GetExtensionAPIDefinition(); |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 tabIdProxy[name] = new chrome.Event("devtools." + tabId + "." + name); | 326 tabIdProxy[name] = new chrome.Event("devtools." + tabId + "." + name); |
327 }); | 327 }); |
328 return tabIdProxy; | 328 return tabIdProxy; |
329 } | 329 } |
330 | 330 |
331 apiFunctions["i18n.getMessage"].handleRequest = | 331 apiFunctions["i18n.getMessage"].handleRequest = |
332 function(message_name, placeholders) { | 332 function(message_name, placeholders) { |
333 return GetL10nMessage(message_name, placeholders); | 333 return GetL10nMessage(message_name, placeholders); |
334 } | 334 } |
335 | 335 |
336 apiFunctions["browserAction.setIcon"].handleRequest = | 336 apiFunctions["browserAction.setIcon"].handleRequest = function(details) { |
337 function(idOrImageData) { | 337 if ("iconIndex" in details) { |
338 if (typeof(idOrImageData) == "number") { | |
339 sendRequest(this.name, arguments, this.definition.parameters); | 338 sendRequest(this.name, arguments, this.definition.parameters); |
340 } else if (typeof(idOrImageData) == "object") { | 339 } else if ("imageData" in details) { |
| 340 // Verify that this at least looks like an ImageData element. |
| 341 // Unfortunately, we cannot use instanceof because the ImageData |
| 342 // constructor is not public. |
| 343 // |
| 344 // We do this manually instead of using JSONSchema to avoid having these |
| 345 // properties show up in the doc. |
| 346 if (!("width" in details.imageData) || |
| 347 !("height" in details.imageData) || |
| 348 !("data" in details.imageData)) { |
| 349 throw new Error( |
| 350 "The imageData property must contain an ImageData object."); |
| 351 } |
341 sendCustomRequest(SetBrowserActionIcon, "browserAction.setIcon", | 352 sendCustomRequest(SetBrowserActionIcon, "browserAction.setIcon", |
342 idOrImageData, this.definition.parameters); | 353 details, this.definition.parameters); |
| 354 } else { |
| 355 throw new Error( |
| 356 "Either the iconIndex or imageData property must be specified."); |
343 } | 357 } |
344 } | 358 } |
345 | 359 |
| 360 setupBrowserActionEvent(extensionId); |
346 setupPageActionEvents(extensionId); | 361 setupPageActionEvents(extensionId); |
347 setupBrowserActionEvent(extensionId); | |
348 setupToolstripEvents(GetRenderViewId()); | 362 setupToolstripEvents(GetRenderViewId()); |
349 }); | 363 }); |
350 })(); | 364 })(); |
OLD | NEW |