mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-26 07:49:24 +01:00
wombat: reinit paths if inited via new window creation/iframe to reflect correct url!
refactor wombat into single _WBWombat object
This commit is contained in:
parent
8fe2c1b5bd
commit
e0878f0f67
@ -22,11 +22,7 @@ This file is part of pywb, https://github.com/ikreymer/pywb
|
|||||||
//============================================
|
//============================================
|
||||||
|
|
||||||
|
|
||||||
|
var _WBWombat = function($wbwindow, wbinfo) {
|
||||||
_WBWombat = (function() {
|
|
||||||
|
|
||||||
|
|
||||||
var wombat_internal = function($wbwindow) {
|
|
||||||
|
|
||||||
// Globals
|
// Globals
|
||||||
var wb_replay_prefix;
|
var wb_replay_prefix;
|
||||||
@ -417,7 +413,8 @@ var wombat_internal = function($wbwindow) {
|
|||||||
baseWin = $wbwindow;
|
baseWin = $wbwindow;
|
||||||
}
|
}
|
||||||
|
|
||||||
var p = baseWin.document.createElement("a", true);
|
var p = baseWin.document.createElement("a");
|
||||||
|
p._no_rewrite = true;
|
||||||
p.href = href;
|
p.href = href;
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
@ -1665,10 +1662,8 @@ var wombat_internal = function($wbwindow) {
|
|||||||
|
|
||||||
var getter = function() {
|
var getter = function() {
|
||||||
for (var i = 0; i < this.__wb_frames.length; i++) {
|
for (var i = 0; i < this.__wb_frames.length; i++) {
|
||||||
if (!this.__wb_frames[i]._wb_wombat) {
|
|
||||||
init_new_window_wombat(this.__wb_frames[i]);
|
init_new_window_wombat(this.__wb_frames[i]);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return this.__wb_frames;
|
return this.__wb_frames;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -2198,13 +2193,6 @@ var wombat_internal = function($wbwindow) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var check_wombat = function(win) {
|
|
||||||
if (win && !win._wb_wombat) {
|
|
||||||
win._WBWombat = wombat_internal(win);
|
|
||||||
win._wb_wombat = new win._WBWombat(wb_info);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write
|
// Write
|
||||||
var orig_doc_write = $wbwindow.document.write;
|
var orig_doc_write = $wbwindow.document.write;
|
||||||
|
|
||||||
@ -2214,7 +2202,7 @@ var wombat_internal = function($wbwindow) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var res = orig_doc_write.call(this, new_buff);
|
var res = orig_doc_write.call(this, new_buff);
|
||||||
check_wombat(this.defaultView);
|
init_new_window_wombat(this.defaultView);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2230,7 +2218,7 @@ var wombat_internal = function($wbwindow) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var res = orig_doc_writeln.call(this, new_buff);
|
var res = orig_doc_writeln.call(this, new_buff);
|
||||||
check_wombat(this.defaultView);
|
init_new_window_wombat(this.defaultView);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2242,7 +2230,7 @@ var wombat_internal = function($wbwindow) {
|
|||||||
|
|
||||||
var new_open = function() {
|
var new_open = function() {
|
||||||
var res = orig_doc_open.call(this);
|
var res = orig_doc_open.call(this);
|
||||||
check_wombat(this.defaultView);
|
init_new_window_wombat(this.defaultView);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2287,9 +2275,15 @@ var wombat_internal = function($wbwindow) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function init_new_window_wombat(win, src) {
|
function init_new_window_wombat(win, src) {
|
||||||
|
if (!win || win._wb_wombat) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!src || src == "" || src == "about:blank" || src.indexOf("javascript:") >= 0) {
|
if (!src || src == "" || src == "about:blank" || src.indexOf("javascript:") >= 0) {
|
||||||
win._WBWombat = wombat_internal(win);
|
//win._WBWombat = wombat_internal(win);
|
||||||
win._wb_wombat = new win._WBWombat(wb_info);
|
//win._wb_wombat = new win._WBWombat(wb_info);
|
||||||
|
win._wb_wombat = new _WBWombat(win, wb_info);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// These should get overriden when content is loaded, but just in case...
|
// These should get overriden when content is loaded, but just in case...
|
||||||
//win._WB_wombat_location = win.location;
|
//win._WB_wombat_location = win.location;
|
||||||
@ -2457,7 +2451,7 @@ var wombat_internal = function($wbwindow) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//============================================
|
//============================================
|
||||||
function wombat_init(wbinfo) {
|
function init_paths(wbinfo) {
|
||||||
wb_info = wbinfo;
|
wb_info = wbinfo;
|
||||||
wb_opts = wbinfo.wombat_opts;
|
wb_opts = wbinfo.wombat_opts;
|
||||||
wb_replay_prefix = wbinfo.prefix;
|
wb_replay_prefix = wbinfo.prefix;
|
||||||
@ -2465,30 +2459,14 @@ var wombat_internal = function($wbwindow) {
|
|||||||
|
|
||||||
wb_info.top_host = wb_info.top_host || "*";
|
wb_info.top_host = wb_info.top_host || "*";
|
||||||
|
|
||||||
init_top_frame($wbwindow);
|
wb_curr_host = $wbwindow.location.protocol + "//" + $wbwindow.location.host;
|
||||||
|
|
||||||
init_wombat_loc($wbwindow);
|
|
||||||
|
|
||||||
wbinfo.wombat_opts = wbinfo.wombat_opts || {};
|
wbinfo.wombat_opts = wbinfo.wombat_opts || {};
|
||||||
|
|
||||||
wb_orig_scheme = wbinfo.wombat_scheme + '://';
|
wb_orig_scheme = wbinfo.wombat_scheme + '://';
|
||||||
|
wb_orig_origin = wb_orig_scheme + wbinfo.wombat_host;
|
||||||
// archival mode: init url-rewriting intercepts
|
|
||||||
if (!wb_is_proxy) {
|
|
||||||
init_wombat_top($wbwindow);
|
|
||||||
|
|
||||||
wb_curr_host = $wbwindow.location.protocol + "//" + $wbwindow.location.host;
|
|
||||||
|
|
||||||
if (wb_replay_prefix && wb_replay_prefix.indexOf($wbwindow.__WB_replay_top.location.origin) == 0) {
|
|
||||||
wb_rel_prefix = wb_replay_prefix.substring($wbwindow.__WB_replay_top.location.origin.length + 1);
|
|
||||||
} else {
|
|
||||||
wb_rel_prefix = wb_replay_prefix;
|
|
||||||
}
|
|
||||||
wb_rel_prefix_check = wb_rel_prefix;
|
|
||||||
|
|
||||||
wb_abs_prefix = wb_replay_prefix;
|
wb_abs_prefix = wb_replay_prefix;
|
||||||
//wb_replay_date_prefix = wb_replay_prefix + ts_mod;
|
|
||||||
//wb_coll_prefix += ts_mod;
|
|
||||||
|
|
||||||
if (!wbinfo.is_live && wbinfo.wombat_ts.length > 0) {
|
if (!wbinfo.is_live && wbinfo.wombat_ts.length > 0) {
|
||||||
wb_capture_date_part = "/" + wbinfo.wombat_ts + "/";
|
wb_capture_date_part = "/" + wbinfo.wombat_ts + "/";
|
||||||
@ -2496,9 +2474,26 @@ var wombat_internal = function($wbwindow) {
|
|||||||
wb_capture_date_part = "";
|
wb_capture_date_part = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
wb_orig_origin = wb_orig_scheme + wbinfo.wombat_host;
|
|
||||||
|
|
||||||
init_bad_prefixes(wb_replay_prefix);
|
init_bad_prefixes(wb_replay_prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
function wombat_init(wbinfo) {
|
||||||
|
init_paths(wbinfo);
|
||||||
|
|
||||||
|
init_top_frame($wbwindow);
|
||||||
|
|
||||||
|
init_wombat_loc($wbwindow);
|
||||||
|
|
||||||
|
// archival mode: init url-rewriting intercepts
|
||||||
|
if (!wb_is_proxy) {
|
||||||
|
init_wombat_top($wbwindow);
|
||||||
|
|
||||||
|
if (wb_replay_prefix && wb_replay_prefix.indexOf($wbwindow.__WB_replay_top.location.origin) == 0) {
|
||||||
|
wb_rel_prefix = wb_replay_prefix.substring($wbwindow.__WB_replay_top.location.origin.length + 1);
|
||||||
|
} else {
|
||||||
|
wb_rel_prefix = wb_replay_prefix;
|
||||||
|
}
|
||||||
|
wb_rel_prefix_check = wb_rel_prefix;
|
||||||
|
|
||||||
//if ($wbwindow.opener) {
|
//if ($wbwindow.opener) {
|
||||||
// $wbwindow.opener.WB_wombat_location = copy_location_obj($wbwindow.opener.location);
|
// $wbwindow.opener.WB_wombat_location = copy_location_obj($wbwindow.opener.location);
|
||||||
@ -2612,10 +2607,13 @@ var wombat_internal = function($wbwindow) {
|
|||||||
init_disable_notifications();
|
init_disable_notifications();
|
||||||
|
|
||||||
// expose functions
|
// expose functions
|
||||||
this.extract_orig = extract_orig;
|
var obj = {}
|
||||||
this.rewrite_url = rewrite_url;
|
obj.extract_orig = extract_orig;
|
||||||
this.watch_elem = watch_elem;
|
obj.rewrite_url = rewrite_url;
|
||||||
this.init_new_window_wombat = init_new_window_wombat;
|
obj.watch_elem = watch_elem;
|
||||||
|
obj.init_new_window_wombat = init_new_window_wombat;
|
||||||
|
obj.init_paths = init_paths;
|
||||||
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
function init_top_frame($wbwindow) {
|
function init_top_frame($wbwindow) {
|
||||||
@ -2766,10 +2764,7 @@ var wombat_internal = function($wbwindow) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return wombat_init;
|
return wombat_init(wbinfo);
|
||||||
};
|
};
|
||||||
|
|
||||||
return wombat_internal(window);
|
|
||||||
})();
|
|
||||||
|
|
||||||
window._WBWombat = _WBWombat;
|
window._WBWombat = _WBWombat;
|
||||||
|
@ -25,9 +25,10 @@
|
|||||||
|
|
||||||
wbinfo.wombat_opts = {{ wbrequest.rewrite_opts.client | tojson if wbrequest.rewrite_opts.client else '{}' }};
|
wbinfo.wombat_opts = {{ wbrequest.rewrite_opts.client | tojson if wbrequest.rewrite_opts.client else '{}' }};
|
||||||
|
|
||||||
|
|
||||||
if (window && window._WBWombat && !window._wb_js_inited && !window._wb_wombat) {
|
if (window && window._WBWombat && !window._wb_js_inited && !window._wb_wombat) {
|
||||||
window._wb_wombat = new _WBWombat(wbinfo);
|
window._wb_wombat = new _WBWombat(window, wbinfo);
|
||||||
|
} else {
|
||||||
|
window._wb_wombat.init_paths(wbinfo);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user