Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: chrome/background.js

Issue 5589897452716032: Implemented ext.contextMenus for Safari (Closed)
Patch Set: Created Jan. 18, 2014, 10:29 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 contextMenuItems = [];
374 var isContextMenuHidden = true;
373 ext.contextMenus = { 375 ext.contextMenus = {
374 create: function(title, contexts, onclick) 376 addMenuItem: function(title, contexts, onclick)
375 { 377 {
376 chrome.contextMenus.create({ 378 contextMenuItems.push({
377 title: title, 379 title: title,
378 contexts: contexts, 380 contexts: contexts,
379 onclick: function(info, tab) 381 onclick: function(info, tab)
380 { 382 {
381 onclick(info.srcUrl, new Tab(tab)); 383 onclick(info.srcUrl, new Tab(tab));
382 } 384 }
383 }); 385 });
386 this.showMenuItems();
384 }, 387 },
385 removeAll: function(callback) 388 removeMenuItems: function()
386 { 389 {
387 chrome.contextMenus.removeAll(callback); 390 contextMenuItems = [];
391 this.hideMenuItems();
392 },
393 showMenuItems: function()
394 {
395 if (!isContextMenuHidden)
396 return;
397
398 chrome.contextMenus.removeAll(function()
399 {
400 for (var i = 0; i < contextMenuItems.length; i++)
401 {
402 var item = contextMenuItems[i];
403 chrome.contextMenus.create({
404 title: item.title,
405 contexts: item.contexts,
406 onclick: item.onclick
407 });
408 }
409 });
410 isContextMenuHidden = false;
411 },
412 hideMenuItems: function()
413 {
414 if (isContextMenuHidden)
415 return;
416
417 chrome.contextMenus.removeAll();
418 isContextMenuHidden = true;
388 } 419 }
389 }; 420 };
390 })(); 421 })();
OLDNEW
« no previous file with comments | « block.js ('k') | include.postload.js » ('j') | safari/background.js » ('J')

Powered by Google App Engine
This is Rietveld