2
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
7
* 1. Redistributions of source code must retain the above copyright
8
* notice, this list of conditions and the following disclaimer.
9
* 2. Redistributions in binary form must reproduce the above copyright
10
* notice, this list of conditions and the following disclaimer in the
11
* documentation and/or other materials provided with the distribution.
13
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
20
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
#include "PluginDocument.h"
29
#include "FrameLoader.h"
30
#include "FrameLoaderClient.h"
32
#include "HTMLNames.h"
34
#include "RenderWidget.h"
35
#include "SegmentedString.h"
38
#include "HTMLEmbedElement.h"
39
#include "XMLTokenizer.h"
43
using namespace HTMLNames;
45
class PluginTokenizer : public Tokenizer {
47
PluginTokenizer(Document* doc) : m_doc(doc), m_embedElement(0) {}
49
virtual bool write(const SegmentedString&, bool appendData);
50
virtual void stopParsing();
51
virtual void finish();
52
virtual bool isWaitingForScripts() const;
54
virtual bool wantsRawData() const { return true; }
55
virtual bool writeRawData(const char* data, int len);
57
void createDocumentStructure();
60
HTMLEmbedElement* m_embedElement;
63
bool PluginTokenizer::write(const SegmentedString& s, bool appendData)
69
void PluginTokenizer::createDocumentStructure()
72
RefPtr<Element> rootElement = m_doc->createElementNS(xhtmlNamespaceURI, "html", ec);
73
m_doc->appendChild(rootElement, ec);
75
RefPtr<Element> body = m_doc->createElementNS(xhtmlNamespaceURI, "body", ec);
76
body->setAttribute(marginwidthAttr, "0");
77
body->setAttribute(marginheightAttr, "0");
78
body->setAttribute(bgcolorAttr, "rgb(38,38,38)");
80
rootElement->appendChild(body, ec);
82
RefPtr<Element> embedElement = m_doc->createElementNS(xhtmlNamespaceURI, "embed", ec);
84
m_embedElement = static_cast<HTMLEmbedElement*>(embedElement.get());
85
m_embedElement->setAttribute(widthAttr, "100%");
86
m_embedElement->setAttribute(heightAttr, "100%");
88
m_embedElement->setAttribute(nameAttr, "plugin");
89
m_embedElement->setSrc(m_doc->URL());
90
m_embedElement->setType(m_doc->frame()->loader()->responseMIMEType());
92
body->appendChild(embedElement, ec);
95
bool PluginTokenizer::writeRawData(const char* data, int len)
97
if (!m_embedElement) {
98
createDocumentStructure();
100
Frame* frame = m_doc->frame();
101
Settings* settings = frame->settings();
102
if (frame && settings && settings->arePluginsEnabled()) {
103
m_doc->updateLayout();
105
if (RenderWidget* renderer = static_cast<RenderWidget*>(m_embedElement->renderer()))
106
frame->loader()->client()->redirectDataToPlugin(renderer->widget());
114
ASSERT_NOT_REACHED();
119
void PluginTokenizer::stopParsing()
121
Tokenizer::stopParsing();
124
void PluginTokenizer::finish()
126
if (!m_parserStopped)
127
m_doc->finishedParsing();
130
bool PluginTokenizer::isWaitingForScripts() const
132
// A plugin document is never waiting for scripts
136
PluginDocument::PluginDocument(DOMImplementation* implementation, Frame* frame)
137
: HTMLDocument(implementation, frame)
139
setParseMode(Compat);
142
Tokenizer* PluginDocument::createTokenizer()
144
return new PluginTokenizer(this);