LinkIconCollector refactoring.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Dec 2016 18:21:30 +0000 (18:21 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Dec 2016 18:21:30 +0000 (18:21 +0000)
https://bugs.webkit.org/show_bug.cgi?id=165657

Reviewed by Dean Jackson.

No new tests (Refactor, no behavior change)

* WebCore.xcodeproj/project.pbxproj:

* html/LinkIconCollector.cpp:
(WebCore::iconSize):
(WebCore::compareIcons):
* html/LinkIconCollector.h:

* platform/LinkIcon.h: Move outside of LinkIconCollector for future expandability.

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

Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/html/LinkIconCollector.cpp
Source/WebCore/html/LinkIconCollector.h
Source/WebCore/platform/LinkIcon.h [new file with mode: 0644]

index 99da23b..2d29c86 100644 (file)
@@ -1,3 +1,21 @@
+2016-12-09  Brady Eidson  <beidson@apple.com>
+
+        LinkIconCollector refactoring.
+        https://bugs.webkit.org/show_bug.cgi?id=165657
+
+        Reviewed by Dean Jackson.
+
+        No new tests (Refactor, no behavior change)
+
+        * WebCore.xcodeproj/project.pbxproj:
+
+        * html/LinkIconCollector.cpp:
+        (WebCore::iconSize):
+        (WebCore::compareIcons):
+        * html/LinkIconCollector.h:
+
+        * platform/LinkIcon.h: Move outside of LinkIconCollector for future expandability.
+
 2016-12-09  Ryan Haddad  <ryanhaddad@apple.com>
 
         Unreviewed, rolling out r209574.
index 620c791..83cb925 100644 (file)
                514129981C6976900059E714 /* IDBRequestCompletionEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 514129961C6976150059E714 /* IDBRequestCompletionEvent.cpp */; };
                514129991C6976900059E714 /* IDBRequestCompletionEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 514129971C6976150059E714 /* IDBRequestCompletionEvent.h */; };
                5141299B1C6C16740059E714 /* JSIDBIndexCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5141299A1C6C166D0059E714 /* JSIDBIndexCustom.cpp */; };
+               5143B2631DDD15200014FAC6 /* LinkIcon.h in Headers */ = {isa = PBXBuildFile; fileRef = 5143B2621DDD14900014FAC6 /* LinkIcon.h */; settings = {ATTRIBUTES = (Private, ); }; };
                5145B1091BC48E2E00E86219 /* IDBResourceIdentifier.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5145B1071BC4890B00E86219 /* IDBResourceIdentifier.cpp */; };
                5145B10A1BC48E2E00E86219 /* IDBResourceIdentifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 5145B1081BC4890B00E86219 /* IDBResourceIdentifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
                5148453E1BB9D07E006A72ED /* IDBError.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5148453C1BB9D076006A72ED /* IDBError.cpp */; };
                514129961C6976150059E714 /* IDBRequestCompletionEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IDBRequestCompletionEvent.cpp; sourceTree = "<group>"; };
                514129971C6976150059E714 /* IDBRequestCompletionEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IDBRequestCompletionEvent.h; sourceTree = "<group>"; };
                5141299A1C6C166D0059E714 /* JSIDBIndexCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSIDBIndexCustom.cpp; sourceTree = "<group>"; };
+               5143B2621DDD14900014FAC6 /* LinkIcon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LinkIcon.h; sourceTree = "<group>"; };
                5145B1071BC4890B00E86219 /* IDBResourceIdentifier.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IDBResourceIdentifier.cpp; sourceTree = "<group>"; };
                5145B1081BC4890B00E86219 /* IDBResourceIdentifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IDBResourceIdentifier.h; sourceTree = "<group>"; };
                5148453C1BB9D076006A72ED /* IDBError.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IDBError.cpp; sourceTree = "<group>"; };
                                BCFF64900EAD15C200C1D6F7 /* LengthSize.h */,
                                A7AD2F850EC89D07008AB002 /* LinkHash.cpp */,
                                A7AD2F860EC89D07008AB002 /* LinkHash.h */,
