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

Unified Diff: extensions/renderer/resources/context_menus_custom_bindings.js

Issue 948243005: Merge custom bindings for context menus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: $Array.unshift -> $Array.concat Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
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..752f78b161b4e39ca3f25d3ee060129ba4272dec 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 createContextMenusHandlers = require('contextMenusHandlers').create;
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 impl = createContextMenusHandlers(/* isWebview = */ false);
- var id = contextMenus.getIdFromCreateProperties(request.args[0]);
+ apiFunctions.setHandleRequest('create', impl.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', impl.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', impl.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', impl.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', impl.callbacks.removeAll);
});
exports.binding = binding.generate();

Powered by Google App Engine
This is Rietveld 408576698