| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 // Implementation of custom bindings for the contextMenus API. | 5 // Implementation of custom bindings for the contextMenus API. |
| 6 // This is used to implement the contextMenus API for extensions and for the | 6 // This is used to implement the contextMenus API for extensions and for the |
| 7 // <webview> tag (see chrome_web_view_experimental.js). | 7 // <webview> tag (see chrome_web_view_experimental.js). |
| 8 | 8 |
| 9 var contextMenuNatives = requireNative('context_menus'); | 9 var contextMenuNatives = requireNative('context_menus'); |
| 10 var sendRequest = bindingUtil ? | 10 var sendRequest = bindingUtil ? |
| 11 $Function.bind(bindingUtil.sendRequest, bindingUtil) : | 11 $Function.bind(bindingUtil.sendRequest, bindingUtil) : |
| 12 require('sendRequest').sendRequest; | 12 require('sendRequest').sendRequest; |
| 13 var hasLastError = bindingUtil ? | 13 var hasLastError = bindingUtil ? |
| 14 $Function.bind(bindingUtil.hasLastError, bindingUtil) : | 14 $Function.bind(bindingUtil.hasLastError, bindingUtil) : |
| 15 require('lastError').hasError; | 15 require('lastError').hasError; |
| 16 | 16 |
| 17 var jsEvent; | 17 var jsEvent; |
| 18 function createNewEvent(name) { | 18 function createNewEvent(name, isWebview) { |
| 19 var supportsLazyListeners = !isWebview; |
| 20 var supportsFilters = false; |
| 19 if (bindingUtil) { | 21 if (bindingUtil) { |
| 20 // Native custom events ignore schema. | 22 // Native custom events ignore schema. |
| 21 return bindingUtil.createCustomEvent(name, undefined, undefined); | 23 return bindingUtil.createCustomEvent(name, undefined, supportsFilters, |
| 24 supportsLazyListeners); |
| 22 } | 25 } |
| 23 if (!jsEvent) | 26 if (!jsEvent) |
| 24 jsEvent = require('event_bindings').Event; | 27 jsEvent = require('event_bindings').Event; |
| 25 return new jsEvent(name); | 28 var eventOpts = { |
| 29 __proto__: null, |
| 30 supportsLazyListeners: supportsLazyListeners, |
| 31 supportsFilters: supportsFilters, |
| 32 }; |
| 33 return new jsEvent(name, null, eventOpts); |
| 26 } | 34 } |
| 27 | 35 |
| 28 // Add the bindings to the contextMenus API. | 36 // Add the bindings to the contextMenus API. |
| 29 function createContextMenusHandlers(isWebview) { | 37 function createContextMenusHandlers(isWebview) { |
| 30 var eventName = isWebview ? 'webViewInternal.contextMenus' : 'contextMenus'; | 38 var eventName = isWebview ? 'webViewInternal.contextMenus' : 'contextMenus'; |
| 31 // Some dummy value for chrome.contextMenus instances. | 39 // Some dummy value for chrome.contextMenus instances. |
| 32 // Webviews use positive integers, and 0 to denote an invalid webview ID. | 40 // Webviews use positive integers, and 0 to denote an invalid webview ID. |
| 33 // The following constant is -1 to avoid any conflicts between webview IDs and | 41 // The following constant is -1 to avoid any conflicts between webview IDs and |
| 34 // extensions. | 42 // extensions. |
| 35 var INSTANCEID_NON_WEBVIEW = -1; | 43 var INSTANCEID_NON_WEBVIEW = -1; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 46 } | 54 } |
| 47 | 55 |
| 48 $Function.apply(handleCallback, null, arguments); | 56 $Function.apply(handleCallback, null, arguments); |
| 49 if (extensionCallback) | 57 if (extensionCallback) |
| 50 extensionCallback(); | 58 extensionCallback(); |
| 51 }; | 59 }; |
| 52 } | 60 } |
| 53 | 61 |
| 54 var contextMenus = { __proto__: null }; | 62 var contextMenus = { __proto__: null }; |
| 55 contextMenus.handlers = { __proto__: null }; | 63 contextMenus.handlers = { __proto__: null }; |
| 56 contextMenus.event = createNewEvent(eventName); | 64 contextMenus.event = createNewEvent(eventName, isWebview); |
| 57 | 65 |
| 58 contextMenus.getIdFromCreateProperties = function(createProperties) { | 66 contextMenus.getIdFromCreateProperties = function(createProperties) { |
| 59 if (typeof createProperties.id !== 'undefined') | 67 if (typeof createProperties.id !== 'undefined') |
| 60 return createProperties.id; | 68 return createProperties.id; |
| 61 return createProperties.generatedId; | 69 return createProperties.generatedId; |
| 62 }; | 70 }; |
| 63 | 71 |
| 64 contextMenus.handlersForId = function(instanceId, id) { | 72 contextMenus.handlersForId = function(instanceId, id) { |
| 65 if (!contextMenus.handlers[instanceId]) { | 73 if (!contextMenus.handlers[instanceId]) { |
| 66 contextMenus.handlers[instanceId] = { | 74 contextMenus.handlers[instanceId] = { |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 sendRequest(name, $Array.from(arguments), | 197 sendRequest(name, $Array.from(arguments), |
| 190 bindingUtil ? undefined : this.definition.parameters, optArgs); | 198 bindingUtil ? undefined : this.definition.parameters, optArgs); |
| 191 }; | 199 }; |
| 192 | 200 |
| 193 return { | 201 return { |
| 194 requestHandlers: requestHandlers, | 202 requestHandlers: requestHandlers, |
| 195 }; | 203 }; |
| 196 } | 204 } |
| 197 | 205 |
| 198 exports.$set('create', createContextMenusHandlers); | 206 exports.$set('create', createContextMenusHandlers); |
| OLD | NEW |