Skip to content

Commit dd1edd3

Browse files
ddorwinwebkit-commit-queue
authored andcommitted
[chromium] Provide access to the WebPlugin created by the helper plugin widget
https://bugs.webkit.org/show_bug.cgi?id=88028 Patch by David Dorwin <ddorwin@chromium.org> on 2012-06-11 Reviewed by Adam Barth. Source/WebKit/chromium: A WebPlugin is created when the document created by createHelperPlugin() is laid out. Expose it so the embedder can interact with the plugin instance. * public/WebHelperPlugin.h: (WebKit): (WebHelperPlugin): * public/WebMediaPlayerClient.h: (WebKit): * public/WebPlugin.h: (WebKit::WebPlugin::isPlaceholder): (WebPlugin): * src/WebHelperPluginImpl.cpp: (WebKit::WebHelperPluginImpl::WebHelperPluginImpl): (WebKit): (WebKit::WebHelperPluginImpl::getPlugin): (WebKit::WebHelperPluginImpl::initPage): (WebKit::WebHelperPluginImpl::close): * src/WebHelperPluginImpl.h: (WebKit): (WebHelperPluginImpl): * src/WebMediaPlayerClientImpl.cpp: (WebKit::WebMediaPlayerClientImpl::createHelperPlugin): * src/WebMediaPlayerClientImpl.h: (WebMediaPlayerClientImpl): * src/WebPagePopupImpl.cpp: Tools: Added isPlaceholder() to WebPlugin. * DumpRenderTree/chromium/TestWebPlugin.h: (TestWebPlugin::isPlaceholder): Canonical link: https://commits.webkit.org/106624@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@119988 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent d6bf36a commit dd1edd3

11 files changed

Lines changed: 115 additions & 9 deletions

File tree

Source/WebKit/chromium/ChangeLog

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,36 @@
1+
2012-06-11 David Dorwin <ddorwin@chromium.org>
2+
3+
[chromium] Provide access to the WebPlugin created by the helper plugin widget
4+
https://bugs.webkit.org/show_bug.cgi?id=88028
5+
6+
Reviewed by Adam Barth.
7+
8+
A WebPlugin is created when the document created by createHelperPlugin() is laid out.
9+
Expose it so the embedder can interact with the plugin instance.
10+
11+
* public/WebHelperPlugin.h:
12+
(WebKit):
13+
(WebHelperPlugin):
14+
* public/WebMediaPlayerClient.h:
15+
(WebKit):
16+
* public/WebPlugin.h:
17+
(WebKit::WebPlugin::isPlaceholder):
18+
(WebPlugin):
19+
* src/WebHelperPluginImpl.cpp:
20+
(WebKit::WebHelperPluginImpl::WebHelperPluginImpl):
21+
(WebKit):
22+
(WebKit::WebHelperPluginImpl::getPlugin):
23+
(WebKit::WebHelperPluginImpl::initPage):
24+
(WebKit::WebHelperPluginImpl::close):
25+
* src/WebHelperPluginImpl.h:
26+
(WebKit):
27+
(WebHelperPluginImpl):
28+
* src/WebMediaPlayerClientImpl.cpp:
29+
(WebKit::WebMediaPlayerClientImpl::createHelperPlugin):
30+
* src/WebMediaPlayerClientImpl.h:
31+
(WebMediaPlayerClientImpl):
32+
* src/WebPagePopupImpl.cpp:
33+
134
2012-06-05 Dana Jansens <danakj@chromium.org>
235

336
[chromium] Free texture from CCIOSurfaceLayerImpl when it is destroyed

