Chromium Code Reviews| 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 var canvas_context; | |
| 336 apiFunctions["browserAction.setIcon"].handleRequest = function(details) { | 337 apiFunctions["browserAction.setIcon"].handleRequest = function(details) { |
| 337 if ("iconIndex" in details) { | 338 if ("iconIndex" in details) { |
| 338 sendRequest(this.name, arguments, this.definition.parameters); | 339 sendRequest(this.name, arguments, this.definition.parameters); |
| 339 } else if ("imageData" in details) { | 340 } else if ("imageData" in details) { |
| 340 // Verify that this at least looks like an ImageData element. | 341 // Verify that this at least looks like an ImageData element. |
| 341 // Unfortunately, we cannot use instanceof because the ImageData | 342 // Unfortunately, we cannot use instanceof because the ImageData |
| 342 // constructor is not public. | 343 // constructor is not public. |
| 343 // | 344 // |
| 344 // We do this manually instead of using JSONSchema to avoid having these | 345 // We do this manually instead of using JSONSchema to avoid having these |
| 345 // properties show up in the doc. | 346 // properties show up in the doc. |
| 346 if (!("width" in details.imageData) || | 347 if (!("width" in details.imageData) || |
| 347 !("height" in details.imageData) || | 348 !("height" in details.imageData) || |
| 348 !("data" in details.imageData)) { | 349 !("data" in details.imageData)) { |
| 349 throw new Error( | 350 throw new Error( |
| 350 "The imageData property must contain an ImageData object."); | 351 "The imageData property must contain an ImageData object."); |
| 351 } | 352 } |
| 352 | 353 |
| 353 sendCustomRequest(SetBrowserActionIcon, "browserAction.setIcon", | 354 sendCustomRequest(SetBrowserActionIcon, "browserAction.setIcon", |
| 354 details, this.definition.parameters); | 355 details, this.definition.parameters); |
| 356 } else if ("path" in details) { | |
| 357 if (!canvas_context) { | |
| 358 var canvas = document.createElement("canvas"); | |
| 359 canvas.width = 19; | |
|
Matt Perry
2009/10/16 19:06:05
isn't it 21 now?
| |
| 360 canvas.height = 19; | |
| 361 canvas_context = canvas.getContext('2d'); | |
| 362 } | |
| 363 | |
| 364 var img = new Image(); | |
| 365 var self = this; | |
| 366 img.onerror = function() { | |
| 367 console.error("Could not load browser action icon '" + details.path + | |
| 368 "'."); | |
| 369 } | |
| 370 img.onload = function() { | |
| 371 canvas_context.clearRect(0, 0, context.width, context.height); | |
| 372 canvas_context.drawImage(img, 0, 0, context.width, context.height); | |
| 373 delete details.path; | |
| 374 details.imageData = canvas_context.getImageData(0, 0, context.width, | |
| 375 context.height); | |
| 376 sendCustomRequest(SetBrowserActionIcon, "browserAction.setIcon", | |
| 377 details, self.definition.parameters); | |
| 378 } | |
| 379 img.src = details.path; | |
| 355 } else { | 380 } else { |
| 356 throw new Error( | 381 throw new Error( |
| 357 "Either the iconIndex or imageData property must be specified."); | 382 "Either the iconIndex or imageData property must be specified."); |
| 358 } | 383 } |
| 359 } | 384 } |
| 360 | 385 |
| 361 setupBrowserActionEvent(extensionId); | 386 setupBrowserActionEvent(extensionId); |
| 362 setupPageActionEvents(extensionId); | 387 setupPageActionEvents(extensionId); |
| 363 setupToolstripEvents(GetRenderViewId()); | 388 setupToolstripEvents(GetRenderViewId()); |
| 364 }); | 389 }); |
| 365 })(); | 390 })(); |
| OLD | NEW |