Title: [247901] trunk
Revision
247901
Author
[email protected]
Date
2019-07-29 02:07:26 -0700 (Mon, 29 Jul 2019)

Log Message

Multiple context menu actions broken for YouTube videos
https://bugs.webkit.org/show_bug.cgi?id=199999

Reviewed by Eric Carlson.

Source/WebCore:

Do not include CopyMediaLinkItem and OpenMediaInNewWindowItem to the context menu when media URL is not
downloadable or the request can't be handled.

* page/ContextMenuController.cpp:
(WebCore::ContextMenuController::populate):

Tools:

Add a test case to check copy link address, open in new window and download options are not included in the
context menu for non-downloadable media.

* TestWebKitAPI/Tests/WebKitGtk/TestContextMenu.cpp:
(writeNextChunk):
(serverCallback):
(testContextMenuLiveStream):
(beforeAll):
(afterAll):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (247900 => 247901)


--- trunk/Source/WebCore/ChangeLog	2019-07-29 04:31:04 UTC (rev 247900)
+++ trunk/Source/WebCore/ChangeLog	2019-07-29 09:07:26 UTC (rev 247901)
@@ -1,3 +1,16 @@
+2019-07-29  Carlos Garcia Campos  <[email protected]>
+
+        Multiple context menu actions broken for YouTube videos
+        https://bugs.webkit.org/show_bug.cgi?id=199999
+
+        Reviewed by Eric Carlson.
+
+        Do not include CopyMediaLinkItem and OpenMediaInNewWindowItem to the context menu when media URL is not
+        downloadable or the request can't be handled.
+
+        * page/ContextMenuController.cpp:
+        (WebCore::ContextMenuController::populate):
+
 2019-07-28  Commit Queue  <[email protected]>
 
         Unreviewed, rolling out r247886.

Modified: trunk/Source/WebCore/page/ContextMenuController.cpp (247900 => 247901)


--- trunk/Source/WebCore/page/ContextMenuController.cpp	2019-07-29 04:31:04 UTC (rev 247900)
+++ trunk/Source/WebCore/page/ContextMenuController.cpp	2019-07-29 09:07:26 UTC (rev 247901)
@@ -886,11 +886,12 @@
 #if PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)
             appendItem(ToggleVideoEnhancedFullscreen, m_contextMenu.get());
 #endif
-            appendItem(*separatorItem(), m_contextMenu.get());
-            appendItem(CopyMediaLinkItem, m_contextMenu.get());
-            appendItem(OpenMediaInNewWindowItem, m_contextMenu.get());
-            if (m_context.hitTestResult().isDownloadableMedia() && loader.client().canHandleRequest(ResourceRequest(mediaURL)))
+            if (m_context.hitTestResult().isDownloadableMedia() && loader.client().canHandleRequest(ResourceRequest(mediaURL))) {
+                appendItem(*separatorItem(), m_contextMenu.get());
+                appendItem(CopyMediaLinkItem, m_contextMenu.get());
+                appendItem(OpenMediaInNewWindowItem, m_contextMenu.get());
                 appendItem(DownloadMediaItem, m_contextMenu.get());
+            }
         }
 
         if (imageURL.isEmpty() && linkURL.isEmpty() && mediaURL.isEmpty()) {

Modified: trunk/Tools/ChangeLog (247900 => 247901)


--- trunk/Tools/ChangeLog	2019-07-29 04:31:04 UTC (rev 247900)
+++ trunk/Tools/ChangeLog	2019-07-29 09:07:26 UTC (rev 247901)
@@ -1,3 +1,20 @@
+2019-07-29  Carlos Garcia Campos  <[email protected]>
+
+        Multiple context menu actions broken for YouTube videos
+        https://bugs.webkit.org/show_bug.cgi?id=199999
+
+        Reviewed by Eric Carlson.
+
+        Add a test case to check copy link address, open in new window and download options are not included in the
+        context menu for non-downloadable media.
+
+        * TestWebKitAPI/Tests/WebKitGtk/TestContextMenu.cpp:
+        (writeNextChunk):
+        (serverCallback):
+        (testContextMenuLiveStream):
+        (beforeAll):
+        (afterAll):
+
 2019-07-28  Tim Horton  <[email protected]>
 
         Reorganize UIScriptController into platform-specific subclasses

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitGtk/TestContextMenu.cpp (247900 => 247901)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitGtk/TestContextMenu.cpp	2019-07-29 04:31:04 UTC (rev 247900)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitGtk/TestContextMenu.cpp	2019-07-29 09:07:26 UTC (rev 247901)
@@ -18,10 +18,14 @@
  */
 
 #include "config.h"
+
+#include "WebKitTestServer.h"
 #include "WebViewTest.h"
 #include <wtf/Vector.h>
 #include <wtf/glib/GRefPtr.h>
 
+static WebKitTestServer* kServer;
+
 class ContextMenuTest: public WebViewTest {
 public:
     enum ContextMenuItemStateFlags {
@@ -295,6 +299,7 @@
         LinkImage,
         Video,
         Audio,
+        VideoLive,
         Editable,
         Selection
     };
@@ -390,6 +395,18 @@
             iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_OPEN_AUDIO_IN_NEW_WINDOW, Visible | Enabled);
             iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_DOWNLOAD_AUDIO_TO_DISK, Visible | Enabled);
             break;
