Closed Bug 1454656 Opened 6 years ago Closed 6 years ago

Unify URLWorker and URLMainThread

Categories

(Core :: DOM: Workers, enhancement, P2)

58 Branch
enhancement

Tracking

()

RESOLVED FIXED
mozilla61
Tracking Status
firefox61 --- fixed

People

(Reporter: baku, Assigned: baku)

Details

Attachments

(1 file, 1 obsolete file)

URL API was split in 2 parts because nsIURI was not thread-safe. Finally, nsIURI can be touched on any thread and we can unify URL implementations.

Only 4 methods need to have custom implementations for workers and main-thread: Constructor, SetHref, SetProtocol, GetOrigin. This methods neeed to create new nsIURI objects and that must happen on the main-thread (for GetOrigin, see nsContentUtils::GetUTFOrigin() when dealing with blobURL).
Attached patch url.patch (obsolete) — Splinter Review
I had this patch in one of my local repository. I think it's nice to land it.
There is no needs to use mStdURL anymore except for GetOrigin().
And if we really want, we can check if the scheme is 'blob' and only in that scenario, jump to main-thread.
Attachment #8968525 - Flags: review?(bugs)
Priority: -- → P2
Attached patch url.patchSplinter Review
Attachment #8968525 - Attachment is obsolete: true
Attachment #8968525 - Flags: review?(bugs)
Attachment #8969174 - Flags: review?(bugs)
Component: DOM → DOM: Workers
Comment on attachment 8969174 [details] [diff] [review]
url.patch

>+void
>+URL::GetHref(nsAString& aHref) const
>+{
>+  MOZ_ASSERT(mURI);
>+
>+  aHref.Truncate();
>+
>+  nsAutoCString href;
>+  nsresult rv = mURI->GetSpec(href);
>+  if (NS_SUCCEEDED(rv)) {
>+    CopyUTF8toUTF16(href, aHref);
>+  }
>+}
Why you don't use URL_GETTER here?

>+
>+void
>+URL::GetProtocol(nsAString& aProtocol) const
>+{
>+  MOZ_ASSERT(mURI);
>+
>+  nsAutoCString protocol;
>+  if (NS_SUCCEEDED(mURI->GetScheme(protocol))) {
>+    aProtocol.Truncate();
>+  }
>+
>+  CopyASCIItoUTF16(protocol, aProtocol);
>+  aProtocol.Append(char16_t(':'));
>+}
Same here (would need to append :)
worker version of this method does truncate before calling the uri method, main thread doesn't.
In practice it doesn't probably matter which one is done.

>+++ b/dom/url/URLMainThread.cpp
>@@ -85,17 +85,18 @@ URLMainThread::Constructor(nsISupports* 
>                           nsContentUtils::GetIOService());
>   if (NS_FAILED(rv)) {
>     // No need to warn in this case. It's common to use the URL constructor
>     // to determine if a URL is valid and an exception will be propagated.
>     aRv.ThrowTypeError<MSG_INVALID_URL>(aURL);
>     return nullptr;
>   }
> 
>-  RefPtr<URLMainThread> url = new URLMainThread(aParent, uri.forget());
>+  RefPtr<URLMainThread> url = new URLMainThread(aParent);
>+  url->SetURI(uri.forget());
I don't understand this change. I don't actually understand why we need SetURI.
But fine.

>+    nsCOMPtr<nsIURI> clone;
>+    nsresult rv = NS_MutateURI(mURI)
>+                    .SetScheme(NS_ConvertUTF16toUTF8(mValue))
>+                    .Finalize(clone);
>+    if (NS_WARN_IF(NS_FAILED(rv))) {
>+      return true;
>     }
> 
>-    if (NS_WARN_IF(rv.Failed())) {
>-      rv.SuppressException();
>-      mFailed = true;
>+    nsAutoCString href;
>+    rv = clone->GetSpec(href);
>+    if (NS_WARN_IF(NS_FAILED(rv))) {
>+      return true;
>     }
> 
>+    nsCOMPtr<nsIURI> uri;
>+    rv = NS_NewURI(getter_AddRefs(uri), href);
>+    if (NS_WARN_IF(NS_FAILED(rv))) {
>+      return true;
>+    }
>+
>+    mRetval = Move(uri);
huh, our APIs are horrible.


r+, if you could use URL_GETTER consistently, or explain why it can't be used
Attachment #8969174 - Flags: review?(bugs) → review+
Pushed by amarchesini@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/b5051b2393f2
Unify URLWorker and URLMainThread, r=smaug
https://hg.mozilla.org/mozilla-central/rev/b5051b2393f2
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla61
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: