summaryrefslogtreecommitdiffstats
path: root/conkeror/.conkerorrc/content-delay.js
blob: eaf89db341513d682abbe228455e9f0da2cafee8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*global require content_buffer session_token load_spec
 * load_spec_uri_string add_hook */

/*

This script is a hack that provides delayed loading for content buffers.
The initial url of a buffer will not be loaded until that buffer is
switched to.  Precaution is taken that the buffer's display_uri_string
returns the delayed url, not about:blank, so things like tabs and sessions
will still work properly.

*/
require('session');

function content_delay (spec) {
    this.delayed_load = spec;
}

function content_delay_init (b) {
    if (b != b.window.buffers.current &&
        b instanceof content_buffer &&
        b.opener instanceof session_token)
    {
        b.load = content_delay;
        b.__defineGetter__("display_uri_string",
            function () {
                if (this.delayed_load) {
                    if (this.delayed_load instanceof load_spec)
                        return load_spec_uri_string(this.delayed_load);
                    return this.delayed_load;
                }
                if (this._display_uri)
                    return this._display_uri;
                if (this.current_uri)
                    return this.current_uri.spec;
                return "";
            });
    }
}

function content_delay_do_initial_load (b) {
    if (b.hasOwnProperty("load")) {
        delete b.load;
        if (b.hasOwnProperty("delayed_load")) {
            b.load(b.delayed_load);
            delete b.delayed_load;
        }
    }
}

add_hook("create_buffer_early_hook", content_delay_init);
add_hook("select_buffer_hook", content_delay_do_initial_load);