3 * A load_spec has the following properties:
5 * Name: Required? Type: Description:
6 * ----- --------- ----- ------------
7 * uri required string Specifies the URI of the target.
9 * document optional nsIDOMDocument Specifies a document corresponding to the target.
10 * Can also provide a default value for the mime_type property,
11 * the title property, and the source_frame property.
13 * flags optional number Specifies flags to pass to nsIWebNavigation.loadURI
15 * cache_key optional nsISHEntry Specifies a key for accessing the target from the cache.
17 * referrer optional nsIURI Specifies the referrer URI to use to access the target.
19 * post_data optional nsIInputStream Specifies POST data to use to access the target.
21 * mime_type optional string Specifies the MIME type of the target.
23 * title optional string Specifies a title/description text associated with the target.
25 * source_frame optional nsIDOMWindow Specifies the frame from which the link to the target was "obtained".
26 * Can provide a default value for referrer if document is not specified.
28 * filename optional string Specifies a default filename to use to save the target.
31 * optional string Specifies a default filename extension to use to save the target.
33 function load_spec(x) { x.__proto__ = load_spec.prototype; return x; }
35 function is_load_spec(x) {
36 return (typeof(x) == "string") || (x instanceof load_spec);
39 function load_spec_document(x) {
43 function load_spec_title(x) {
47 return x.document.title;
51 function load_spec_mime_type(x) {
52 if (typeof(x) == "object") {
56 return x.document.contentType || "application/octet-stream";
58 return mime_type_from_uri(load_spec_uri(x));
61 function load_spec_filename(x) {
65 function load_spec_filename_extension(x) {
66 return x.filename_extension;
69 function get_web_navigation_for_frame(frame) {
70 var ifr = frame.QueryInterface(Ci.nsIInterfaceRequestor);
71 return ifr.getInterface(Ci.nsIWebNavigation);
74 function get_SHEntry_for_document(doc)
78 var frame = doc.defaultView;
79 var webNav = get_web_navigation_for_frame(frame);
80 var pageLoader = webNav.QueryInterface(Ci.nsIWebPageDescriptor);
81 var desc = pageLoader.currentDescriptor.QueryInterface(Ci.nsISHEntry);
83 } catch (e) { return null; }
86 function load_spec_set_properties_from_sh_entry(x) {
87 var sh_entry = get_SHEntry_for_document(x.document);
88 if (sh_entry != null) {
89 x.cache_key = sh_entry;
90 x.referrer = sh_entry.referrerURI;
91 x.post_data = sh_entry.postData;
95 function load_spec_referrer(x) {
99 load_spec_set_properties_from_sh_entry(x);
102 if (x.source_frame) {
103 x.referrer = x.source_frame.document.documentURIObject;
109 function load_spec_post_data(x) {
113 load_spec_set_properties_from_sh_entry(x);
119 function load_spec_cache_key(x) {
123 load_spec_set_properties_from_sh_entry(x);
129 function load_spec_source_frame(x) {
131 return x.source_frame;
133 return x.document.defaultView;
137 function load_spec_uri_string(x) {
138 if (typeof(x) == "string")
143 return x.document.documentURI;
147 function load_spec_uri(x) {
149 return x.document.documentURIObject;
150 return make_uri(load_spec_uri_string(x));
153 function load_spec_flags(x) {
154 return x.load_spec_flags;
157 function load_spec_mime_info(x) {
158 var type = load_spec_mime_type(x);
159 return mime_info_from_mime_type(type);
162 function load_spec_default_shell_command(x) {
163 var mime_type = load_spec_mime_type(x);
164 return get_external_handler_for_mime_type(mime_type);
167 /* Target can be either a content_buffer or an nsIWebNavigation */
168 function apply_load_spec(target, spec) {
169 var uri = load_spec_uri_string(spec);
170 var flags = load_spec_flags(spec);
171 var referrer = load_spec_referrer(spec);
172 var post_data = load_spec_post_data(spec);
175 flags = Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
177 if (target instanceof content_buffer) {
178 target._display_URI = uri;
179 target = target.web_navigation;
180 //buffer_description_change_hook.run(target);
182 target.loadURI(uri, flags, referrer, post_data, null /* headers */);