Chromium Code Reviews| Index: extensions/renderer/resources/context_menus_custom_bindings.js |
| diff --git a/extensions/renderer/resources/context_menus_custom_bindings.js b/extensions/renderer/resources/context_menus_custom_bindings.js |
| index 0e82711b5c41fb47b4c8a998e609d576330fe303..8183ae614a20759faac22f8b83de2a13def6232f 100644 |
| --- a/extensions/renderer/resources/context_menus_custom_bindings.js |
| +++ b/extensions/renderer/resources/context_menus_custom_bindings.js |
| @@ -5,117 +5,22 @@ |
| // Custom binding for the contextMenus API. |
| var binding = require('binding').Binding.create('contextMenus'); |
| - |
| -var contextMenuNatives = requireNative('context_menus'); |
| -var sendRequest = require('sendRequest').sendRequest; |
| -var Event = require('event_bindings').Event; |
| -var lastError = require('lastError'); |
| +var contextMenusHandlers = require('contextMenusHandlers'); |
| binding.registerCustomHook(function(bindingsAPI) { |
| var apiFunctions = bindingsAPI.apiFunctions; |
| - var contextMenus = {}; |
| - contextMenus.generatedIdHandlers = {}; |
| - contextMenus.stringIdHandlers = {}; |
| - var eventName = 'contextMenus'; |
| - contextMenus.event = new Event(eventName); |
| - contextMenus.getIdFromCreateProperties = function(prop) { |
| - if (typeof(prop.id) !== 'undefined') |
| - return prop.id; |
| - return prop.generatedId; |
| - }; |
| - contextMenus.handlersForId = function(id) { |
| - if (typeof(id) === 'number') |
| - return contextMenus.generatedIdHandlers; |
| - return contextMenus.stringIdHandlers; |
| - }; |
| - contextMenus.ensureListenerSetup = function() { |
| - if (contextMenus.listening) { |
| - return; |
| - } |
| - contextMenus.listening = true; |
| - contextMenus.event.addListener(function() { |
| - // An extension context menu item has been clicked on - fire the onclick |
| - // if there is one. |
| - var id = arguments[0].menuItemId; |
| - var onclick = contextMenus.handlersForId(id)[id]; |
| - if (onclick) { |
| - $Function.apply(onclick, null, arguments); |
| - } |
| - }); |
| - }; |
| - |
| - apiFunctions.setHandleRequest('create', function() { |
| - var args = arguments; |
| - var id = contextMenuNatives.GetNextContextMenuId(); |
| - args[0].generatedId = id; |
| - var optArgs = { |
| - customCallback: this.customCallback, |
| - }; |
| - sendRequest(this.name, args, this.definition.parameters, optArgs); |
| - return contextMenus.getIdFromCreateProperties(args[0]); |
| - }); |
| - |
| - apiFunctions.setCustomCallback('create', |
| - function(name, request, callback, response) { |
| - if (lastError.hasError(chrome)) { |
| - if (callback) |
| - callback(); |
| - return; |
| - } |
| + var handlers = contextMenusHandlers.create(true /* isWebview */); |
|
lazyboy
2015/02/26 18:04:37
This should be false?
robwu
2015/02/26 22:51:23
Yes indeed, thanks for catching!
|
| - var id = contextMenus.getIdFromCreateProperties(request.args[0]); |
| + apiFunctions.setHandleRequest('create', handlers.requestHandlers.create); |
| - // Set up the onclick handler if we were passed one in the request. |
| - var onclick = request.args.length ? request.args[0].onclick : null; |
| - if (onclick) { |
| - contextMenus.ensureListenerSetup(); |
| - contextMenus.handlersForId(id)[id] = onclick; |
| - } |
| - if (callback) |
| - callback(); |
| - }); |
| + apiFunctions.setCustomCallback('create', handlers.callbacks.create); |
| - apiFunctions.setCustomCallback('remove', |
| - function(name, request, callback, response) { |
| - if (lastError.hasError(chrome)) { |
| - if (callback) |
| - callback(); |
| - return; |
| - } |
| - var id = request.args[0]; |
| - delete contextMenus.handlersForId(id)[id]; |
| - if (callback) |
| - callback(); |
| - }); |
| + apiFunctions.setCustomCallback('remove', handlers.callbacks.remove); |
| - apiFunctions.setCustomCallback('update', |
| - function(name, request, callback, response) { |
| - if (lastError.hasError(chrome)) { |
| - if (callback) |
| - callback(); |
| - return; |
| - } |
| - var id = request.args[0]; |
| - if (request.args[1].onclick) { |
| - contextMenus.handlersForId(id)[id] = request.args[1].onclick; |
| - } |
| - if (callback) |
| - callback(); |
| - }); |
| + apiFunctions.setCustomCallback('update', handlers.callbacks.update); |
| - apiFunctions.setCustomCallback('removeAll', |
| - function(name, request, callback, response) { |
| - if (lastError.hasError(chrome)) { |
| - if (callback) |
| - callback(); |
| - return; |
| - } |
| - contextMenus.generatedIdHandlers = {}; |
| - contextMenus.stringIdHandlers = {}; |
| - if (callback) |
| - callback(); |
| - }); |
| + apiFunctions.setCustomCallback('removeAll', handlers.callbacks.removeAll); |
| }); |
| exports.binding = binding.generate(); |