Loading
Bug 26540: Enabling pdfjs disableRange option prevents pdfs from loading
Large pdf files download in parts via range-based requests so that users can begin reading before the entire file has finished downloading. This is implemented using XMLHttpRequests. However, since these requests are created in the chrome, they are given the System Principal and lack the correct firstPartyDomain associated with the parent window. This patch manually sets the XMLHttpRequest's originAttributes to the one provided by the real owning window cached in the RangedChromeActions object. This is done via the chrome-only setOriginAttributes method. The method is called in the xhr_onreadystatechanged() callback rather than directly after construction in getXhr() because the setOriginAttributes implementation requires the internal nsIChannel object to have been created but not used. Fortunately, the XMLHttpRequest object fires the readStateChangedEvent precisely after the channel has been created in the XmlHttpRequest's Open() method. The nsIChannel's nsILoadInfo's OriginAttributes are now overwritten with the known OriginAttributes of the parent window before anything else has had a chance to use it.