Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(627)

Unified Diff: Source/core/html/shadow/PluginPlaceholderElement.cpp

Issue 740063002: Move creation of plugin placeholder DOM from JS to C++. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: oilpan Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/html/shadow/PluginPlaceholderElement.cpp
diff --git a/Source/core/html/shadow/PluginPlaceholderElement.cpp b/Source/core/html/shadow/PluginPlaceholderElement.cpp
index 74efd5581f3fba8c0eea153e418bf9210b437e95..f628ef58b0379742ccb6876da1c43a08c4edb8f2 100644
--- a/Source/core/html/shadow/PluginPlaceholderElement.cpp
+++ b/Source/core/html/shadow/PluginPlaceholderElement.cpp
@@ -6,33 +6,141 @@
#include "core/html/shadow/PluginPlaceholderElement.h"
#include "bindings/core/v8/V8PluginPlaceholderElement.h"
+#include "core/CSSPropertyNames.h"
+#include "core/CSSValueKeywords.h"
+#include "core/EventTypeNames.h"
#include "core/dom/Document.h"
+#include "core/events/Event.h"
+#include "core/events/EventListener.h"
+#include "core/html/HTMLStyleElement.h"
+#include "platform/heap/Visitor.h"
#include "wtf/Assertions.h"
+#include "wtf/Functional.h"
+#include "wtf/StdLibExtras.h"
+#include "wtf/text/AtomicString.h"
namespace blink {
+namespace {
+
+// FIXME: Move this into a resource and @import it.
+const char kStyleSource[] =
+ "#plugin-placeholder {"
+ " all: initial;"
+ " width: 100%;"
+ " height: 100%;"
+ " overflow: hidden;"
+ " display: flex;"
+ " align-items: center;"
+ " background: gray;"
+ " font: 12px -webkit-control;"
+ "}"
+ "#plugin-placeholder-content {"
+ " text-align: center;"
+ " margin: auto;"
+ "}";
+
+// Invokes a closure when an event occurs.
+// Take care to use a WeakPtr where necessary to avoid reference cycles.
+class SimpleEventListener : public EventListener {
+public:
+ static PassRefPtr<SimpleEventListener> create(PassOwnPtr<Closure> closure)
+ {
+ return adoptRef(new SimpleEventListener(closure));
+ }
+
+ ~SimpleEventListener() override { }
+
+private:
+ SimpleEventListener(PassOwnPtr<Closure> closure)
+ : EventListener(CPPEventListenerType)
+ , m_closure(closure)
+ {
+ }
+
+ bool operator==(const EventListener& other) override { return this == &other; }
+
+ void handleEvent(ExecutionContext*, Event*) override
+ {
+ (*m_closure)();
+ }
+
+ OwnPtr<Closure> m_closure;
+};
+
+} // namespace
PluginPlaceholderElement::PluginPlaceholderElement(Document& document)
: HTMLDivElement(document)
+ , m_weakPtrFactory(this)
{
}
-PassRefPtrWillBeRawPtr<PluginPlaceholderElement> PluginPlaceholderElement::create(Document& document)
+PluginPlaceholderElement::~PluginPlaceholderElement()
{
- RefPtrWillBeRawPtr<PluginPlaceholderElement> element = adoptRefWillBeNoop(new PluginPlaceholderElement(document));
- bool success = V8PluginPlaceholderElement::PrivateScript::createdCallbackMethod(document.frame(), element.get());
- ASSERT_UNUSED(success, success);
- return element.release();
+}
+
+void PluginPlaceholderElement::trace(Visitor* visitor)
+{
+ visitor->trace(m_messageElement);
+ visitor->trace(m_closeButton);
+ HTMLDivElement::trace(visitor);
}
void PluginPlaceholderElement::setMessage(const String& message)
{
- bool success = V8PluginPlaceholderElement::PrivateScript::messageAttributeSetter(document().frame(), this, message);
- ASSERT_UNUSED(success, success);
+ m_messageElement->setTextContent(message);
}
void PluginPlaceholderElement::setIsCloseable(bool closeable)
{
- bool success = V8PluginPlaceholderElement::PrivateScript::closeableAttributeSetter(document().frame(), this, closeable);
+ if (closeable)
+ m_closeButton->removeInlineStyleProperty(CSSPropertyDisplay);
+ else
+ m_closeButton->setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone);
+}
+
+void PluginPlaceholderElement::initialize()
+{
+ DEFINE_STATIC_LOCAL(AtomicString, elementId, ("plugin-placeholder", AtomicString::ConstructFromLiteral));
+ setIdAttribute(elementId);
+
+ RefPtrWillBeRawPtr<HTMLStyleElement> styleElement = HTMLStyleElement::create(document(), false);
+ styleElement->setTextContent(kStyleSource);
+
+ DEFINE_STATIC_LOCAL(AtomicString, contentElementId, ("plugin-placeholder-content", AtomicString::ConstructFromLiteral));
+ RefPtrWillBeRawPtr<HTMLDivElement> contentElement = HTMLDivElement::create(document());
+ contentElement->setIdAttribute(contentElementId);
+
+ DEFINE_STATIC_LOCAL(AtomicString, messageElementId, ("plugin-placeholder-message", AtomicString::ConstructFromLiteral));
+ RefPtrWillBeRawPtr<HTMLDivElement> messageElement = HTMLDivElement::create(document());
+ messageElement->setIdAttribute(messageElementId);
+
+ // FIXME: UI polish, l10n, etc. for the close button.
+ DEFINE_STATIC_LOCAL(AtomicString, closeButtonId, ("plugin-placeholder-close-button", AtomicString::ConstructFromLiteral));
+ RefPtrWillBeRawPtr<HTMLButtonElement> closeButton = HTMLButtonElement::create(document(), nullptr);
+ closeButton->setIdAttribute(closeButtonId);
+ closeButton->setTextContent("Close");
+ closeButton->setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone);
+ closeButton->addEventListener(EventTypeNames::click, createSimpleEventListener(&PluginPlaceholderElement::onCloseButtonClick));
+
+ contentElement->appendChild(messageElement);
+ contentElement->appendChild(closeButton);
+ appendChild(styleElement);
+ appendChild(contentElement);
+
+ m_messageElement = messageElement.release();
+ m_closeButton = closeButton.release();
+}
+
+PassRefPtr<EventListener> PluginPlaceholderElement::createSimpleEventListener(void(PluginPlaceholderElement::*method)())
+{
+ return SimpleEventListener::create(bind(method, m_weakPtrFactory.createWeakPtr()));
+}
+
+void PluginPlaceholderElement::onCloseButtonClick()
+{
+ // FIXME: Record UMA Plugin_Hide_Click or an equivalent UseCounter.
+ bool success = V8PluginPlaceholderElement::PrivateScript::hideMethod(document().frame(), this);
ASSERT_UNUSED(success, success);
}
« no previous file with comments | « Source/core/html/shadow/PluginPlaceholderElement.h ('k') | Source/core/html/shadow/PluginPlaceholderElement.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698