| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 Eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 else | 34 else |
| 35 // while the new tab page is shown on Safari 7, the 'page' property | 35 // while the new tab page is shown on Safari 7, the 'page' property |
| 36 // of the tab is undefined, and we can't send messages to that page | 36 // of the tab is undefined, and we can't send messages to that page |
| 37 this._messageProxy = { | 37 this._messageProxy = { |
| 38 handleRequest: function() {}, | 38 handleRequest: function() {}, |
| 39 handleResponse: function() {}, | 39 handleResponse: function() {}, |
| 40 sendMessage: function() {} | 40 sendMessage: function() {} |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 this.browserAction = new BrowserAction(this); | 43 this.browserAction = new BrowserAction(this); |
| 44 this.contextMenus = new ContextMenus(this); | |
| 44 }; | 45 }; |
| 45 Page.prototype = { | 46 Page.prototype = { |
| 46 get url() | 47 get url() |
| 47 { | 48 { |
| 48 return this._frames[0].url; | 49 return this._frames[0].url; |
| 49 }, | 50 }, |
| 50 activate: function() | 51 activate: function() |
| 51 { | 52 { |
| 52 this._tab.activate(); | 53 this._tab.activate(); |
| 53 }, | 54 }, |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 { | 230 { |
| 230 activePage = page; | 231 activePage = page; |
| 231 break; | 232 break; |
| 232 } | 233 } |
| 233 } | 234 } |
| 234 | 235 |
| 235 updateToolbarItemForPage(activePage, event.target.browserWindow); | 236 updateToolbarItemForPage(activePage, event.target.browserWindow); |
| 236 }, true); | 237 }, true); |
| 237 | 238 |
| 238 | 239 |
| 239 /* Web requests */ | |
| 240 | |
| 241 ext.webRequest = { | |
| 242 onBeforeRequest: new ext._EventTarget(true), | |
| 243 handlerBehaviorChanged: function() {} | |
| 244 }; | |
| 245 | |
| 246 | |
| 247 /* Context menus */ | 240 /* Context menus */ |
| 248 | 241 |
| 249 var contextMenuItems = []; | 242 var contextMenuItems = new ext.PageMap(); |
| 250 var isContextMenuHidden = true; | |
| 251 | 243 |
| 252 ext.contextMenus = { | 244 var ContextMenus = function(page) |
| 253 addMenuItem: function(title, contexts, onclick) | 245 { |
| 246 this._page = page; | |
| 247 }; | |
| 248 ContextMenus.prototype = { | |
| 249 create: function(item) | |
| 254 { | 250 { |
| 255 contextMenuItems.push({ | 251 var items = contextMenuItems.get(this._page); |
| 256 id: String(contextMenuItems.length), | 252 if (!items) |
| 257 title: title, | 253 contextMenuItems.set(this._page, items = []); |
| 258 item: null, | 254 |
| 259 contexts: contexts, | 255 items.push(item); |
| 260 onclick: onclick | |
| 261 }); | |
| 262 this.showMenuItems(); | |
| 263 }, | 256 }, |
| 264 removeMenuItems: function() | 257 removeAll: function() |
| 265 { | 258 { |
| 266 contextMenuItems = []; | 259 contextMenuItems.delete(this._page); |
| 267 this.hideMenuItems(); | |
| 268 }, | |
| 269 showMenuItems: function() | |
| 270 { | |
| 271 isContextMenuHidden = false; | |
| 272 }, | |
| 273 hideMenuItems: function() | |
| 274 { | |
| 275 isContextMenuHidden = true; | |
| 276 } | 260 } |
| 277 }; | 261 }; |
| 278 | 262 |
| 279 safari.application.addEventListener("contextmenu", function(event) | 263 safari.application.addEventListener("contextmenu", function(event) |
| 280 { | 264 { |
| 281 if (isContextMenuHidden) | 265 var pageId = event.userInfo.pageId; |
| 266 if (!pageId) | |
| 267 return; | |
| 268 | |
| 269 var page = pages[event.userInfo.pageId]; | |
| 270 var items = contextMenuItems.get(page); | |
| 271 if (!items) | |
| 282 return; | 272 return; |
| 283 | 273 |
| 284 var context = event.userInfo.tagName; | 274 var context = event.userInfo.tagName; |
| 285 if (context == "img") | 275 if (context == "img") |
| 286 context = "image"; | 276 context = "image"; |
| 287 if (!event.userInfo.srcUrl) | 277 if (!event.userInfo.srcUrl) |
| 288 context = null; | 278 context = null; |
| 289 | 279 |
| 290 for (var i = 0; i < contextMenuItems.length; i++) | 280 for (var i = 0; i < items.length; i++) |
| 291 { | 281 { |
| 292 // Supported contexts are: all, audio, image, video | 282 // Supported contexts are: all, audio, image, video |
| 293 var menuItem = contextMenuItems[i]; | 283 var menuItem = items[i]; |
| 294 if (menuItem.contexts.indexOf("all") == -1 && menuItem.contexts.indexOf(co ntext) == -1) | 284 if (menuItem.contexts.indexOf("all") == -1 && menuItem.contexts.indexOf(co ntext) == -1) |
| 295 continue; | 285 continue; |
| 296 | 286 |
| 297 event.contextMenu.appendContextMenuItem(menuItem.id, menuItem.title); | 287 event.contextMenu.appendContextMenuItem(i, menuItem.title); |
| 298 } | 288 } |
| 299 }); | 289 }); |
| 300 | 290 |
| 301 safari.application.addEventListener("command", function(event) | 291 safari.application.addEventListener("command", function(event) |
| 302 { | 292 { |
| 303 for (var i = 0; i < contextMenuItems.length; i++) | 293 var page = pages[event.userInfo.pageId]; |
| 304 { | 294 var items = contextMenuItems.get(page); |
| 305 if (contextMenuItems[i].id == event.command) | 295 |
| 306 { | 296 items[event.command].onclick(event.userInfo.srcUrl, page); |
|
Wladimir Palant
2014/04/25 11:35:50
Can there be unknown commands, e.g. from the brows
Sebastian Noack
2014/04/25 11:48:03
As far as I know the "command" event is only dispa
| |
| 307 contextMenuItems[i].onclick(event.userInfo.srcUrl, pages[event.userInfo. pageId]); | |
| 308 break; | |
| 309 } | |
| 310 } | |
| 311 }); | 297 }); |
| 312 | 298 |
| 313 | 299 |
| 300 /* Web requests */ | |
| 301 | |
| 302 ext.webRequest = { | |
| 303 onBeforeRequest: new ext._EventTarget(true), | |
| 304 handlerBehaviorChanged: function() {} | |
| 305 }; | |
| 306 | |
| 307 | |
| 314 /* Background page */ | 308 /* Background page */ |
| 315 | 309 |
| 316 ext.backgroundPage = { | 310 ext.backgroundPage = { |
| 317 getWindow: function() | 311 getWindow: function() |
| 318 { | 312 { |
| 319 return window; | 313 return window; |
| 320 } | 314 } |
| 321 }; | 315 }; |
| 322 | 316 |
| 323 | 317 |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 657 replacePage(page); | 651 replacePage(page); |
| 658 break; | 652 break; |
| 659 } | 653 } |
| 660 }); | 654 }); |
| 661 | 655 |
| 662 | 656 |
| 663 /* Storage */ | 657 /* Storage */ |
| 664 | 658 |
| 665 ext.storage = safari.extension.settings; | 659 ext.storage = safari.extension.settings; |
| 666 })(); | 660 })(); |
| OLD | NEW |