Title: [274760] branches/safari-607-branch/Source/WebCore

Diff

Modified: branches/safari-607-branch/Source/WebCore/Modules/plugins/PluginReplacement.h (274759 => 274760)


--- branches/safari-607-branch/Source/WebCore/Modules/plugins/PluginReplacement.h	2021-03-22 18:34:17 UTC (rev 274759)
+++ branches/safari-607-branch/Source/WebCore/Modules/plugins/PluginReplacement.h	2021-03-22 18:38:34 UTC (rev 274760)
@@ -26,6 +26,8 @@
 #pragma once
 
 #include "RenderPtr.h"
+#include <_javascript_Core/JSCJSValue.h>
+#include <_javascript_Core/JSCJSValueInlines.h>
 #include <wtf/text/WTFString.h>
 
 namespace JSC {
@@ -45,9 +47,15 @@
 public:
     virtual ~PluginReplacement() = default;
 
-    virtual bool installReplacement(ShadowRoot&) = 0;
-    virtual JSC::JSObject* scriptObject() { return nullptr; }
+    struct InstallResult {
+        bool success;
+#if PLATFORM(COCOA)
+        JSC::JSValue scriptObject { };
+#endif
+    };
 
+    virtual InstallResult installReplacement(ShadowRoot&) = 0;
+
     virtual bool willCreateRenderer() { return false; }
     virtual RenderPtr<RenderElement> createElementRenderer(HTMLPlugInElement&, RenderStyle&&, const RenderTreePosition&) = 0;
 };

Modified: branches/safari-607-branch/Source/WebCore/Modules/plugins/QuickTimePluginReplacement.h (274759 => 274760)


--- branches/safari-607-branch/Source/WebCore/Modules/plugins/QuickTimePluginReplacement.h	2021-03-22 18:34:17 UTC (rev 274759)
+++ branches/safari-607-branch/Source/WebCore/Modules/plugins/QuickTimePluginReplacement.h	2021-03-22 18:38:34 UTC (rev 274760)
@@ -51,8 +51,7 @@
     static bool supportsURL(const URL&) { return true; }
     static bool isEnabledBySettings(const Settings&);
 
-    bool installReplacement(ShadowRoot&) final;
-    JSC::JSObject* scriptObject() final { return m_scriptObject; }
+    InstallResult installReplacement(ShadowRoot&) final;
 
     bool willCreateRenderer() final { return m_mediaElement; }
     RenderPtr<RenderElement> createElementRenderer(HTMLPlugInElement&, RenderStyle&&, const RenderTreePosition&) final;
@@ -64,7 +63,6 @@
     RefPtr<HTMLVideoElement> m_mediaElement;
     const Vector<String> m_names;
     const Vector<String> m_values;
-    JSC::JSObject* m_scriptObject { nullptr }; // FIXME: Why is it safe to have this pointer here? What keeps it alive during GC?
 };
 
 }

Modified: branches/safari-607-branch/Source/WebCore/Modules/plugins/QuickTimePluginReplacement.mm (274759 => 274760)


--- branches/safari-607-branch/Source/WebCore/Modules/plugins/QuickTimePluginReplacement.mm	2021-03-22 18:34:17 UTC (rev 274759)
+++ branches/safari-607-branch/Source/WebCore/Modules/plugins/QuickTimePluginReplacement.mm	2021-03-22 18:38:34 UTC (rev 274760)
@@ -123,10 +123,7 @@
 
 QuickTimePluginReplacement::~QuickTimePluginReplacement()
 {
-    // FIXME: Why is it useful to null out pointers in an object that is being destroyed?
     m_parentElement = nullptr;
-    m_scriptObject = nullptr;
-    m_mediaElement = nullptr;
 }
 
 RenderPtr<RenderElement> QuickTimePluginReplacement::createElementRenderer(HTMLPlugInElement& plugin, RenderStyle&& style, const RenderTreePosition& insertionPosition)
