2 * Copyright (C) 2012 Google 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 are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "web/WebHelperPluginImpl.h"
34 #include "core/html/HTMLObjectElement.h"
35 #include "core/loader/FrameLoader.h"
36 #include "core/loader/FrameLoaderClient.h"
37 #include "public/web/WebPlugin.h"
38 #include "web/WebLocalFrameImpl.h"
39 #include "web/WebPluginContainerImpl.h"
43 DEFINE_TYPE_CASTS(WebHelperPluginImpl, WebHelperPlugin, plugin, true, true);
45 WebHelperPlugin* WebHelperPlugin::create(const WebString& pluginType, WebLocalFrame* frame)
47 OwnPtr<WebHelperPlugin> plugin = adoptPtr<WebHelperPlugin>(new WebHelperPluginImpl());
48 if (!toWebHelperPluginImpl(plugin.get())->initialize(pluginType, toWebLocalFrameImpl(frame)))
50 return plugin.leakPtr();
53 WebHelperPluginImpl::WebHelperPluginImpl()
54 : m_destructionTimer(this, &WebHelperPluginImpl::reallyDestroy)
58 WebHelperPluginImpl::~WebHelperPluginImpl()
62 bool WebHelperPluginImpl::initialize(const String& pluginType, WebLocalFrameImpl* frame)
64 ASSERT(!m_objectElement && !m_pluginContainer);
65 if (!frame->frame()->loader().client())
68 m_objectElement = HTMLObjectElement::create(*frame->frame()->document(), 0, false);
69 Vector<String> attributeNames;
70 Vector<String> attributeValues;
71 ASSERT(frame->frame()->document()->url().isValid());
72 m_pluginContainer = adoptRef(toWebPluginContainerImpl(frame->frame()->loader().client()->createPlugin(
73 m_objectElement.get(),
74 frame->frame()->document()->url(),
79 FrameLoaderClient::AllowDetachedPlugin).leakRef()));
81 if (!m_pluginContainer)
84 // Getting a placeholder plugin is also failure, since it's not the plugin the caller needed.
85 return !getPlugin()->isPlaceholder();
88 void WebHelperPluginImpl::reallyDestroy(Timer<WebHelperPluginImpl>*)
93 void WebHelperPluginImpl::destroy()
95 // Defer deletion so we don't do too much work when called via stopActiveDOMObjects().
96 // FIXME: It's not clear why we still need this. The original code held a Page and a
97 // WebFrame, and destroying it would cause JavaScript triggered by frame detach to run,
98 // which isn't allowed inside stopActiveDOMObjects(). Removing this causes one Chrome test
99 // to fail with a timeout.
100 m_destructionTimer.startOneShot(0, FROM_HERE);
103 WebPlugin* WebHelperPluginImpl::getPlugin()
105 ASSERT(m_pluginContainer);
106 ASSERT(m_pluginContainer->plugin());
107 return m_pluginContainer->plugin();