Index: ext/background.js |
=================================================================== |
--- a/ext/background.js |
+++ b/ext/background.js |
@@ -70,17 +70,19 @@ |
/* Pages */ |
let Page = ext.Page = function(tab) |
{ |
this.id = tab.id; |
this._url = tab.url && new URL(tab.url); |
this.browserAction = new BrowserAction(tab.id); |
- this.contextMenus = new ContextMenus(this); |
+ |
+ if (chrome.contextMenus) |
+ this.contextMenus = new ContextMenus(this); |
}; |
Page.prototype = { |
get url() |
{ |
// usually our Page objects are created from Chrome's Tab objects, which |
// provide the url. So we can return the url given in the constructor. |
if (this._url) |
return this._url; |
@@ -413,91 +415,96 @@ |
this._addChange("badgeColor", badge.color); |
} |
} |
}; |
/* Context menus */ |
- let contextMenuItems = new ext.PageMap(); |
- let contextMenuUpdating = false; |
+ let ContextMenus = null; |
- let updateContextMenu = () => |
+ if (chrome.contextMenus) |
Manish Jethani
2017/08/10 07:40:05
Rietveld seems to have messed up the diff. I've on
|
{ |
- if (contextMenuUpdating) |
- return; |
+ let contextMenuItems = new ext.PageMap(); |
+ let contextMenuUpdating = false; |
- contextMenuUpdating = true; |
- |
- chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs => |
+ let updateContextMenu = () => |
{ |
- chrome.contextMenus.removeAll(() => |
- { |
- contextMenuUpdating = false; |
+ if (contextMenuUpdating) |
+ return; |
+ |
+ contextMenuUpdating = true; |
- if (tabs.length == 0) |
- return; |
+ chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs => |
+ { |
+ chrome.contextMenus.removeAll(() => |
+ { |
+ contextMenuUpdating = false; |
- let items = contextMenuItems.get({id: tabs[0].id}); |
+ if (tabs.length == 0) |
+ return; |
- if (!items) |
- return; |
+ let items = contextMenuItems.get({id: tabs[0].id}); |
- items.forEach(item => |
- { |
- chrome.contextMenus.create({ |
- title: item.title, |
- contexts: item.contexts, |
- onclick(info, tab) |
- { |
- item.onclick(new Page(tab)); |
- } |
+ if (!items) |
+ return; |
+ |
+ items.forEach(item => |
+ { |
+ chrome.contextMenus.create({ |
+ title: item.title, |
+ contexts: item.contexts, |
+ onclick(info, tab) |
+ { |
+ item.onclick(new Page(tab)); |
+ } |
+ }); |
}); |
}); |
}); |
- }); |
- }; |
+ }; |
- let ContextMenus = function(page) |
- { |
- this._page = page; |
- }; |
- ContextMenus.prototype = { |
- create(item) |
+ ContextMenus = function(page) |
{ |
- let items = contextMenuItems.get(this._page); |
- if (!items) |
- contextMenuItems.set(this._page, items = []); |
+ this._page = page; |
+ }; |
+ ContextMenus.prototype = { |
+ create(item) |
+ { |
+ let items = contextMenuItems.get(this._page); |
+ if (!items) |
+ contextMenuItems.set(this._page, items = []); |
- items.push(item); |
- updateContextMenu(); |
- }, |
- remove(item) |
- { |
- let items = contextMenuItems.get(this._page); |
- if (items) |
+ items.push(item); |
+ updateContextMenu(); |
+ }, |
+ remove(item) |
{ |
- let index = items.indexOf(item); |
- if (index != -1) |
+ let items = contextMenuItems.get(this._page); |
+ if (items) |
{ |
- items.splice(index, 1); |
- updateContextMenu(); |
+ let index = items.indexOf(item); |
+ if (index != -1) |
+ { |
+ items.splice(index, 1); |
+ updateContextMenu(); |
+ } |
} |
} |
- } |
- }; |
+ }; |
- chrome.tabs.onActivated.addListener(updateContextMenu); |
+ chrome.tabs.onActivated.addListener(updateContextMenu); |
- chrome.windows.onFocusChanged.addListener(windowId => |
- { |
- if (windowId != chrome.windows.WINDOW_ID_NONE) |
- updateContextMenu(); |
- }); |
+ chrome.windows.onFocusChanged.addListener(windowId => |
+ { |
+ if (windowId != chrome.windows.WINDOW_ID_NONE) |
+ updateContextMenu(); |
+ }); |
+ } |
/* Web requests */ |
let framesOfTabs = new Map(); |
ext.getFrame = (tabId, frameId) => |
{ |