@@ -172,13 +169,13 @@
     return true;
 }
 
-bool QuickTimePluginReplacement::installReplacement(ShadowRoot& root)
+auto QuickTimePluginReplacement::installReplacement(ShadowRoot& root) -> InstallResult
 {
     if (!ensureReplacementScriptInjected())
-        return false;
+        return { false };
 
     if (!m_parentElement->document().frame())
-        return false;
+        return { false };
 
     DOMWrapperWorld& world = isolatedWorld();
     ScriptController& scriptController = m_parentElement->document().frame()->script();
@@ -191,13 +188,13 @@
     // Lookup the "createPluginReplacement" function.
     JSC::JSValue replacementFunction = globalObject->get(exec, JSC::Identifier::fromString(exec, "createPluginReplacement"));
     if (replacementFunction.isUndefinedOrNull())
-        return false;
+        return { false };
     JSC::JSObject* replacementObject = replacementFunction.toObject(exec);
     scope.assertNoException();
     JSC::CallData callData;
     JSC::CallType callType = replacementObject->methodTable(vm)->getCallData(replacementObject, callData);
     if (callType == JSC::CallType::None)
-        return false;
+        return { false };
 
     JSC::MarkedArgumentBuffer argList;
     argList.append(toJS(exec, globalObject, &root));
@@ -209,7 +206,7 @@
     JSC::JSValue replacement = call(exec, replacementObject, callType, callData, globalObject, argList);
     if (UNLIKELY(scope.exception())) {
         scope.clearException();
-        return false;
+        return { false };
     }
 
     // Get the <video> created to replace the plug-in.
@@ -220,23 +217,18 @@
     if (!m_mediaElement) {
         LOG(Plugins, "%p - Failed to find <video> element created by QuickTime plugin replacement script.", this);
         scope.clearException();
-        return false;
+        return { false };
     }
 
     // Get the scripting interface.
     value = replacement.get(exec, JSC::Identifier::fromString(exec, "scriptObject"));
-    if (!scope.exception() && !value.isUndefinedOrNull()) {
-        m_scriptObject = value.toObject(exec);
-        scope.assertNoException();
-    }
-
-    if (!m_scriptObject) {
+    if (!value.isObject()) {
         LOG(Plugins, "%p - Failed to find script object created by QuickTime plugin replacement.", this);
         scope.clearException();
-        return false;
+        return { false };
     }
 
-    return true;
+    return { true, value };
 }
 
 unsigned long long QuickTimePluginReplacement::movieSize() const

Modified: branches/safari-607-branch/Source/WebCore/Modules/plugins/YouTubePluginReplacement.cpp (274759 => 274760)


--- branches/safari-607-branch/Source/WebCore/Modules/plugins/YouTubePluginReplacement.cpp	2021-03-22 18:34:17 UTC (rev 274759)
+++ branches/safari-607-branch/Source/WebCore/Modules/plugins/YouTubePluginReplacement.cpp	2021-03-22 18:38:34 UTC (rev 274760)
@@ -77,7 +77,7 @@
     return m_embedShadowElement->createElementRenderer(WTFMove(style), insertionPosition);
 }
 
-bool YouTubePluginReplacement::installReplacement(ShadowRoot& root)
+auto YouTubePluginReplacement::installReplacement(ShadowRoot& root) -> InstallResult
 {
     m_embedShadowElement = YouTubeEmbedShadowElement::create(m_parentElement->document());
 
@@ -100,7 +100,7 @@
     iframeElement->setAttributeWithoutSynchronization(HTMLNames::scrollingAttr, AtomicString("no", AtomicString::ConstructFromLiteral));
     m_embedShadowElement->appendChild(iframeElement);
 
-    return true;
+    return { true };
 }
     
 static inline URL createYouTubeURL(const String& videoID, const String& timeID)

Modified: branches/safari-607-branch/Source/WebCore/Modules/plugins/YouTubePluginReplacement.h (274759 => 274760)


