[Mac] Spins seen in WKSetApplicationInformationItem, so it should not be called on...
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 5 Apr 2015 22:24:26 +0000 (22:24 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 5 Apr 2015 22:24:26 +0000 (22:24 +0000)
https://bugs.webkit.org/show_bug.cgi?id=143423
rdar://problem/18773785

Reviewed by Alexey Proskuryakov.

* WebProcess/cocoa/WebProcessCocoa.mm:
(WebKit::origin): Factored out this helper function from updateActivePages below, so
the function below is easier to read.
(WebKit::WebProcess::updateActivePages): Refactored to use the new origin function.
Use dispatch_async to call WKSetApplicationInformationItem without blocking.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@182366 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/cocoa/WebProcessCocoa.mm

index eadde5b6512cd791d89b69b6c4e4217e99d50e49..0bd271f62bf640886215ac002588477b65607181 100644 (file)
@@ -1,3 +1,17 @@
+2015-04-05  Darin Adler  <darin@apple.com>
+
+        [Mac] Spins seen in WKSetApplicationInformationItem, so it should not be called on the main thread
+        https://bugs.webkit.org/show_bug.cgi?id=143423
+        rdar://problem/18773785
+
+        Reviewed by Alexey Proskuryakov.
+
+        * WebProcess/cocoa/WebProcessCocoa.mm:
+        (WebKit::origin): Factored out this helper function from updateActivePages below, so
+        the function below is easier to read.
+        (WebKit::WebProcess::updateActivePages): Refactored to use the new origin function.
+        Use dispatch_async to call WKSetApplicationInformationItem without blocking.
+
 2015-04-05  Gyuyoung Kim  <gyuyoung.kim@samsung.com>
 
         Use constants of sqlite3 directly for status of SQL result in webdatabase
index 01c8aacf8a04ab053c90265018691a9f8e62510f..a65fbf9db42b527ff6c43846ae8e30355a6a4cb9 100644 (file)
@@ -267,31 +267,42 @@ void WebProcess::initializeSandbox(const ChildProcessInitializationParameters& p
 #endif
 }
 
+#if PLATFORM(MAC)
+
+static NSURL *origin(WebPage& page)
+{
+    WebFrame* mainFrame = page.mainWebFrame();
+    if (!mainFrame)
+        return nil;
+
+    URL mainFrameURL(URL(), mainFrame->url());
+    RefPtr<SecurityOrigin> mainFrameOrigin = SecurityOrigin::create(mainFrameURL);
+    String mainFrameOriginString;
+    if (!mainFrameOrigin->isUnique())
+        mainFrameOriginString = mainFrameOrigin->toRawString();
+    else
+        mainFrameOriginString = mainFrameURL.protocol() + ':'; // toRawString() is not supposed to work with unique origins, and would just return "://".
+
+    // +[NSURL URLWithString:] returns nil when its argument is malformed. It's unclear when we would have a malformed URL here,
+    // but it happens in practice according to <rdar://problem/14173389>. Leaving an assertion in to catch a reproducible case.
+    ASSERT([NSURL URLWithString:mainFrameOriginString]);
+
+    return [NSURL URLWithString:mainFrameOriginString];
+}
+
+#endif
+
 void WebProcess::updateActivePages()
 {
-#if USE(APPKIT)
+#if PLATFORM(MAC)
     RetainPtr<CFMutableArrayRef> activePageURLs = adoptCF(CFArrayCreateMutable(0, 0, &kCFTypeArrayCallBacks));
-    for (const auto& iter: m_pageMap) {
-        WebPage* page = iter.value.get();
-        WebFrame* mainFrame = page->mainWebFrame();
-        if (!mainFrame)
-            continue;
-        String mainFrameOriginString;
-        RefPtr<SecurityOrigin> mainFrameOrigin = SecurityOrigin::createFromString(mainFrame->url());
-        if (!mainFrameOrigin->isUnique())
-            mainFrameOriginString = mainFrameOrigin->toRawString();
-        else
-            mainFrameOriginString = URL(URL(), mainFrame->url()).protocol() + ':'; // toRawString() is not supposed to work with unique origins, and would just return "://".
-
-        NSURL *originAsNSURL = [NSURL URLWithString:mainFrameOriginString];
-        // +[NSURL URLWithString:] returns nil when its argument is malformed. It's unclear how we can possibly have a malformed URL here,
-        // but it happens in practice according to <rdar://problem/14173389>. Leaving an assertion in to catch a reproducible case.
-        ASSERT(originAsNSURL);
-        NSString *userVisibleOriginString = originAsNSURL ? userVisibleString(originAsNSURL) : @"(null)";
-
-        CFArrayAppendValue(activePageURLs.get(), userVisibleOriginString);
+    for (auto& page : m_pageMap.values()) {
+        if (NSURL *originAsURL = origin(*page))
+            CFArrayAppendValue(activePageURLs.get(), userVisibleString(originAsURL));
     }
-    WKSetApplicationInformationItem(CFSTR("LSActivePageUserVisibleOriginsKey"), activePageURLs.get());
+    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), [activePageURLs] {
+        WKSetApplicationInformationItem(CFSTR("LSActivePageUserVisibleOriginsKey"), activePageURLs.get());
+    });
 #endif
 }