~ubuntu-branches/ubuntu/maverick/webkit/maverick

« back to all changes in this revision

Viewing changes to WebCore/loader/PluginDocument.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mike Hommey
  • Date: 2007-08-19 15:54:12 UTC
  • Revision ID: james.westby@ubuntu.com-20070819155412-uxxg1h9plpghmtbi
Tags: upstream-0~svn25144
ImportĀ upstreamĀ versionĀ 0~svn25144

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without
 
5
 * modification, are permitted provided that the following conditions
 
6
 * are met:
 
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.
 
12
 *
 
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. 
 
23
 */
 
24
 
 
25
#include "config.h"
 
26
#include "PluginDocument.h"
 
27
 
 
28
#include "Frame.h"
 
29
#include "FrameLoader.h"
 
30
#include "FrameLoaderClient.h"
 
31
#include "Element.h"
 
32
#include "HTMLNames.h"
 
33
#include "Page.h"
 
34
#include "RenderWidget.h"
 
35
#include "SegmentedString.h"
 
36
#include "Settings.h"
 
37
#include "Text.h"
 
38
#include "HTMLEmbedElement.h"
 
39
#include "XMLTokenizer.h"
 
40
 
 
41
namespace WebCore {
 
42
    
 
43
using namespace HTMLNames;
 
44
    
 
45
class PluginTokenizer : public Tokenizer {
 
46
public:
 
47
    PluginTokenizer(Document* doc) : m_doc(doc), m_embedElement(0) {}
 
48
        
 
49
    virtual bool write(const SegmentedString&, bool appendData);
 
50
    virtual void stopParsing();
 
51
    virtual void finish();
 
52
    virtual bool isWaitingForScripts() const;
 
53
        
 
54
    virtual bool wantsRawData() const { return true; }
 
55
    virtual bool writeRawData(const char* data, int len);
 
56
        
 
57
    void createDocumentStructure();
 
58
private:
 
59
    Document* m_doc;
 
60
    HTMLEmbedElement* m_embedElement;
 
61
};
 
62
    
 
63
bool PluginTokenizer::write(const SegmentedString& s, bool appendData)
 
64
{
 
65
    ASSERT_NOT_REACHED();
 
66
    return false;
 
67
}
 
68
    
 
69
void PluginTokenizer::createDocumentStructure()
 
70
{
 
71
    ExceptionCode ec;
 
72
    RefPtr<Element> rootElement = m_doc->createElementNS(xhtmlNamespaceURI, "html", ec);
 
73
    m_doc->appendChild(rootElement, ec);
 
74
        
 
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)");
 
79
 
 
80
    rootElement->appendChild(body, ec);
 
81
        
 
82
    RefPtr<Element> embedElement = m_doc->createElementNS(xhtmlNamespaceURI, "embed", ec);
 
83
        
 
84
    m_embedElement = static_cast<HTMLEmbedElement*>(embedElement.get());
 
85
    m_embedElement->setAttribute(widthAttr, "100%");
 
86
    m_embedElement->setAttribute(heightAttr, "100%");
 
87
    
 
88
    m_embedElement->setAttribute(nameAttr, "plugin");
 
89
    m_embedElement->setSrc(m_doc->URL());
 
90
    m_embedElement->setType(m_doc->frame()->loader()->responseMIMEType());
 
91
    
 
92
    body->appendChild(embedElement, ec);    
 
93
}
 
94
    
 
95
bool PluginTokenizer::writeRawData(const char* data, int len)
 
96
{
 
97
    if (!m_embedElement) {
 
98
        createDocumentStructure();
 
99
 
 
100
        Frame* frame = m_doc->frame();
 
101
        Settings* settings = frame->settings();
 
102
        if (frame && settings && settings->arePluginsEnabled()) {
 
103
            m_doc->updateLayout();
 
104
            
 
105
            if (RenderWidget* renderer = static_cast<RenderWidget*>(m_embedElement->renderer()))
 
106
                frame->loader()->client()->redirectDataToPlugin(renderer->widget());
 
107
            
 
108
            finish();
 
109
        }
 
110
        
 
111
        return false;
 
112
    }
 
113
    
 
114
    ASSERT_NOT_REACHED();
 
115
    
 
116
    return false;
 
117
}
 
118
    
 
119
void PluginTokenizer::stopParsing()
 
120
{
 
121
    Tokenizer::stopParsing();        
 
122
}
 
123
    
 
124
void PluginTokenizer::finish()
 
125
{
 
126
    if (!m_parserStopped) 
 
127
        m_doc->finishedParsing();            
 
128
}
 
129
    
 
130
bool PluginTokenizer::isWaitingForScripts() const
 
131
{
 
132
    // A plugin document is never waiting for scripts
 
133
    return false;
 
134
}
 
135
    
 
136
PluginDocument::PluginDocument(DOMImplementation* implementation, Frame* frame)
 
137
    : HTMLDocument(implementation, frame)
 
138
{
 
139
    setParseMode(Compat);
 
140
}
 
141
    
 
142
Tokenizer* PluginDocument::createTokenizer()
 
143
{
 
144
    return new PluginTokenizer(this);
 
145
}
 
146
    
 
147
}