mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-28 00:25:21 +01:00
wombat: continue using anchor element (with no rewriting) instead of less standard URL class, avoid
edge cases/browser differences
This commit is contained in:
parent
f62bf9a252
commit
69f838211d
@ -48,17 +48,6 @@ var wombat_internal = function($wbwindow) {
|
|||||||
// custom options
|
// custom options
|
||||||
var wb_opts;
|
var wb_opts;
|
||||||
|
|
||||||
//============================================
|
|
||||||
function load_url_js() {
|
|
||||||
var s = $wbwindow.document.createElement("script");
|
|
||||||
s.src = wbinfo.static_prefix + "/url.js";
|
|
||||||
$wbwindow.document.head.appendChild(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$wbwindow.URL) {
|
|
||||||
load_url_js();
|
|
||||||
}
|
|
||||||
|
|
||||||
//============================================
|
//============================================
|
||||||
function is_host_url(str) {
|
function is_host_url(str) {
|
||||||
// Good guess that's its a hostname
|
// Good guess that's its a hostname
|
||||||
@ -156,6 +145,8 @@ var wombat_internal = function($wbwindow) {
|
|||||||
|
|
||||||
var REWRITE_ATTRS = ["src", "href", "poster"];
|
var REWRITE_ATTRS = ["src", "href", "poster"];
|
||||||
|
|
||||||
|
var URL_PROPS = ["href", "hash", "pathname", "host", "hostname", "protocol", "origin", "search", "port"];
|
||||||
|
|
||||||
//============================================
|
//============================================
|
||||||
function rewrite_url_(url) {
|
function rewrite_url_(url) {
|
||||||
// If undefined, just return it
|
// If undefined, just return it
|
||||||
@ -366,18 +357,11 @@ var wombat_internal = function($wbwindow) {
|
|||||||
function make_parser(href) {
|
function make_parser(href) {
|
||||||
href = extract_orig(href);
|
href = extract_orig(href);
|
||||||
|
|
||||||
if (!$wbwindow.URL) {
|
var p = $wbwindow.document.createElement("a", true);
|
||||||
var p = $wbwindow.document.createElement("a");
|
|
||||||
p.href = href;
|
p.href = href;
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (href.indexOf("//") == 0) {
|
|
||||||
href = $wbwindow.location.protocol + href;
|
|
||||||
}
|
|
||||||
return new $wbwindow.URL(href);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//============================================
|
//============================================
|
||||||
function set_loc(loc, orig_href) {
|
function set_loc(loc, orig_href) {
|
||||||
@ -422,7 +406,11 @@ var wombat_internal = function($wbwindow) {
|
|||||||
function init_loc_override(loc_obj, orig_setter, orig_getter) {
|
function init_loc_override(loc_obj, orig_setter, orig_getter) {
|
||||||
var make_get_loc_prop = function(prop) {
|
var make_get_loc_prop = function(prop) {
|
||||||
function getter() {
|
function getter() {
|
||||||
var curr_orig_href = orig_getter.call(this);
|
if (this._no_rewrite) {
|
||||||
|
return orig_getter.call(this, prop);
|
||||||
|
}
|
||||||
|
|
||||||
|
var curr_orig_href = orig_getter.call(this, "href");
|
||||||
|
|
||||||
if (prop == "href") {
|
if (prop == "href") {
|
||||||
return extract_orig(curr_orig_href);
|
return extract_orig(curr_orig_href);
|
||||||
@ -442,13 +430,23 @@ var wombat_internal = function($wbwindow) {
|
|||||||
|
|
||||||
var make_set_loc_prop = function(prop) {
|
var make_set_loc_prop = function(prop) {
|
||||||
function setter(value) {
|
function setter(value) {
|
||||||
|
if (this._no_rewrite) {
|
||||||
|
orig_setter.call(this, prop, value);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this["_" + prop] = value;
|
this["_" + prop] = value;
|
||||||
|
|
||||||
if (!this._parser) {
|
if (!this._parser) {
|
||||||
var href = orig_getter.call(this);
|
var href = orig_getter.call(this);
|
||||||
this._parser = make_parser(href);
|
this._parser = make_parser(href);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
this._parser[prop] = value;
|
this._parser[prop] = value;
|
||||||
|
} catch (e) {
|
||||||
|
console.log('Error setting ' + prop + ' = ' + value);
|
||||||
|
}
|
||||||
|
|
||||||
if (prop == "hash") {
|
if (prop == "hash") {
|
||||||
value = this._parser[prop];
|
value = this._parser[prop];
|
||||||
@ -468,15 +466,9 @@ var wombat_internal = function($wbwindow) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Object.defineProperty) {
|
if (Object.defineProperty) {
|
||||||
add_loc_prop(loc_obj, "href");
|
for (var i = 0; i < URL_PROPS.length; i++) {
|
||||||
add_loc_prop(loc_obj, "hash");
|
add_loc_prop(loc_obj, URL_PROPS[i]);
|
||||||
add_loc_prop(loc_obj, "host");
|
}
|
||||||
add_loc_prop(loc_obj, "hostname");
|
|
||||||
add_loc_prop(loc_obj, "pathname");
|
|
||||||
add_loc_prop(loc_obj, "origin");
|
|
||||||
add_loc_prop(loc_obj, "port");
|
|
||||||
add_loc_prop(loc_obj, "protocol");
|
|
||||||
add_loc_prop(loc_obj, "search");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -508,8 +500,8 @@ var wombat_internal = function($wbwindow) {
|
|||||||
|
|
||||||
this.reload = orig_loc.reload;
|
this.reload = orig_loc.reload;
|
||||||
|
|
||||||
this.orig_getter = function() {
|
this.orig_getter = function(prop) {
|
||||||
return this._orig_loc.href;
|
return this._orig_loc[prop];
|
||||||
}
|
}
|
||||||
|
|
||||||
this.orig_setter = function(prop, value) {
|
this.orig_setter = function(prop, value) {
|
||||||
@ -1188,22 +1180,33 @@ var wombat_internal = function($wbwindow) {
|
|||||||
|
|
||||||
//override_attr($wbwindow.HTMLAnchorElement.prototype, "href");
|
//override_attr($wbwindow.HTMLAnchorElement.prototype, "href");
|
||||||
//return;
|
//return;
|
||||||
|
var anchor_orig = {}
|
||||||
|
|
||||||
var anchor_orig_getter = get_orig_getter($wbwindow.HTMLAnchorElement.prototype, "href");
|
function save_prop(prop) {
|
||||||
var anchor_orig_setter_href = get_orig_setter($wbwindow.HTMLAnchorElement.prototype, "href");
|
anchor_orig["get_" + prop] = get_orig_getter($wbwindow.HTMLAnchorElement.prototype, prop);
|
||||||
var anchor_orig_setter_hash = get_orig_setter($wbwindow.HTMLAnchorElement.prototype, "hash");
|
anchor_orig["set_" + prop] = get_orig_setter($wbwindow.HTMLAnchorElement.prototype, prop);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < URL_PROPS.length; i++) {
|
||||||
|
save_prop(URL_PROPS[i]);
|
||||||
|
}
|
||||||
|
|
||||||
var anchor_setter = function(prop, value) {
|
var anchor_setter = function(prop, value) {
|
||||||
if (prop == "href") {
|
var func = anchor_orig["set_" + prop];
|
||||||
anchor_orig_setter_href.call(this, value);
|
if (func) {
|
||||||
|
return func.call(this, value);
|
||||||
} else {
|
} else {
|
||||||
anchor_orig_setter_hash.call(this, value);
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var anchor_getter = function() {
|
var anchor_getter = function(prop) {
|
||||||
var value = anchor_orig_getter.call(this);
|
var func = anchor_orig["get_" + prop];
|
||||||
return value;
|
if (func) {
|
||||||
|
return func.call(this);
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
init_loc_override($wbwindow.HTMLAnchorElement.prototype, anchor_setter, anchor_getter);
|
init_loc_override($wbwindow.HTMLAnchorElement.prototype, anchor_setter, anchor_getter);
|
||||||
@ -1462,8 +1465,8 @@ var wombat_internal = function($wbwindow) {
|
|||||||
/*
|
/*
|
||||||
for (var i = 0; i < $wbwindow.frames.length; i++) {
|
for (var i = 0; i < $wbwindow.frames.length; i++) {
|
||||||
try {
|
try {
|
||||||
init_postmessage_override($wbwindow.frames[i]);
|
//init_postmessage_override($wbwindow.frames[i]);
|
||||||
//$wbwindow.frames[i].postMessage = postmessage_rewritten;
|
$wbwindow.frames[i].postMessage = postmessage_rewritten;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
@ -1644,9 +1647,9 @@ var wombat_internal = function($wbwindow) {
|
|||||||
win._wb_wombat = new win._WBWombat(wb_info);
|
win._wb_wombat = new win._WBWombat(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;
|
||||||
//win.document.WB_wombat_location = win.document.location;
|
//win.document.WB_wombat_location = win.document.location;
|
||||||
//win.WB_wombat_top = $wbwindow.WB_wombat_top;
|
//win._WB_wombat_top = $wbwindow.WB_wombat_top;
|
||||||
|
|
||||||
init_proto_pm_origin(win);
|
init_proto_pm_origin(win);
|
||||||
//init_postmessage_override(win);
|
//init_postmessage_override(win);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user