Source/WebKit/chromium/public/WebHelperPlugin.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
namespace WebKit {
3838

3939
class WebFrameClient;
40+
class WebPlugin;
4041
class WebWidgetClient;
4142

4243
class WebHelperPlugin : public WebWidget {
@@ -45,6 +46,11 @@ class WebHelperPlugin : public WebWidget {
4546

4647
virtual void initializeFrame(WebFrameClient*) = 0;
4748

49+
// The returned pointer may be 0 even if initialization was successful.
50+
// For example, if the plugin cannot be found or the plugin is disabled.
51+
// If not 0, the returned pointer is valid for the lifetime of this object.
52+
virtual WebPlugin* getPlugin() = 0;
53+
4854
protected:
4955
~WebHelperPlugin() { }
5056
};

Source/WebKit/chromium/public/WebMediaPlayerClient.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
namespace WebKit {
3737

3838
class WebFrame;
39+
class WebPlugin;
3940
class WebRequest;
4041
class WebURL;
4142

@@ -76,7 +77,9 @@ class WebMediaPlayerClient {
7677
virtual void keyError(const WebString&, const WebString&, MediaKeyErrorCode, unsigned short systemCode) = 0;
7778
virtual void keyMessage(const WebString&, const WebString&, const unsigned char*, unsigned) = 0;
7879
virtual void keyNeeded(const WebString&, const WebString&, const unsigned char* initData, unsigned initDataLength) = 0;
79-
virtual void createHelperPlugin(const WebString& pluginType, WebFrame*) = 0;
80+
// The returned pointer is valid until closeHelperPlugin() is called.
81+
// Returns 0 if the plugin could not be instantiated.
82+
virtual WebPlugin* createHelperPlugin(const WebString& pluginType, WebFrame*) = 0;
8083
virtual void closeHelperPlugin() = 0;
8184
virtual void disableAcceleratedCompositing() = 0;
8285
protected:

Source/WebKit/chromium/public/WebPlugin.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ class WebPlugin {
139139
// Rotates the plugin's view of its content.
140140
virtual void rotateView(RotationType type) { }
141141

142+
virtual bool isPlaceholder() { return true; }
143+
142144
protected:
143145
~WebPlugin() { }
144146
};

Source/WebKit/chromium/src/WebHelperPluginImpl.cpp

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,18 @@
3131
#include "config.h"
3232
#include "WebHelperPluginImpl.h"
3333

34-
#include "Chrome.h"
3534
#include "DocumentLoader.h"
3635
#include "EmptyClients.h"
3736
#include "FocusController.h"
3837
#include "FrameView.h"
38+
#include "HTMLPlugInElement.h"
39+
#include "NodeList.h"
3940
#include "Page.h"
4041
#include "PageWidgetDelegate.h"
4142
#include "Settings.h"
4243
#include "WebFrameImpl.h"
44+
#include "WebPlugin.h"
45+
#include "WebPluginContainerImpl.h"
4346
#include "WebViewClient.h"
4447
#include "WebViewImpl.h"
4548
#include "WebWidgetClient.h"
@@ -99,6 +102,7 @@ class HelperPluginChromeClient : public EmptyChromeClient {
99102

100103
WebHelperPluginImpl::WebHelperPluginImpl(WebWidgetClient* client)
101104
: m_widgetClient(client)
105+
, m_webView(0)
102106
{
103107
ASSERT(client);
104108
}
@@ -143,6 +147,31 @@ void WebHelperPluginImpl::initializeFrame(WebFrameClient* client)
143147
frame->initializeAsMainFrame(m_page.get());
144148
}
145149

150+
// Returns a pointer to the WebPlugin by finding the single <object> tag in the page.
151+
WebPlugin* WebHelperPluginImpl::getPlugin()
152+
{
153+
ASSERT(m_page);
154+
155+
RefPtr<NodeList> objectElements = m_page->mainFrame()->document()->getElementsByTagName(WebCore::HTMLNames::objectTag.localName());
156+
ASSERT(objectElements && objectElements->length() == 1);
157+
if (!objectElements || objectElements->length() < 1)
158+
return 0;
159+
Node* node = objectElements->item(0);
160+
ASSERT(node->hasTagName(WebCore::HTMLNames::objectTag));
161+
WebCore::Widget* widget = static_cast<HTMLPlugInElement*>(node)->pluginWidget();
162+
if (!widget)
163+
return 0;
164+
WebPlugin* plugin = static_cast<WebPluginContainerImpl*>(widget)->plugin();
165+
ASSERT(plugin);
166+
// If the plugin is a placeholder, it is not useful to the caller, and it
167+
// could be replaced at any time. Therefore, do not return it.
168+
if (plugin->isPlaceholder())
169+
return 0;
170+
171+
// The plugin was instantiated and will outlive this object.
172+
return plugin;
173+
}
174+
146175
bool WebHelperPluginImpl::initPage(WebKit::WebViewImpl* webView, const String& pluginType)
147176
{
148177
Page::PageClients pageClients;
@@ -157,7 +186,7 @@ bool WebHelperPluginImpl::initPage(WebKit::WebViewImpl* webView, const String& p
157186

158187
webView->client()->initializeHelperPluginWebFrame(this);
159188

160-
// The page's main frame was set in initializeMainFrame() as a result of the above call.
189+
// The page's main frame was set in initializeFrame() as a result of the above call.
161190
Frame* frame = m_page->mainFrame();
162191
ASSERT(frame);
163192
frame->setView(FrameView::create(frame));
@@ -193,7 +222,17 @@ void WebHelperPluginImpl::setFocus(bool enable)
193222

194223
void WebHelperPluginImpl::close()
195224
{
196-
m_page.clear();
225+
RefPtr<WebFrameImpl> mainFrameImpl;
226+
227+
if (m_page) {
228+
// Initiate shutdown. This will cause a lot of notifications to be sent.
229+
if (m_page->mainFrame()) {
230+
mainFrameImpl = WebFrameImpl::fromFrame(m_page->mainFrame());
231+
m_page->mainFrame()->loader()->frameDetached();
232+
}
233+
m_page.clear();
234+
}
235+
197236
m_widgetClient = 0;
198237
deref();
199238
}

Source/WebKit/chromium/src/WebHelperPluginImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class Page;
4242
namespace WebKit {
4343

4444
class HelperPluginChromeClient;
45-
class WebFrameImpl;
4645
class WebViewImpl;
4746
class WebWidgetClient;
4847

@@ -60,6 +59,7 @@ class WebHelperPluginImpl : public WebHelperPlugin,
6059

6160
// WebHelperPlugin methods:
6261
virtual void initializeFrame(WebFrameClient*) OVERRIDE;
62+
virtual WebPlugin* getPlugin() OVERRIDE;
6363

6464
private:
6565
explicit WebHelperPluginImpl(WebWidgetClient*);

Source/WebKit/chromium/src/WebMediaPlayerClientImpl.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,23 @@ void WebMediaPlayerClientImpl::keyNeeded(const WebString& keySystem, const WebSt
267267
#endif
268268
}
269269

270-
void WebMediaPlayerClientImpl::createHelperPlugin(const WebString& pluginType, WebFrame* frame)
270+
WebPlugin* WebMediaPlayerClientImpl::createHelperPlugin(const WebString& pluginType, WebFrame* frame)
271271
{
272272
ASSERT(!m_helperPlugin);
273273
WebViewImpl* webView = static_cast<WebViewImpl*>(frame->view());
274274
m_helperPlugin = webView->createHelperPlugin(pluginType);
275+
if (!m_helperPlugin)
276+
return 0;
277+
278+
WebPlugin* plugin = m_helperPlugin->getPlugin();
279+
if (!plugin) {
280+
// There is no need to keep the helper plugin around and the caller
281+
// should not be expected to call close after a failure (null pointer).
282+
closeHelperPlugin();
283+
return 0;
284+
}
285+
286+
return plugin;
275287
}
276288

277289
void WebMediaPlayerClientImpl::closeHelperPlugin()

Source/WebKit/chromium/src/WebMediaPlayerClientImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class WebMediaPlayerClientImpl : public WebCore::MediaPlayerPrivateInterface
9090
virtual void keyError(const WebString& keySystem, const WebString& sessionId, MediaKeyErrorCode, unsigned short systemCode);
9191
virtual void keyMessage(const WebString& keySystem, const WebString& sessionId, const unsigned char* message, unsigned messageLength);
9292
virtual void keyNeeded(const WebString& keySystem, const WebString& sessionId, const unsigned char* initData, unsigned initDataLength);
93-
virtual void createHelperPlugin(const WebString& pluginType, WebFrame*);
93+
virtual WebPlugin* createHelperPlugin(const WebString& pluginType, WebFrame*);
9494
virtual void closeHelperPlugin();
9595
virtual void disableAcceleratedCompositing();
9696

Source/WebKit/chromium/src/WebPagePopupImpl.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,11 @@
3636
#include "DocumentLoader.h"
3737
#include "EmptyClients.h"
3838
#include "FocusController.h"
39-
#include "Frame.h"
4039
#include "FrameView.h"
4140
#include "Page.h"
4241
#include "PagePopupClient.h"
4342
#include "PageWidgetDelegate.h"
4443
#include "Settings.h"
45-
#include "WebInputEvent.h"
4644
#include "WebInputEventConversion.h"
4745
#include "WebPagePopup.h"
4846
#include "WebViewImpl.h"

Tools/ChangeLog

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
2012-06-11 David Dorwin <ddorwin@chromium.org>
2+
3+
[chromium] Provide access to the WebPlugin created by the helper plugin widget
4+
https://bugs.webkit.org/show_bug.cgi?id=88028
5+
6+
Reviewed by Adam Barth.
7+
8+
Added isPlaceholder() to WebPlugin.
9+
10+
* DumpRenderTree/chromium/TestWebPlugin.h:
11+
(TestWebPlugin::isPlaceholder):
12+
113
2012-06-11 Tony Chang <tony@chromium.org>
214

315
rebaseline from garden-o-matic leaves N processes each time it is run

0 commit comments

Comments
 (0)