2 * (C) Copyright 2012 John J. Foerch
4 * Use, modification, and distribution are subject to the terms specified in the
10 function define_client_redirect (name) {
11 var transforms = Array.prototype.slice.call(arguments, 1);
12 function transform (location) {
13 for (var i = 0, n = transforms.length; i < n; ++i) {
14 if (transforms[i] instanceof RegExp) {
15 if (location instanceof Ci.nsIURI)
16 var lstr = location.spec;
19 location = transforms[i].exec(lstr);
21 location = transforms[i](location);
27 redirects[name] = transform;
30 function do_client_redirect (buffer, request, location) {
32 location = location.QueryInterface(Ci.nsIURL);
33 for (let [name, handler] in Iterator(redirects)) {
34 var redirect = handler(location);
36 var history = buffer.web_navigation.sessionHistory;
37 if (history.index > 0)
38 history.getEntryAtIndex(history.index - 1, true);
40 history.PurgeHistory(1);
41 buffer.load(redirect);
48 add_hook('content_buffer_location_change_hook', do_client_redirect);
50 conkeror.define_client_redirect = define_client_redirect;
52 provide("client-redirect");