Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get build info from chrome.management API #113

Merged
merged 16 commits into from
Jan 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<key>Author</key>
<string>CatBlock Team</string>
<key>Builder Version</key>
<string>12602.2.14.0.7</string>
<string>12602.4.8</string>
<key>CFBundleDisplayName</key>
<string>CatBlock</string>
<key>CFBundleIdentifier</key>
Expand Down
2 changes: 1 addition & 1 deletion button/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,4 @@ $(function() {
$("#help_hide_explanation").slideToggle();
}
});
});
});
157 changes: 91 additions & 66 deletions js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
);
})();
Expand Down Expand Up @@ -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");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't handling potential future copies, which is what the original code was made for.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kpeckett You are right, I will add chrome.runtime.id handling in the next commit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kpeckett Please review changes in the latest commit (handling potential future copies).

});
}

// 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
Expand Down
3 changes: 2 additions & 1 deletion js/functions.js
Original file line number Diff line number Diff line change
@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there really no reliable way of detecting if it's Chrome without just assuming it's the default?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kpeckett This is the safest way, how to detect Chrome afaik.


// Edge uses "browser" namespace for its API
if (EDGE) {
Expand Down
16 changes: 10 additions & 6 deletions js/port.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
47 changes: 33 additions & 14 deletions options/support.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
14 changes: 11 additions & 3 deletions pages/adreport.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
Expand Down