Skip to content

Commit

Permalink
Have PluginDocument express its style through a stylesheet rather tha…
Browse files Browse the repository at this point in the history
…n inline style

https://bugs.webkit.org/show_bug.cgi?id=262408
rdar://116257438

Reviewed by Tim Horton and Richard Robinson.

In the plug-in document, create a `<head>` element which contains a `<style>` element,
and set the text contents of the `style` element to style which is equivalent to the
inline style attributes that the old code was using.

* Source/WebCore/html/PluginDocument.cpp:
(WebCore::PluginDocumentParser::createStyleElement):
(WebCore::PluginDocumentParser::createDocumentStructure): Deleted.
(WebCore::PluginDocumentParser::appendBytes): Deleted.
(WebCore::PluginDocument::PluginDocument): Deleted.
(WebCore::PluginDocument::createParser): Deleted.
(WebCore::PluginDocument::pluginWidget): Deleted.
(WebCore::PluginDocument::setPluginElement): Deleted.
(WebCore::PluginDocument::detachFromPluginElement): Deleted.
(WebCore::PluginDocument::cancelManualPluginLoad): Deleted.

Canonical link: https://commits.webkit.org/268684@main
  • Loading branch information
smfr committed Sep 30, 2023
1 parent 3c8f455 commit 25fb6b6
Showing 1 changed file with 32 additions and 22 deletions.
54 changes: 32 additions & 22 deletions Source/WebCore/html/PluginDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,24 @@
#include "config.h"
#include "PluginDocument.h"

#include "CSSValuePool.h"
#include "DocumentLoader.h"
#include "FrameLoader.h"
#include "HTMLBodyElement.h"
#include "HTMLEmbedElement.h"
#include "HTMLHeadElement.h"
#include "HTMLHtmlElement.h"
#include "HTMLNames.h"
#include "HTMLStyleElement.h"
#include "LocalFrame.h"
#include "LocalFrameLoaderClient.h"
#include "LocalFrameView.h"
#include "Logging.h"
#include "PluginViewBase.h"
#include "RawDataDocumentParser.h"
#include "RenderEmbeddedObject.h"
#include "StyleSheetContents.h"
#include <wtf/IsoMallocInlines.h>
#include <wtf/text/TextStream.h>

namespace WebCore {

Expand All @@ -62,19 +66,44 @@ class PluginDocumentParser final : public RawDataDocumentParser {

void appendBytes(DocumentWriter&, const uint8_t*, size_t) final;
void createDocumentStructure();
static Ref<HTMLStyleElement> createStyleElement(Document&);

WeakPtr<HTMLEmbedElement, WeakPtrImplWithEventTargetData> m_embedElement;
};

Ref<HTMLStyleElement> PluginDocumentParser::createStyleElement(Document& document)
{
auto styleElement = HTMLStyleElement::create(document);

constexpr auto styleSheetContents = R"CONTENTS(
html { width: 100%; height: 100%; }
body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
embed { width: 100%; height: 100%; }
)CONTENTS"_s;

#if PLATFORM(IOS_FAMILY)
constexpr auto bodyBackgroundColorStyle = "body { background-color: rgb(217, 224, 233) }"_s;
#else
constexpr auto bodyBackgroundColorStyle = "body { background-color: rgb(38, 38, 38) }"_s;
#endif
styleElement->setTextContent(makeString(styleSheetContents, bodyBackgroundColorStyle));
return styleElement;
}

void PluginDocumentParser::createDocumentStructure()
{
auto& document = downcast<PluginDocument>(*this->document());

LOG_WITH_STREAM(Plugins, stream << "PluginDocumentParser::createDocumentStructure() for document " << document);

auto rootElement = HTMLHtmlElement::create(document);
document.appendChild(rootElement);
rootElement->insertedByParser();
rootElement->setInlineStyleProperty(CSSPropertyHeight, 100, CSSUnitType::CSS_PERCENTAGE);
rootElement->setInlineStyleProperty(CSSPropertyWidth, 100, CSSUnitType::CSS_PERCENTAGE);

auto headElement = HTMLHeadElement::create(document);
auto styleElement = createStyleElement(document);
headElement->appendChild(styleElement);
rootElement->appendChild(headElement);

if (document.frame())
document.frame()->injectUserScripts(UserScriptInjectionTime::DocumentStart);
Expand All @@ -85,29 +114,10 @@ void PluginDocumentParser::createDocumentStructure()
#endif

auto body = HTMLBodyElement::create(document);
body->setAttributeWithoutSynchronization(marginwidthAttr, "0"_s);
body->setAttributeWithoutSynchronization(marginheightAttr, "0"_s);
#if PLATFORM(IOS_FAMILY)
constexpr auto bodyBackgroundColor = SRGBA<uint8_t> { 217, 224, 233 };
#else
constexpr auto bodyBackgroundColor = SRGBA<uint8_t> { 38, 38, 38 };
#endif

// If the plugin is a PDF, the background color is overriden in `PDFPlugin::PDFPlugin`.
body->setInlineStyleProperty(CSSPropertyBackgroundColor, CSSValuePool::singleton().createColorValue(bodyBackgroundColor));
body->setInlineStyleProperty(CSSPropertyHeight, 100, CSSUnitType::CSS_PERCENTAGE);
body->setInlineStyleProperty(CSSPropertyWidth, 100, CSSUnitType::CSS_PERCENTAGE);
body->setInlineStyleProperty(CSSPropertyOverflow, CSSValueHidden);
body->setInlineStyleProperty(CSSPropertyMargin, 0, CSSUnitType::CSS_PERCENTAGE);

rootElement->appendChild(body);

auto embedElement = HTMLEmbedElement::create(document);

m_embedElement = embedElement.get();
embedElement->setAttributeWithoutSynchronization(widthAttr, "100%"_s);
embedElement->setAttributeWithoutSynchronization(heightAttr, "100%"_s);

embedElement->setAttributeWithoutSynchronization(nameAttr, "plugin"_s);
embedElement->setAttributeWithoutSynchronization(srcAttr, AtomString { document.url().string() });

Expand Down

0 comments on commit 25fb6b6

Please sign in to comment.