| 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 var canvas; |
| 337 function setIconCommon(details, name, parameters) { | 337 function setIconCommon(details, name, parameters) { |
| 338 if ("iconIndex" in details) { | 338 if ("iconIndex" in details) { |
| 339 sendRequest(name, [details], parameters); | 339 sendRequest(name, [details], parameters); |
| 340 } else if ("imageData" in details) { | 340 } else if ("imageData" in details) { |
| 341 // Verify that this at least looks like an ImageData element. | 341 // Verify that this at least looks like an ImageData element. |
| 342 // Unfortunately, we cannot use instanceof because the ImageData | 342 // Unfortunately, we cannot use instanceof because the ImageData |
| 343 // constructor is not public. | 343 // constructor is not public. |
| 344 // | 344 // |
| 345 // 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 |
| 346 // properties show up in the doc. | 346 // properties show up in the doc. |
| 347 if (!("width" in details.imageData) || | 347 if (!("width" in details.imageData) || |
| 348 !("height" in details.imageData) || | 348 !("height" in details.imageData) || |
| 349 !("data" in details.imageData)) { | 349 !("data" in details.imageData)) { |
| 350 throw new Error( | 350 throw new Error( |
| 351 "The imageData property must contain an ImageData object."); | 351 "The imageData property must contain an ImageData object."); |
| 352 } | 352 } |
| 353 sendCustomRequest(SetExtensionActionIcon, name, [details], parameters); | 353 sendCustomRequest(SetExtensionActionIcon, name, [details], parameters); |
| 354 } else if ("path" in details) { | 354 } else if ("path" in details) { |
| 355 if (!canvas_context) { | 355 if (!canvas) { |
| 356 var canvas = document.createElement("canvas"); | 356 var canvas = document.createElement("canvas"); |
| 357 canvas.width = 19; | 357 canvas.width = 19; |
| 358 canvas.height = 19; | 358 canvas.height = 19; |
| 359 canvas_context = canvas.getContext('2d'); | |
| 360 } | 359 } |
| 361 | 360 |
| 361 var canvas_context = canvas.getContext('2d'); |
| 362 var img = new Image(); | 362 var img = new Image(); |
| 363 var self = this; | 363 var self = this; |
| 364 img.onerror = function() { | 364 img.onerror = function() { |
| 365 console.error("Could not load browser action icon '" + details.path + | 365 console.error("Could not load browser action icon '" + details.path + |
| 366 "'."); | 366 "'."); |
| 367 } | 367 } |
| 368 img.onload = function() { | 368 img.onload = function() { |
| 369 canvas_context.clearRect(0, 0, canvas.width, canvas.height); | 369 canvas_context.clearRect(0, 0, canvas.width, canvas.height); |
| 370 canvas_context.drawImage(img, 0, 0, canvas.width, canvas.height); | 370 canvas_context.drawImage(img, 0, 0, canvas.width, canvas.height); |
| 371 delete details.path; | 371 delete details.path; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 386 | 386 |
| 387 apiFunctions["pageAction.setIcon"].handleRequest = function(details) { | 387 apiFunctions["pageAction.setIcon"].handleRequest = function(details) { |
| 388 setIconCommon(details, this.name, this.definition.parameters); | 388 setIconCommon(details, this.name, this.definition.parameters); |
| 389 }; | 389 }; |
| 390 | 390 |
| 391 setupBrowserActionEvent(extensionId); | 391 setupBrowserActionEvent(extensionId); |
| 392 setupPageActionEvents(extensionId); | 392 setupPageActionEvents(extensionId); |
| 393 setupToolstripEvents(GetRenderViewId()); | 393 setupToolstripEvents(GetRenderViewId()); |
| 394 }); | 394 }); |
| 395 })(); | 395 })(); |
| OLD | NEW |