Use the <code>chrome.contextMenus</code> API to add items to Google Chrome's context
menu. You can choose what types of objects your context menu additions apply to,
such as images, hyperlinks, and pages.
@constructor
@param {Object} chrome
541256
function ContextMenus(chrome) {
  this.chrome = chrome;

  /**
   * The maximum number of top level extension items that can be added to an extension
   * action context menu. Any items beyond this limit will be ignored.
   * @property {undefined}
   */
  this.ACTION_MENU_TOP_LEVEL_LIMIT = null;

  /**
   * Creates a new context menu item. Note that if an error occurs during creation, you
   * may not find out until the creation callback fires (the details will be in chro
   * me.runtime.lastError).
   *
   * @param {Object} createProperties
   * @param {function} callback Called when the item has been created in the browser. If there were any probl...
   * @returns {undefined} The ID of the newly created item.
   */
  this.create = sinon.stub();

  /**
   * Updates a previously created context menu item.
   *
   * @param {undefined} id The ID of the item to update.
   * @param {Object} updateProperties The properties to update. Accepts the same values as the create function.
   * @param {function} callback Called when the context menu has been updated.
   */
  this.update = sinon.stub();

  /**
   * Removes a context menu item.
   *
   * @param {undefined} menuItemId The ID of the context menu item to remove.
   * @param {function} callback Called when the context menu has been removed.
   */
  this.remove = sinon.stub();

  /**
   * Removes all context menu items added by this extension.
   *
   * @param {function} callback Called when removal is complete.
   */
  this.removeAll = sinon.stub();

  /**
   * onClicked Event
   */
  this.onClicked = new Event();
}
206933
def _popup_menu(self, icon, button, time, extended=True):
        """"""
        m = self.create_context_menu(extended)
        m.show_all()
        m.popup(parent_menu_shell=None,
                parent_menu_item=None,
                func=icon.position_menu,
                data=icon,
                button=button,
                activate_time=time)
        # need to store reference or menu will be destroyed before showing:
        self._m = m
385575
function _createMenu () {
  // Set up the application menu1
  const template = [
    {
      label: 'File',
      submenu: [
        {
          label: 'New',
          submenu: [
            {
              label: 'Article',
              accelerator: 'CommandOrControl+N',
              click () {
                _openNew('article')
              }
            },
            {
              label: 'Figure Package',
              click () {
                _openNew('figure-package')
              }
            }
          ]
        },
        {
          label: 'Open',
          accelerator: 'CommandOrControl+O',
          click () {
            _promptOpen()
          }
        },
        {
          label: 'Save',
          accelerator: 'CommandOrControl+S',
          click () {
            _save()
          }
        },
        {
          label: 'Save As...',
          accelerator: 'CommandOrControl+Shift+S',
          click () {
            _saveAs()
          }
        }
      ]
    },
    {
      label: 'Edit',
      submenu: [
        { role: 'undo' },
        { role: 'redo' },
        { type: 'separator' },
        { role: 'cut' },
        { role: 'copy' },
        { role: 'paste' },
        { role: 'pasteandmatchstyle' },
        { role: 'delete' },
        { role: 'selectall' }
      ]
    },
    {
      label: 'View',
      submenu: [
        { role: 'toggledevtools' },
        { type: 'separator' },
        { role: 'resetzoom' },
        { role: 'zoomin' },
        { role: 'zoomout' },
        { type: 'separator' },
        { role: 'togglefullscreen' }
      ]
    },
    {
      role: 'window',
      submenu: [
        { role: 'minimize' },
        { role: 'close' }
      ]
    },
    {
      role: 'help',
      submenu: [
        {
          label: 'Learn More',
          click () {
            // TODO: why not use the globally required electron?
            shell.openExternal('http://substance.io/texture')
          }
        }
      ]
    }
  ]

  if (process.platform === 'darwin') {
    template.unshift({
      label: app.getName(),
      submenu: [
        { role: 'about' },
        { type: 'separator' },
        { role: 'services', submenu: [] },
        { type: 'separator' },
        { role: 'hide' },
        { role: 'hideothers' },
        { role: 'unhide' },
        { type: 'separator' },
        { role: 'quit' }
      ]
    })
  }

  const menu = Menu.buildFromTemplate(template)
  Menu.setApplicationMenu(menu)
}
1222819
function (target, position) {
                // look for existing Contextual menu
                if (this._popup) {
                    aria.tools.contextual.ContextualMenu.close();
                }
                // first check the position else get positon from dom
                // element
                var domPosition = {};
                if (!position) {
                    if (!target.$TemplateCtxt) {
                        domPosition = domUtils.getGeometry(target);
                    } else {
                        domPosition = {
                            x : 0,
                            y : 0
                        };
                    }
                } else {
                    domPosition = position;
                }

                // look for template context
                if (target.$TemplateCtxt) {
                    this._notifyFound(target, domPosition.x, domPosition.y);
                    return;
                }
                // Internal call to initiate the notify
                this.__callContextualMenu(target, domPosition.x, domPosition.y);

                return false;

            }
