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 var entry = history.getEntryAtIndex(history.index, false);
38 if (history.index > 0) {
39 if (entry.URI.spec == location.spec)
40 history.getEntryAtIndex(history.index - 1, true);
41 } else if (entry.URI.spec == location.spec)
42 history.PurgeHistory(1);
43 buffer.load(redirect);
50 add_hook('content_buffer_location_change_hook', do_client_redirect);
52 conkeror.define_client_redirect = define_client_redirect;
54 provide("client-redirect");