servo: Merge #12195 - Fix Blob URL origin when scheme is file (from izgzhen:fix-url-blob); r=Manishearth
authorZhen Zhang <izgzhen@gmail.com>
Sun, 03 Jul 2016 11:59:26 -0700
changeset 339192 832f74e40511cfa776bb9b0b8e4ce269cc2b48c8
parent 339191 a4aef7782594e9bcb2c131e5ffd84f9c05aff7f2
child 339193 8fd2dbdc95ce5aa51937164f3e37e4f6d8dfa917
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersManishearth
servo: Merge #12195 - Fix Blob URL origin when scheme is file (from izgzhen:fix-url-blob); r=Manishearth <!-- Please describe your changes on the following line: --> r? @Manishearth --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors <!-- Either: --> - [x] These changes do not require tests because it needs future integration <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: b832f2b79f8d2fd08b2e610b004591162155ce7c
servo/components/script/dom/url.rs
--- a/servo/components/script/dom/url.rs
+++ b/servo/components/script/dom/url.rs
@@ -112,17 +112,17 @@ impl URL {
     pub fn DomainToUnicode(_: GlobalRef, origin: USVString) -> USVString {
         USVString(domain_to_unicode(&origin.0))
     }
 
     // https://w3c.github.io/FileAPI/#dfn-createObjectURL
     pub fn CreateObjectURL(global: GlobalRef, blob: &Blob) -> DOMString {
         /// XXX: Second field is an unicode-serialized Origin, it is a temporary workaround
         ///      and should not be trusted. See issue https://github.com/servo/servo/issues/11722
-        let origin = global.get_url().origin().unicode_serialization();
+        let origin = URL::get_blob_origin(&global.get_url());
 
         if blob.IsClosed() {
             // Generate a dummy id
             let id = Uuid::new_v4().simple().to_string();
             return DOMString::from(URL::unicode_serialization_blob_url(&origin, &id));
         }
 
         let filemanager = global.resource_threads().sender();
@@ -191,16 +191,29 @@ impl URL {
         // Step 4
         result.push('/');
 
         // Step 5
         result.push_str(id);
 
         result
     }
+
+    // XXX: change String to FileOrigin
+    /* NOTE(izgzhen): WebKit will return things like blob:file:///XXX
+       while Chrome will return blob:null/XXX
+       This is not well-specified, and I prefer the WebKit way here
+    */
+    fn get_blob_origin(url: &Url) -> String {
+        if url.scheme() == "file" {
+            "file://".to_string()
+        } else {
+            url.origin().unicode_serialization()
+        }
+    }
 }
 
 impl URLMethods for URL {
     // https://url.spec.whatwg.org/#dom-url-hash
     fn Hash(&self) -> USVString {
         UrlHelper::Hash(&self.url.borrow())
     }