[WebIDL] Remove custom bindings for InspectorFrontendHost
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 20 Jul 2017 16:58:06 +0000 (16:58 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 20 Jul 2017 16:58:06 +0000 (16:58 +0000)
https://bugs.webkit.org/show_bug.cgi?id=174659

Patch by Sam Weinig <sam@webkit.org> on 2017-07-20
Reviewed by Chris Dumez.

* CMakeLists.txt:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSBindingsAllInOne.cpp:
* bindings/js/JSInspectorFrontendHostCustom.cpp: Removed.
Remove JSInspectorFrontendHostCustom.cpp.

* inspector/InspectorFrontendHost.cpp:
(WebCore::populateContextMenu):
(WebCore::InspectorFrontendHost::showContextMenu):
* inspector/InspectorFrontendHost.h:
* inspector/InspectorFrontendHost.idl:
Re-implement showContextMenu by using an IDL defined ContextMenuItem dictionary
and converting from that to a WebCore::ContextMenu in the implementation.

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

Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/JSBindingsAllInOne.cpp
Source/WebCore/bindings/js/JSInspectorFrontendHostCustom.cpp [deleted file]
Source/WebCore/inspector/InspectorFrontendHost.cpp
Source/WebCore/inspector/InspectorFrontendHost.h
Source/WebCore/inspector/InspectorFrontendHost.idl

index a8bf038..29b60ea 100644 (file)
@@ -1202,7 +1202,6 @@ set(WebCore_SOURCES
     bindings/js/JSIDBObjectStoreCustom.cpp
     bindings/js/JSIDBTransactionCustom.cpp
     bindings/js/JSImageDataCustom.cpp
-    bindings/js/JSInspectorFrontendHostCustom.cpp
     bindings/js/JSLazyEventListener.cpp
     bindings/js/JSLocationCustom.cpp
     bindings/js/JSMainThreadExecState.cpp
index 1cc8878..680dcda 100644 (file)
@@ -1,3 +1,24 @@
+2017-07-20  Sam Weinig  <sam@webkit.org>
+
+        [WebIDL] Remove custom bindings for InspectorFrontendHost
+        https://bugs.webkit.org/show_bug.cgi?id=174659
+
+        Reviewed by Chris Dumez.
+
+        * CMakeLists.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * bindings/js/JSBindingsAllInOne.cpp:
+        * bindings/js/JSInspectorFrontendHostCustom.cpp: Removed.
+        Remove JSInspectorFrontendHostCustom.cpp.
+
+        * inspector/InspectorFrontendHost.cpp:
+        (WebCore::populateContextMenu):
+        (WebCore::InspectorFrontendHost::showContextMenu):
+        * inspector/InspectorFrontendHost.h:
+        * inspector/InspectorFrontendHost.idl:
+        Re-implement showContextMenu by using an IDL defined ContextMenuItem dictionary
+        and converting from that to a WebCore::ContextMenu in the implementation.
+
 2017-07-20  Charlie Turner  <cturner@igalia.com>
 
         [GTK] Layout Test http/tests/media/hls/hls-progress.html is failing
index af264c1..340aee8 100644 (file)
                7A674BDC0F9EBF4E006CF099 /* PageGroupLoadDeferrer.h in Headers */ = {isa = PBXBuildFile; fileRef = 7A674BDA0F9EBF4E006CF099 /* PageGroupLoadDeferrer.h */; };
                7A74ECBA101839A600BF939E /* InspectorDOMStorageAgent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A74ECB8101839A500BF939E /* InspectorDOMStorageAgent.cpp */; };
                7A74ECBB101839A600BF939E /* InspectorDOMStorageAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = 7A74ECB9101839A600BF939E /* InspectorDOMStorageAgent.h */; };
-               7A74ECBD101839DA00BF939E /* JSInspectorFrontendHostCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A74ECBC101839DA00BF939E /* JSInspectorFrontendHostCustom.cpp */; };
                7A929CA61C598A9E004DF226 /* ResourceLoadStatistics.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A929CA11C598378004DF226 /* ResourceLoadStatistics.cpp */; };
                7A929CA71C598AA9004DF226 /* ResourceLoadStatistics.h in Headers */ = {isa = PBXBuildFile; fileRef = 7A929CA21C598378004DF226 /* ResourceLoadStatistics.h */; settings = {ATTRIBUTES = (Private, ); }; };
                7A93868518DCC14500B8263D /* VTTScanner.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A93868218DCC14500B8263D /* VTTScanner.cpp */; };
                7A7256B915EB9F5B007323A7 /* InspectorOverlayPage.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = InspectorOverlayPage.html; sourceTree = "<group>"; };
                7A74ECB8101839A500BF939E /* InspectorDOMStorageAgent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorDOMStorageAgent.cpp; sourceTree = "<group>"; };
                7A74ECB9101839A600BF939E /* InspectorDOMStorageAgent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorDOMStorageAgent.h; sourceTree = "<group>"; };
-               7A74ECBC101839DA00BF939E /* JSInspectorFrontendHostCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSInspectorFrontendHostCustom.cpp; sourceTree = "<group>"; };
                7A929CA11C598378004DF226 /* ResourceLoadStatistics.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ResourceLoadStatistics.cpp; sourceTree = "<group>"; };
                7A929CA21C598378004DF226 /* ResourceLoadStatistics.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ResourceLoadStatistics.h; sourceTree = "<group>"; };
                7A93868218DCC14500B8263D /* VTTScanner.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = VTTScanner.cpp; sourceTree = "<group>"; };
                                9392262C1032107B006E7D5D /* JSHTMLCanvasElementCustom.cpp */,
                                BC5823F40C0A98DF0053F1B5 /* JSHTMLElementCustom.cpp */,
                                D6F7960C166FFECE0076DD18 /* JSHTMLTemplateElementCustom.cpp */,
-                               7A74ECBC101839DA00BF939E /* JSInspectorFrontendHostCustom.cpp */,
                                BCE1C43F0D9830F4003B02F2 /* JSLocationCustom.cpp */,
                                410B7E711045FAB000D8224F /* JSMessageEventCustom.cpp */,
                                C6F0917E143A2BB900685849 /* JSMutationObserverCustom.cpp */,
                                A7D0318E0E93540300E24ACD /* JSImageDataCustom.cpp in Sources */,
                                A86629D409DA2B48009633A6 /* JSInputEvent.cpp in Sources */,
                                7A0E771E10C00DB100A0276E /* JSInspectorFrontendHost.cpp in Sources */,
-                               7A74ECBD101839DA00BF939E /* JSInspectorFrontendHostCustom.cpp in Sources */,
                                0F4710E51DB700C7002DCEC3 /* JSIntersectionObserver.cpp in Sources */,
                                0F8B45751DC41DBA00443C3F /* JSIntersectionObserverCallback.cpp in Sources */,
                                0F4710E71DB700C7002DCEC3 /* JSIntersectionObserverEntry.cpp in Sources */,
index 365763f..86beed6 100644 (file)
@@ -70,7 +70,6 @@
 #include "JSHTMLTemplateElementCustom.cpp"
 #include "JSHistoryCustom.cpp"
 #include "JSImageDataCustom.cpp"
-#include "JSInspectorFrontendHostCustom.cpp"
 #include "JSLazyEventListener.cpp"
 #include "JSLocationCustom.cpp"
 #include "JSMainThreadExecState.cpp"
diff --git a/Source/WebCore/bindings/js/JSInspectorFrontendHostCustom.cpp b/Source/WebCore/bindings/js/JSInspectorFrontendHostCustom.cpp
deleted file mode 100644 (file)
index 447dde6..0000000
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
- * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com>
- * Copyright (C) 2009 Google 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:
- *
- *     * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *     * 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.
- *     * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
- * OWNER OR 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 "JSInspectorFrontendHost.h"
-
-#include "ContextMenuItem.h"
-#include "InspectorController.h"
-#include "InspectorFrontendHost.h"
-#include "JSDOMBinding.h"
-#include "JSEvent.h"
-#include "MouseEvent.h"
-#include <runtime/JSArray.h>
-#include <runtime/JSLock.h>
-#include <runtime/JSObject.h>
-#include <wtf/text/WTFString.h>
-
-using namespace JSC;
-
-namespace WebCore {
-
-#if ENABLE(CONTEXT_MENUS)
-static void populateContextMenuItems(ExecState* exec, JSArray* array, ContextMenu& menu)
-{
-    VM& vm = exec->vm();
-    for (size_t i = 0; i < array->length(); ++i) {
-        JSObject* item = asObject(array->getIndex(exec, i));
-        JSValue label = item->get(exec, Identifier::fromString(exec, "label"));
-        JSValue type = item->get(exec, Identifier::fromString(exec, "type"));
-        JSValue id = item->get(exec, Identifier::fromString(exec, "id"));
-        JSValue enabled = item->get(exec, Identifier::fromString(exec, "enabled"));
-        JSValue checked = item->get(exec, Identifier::fromString(exec, "checked"));
-        JSValue subItems = item->get(exec, Identifier::fromString(exec, "subItems"));
-        if (!type.isString())
-            continue;
-
-        String typeString = asString(type)->value(exec);
-        if (typeString == "separator") {
-            ContextMenuItem item(SeparatorType, ContextMenuItemTagNoAction, String());
-            menu.appendItem(item);
-        } else if (typeString == "subMenu" && subItems.inherits(vm, JSArray::info())) {
-            ContextMenu subMenu;
-            JSArray* subItemsArray = asArray(subItems);
-            populateContextMenuItems(exec, subItemsArray, subMenu);
-            ContextMenuItem item(SubmenuType, ContextMenuItemTagNoAction, label.toWTFString(exec), &subMenu);
-            menu.appendItem(item);
-        } else {
-            ContextMenuAction typedId = static_cast<ContextMenuAction>(ContextMenuItemBaseCustomTag + id.toInt32(exec));
-            ContextMenuItem menuItem((typeString == "checkbox" ? CheckableActionType : ActionType), typedId, label.toWTFString(exec));
-            if (!enabled.isUndefined())
-                menuItem.setEnabled(enabled.toBoolean(exec));
-            if (!checked.isUndefined())
-                menuItem.setChecked(checked.toBoolean(exec));
-            menu.appendItem(menuItem);
-        }
-    }
-}
-#endif
-
-JSValue JSInspectorFrontendHost::showContextMenu(ExecState& state)
-{
-#if ENABLE(CONTEXT_MENUS)
-    if (state.argumentCount() < 2)
-        return jsUndefined();
-    VM& vm = state.vm();
-    Event* event = JSEvent::toWrapped(vm, state.argument(0));
-
-    JSArray* array = asArray(state.argument(1));
-    ContextMenu menu;
-    populateContextMenuItems(&state, array, menu);
-
-    wrapped().showContextMenu(event, menu.items());
-#else
-    UNUSED_PARAM(state);
-#endif
-    return jsUndefined();
-}
-
-} // namespace WebCore
index 41db68c..b10e85d 100644 (file)
@@ -334,8 +334,37 @@ void InspectorFrontendHost::sendMessageToBackend(const String& message)
 
 #if ENABLE(CONTEXT_MENUS)
 
