Skip to content

Commit

Permalink
Block infobars when already dismissed or blocked
Browse files Browse the repository at this point in the history
See Bug 1369147.

Testing
- Navigated to site with hidden flash, ensured that the infobar
  showed up. Checked telemetry to ensure that it was marked as
  shown.
- Navigated to the same site, dismissed the infobar. Navigated to
  it again and ensured that the infobar didn't show up. Checked
  telemetry to ensure that it was marked as dismissed the first
  time, and as 'none' the second time.
- Added the site's base domain to the block list, and ensured that
  the infobar never showed up, and that it was marked as 'none' in
  the telemetry payload.
- Did the same for a subframe of a site that was causing an
  infobar.[1]

This is the site:
http://viralko.org/to-nisu-iste-zene-ili-jesu-pogledajte-ovih-10-nevjerovatnih-transformacija-i-shvatit-cete-koliku-moc-ima-sminka/
  • Loading branch information
squarewave committed May 31, 2017
1 parent 1877389 commit b1af902
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 5 deletions.
22 changes: 20 additions & 2 deletions lib/dataCollection.js
Expand Up @@ -110,7 +110,12 @@ function rollUpEvents() {
'allow-and-remember': 0,
'deny': 0,
'feedback-given': 0,
}
},

infobars: {
shown: 0,
dismissed: 0,
},
};

