Skip to content

Commit ae2aefe

Browse files
committed
Merge branch 'onestep-gmailjs-368'
2 parents acaa974 + b2b58dd commit ae2aefe

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/gmail.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@ var Gmail = function(localJQuery) {
2727
}
2828
}
2929

30+
var window_opener = typeof (window) !== "undefined" ? window.opener : null;
31+
if (window_opener) {
32+
try {
33+
// access to window.opener domain will fail in case of cross-origin access
34+
var opener_domain = window_opener.document.domain;
35+
if (opener_domain !== window.document.domain) {
36+
console.warn("GmailJS: window.opener domain differs from window domain.");
37+
window_opener = null;
38+
}
39+
} catch (error) {
40+
console.warn("GmailJS: Unable to access window.opener!", error);
41+
window_opener = null;
42+
}
43+
}
44+
3045
var api = {
3146
get : {},
3247
observe : {},
@@ -43,12 +58,12 @@ var Gmail = function(localJQuery) {
4358
api.tracker.globals = typeof GLOBALS !== "undefined"
4459
? GLOBALS
4560
: (
46-
typeof(window) !== "undefined" && window.opener && window.opener.GLOBALS || []
61+
window_opener && window_opener.GLOBALS || []
4762
);
4863
api.tracker.view_data = typeof VIEW_DATA !== "undefined"
4964
? VIEW_DATA
5065
: (
51-
typeof(window) !== "undefined" && window.opener && window.opener.VIEW_DATA || []
66+
window_opener && window_opener.VIEW_DATA || []
5267
);
5368
api.tracker.ik = api.tracker.globals[9] || "";
5469
api.tracker.hangouts = undefined;
@@ -1655,12 +1670,12 @@ var Gmail = function(localJQuery) {
16551670

16561671
if (top.document.getElementById("js_frame")){
16571672
js_frame = top.document.getElementById("js_frame");
1658-
} else if (window.opener) {
1659-
js_frame = window.opener.top.document.getElementById("js_frame");
1673+
} else if (window_opener) {
1674+
js_frame = window_opener.top.document.getElementById("js_frame");
16601675
}
16611676
if (!js_frame){
1662-
if (window.opener) {
1663-
js_frame = window.opener.top;
1677+
if (window_opener) {
1678+
js_frame = window_opener.top;
16641679
} else {
16651680
js_frame = top;
16661681
}

0 commit comments

Comments
 (0)