442371
function Menu() {
  ui.Emitter.call(this);
  this.items = {};
  this.el = $(html).hide().appendTo('body');
  this.el.hover(this.deselect.bind(this));
  $('html').click(this.hide.bind(this));
  this.on('show', this.bindKeyboardEvents.bind(this));
  this.on('hide', this.unbindKeyboardEvents.bind(this));
}
1014578
function inner_onclick(e) {
            var value = this.value;
            var close_parent = true;

            if (that.current_submenu) {
                that.current_submenu.close(e);
            }

            //global callback
            if (options.callback) {
                var r = options.callback.call(
                    this,
                    value,
                    options,
                    e,
                    that,
                    options.node
                );
                if (r === true) {
                    close_parent = false;
                }
            }

            //special cases
            if (value) {
                if (
                    value.callback &&
                    !options.ignore_item_callbacks &&
                    value.disabled !== true
                ) {
                    //item callback
                    var r = value.callback.call(
                        this,
                        value,
                        options,
                        e,
                        that,
                        options.extra
                    );
                    if (r === true) {
                        close_parent = false;
                    }
                }
                if (value.submenu) {
                    if (!value.submenu.options) {
                        throw "ContextMenu submenu needs options";
                    }
                    var submenu = new that.constructor(value.submenu.options, {
                        callback: value.submenu.callback,
                        event: e,
                        parentMenu: that,
                        ignore_item_callbacks:
                            value.submenu.ignore_item_callbacks,
                        title: value.submenu.title,
                        extra: value.submenu.extra,
                        autoopen: options.autoopen
                    });
                    close_parent = false;
                }
            }

            if (close_parent && !that.lock) {
                that.close();
            }
        }
200527
function (evt) {
        if (!evt || !evt.changedProperties || ArrayUtils.contains(evt.changedProperties, "contextualMenu")) {
            Aria.load({
                classes : ["aria.tools.contextual.ContextualMenu"]
            });
        }
    }
504207
function()
	{
		CKEDITOR.plugins.contextMenu = CKEDITOR.tools.createClass(
		{
			base : CKEDITOR.menu,

			$ : function( editor )
			{
				this.base.call( this, editor,
				{
					panel:
					{
						className : editor.skinClass + ' cke_contextmenu',
						attributes :
						{
							'aria-label' : editor.lang.contextmenu.options
						}
					}
				});
			},

			proto :
			{
				addTarget : function( element, nativeContextMenuOnCtrl )
				{
					// Opera doesn't support 'contextmenu' event, we have duo approaches employed here:
					// 1. Inherit the 'button override' hack we introduced in v2 (#4530), while this require the Opera browser
					//  option 'Allow script to detect context menu/right click events' to be always turned on.
					// 2. Considering the fact that ctrl/meta key is not been occupied
					//  for multiple range selecting (like Gecko), we use this key
					//  combination as a fallback for triggering context-menu. (#4530)
					if ( CKEDITOR.env.opera && !( 'oncontextmenu' in document.body ))
					{
						var contextMenuOverrideButton;
						element.on( 'mousedown', function( evt )
						{
							evt = evt.data;
							if ( evt.$.button != 2 )
							{
								if ( evt.getKeystroke() == CKEDITOR.CTRL + 1 )
									element.fire( 'contextmenu', evt );
								return;
							}

							if ( nativeContextMenuOnCtrl
								 && ( CKEDITOR.env.mac ? evt.$.metaKey : evt.$.ctrlKey ) )
								return;

							var target = evt.getTarget();

							if ( !contextMenuOverrideButton )
							{
								var ownerDoc =  target.getDocument();
								contextMenuOverrideButton = ownerDoc.createElement( 'input' ) ;
								contextMenuOverrideButton.$.type = 'button' ;
								ownerDoc.getBody().append( contextMenuOverrideButton ) ;
							}

							contextMenuOverrideButton.setAttribute( 'style', 'position:absolute;top:' + ( evt.$.clientY - 2 ) +
								'px;left:' + ( evt.$.clientX - 2 ) +
								'px;width:5px;height:5px;opacity:0.01' );

						} );

						element.on( 'mouseup', function ( evt )
						{
							if ( contextMenuOverrideButton )
							{
								contextMenuOverrideButton.remove();
								contextMenuOverrideButton = undefined;
								// Simulate 'contextmenu' event.
								element.fire( 'contextmenu', evt.data );
							}
						} );
					}

					element.on( 'contextmenu', function( event )
						{
							var domEvent = event.data;

							if ( nativeContextMenuOnCtrl &&
								 // Safari on Windows always show 'ctrlKey' as true in 'contextmenu' event,
								// which make this property unreliable. (#4826)
								 ( CKEDITOR.env.webkit ? holdCtrlKey : ( CKEDITOR.env.mac ? domEvent.$.metaKey : domEvent.$.ctrlKey ) ) )
								return;


							// Cancel the browser context menu.
							domEvent.preventDefault();

							var offsetParent = domEvent.getTarget().getDocument().getDocumentElement(),
								offsetX = domEvent.$.clientX,
								offsetY = domEvent.$.clientY;

							CKEDITOR.tools.setTimeout( function()
								{
									this.open( offsetParent, null, offsetX, offsetY );

								// IE needs a short while to allow selection change before opening menu. (#7908)
								}, CKEDITOR.env.ie? 200 : 0, this );
						},
						this );

					if ( CKEDITOR.env.opera )
					{
						// 'contextmenu' event triggered by Windows menu key is unpreventable,
						// cancel the key event itself. (#6534)
						element.on( 'keypress' , function ( evt )
						{
							var domEvent = evt.data;

							if ( domEvent.$.keyCode === 0 )
								domEvent.preventDefault();
						});
					}

					if ( CKEDITOR.env.webkit )
					{
						var holdCtrlKey,
							onKeyDown = function( event )
							{
								holdCtrlKey = CKEDITOR.env.mac ? event.data.$.metaKey : event.data.$.ctrlKey ;
							},
							resetOnKeyUp = function()
							{
								holdCtrlKey = 0;
							};

						element.on( 'keydown', onKeyDown );
						element.on( 'keyup', resetOnKeyUp );
						element.on( 'contextmenu', resetOnKeyUp );
					}
				},

				open : function( offsetParent, corner, offsetX, offsetY )
				{
					this.editor.focus();
					offsetParent = offsetParent || CKEDITOR.document.getDocumentElement();
					this.show( offsetParent, corner, offsetX, offsetY );
				}
			}
		});
	}
