Improve NowPlaying "title"
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 19 May 2018 04:22:03 +0000 (04:22 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 19 May 2018 04:22:03 +0000 (04:22 +0000)
https://bugs.webkit.org/show_bug.cgi?id=185680
<rdar://problem/40296700>

Reviewed by Dean Jackson.

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::mediaSessionTitle const): Use decodeHostName and
topPrivatelyControlledDomain when possible to make the host name more readable.

* platform/PublicSuffix.h:
* platform/mac/PublicSuffixMac.mm:
(WebCore::decodeHostName): Expose topPrivatelyControlledDomain method to .cpp functions.

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

Source/WebCore/ChangeLog
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/platform/PublicSuffix.h
Source/WebCore/platform/mac/PublicSuffixMac.mm

index c5e2f63..220e841 100644 (file)
@@ -1,3 +1,19 @@
+2018-05-18  Eric Carlson  <eric.carlson@apple.com>
+
+        Improve NowPlaying "title"
+        https://bugs.webkit.org/show_bug.cgi?id=185680
+        <rdar://problem/40296700>
+
+        Reviewed by Dean Jackson.
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::mediaSessionTitle const): Use decodeHostName and 
+        topPrivatelyControlledDomain when possible to make the host name more readable.
+
+        * platform/PublicSuffix.h:
+        * platform/mac/PublicSuffixMac.mm:
+        (WebCore::decodeHostName): Expose topPrivatelyControlledDomain method to .cpp functions.
+
 2018-05-18  Rob Buis  <rbuis@igalia.com>
 
         Cannot unset transition with important
index 6c6ee24..b817da2 100644 (file)
@@ -72,6 +72,7 @@
 #include "PageGroup.h"
 #include "PlatformMediaSessionManager.h"
 #include "ProgressTracker.h"
+#include "PublicSuffix.h"
 #include "RenderLayerCompositor.h"
 #include "RenderTheme.h"
 #include "RenderVideo.h"
@@ -7452,17 +7453,25 @@ String HTMLMediaElement::mediaSessionTitle() const
     if (!document().page() || document().page()->usesEphemeralSession())
         return emptyString();
 
-    if (hasAttributeWithoutSynchronization(titleAttr)) {
-        auto title = attributeWithoutSynchronization(titleAttr);
-        if (!title.isEmpty())
-            return title;
-    }
+    auto title = String(attributeWithoutSynchronization(titleAttr)).stripWhiteSpace().simplifyWhiteSpace();
+    if (!title.isEmpty())
+        return title;
 
-    auto title = document().title();
+    title = document().title().stripWhiteSpace().simplifyWhiteSpace();
     if (!title.isEmpty())
         return title;
 
-    return m_currentSrc.host();
+    title = m_currentSrc.host();
+#if ENABLE(PUBLIC_SUFFIX_LIST)
+    if (!title.isEmpty()) {
+        title = decodeHostName(title);
+        auto domain = topPrivatelyControlledDomain(title);
+        if (!domain.isEmpty())
+            title = domain;
+    }
+#endif
+
+    return title;
 }
 
 uint64_t HTMLMediaElement::mediaSessionUniqueIdentifier() const
index f7ee973..22a539a 100644 (file)
@@ -34,6 +34,7 @@ namespace WebCore {
 
 WEBCORE_EXPORT bool isPublicSuffix(const String& domain);
 WEBCORE_EXPORT String topPrivatelyControlledDomain(const String& domain);
+String decodeHostName(const String& domain);
 
 } // namespace WebCore
 
index 1a8c8f1..6736e2d 100644 (file)
@@ -60,6 +60,11 @@ String topPrivatelyControlledDomain(const String& domain)
     return String();
 }
 
+String decodeHostName(const String& domain)
+{
+    return decodeHostName(static_cast<NSString*>(domain));
+}
+
 }
 
 #endif