REGRESSION (r262994): Web Inspector is killed when context-clicking anywhere
authorddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 16 Jun 2020 20:42:13 +0000 (20:42 +0000)
committerddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 16 Jun 2020 20:42:13 +0000 (20:42 +0000)
<https://webkit.org/b/213224>
<rdar://problem/64383320>

Reviewed by Darin Adler.

Source/WebCore:

Test: TestWebKitAPI.WebCore.ContextMenuAction_IsValidEnum

The issue is that using WTF::isValidEnum() with
WTF::EnumTraits<WebCore::ContextMenuAction> didn't explicitly
list all 1000 custom tags, or any application tags (besides the
base), so the unlisted tags were marked as invalid during enum
validation.

The fix is to define a custom validation function for
WebCore::ContextMenuAction enum values.

* platform/ContextMenuItem.h:
(WTF::isValidEnum):

* platform/ContextMenuItem.cpp:
(WebCore::isValidContextMenuAction): Add.
- Validates CustomTag and ApplicationTag ranges.
* platform/ContextMenuItem.h:
(WebCore::isValidContextMenuAction): Add declaration.
(WTF::EnumTraits<WebCore::ContextMenuAction>): Delete.
(WTF::HasCustomIsValidEnum<WebCore::ContextMenuAction>): Add.
(WTF::isValidEnum): Add.
- Call WebCore::isValidContextMenuAction() to validate all enum
  values.

Source/WebKit:

* Platform/IPC/Decoder.h:
* Platform/IPC/Encoder.h:
- Include <WebCore/ContextMenuItem.h> since the definition of
  the custom WTF::isValidEnum<WebCore::ContextMenuAction>
  function is needed.
* Scripts/webkit/messages.py:
(generate_message_names_header):
- Change the third typename in the template for
  WTF::isValidEnum<IPC::MessageName>() to avoid partial template
  specialization errors from other implementations like
  WTF::isValidEnum<WebCore::ContextMenuAction>().
- Also replace hard-coded "IPC::MessageName" names with template
  values.

Tools:

* TestWebKitAPI/CMakeLists.txt:
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
- Add ContextMenuAction.cpp to build systems.
* TestWebKitAPI/Tests/WebCore/ContextMenuAction.cpp: Add.
(TestWebKitAPI::TEST):
- Add TestWebKitAPI.WebCore.ContextMenuAction_IsValidEnum.

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

Source/WebCore/ChangeLog
Source/WebCore/platform/ContextMenuItem.cpp
Source/WebCore/platform/ContextMenuItem.h
Source/WebKit/ChangeLog
Source/WebKit/Platform/IPC/Decoder.h
Source/WebKit/Platform/IPC/Encoder.h
Source/WebKit/Scripts/webkit/messages.py
Tools/ChangeLog
Tools/TestWebKitAPI/CMakeLists.txt
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebCore/ContextMenuAction.cpp [new file with mode: 0644]

index 0ca79dd..e21a3ff 100644 (file)
@@ -1,3 +1,36 @@
+2020-06-16  David Kilzer  <ddkilzer@apple.com>
+
+        REGRESSION (r262994): Web Inspector is killed when context-clicking anywhere
+        <https://webkit.org/b/213224>
+        <rdar://problem/64383320>
+
+        Reviewed by Darin Adler.
+
+        Test: TestWebKitAPI.WebCore.ContextMenuAction_IsValidEnum
+
+        The issue is that using WTF::isValidEnum() with
+        WTF::EnumTraits<WebCore::ContextMenuAction> didn't explicitly
+        list all 1000 custom tags, or any application tags (besides the
+        base), so the unlisted tags were marked as invalid during enum
+        validation.
+
+        The fix is to define a custom validation function for
+        WebCore::ContextMenuAction enum values.
+
+        * platform/ContextMenuItem.h:
+        (WTF::isValidEnum):
+
+        * platform/ContextMenuItem.cpp:
+        (WebCore::isValidContextMenuAction): Add.
+        - Validates CustomTag and ApplicationTag ranges.
+        * platform/ContextMenuItem.h:
+        (WebCore::isValidContextMenuAction): Add declaration.
+        (WTF::EnumTraits<WebCore::ContextMenuAction>): Delete.
+        (WTF::HasCustomIsValidEnum<WebCore::ContextMenuAction>): Add.
+        (WTF::isValidEnum): Add.
+        - Call WebCore::isValidContextMenuAction() to validate all enum
+          values.
+
 2020-06-16  Fujii Hironori  <Hironori.Fujii@sony.com>
 
         [CMake][Visual Studio] CSSPropertyNames.h is generated twice in WebCore.vcxproj and WebCore_CopyPrivateHeaders.vcxproj
