Fix manfifest.json

main
Elbert Alias 8 years ago
parent 147c030f2b
commit bc20282bf8

@ -101,11 +101,7 @@
// Do nothing // Do nothing
} }
if ( typeof chrome === 'undefined' ) { ( chrome || browser ).runtime.onMessage.addListener(w.driver.onMessage);
browser.runtime.onMessage.addListener(w.driver.onMessage);
} else {
chrome.runtime.onMessage.addListener(w.driver.onMessage);
}
var callback = function(tabs) { var callback = function(tabs) {
tabs.forEach(function(tab) { tabs.forEach(function(tab) {

@ -7,18 +7,19 @@ var exports = {};
(function(exports) { (function(exports) {
var utils = { var utils = {
getReferrer: function() { normalizeUrl: function(url) {
return this.hashUrl(document.referrer) || null; return this.hashUrl(url) || null;
}, },
getPageUrl: function() { getReferrer: function() {
return this.normalizeUrl(document.referrer);
return this.hashUrl(window.location.href) || null;
}, },
getPageUrl: function() {
return this.normalizeUrl(window.location.href);
},
hashUrl: function(url) { hashUrl: function(url) {
var a, var a,
result; result;
@ -68,6 +69,7 @@ var exports = {};
realArray: function(a) { realArray: function(a) {
return Array.prototype.slice.apply(a); return Array.prototype.slice.apply(a);
}, },
onDocLoaded: function(doc, callback) { onDocLoaded: function(doc, callback) {
if ( doc.readyState === 'loading' ) { if ( doc.readyState === 'loading' ) {
doc.addEventListener('DOMContentLoaded', callback); doc.addEventListener('DOMContentLoaded', callback);
@ -117,10 +119,41 @@ var exports = {};
} }
return dict; return dict;
}, },
sendToBackground: function(message, event, responseMessage, onResponse) {
if ( typeof browser !== 'undefined' ) {
var response = browser.runtime.sendMessage(message);
response.then(onResponse);
} else if ( typeof chrome !== 'undefined' ) {
chrome.runtime.sendMessage(message, onResponse);
} else if ( window.self.port ) {
window.self.port.on(responseMessage, onResponse);
window.self.port.emit(event, message);
}
},
ifTrackingEnabled: function(callback, elseCallback) {
this.sendToBackground(
'is_tracking_enabled',
'',
'tracking_enabled_response',
function(message) {
if ( message.tracking_enabled ) {
callback();
} else {
elseCallback();
}
}
);
}
}; };
utils.SCRIPT_IN_FRIENDLY_IFRAME = !utils.SCRIPT_IN_WINDOW_TOP && utils.isFriendlyWindow(window.parent); utils.SCRIPT_IN_FRIENDLY_IFRAME = !utils.SCRIPT_IN_WINDOW_TOP && utils.isFriendlyWindow(window.parent);
utils.SCRIPT_IN_HOSTILE_IFRAME = !utils.SCRIPT_IN_WINDOW_TOP && !utils.SCRIPT_IN_FRIENDLY_IFRAME; utils.SCRIPT_IN_HOSTILE_IFRAME = !utils.SCRIPT_IN_WINDOW_TOP && !utils.SCRIPT_IN_FRIENDLY_IFRAME;
function LogGenerator() { function LogGenerator() {
this.msgNum = 0; this.msgNum = 0;
this.pageMeta = { this.pageMeta = {
@ -134,11 +167,21 @@ var exports = {};
LogGenerator.prototype = { LogGenerator.prototype = {
log: function(event, opt_assets, opt_pageTags) { log: function(event, opt_assets, opt_pageTags) {
var opt_video_assets;
if ( event === 'video' || event === 'invalid-video' ) {
opt_video_assets = opt_assets || [];
opt_assets = [];
} else {
opt_video_assets = [];
opt_assets = opt_assets || [];
}
var result = { var result = {
doc: this.pageMeta, doc: this.pageMeta,
event: event, event: event,
assets: opt_assets || [], video_assets: opt_video_assets,
assets: opt_assets,
version: '3', version: '3',
mrev: '9c4d5b3-c',
msgNum: this.msgNum, msgNum: this.msgNum,
timestamp: new Date().getTime(), timestamp: new Date().getTime(),
pageVis: document.visibilityState, pageVis: document.visibilityState,
@ -157,255 +200,342 @@ var exports = {};
(function(exports) { (function(exports) {
var VALID_AD_SIZES = [ var SizeMatcher = {
[160, 600], VALID_AD_SIZES: [
[300, 50],
[300, 250], [320, 50],
[300, 600], [160, 600],
[300, 1050], [300, 250],
[300, 600],
[336, 280], [300, 1050],
[336, 850], [336, 280],
[468, 60], [336, 850],
[728, 90], [468, 60],
[728, 270], [728, 90],
[970, 66], [728, 250],
[970, 90], [728, 270],
[970, 125], [970, 66],
[970, 250], [970, 90],
[970, 400], [970, 125],
[970, 415], [970, 250],
[1280, 100] [970, 400],
]; [970, 415],
[1280, 100]
var PX_SIZE_TOL = 10; ],
var MIN_WINDOW_PX = 10;
var MAX_SEARCHES_PER_WINDOW = 10; PX_SIZE_TOL: 10,
var MAX_SEARCHES_PER_ELEMENT = 2;
getMatchedAdSize: function(width, height) {
function makeSizeSet(validAdSizes, sizeTol) {
var set = {}; if ( !this.set ) {
var i; this.set = this._makeSizeSet();
var xfuz;
var yfuz;
var size;
var width;
var height;
for ( i = 0; i < validAdSizes.length; i++ ) {
for ( xfuz = -sizeTol; xfuz <= sizeTol; xfuz++ ) {
for ( yfuz = -sizeTol; yfuz <= sizeTol; yfuz++ ) {
size = validAdSizes[i];
width = size[0] + xfuz;
height = size[1] + yfuz;
set[width + 'x' + height] = size;
}
} }
}
return set;
}
var SIZE_SET = makeSizeSet(VALID_AD_SIZES, PX_SIZE_TOL);
function elementIsAd(el) { return this.set[Math.round(width) + 'x' + Math.round(height)];
if ( typeof el.searches !== 'number' ) { },
el.searches = 0;
}
if ( el.searches >= MAX_SEARCHES_PER_ELEMENT ) {
return false;
}
el.searches += 1;
var isImgWithoutSrc = el.tagName === 'IMG' && !el.src;
var isImgWithoutAnchor = el.tagName === 'IMG' && !(el.parentNode.tagName === 'A' || el.getAttribute('onclick'));
return elementIsAdShaped(el) && !isImgWithoutSrc && !isImgWithoutAnchor; elementIsAdShaped: function(el) {
} return !!this.getMatchedAdSizeForElement(el);
},
function isNewAd(el, win) { getMatchedAdSizeForElement: function(el) {
return !el.mp_adFound && (win === win.top || !win.mp_adFound); var rect = el.getBoundingClientRect();
} return this.getMatchedAdSize(rect.width, rect.height);
},
function getFriendlyIframes(win) { _makeSizeSet: function() {
var iframes = win.document.querySelectorAll('iframe'); var set = {};
iframes = exports.utils.realArray(iframes); var i;
var friendlyIframes = iframes.filter(function(ifr) { var xfuz;
return exports.utils.isFriendlyWindow(ifr.contentWindow); var yfuz;
}); var size;
return friendlyIframes; var width;
} var height;
for ( i = 0; i < this.VALID_AD_SIZES.length; i++ ) {
for ( xfuz = -this.PX_SIZE_TOL; xfuz <= this.PX_SIZE_TOL; xfuz++ ) {
for ( yfuz = -this.PX_SIZE_TOL; yfuz <= this.PX_SIZE_TOL; yfuz++ ) {
size = this.VALID_AD_SIZES[i];
width = size[0] + xfuz;
height = size[1] + yfuz;
set[width + 'x' + height] = size;
}
}
}
return set;
}
};
function getMatchedAdSize(width, height) { var Throttler = {
return SIZE_SET[width + 'x' + height]; MAX_SEARCHES_PER_WINDOW: 10,
} MAX_SEARCHES_PER_ELEMENT: 2,
function elementIsAdShaped(el) { countSearch: function(el) {
return !!getMatchedAdSizeForElement(el); if ( typeof el.searches !== 'number' ) {
} el.searches = 0;
}
function getMatchedAdSizeForElement(el) { el.searches += 1;
var rect = el.getBoundingClientRect(); },
return getMatchedAdSize(rect.width, rect.height);
}
function containsLargeIframes(win) { throttle: function(el, max) {
var iframes = win.document.querySelectorAll('iframe'); if ( typeof el.searches === 'number' && el.searches >= max ) {
var rect;
var i;
for ( i = 0; i < iframes.length; i++ ) {
rect = iframes[i].getBoundingClientRect();
if ( rect.width > 10 || rect.height > 10 ) {
return true; return true;
} }
} return false;
return false; },
}
function isValidHTML5Div(div, winSize) {
var elSize = getMatchedAdSizeForElement(div);
if ( typeof div.checks !== 'number' ) {
div.checks = 1;
} else {
div.checks += 1;
}
return (elSize &&
elSize[0] === winSize[0] && elSize[1] === winSize[1] &&
div.checks > 1);
}
var HTML5_SIGNAL_ELEMENTS = 'canvas, button, video, svg, img'; throttleElement: function(el) {
function iframeGetHTMLAd(win) { return this.throttle(el, this.MAX_SEARCHES_PER_ELEMENT);
var body = win.document.body, },
elements, i, el, divs, div, numElements,
winSize, elSize;
if ( !body ) { throttleWin: function(win) {
return null; return this.throttle(win, this.MAX_SEARCHES_PER_WINDOW);
} },
winSize = getMatchedAdSize(win.innerWidth, win.innerHeight);
if ( !winSize ) { getCount: function(el) {
return null; return el.searches || 0;
} }
};
elements = body.querySelectorAll(HTML5_SIGNAL_ELEMENTS); function TopSearcher(win) {
this.win = win;
this.doc = win.document;
}
for ( i = 0; i < elements.length; i++ ) { TopSearcher.prototype.search = function() {
el = elements[i]; var candidates = exports.utils.realArray(this.doc.querySelectorAll('img, object, embed')),
elSize = getMatchedAdSizeForElement(el); html5Ad,
if ( elSize && elSize[0] === winSize[0] && elSize[1] === winSize[1] ) { ads = [];
return el;
ads = ads.concat(candidates.filter(function(el) {
if ( !el.mpAdFound && !Throttler.throttleElement(el) ) {
Throttler.countSearch(el);
if ( (el.tagName !== 'IMG' || isStandardImage(el)) && SizeMatcher.elementIsAdShaped(el) ) {
el.mpAdFound = true;
return true;
}
} }
} return false;
}));
numElements = body.querySelectorAll('*').length; html5Ad = this._mainGetHTMLAd();
if ( numElements < 5 ) { if ( html5Ad ) {
return null; html5Ad.html5 = true;
html5Ad.mpAdFound = true;
ads.push(html5Ad);
} }
divs = body.querySelectorAll('div'); return ads;
};
for ( i = 0; i < divs.length; i++ ) { TopSearcher.prototype._mainGetHTMLAd = function() {
div = divs[i]; var styles = this.doc.querySelectorAll('div > style, div > link[rel="stylesheet"]'),
if ( isValidHTML5Div(div, winSize) ) { i, div;
for ( i = 0; i < styles.length; i++ ) {
div = styles[i].parentNode;
if ( !div.mpAdFound && SizeMatcher.elementIsAdShaped(div) && this._jumpedOut(div) ) {
return div; return div;
} }
} }
};
return null; TopSearcher.prototype._jumpedOut = function(el) {
}
function jumpedOut(el) {
var siblings, ifrs; var siblings, ifrs;
siblings = exports.utils.realArray(el.parentNode.children); siblings = exports.utils.realArray(el.parentNode.children);
ifrs = siblings.filter(function(el) { ifrs = siblings.filter(function(el) {
return el.tagName === 'IFRAME' && el.offsetWidth === 0 && el.offsetHeight === 0; return el.tagName === 'IFRAME' && el.offsetWidth === 0 && el.offsetHeight === 0;
}); });
return ifrs.length > 0; return ifrs.length > 0;
} };
function mainGetHTMLAd(win) { function IframeSearcher(win) {
var styles = win.document.querySelectorAll('div > style, div > link[rel="stylesheet"]'), this.MIN_AD_AREA = 14000;
i, div; this.MIN_WINDOW_PX = 10;
for ( i = 0; i < styles.length; i++ ) {
div = styles[i].parentNode; this.win = win;
if ( elementIsAdShaped(div) && jumpedOut(div) ) { this.doc = win.document;
return div; this.body = win.document.body;
this.winClickTag = win.clickTag;
this.adSizeMeta = this._getAdSizeMeta();
this.numElementsInBody = (this.body && this.body.querySelectorAll('*').length) || 0;
this.shouldSearchWindow = false;
if ( !this.win.mpAdFound && this.body && !Throttler.throttleWin(this.win) ) {
this.winWidth = this.win.innerWidth;
this.winHeight = this.win.innerHeight;
if ( this._meetsMinAdSize(this.winWidth, this.winHeight) && !this._containsLargeIframes() ) {
this.shouldSearchWindow = true;
} }
} }
} }
function findAds(win, opt_ads) { IframeSearcher.prototype.search = function() {
var ad;
if ( typeof win.searches !== 'number' ) { if ( this.shouldSearchWindow ) {
win.searches = 0; ad = this._search();
if ( ad ) {
ad.mpAdFound = true;
win.mpAdFound = true;
return ad;
}
Throttler.countSearch(this.win);
} }
var ads = opt_ads || []; return null;
var adsFound = 0; };
IframeSearcher.prototype._search = function() {
var _this = this,
stdCandidates,
html5Candidates,
stdEl,
html5El;
stdCandidates = this.body.querySelectorAll('img, object, embed');
stdEl = getFirst(stdCandidates, function(el) {
if ( !el.mpAdFound &&
!Throttler.throttleElement(el) &&
(el.tagName !== 'IMG' || isStandardImage(el)) &&
_this._elementIsAtLeastAsBigAsWindow(el))
{
return true;
}
Throttler.countSearch(el);
return false;
});
if ( win.innerWidth <= MIN_WINDOW_PX || win.innerHeight <= MIN_WINDOW_PX ) { if ( stdEl ) {
win.searches++; return stdEl;
return ads;
} }
if ( exports.utils.SCRIPT_IN_WINDOW_TOP || win.searches < MAX_SEARCHES_PER_WINDOW ) { if ( this._isHTML5Iframe() ) {
var adCandidates = win.document.querySelectorAll('img, object, embed'); html5Candidates = this.doc.querySelectorAll('body, canvas, button, video, svg, div');
adCandidates = exports.utils.realArray(adCandidates); html5El = getFirst(html5Candidates, function(el) {
adCandidates.forEach(function(el) { if ( _this._elementIsAtLeastAsBigAsWindow(el) ) {
if ( elementIsAd(el) && isNewAd(el, win) ) { return true;
el.mp_adFound = true;
el.inIframe = win !== win.top;
win.mp_adFound = true;
ads.push(el);
adsFound += 1;
} }
Throttler.countSearch(el);
return false;
}); });
}
var htmlAd, adSizeMeta; if ( html5El ) {
if ( win === win.top ) { html5El.html5 = true;
htmlAd = mainGetHTMLAd(win); html5El.winClickTag = this.winClickTag;
} else { html5El.adSizeMeta = this.adSizeMeta;
if ( adsFound === 0 && !containsLargeIframes(win) ) { return html5El;
htmlAd = iframeGetHTMLAd(win); }
}
}
if ( htmlAd && isNewAd(htmlAd, win) ) { return null;
htmlAd.html5 = true; };
htmlAd.inIframe = win !== win.top;
if ( htmlAd.inIframe ) { IframeSearcher.prototype._isHTML5Iframe = function() {
adSizeMeta = win.document.querySelectorAll('meta[name="ad.size"]'); if ( this.winClickTag || this.adSizeMeta ) {
if ( adSizeMeta.length > 0 ) { return true;
htmlAd.adSizeMeta = adSizeMeta[0].content; }
}
if ( win.clickTag ) { if ( this.doc.querySelectorAll('canvas', 'button', 'video', 'svg').length > 0 ) {
htmlAd.winClickTag = win.clickTag; return true;
} }
}
htmlAd.mp_adFound = true; if ( this.numElementsInBody >= 5 && Throttler.getCount(this.win) > 0 && this.doc.querySelectorAll('div').length > 0 ) {
win.mp_adFound = true; return true;
ads.push(htmlAd); }
return false;
};
IframeSearcher.prototype._elementIsAtLeastAsBigAsWindow = function(el) {
var rect = el.getBoundingClientRect(),
tol = 0.95;
return rect.width >= (tol * this.winWidth) && rect.height >= (tol * this.winHeight);
};
IframeSearcher.prototype._meetsMinAdSize = function(width, height) {
return (width * height) >= this.MIN_AD_AREA;
};
IframeSearcher.prototype._containsLargeIframes = function() {
var iframes = this.doc.querySelectorAll('iframe');
var rect;
var i;
for ( i = 0; i < iframes.length; i++ ) {
rect = iframes[i].getBoundingClientRect();
if ( rect.width > this.MIN_WINDOW_PX || rect.height > this.MIN_WINDOW_PX ) {
return true;
} }
}
return false;
};
win.searches += 1; IframeSearcher.prototype._getAdSizeMeta = function() {
var adSizeMeta = this.doc.querySelectorAll('meta[name="ad.size"]');
if ( adSizeMeta.length > 0 ) {
return adSizeMeta[0].content;
} else {
return null;
} }
};
var iframes = getFriendlyIframes(win); function getFirst(arr, testFn) {
iframes.forEach(function(ifr) { var i, el;
findAds(ifr.contentWindow, ads); for ( i = 0; i < arr.length; i++ ) {
el = arr[i];
if ( testFn(el) ) {
return el;
}
}
return null;
}
function isStandardImage(img) {
return img.src && (img.parentNode.tagName === 'A' || img.getAttribute('onclick'));
}
function getFriendlyIframes(win) {
var iframes = win.document.querySelectorAll('iframe');
iframes = exports.utils.realArray(iframes);
var friendlyIframes = iframes.filter(function(ifr) {
return exports.utils.isFriendlyWindow(ifr.contentWindow);
}); });
return friendlyIframes;
}
function findAds(win) {
var i,
iframes,
searcher,
ad,
ads = [];
if ( win === win.top ) {
searcher = new TopSearcher(win);
ads = ads.concat(searcher.search());
} else {
searcher = new IframeSearcher(win);
ad = searcher.search();
if ( ad ) {
ads.push(ad);
}
}
iframes = getFriendlyIframes(win);
for ( i = 0; i < iframes.length; i++ ) {
ads = ads.concat(findAds(iframes[i].contentWindow));
}
return ads; return ads;
} }
exports.adfinder = { exports.adfinder = {
getMatchedAdSize: getMatchedAdSize, getMatchedAdSize: SizeMatcher.getMatchedAdSize.bind(SizeMatcher),
findAds: findAds findAds: findAds
}; };
})(exports); })(exports);
@ -463,11 +593,12 @@ var exports = {};
getPosition: function(el) { getPosition: function(el) {
var rect = el.getBoundingClientRect(); var rect = el.getBoundingClientRect();
var win = exports.utils.elementWindow(el); var win = exports.utils.elementWindow(el);
return { return {
width: rect.width, width: Math.round(rect.width),
height: rect.height, height: Math.round(rect.height),
left: rect.left + win.pageXOffset, left: Math.round(rect.left + win.pageXOffset),
top: rect.top + win.pageYOffset top: Math.round(rect.top + win.pageYOffset)
}; };
}, },
@ -682,7 +813,7 @@ var exports = {};
while ( true ) { while ( true ) {
parentContainer = curContainer.parentElement; parentContainer = curContainer.parentElement;
if ( this.isValidContainer(parentContainer) ) { if ( parentContainer && this.isValidContainer(parentContainer) ) {
curContainer = parentContainer; curContainer = parentContainer;
} else { } else {
return curContainer; return curContainer;
@ -693,12 +824,6 @@ var exports = {};
var tagfinder = { var tagfinder = {
prepToSend: function(adData) {
adData.matchedSize = exports.adfinder.getMatchedAdSize(adData.width, adData.height);
delete adData.width;
delete adData.height;
},
setPositions: function(adData, opt_el, opt_winPos) { setPositions: function(adData, opt_el, opt_winPos) {
var el = opt_el || adData.context; var el = opt_el || adData.context;
var winPos = opt_winPos || {left: 0, top: 0}; var winPos = opt_winPos || {left: 0, top: 0};
@ -732,10 +857,12 @@ var exports = {};
while ( true ) { while ( true ) {
highestContainer = mgr.highestContainer(curWin, referenceElement); highestContainer = mgr.highestContainer(curWin, referenceElement);
mgr.captureHTML(highestContainer); mgr.captureHTML(highestContainer);
if ( curWin === curWin.top ) { if ( curWin === curWin.top ) {
break; break;
} else { } else {
curWin.mpAdFound = true;
mgr.adData.serializedIframeContents = mgr.adData.context; mgr.adData.serializedIframeContents = mgr.adData.context;
if ( exports.utils.isFriendlyWindow(curWin.parent) ) { if ( exports.utils.isFriendlyWindow(curWin.parent) ) {
@ -763,6 +890,8 @@ var exports = {};
var _pageTags; var _pageTags;
var INIT_MS_BW_SEARCHES = 2000; var INIT_MS_BW_SEARCHES = 2000;
var PAGE_TAG_RE = new RegExp('gpt|oascentral'); var PAGE_TAG_RE = new RegExp('gpt|oascentral');
var POST_MSG_ID = '1490888598-28717-31700-14775-21098';
var AD_SERVER_RE = new RegExp('^(google_ads_iframe|oas_frame|atwAdFrame)');
function getPageTags(doc) { function getPageTags(doc) {
var scripts = doc.getElementsByTagName('script'); var scripts = doc.getElementsByTagName('script');
@ -778,7 +907,7 @@ var exports = {};
function messageAllParentFrames(adData) { function messageAllParentFrames(adData) {
adData.dummyId = true; adData.postMessageId = POST_MSG_ID;
adData = JSON.stringify(adData); adData = JSON.stringify(adData);
@ -795,16 +924,31 @@ var exports = {};
messageAllParentFrames(adData); messageAllParentFrames(adData);
} else if ( exports.utils.SCRIPT_IN_WINDOW_TOP ) { } else if ( exports.utils.SCRIPT_IN_WINDOW_TOP ) {
exports.tagfinder.setPositions(adData); exports.tagfinder.setPositions(adData);
exports.tagfinder.prepToSend(adData);
adData.matchedSize = exports.adfinder.getMatchedAdSize(adData.width, adData.height);
if ( !adData.matchedSize ) {
if ( AD_SERVER_RE.exec(results.referenceElement.id) ) {
adData.matchedSize = [adData.width, adData.height];
adData.oddSize = true;
} else {
return;
}
}
delete adData.width;
delete adData.height;
adData.curPageUrl = exports.utils.getPageUrl(); adData.curPageUrl = exports.utils.getPageUrl();
_pageTags = _pageTags || getPageTags(document); _pageTags = _pageTags || getPageTags(document);
var log = _logGen.log('ad', [adData], _pageTags); var log = _logGen.log('ad', [adData], _pageTags);
if ( _onAdFound ) { if ( _onAdFound ) {
_onAdFound(log, results.referenceElement);
}
_onAdFound(log, results.referenceElement);
}
} }
} }
@ -812,33 +956,27 @@ var exports = {};
if ( exports.utils.SCRIPT_IN_WINDOW_TOP || document.readyState === 'complete' ) { if ( exports.utils.SCRIPT_IN_WINDOW_TOP || document.readyState === 'complete' ) {
extractAds(); extractAds();
} }
setTimeout(function() { setTimeout(
extractAdsWrapper(); function() { extractAdsWrapper(); }, INIT_MS_BW_SEARCHES
}, INIT_MS_BW_SEARCHES); );
} }
function extractAds() { function extractAds() {
var ads = exports.adfinder.findAds(window); var ads = exports.adfinder.findAds(window);
if ( !ads ) {
return;
}
ads.forEach(function(ad) { ads.forEach(function(ad) {
var startTime = new Date().getTime(); var startTime = new Date().getTime();
var adId = startTime + '-' + Math.floor(Math.random() * 10e12); var adId = startTime + '-' + Math.floor(Math.random() * 10e12);
var adData = { var adData = {
width: ad.offsetWidth, width: Math.round(ad.offsetWidth),
height: ad.offsetHeight, height: Math.round(ad.offsetHeight),
startTime: startTime, startTime: startTime,
adId: adId, adId: adId,
html5: ad.html5 || false, html5: ad.html5 || false
inIframe: ad.inIframe
}; };
if ( ad.html5 && ad.inIframe ) { if ( ad.html5 ) {
adData.adSizeMeta = ad.adSizeMeta || null; adData.adSizeMeta = ad.adSizeMeta || null;
adData.winClickTag = ad.winClickTag || null; adData.winClickTag = ad.winClickTag || null;
} }
@ -898,9 +1036,11 @@ var exports = {};
return; return;
} }
if ( adData.dummyId ) { if ( adData.postMessageId === POST_MSG_ID ) {
delete adData.postMessageId;
delete adData.dummyId; event.stopImmediatePropagation();
if ( isChildWin(myWin, ifrWin) ) { if ( isChildWin(myWin, ifrWin) ) {
if ( exports.utils.isFriendlyWindow(ifrWin) ) { if ( exports.utils.isFriendlyWindow(ifrWin) ) {
@ -917,7 +1057,53 @@ var exports = {};
} }
} }
function onVideoMessage(msg, sender, callback) {
var log;
if ( msg.event === 'new-video-ad' ) {
msg.assets.forEach(function(asset) {
});
log = _logGen.log('video', msg.assets);
} else {
log = _logGen.log('invalid-video', msg.assets);
}
msg.assets.forEach(function(a) {delete a.isVideo;});
log.displayAdFound = msg.displayAdFound;
log.requests = msg.requests;
log.data = msg.event_data;
log.doc.finalPageUrl = log.doc.url;
log.doc.url = exports.utils.normalizeUrl(msg.origUrl);
_onAdFound(log);
}
function addBackgroundListener(event, callback) {
if ( typeof browser !== 'undefined' ) {
browser.runtime.onMessage.addListener(function(msg) {
if ( msg.event === event ) {
callback(msg);
}
});
} else if ( typeof chrome !== 'undefined' ) {
chrome.runtime.onMessage.addListener(function(msg) {
if ( msg.event === event ) {
callback(msg);
}
});
} else if ( window.self.port ) {
window.self.port.on(event, callback);
}
}
exports.coordinator = { exports.coordinator = {
addPostMessageListener: function() {
if ( !exports.utils.SCRIPT_IN_FRIENDLY_IFRAME ) {
window.addEventListener('message', onPostMessage, false);
}
},
init: function(onAdFound) { init: function(onAdFound) {
if ( exports.utils.SCRIPT_IN_FRIENDLY_IFRAME ) { if ( exports.utils.SCRIPT_IN_FRIENDLY_IFRAME ) {
@ -925,19 +1111,19 @@ var exports = {};
} }
_onAdFound = onAdFound; _onAdFound = onAdFound;
if ( exports.utils.SCRIPT_IN_WINDOW_TOP ) { if ( exports.utils.SCRIPT_IN_WINDOW_TOP ) {
var log = _logGen.log('page'); var log = _logGen.log('page');
onAdFound(log); onAdFound(log);
}
window.addEventListener('message', onPostMessage, false);
if ( exports.utils.SCRIPT_IN_WINDOW_TOP ) {
window.addEventListener('beforeunload', function(event) { window.addEventListener('beforeunload', function(event) {
var log = _logGen.log('unload'); var log = _logGen.log('unload');
log.timing = window.performance.timing; log.timing = window.performance.timing;
onAdFound(log); onAdFound(log);
}); });
addBackgroundListener('new-video-ad', onVideoMessage);
addBackgroundListener('new-invalid-video-ad', onVideoMessage);
} }
exports.utils.onDocLoaded(document, extractAdsWrapper); exports.utils.onDocLoaded(document, extractAdsWrapper);
@ -949,27 +1135,32 @@ var exports = {};
if ( exports.utils.SCRIPT_IN_WINDOW_TOP ) { if ( exports.utils.SCRIPT_IN_WINDOW_TOP ) {
window.adparser = { window.adparser = {
init: exports.coordinator.init, init: exports.coordinator.init,
addPostMessageListener: exports.coordinator.addPostMessageListener,
ifTrackingEnabled: exports.utils.ifTrackingEnabled,
sendToBackground: exports.utils.sendToBackground
}; };
} else { } else {
exports.coordinator.init(function() {}); exports.coordinator.addPostMessageListener();
exports.utils.ifTrackingEnabled(
function() {
exports.coordinator.init(function() {});
},
function() {}
);
} }
})(window); })(window);
(function(adparser) { (function(adparser) {
function sendToBackground(event, message) {
if ( window.self.port ) {
window.self.port.emit(event, message);
} else if ( typeof chrome !== 'undefined' ) {
chrome.extension.sendRequest(message);
}
}
function onAdFound(log) { function onAdFound(log) {
sendToBackground('ad_log', { id: 'ad_log', subject: log }); adparser.sendToBackground({ id: 'ad_log', subject: log }, 'ad_log', '', function(){});
} }
if ( window === window.top ) { if ( window === window.top ) {
adparser.init(onAdFound); adparser.addPostMessageListener();
adparser.ifTrackingEnabled(
function() {
adparser.init(onAdFound);
},
function() {}
)
} }
})(window.adparser); })(window.adparser);

@ -782,4 +782,3 @@
}); });
})(); })();

@ -59,6 +59,7 @@
], ],
"options_page": "options.html", "options_page": "options.html",
"permissions": [ "permissions": [
"storage",
"tabs", "tabs",
"webRequest", "webRequest",
"webNavigation", "webNavigation",

@ -26,8 +26,8 @@
"default_popup": "popup.html" "default_popup": "popup.html"
}, },
"background": { "background": {
"page": "background.html", "page": "background.html"
"persistent": true
}, },
"content_scripts": [ "content_scripts": [
{ {
@ -43,7 +43,7 @@
}, },
{ {
"matches": [ "matches": [
"http://*/*", "http://*/*",
"https://*/*" "https://*/*"
], ],
"js": [ "js": [
@ -58,16 +58,19 @@
"js/inject.js" "js/inject.js"
], ],
"options_page": "options.html", "options_page": "options.html",
"options_ui": {
"page": "options.html",
"open_in_tab": false
},
"permissions": [ "permissions": [
"storage",
"tabs", "tabs",
"webRequest", "webRequest",
"webNavigation", "webNavigation",
"http://*/*", "http://*/*",
"https://*/*" "https://*/*"
], ],
"content_security_policy": "script-src 'self'; object-src 'self'", "content_security_policy": "script-src 'self'; object-src 'self'"
"-ms-preload": {
"backgroundScript": "js/ms_background_scripts_api_bridge.js",
"contentScript": "js/ms_content_scripts_api_bridge.js"
}
} }

Loading…
Cancel
Save