Left: | ||
Right: |
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 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
407 for (var frameId in frames) | 407 for (var frameId in frames) |
408 { | 408 { |
409 if (frames[frameId].url == this._url) | 409 if (frames[frameId].url == this._url) |
410 { | 410 { |
411 frame = frames[frameId]; | 411 frame = frames[frameId]; |
412 break; | 412 break; |
413 } | 413 } |
414 } | 414 } |
415 } | 415 } |
416 | 416 |
417 if (frame) | 417 if (!frame || frame.parent == -1) |
Felix Dahlke
2014/01/18 13:39:19
This would return undefined if frame is falsy. I t
Sebastian Noack
2014/01/19 10:19:40
Done.
| |
418 if (frame.parent != -1) | 418 return null; |
419 return new Frame({id: frame.parent, tab: this._tab}); | 419 |
420 else | 420 return new Frame({id: frame.parent, tab: this._tab}); |
421 return null; | |
422 } | 421 } |
423 } | 422 } |
424 }; | 423 }; |
425 | 424 |
426 | 425 |
427 /* Web request blocking */ | 426 /* Web request blocking */ |
428 | 427 |
429 chrome.webRequest.onBeforeRequest.addListener(function(details) | 428 chrome.webRequest.onBeforeRequest.addListener(function(details) |
430 { | 429 { |
431 // the high-level code isn't interested in requests that aren't related | 430 // the high-level code isn't interested in requests that aren't related |
432 // to a tab and since those can only be handled in Chrome, we ignore | 431 // to a tab and since those can only be handled in Chrome, we ignore |
433 // them here instead of in the browser independant high-level code. | 432 // them here instead of in the browser independent high-level code. |
Felix Dahlke
2014/01/18 13:39:19
s/independant/independent/
Sebastian Noack
2014/01/19 10:19:40
Done.
| |
434 if (details.tabId == -1) | 433 if (details.tabId == -1) |
435 return; | 434 return; |
436 | 435 |
437 var tab = new Tab({id: details.tabId}); | 436 var tab = new Tab({id: details.tabId}); |
438 var frames = framesOfTabs.get(tab); | 437 var frames = framesOfTabs.get(tab); |
439 | 438 |
440 if (!frames) | 439 if (!frames) |
441 { | 440 { |
442 frames = []; | 441 frames = []; |
443 framesOfTabs.set(tab, frames); | 442 framesOfTabs.set(tab, frames); |
(...skipping 15 matching lines...) Expand all Loading... | |
459 // since those can only be handled in Chrome, we ignore them here | 458 // since those can only be handled in Chrome, we ignore them here |
460 // instead of in the browser independent high-level code. | 459 // instead of in the browser independent high-level code. |
461 if (details.type == "main_frame") | 460 if (details.type == "main_frame") |
462 return; | 461 return; |
463 } | 462 } |
464 else | 463 else |
465 frameId = details.frameId; | 464 frameId = details.frameId; |
466 | 465 |
467 // the high-level code relies on the frame. However in case the frame can't | 466 // the high-level code relies on the frame. However in case the frame can't |
468 // be controlled by the extension or the extension was (re)loaded after the | 467 // be controlled by the extension or the extension was (re)loaded after the |
469 // frame was loaded, the frame is unkown and we have to ignore the request. | 468 // frame was loaded, the frame is unknown and we have to ignore the request. |
Felix Dahlke
2014/01/18 13:39:19
s/unkown/unknown/
Sebastian Noack
2014/01/19 10:19:40
Done.
| |
470 if (!(frameId in frames)) | 469 if (!(frameId in frames)) |
471 return; | 470 return; |
472 | 471 |
473 var frame = new Frame({id: frameId, tab: tab}); | 472 var frame = new Frame({id: frameId, tab: tab}); |
474 | 473 |
475 for (var i = 0; i < ext.webRequest.onBeforeRequest._listeners.length; i++) | 474 for (var i = 0; i < ext.webRequest.onBeforeRequest._listeners.length; i++) |
476 { | 475 { |
477 if (ext.webRequest.onBeforeRequest._listeners[i](details.url, details.type , tab, frame) === false) | 476 if (ext.webRequest.onBeforeRequest._listeners[i](details.url, details.type , tab, frame) === false) |
Felix Dahlke
2014/01/18 13:39:19
Why not the following?
if (!ext.webRequest.onBefo
Sebastian Noack
2014/01/19 10:19:40
In order to block the request, the handler should
| |
478 return {cancel: true}; | 477 return {cancel: true}; |
479 } | 478 } |
480 }, {urls: ["<all_urls>"]}, ["blocking"]); | 479 }, {urls: ["<all_urls>"]}, ["blocking"]); |
481 | 480 |
482 | 481 |
483 /* API */ | 482 /* API */ |
484 | 483 |
485 ext.windows = { | 484 ext.windows = { |
486 getAll: function(callback) | 485 getAll: function(callback) |
487 { | 486 { |
(...skipping 20 matching lines...) Expand all Loading... | |
508 onCompleted: new CompletedTabEventTarget(), | 507 onCompleted: new CompletedTabEventTarget(), |
509 onActivated: new ActivatedTabEventTarget(), | 508 onActivated: new ActivatedTabEventTarget(), |
510 onRemoved: new RemovedTabEventTarget() | 509 onRemoved: new RemovedTabEventTarget() |
511 }; | 510 }; |
512 | 511 |
513 ext.webRequest = { | 512 ext.webRequest = { |
514 onBeforeRequest: new SimpleEventTarget(), | 513 onBeforeRequest: new SimpleEventTarget(), |
515 handlerBehaviorChanged: chrome.webRequest.handlerBehaviorChanged | 514 handlerBehaviorChanged: chrome.webRequest.handlerBehaviorChanged |
516 }; | 515 }; |
517 | 516 |
517 var contextMenuItems = []; | |
518 var isContextMenuHidden = true; | |
518 ext.contextMenus = { | 519 ext.contextMenus = { |
519 create: function(title, contexts, onclick) | 520 addMenuItem: function(title, contexts, onclick) |
520 { | 521 { |
521 chrome.contextMenus.create({ | 522 contextMenuItems.push({ |
522 title: title, | 523 title: title, |
523 contexts: contexts, | 524 contexts: contexts, |
524 onclick: function(info, tab) | 525 onclick: function(info, tab) |
525 { | 526 { |
526 onclick(info.srcUrl, new Tab(tab)); | 527 onclick(info.srcUrl, new Tab(tab)); |
527 } | 528 } |
528 }); | 529 }); |
529 }, | 530 this.showMenuItems(); |
530 removeAll: function(callback) | 531 }, |
531 { | 532 removeMenuItems: function() |
532 chrome.contextMenus.removeAll(callback); | 533 { |
534 contextMenuItems = []; | |
535 this.hideMenuItems(); | |
536 }, | |
537 showMenuItems: function() | |
538 { | |
539 if (!isContextMenuHidden) | |
540 return; | |
541 | |
542 chrome.contextMenus.removeAll(function() | |
543 { | |
544 for (var i = 0; i < contextMenuItems.length; i++) | |
545 { | |
546 var item = contextMenuItems[i]; | |
547 chrome.contextMenus.create({ | |
548 title: item.title, | |
549 contexts: item.contexts, | |
550 onclick: item.onclick | |
551 }); | |
552 } | |
553 }); | |
554 isContextMenuHidden = false; | |
555 }, | |
556 hideMenuItems: function() | |
557 { | |
558 if (isContextMenuHidden) | |
559 return; | |
560 | |
561 chrome.contextMenus.removeAll(); | |
562 isContextMenuHidden = true; | |
533 } | 563 } |
534 }; | 564 }; |
535 | 565 |
536 ext.onMessage = new BackgroundMessageEventTarget(); | 566 ext.onMessage = new BackgroundMessageEventTarget(); |
537 })(); | 567 })(); |
LEFT | RIGHT |