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 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 // We do this manually instead of using JSONSchema to avoid having these | 357 // We do this manually instead of using JSONSchema to avoid having these |
358 // properties show up in the doc. | 358 // properties show up in the doc. |
359 if (!("width" in details.imageData) || | 359 if (!("width" in details.imageData) || |
360 !("height" in details.imageData) || | 360 !("height" in details.imageData) || |
361 !("data" in details.imageData)) { | 361 !("data" in details.imageData)) { |
362 throw new Error( | 362 throw new Error( |
363 "The imageData property must contain an ImageData object."); | 363 "The imageData property must contain an ImageData object."); |
364 } | 364 } |
365 sendCustomRequest(SetExtensionActionIcon, name, [details], parameters); | 365 sendCustomRequest(SetExtensionActionIcon, name, [details], parameters); |
366 } else if ("path" in details) { | 366 } else if ("path" in details) { |
367 if (!canvas) { | |
368 var canvas = document.createElement("canvas"); | |
369 canvas.width = 19; | |
370 canvas.height = 19; | |
371 } | |
372 | |
373 var canvas_context = canvas.getContext('2d'); | |
374 var img = new Image(); | 367 var img = new Image(); |
375 var self = this; | |
376 img.onerror = function() { | 368 img.onerror = function() { |
377 console.error("Could not load browser action icon '" + details.path + | 369 console.error("Could not load browser action icon '" + details.path + |
378 "'."); | 370 "'."); |
379 } | 371 } |
380 img.onload = function() { | 372 img.onload = function() { |
| 373 var canvas = document.createElement("canvas"); |
| 374 canvas.width = img.width > 19 ? 19 : img.width; |
| 375 canvas.height = img.height > 19 ? 19 : img.height; |
| 376 |
| 377 var canvas_context = canvas.getContext('2d'); |
381 canvas_context.clearRect(0, 0, canvas.width, canvas.height); | 378 canvas_context.clearRect(0, 0, canvas.width, canvas.height); |
382 canvas_context.drawImage(img, 0, 0, canvas.width, canvas.height); | 379 canvas_context.drawImage(img, 0, 0, canvas.width, canvas.height); |
383 delete details.path; | 380 delete details.path; |
384 details.imageData = canvas_context.getImageData(0, 0, canvas.width, | 381 details.imageData = canvas_context.getImageData(0, 0, canvas.width, |
385 canvas.height); | 382 canvas.height); |
386 sendCustomRequest(SetExtensionActionIcon, name, [details], parameters)
; | 383 sendCustomRequest(SetExtensionActionIcon, name, [details], parameters)
; |
387 } | 384 } |
388 img.src = details.path; | 385 img.src = details.path; |
389 } else { | 386 } else { |
390 throw new Error( | 387 throw new Error( |
391 "Either the path or imageData property must be specified."); | 388 "Either the path or imageData property must be specified."); |
392 } | 389 } |
393 } | 390 } |
394 | 391 |
395 apiFunctions["browserAction.setIcon"].handleRequest = function(details) { | 392 apiFunctions["browserAction.setIcon"].handleRequest = function(details) { |
396 setIconCommon(details, this.name, this.definition.parameters); | 393 setIconCommon(details, this.name, this.definition.parameters); |
397 }; | 394 }; |
398 | 395 |
399 apiFunctions["pageAction.setIcon"].handleRequest = function(details) { | 396 apiFunctions["pageAction.setIcon"].handleRequest = function(details) { |
400 setIconCommon(details, this.name, this.definition.parameters); | 397 setIconCommon(details, this.name, this.definition.parameters); |
401 }; | 398 }; |
402 | 399 |
403 setupBrowserActionEvent(extensionId); | 400 setupBrowserActionEvent(extensionId); |
404 setupPageActionEvents(extensionId); | 401 setupPageActionEvents(extensionId); |
405 setupToolstripEvents(GetRenderViewId()); | 402 setupToolstripEvents(GetRenderViewId()); |
406 }); | 403 }); |
407 })(); | 404 })(); |
OLD | NEW |