LEFT | RIGHT |
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-2013 Eyeo GmbH | 3 * Copyright (C) 2006-2013 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 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 onCompleted: new CompletedTabEventTarget(), | 363 onCompleted: new CompletedTabEventTarget(), |
364 onActivated: new ActivatedTabEventTarget(), | 364 onActivated: new ActivatedTabEventTarget(), |
365 onRemoved: new RemovedTabEventTarget() | 365 onRemoved: new RemovedTabEventTarget() |
366 }; | 366 }; |
367 | 367 |
368 ext.webRequest = { | 368 ext.webRequest = { |
369 onBeforeRequest: new BeforeRequestEventTarget(), | 369 onBeforeRequest: new BeforeRequestEventTarget(), |
370 handlerBehaviorChanged: chrome.webRequest.handlerBehaviorChanged | 370 handlerBehaviorChanged: chrome.webRequest.handlerBehaviorChanged |
371 }; | 371 }; |
372 | 372 |
373 var contextMenu = []; | 373 var contextMenuItems = []; |
| 374 var isContextMenuHidden = true; |
374 ext.contextMenus = { | 375 ext.contextMenus = { |
375 addMenuItem: function(title, contexts, onclick) | 376 addMenuItem: function(title, contexts, onclick) |
376 { | 377 { |
377 contextMenu.push({ | 378 contextMenuItems.push({ |
378 title: title, | 379 title: title, |
379 contexts: contexts, | 380 contexts: contexts, |
380 onclick: function(info, tab) | 381 onclick: function(info, tab) |
381 { | 382 { |
382 onclick(info.srcUrl, new Tab(tab)); | 383 onclick(info.srcUrl, new Tab(tab)); |
383 } | 384 } |
384 }); | 385 }); |
| 386 this.showMenuItems(); |
385 }, | 387 }, |
386 removeMenuItems: function() | 388 removeMenuItems: function() |
387 { | 389 { |
388 contextMenu = []; | 390 contextMenuItems = []; |
389 }, | 391 this.hideMenuItems(); |
390 showMenu: function() | 392 }, |
391 { | 393 showMenuItems: function() |
| 394 { |
| 395 if (!isContextMenuHidden) |
| 396 return; |
| 397 |
392 chrome.contextMenus.removeAll(function() | 398 chrome.contextMenus.removeAll(function() |
393 { | 399 { |
394 for (var i = 0; i < contextMenu.length; i++) | 400 for (var i = 0; i < contextMenuItems.length; i++) |
395 { | 401 { |
396 var item = contextMenu[i]; | 402 var item = contextMenuItems[i]; |
397 chrome.contextMenus.create({ | 403 chrome.contextMenus.create({ |
398 title: item.title, | 404 title: item.title, |
399 contexts: item.contexts, | 405 contexts: item.contexts, |
400 onclick: item.onclick | 406 onclick: item.onclick |
401 }); | 407 }); |
402 } | 408 } |
403 }); | 409 }); |
404 }, | 410 isContextMenuHidden = false; |
405 hideMenu: function() | 411 }, |
406 { | 412 hideMenuItems: function() |
| 413 { |
| 414 if (isContextMenuHidden) |
| 415 return; |
| 416 |
407 chrome.contextMenus.removeAll(); | 417 chrome.contextMenus.removeAll(); |
408 } | 418 isContextMenuHidden = true; |
409 }; | 419 } |
410 | 420 }; |
411 })(); | 421 })(); |
LEFT | RIGHT |