--- branches/safari-607-branch/Source/WebCore/Modules/plugins/YouTubePluginReplacement.h	2021-03-22 18:34:17 UTC (rev 274759)
+++ branches/safari-607-branch/Source/WebCore/Modules/plugins/YouTubePluginReplacement.h	2021-03-22 18:38:34 UTC (rev 274760)
@@ -48,7 +48,7 @@
     static bool supportsURL(const URL&);
     static bool isEnabledBySettings(const Settings&);
 
-    bool installReplacement(ShadowRoot&) final;
+    InstallResult installReplacement(ShadowRoot&) final;
 
     String youTubeURL(const String& rawURL);
 

Modified: branches/safari-607-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj (274759 => 274760)


--- branches/safari-607-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-03-22 18:34:17 UTC (rev 274759)
+++ branches/safari-607-branch/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-03-22 18:38:34 UTC (rev 274760)
@@ -2896,6 +2896,7 @@
 		9B6C41531344949000085B62 /* StringWithDirection.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B6C41521344949000085B62 /* StringWithDirection.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		9B714E211C91166900AC0E92 /* EventPath.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B714E1F1C91166900AC0E92 /* EventPath.h */; };
 		9BA273F4172206BB0097CE47 /* LogicalSelectionOffsetCaches.h in Headers */ = {isa = PBXBuildFile; fileRef = 9BA273F3172206BB0097CE47 /* LogicalSelectionOffsetCaches.h */; };
