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

Delta Between Two Patch Sets: safari/ext/background.js

Issue 29340571: Issue 3687 - Add experimental support for Safari content blockers (Closed)
Left Patch Set: Rebased Created May 17, 2016, 9:19 a.m.
Right Patch Set: Addressed Nits Created May 18, 2016, 11:30 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « safari/contentBlocking.js ('k') | safari/ext/content.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 { 377 {
378 }, 378 },
379 getIndistinguishableTypes: function() 379 getIndistinguishableTypes: function()
380 { 380 {
381 return []; 381 return [];
382 } 382 }
383 }; 383 };
384 384
385 /* Message processing */ 385 /* Message processing */
386 386
387 var dispatchedLegacyAPISupportMessage = false;
387 safari.application.addEventListener("message", function(event) 388 safari.application.addEventListener("message", function(event)
388 { 389 {
389 var tab = event.target; 390 var tab = event.target;
390 var message = event.message; 391 var message = event.message;
391 var sender; 392 var sender;
392 if ("documentId" in message && "_documentLookup" in tab) 393 if ("documentId" in message && "_documentLookup" in tab)
393 { 394 {
394 sender = tab._documentLookup[message.documentId]; 395 sender = tab._documentLookup[message.documentId];
395 if (sender) 396 if (sender)
396 { 397 {
(...skipping 15 matching lines...) Expand all
412 413
413 event.message = (results.indexOf(false) == -1); 414 event.message = (results.indexOf(false) == -1);
414 break; 415 break;
415 case "request": 416 case "request":
416 var response = null; 417 var response = null;
417 var sendResponse = function(message) { response = message; }; 418 var sendResponse = function(message) { response = message; };
418 419
419 ext.onMessage._dispatch(message.payload, sender, sendResponse); 420 ext.onMessage._dispatch(message.payload, sender, sendResponse);
420 421
421 event.message = response; 422 event.message = response;
422 break;
423 case "useContentBlockerAPI":
424 event.message = require("prefs").Prefs["safariContentBlocker"];
425 break; 423 break;
426 } 424 }
427 break; 425 break;
428 case "request": 426 case "request":
429 sender.page._messageProxy.handleRequest(message, sender); 427 sender.page._messageProxy.handleRequest(message, sender);
430 break; 428 break;
431 case "response": 429 case "response":
432 // All documents within a page have the same pageId and that's all we 430 // All documents within a page have the same pageId and that's all we
433 // care about here. 431 // care about here.
434 var pageId = tab._documentLookup[message.targetDocuments[0]].pageId; 432 var pageId = tab._documentLookup[message.targetDocuments[0]].pageId;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 pageId = lastPageId; 497 pageId = lastPageId;
500 page = lastPage; 498 page = lastPage;
501 parentFrame = lastPageTopLevelFrame; 499 parentFrame = lastPageTopLevelFrame;
502 } 500 }
503 501
504 frameId = page._frames.length; 502 frameId = page._frames.length;
505 page._frames.push({url: new URL(message.url), parent: parentFrame}); 503 page._frames.push({url: new URL(message.url), parent: parentFrame});
506 } 504 }
507 505
508 tab._documentLookup[documentId] = {pageId: pageId, frameId: frameId}; 506 tab._documentLookup[documentId] = {pageId: pageId, frameId: frameId};
507
508 if (!dispatchedLegacyAPISupportMessage)
509 {
510 ext.onMessage._dispatch({
511 type: "safari.legacyAPISupported",
512 legacyAPISupported: message.legacyAPISupported
513 });
514 dispatchedLegacyAPISupportMessage = true;
515 }
509 break; 516 break;
510 case "documentId": 517 case "documentId":
511 tab._documentLookup[message.documentId] = { 518 tab._documentLookup[message.documentId] = {
512 pageId: message.pageId, frameId: 0 519 pageId: message.pageId, frameId: 0
513 }; 520 };
514 break; 521 break;
515 } 522 }
516 }); 523 });
517 524
518 525
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 /* Windows */ 597 /* Windows */
591 ext.windows = { 598 ext.windows = {
592 // Safari doesn't provide as rich a windows API as Chrome does, so instead 599 // Safari doesn't provide as rich a windows API as Chrome does, so instead
593 // of chrome.windows.create we have to fall back to just opening a new tab. 600 // of chrome.windows.create we have to fall back to just opening a new tab.
594 create: function(createData, callback) 601 create: function(createData, callback)
595 { 602 {
596 ext.pages.open(createData.url, callback); 603 ext.pages.open(createData.url, callback);
597 } 604 }
598 }; 605 };
599 })(); 606 })();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld