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

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

Issue 262016: Implement chrome.extension.connectExternal and fix various API inconsistencies. (Closed)
Patch Set: addressed comments 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 // -----------------------------------------------------------------------------
6 // NOTE: If you change this file you need to touch renderer_resources.grd to
7 // have your change take effect.
8 // -----------------------------------------------------------------------------
9
10 // This script contains privileged chrome extension related javascript APIs. 5 // This script contains privileged chrome extension related javascript APIs.
11 // 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.
12 7
13 var chrome = chrome || {}; 8 var chrome = chrome || {};
14 (function() { 9 (function() {
15 native function GetExtensionAPIDefinition(); 10 native function GetExtensionAPIDefinition();
16 native function StartRequest(); 11 native function StartRequest();
17 native function GetCurrentPageActions(extensionId); 12 native function GetCurrentPageActions(extensionId);
18 native function GetExtensionViews(); 13 native function GetExtensionViews();
19 native function GetChromeHidden(); 14 native function GetChromeHidden();
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 209
215 function setupToolstripEvents(renderViewId) { 210 function setupToolstripEvents(renderViewId) {
216 chrome.toolstrip = chrome.toolstrip || {}; 211 chrome.toolstrip = chrome.toolstrip || {};
217 chrome.toolstrip.onExpanded = 212 chrome.toolstrip.onExpanded =
218 new chrome.Event("toolstrip.onExpanded." + renderViewId); 213 new chrome.Event("toolstrip.onExpanded." + renderViewId);
219 chrome.toolstrip.onCollapsed = 214 chrome.toolstrip.onCollapsed =
220 new chrome.Event("toolstrip.onCollapsed." + renderViewId); 215 new chrome.Event("toolstrip.onCollapsed." + renderViewId);
221 } 216 }
222 217
223 chromeHidden.onLoad.addListener(function (extensionId) { 218 chromeHidden.onLoad.addListener(function (extensionId) {
224 chrome.extension = new chrome.Extension(extensionId); 219 chrome.initExtension(extensionId);
225
226 // TODO(mpcomplete): chrome.self is deprecated. Remove it at 1.0.
227 // http://code.google.com/p/chromium/issues/detail?id=16356
228 chrome.self = chrome.extension;
229 220
230 // |apiFunctions| is a hash of name -> object that stores the 221 // |apiFunctions| is a hash of name -> object that stores the
231 // name & definition of the apiFunction. Custom handling of api functions 222 // name & definition of the apiFunction. Custom handling of api functions
232 // is implemented by adding a "handleRequest" function to the object. 223 // is implemented by adding a "handleRequest" function to the object.
233 var apiFunctions = {}; 224 var apiFunctions = {};
234 225
235 // Read api definitions and setup api functions in the chrome namespace. 226 // Read api definitions and setup api functions in the chrome namespace.
236 // TODO(rafaelw): Consider defining a json schema for an api definition 227 // TODO(rafaelw): Consider defining a json schema for an api definition
237 // and validating either here, in a unit_test or both. 228 // and validating either here, in a unit_test or both.
238 // TODO(rafaelw): Handle synchronous functions. 229 // TODO(rafaelw): Handle synchronous functions.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 }); 281 });
291 } 282 }
292 }); 283 });
293 284
294 apiFunctions["tabs.connect"].handleRequest = function(tabId, connectInfo) { 285 apiFunctions["tabs.connect"].handleRequest = function(tabId, connectInfo) {
295 var name = ""; 286 var name = "";
296 if (connectInfo) { 287 if (connectInfo) {
297 name = connectInfo.name || name; 288 name = connectInfo.name || name;
298 } 289 }
299 var portId = OpenChannelToTab( 290 var portId = OpenChannelToTab(
300 tabId, chrome.extension.id_, name); 291 tabId, chromeHidden.extensionId, name);
301 return chromeHidden.Port.createPort(portId, name); 292 return chromeHidden.Port.createPort(portId, name);
302 } 293 }
303 294
304 apiFunctions["extension.getViews"].handleRequest = function() { 295 apiFunctions["extension.getViews"].handleRequest = function() {
305 return GetExtensionViews(-1, "ALL"); 296 return GetExtensionViews(-1, "ALL");
306 } 297 }
307 298
308 apiFunctions["extension.getBackgroundPage"].handleRequest = function() { 299 apiFunctions["extension.getBackgroundPage"].handleRequest = function() {
309 return GetExtensionViews(-1, "BACKGROUND")[0] || null; 300 return GetExtensionViews(-1, "BACKGROUND")[0] || null;
310 } 301 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 sendCustomRequest(SetBrowserActionIcon, "browserAction.setIcon", 339 sendCustomRequest(SetBrowserActionIcon, "browserAction.setIcon",
349 idOrImageData, this.definition.parameters); 340 idOrImageData, this.definition.parameters);
350 } 341 }
351 } 342 }
352 343
353 setupPageActionEvents(extensionId); 344 setupPageActionEvents(extensionId);
354 setupBrowserActionEvent(extensionId); 345 setupBrowserActionEvent(extensionId);
355 setupToolstripEvents(GetRenderViewId()); 346 setupToolstripEvents(GetRenderViewId());
356 }); 347 });
357 })(); 348 })();
OLDNEW
« no previous file with comments | « chrome/renderer/resources/event_bindings.js ('k') | chrome/renderer/resources/renderer_extension_bindings.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698