+		9BA584C226061EFF001A5C51 /* JSValueInWrappedObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 931AE3B81FB80EAE00F5EFB2 /* JSValueInWrappedObject.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		9BAAC45C21520128003D4A98 /* GCReachableRef.h in Headers */ = {isa = PBXBuildFile; fileRef = 9BAAC4562151E39E003D4A98 /* GCReachableRef.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		9BAB6C6C12550631001626D4 /* EditingStyle.h in Headers */ = {isa = PBXBuildFile; fileRef = 9BAB6C6A12550631001626D4 /* EditingStyle.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		9BAF3B2412C1A39800014BF1 /* WritingDirection.h in Headers */ = {isa = PBXBuildFile; fileRef = 9BAF3B2312C1A39800014BF1 /* WritingDirection.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -30341,6 +30342,7 @@
 				078E091917D14D1C00420AA1 /* MediaStreamTrackEvent.h in Headers */,
 				07FFDE69181AED420072D409 /* MediaStreamTrackPrivate.h in Headers */,
 				932CC0B71DFFD158004C0F9F /* MediaTrackConstraints.h in Headers */,
+				9BA584C226061EFF001A5C51 /* JSValueInWrappedObject.h in Headers */,
 				07C1C0E21BFB600100BD2256 /* MediaTrackSupportedConstraints.h in Headers */,
 				51E1BAC31BD8064E0055D81F /* MemoryBackingStoreTransaction.h in Headers */,
 				BCB16C180979C3BD00467741 /* MemoryCache.h in Headers */,

Modified: branches/safari-607-branch/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm (274759 => 274760)


--- branches/safari-607-branch/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2021-03-22 18:34:17 UTC (rev 274759)
+++ branches/safari-607-branch/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2021-03-22 18:38:34 UTC (rev 274760)
@@ -1920,6 +1920,7 @@
     }
 
     return 1 if $interface->extendedAttributes->{JSCustomMarkFunction};
+    return 1 if $interface->extendedAttributes->{Plugin};
     return 1 if $interface->extendedAttributes->{ReportExtraMemoryCost};
     return 0;
 }
@@ -4525,6 +4526,11 @@
         push(@implContent, "    ASSERT_GC_OBJECT_INHERITS(thisObject, info());\n");
         push(@implContent, "    Base::visitChildren(thisObject, visitor);\n");
         push(@implContent, "    thisObject->visitAdditionalChildren(visitor);\n") if $interface->extendedAttributes->{JSCustomMarkFunction};
+        if ($interface->extendedAttributes->{Plugin}) {
+            push(@implContent, "#if PLATFORM(COCOA)\n");
+            push(@implContent, "    thisObject->wrapped().pluginReplacementScriptObject().visit(visitor);\n");
+            push(@implContent, "#endif\n");
+        }
         if ($interface->extendedAttributes->{ReportExtraMemoryCost}) {
             push(@implContent, "    visitor.reportExtraMemoryVisited(thisObject->wrapped().memoryCost());\n");
             if ($interface->extendedAttributes->{ReportExternalMemoryCost}) {;

Modified: branches/safari-607-branch/Source/WebCore/html/HTMLPlugInElement.cpp (274759 => 274760)


--- branches/safari-607-branch/Source/WebCore/html/HTMLPlugInElement.cpp	2021-03-22 18:34:17 UTC (rev 274759)
+++ branches/safari-607-branch/Source/WebCore/html/HTMLPlugInElement.cpp	2021-03-22 18:38:34 UTC (rev 274760)
@@ -305,7 +305,14 @@
         return;
     
     root.setResetStyleInheritance(true);
-    if (m_pluginReplacement->installReplacement(root)) {
+    auto result = m_pluginReplacement->installReplacement(root);
+
+#if PLATFORM(COCOA)
+    RELEASE_ASSERT(result.success || !result.scriptObject);
+    m_pluginReplacementScriptObject = result.scriptObject;
+#endif
+
+    if (result.success) {
         setDisplayState(DisplayingPluginReplacement);
         invalidateStyleAndRenderersForSubtree();
     }
@@ -401,9 +408,14 @@
 
 JSC::JSObject* HTMLPlugInElement::scriptObjectForPluginReplacement()
 {
-    if (m_pluginReplacement)
-        return m_pluginReplacement->scriptObject();
+#if PLATFORM(COCOA)
+    JSC::JSValue value = m_pluginReplacementScriptObject;
+    if (!value)
+        return nullptr;
+    return value.getObject();
+#else
     return nullptr;
+#endif
 }
 
 bool HTMLPlugInElement::setReplacement(RenderEmbeddedObject::PluginUnavailabilityReason reason, const String& unavailabilityDescription)

Modified: branches/safari-607-branch/Source/WebCore/html/HTMLPlugInElement.h (274759 => 274760)


--- branches/safari-607-branch/Source/WebCore/html/HTMLPlugInElement.h	2021-03-22 18:34:17 UTC (rev 274759)
+++ branches/safari-607-branch/Source/WebCore/html/HTMLPlugInElement.h	2021-03-22 18:38:34 UTC (rev 274760)
@@ -24,6 +24,7 @@
 
 #include "HTMLFrameOwnerElement.h"
 #include "Image.h"
+#include "JSValueInWrappedObject.h"
 #include "RenderEmbeddedObject.h"
 
 namespace JSC {
@@ -66,6 +67,9 @@
     virtual bool isRestartedPlugin() const { return false; }
 
     JSC::JSObject* scriptObjectForPluginReplacement();
+#if PLATFORM(COCOA)
+    JSValueInWrappedObject& pluginReplacementScriptObject() { return m_pluginReplacementScriptObject; }
+#endif
 
     bool isCapturingMouseEvents() const { return m_isCapturingMouseEvents; }
     void setIsCapturingMouseEvents(bool capturing) { m_isCapturingMouseEvents = capturing; }
@@ -125,6 +129,9 @@
     RefPtr<JSC::Bindings::Instance> m_instance;
     Timer m_swapRendererTimer;
     RefPtr<PluginReplacement> m_pluginReplacement;
+#if PLATFORM(COCOA)
+    JSValueInWrappedObject m_pluginReplacementScriptObject;
+#endif
     bool m_isCapturingMouseEvents;
 
     DisplayState m_displayState;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to