-void InspectorFrontendHost::showContextMenu(Event* event, const Vector<ContextMenuItem>& items)
+static void populateContextMenu(Vector<InspectorFrontendHost::ContextMenuItem>&& items, ContextMenu& menu)
 {
+    for (auto& item : items) {
+        if (item.type == "separator") {
+            menu.appendItem({ SeparatorType, ContextMenuItemTagNoAction, { } });
+            continue;
+        }
+
+        if (item.type == "subMenu" && item.subItems) {
+            ContextMenu subMenu;
+            populateContextMenu(WTFMove(*item.subItems), subMenu);
+
+            menu.appendItem({ SubmenuType, ContextMenuItemTagNoAction, item.label, &subMenu });
+            continue;
+        }
+
+        auto type = item.type == "checkbox" ? CheckableActionType : ActionType;
+        auto action = static_cast<ContextMenuAction>(ContextMenuItemBaseCustomTag + item.id.value_or(0));
+        ContextMenuItem menuItem = { type, action, item.label };
+        if (item.enabled)
+            menuItem.setEnabled(*item.enabled);
+        if (item.checked)
+            menuItem.setChecked(*item.checked);
+        menu.appendItem(menuItem);
+    }
+}
+#endif
+
+void InspectorFrontendHost::showContextMenu(Event* event, Vector<ContextMenuItem>&& items)
+{
+#if ENABLE(CONTEXT_MENUS)
     if (!event)
         return;
 
@@ -346,12 +375,18 @@ void InspectorFrontendHost::showContextMenu(Event* event, const Vector<ContextMe
         ASSERT_NOT_REACHED();
         return;
     }
-    auto menuProvider = FrontendMenuProvider::create(this, { &state, frontendApiObject }, items);
+    
+    ContextMenu menu;
+    populateContextMenu(WTFMove(items), menu);
+
+    auto menuProvider = FrontendMenuProvider::create(this, { &state, frontendApiObject }, menu.items());
     m_menuProvider = menuProvider.ptr();
     m_frontendPage->contextMenuController().showContextMenu(*event, menuProvider);
-}
-
+#else
+    UNUSED_PARAM(event);
+    UNUSED_PARAM(items);
 #endif
+}
 
 void InspectorFrontendHost::dispatchEventAsContextMenuEvent(Event* event)
 {
index b6af405..74db9ec 100644 (file)
@@ -36,7 +36,6 @@
 
 namespace WebCore {
 
-class ContextMenuItem;
 class Event;
 class FrontendMenuProvider;
 class InspectorFrontendClient;
@@ -85,10 +84,16 @@ public:
     void append(const String& url, const String& content);
     void close(const String& url);
 
-#if ENABLE(CONTEXT_MENUS)
-    // Called from [Custom] implementations.
-    void showContextMenu(Event*, const Vector<ContextMenuItem>& items);
-#endif
+    struct ContextMenuItem {
+        String type;
+        String label;
+        std::optional<int> id;
+        std::optional<bool> enabled;
+        std::optional<bool> checked;
+        std::optional<Vector<ContextMenuItem>> subItems;
+    };
+    void showContextMenu(Event*, Vector<ContextMenuItem>&&);
+
     void sendMessageToBackend(const String& message);
     void dispatchEventAsContextMenuEvent(Event*);
 
index 0fe5feb..9b7c1b6 100644 (file)
@@ -68,7 +68,7 @@
     DOMString platform();
     DOMString port();
 
-    [Custom] void showContextMenu(MouseEvent event, any items);
+    void showContextMenu(Event? event, sequence<ContextMenuItem> items);
     void dispatchEventAsContextMenuEvent(Event? event);
     void sendMessageToBackend(DOMString message);
     void unbufferedLog(DOMString message);
 
     void beep();
 };
+
+[
+    JSGenerateToJSObject
+] dictionary ContextMenuItem {
+    DOMString type;
+    DOMString label;
+    long id;
+    boolean enabled;
+    boolean checked;
+    sequence<ContextMenuItem> subItems;
+};