+                               5143B2621DDD14900014FAC6 /* LinkIcon.h */,
                                C046E1AB1208A9FE00BA2CF7 /* LocalizedStrings.cpp */,
                                935207BD09BD410A00F2038D /* LocalizedStrings.h */,
                                A8239DFE09B3CF8A00B60641 /* Logging.cpp */,
                                B22279F40D00BF220071B782 /* SVGFEMergeElement.h in Headers */,
                                B22279F70D00BF220071B782 /* SVGFEMergeNodeElement.h in Headers */,
                                84224194107E78A700766A87 /* SVGFEMorphologyElement.h in Headers */,
+                               5143B2631DDD15200014FAC6 /* LinkIcon.h in Headers */,
                                B22279FA0D00BF220071B782 /* SVGFEOffsetElement.h in Headers */,
                                B22279FD0D00BF220071B782 /* SVGFEPointLightElement.h in Headers */,
                                B2227A000D00BF220071B782 /* SVGFESpecularLightingElement.h in Headers */,
index b9812b9..4d2b6e1 100644 (file)
@@ -36,7 +36,7 @@ namespace WebCore {
 
 const unsigned defaultTouchIconWidth = 60;
 
-static unsigned iconSize(const LinkIconCollector::Icon& icon)
+static unsigned iconSize(const LinkIcon& icon)
 {
     if (icon.size)
         return *icon.size;
@@ -47,7 +47,7 @@ static unsigned iconSize(const LinkIconCollector::Icon& icon)
     return 0;
 }
 
-static int compareIcons(const LinkIconCollector::Icon& a, const LinkIconCollector::Icon& b)
+static int compareIcons(const LinkIcon& a, const LinkIcon& b)
 {
     // Apple Touch icons always come first.
     if (a.type == LinkIconType::Favicon && b.type != LinkIconType::Favicon)
@@ -72,13 +72,13 @@ static int compareIcons(const LinkIconCollector::Icon& a, const LinkIconCollecto
     return 0;
 }
 
-auto LinkIconCollector::iconsOfTypes(OptionSet<LinkIconType> iconTypes) -> Vector<Icon>
+auto LinkIconCollector::iconsOfTypes(OptionSet<LinkIconType> iconTypes) -> Vector<LinkIcon>
 {
     auto* head = m_document.head();
     if (!head)
         return { };
 
-    Vector<Icon> icons;
+    Vector<LinkIcon> icons;
 
     for (auto& linkElement : childrenOfType<HTMLLinkElement>(*head)) {
         if (!linkElement.iconType())
@@ -104,7 +104,7 @@ auto LinkIconCollector::iconsOfTypes(OptionSet<LinkIconType> iconTypes) -> Vecto
                 iconSize = size;
         }
 
-        icons.append({ url, iconType, iconSize });
+        icons.append({ url, iconType, linkElement.type(), iconSize });
     }
 
     std::sort(icons.begin(), icons.end(), [](auto& a, auto& b) {
index 77c1055..43f22b8 100644 (file)
@@ -25,9 +25,8 @@
 
 #pragma once
 
-#include "URL.h"
+#include "LinkIcon.h"
 #include <wtf/OptionSet.h>
-#include <wtf/Optional.h>
 
 namespace WebCore {
 
@@ -41,14 +40,7 @@ public:
     {
     }
 
-    struct Icon {
-        URL url;
-
-        LinkIconType type;
-        std::optional<unsigned> size;
-    };
-
-    WEBCORE_EXPORT Vector<Icon> iconsOfTypes(OptionSet<LinkIconType>);
+    WEBCORE_EXPORT Vector<LinkIcon> iconsOfTypes(OptionSet<LinkIconType>);
 
 private:
     Document& m_document;
diff --git a/Source/WebCore/platform/LinkIcon.h b/Source/WebCore/platform/LinkIcon.h
new file mode 100644 (file)
index 0000000..9e67481
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "LinkIconType.h"
+#include "URL.h"
+#include <wtf/Optional.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+struct LinkIcon {
+    URL url;
+    LinkIconType type;
+    String mimeType;
+    std::optional<unsigned> size;
+};
+
+} // namespace WebCore