for (const event of allEvents) {
Expand All @@ -124,6 +129,7 @@ function rollUpEvents() {
ctpVia: event.docObj.ctpVia, // TODO
docshellId: event.docObj.docshellId,
private: event.docObj.private,
infobarAction: 'none', // none | shown | dismissed
'user-feedback': {},
flashObjs: [],
subDocs: [],
Expand Down Expand Up @@ -176,6 +182,18 @@ function rollUpEvents() {
}
doc.userAction.push(event.kind);
break;
case 'InfoBar':
doc.infobarAction = event.kind;
if (event.kind != 'none') {
counts['infobars'][event.kind]++;
}
if (event.kind == 'dismissed') {
// dismissed overrides shown, but we don't want the data to be misleading.
// Increment shown because in order to be dismissed the notification must
// first be shown.
counts['infobars']['shown']++;
}
break;
}
}
}
Expand Down Expand Up @@ -262,7 +280,7 @@ function rollUpEvents() {
const daysInExperiment = (Date.now() - ss.storage.experimentStart) / ONE_DAY_MILLIS;

const payload = {
version: 2,
version: 3,
clientID: ClientID.getCachedClientID(),
locale: tryGetCharPref('general.useragent.locale', 'zz-ZZ'),
geo: tryGetCharPref('browser.search.countryCode', 'ZZ'),
Expand Down
52 changes: 49 additions & 3 deletions lib/ui.js
Expand Up @@ -18,6 +18,7 @@ const utils = require('./utils');
const dataCollection = require('./dataCollection');

const { Services } = Cu.import('resource://gre/modules/Services.jsm', {});
const { NetUtil } = Cu.import('resource://gre/modules/NetUtil.jsm', {});

const { PLUGIN_ACTIVE } = Ci.nsIObjectLoadingContent;

Expand All @@ -36,6 +37,18 @@ const DEFAULT_HEIGHT = (IS_OSX ? 294 : 334) + HEIGHT_ADJUST;
const HAVING_PROBLEMS_HEIGHT = (IS_OSX ? 144 : 158);
const HAS_ACTIVATING_SOLVED_HEIGHT = (IS_OSX ? 196 : 214);

const INFOBAR_BLOCKLIST = new Set([
'yandex.ru',
'chpoking.ru',
'ok.ru',
'amazon.com',
'amazon.co.jp',
'amazon.fr',
'twitch.tv',
'ebay.com',
'aol.com',
]);

const config = {
tellUsMoreAfterHasThisSolvedTimeout: 60 * 1000,
useAnchor: true,
Expand Down Expand Up @@ -95,6 +108,14 @@ function reportModifier(kind) {
});
}

function reportInfobar(kind, browser) {
dataCollection.ingest({
type: 'InfoBar',
windowID: browser.innerWindowID,
kind
});
}

function showView(name, options) {
if (!options) {
options = { height: DEFAULT_HEIGHT };
Expand Down Expand Up @@ -186,7 +207,13 @@ function listenOnContentProcessMessages(chromeGlobal) {
if (msg.data.flashObj.path === null && msg.target.removeNextPluginBar === undefined) {
msg.target.removeNextPluginBar = true;
} else if (msg.data.flashObj.path !== null) {
msg.target.removeNextPluginBar = false;
let pathURI = NetUtil.newURI(msg.data.flashObj.path);
let baseDomain = Services.eTLD.getBaseDomain(pathURI);
if (INFOBAR_BLOCKLIST.has(baseDomain)) {
msg.target.removeNextPluginBar = true;
} else {
msg.target.removeNextPluginBar = false;
}
}
} else if (msg.data.type == 'pageshow') {
delete msg.target.removeNextPluginBar;
Expand All @@ -195,8 +222,27 @@ function listenOnContentProcessMessages(chromeGlobal) {

mm.addMessageListener('PluginContent:UpdateHiddenPluginUI', (msg) => {
if (!msg.target.removeNextPluginBar) {
chromeGlobal.gPluginHandler.updateHiddenPluginUI(msg.target,
msg.data.haveInsecure, msg.data.actions, msg.principal, msg.data.location);
let baseDomain = Services.eTLD.getBaseDomain(msg.target.documentURI);
if (!INFOBAR_BLOCKLIST.has(baseDomain) && !utils.testHadInfobarDismissed(baseDomain)) {
chromeGlobal.gPluginHandler.updateHiddenPluginUI(msg.target,
msg.data.haveInsecure, msg.data.actions, msg.principal, msg.data.location);
let notificationBox = chromeGlobal.gBrowser.getNotificationBox(msg.target);
let notification = notificationBox.getNotificationWithValue("plugin-hidden");
if (notification && !notification.alreadyHooked) {
notification.alreadyHooked = true;
reportInfobar('shown', msg.target);
let oldCallback = notification.eventCallback;
notification.eventCallback = (reason) => {
if (reason == 'dismissed') {
reportInfobar('dismissed', msg.target);
utils.storeHadInfobarDismissed(baseDomain);
}
if (oldCallback) {
oldCallback(reason);
}
};
}
}
}

delete msg.target.removeNextPluginBar;
Expand Down
18 changes: 18 additions & 0 deletions lib/utils.js
Expand Up @@ -16,6 +16,14 @@ function getSeenHosts() {
return ss.storage.seenHosts;
}

function getDismissedInfobars() {
if (!ss.storage.dismissedInfobars) {
ss.storage.dismissedInfobars = {};
}

return ss.storage.dismissedInfobars;
}

function storeSeenHost(chromeGlobal, val = true) {
const host = getHostFromChromeGlobal(chromeGlobal);

Expand All @@ -28,6 +36,14 @@ function testIfSeenHostBefore(chromeGlobal) {
return getSeenHosts()[host];
}

function storeHadInfobarDismissed(baseDomain) {
getDismissedInfobars()[baseDomain] = true;
}

function testHadInfobarDismissed(baseDomain) {
return getDismissedInfobars()[baseDomain];
}

function storeClickedOnBrick(val = true) {
return ss.storage.clickedOnBrick = val;
}
Expand Down Expand Up @@ -96,8 +112,10 @@ module.exports = {
getSeenHosts,
storeSeenHost,
storeClickedOnBrick,
storeHadInfobarDismissed,
testIfClickedOnBrickBefore,
testIfSeenHostBefore,
testHadInfobarDismissed,
getHostFromChromeGlobal,
getPluginNotificationForWindow,
getFlashPluginFromNotification,
Expand Down

1 comment on commit b1af902

@felipc
Copy link

@felipc felipc commented on b1af902 Jun 1, 2017

Choose a reason for hiding this comment

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

r=felipe

Please sign in to comment.