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.
20 * The request headers should be included in this stream.
23 * optional string Specifies the MIME type for the request post data.
26 * optional nsIInputStream Specifies the POST data to use to access the target.
27 * The request_mime_type property must also be set.
28 * This provides a value for post_data.
30 * mime_type optional string Specifies the MIME type of the target.
32 * title optional string Specifies a title/description text associated with the target.
34 * source_frame optional nsIDOMWindow Specifies the frame from which the link to the target was "obtained".
35 * Can provide a default value for referrer if document is not specified.
37 * filename optional string Specifies a default filename to use to save the target.
40 * optional string Specifies a default filename extension to use to save the target.
42 * suggest_filename_from_uri
43 * optional boolean Specifies whether to attempt to generate a filename from the URI.
46 function load_spec(x) { x.__proto__ = load_spec.prototype; return x; }
48 function is_load_spec(x) {
49 return (typeof(x) == "string") || (x instanceof load_spec);
52 function load_spec_document(x) {
56 function load_spec_title(x) {
60 return x.document.title;
64 function load_spec_mime_type(x) {
65 if (typeof(x) == "object") {
69 return x.document.contentType || "application/octet-stream";
71 return mime_type_from_uri(load_spec_uri(x));
74 function load_spec_filename(x) {
78 function load_spec_filename_extension(x) {
79 return x.filename_extension;
82 function get_web_navigation_for_frame(frame) {
83 var ifr = frame.QueryInterface(Ci.nsIInterfaceRequestor);
84 return ifr.getInterface(Ci.nsIWebNavigation);
87 function get_SHEntry_for_document(doc)
91 var frame = doc.defaultView;
92 var webNav = get_web_navigation_for_frame(frame);
93 var pageLoader = webNav.QueryInterface(Ci.nsIWebPageDescriptor);
94 var desc = pageLoader.currentDescriptor.QueryInterface(Ci.nsISHEntry);
96 } catch (e) { return null; }
99 function load_spec_set_properties_from_sh_entry(x) {
100 var sh_entry = get_SHEntry_for_document(x.document);
101 if (sh_entry != null) {
102 x.cache_key = sh_entry;
103 x.referrer = sh_entry.referrerURI;
104 x.post_data = sh_entry.postData;
108 function load_spec_referrer(x) {
112 load_spec_set_properties_from_sh_entry(x);
115 if (x.source_frame) {
116 x.referrer = x.source_frame.document.documentURIObject;
122 function load_spec_post_data(x) {
125 if (x.raw_post_data) {
126 let y = x.raw_post_data;
127 if (typeof(y) == "string")
128 y = string_input_stream(y);
129 x.post_data = mime_input_stream(y, [["Content-Type", x.request_mime_type]]);
133 load_spec_set_properties_from_sh_entry(x);
139 function load_spec_raw_post_data(x) {
140 return x.raw_post_data;
143 function load_spec_request_mime_type(x) {
144 return x.request_mime_type;
147 function load_spec_cache_key(x) {
151 load_spec_set_properties_from_sh_entry(x);
157 function load_spec_source_frame(x) {
159 return x.source_frame;
161 return x.document.defaultView;
165 function load_spec_uri_string(x) {
166 if (typeof(x) == "string")
170 if (x.document && x.document.defaultView)
171 return x.document.defaultView.location.href;
173 return x.document.documentURI;
177 function load_spec_uri(x) {
178 if (x.document && x.document.defaultView)
179 return x.document.defaultView.location.href;
181 return x.document.documentURIObject;
182 return make_uri(load_spec_uri_string(x));
185 function load_spec_flags(x) {
186 return x.load_spec_flags;
189 function load_spec_mime_info(x) {
190 var type = load_spec_mime_type(x);
191 return mime_info_from_mime_type(type);
194 function load_spec_default_shell_command(x) {
195 var mime_type = load_spec_mime_type(x);
196 return get_external_handler_for_mime_type(mime_type);
199 /* Target can be either a content_buffer or an nsIWebNavigation */
200 function apply_load_spec(target, spec) {
201 var uri = load_spec_uri_string(spec);
202 var flags = load_spec_flags(spec);
203 var referrer = load_spec_referrer(spec);
204 var post_data = load_spec_post_data(spec);
207 flags = Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
209 if (target instanceof content_buffer) {
210 target._display_URI = uri;
211 target = target.web_navigation;
212 //buffer_description_change_hook.run(target);
214 target.loadURI(uri, flags, referrer, post_data, null /* headers */);