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

Side by Side Diff: extensions/renderer/resources/context_menus_handlers.js

Issue 2973903002: [Extensions Bindings] Introduce a supportsLazyListeners property (Closed)
Patch Set: . Created 3 years, 5 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 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;
19 if (bindingUtil) { 20 if (bindingUtil) {
21 var supportsFilters = false;
lazyboy 2017/07/14 00:04:42 Pull this out after line 19 and use it for eventOp
Devlin 2017/07/14 15:37:54 Wasn't like this previously because supportsFilter
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;
28 var eventOpts =
29 { __proto__: null, supportsLazyListeners: supportsLazyListeners };
lazyboy 2017/07/14 00:04:42 I don't remember style guide put space after {, is
Devlin 2017/07/14 15:37:54 I think clang-format doesn't (though JS support fo
25 return new jsEvent(name); 30 return new jsEvent(name);
lazyboy 2017/07/14 00:04:42 Should we not use eventOpts here?
Devlin 2017/07/14 15:37:54 We should! Thanks for catching this. I've expand
26 } 31 }
27 32
28 // Add the bindings to the contextMenus API. 33 // Add the bindings to the contextMenus API.
29 function createContextMenusHandlers(isWebview) { 34 function createContextMenusHandlers(isWebview) {
30 var eventName = isWebview ? 'webViewInternal.contextMenus' : 'contextMenus'; 35 var eventName = isWebview ? 'webViewInternal.contextMenus' : 'contextMenus';
31 // Some dummy value for chrome.contextMenus instances. 36 // Some dummy value for chrome.contextMenus instances.
32 // Webviews use positive integers, and 0 to denote an invalid webview ID. 37 // 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 38 // The following constant is -1 to avoid any conflicts between webview IDs and
34 // extensions. 39 // extensions.
35 var INSTANCEID_NON_WEBVIEW = -1; 40 var INSTANCEID_NON_WEBVIEW = -1;
(...skipping 10 matching lines...) Expand all
46 } 51 }
47 52
48 $Function.apply(handleCallback, null, arguments); 53 $Function.apply(handleCallback, null, arguments);
49 if (extensionCallback) 54 if (extensionCallback)
50 extensionCallback(); 55 extensionCallback();
51 }; 56 };
52 } 57 }
53 58
54 var contextMenus = { __proto__: null }; 59 var contextMenus = { __proto__: null };
55 contextMenus.handlers = { __proto__: null }; 60 contextMenus.handlers = { __proto__: null };
56 contextMenus.event = createNewEvent(eventName); 61 contextMenus.event = createNewEvent(eventName, isWebview);
57 62
58 contextMenus.getIdFromCreateProperties = function(createProperties) { 63 contextMenus.getIdFromCreateProperties = function(createProperties) {
59 if (typeof createProperties.id !== 'undefined') 64 if (typeof createProperties.id !== 'undefined')
60 return createProperties.id; 65 return createProperties.id;
61 return createProperties.generatedId; 66 return createProperties.generatedId;
62 }; 67 };
63 68
64 contextMenus.handlersForId = function(instanceId, id) { 69 contextMenus.handlersForId = function(instanceId, id) {
65 if (!contextMenus.handlers[instanceId]) { 70 if (!contextMenus.handlers[instanceId]) {
66 contextMenus.handlers[instanceId] = { 71 contextMenus.handlers[instanceId] = {
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 sendRequest(name, $Array.from(arguments), 194 sendRequest(name, $Array.from(arguments),
190 bindingUtil ? undefined : this.definition.parameters, optArgs); 195 bindingUtil ? undefined : this.definition.parameters, optArgs);
191 }; 196 };
192 197
193 return { 198 return {
194 requestHandlers: requestHandlers, 199 requestHandlers: requestHandlers,
195 }; 200 };
196 } 201 }
197 202
198 exports.$set('create', createContextMenusHandlers); 203 exports.$set('create', createContextMenusHandlers);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698