Skip to content

Commit

Permalink
🐛 amp-ima-video: Fix wrong null check (ampproject#22003)
Browse files Browse the repository at this point in the history
* amp-ima-video: Fix wrong null check

* fix dep

* Fix types
  • Loading branch information
aghassemi authored and alanorozco committed Apr 30, 2019
1 parent 2b3159a commit 1f0a26d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
31 changes: 19 additions & 12 deletions ads/google/imaVideo.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
import {CONSENT_POLICY_STATE} from '../../src/consent-state';
import {ImaPlayerData} from './ima-player-data';
import {camelCaseToTitleCase, px, setStyle, setStyles} from '../../src/style';
import {getData} from '../../src/event-helper';
import {isObject} from '../../src/types';
import {loadScript} from '../../3p/3p';
import {throttle} from '../../src/utils/rate-limit';
import {tryParseJson} from '../../src/json';


/**
* Possible player states.
* @enum {number}
Expand Down Expand Up @@ -1354,14 +1356,18 @@ export function hideControls() {
* @param {!Event} event
*/
function onMessage(global, event) {
const msg = isObject(event.data) ? event.data : tryParseJson(event.data);
if (msg === undefined) {
const eventData = getData(event);
if (!eventData) {
return;
}
const msg = isObject(eventData) ? eventData : tryParseJson(eventData);
if (!msg) {
return; // We only process valid JSON.
}
if (!msg.event || !msg.func) {
if (!msg['event'] || !msg['func']) {
return;
}
switch (msg.func) {
switch (msg['func']) {
case 'playVideo':
if (adsActive) {
adsManager.resume();
Expand Down Expand Up @@ -1398,22 +1404,23 @@ function onMessage(global, event) {
}
break;
case 'resize':
if (msg.args && msg.args.width && msg.args.height) {
const args = msg['args'];
if (args && args.width && args.height) {
setStyles(wrapperDiv, {
'width': px(msg.args.width),
'height': px(msg.args.height),
'width': px(args.width),
'height': px(args.height),
});
setStyles(bigPlayDiv, {
'width': px(msg.args.width),
'height': px(msg.args.height),
'width': px(args.width),
'height': px(args.height),
});
if (adsActive && !fullscreen) {
adsManager.resize(
msg.args.width, msg.args.height,
args.width, args.height,
global.google.ima.ViewMode.NORMAL);
} else {
adsManagerWidthOnLoad = msg.args.width;
adsManagerHeightOnLoad = msg.args.height;
adsManagerWidthOnLoad = args.width;
adsManagerHeightOnLoad = args.height;
}
}
break;
Expand Down
2 changes: 2 additions & 0 deletions build-system/dep-check-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ exports.rules = [
'ads/alp/handler.js->src/config.js',
// Some ads need to depend on json.js
'ads/**->src/json.js',
// IMA, similar to other non-Ad 3Ps above, needs access to event-helper
'ads/google/imaVideo.js->src/event-helper.js',
],
},
{
Expand Down

0 comments on commit 1f0a26d

Please sign in to comment.