438620
function(e) {
            var $this = $(this),
                $related = $(e.relatedTarget),
                $document = $(document);
            
            // abort if we're coming from a menu
            if ($related.is('.context-menu-list') || $related.closest('.context-menu-list').length) {
                return;
            }
            
            // abort if a menu is shown
            if ($currentTrigger && $currentTrigger.length) {
                return;
            }
            
            hoveract.pageX = e.pageX;
            hoveract.pageY = e.pageY;
            hoveract.data = e.data;
            $document.on('mousemove.contextMenuShow', handle.mousemove);
            hoveract.timer = setTimeout(function() {
                hoveract.timer = null;
                $document.off('mousemove.contextMenuShow');
                $currentTrigger = $this;
                $this.trigger($.Event("contextmenu", { data: hoveract.data, pageX: hoveract.pageX, pageY: hoveract.pageY }));
            }, e.data.delay );
        }
897440
function(context) {
		this._keymap = Object.create(null);
		["keydown", "keypress", "keyup"].forEach(function(type) {
			context.document.addEventListener(type, this, false);
		}, this);
	}
772023
def set_context_menu(self, context_menu):
        
        self.context_menu = context_menu
        self.context_menu.tree_view = self
        self.context_menu.init_actions()
        for action in self.context_menu.actions():
            self.addAction(action)
54960
function ( e ) {
            // Default context is `this` element
            var context = (selector ? matchElement( e.target, selector, true ) : this);

            // Handle `mouseenter` and `mouseleave`
            if ( event === "mouseenter" || event === "mouseleave" ) {
                var relatedElement = (event === "mouseenter" ? e.fromElement : e.toElement);

                if ( context && ( relatedElement !== context && !context.contains( relatedElement ) ) ) {
                    callback.call( context, e );
                }

            // Fire callback if context element
            } else if ( context ) {
                callback.call( context, e );
            }
        }
75748
def mk_notebook_context_menu(callback_object):
    
    callback_object.context_menu = Gtk.Menu()
    menu = callback_object.context_menu
    mi = Gtk.MenuItem(_("New Tab"))
    mi.connect("activate", callback_object.on_new_tab)
    menu.add(mi)
    menu.add(Gtk.SeparatorMenuItem())
    mi = Gtk.MenuItem(_("Save Tabs"))
    mi.connect("activate", callback_object.on_save_tabs)
    menu.add(mi)
    mi = Gtk.MenuItem(_("Restore Tabs"))
    mi.connect("activate", callback_object.on_restore_tabs_with_dialog)
    menu.add(mi)
    menu.add(Gtk.SeparatorMenuItem())
    mi = Gtk.ImageMenuItem("gtk-preferences")
    mi.set_use_stock(True)
    mi.connect("activate", callback_object.on_show_preferences)
    menu.add(mi)
    mi = Gtk.ImageMenuItem("gtk-about")
    mi.set_use_stock(True)
    mi.connect("activate", callback_object.on_show_about)
    menu.add(mi)
    menu.add(Gtk.SeparatorMenuItem())
    mi = Gtk.MenuItem(_("Quit"))
    mi.connect("activate", callback_object.on_quit)
    menu.add(mi)
    menu.show_all()
    return menu
