| 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(); |
| 11 native function StartRequest(); | 11 native function StartRequest(); |
| 12 native function GetCurrentPageActions(extensionId); | 12 native function GetCurrentPageActions(extensionId); |
| 13 native function GetExtensionViews(); | 13 native function GetExtensionViews(); |
| 14 native function GetChromeHidden(); | 14 native function GetChromeHidden(); |
| 15 native function GetNextRequestId(); | 15 native function GetNextRequestId(); |
| 16 native function OpenChannelToTab(); | 16 native function OpenChannelToTab(); |
| 17 native function GetRenderViewId(); | 17 native function GetRenderViewId(); |
| 18 native function GetL10nMessage(); | 18 native function GetL10nMessage(); |
| 19 native function SetBrowserActionIcon(); | 19 native function SetExtensionActionIcon(); |
| 20 | 20 |
| 21 if (!chrome) | 21 if (!chrome) |
| 22 chrome = {}; | 22 chrome = {}; |
| 23 | 23 |
| 24 var chromeHidden = GetChromeHidden(); | 24 var chromeHidden = GetChromeHidden(); |
| 25 | 25 |
| 26 // Validate arguments. | 26 // Validate arguments. |
| 27 chromeHidden.validationTypes = []; | 27 chromeHidden.validationTypes = []; |
| 28 chromeHidden.validate = function(args, schemas) { | 28 chromeHidden.validate = function(args, schemas) { |
| 29 if (args.length > schemas.length) | 29 if (args.length > schemas.length) |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 return StartRequest(functionName, sargs, requestId, | 170 return StartRequest(functionName, sargs, requestId, |
| 171 request.callback ? true : false); | 171 request.callback ? true : false); |
| 172 } | 172 } |
| 173 | 173 |
| 174 // Send a special API request that is not JSON stringifiable, and optionally | 174 // Send a special API request that is not JSON stringifiable, and optionally |
| 175 // register a callback. | 175 // register a callback. |
| 176 function sendCustomRequest(nativeFunction, functionName, args, argSchemas) { | 176 function sendCustomRequest(nativeFunction, functionName, args, argSchemas) { |
| 177 var request = prepareRequest(args, argSchemas); | 177 var request = prepareRequest(args, argSchemas); |
| 178 var requestId = GetNextRequestId(); | 178 var requestId = GetNextRequestId(); |
| 179 requests[requestId] = request; | 179 requests[requestId] = request; |
| 180 return nativeFunction(functionName, args, requestId, | 180 return nativeFunction(functionName, request.args, requestId, |
| 181 request.callback ? true : false); | 181 request.callback ? true : false); |
| 182 } | 182 } |
| 183 | 183 |
| 184 function bind(obj, func) { | 184 function bind(obj, func) { |
| 185 return function() { | 185 return function() { |
| 186 return func.apply(obj, arguments); | 186 return func.apply(obj, arguments); |
| 187 }; | 187 }; |
| 188 } | 188 } |
| 189 | 189 |
| 190 // --- Setup additional api's not currently handled in common/extensions/api | 190 // --- Setup additional api's not currently handled in common/extensions/api |
| (...skipping 135 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 = function(details) { | 336 function setIconCommon(details, name, parameters) { |
| 337 if ("iconIndex" in details) { | 337 if ("iconIndex" in details) { |
| 338 sendRequest(this.name, arguments, this.definition.parameters); | 338 sendRequest(name, [details], parameters); |
| 339 } else if ("imageData" in details) { | 339 } else if ("imageData" in details) { |
| 340 // Verify that this at least looks like an ImageData element. | 340 // Verify that this at least looks like an ImageData element. |
| 341 // Unfortunately, we cannot use instanceof because the ImageData | 341 // Unfortunately, we cannot use instanceof because the ImageData |
| 342 // constructor is not public. | 342 // constructor is not public. |
| 343 // | 343 // |
| 344 // We do this manually instead of using JSONSchema to avoid having these | 344 // We do this manually instead of using JSONSchema to avoid having these |
| 345 // properties show up in the doc. | 345 // properties show up in the doc. |
| 346 if (!("width" in details.imageData) || | 346 if (!("width" in details.imageData) || |
| 347 !("height" in details.imageData) || | 347 !("height" in details.imageData) || |
| 348 !("data" in details.imageData)) { | 348 !("data" in details.imageData)) { |
| 349 throw new Error( | 349 throw new Error( |
| 350 "The imageData property must contain an ImageData object."); | 350 "The imageData property must contain an ImageData object."); |
| 351 } | 351 } |
| 352 | 352 sendCustomRequest(SetExtensionActionIcon, name, [details], parameters); |
| 353 sendCustomRequest(SetBrowserActionIcon, "browserAction.setIcon", | |
| 354 details, this.definition.parameters); | |
| 355 } else { | 353 } else { |
| 356 throw new Error( | 354 throw new Error( |
| 357 "Either the iconIndex or imageData property must be specified."); | 355 "Either the iconIndex or imageData property must be specified."); |
| 358 } | 356 } |
| 359 } | 357 } |
| 360 | 358 |
| 359 apiFunctions["browserAction.setIcon"].handleRequest = function(details) { |
| 360 setIconCommon(details, this.name, this.definition.parameters); |
| 361 }; |
| 362 |
| 363 apiFunctions["pageAction.setIcon"].handleRequest = function(details) { |
| 364 setIconCommon(details, this.name, this.definition.parameters); |
| 365 }; |
| 366 |
| 361 setupBrowserActionEvent(extensionId); | 367 setupBrowserActionEvent(extensionId); |
| 362 setupPageActionEvents(extensionId); | 368 setupPageActionEvents(extensionId); |
| 363 setupToolstripEvents(GetRenderViewId()); | 369 setupToolstripEvents(GetRenderViewId()); |
| 364 }); | 370 }); |
| 365 })(); | 371 })(); |
| OLD | NEW |