+        case VideoLive:
+            g_assert_false(webkit_hit_test_result_context_is_link(hitTestResult));
+            g_assert_false(webkit_hit_test_result_context_is_image(hitTestResult));
+            g_assert_true(webkit_hit_test_result_context_is_media(hitTestResult));
+            g_assert_false(webkit_hit_test_result_context_is_editable(hitTestResult));
+            g_assert_false(webkit_hit_test_result_context_is_selection(hitTestResult));
+            iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_MEDIA_PLAY, Visible | Enabled);
+            iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_MEDIA_MUTE, Visible | Enabled);
+            iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_TOGGLE_MEDIA_CONTROLS, Visible | Enabled);
+            iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_TOGGLE_MEDIA_LOOP, Visible | Enabled);
+            iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_ENTER_VIDEO_FULLSCREEN, Visible | Enabled);
+            break;
         case Editable:
             g_assert_false(webkit_hit_test_result_context_is_link(hitTestResult));
             g_assert_false(webkit_hit_test_result_context_is_image(hitTestResult));
@@ -1068,11 +1085,68 @@
     g_assert_cmpstr(test->m_node.parentName.data(), ==, "A");
 }
 
+static void writeNextChunk(SoupMessage* message)
+{
+    GUniquePtr<char> filePath(g_build_filename(Test::getResourcesDir().data(), "silence.webm", nullptr));
+    char* contents;
+    gsize contentsLength;
+    if (!g_file_get_contents(filePath.get(), &contents, &contentsLength, nullptr)) {
+        soup_message_set_status(message, SOUP_STATUS_NOT_FOUND);
+        soup_message_body_complete(message->response_body);
+        return;
+    }
+
+    soup_message_body_append(message->response_body, SOUP_MEMORY_TAKE, contents, contentsLength);
+    soup_message_body_complete(message->response_body);
+}
+
+static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer)
+{
+    if (message->method != SOUP_METHOD_GET) {
+        soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED);
+        return;
+    }
+
+    soup_message_set_status(message, SOUP_STATUS_OK);
+
+    if (g_str_equal(path, "/live-stream")) {
+        static const char* html =
+            "<html><body>"
+            " <video style='position:absolute; left:1; top:1' width='300' height='300'>"
+            "  <source src='' type='video/webm' />"
+            " </video>"
+            "</body></html>";
+        soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, html, strlen(html));
+    } else if (g_str_equal(path, "/live-stream.webm")) {
+        soup_message_headers_set_encoding(message->response_headers, SOUP_ENCODING_CHUNKED);
+        g_signal_connect(message, "wrote_headers", G_CALLBACK(writeNextChunk), nullptr);
+        g_signal_connect(message, "wrote_chunk", G_CALLBACK(writeNextChunk), nullptr);
+        return;
+    }
+
+    soup_message_body_complete(message->response_body);
+}
+
+static void testContextMenuLiveStream(ContextMenuDefaultTest* test, gconstpointer)
+{
+    test->showInWindowAndWaitUntilMapped();
+
+    test->loadURI(kServer->getURIForPath("/live-stream").data());
+    test->waitUntilLoadFinished();
+
+    test->m_expectedMenuType = ContextMenuDefaultTest::VideoLive;
+    test->showContextMenuAtPositionAndWaitUntilFinished(1, 1);
+}
+
 void beforeAll()
 {
+    kServer = new WebKitTestServer();
+    kServer->run(serverCallback);
+
     ContextMenuDefaultTest::add("WebKitWebView", "default-menu", testContextMenuDefaultMenu);
     ContextMenuDefaultTest::add("WebKitWebView", "context-menu-key", testContextMenuKey);
     ContextMenuDefaultTest::add("WebKitWebView", "popup-event-signal", testPopupEventSignal);
+    ContextMenuDefaultTest::add("WebKitWebView", "live-stream", testContextMenuLiveStream);
     ContextMenuCustomTest::add("WebKitWebView", "populate-menu", testContextMenuPopulateMenu);
     ContextMenuCustomFullTest::add("WebKitWebView", "custom-menu", testContextMenuCustomMenu);
     ContextMenuDisabledTest::add("WebKitWebView", "disable-menu", testContextMenuDisableMenu);
@@ -1084,4 +1158,5 @@
 
 void afterAll()
 {
+    delete kServer;
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to