Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Google 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 are |
| 6 | * met: |
| 7 | * |
| 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 |
| 13 | * distribution. |
| 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. |
| 17 | * |
| 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. |
| 29 | */ |
| 30 | |
| 31 | #include "config.h" |
| 32 | #include "WebHelperPluginImpl.h" |
| 33 | |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 34 | #include "WebFrameImpl.h" |
| 35 | #include "WebPlugin.h" |
| 36 | #include "WebPluginContainerImpl.h" |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 37 | #include "core/html/HTMLObjectElement.h" |
| 38 | #include "core/loader/FrameLoader.h" |
| 39 | #include "core/loader/FrameLoaderClient.h" |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 40 | |
| 41 | using namespace WebCore; |
| 42 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 43 | namespace blink { |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 44 | |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 45 | DEFINE_TYPE_CASTS(WebHelperPluginImpl, WebHelperPlugin, plugin, true, true); |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 46 | |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 47 | WebHelperPlugin* WebHelperPlugin::create(const WebString& pluginType, WebFrame* frame) |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 48 | { |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 49 | OwnPtr<WebHelperPlugin> plugin = adoptPtr<WebHelperPlugin>(new WebHelperPluginImpl()); |
| 50 | if (!toWebHelperPluginImpl(plugin.get())->initialize(pluginType, toWebFrameImpl(frame))) |
| 51 | return 0; |
| 52 | return plugin.leakPtr(); |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 55 | WebHelperPluginImpl::WebHelperPluginImpl() |
| 56 | : m_destructionTimer(this, &WebHelperPluginImpl::reallyDestroy) |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 57 | { |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | WebHelperPluginImpl::~WebHelperPluginImpl() |
| 61 | { |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 62 | } |
| 63 | |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 64 | bool WebHelperPluginImpl::initialize(const String& pluginType, WebFrameImpl* frame) |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 65 | { |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 66 | ASSERT(!m_objectElement && !m_pluginContainer); |
| 67 | if (!frame->frame()->loader().client()) |
| 68 | return false; |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 69 | |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 70 | m_objectElement = HTMLObjectElement::create(*frame->frame()->document(), 0, false); |
| 71 | Vector<String> attributeNames; |
| 72 | Vector<String> attributeValues; |
| 73 | ASSERT(frame->frame()->document()->url().isValid()); |
| 74 | m_pluginContainer = adoptRef(toWebPluginContainerImpl(frame->frame()->loader().client()->createPlugin( |
| 75 | m_objectElement.get(), |
| 76 | frame->frame()->document()->url(), |
| 77 | attributeNames, |
| 78 | attributeValues, |
| 79 | pluginType, |
| 80 | false, |
| 81 | FrameLoaderClient::AllowDetachedPlugin).leakRef())); |
| 82 | |
| 83 | if (!m_pluginContainer) |
| 84 | return false; |
| 85 | |
| 86 | // Getting a placeholder plugin is also failure, since it's not the plugin the caller needed. |
| 87 | return !getPlugin()->isPlaceholder(); |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 88 | } |
| 89 | |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 90 | void WebHelperPluginImpl::reallyDestroy(Timer<WebHelperPluginImpl>*) |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 91 | { |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 92 | delete this; |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 95 | void WebHelperPluginImpl::destroy() |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 96 | { |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 97 | // Defer deletion so we don't do too much work when called via stopActiveDOMObjects(). |
| 98 | // FIXME: It's not clear why we still need this. The original code held a Page and a |
| 99 | // WebFrame, and destroying it would cause JavaScript triggered by frame detach to run, |
| 100 | // which isn't allowed inside stopActiveDOMObjects(). Removing this causes one Chrome test |
| 101 | // to fail with a timeout. |
| 102 | m_destructionTimer.startOneShot(0, FROM_HERE); |
| 103 | } |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 104 | |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 105 | WebPlugin* WebHelperPluginImpl::getPlugin() |
| 106 | { |
| 107 | ASSERT(m_pluginContainer); |
| 108 | ASSERT(m_pluginContainer->plugin()); |
| 109 | return m_pluginContainer->plugin(); |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 110 | } |
| 111 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 112 | } // namespace blink |