Bug 1543321 - Use nsContentUtils::GetThreadSafeUTFOrigin in the URL API, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 10 Apr 2019 08:05:00 +0000
changeset 468753 1d58cd8e6457bae9de68d0470cf5236479ea7b2c
parent 468752 1cd48cfaec567b2c023a58b133aa313c1f0fa920
child 468754 4c8055acb67b68829fa037cc2127812d0f9b41a1
push id112755
push userdvarga@mozilla.com
push dateWed, 10 Apr 2019 22:06:41 +0000
treeherdermozilla-inbound@606f85641d0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1543321
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1543321 - Use nsContentUtils::GetThreadSafeUTFOrigin in the URL API, r=smaug Depends on D26862 Differential Revision: https://phabricator.services.mozilla.com/D26863
dom/url/URLWorker.cpp
--- a/dom/url/URLWorker.cpp
+++ b/dom/url/URLWorker.cpp
@@ -219,19 +219,17 @@ class ConstructorRunnable : public Worke
   }
 };
 
 class OriginGetterRunnable : public WorkerMainThreadRunnable {
  public:
   OriginGetterRunnable(WorkerPrivate* aWorkerPrivate, nsAString& aValue,
                        nsIURI* aURI)
       : WorkerMainThreadRunnable(aWorkerPrivate,
-                                 // We can have telemetry keys for each getter
-                                 // when needed.
-                                 NS_LITERAL_CSTRING("URL :: getter")),
+                                 NS_LITERAL_CSTRING("URL :: origin getter")),
         mValue(aValue),
         mURI(aURI) {
     mWorkerPrivate->AssertIsOnWorkerThread();
   }
 
   bool MainThreadRun() override {
     AssertIsOnMainThread();
     ErrorResult rv;
@@ -479,20 +477,28 @@ void URLWorker::SetHref(const nsAString&
     return;
   }
 
   SetURI(uri.forget());
   UpdateURLSearchParams();
 }
 
 void URLWorker::GetOrigin(nsAString& aOrigin, ErrorResult& aRv) const {
-  RefPtr<OriginGetterRunnable> runnable =
-      new OriginGetterRunnable(mWorkerPrivate, aOrigin, GetURI());
+  nsresult rv = nsContentUtils::GetThreadSafeUTFOrigin(GetURI(), aOrigin);
+  if (rv == NS_ERROR_UNKNOWN_PROTOCOL) {
+    RefPtr<OriginGetterRunnable> runnable =
+        new OriginGetterRunnable(mWorkerPrivate, aOrigin, GetURI());
 
-  runnable->Dispatch(aRv);
+    runnable->Dispatch(aRv);
+    return;
+  }
+
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    aOrigin.Truncate();
+  }
 }
 
 void URLWorker::SetProtocol(const nsAString& aProtocol, ErrorResult& aRv) {
   nsAString::const_iterator start, end;
   aProtocol.BeginReading(start);
   aProtocol.EndReading(end);
   nsAString::const_iterator iter(start);