diff --git a/Info.plist b/Info.plist index d1bc2919..07bba47c 100644 --- a/Info.plist +++ b/Info.plist @@ -5,7 +5,7 @@ Author CatBlock Team Builder Version - 12602.2.14.0.7 + 12602.4.8 CFBundleDisplayName CatBlock CFBundleIdentifier diff --git a/button/popup.js b/button/popup.js index a59845be..6315e441 100644 --- a/button/popup.js +++ b/button/popup.js @@ -272,4 +272,4 @@ $(function() { $("#help_hide_explanation").slideToggle(); } }); -}); +}); \ No newline at end of file diff --git a/js/background.js b/js/background.js index 141d1916..89a201c8 100644 --- a/js/background.js +++ b/js/background.js @@ -1222,6 +1222,7 @@ var get_l10n_data = (SAFARI ? chrome.i18n._getL10nData : undefined); request.args.push(sender); var result = fn.apply(window, request.args); sendResponse(result); + return true; } ); })(); @@ -1407,87 +1408,111 @@ function isSafariContentBlockingAvailable() { // DEBUG INFO // Get debug info for bug reporting and ad reporting - returns an object -function getDebugInfo() { - - // An object, which contains info about AdBlock like - // subscribed filter lists, settings and other settings - var the_debug_info = { - filter_lists: [], - settings: [], - other_info: [] - }; +// Callback: is defined for every browser except Safari +function getDebugInfo(callback) { + + // Is this installed build of CatBlock the official one? + function getBuildInfo(callback) { + chrome.management.getSelf(function(selfData) { + if (!selfData || !selfData.installType || !selfData.id) { + callback("Undefined"); + return; + } - // Process subscribed filter lists - var get_subscriptions = get_subscriptions_minus_text(); - for (var id in get_subscriptions) { - if (get_subscriptions[id].subscribed) { - the_debug_info.filter_lists.push(id); - the_debug_info.filter_lists.push(" last updated: " + new Date(get_subscriptions[id].last_update).toUTCString()); - } + var extensionID = selfData.id; + var installType = selfData.installType; + + if (extensionID !== "mdcgnhlfpnbeieiiccmebgkfdebafodo" && + extensionID !== "pejeadkbfbppoaoinpmkeonebmngpnkk" && + extensionID !== "catblock@catblock.tk") { + callback("Unsupported"); + return; + } + + if (installType === "normal" || installType === "admin") { + callback("Stable"); + } else if (installType === "development") { + callback("Developer"); + } else { + callback("Unsupported"); + } + }); } - // Format info about filter lists properly - the_debug_info.filter_lists = the_debug_info.filter_lists.join("\n"); + // Push CatBlock version and build to |the_debug_info| object + function processDebugInfo(buildInfo) { + // An object, which contains info about AdBlock like + // subscribed filter lists, settings and other settings + var the_debug_info = { + filter_lists: [], + settings: [], + other_info: [] + }; - // Process custom filters & excluded filters - var adblock_custom_filters = storage_get("custom_filters"); + // Process subscribed filter lists + var get_subscriptions = get_subscriptions_minus_text(); + for (var id in get_subscriptions) { + if (get_subscriptions[id].subscribed) { + the_debug_info.filter_lists.push(id); + the_debug_info.filter_lists.push(" last updated: " + new Date(get_subscriptions[id].last_update).toUTCString()); + } + } - if (adblock_custom_filters) { - the_debug_info.custom_filters = adblock_custom_filters; - } + // Format info about filter lists properly + the_debug_info.filter_lists = the_debug_info.filter_lists.join("\n"); - if (get_exclude_filters_text()) { - the_debug_info.exclude_filters = get_exclude_filters_text(); - } + // Process custom filters & excluded filters + var adblock_custom_filters = storage_get("custom_filters"); - // Process settings - var settings = get_settings(); - for (setting in settings) { - the_debug_info.settings.push(setting + ": " + JSON.stringify(settings[setting]) + "\n"); - } + if (adblock_custom_filters) { + the_debug_info.custom_filters = adblock_custom_filters; + } - // We need to hardcode malware-notification setting, - // because it isn't included in _settings object, but just in localStorage - the_debug_info.settings.push("malware-notification: " + storage_get("malware-notification") + "\n"); - the_debug_info.settings = the_debug_info.settings.join(""); + if (get_exclude_filters_text()) { + the_debug_info.exclude_filters = get_exclude_filters_text(); + } - // Find out AdBlock version - var AdBlockVersion = chrome.runtime.getManifest().version; + // Process settings + var settings = get_settings(); + for (setting in settings) { + the_debug_info.settings.push(setting + ": " + JSON.stringify(settings[setting]) + "\n"); + } - // Is this installed build of AdBlock the official one? - function AdBlockBuild() { - if (!SAFARI) { - if (chrome.runtime.id === "pljaalgmajnlogcgiohkhdmgpomjcihk") { - return "Beta"; - } else if (chrome.runtime.id === "gighmmpiobklfepjocnamgkkbiglidom" || - chrome.runtime.id === "aobdicepooefnbaeokijohmhjlleamfj") { - return "Stable"; - } else { - return "Developer"; - } - } else { - if (safari.extension.baseURI.indexOf("com.betafish.adblockforsafari-UAMUU4S2D9") > -1) { - return "Stable"; - } else { - return "Developer"; - } + // We need to hardcode malware-notification setting, + // because it isn't included in _settings object, but just in localStorage + the_debug_info.settings.push("malware-notification: " + storage_get("malware-notification") + "\n"); + the_debug_info.settings = the_debug_info.settings.join(""); + + // Find out CatBlock version + var AdBlockVersion = chrome.runtime.getManifest().version; + the_debug_info.other_info.push("CatBlock version number: " + AdBlockVersion + " " + buildInfo); + + // Get & process last known error + var adblock_error = storage_get("error"); + if (adblock_error) { + the_debug_info.other_info.push("Last known error: " + adblock_error); } - } - // Push AdBlock version and build to |the_debug_info| object - the_debug_info.other_info.push("CatBlock version number: " + AdBlockVersion + " " + AdBlockBuild()); + // Get & process userAgent + the_debug_info.other_info.push("UserAgent: " + navigator.userAgent.replace(/;/, "")); + the_debug_info.other_info = the_debug_info.other_info.join("\n"); - // Get & process last known error - var adblock_error = storage_get("error"); - if (adblock_error) { - the_debug_info.other_info.push("Last known error: " + adblock_error); + return the_debug_info; } - // Get & process userAgent - the_debug_info.other_info.push("UserAgent: " + navigator.userAgent.replace(/;/, "")); - the_debug_info.other_info = the_debug_info.other_info.join("\n"); - - return the_debug_info; + if (!(SAFARI || EDGE)) { + getBuildInfo(function(buildInfo) { + var debugData = processDebugInfo(buildInfo); + callback(debugData); + }); + } else { + // SAFARI: + // We don't have access to the CatBlock's BG page from other pages + // like we have in other browsers. Plus we rely on sync messaging, + // so we need to return sync message to the requesting page. + var debugData = processDebugInfo("Developer"); // we have only dev version on Edge as well + return debugData; + } } // Code for making a bug report diff --git a/js/functions.js b/js/functions.js index 5c7986f8..56d9b6c5 100644 --- a/js/functions.js +++ b/js/functions.js @@ -1,10 +1,11 @@ // Set to true to get noisier console.log statements var VERBOSE_DEBUG = false; -// Global variable for detection of Opera, Edge and Firefox +// Global variable for browser detection var OPERA = navigator.userAgent.indexOf("OPR") > -1; var EDGE = navigator.userAgent.indexOf("Edge") > -1; var FIREFOX = navigator.userAgent.indexOf("Firefox") > -1; +var CHROME = !OPERA && !EDGE && !FIREFOX && !SAFARI; // SAFARI is defined in port.js // Edge uses "browser" namespace for its API if (EDGE) { diff --git a/js/port.js b/js/port.js index de29e847..7553b173 100644 --- a/js/port.js +++ b/js/port.js @@ -97,13 +97,17 @@ if (typeof SAFARI === "undefined") { // Replace the 'chrome' object with a Safari adapter. chrome = { - extension: { - getBackgroundPage: function() { - return safari.extension.globalPage.contentWindow; - } - }, - runtime: { + getBackgroundPage: function(callback) { + try { + callback(safari.extension.globalPage.contentWindow); + } catch(e) { + // BG page is not accessible from other pages + // other than self & popup.html + callback(undefined); + } + }, + getManifest: function() { var xhr = new XMLHttpRequest(); xhr.open("GET", chrome.runtime.getURL("manifest.json"), false); diff --git a/options/support.js b/options/support.js index 4f1fea9c..f597c292 100644 --- a/options/support.js +++ b/options/support.js @@ -10,38 +10,57 @@ $(document).ready(function() { $(".english-only").css("display", "inline"); } - // Show debug info - $("#debug").click(function() { - BGcall("getDebugInfo", function(the_debug_info) { - // the_debug_info is the debug info object from the BG page - content = []; + chrome.runtime.getBackgroundPage(function(backgroundPage) { + + var debug_data = null; + + function processDebugData(debugInfo) { + // |debugInfo| is the debug info object from the BG page + var content = []; + content.push("=== Filter Lists ==="); - content.push(the_debug_info.filter_lists); + content.push(debugInfo.filter_lists); content.push(""); // Custom & Excluded filters might not always be in the object - if (the_debug_info.custom_filters) { + if (debugInfo.custom_filters) { content.push("=== Custom Filters ==="); - content.push(the_debug_info.custom_filters); + content.push(debugInfo.custom_filters); content.push(""); } - if (the_debug_info.exclude_filters) { + if (debugInfo.exclude_filters) { content.push("=== Exclude Filters ==="); - content.push(the_debug_info.exclude_filters); + content.push(debugInfo.exclude_filters); content.push(""); } content.push("=== Settings ==="); - content.push(the_debug_info.settings); + content.push(debugInfo.settings); content.push(""); + content.push("=== Other Info ==="); - content.push(the_debug_info.other_info); + content.push(debugInfo.other_info); // Put it together to put into the textbox - debug_info = content.join("\n"); + debug_data = content.join("\n"); + } + + // Get debug info + // BG page is not defined on Safari + if (!backgroundPage) { + BGcall("getDebugInfo", function(debugInfo) { + processDebugData(debugInfo); + }); + } else { + backgroundPage.getDebugInfo(function(debugInfo) { + processDebugData(debugInfo); + }); + } - $("#debugInfo").html(debug_info); + // Show debug data + $("#debug").click(function() { + $("#debugInfo").html(debug_data); $("#debugInfo").css({ width: "450px", height: "100px"}); $("#debugInfo").fadeIn(); }); diff --git a/pages/adreport.js b/pages/adreport.js index 2d32955d..1759446b 100644 --- a/pages/adreport.js +++ b/pages/adreport.js @@ -81,8 +81,16 @@ BGcall("get_subscriptions_minus_text", function(subs) { }); // Get debug info -BGcall("getDebugInfo", function(info) { - debug_info = info; +chrome.runtime.getBackgroundPage(function(backgroundPage) { + if (!backgroundPage) { + BGcall("getDebugInfo", function(debugInfo) { + debug_info = debugInfo; + }); + } else { + backgroundPage.getDebugInfo(function(debugInfo) { + debug_info = debugInfo; + }); + } }); function sendReport() { @@ -616,7 +624,7 @@ $("#OtherExtensions").click(function() { // If the extension is a developer version, continue, don't disable. if (result[i].installType === "development" && result[i].type === "extension" && - result[i].name === "CatBlock") { + result[i].name === "CatBlock") { continue; } chrome.management.setEnabled(result[i].id, false);