index 2c501d0..063fe3c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2010-2020 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -129,6 +129,134 @@ bool ContextMenuItem::enabled() const
     return m_enabled;
 }
 
+bool isValidContextMenuAction(ContextMenuAction action)
+{
+    switch (action) {
+    case ContextMenuAction::ContextMenuItemTagNoAction:
+    case ContextMenuAction::ContextMenuItemTagOpenLinkInNewWindow:
+    case ContextMenuAction::ContextMenuItemTagDownloadLinkToDisk:
+    case ContextMenuAction::ContextMenuItemTagCopyLinkToClipboard:
+    case ContextMenuAction::ContextMenuItemTagOpenImageInNewWindow:
+    case ContextMenuAction::ContextMenuItemTagDownloadImageToDisk:
+    case ContextMenuAction::ContextMenuItemTagCopyImageToClipboard:
+#if PLATFORM(GTK)
+    case ContextMenuAction::ContextMenuItemTagCopyImageUrlToClipboard:
+#endif
+    case ContextMenuAction::ContextMenuItemTagOpenFrameInNewWindow:
+    case ContextMenuAction::ContextMenuItemTagCopy:
+    case ContextMenuAction::ContextMenuItemTagGoBack:
+    case ContextMenuAction::ContextMenuItemTagGoForward:
+    case ContextMenuAction::ContextMenuItemTagStop:
+    case ContextMenuAction::ContextMenuItemTagReload:
+    case ContextMenuAction::ContextMenuItemTagCut:
+    case ContextMenuAction::ContextMenuItemTagPaste:
+#if PLATFORM(GTK)
+    case ContextMenuAction::ContextMenuItemTagPasteAsPlainText:
+    case ContextMenuAction::ContextMenuItemTagDelete:
+    case ContextMenuAction::ContextMenuItemTagSelectAll:
+    case ContextMenuAction::ContextMenuItemTagInputMethods:
+    case ContextMenuAction::ContextMenuItemTagUnicode:
+    case ContextMenuAction::ContextMenuItemTagUnicodeInsertLRMMark:
+    case ContextMenuAction::ContextMenuItemTagUnicodeInsertRLMMark:
+    case ContextMenuAction::ContextMenuItemTagUnicodeInsertLREMark:
+    case ContextMenuAction::ContextMenuItemTagUnicodeInsertRLEMark:
+    case ContextMenuAction::ContextMenuItemTagUnicodeInsertLROMark:
+    case ContextMenuAction::ContextMenuItemTagUnicodeInsertRLOMark:
+    case ContextMenuAction::ContextMenuItemTagUnicodeInsertPDFMark:
+    case ContextMenuAction::ContextMenuItemTagUnicodeInsertZWSMark:
+    case ContextMenuAction::ContextMenuItemTagUnicodeInsertZWJMark:
+    case ContextMenuAction::ContextMenuItemTagUnicodeInsertZWNJMark:
+    case ContextMenuAction::ContextMenuItemTagInsertEmoji:
+#endif
+    case ContextMenuAction::ContextMenuItemTagSpellingGuess:
+    case ContextMenuAction::ContextMenuItemTagNoGuessesFound:
+    case ContextMenuAction::ContextMenuItemTagIgnoreSpelling:
+    case ContextMenuAction::ContextMenuItemTagLearnSpelling:
+    case ContextMenuAction::ContextMenuItemTagOther:
+    case ContextMenuAction::ContextMenuItemTagSearchInSpotlight:
+    case ContextMenuAction::ContextMenuItemTagSearchWeb:
+    case ContextMenuAction::ContextMenuItemTagLookUpInDictionary:
+    case ContextMenuAction::ContextMenuItemTagOpenWithDefaultApplication:
+    case ContextMenuAction::ContextMenuItemPDFActualSize:
+    case ContextMenuAction::ContextMenuItemPDFZoomIn:
+    case ContextMenuAction::ContextMenuItemPDFZoomOut:
+    case ContextMenuAction::ContextMenuItemPDFAutoSize:
+    case ContextMenuAction::ContextMenuItemPDFSinglePage:
+    case ContextMenuAction::ContextMenuItemPDFFacingPages:
+    case ContextMenuAction::ContextMenuItemPDFContinuous:
+    case ContextMenuAction::ContextMenuItemPDFNextPage:
+    case ContextMenuAction::ContextMenuItemPDFPreviousPage:
+    case ContextMenuAction::ContextMenuItemTagOpenLink:
+    case ContextMenuAction::ContextMenuItemTagIgnoreGrammar:
+    case ContextMenuAction::ContextMenuItemTagSpellingMenu:
+    case ContextMenuAction::ContextMenuItemTagShowSpellingPanel:
+    case ContextMenuAction::ContextMenuItemTagCheckSpelling:
+    case ContextMenuAction::ContextMenuItemTagCheckSpellingWhileTyping:
+    case ContextMenuAction::ContextMenuItemTagCheckGrammarWithSpelling:
+    case ContextMenuAction::ContextMenuItemTagFontMenu:
+    case ContextMenuAction::ContextMenuItemTagShowFonts:
+    case ContextMenuAction::ContextMenuItemTagBold:
+    case ContextMenuAction::ContextMenuItemTagItalic:
+    case ContextMenuAction::ContextMenuItemTagUnderline:
+    case ContextMenuAction::ContextMenuItemTagOutline:
+    case ContextMenuAction::ContextMenuItemTagStyles:
+    case ContextMenuAction::ContextMenuItemTagShowColors:
+    case ContextMenuAction::ContextMenuItemTagSpeechMenu:
+    case ContextMenuAction::ContextMenuItemTagStartSpeaking:
+    case ContextMenuAction::ContextMenuItemTagStopSpeaking:
+    case ContextMenuAction::ContextMenuItemTagWritingDirectionMenu:
+    case ContextMenuAction::ContextMenuItemTagDefaultDirection:
+    case ContextMenuAction::ContextMenuItemTagLeftToRight:
+    case ContextMenuAction::ContextMenuItemTagRightToLeft:
+    case ContextMenuAction::ContextMenuItemTagPDFSinglePageScrolling:
+    case ContextMenuAction::ContextMenuItemTagPDFFacingPagesScrolling:
+    case ContextMenuAction::ContextMenuItemTagInspectElement:
+    case ContextMenuAction::ContextMenuItemTagTextDirectionMenu:
+    case ContextMenuAction::ContextMenuItemTagTextDirectionDefault:
+    case ContextMenuAction::ContextMenuItemTagTextDirectionLeftToRight:
+    case ContextMenuAction::ContextMenuItemTagTextDirectionRightToLeft:
+#if PLATFORM(COCOA)
+    case ContextMenuAction::ContextMenuItemTagCorrectSpellingAutomatically:
+    case ContextMenuAction::ContextMenuItemTagSubstitutionsMenu:
+    case ContextMenuAction::ContextMenuItemTagShowSubstitutions:
+    case ContextMenuAction::ContextMenuItemTagSmartCopyPaste:
+    case ContextMenuAction::ContextMenuItemTagSmartQuotes:
+    case ContextMenuAction::ContextMenuItemTagSmartDashes:
+    case ContextMenuAction::ContextMenuItemTagSmartLinks:
+    case ContextMenuAction::ContextMenuItemTagTextReplacement:
+    case ContextMenuAction::ContextMenuItemTagTransformationsMenu:
+    case ContextMenuAction::ContextMenuItemTagMakeUpperCase:
+    case ContextMenuAction::ContextMenuItemTagMakeLowerCase:
+    case ContextMenuAction::ContextMenuItemTagCapitalize:
+    case ContextMenuAction::ContextMenuItemTagChangeBack:
+#endif
+    case ContextMenuAction::ContextMenuItemTagOpenMediaInNewWindow:
+    case ContextMenuAction::ContextMenuItemTagDownloadMediaToDisk:
+    case ContextMenuAction::ContextMenuItemTagCopyMediaLinkToClipboard:
+    case ContextMenuAction::ContextMenuItemTagToggleMediaControls:
+    case ContextMenuAction::ContextMenuItemTagToggleMediaLoop:
+    case ContextMenuAction::ContextMenuItemTagEnterVideoFullscreen:
+    case ContextMenuAction::ContextMenuItemTagMediaPlayPause:
+    case ContextMenuAction::ContextMenuItemTagMediaMute:
+    case ContextMenuAction::ContextMenuItemTagDictationAlternative:
+    case ContextMenuAction::ContextMenuItemTagToggleVideoFullscreen:
+    case ContextMenuAction::ContextMenuItemTagShareMenu:
+    case ContextMenuAction::ContextMenuItemTagToggleVideoEnhancedFullscreen:
+    case ContextMenuAction::ContextMenuItemBaseCustomTag:
+    case ContextMenuAction::ContextMenuItemLastCustomTag:
+    case ContextMenuAction::ContextMenuItemBaseApplicationTag:
+        return true;
+    }
+
+    if (action > ContextMenuAction::ContextMenuItemBaseCustomTag && action < ContextMenuAction::ContextMenuItemLastCustomTag)
+        return true;
+
+    if (action > ContextMenuAction::ContextMenuItemBaseApplicationTag)
+        return true;
+
+    return false;
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(CONTEXT_MENUS)
index 424fe6b..cbbcb08 100644 (file)
@@ -197,127 +197,20 @@ private:
     Vector<ContextMenuItem> m_subMenuItems;
 };
 
