This source file includes following definitions.
- create
- m_embedElement
- createDocumentStructure
- appendBytes
- finish
- pluginView
- m_shouldLoadPluginManually
- createParser
- pluginWidget
- pluginNode
- detach
- cancelManualPluginLoad
#include "config.h"
#include "core/html/PluginDocument.h"
#include "HTMLNames.h"
#include "bindings/v8/ExceptionStatePlaceholder.h"
#include "core/dom/RawDataDocumentParser.h"
#include "core/frame/FrameView.h"
#include "core/frame/LocalFrame.h"
#include "core/html/HTMLBodyElement.h"
#include "core/html/HTMLEmbedElement.h"
#include "core/html/HTMLHtmlElement.h"
#include "core/loader/DocumentLoader.h"
#include "core/loader/FrameLoader.h"
#include "core/loader/FrameLoaderClient.h"
#include "core/plugins/PluginView.h"
#include "core/rendering/RenderEmbeddedObject.h"
namespace WebCore {
using namespace HTMLNames;
class PluginDocumentParser : public RawDataDocumentParser {
public:
static PassRefPtr<PluginDocumentParser> create(PluginDocument* document)
{
return adoptRef(new PluginDocumentParser(document));
}
private:
PluginDocumentParser(Document* document)
: RawDataDocumentParser(document)
, m_embedElement(nullptr)
{
}
virtual void appendBytes(const char*, size_t) OVERRIDE;
virtual void finish() OVERRIDE;
void createDocumentStructure();
PluginView* pluginView() const;
RefPtr<HTMLEmbedElement> m_embedElement;
};
void PluginDocumentParser::createDocumentStructure()
{
ASSERT(document());
RELEASE_ASSERT(document()->loader());
LocalFrame* frame = document()->frame();
if (!frame)
return;
if (!frame->settings() || !frame->loader().allowPlugins(NotAboutToInstantiatePlugin))
return;
RefPtr<HTMLHtmlElement> rootElement = HTMLHtmlElement::create(*document());
rootElement->insertedByParser();
document()->appendChild(rootElement);
frame->loader().dispatchDocumentElementAvailable();
RefPtr<HTMLBodyElement> body = HTMLBodyElement::create(*document());
body->setAttribute(marginwidthAttr, "0");
body->setAttribute(marginheightAttr, "0");
body->setAttribute(styleAttr, "background-color: rgb(38,38,38)");
rootElement->appendChild(body);
m_embedElement = HTMLEmbedElement::create(*document());
m_embedElement->setAttribute(widthAttr, "100%");
m_embedElement->setAttribute(heightAttr, "100%");
m_embedElement->setAttribute(nameAttr, "plugin");
m_embedElement->setAttribute(srcAttr, AtomicString(document()->url().string()));
m_embedElement->setAttribute(typeAttr, document()->loader()->mimeType());
body->appendChild(m_embedElement);
toPluginDocument(document())->setPluginNode(m_embedElement.get());
document()->updateLayout();
frame->view()->flushAnyPendingPostLayoutTasks();
if (PluginView* view = pluginView())
view->didReceiveResponse(document()->loader()->response());
}
void PluginDocumentParser::appendBytes(const char* data, size_t length)
{
if (!m_embedElement)
createDocumentStructure();
if (!length)
return;
if (PluginView* view = pluginView())
view->didReceiveData(data, length);
}
void PluginDocumentParser::finish()
{
if (PluginView* view = pluginView()) {
const ResourceError& error = document()->loader()->mainDocumentError();
if (error.isNull())
view->didFinishLoading();
else
view->didFailLoading(error);
m_embedElement = nullptr;
}
RawDataDocumentParser::finish();
}
PluginView* PluginDocumentParser::pluginView() const
{
if (Widget* widget = toPluginDocument(document())->pluginWidget()) {
ASSERT_WITH_SECURITY_IMPLICATION(widget->isPluginContainer());
return toPluginView(widget);
}
return 0;
}
PluginDocument::PluginDocument(const DocumentInit& initializer)
: HTMLDocument(initializer, PluginDocumentClass)
, m_shouldLoadPluginManually(true)
{
setCompatibilityMode(QuirksMode);
lockCompatibilityMode();
}
PassRefPtr<DocumentParser> PluginDocument::createParser()
{
return PluginDocumentParser::create(this);
}
Widget* PluginDocument::pluginWidget()
{
if (m_pluginNode && m_pluginNode->renderer()) {
ASSERT(m_pluginNode->renderer()->isEmbeddedObject());
return toRenderEmbeddedObject(m_pluginNode->renderer())->widget();
}
return 0;
}
Node* PluginDocument::pluginNode()
{
return m_pluginNode.get();
}
void PluginDocument::detach(const AttachContext& context)
{
m_pluginNode = nullptr;
HTMLDocument::detach(context);
}
void PluginDocument::cancelManualPluginLoad()
{
if (!shouldLoadPluginManually())
return;
DocumentLoader* documentLoader = frame()->loader().documentLoader();
documentLoader->cancelMainResourceLoad(ResourceError::cancelledError(documentLoader->request().url()));
setShouldLoadPluginManually(false);
}
}