OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium 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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 // Page action events send (pageActionId, {tabId, tabUrl}). | 239 // Page action events send (pageActionId, {tabId, tabUrl}). |
240 function setupPageActionEvents(extensionId) { | 240 function setupPageActionEvents(extensionId) { |
241 var pageActions = GetCurrentPageActions(extensionId); | 241 var pageActions = GetCurrentPageActions(extensionId); |
242 | 242 |
243 var oldStyleEventName = "pageActions/" + extensionId; | 243 var oldStyleEventName = "pageActions/" + extensionId; |
244 // TODO(EXTENSIONS_DEPRECATED): only one page action | 244 // TODO(EXTENSIONS_DEPRECATED): only one page action |
245 for (var i = 0; i < pageActions.length; ++i) { | 245 for (var i = 0; i < pageActions.length; ++i) { |
246 // Setup events for each extension_id/page_action_id string we find. | 246 // Setup events for each extension_id/page_action_id string we find. |
247 chrome.pageActions[pageActions[i]] = new chrome.Event(oldStyleEventName); | 247 chrome.pageActions[pageActions[i]] = new chrome.Event(oldStyleEventName); |
248 } | 248 } |
249 | |
250 // Note this is singular. | |
251 var eventName = "pageAction/" + extensionId; | |
252 chrome.pageAction = chrome.pageAction || {}; | |
253 chrome.pageAction.onClicked = new chrome.Event(eventName); | |
254 } | |
255 | |
256 // Browser action events send {windowpId}. | |
257 function setupBrowserActionEvent(extensionId) { | |
258 var eventName = "browserAction/" + extensionId; | |
259 chrome.browserAction = chrome.browserAction || {}; | |
260 chrome.browserAction.onClicked = new chrome.Event(eventName); | |
261 } | 249 } |
262 | 250 |
263 function setupToolstripEvents(renderViewId) { | 251 function setupToolstripEvents(renderViewId) { |
264 chrome.toolstrip = chrome.toolstrip || {}; | 252 chrome.toolstrip = chrome.toolstrip || {}; |
265 chrome.toolstrip.onExpanded = | 253 chrome.toolstrip.onExpanded = |
266 new chrome.Event("toolstrip.onExpanded." + renderViewId); | 254 new chrome.Event("toolstrip.onExpanded." + renderViewId); |
267 chrome.toolstrip.onCollapsed = | 255 chrome.toolstrip.onCollapsed = |
268 new chrome.Event("toolstrip.onCollapsed." + renderViewId); | 256 new chrome.Event("toolstrip.onCollapsed." + renderViewId); |
269 } | 257 } |
270 | 258 |
(...skipping 16 matching lines...) Expand all Loading... |
287 | 275 |
288 var parentMenuItemId = arguments[0].parentMenuItemId; | 276 var parentMenuItemId = arguments[0].parentMenuItemId; |
289 var parentOnclick = chromeHidden.contextMenuHandlers[parentMenuItemId]; | 277 var parentOnclick = chromeHidden.contextMenuHandlers[parentMenuItemId]; |
290 if (parentOnclick) { | 278 if (parentOnclick) { |
291 parentOnclick.apply(parentOnclick, arguments); | 279 parentOnclick.apply(parentOnclick, arguments); |
292 } | 280 } |
293 }); | 281 }); |
294 } | 282 } |
295 | 283 |
296 function setupOmniboxEvents(extensionId) { | 284 function setupOmniboxEvents(extensionId) { |
297 chrome.experimental.omnibox.onInputEntered = | |
298 new chrome.Event("experimental.omnibox.onInputEntered/" + extensionId); | |
299 | |
300 chrome.experimental.omnibox.onInputChanged = | |
301 new chrome.Event("experimental.omnibox.onInputChanged/" + extensionId); | |
302 chrome.experimental.omnibox.onInputChanged.dispatch = | 285 chrome.experimental.omnibox.onInputChanged.dispatch = |
303 function(text, requestId) { | 286 function(text, requestId) { |
304 var suggestCallback = function(suggestions) { | 287 var suggestCallback = function(suggestions) { |
305 chrome.experimental.omnibox.sendSuggestions(requestId, suggestions); | 288 chrome.experimental.omnibox.sendSuggestions(requestId, suggestions); |
306 } | 289 } |
307 chrome.Event.prototype.dispatch.apply(this, [text, suggestCallback]); | 290 chrome.Event.prototype.dispatch.apply(this, [text, suggestCallback]); |
308 }; | 291 }; |
309 } | 292 } |
310 | 293 |
311 chromeHidden.onLoad.addListener(function (extensionId) { | 294 chromeHidden.onLoad.addListener(function (extensionId) { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 | 370 |
388 // Setup Events | 371 // Setup Events |
389 if (apiDef.events) { | 372 if (apiDef.events) { |
390 apiDef.events.forEach(function(eventDef) { | 373 apiDef.events.forEach(function(eventDef) { |
391 // Module events may have been defined earlier by hand. Don't clobber | 374 // Module events may have been defined earlier by hand. Don't clobber |
392 // them. | 375 // them. |
393 if (module[eventDef.name]) | 376 if (module[eventDef.name]) |
394 return; | 377 return; |
395 | 378 |
396 var eventName = apiDef.namespace + "." + eventDef.name; | 379 var eventName = apiDef.namespace + "." + eventDef.name; |
| 380 if (eventDef.perExtensionEvent) |
| 381 eventName = eventName + "/" + extensionId; |
397 module[eventDef.name] = new chrome.Event(eventName, | 382 module[eventDef.name] = new chrome.Event(eventName, |
398 eventDef.parameters); | 383 eventDef.parameters); |
399 }); | 384 }); |
400 } | 385 } |
401 | 386 |
402 | 387 |
403 // Parse any values defined for properties. | 388 // Parse any values defined for properties. |
404 if (apiDef.properties) { | 389 if (apiDef.properties) { |
405 for (var prop in apiDef.properties) { | 390 for (var prop in apiDef.properties) { |
406 if (!apiDef.properties.hasOwnProperty(prop)) | 391 if (!apiDef.properties.hasOwnProperty(prop)) |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 } | 649 } |
665 apiFunctions["experimental.omnibox.styleDim"].handleRequest = | 650 apiFunctions["experimental.omnibox.styleDim"].handleRequest = |
666 function(offset) { | 651 function(offset) { |
667 return {type: "dim", offset: offset}; | 652 return {type: "dim", offset: offset}; |
668 } | 653 } |
669 | 654 |
670 if (chrome.test) { | 655 if (chrome.test) { |
671 chrome.test.getApiDefinitions = GetExtensionAPIDefinition; | 656 chrome.test.getApiDefinitions = GetExtensionAPIDefinition; |
672 } | 657 } |
673 | 658 |
674 setupBrowserActionEvent(extensionId); | |
675 setupPageActionEvents(extensionId); | 659 setupPageActionEvents(extensionId); |
676 setupToolstripEvents(GetRenderViewId()); | 660 setupToolstripEvents(GetRenderViewId()); |
677 setupPopupEvents(GetRenderViewId()); | 661 setupPopupEvents(GetRenderViewId()); |
678 setupHiddenContextMenuEvent(extensionId); | 662 setupHiddenContextMenuEvent(extensionId); |
679 setupOmniboxEvents(extensionId); | 663 setupOmniboxEvents(extensionId); |
680 }); | 664 }); |
681 | 665 |
682 if (!chrome.experimental) | 666 if (!chrome.experimental) |
683 chrome.experimental = {}; | 667 chrome.experimental = {}; |
684 | 668 |
685 if (!chrome.experimental.accessibility) | 669 if (!chrome.experimental.accessibility) |
686 chrome.experimental.accessibility = {}; | 670 chrome.experimental.accessibility = {}; |
687 })(); | 671 })(); |
OLD | NEW |