+WEBCORE_EXPORT bool isValidContextMenuAction(ContextMenuAction);
+
 } // namespace WebCore
 
 namespace WTF {
 
-template<> struct EnumTraits<WebCore::ContextMenuAction> {
-    using values = EnumValues<
-        WebCore::ContextMenuAction,
-        WebCore::ContextMenuAction::ContextMenuItemTagNoAction,
-        WebCore::ContextMenuAction::ContextMenuItemTagOpenLinkInNewWindow,
-        WebCore::ContextMenuAction::ContextMenuItemTagDownloadLinkToDisk,
-        WebCore::ContextMenuAction::ContextMenuItemTagCopyLinkToClipboard,
-        WebCore::ContextMenuAction::ContextMenuItemTagOpenImageInNewWindow,
-        WebCore::ContextMenuAction::ContextMenuItemTagDownloadImageToDisk,
-        WebCore::ContextMenuAction::ContextMenuItemTagCopyImageToClipboard,
-#if PLATFORM(GTK)
-        WebCore::ContextMenuAction::ContextMenuItemTagCopyImageUrlToClipboard,
-#endif
-        WebCore::ContextMenuAction::ContextMenuItemTagOpenFrameInNewWindow,
-        WebCore::ContextMenuAction::ContextMenuItemTagCopy,
-        WebCore::ContextMenuAction::ContextMenuItemTagGoBack,
-        WebCore::ContextMenuAction::ContextMenuItemTagGoForward,
-        WebCore::ContextMenuAction::ContextMenuItemTagStop,
-        WebCore::ContextMenuAction::ContextMenuItemTagReload,
-        WebCore::ContextMenuAction::ContextMenuItemTagCut,
-        WebCore::ContextMenuAction::ContextMenuItemTagPaste,
-#if PLATFORM(GTK)
-        WebCore::ContextMenuAction::ContextMenuItemTagPasteAsPlainText,
-        WebCore::ContextMenuAction::ContextMenuItemTagDelete,
-        WebCore::ContextMenuAction::ContextMenuItemTagSelectAll,
-        WebCore::ContextMenuAction::ContextMenuItemTagInputMethods,
-        WebCore::ContextMenuAction::ContextMenuItemTagUnicode,
-        WebCore::ContextMenuAction::ContextMenuItemTagUnicodeInsertLRMMark,
-        WebCore::ContextMenuAction::ContextMenuItemTagUnicodeInsertRLMMark,
-        WebCore::ContextMenuAction::ContextMenuItemTagUnicodeInsertLREMark,
-        WebCore::ContextMenuAction::ContextMenuItemTagUnicodeInsertRLEMark,
-        WebCore::ContextMenuAction::ContextMenuItemTagUnicodeInsertLROMark,
-        WebCore::ContextMenuAction::ContextMenuItemTagUnicodeInsertRLOMark,
-        WebCore::ContextMenuAction::ContextMenuItemTagUnicodeInsertPDFMark,
-        WebCore::ContextMenuAction::ContextMenuItemTagUnicodeInsertZWSMark,
-        WebCore::ContextMenuAction::ContextMenuItemTagUnicodeInsertZWJMark,
-        WebCore::ContextMenuAction::ContextMenuItemTagUnicodeInsertZWNJMark,
-        WebCore::ContextMenuAction::ContextMenuItemTagInsertEmoji,
-#endif
-        WebCore::ContextMenuAction::ContextMenuItemTagSpellingGuess,
-        WebCore::ContextMenuAction::ContextMenuItemTagNoGuessesFound,
-        WebCore::ContextMenuAction::ContextMenuItemTagIgnoreSpelling,
-        WebCore::ContextMenuAction::ContextMenuItemTagLearnSpelling,
-        WebCore::ContextMenuAction::ContextMenuItemTagOther,
-        WebCore::ContextMenuAction::ContextMenuItemTagSearchInSpotlight,
-        WebCore::ContextMenuAction::ContextMenuItemTagSearchWeb,
-        WebCore::ContextMenuAction::ContextMenuItemTagLookUpInDictionary,
-        WebCore::ContextMenuAction::ContextMenuItemTagOpenWithDefaultApplication,
-        WebCore::ContextMenuAction::ContextMenuItemPDFActualSize,
-        WebCore::ContextMenuAction::ContextMenuItemPDFZoomIn,
-        WebCore::ContextMenuAction::ContextMenuItemPDFZoomOut,
-        WebCore::ContextMenuAction::ContextMenuItemPDFAutoSize,
-        WebCore::ContextMenuAction::ContextMenuItemPDFSinglePage,
-        WebCore::ContextMenuAction::ContextMenuItemPDFFacingPages,
-        WebCore::ContextMenuAction::ContextMenuItemPDFContinuous,
-        WebCore::ContextMenuAction::ContextMenuItemPDFNextPage,
-        WebCore::ContextMenuAction::ContextMenuItemPDFPreviousPage,
-        WebCore::ContextMenuAction::ContextMenuItemTagOpenLink,
-        WebCore::ContextMenuAction::ContextMenuItemTagIgnoreGrammar,
-        WebCore::ContextMenuAction::ContextMenuItemTagSpellingMenu,
-        WebCore::ContextMenuAction::ContextMenuItemTagShowSpellingPanel,
-        WebCore::ContextMenuAction::ContextMenuItemTagCheckSpelling,
-        WebCore::ContextMenuAction::ContextMenuItemTagCheckSpellingWhileTyping,
-        WebCore::ContextMenuAction::ContextMenuItemTagCheckGrammarWithSpelling,
-        WebCore::ContextMenuAction::ContextMenuItemTagFontMenu,
-        WebCore::ContextMenuAction::ContextMenuItemTagShowFonts,
-        WebCore::ContextMenuAction::ContextMenuItemTagBold,
-        WebCore::ContextMenuAction::ContextMenuItemTagItalic,
-        WebCore::ContextMenuAction::ContextMenuItemTagUnderline,
-        WebCore::ContextMenuAction::ContextMenuItemTagOutline,
-        WebCore::ContextMenuAction::ContextMenuItemTagStyles,
-        WebCore::ContextMenuAction::ContextMenuItemTagShowColors,
-        WebCore::ContextMenuAction::ContextMenuItemTagSpeechMenu,
-        WebCore::ContextMenuAction::ContextMenuItemTagStartSpeaking,
-        WebCore::ContextMenuAction::ContextMenuItemTagStopSpeaking,
-        WebCore::ContextMenuAction::ContextMenuItemTagWritingDirectionMenu,
-        WebCore::ContextMenuAction::ContextMenuItemTagDefaultDirection,
-        WebCore::ContextMenuAction::ContextMenuItemTagLeftToRight,
-        WebCore::ContextMenuAction::ContextMenuItemTagRightToLeft,
-        WebCore::ContextMenuAction::ContextMenuItemTagPDFSinglePageScrolling,
-        WebCore::ContextMenuAction::ContextMenuItemTagPDFFacingPagesScrolling,
-        WebCore::ContextMenuAction::ContextMenuItemTagInspectElement,
-        WebCore::ContextMenuAction::ContextMenuItemTagTextDirectionMenu,
-        WebCore::ContextMenuAction::ContextMenuItemTagTextDirectionDefault,
-        WebCore::ContextMenuAction::ContextMenuItemTagTextDirectionLeftToRight,
-        WebCore::ContextMenuAction::ContextMenuItemTagTextDirectionRightToLeft,
-#if PLATFORM(COCOA)
-        WebCore::ContextMenuAction::ContextMenuItemTagCorrectSpellingAutomatically,
-        WebCore::ContextMenuAction::ContextMenuItemTagSubstitutionsMenu,
-        WebCore::ContextMenuAction::ContextMenuItemTagShowSubstitutions,
-        WebCore::ContextMenuAction::ContextMenuItemTagSmartCopyPaste,
-        WebCore::ContextMenuAction::ContextMenuItemTagSmartQuotes,
-        WebCore::ContextMenuAction::ContextMenuItemTagSmartDashes,
-        WebCore::ContextMenuAction::ContextMenuItemTagSmartLinks,
-        WebCore::ContextMenuAction::ContextMenuItemTagTextReplacement,
-        WebCore::ContextMenuAction::ContextMenuItemTagTransformationsMenu,
-        WebCore::ContextMenuAction::ContextMenuItemTagMakeUpperCase,
-        WebCore::ContextMenuAction::ContextMenuItemTagMakeLowerCase,
-        WebCore::ContextMenuAction::ContextMenuItemTagCapitalize,
-        WebCore::ContextMenuAction::ContextMenuItemTagChangeBack,
-#endif
-        WebCore::ContextMenuAction::ContextMenuItemTagOpenMediaInNewWindow,
-        WebCore::ContextMenuAction::ContextMenuItemTagDownloadMediaToDisk,
-        WebCore::ContextMenuAction::ContextMenuItemTagCopyMediaLinkToClipboard,
-        WebCore::ContextMenuAction::ContextMenuItemTagToggleMediaControls,
-        WebCore::ContextMenuAction::ContextMenuItemTagToggleMediaLoop,
-        WebCore::ContextMenuAction::ContextMenuItemTagEnterVideoFullscreen,
-        WebCore::ContextMenuAction::ContextMenuItemTagMediaPlayPause,
-        WebCore::ContextMenuAction::ContextMenuItemTagMediaMute,
-        WebCore::ContextMenuAction::ContextMenuItemTagDictationAlternative,
-        WebCore::ContextMenuAction::ContextMenuItemTagToggleVideoFullscreen,
-        WebCore::ContextMenuAction::ContextMenuItemTagShareMenu,
-        WebCore::ContextMenuAction::ContextMenuItemTagToggleVideoEnhancedFullscreen,
-        WebCore::ContextMenuAction::ContextMenuItemBaseCustomTag,
-        WebCore::ContextMenuAction::ContextMenuItemLastCustomTag,
-        WebCore::ContextMenuAction::ContextMenuItemBaseApplicationTag
-    >;
+template<>
+class HasCustomIsValidEnum<WebCore::ContextMenuAction> : public std::true_type { };
+
+template<typename E, typename T, std::enable_if_t<std::is_same_v<E, WebCore::ContextMenuAction>>* = nullptr>
+bool isValidEnum(T action)
+{
+    static_assert(sizeof(T) == sizeof(E), "isValidEnum<WebCore::ContextMenuAction> should only be called with 32-bit types");
+    return WebCore::isValidContextMenuAction(static_cast<E>(action));
 };
 
 template<> struct EnumTraits<WebCore::ContextMenuItemType> {
index 47394eb..cd655c7 100644 (file)
@@ -1,3 +1,25 @@
+2020-06-16  David Kilzer  <ddkilzer@apple.com>
+
+        REGRESSION (r262994): Web Inspector is killed when context-clicking anywhere
+        <https://webkit.org/b/213224>
+        <rdar://problem/64383320>
+
+        Reviewed by Darin Adler.
+
+        * Platform/IPC/Decoder.h:
+        * Platform/IPC/Encoder.h:
+        - Include <WebCore/ContextMenuItem.h> since the definition of
+          the custom WTF::isValidEnum<WebCore::ContextMenuAction>
+          function is needed.
+        * Scripts/webkit/messages.py:
+        (generate_message_names_header):
+        - Change the third typename in the template for
+          WTF::isValidEnum<IPC::MessageName>() to avoid partial template
+          specialization errors from other implementations like
+          WTF::isValidEnum<WebCore::ContextMenuAction>().
+        - Also replace hard-coded "IPC::MessageName" names with template
+          values.
+
 2020-06-16  Chris Dumez  <cdumez@apple.com>
 
         Stop calling userPreferredLanguages() in the UIProcess
index 7db3d8c..4293b6b 100644 (file)
@@ -29,6 +29,7 @@
 #include "Attachment.h"
 #include "MessageNames.h"
 #include "StringReference.h"
+#include <WebCore/ContextMenuItem.h>
 #include <wtf/EnumTraits.h>
 #include <wtf/OptionSet.h>
 #include <wtf/Vector.h>
index ab7499f..de73041 100644 (file)
@@ -29,6 +29,7 @@
 #include "Attachment.h"
 #include "MessageNames.h"
 #include "StringReference.h"
+#include <WebCore/ContextMenuItem.h>
 #include <wtf/EnumTraits.h>
 #include <wtf/Vector.h>
 
index 62c508e..a5fc6cd 100644 (file)
@@ -939,11 +939,11 @@ def generate_message_names_header(receivers):
     result.append('\n')
     result.append('template<>\n')
     result.append('class HasCustomIsValidEnum<IPC::MessageName> : public std::true_type { };\n')
-    result.append('template<typename E, typename T, typename = std::enable_if_t<std::is_same<E, IPC::MessageName>::value>>\n')
+    result.append('template<typename E, typename T, std::enable_if_t<std::is_same_v<E, IPC::MessageName>>* = nullptr>\n')
     result.append('bool isValidEnum(T messageName)\n')
     result.append('{\n')
-    result.append('    static_assert(sizeof(T) == sizeof(IPC::MessageName), "isValidEnum<MessageName> should only be called with 16-bit types");\n')
-    result.append('    return IPC::isValidMessageName(static_cast<IPC::MessageName>(messageName));\n')
+    result.append('    static_assert(sizeof(T) == sizeof(E), "isValidEnum<IPC::MessageName> should only be called with 16-bit types");\n')
+    result.append('    return IPC::isValidMessageName(static_cast<E>(messageName));\n')
     result.append('};\n')
     result.append('\n')
     result.append('} // namespace WTF\n')
index fa8a74c..3ce23d5 100644 (file)
@@ -1,3 +1,18 @@
+2020-06-16  David Kilzer  <ddkilzer@apple.com>
+
+        REGRESSION (r262994): Web Inspector is killed when context-clicking anywhere
+        <https://webkit.org/b/213224>
+        <rdar://problem/64383320>
+
+        Reviewed by Darin Adler.
+
+        * TestWebKitAPI/CMakeLists.txt:
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        - Add ContextMenuAction.cpp to build systems.
+        * TestWebKitAPI/Tests/WebCore/ContextMenuAction.cpp: Add.
+        (TestWebKitAPI::TEST):
+        - Add TestWebKitAPI.WebCore.ContextMenuAction_IsValidEnum.
+
 2020-06-16  Fujii Hironori  <Hironori.Fujii@sony.com>
 
         [Win] Mouse dragging tests are failing because WebKitTestRunner dispatches WM_MOUSELEAVE to the hidden WebView
index a8a52a0..3602b0b 100644 (file)
@@ -130,8 +130,9 @@ if (ENABLE_WEBCORE)
         Tests/WebCore/AffineTransform.cpp
         Tests/WebCore/CSSParser.cpp
         Tests/WebCore/CalculationValue.cpp
-        Tests/WebCore/ComplexTextController.cpp
         Tests/WebCore/ColorTests.cpp
+        Tests/WebCore/ComplexTextController.cpp
+        Tests/WebCore/ContextMenuAction.cpp
         Tests/WebCore/ExtendedColorTests.cpp
         Tests/WebCore/FileMonitor.cpp
         Tests/WebCore/FloatPointTests.cpp
index 57a2026..78b541c 100644 (file)
                44817A2F1F0486BF00003810 /* WKRequestActivatedElementInfo.mm in Sources */ = {isa = PBXBuildFile; fileRef = 44817A2E1F0486BF00003810 /* WKRequestActivatedElementInfo.mm */; };
                448D7E471EA6C55500ECC756 /* EnvironmentUtilitiesTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 448D7E451EA6C55500ECC756 /* EnvironmentUtilitiesTest.cpp */; };
                44AC8BC621D0245A00CAFB34 /* RetainPtr.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC029B161486AD6400817DA9 /* RetainPtr.cpp */; };
+               44CF31FD249941E8009CB6CB /* ContextMenuAction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 44CF31FB24993F66009CB6CB /* ContextMenuAction.cpp */; };
                4612C2B9210A6ACE00B788A6 /* LoadFileThenReload.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4612C2B8210A6ABF00B788A6 /* LoadFileThenReload.mm */; };
                4628C8E92367ABD100B073F0 /* WKSecurityOrigin.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4628C8E82367ABBC00B073F0 /* WKSecurityOrigin.cpp */; };
                46397B951DC2C850009A78AE /* DOMNode.mm in Sources */ = {isa = PBXBuildFile; fileRef = 46397B941DC2C850009A78AE /* DOMNode.mm */; };
                44817A2E1F0486BF00003810 /* WKRequestActivatedElementInfo.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKRequestActivatedElementInfo.mm; sourceTree = "<group>"; };
                448D7E451EA6C55500ECC756 /* EnvironmentUtilitiesTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EnvironmentUtilitiesTest.cpp; sourceTree = "<group>"; };
                44A622C114A0E2B60048515B /* WTFStringUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WTFStringUtilities.h; sourceTree = "<group>"; };
+               44CF31FB24993F66009CB6CB /* ContextMenuAction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ContextMenuAction.cpp; sourceTree = "<group>"; };
                4612C2B8210A6ABF00B788A6 /* LoadFileThenReload.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LoadFileThenReload.mm; sourceTree = "<group>"; };
                4628C8E82367ABBC00B073F0 /* WKSecurityOrigin.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKSecurityOrigin.cpp; sourceTree = "<group>"; };
                46397B941DC2C850009A78AE /* DOMNode.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DOMNode.mm; sourceTree = "<group>"; };
                                7C3965051CDD74F90094DBB8 /* ColorTests.cpp */,
                                1C9EB8401E380DA1005C6442 /* ComplexTextController.cpp */,
                                7CB184C41AA3F2100066EDFD /* ContentExtensions.cpp */,
