Override web inspector's context menu.

This commit is contained in:
Cheng Zhao 2014-04-03 20:54:42 +08:00
parent ac794c8085
commit b1f0c2d174
3 changed files with 38 additions and 2 deletions

View file

@ -32,6 +32,7 @@
'atom/common/api/lib/shell.coffee',
'atom/common/lib/init.coffee',
'atom/renderer/lib/init.coffee',
'atom/renderer/lib/inspector.coffee',
'atom/renderer/lib/override.coffee',
'atom/renderer/api/lib/ipc.coffee',
'atom/renderer/api/lib/remote.coffee',

View file

@ -1,4 +1,5 @@
path = require 'path'
url = require 'url'
Module = require 'module'
# Expose information of current process.
@ -42,5 +43,9 @@ else
global.__filename = __filename
global.__dirname = __dirname
# Override default web functions.
require path.join(__dirname, 'override')
if location.protocol is 'chrome-devtools:'
# Override some inspector APIs.
require path.join(__dirname, 'inspector')
else
# Override default web functions.
require path.join(__dirname, 'override')

View file

@ -0,0 +1,30 @@
# Use menu API to show context menu.
window.onload = ->
WebInspector.ContextMenu.prototype.show = ->
menuObject = @_buildDescriptor()
if menuObject.length
WebInspector._contextMenu = this
createMenu(menuObject, @_event)
@_event.consume()
convertToMenuTemplate = (items) ->
template = []
for item in items
if item.type is 'subMenu'
template.push
type: 'submenu'
label: item.label
submenu: convertToMenuTemplate item.subItems
else
template.push
type: 'normal'
label: item.label
template
createMenu = (items, event) ->
remote = require 'remote'
Menu = remote.require 'menu'
menu = Menu.buildFromTemplate convertToMenuTemplate(items.subItems)
menu.popup()
event.consume true