351961
function attachBrowserEvents(self) {
  if (isChromeApp()) {
    chrome.storage.onChanged.addListener(function (e) {
      // make sure it's event addressed to us
      if (e.db_name != null) {
        //object only has oldValue, newValue members
        self.emit(e.dbName.newValue);
      }
    });
  } else if (hasLocalStorage()) {
    if (typeof addEventListener !== 'undefined') {
      addEventListener("storage", function (e) {
        self.emit(e.key);
      });
    } else { // old IE
      window.attachEvent("storage", function (e) {
        self.emit(e.key);
      });
    }
  }
}
120082
function manageWindow(tabliFolderId, tabWindow, title, cb) {
  // and write out a Bookmarks folder for this newly managed window:
  if (!tabliFolderId) {
    alert('Could not save bookmarks -- no tab manager folder');
  }

  var windowFolder = { parentId: tabliFolderId,
    title: title
  };
  chrome.bookmarks.create(windowFolder, function (windowFolderNode) {
    // console.log( "succesfully created bookmarks folder ", windowFolderNode );
    // console.log( "for window: ", tabWindow );

    // We'll groupBy and then take the first item of each element of the sequence:
    var uniqTabItems = tabWindow.tabItems.groupBy(function (ti) {
      return ti.url;
    }).toIndexedSeq().map(function (vs) {
      return vs.get(0);
    }).toArray();

    var bookmarkActions = uniqTabItems.map(function (tabItem) {
      function makeBookmarkAction(v, bmcb) {
        var tabMark = { parentId: windowFolderNode.id, title: tabItem.title, url: tabItem.url };
        chrome.bookmarks.create(tabMark, bmcb);
      }

      return makeBookmarkAction;
    });

    utils.seqActions(bookmarkActions, null, function () {
      // Now do an explicit get of subtree to get node populated with children
      chrome.bookmarks.getSubTree(windowFolderNode.id, function (folderNodes) {
        var fullFolderNode = folderNodes[0];

        // We'll retrieve the latest chrome Window state and attach that:
        chrome.windows.get(tabWindow.openWindowId, { populate: true }, function (chromeWindow) {
          // Hack:  Chrome may think focus has moved to the popup itself, so let's just
          // set chromeWindow.focused to last focused state (tabWindow.focused)
          var focusedChromeWindow = Object.assign({}, chromeWindow, { focused: tabWindow.focused });
          cb(function (state) {
            return state.attachBookmarkFolder(fullFolderNode, focusedChromeWindow);
          });
        });
      });
    });
  });
}
807901
function initBrowser() {
  if (window.chrome) {
    Object.assign(module.exports, chromeConstants);
  } else {
    Object.assign(module.exports, braveConstants);
  }
}
962737
function() {
  /**
   * Whether to show the page-action 'inject' icon.
   * @type {boolean}
   */
  this.showPageAction = true;

  /**
   * Whether to show the context menu items.
   * @type {boolean}
   */
  this.showContextMenu = false;

  /**
   * Whether to show the devtools panel.
   * @type {boolean}
   */
  this.showDevPanel = false;

  /**
   * A list of all added extensions, mapped by URL.
   * @type {!Object.<!Object>}
   * @private
   */
  this.addons_ = {};

  /**
   * A map of instrumented tab IDs to their instrumentation options.
   * If a tab has an entry in this map it is considered instrumented and
   * that superceeds other whitelisting options.
   * This is not saved (yet), as it's usually a one-off thing.
   * @type {!Object.<number, Object>}
   */
  this.instrumentedTabs_ = {};

  /**
   * A list of page match patterns that will have tracing on.
   * @type {!Array.<string>}
   * @private
   */
  this.pageWhitelist_ = [];

  /**
   * A list of page match patterns that will have tracing off.
   * @type {!Array.<string>}
   * @private
   */
  this.pageBlacklist_ = [];

  /**
   * A map of URLs to page options objects.
   * @type {!Object.<!Object>}
   * @private
   */
  this.pageOptions_ = {};

  /**
   * Default endpoint to use for pages.
   * @type {{mode: string, endpoint: string}}
   * @private
   */
  this.defaultEndpoint_ = {
    mode: 'page',
    endpoint: chrome.extension.getURL('app/maindisplay.html')
  };
}