+                               44CF31FB24993F66009CB6CB /* ContextMenuAction.cpp */,
                                CD5451E919E41F9D0016936F /* CSSParser.cpp */,
                                5758597E23A2527A00C74572 /* CtapPinTest.cpp */,
                                5758597D23A2527A00C74572 /* CtapPinTest.h */,
                                A1146A8D1D2D7115000FE710 /* ContentFiltering.mm in Sources */,
                                A14FC5881B8991BF00D107EB /* ContentFiltering.mm in Sources */,
                                5CA1DED91F74A91A00E71BD3 /* ContentRuleListNotification.mm in Sources */,
+                               44CF31FD249941E8009CB6CB /* ContextMenuAction.cpp in Sources */,
                                7CCE7EB81A411A7E00447C4C /* ContextMenuCanCopyURL.mm in Sources */,
                                37FB72971DB2E82F00E41BE4 /* ContextMenuDefaultItemsHaveTags.mm in Sources */,
                                8349D3C21DB96DDE004A9F65 /* ContextMenuDownload.mm in Sources */,
diff --git a/Tools/TestWebKitAPI/Tests/WebCore/ContextMenuAction.cpp b/Tools/TestWebKitAPI/Tests/WebCore/ContextMenuAction.cpp
new file mode 100644 (file)
index 0000000..e79e489
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2016-2020 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.
+ */
+
+#include "config.h"
+
+#include <WebCore/ContextMenuItem.h>
+
+#if ENABLE(CONTEXT_MENUS)
+
+namespace TestWebKitAPI {
+
+TEST(WebCore, ContextMenuAction_IsValidEnum)
+{
+    EXPECT_FALSE(WTF::isValidEnum<WebCore::ContextMenuAction>(WebCore::ContextMenuAction::ContextMenuItemTagNoAction - 1));
+    EXPECT_TRUE(WTF::isValidEnum<WebCore::ContextMenuAction>(WebCore::ContextMenuAction::ContextMenuItemTagNoAction));
+    EXPECT_TRUE(WTF::isValidEnum<WebCore::ContextMenuAction>(WebCore::ContextMenuAction::ContextMenuItemTagNoAction + 1));
+
+    EXPECT_TRUE(WTF::isValidEnum<WebCore::ContextMenuAction>(WebCore::ContextMenuAction::ContextMenuItemTagToggleVideoEnhancedFullscreen - 1));
+    EXPECT_TRUE(WTF::isValidEnum<WebCore::ContextMenuAction>(WebCore::ContextMenuAction::ContextMenuItemTagToggleVideoEnhancedFullscreen));
+    EXPECT_FALSE(WTF::isValidEnum<WebCore::ContextMenuAction>(WebCore::ContextMenuAction::ContextMenuItemTagToggleVideoEnhancedFullscreen + 1));
+
+    EXPECT_FALSE(WTF::isValidEnum<WebCore::ContextMenuAction>(WebCore::ContextMenuAction::ContextMenuItemBaseCustomTag - 1));
+    EXPECT_TRUE(WTF::isValidEnum<WebCore::ContextMenuAction>(WebCore::ContextMenuAction::ContextMenuItemBaseCustomTag));
+    EXPECT_TRUE(WTF::isValidEnum<WebCore::ContextMenuAction>(WebCore::ContextMenuAction::ContextMenuItemBaseCustomTag + 1));
+    EXPECT_TRUE(WTF::isValidEnum<WebCore::ContextMenuAction>(WebCore::ContextMenuAction::ContextMenuItemLastCustomTag - 1));
+    EXPECT_TRUE(WTF::isValidEnum<WebCore::ContextMenuAction>(WebCore::ContextMenuAction::ContextMenuItemLastCustomTag));
+    EXPECT_FALSE(WTF::isValidEnum<WebCore::ContextMenuAction>(WebCore::ContextMenuAction::ContextMenuItemLastCustomTag + 1));
+
+    EXPECT_FALSE(WTF::isValidEnum<WebCore::ContextMenuAction>(WebCore::ContextMenuAction::ContextMenuItemBaseApplicationTag - 1));
+    EXPECT_TRUE(WTF::isValidEnum<WebCore::ContextMenuAction>(WebCore::ContextMenuAction::ContextMenuItemBaseApplicationTag));
+    EXPECT_TRUE(WTF::isValidEnum<WebCore::ContextMenuAction>(WebCore::ContextMenuAction::ContextMenuItemBaseApplicationTag + 1));
+    EXPECT_TRUE(WTF::isValidEnum<WebCore::ContextMenuAction>(std::numeric_limits<int>::max()));
+}
+
+} // namespace TestWebKitAPI
+
+#endif // ENABLE(CONTEXT_MENUS)