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 * suggest_filename_from_uri
34 * optional boolean Specifies whether to attempt to generate a filename from the URI.
37 function load_spec(x) { x.__proto__ = load_spec.prototype; return x; }
39 function is_load_spec(x) {
40 return (typeof(x) == "string") || (x instanceof load_spec);
43 function load_spec_document(x) {
47 function load_spec_title(x) {
51 return x.document.title;
55 function load_spec_mime_type(x) {
56 if (typeof(x) == "object") {
60 return x.document.contentType || "application/octet-stream";
62 return mime_type_from_uri(load_spec_uri(x));
65 function load_spec_filename(x) {
69 function load_spec_filename_extension(x) {
70 return x.filename_extension;
73 function get_web_navigation_for_frame(frame) {
74 var ifr = frame.QueryInterface(Ci.nsIInterfaceRequestor);
75 return ifr.getInterface(Ci.nsIWebNavigation);
78 function get_SHEntry_for_document(doc)
82 var frame = doc.defaultView;
83 var webNav = get_web_navigation_for_frame(frame);
84 var pageLoader = webNav.QueryInterface(Ci.nsIWebPageDescriptor);
85 var desc = pageLoader.currentDescriptor.QueryInterface(Ci.nsISHEntry);
87 } catch (e) { return null; }
90 function load_spec_set_properties_from_sh_entry(x) {
91 var sh_entry = get_SHEntry_for_document(x.document);
92 if (sh_entry != null) {
93 x.cache_key = sh_entry;
94 x.referrer = sh_entry.referrerURI;
95 x.post_data = sh_entry.postData;
99 function load_spec_referrer(x) {
103 load_spec_set_properties_from_sh_entry(x);
106 if (x.source_frame) {
107 x.referrer = x.source_frame.document.documentURIObject;
113 function load_spec_post_data(x) {
117 load_spec_set_properties_from_sh_entry(x);
123 function load_spec_cache_key(x) {
127 load_spec_set_properties_from_sh_entry(x);
133 function load_spec_source_frame(x) {
135 return x.source_frame;
137 return x.document.defaultView;
141 function load_spec_uri_string(x) {
142 if (typeof(x) == "string")
147 return x.document.documentURI;
151 function load_spec_uri(x) {
153 return x.document.documentURIObject;
154 return make_uri(load_spec_uri_string(x));
157 function load_spec_flags(x) {
158 return x.load_spec_flags;
161 function load_spec_mime_info(x) {
162 var type = load_spec_mime_type(x);
163 return mime_info_from_mime_type(type);
166 function load_spec_default_shell_command(x) {
167 var mime_type = load_spec_mime_type(x);
168 return get_external_handler_for_mime_type(mime_type);
171 /* Target can be either a content_buffer or an nsIWebNavigation */
172 function apply_load_spec(target, spec) {
173 var uri = load_spec_uri_string(spec);
174 var flags = load_spec_flags(spec);
175 var referrer = load_spec_referrer(spec);
176 var post_data = load_spec_post_data(spec);
179 flags = Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
181 if (target instanceof content_buffer) {
182 target._display_URI = uri;
183 target = target.web_navigation;
184 //buffer_description_change_hook.run(target);
186 target.loadURI(uri, flags, referrer, post_data, null /* headers */);