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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 chrome.experimental.popup.onClosed = | 261 chrome.experimental.popup.onClosed = |
262 new chrome.Event("experimental.popup.onClosed." + renderViewId); | 262 new chrome.Event("experimental.popup.onClosed." + renderViewId); |
263 } | 263 } |
264 | 264 |
265 function setupHiddenContextMenuEvent(extensionId) { | 265 function setupHiddenContextMenuEvent(extensionId) { |
266 chromeHidden.contextMenus = {}; | 266 chromeHidden.contextMenus = {}; |
267 chromeHidden.contextMenus.nextId = 1; | 267 chromeHidden.contextMenus.nextId = 1; |
268 chromeHidden.contextMenus.handlers = {}; | 268 chromeHidden.contextMenus.handlers = {}; |
269 var eventName = "contextMenus/" + extensionId; | 269 var eventName = "contextMenus/" + extensionId; |
270 chromeHidden.contextMenus.event = new chrome.Event(eventName); | 270 chromeHidden.contextMenus.event = new chrome.Event(eventName); |
271 chromeHidden.contextMenus.event.addListener(function() { | 271 chromeHidden.contextMenus.ensureListenerSetup = function() { |
272 // An extension context menu item has been clicked on - fire the onclick | 272 if (chromeHidden.contextMenus.listening) { |
273 // if there is one. | 273 return; |
274 var id = arguments[0].menuItemId; | |
275 var onclick = chromeHidden.contextMenus.handlers[id]; | |
276 if (onclick) { | |
277 onclick.apply(onclick, arguments); | |
278 } | 274 } |
279 }); | 275 chromeHidden.contextMenus.listening = true; |
| 276 chromeHidden.contextMenus.event.addListener(function() { |
| 277 // An extension context menu item has been clicked on - fire the onclick |
| 278 // if there is one. |
| 279 var id = arguments[0].menuItemId; |
| 280 var onclick = chromeHidden.contextMenus.handlers[id]; |
| 281 if (onclick) { |
| 282 onclick.apply(onclick, arguments); |
| 283 } |
| 284 }); |
| 285 }; |
280 } | 286 } |
281 | 287 |
282 function setupOmniboxEvents(extensionId) { | 288 function setupOmniboxEvents(extensionId) { |
283 chrome.experimental.omnibox.onInputChanged.dispatch = | 289 chrome.experimental.omnibox.onInputChanged.dispatch = |
284 function(text, requestId) { | 290 function(text, requestId) { |
285 var suggestCallback = function(suggestions) { | 291 var suggestCallback = function(suggestions) { |
286 chrome.experimental.omnibox.sendSuggestions(requestId, suggestions); | 292 chrome.experimental.omnibox.sendSuggestions(requestId, suggestions); |
287 } | 293 } |
288 chrome.Event.prototype.dispatch.apply(this, [text, suggestCallback]); | 294 chrome.Event.prototype.dispatch.apply(this, [text, suggestCallback]); |
289 }; | 295 }; |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 function(name, request, response) { | 615 function(name, request, response) { |
610 if (chrome.extension.lastError) { | 616 if (chrome.extension.lastError) { |
611 return; | 617 return; |
612 } | 618 } |
613 | 619 |
614 var id = request.args[0].generatedId; | 620 var id = request.args[0].generatedId; |
615 | 621 |
616 // Set up the onclick handler if we were passed one in the request. | 622 // Set up the onclick handler if we were passed one in the request. |
617 var onclick = request.args.length ? request.args[0].onclick : null; | 623 var onclick = request.args.length ? request.args[0].onclick : null; |
618 if (onclick) { | 624 if (onclick) { |
| 625 chromeHidden.contextMenus.ensureListenerSetup(); |
619 chromeHidden.contextMenus.handlers[id] = onclick; | 626 chromeHidden.contextMenus.handlers[id] = onclick; |
620 } | 627 } |
621 }; | 628 }; |
622 | 629 |
623 apiFunctions["experimental.contextMenus.remove"].customCallback = | 630 apiFunctions["experimental.contextMenus.remove"].customCallback = |
624 function(name, request, response) { | 631 function(name, request, response) { |
625 if (chrome.extension.lastError) { | 632 if (chrome.extension.lastError) { |
626 return; | 633 return; |
627 } | 634 } |
628 var id = request.args[0]; | 635 var id = request.args[0]; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 setupHiddenContextMenuEvent(extensionId); | 701 setupHiddenContextMenuEvent(extensionId); |
695 setupOmniboxEvents(extensionId); | 702 setupOmniboxEvents(extensionId); |
696 }); | 703 }); |
697 | 704 |
698 if (!chrome.experimental) | 705 if (!chrome.experimental) |
699 chrome.experimental = {}; | 706 chrome.experimental = {}; |
700 | 707 |
701 if (!chrome.experimental.accessibility) | 708 if (!chrome.experimental.accessibility) |
702 chrome.experimental.accessibility = {}; | 709 chrome.experimental.accessibility = {}; |
703 })(); | 710 })(); |
OLD | NEW |