Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(820)

Side by Side Diff: chrome/renderer/resources/extension_process_bindings.js

Issue 242150: Implement browserAction.setIcon(ImageData) for extensions. (Closed)
Patch Set: common function Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // ----------------------------------------------------------------------------- 5 // -----------------------------------------------------------------------------
6 // NOTE: If you change this file you need to touch renderer_resources.grd to 6 // NOTE: If you change this file you need to touch renderer_resources.grd to
7 // have your change take effect. 7 // have your change take effect.
8 // ----------------------------------------------------------------------------- 8 // -----------------------------------------------------------------------------
9 9
10 // This script contains privileged chrome extension related javascript APIs. 10 // This script contains privileged chrome extension related javascript APIs.
11 // It is loaded by pages whose URL has the chrome-extension protocol. 11 // It is loaded by pages whose URL has the chrome-extension protocol.
12 12
13 var chrome = chrome || {}; 13 var chrome = chrome || {};
14 (function() { 14 (function() {
15 native function GetExtensionAPIDefinition(); 15 native function GetExtensionAPIDefinition();
16 native function StartRequest(); 16 native function StartRequest();
17 native function GetCurrentPageActions(extensionId); 17 native function GetCurrentPageActions(extensionId);
18 native function GetExtensionViews(); 18 native function GetExtensionViews();
19 native function GetChromeHidden(); 19 native function GetChromeHidden();
20 native function GetNextRequestId(); 20 native function GetNextRequestId();
21 native function OpenChannelToTab(); 21 native function OpenChannelToTab();
22 native function GetRenderViewId(); 22 native function GetRenderViewId();
23 native function GetL10nMessage(); 23 native function GetL10nMessage();
24 native function SetBrowserActionIcon();
24 25
25 if (!chrome) 26 if (!chrome)
26 chrome = {}; 27 chrome = {};
27 28
28 var chromeHidden = GetChromeHidden(); 29 var chromeHidden = GetChromeHidden();
29 30
30 // Validate arguments. 31 // Validate arguments.
31 chromeHidden.validationTypes = []; 32 chromeHidden.validationTypes = [];
32 chromeHidden.validate = function(args, schemas) { 33 chromeHidden.validate = function(args, schemas) {
33 if (args.length > schemas.length) 34 if (args.length > schemas.length)
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 // JSON.stringify doesn't support a root object which is undefined. 169 // JSON.stringify doesn't support a root object which is undefined.
169 if (request.args === undefined) 170 if (request.args === undefined)
170 request.args = null; 171 request.args = null;
171 var sargs = JSON.stringify(request.args); 172 var sargs = JSON.stringify(request.args);
172 var requestId = GetNextRequestId(); 173 var requestId = GetNextRequestId();
173 requests[requestId] = request; 174 requests[requestId] = request;
174 return StartRequest(functionName, sargs, requestId, 175 return StartRequest(functionName, sargs, requestId,
175 request.callback ? true : false); 176 request.callback ? true : false);
176 } 177 }
177 178
179 // Send a special API request that is not JSON stringifiable, and optionally
180 // register a callback.
181 function sendCustomRequest(nativeFunction, functionName, args, argSchemas) {
182 var request = prepareRequest(args, argSchemas);
183 var requestId = GetNextRequestId();
184 requests[requestId] = request;
185 return nativeFunction(functionName, args, requestId,
186 request.callback ? true : false);
187 }
188
178 function bind(obj, func) { 189 function bind(obj, func) {
179 return function() { 190 return function() {
180 return func.apply(obj, arguments); 191 return func.apply(obj, arguments);
181 }; 192 };
182 } 193 }
183 194
184 // --- Setup additional api's not currently handled in common/extensions/api 195 // --- Setup additional api's not currently handled in common/extensions/api
185 196
186 // Page action events send (pageActionId, {tabId, tabUrl}). 197 // Page action events send (pageActionId, {tabId, tabUrl}).
187 function setupPageActionEvents(extensionId) { 198 function setupPageActionEvents(extensionId) {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 tabIdProxy[name] = new chrome.Event("devtools." + tabId + "." + name); 333 tabIdProxy[name] = new chrome.Event("devtools." + tabId + "." + name);
323 }); 334 });
324 return tabIdProxy; 335 return tabIdProxy;
325 } 336 }
326 337
327 apiFunctions["i18n.getMessage"].handleRequest = 338 apiFunctions["i18n.getMessage"].handleRequest =
328 function(message_name, placeholders) { 339 function(message_name, placeholders) {
329 return GetL10nMessage(message_name, placeholders); 340 return GetL10nMessage(message_name, placeholders);
330 } 341 }
331 342
343 apiFunctions["browserAction.setIcon"].handleRequest =
344 function(idOrImageData) {
345 if (typeof(idOrImageData) == "number") {
346 sendRequest(this.name, arguments, this.definition.parameters);
347 } else if (typeof(idOrImageData) == "object") {
348 sendCustomRequest(SetBrowserActionIcon, "browserAction.setIcon",
349 idOrImageData, this.definition.parameters);
350 }
351 }
352
332 setupPageActionEvents(extensionId); 353 setupPageActionEvents(extensionId);
333 setupBrowserActionEvent(extensionId); 354 setupBrowserActionEvent(extensionId);
334 setupToolstripEvents(GetRenderViewId()); 355 setupToolstripEvents(GetRenderViewId());
335 }); 356 });
336 })(); 357 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698