Commit 35720993 authored by aroben@apple.com's avatar aroben@apple.com

Move plugin-related methods to WebFrameLoaderClient

         Reviewed by Anders.

         * WebCoreSupport/WebFrameLoaderClient.cpp:
         (WebFrameLoaderClient::WebFrameLoaderClient):
         (WebFrameLoaderClient::setMainDocumentError):
         (WebFrameLoaderClient::committedLoad): Added some early returns.
         (WebFrameLoaderClient::receivedData):
         (WebFrameLoaderClient::finishedLoading): Ditto.
         (getWebDataSource):
         (WebFrameLoaderClient::createPlugin):
         * WebCoreSupport/WebFrameLoaderClient.h:
         * WebFrame.cpp:
         (WebFrame::WebFramePrivate::WebFramePrivate):
         * WebFrame.h:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@30582 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent db07d227
2008-02-25 Adam Roben <aroben@apple.com>
Move plugin-related methods to WebFrameLoaderClient
Reviewed by Anders.
* WebCoreSupport/WebFrameLoaderClient.cpp:
(WebFrameLoaderClient::WebFrameLoaderClient):
(WebFrameLoaderClient::setMainDocumentError):
(WebFrameLoaderClient::committedLoad): Added some early returns.
(WebFrameLoaderClient::receivedData):
(WebFrameLoaderClient::finishedLoading): Ditto.
(getWebDataSource):
(WebFrameLoaderClient::createPlugin):
* WebCoreSupport/WebFrameLoaderClient.h:
* WebFrame.cpp:
(WebFrame::WebFramePrivate::WebFramePrivate):
* WebFrame.h:
2008-02-25 Adam Roben <aroben@apple.com>
Move createFrame to WebFrameLoaderClient
......
......@@ -29,8 +29,10 @@
#include "config.h"
#include "WebFrameLoaderClient.h"
#include "CFDictionaryPropertyBag.h"
#include "MarshallingHelpers.h"
#include "WebDocumentLoader.h"
#include "WebError.h"
#include "WebFrame.h"
#include "WebNotificationCenter.h"
#include "WebView.h"
......@@ -43,6 +45,8 @@
#include <WebCore/HTMLFrameOwnerElement.h>
#include <WebCore/HTMLNames.h>
#include <WebCore/HistoryItem.h>
#include <WebCore/PluginPackage.h>
#include <WebCore/PluginView.h>
#pragma warning(pop)
using namespace WebCore;
......@@ -50,6 +54,8 @@ using namespace HTMLNames;
WebFrameLoaderClient::WebFrameLoaderClient(WebFrame* webFrame)
: m_webFrame(webFrame)
, m_pluginView(0)
, m_hasSentResponseToPlugin(false)
{
ASSERT_ARG(webFrame, webFrame);
}
......@@ -182,6 +188,17 @@ void WebFrameLoaderClient::dispatchShow()
ui->webViewShow(webView);
}
void WebFrameLoaderClient::setMainDocumentError(DocumentLoader*, const ResourceError& error)
{
if (!m_pluginView)
return;
if (m_pluginView->status() == PluginStatusLoadedSuccessfully)
m_pluginView->didFail(error);
m_pluginView = 0;
m_hasSentResponseToPlugin = false;
}
void WebFrameLoaderClient::postProgressStartedNotification()
{
static BSTR progressStartedName = SysAllocString(WebViewProgressStartedNotification);
......@@ -203,6 +220,61 @@ void WebFrameLoaderClient::postProgressFinishedNotification()
notifyCenter->postNotificationName(progressFinishedName, static_cast<IWebView*>(m_webFrame->webView()), 0);
}
void WebFrameLoaderClient::committedLoad(DocumentLoader* loader, const char* data, int length)
{
// FIXME: This should probably go through the data source.
const String& textEncoding = loader->response().textEncodingName();
if (!m_pluginView)
receivedData(data, length, textEncoding);
if (!m_pluginView || m_pluginView->status() != PluginStatusLoadedSuccessfully)
return;
if (!m_hasSentResponseToPlugin) {
m_pluginView->didReceiveResponse(core(m_webFrame)->loader()->documentLoader()->response());
// didReceiveResponse sets up a new stream to the plug-in. on a full-page plug-in, a failure in
// setting up this stream can cause the main document load to be cancelled, setting m_pluginView
// to null
if (!m_pluginView)
return;
m_hasSentResponseToPlugin = true;
}
m_pluginView->didReceiveData(data, length);
}
void WebFrameLoaderClient::receivedData(const char* data, int length, const String& textEncoding)
{
Frame* coreFrame = core(m_webFrame);
if (!coreFrame)
return;
// Set the encoding. This only needs to be done once, but it's harmless to do it again later.
String encoding = coreFrame->loader()->documentLoader()->overrideEncoding();
bool userChosen = !encoding.isNull();
if (encoding.isNull())
encoding = textEncoding;
coreFrame->loader()->setEncoding(encoding, userChosen);
coreFrame->loader()->addData(data, length);
}
void WebFrameLoaderClient::finishedLoading(DocumentLoader* loader)
{
// Telling the frame we received some data and passing 0 as the data is our
// way to get work done that is normally done when the first bit of data is
// received, even for the case of a document with no data (like about:blank)
if (!m_pluginView) {
committedLoad(loader, 0, 0);
return;
}
if (m_pluginView->status() == PluginStatusLoadedSuccessfully)
m_pluginView->didFinishLoading();
m_pluginView = 0;
m_hasSentResponseToPlugin = false;
}
PassRefPtr<DocumentLoader> WebFrameLoaderClient::createDocumentLoader(const ResourceRequest& request, const SubstituteData& substituteData)
{
RefPtr<WebDocumentLoader> loader = new WebDocumentLoader(request, substituteData);
......@@ -304,3 +376,80 @@ void WebFrameLoaderClient::loadURLIntoChild(const KURL& originalURL, const Strin
core(childFrame)->loader()->load(url, referrer, childLoadType, String(), 0, 0);
}
static WebDataSource* getWebDataSource(DocumentLoader* loader)
{
return loader ? static_cast<WebDocumentLoader*>(loader)->dataSource() : 0;
}
Widget* WebFrameLoaderClient::createPlugin(const IntSize& pluginSize, Element* element, const KURL& url, const Vector<String>& paramNames, const Vector<String>& paramValues, const String& mimeType, bool loadManually)
{
Frame* frame = core(m_webFrame);
PluginView* pluginView = PluginView::create(frame, pluginSize, element, url, paramNames, paramValues, mimeType, loadManually);
if (pluginView->status() == PluginStatusLoadedSuccessfully)
return pluginView;
COMPtr<IWebResourceLoadDelegate> resourceLoadDelegate;
WebView* webView = m_webFrame->webView();
if (FAILED(webView->resourceLoadDelegate(&resourceLoadDelegate)))
return pluginView;
RetainPtr<CFMutableDictionaryRef> userInfo(AdoptCF, CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
unsigned count = (unsigned)paramNames.size();
for (unsigned i = 0; i < count; i++) {
if (paramNames[i] == "pluginspage") {
static CFStringRef key = MarshallingHelpers::LPCOLESTRToCFStringRef(WebKitErrorPlugInPageURLStringKey);
RetainPtr<CFStringRef> str(AdoptCF, paramValues[i].createCFString());
CFDictionarySetValue(userInfo.get(), key, str.get());
break;
}
}
if (!mimeType.isNull()) {
static CFStringRef key = MarshallingHelpers::LPCOLESTRToCFStringRef(WebKitErrorMIMETypeKey);
RetainPtr<CFStringRef> str(AdoptCF, mimeType.createCFString());
CFDictionarySetValue(userInfo.get(), key, str.get());
}
String pluginName;
if (pluginView->plugin())
pluginName = pluginView->plugin()->name();
if (!pluginName.isNull()) {
static CFStringRef key = MarshallingHelpers::LPCOLESTRToCFStringRef(WebKitErrorPlugInNameKey);
RetainPtr<CFStringRef> str(AdoptCF, pluginName.createCFString());
CFDictionarySetValue(userInfo.get(), key, str.get());
}
COMPtr<CFDictionaryPropertyBag> userInfoBag(AdoptCOM, CFDictionaryPropertyBag::createInstance());
userInfoBag->setDictionary(userInfo.get());
int errorCode = 0;
switch (pluginView->status()) {
case PluginStatusCanNotFindPlugin:
errorCode = WebKitErrorCannotFindPlugIn;
break;
case PluginStatusCanNotLoadPlugin:
errorCode = WebKitErrorCannotLoadPlugIn;
break;
default:
ASSERT_NOT_REACHED();
}
ResourceError resourceError(String(WebKitErrorDomain), errorCode, url.string(), String());
COMPtr<IWebError> error(AdoptCOM, WebError::createInstance(resourceError, userInfoBag.get()));
resourceLoadDelegate->plugInFailedWithError(webView, error.get(), getWebDataSource(frame->loader()->documentLoader()));
return pluginView;
}
void WebFrameLoaderClient::redirectDataToPlugin(Widget* pluginWidget)
{
// Ideally, this function shouldn't be necessary, see <rdar://problem/4852889>
m_pluginView = static_cast<PluginView*>(pluginWidget);
}
......@@ -33,6 +33,10 @@
#include <WebCore/FrameLoaderClient.h>
#pragma warning(pop)
namespace WebCore {
class PluginView;
}
class WebFrame;
class WebFrameLoaderClient : public WebCore::FrameLoaderClient {
......@@ -55,14 +59,21 @@ public:
virtual void dispatchDidFirstLayout();
virtual void dispatchShow();
virtual void setMainDocumentError(WebCore::DocumentLoader*, const WebCore::ResourceError&);
virtual void postProgressStartedNotification();
virtual void postProgressEstimateChangedNotification();
virtual void postProgressFinishedNotification();
virtual void committedLoad(WebCore::DocumentLoader*, const char*, int);
virtual void finishedLoading(WebCore::DocumentLoader*);
virtual PassRefPtr<WebCore::DocumentLoader> createDocumentLoader(const WebCore::ResourceRequest&, const WebCore::SubstituteData&);
virtual PassRefPtr<WebCore::Frame> createFrame(const WebCore::KURL& url, const WebCore::String& name, WebCore::HTMLFrameOwnerElement* ownerElement,
const WebCore::String& referrer, bool allowsScrolling, int marginWidth, int marginHeight);
virtual WebCore::Widget* createPlugin(const WebCore::IntSize&, WebCore::Element*, const WebCore::KURL&, const Vector<WebCore::String>&, const Vector<WebCore::String>&, const WebCore::String&, bool loadManually);
virtual void redirectDataToPlugin(WebCore::Widget* pluginWidget);
protected:
WebFrameLoaderClient(WebFrame*);
......@@ -71,8 +82,14 @@ protected:
private:
PassRefPtr<WebCore::Frame> createFrame(const WebCore::KURL&, const WebCore::String& name, WebCore::HTMLFrameOwnerElement*, const WebCore::String& referrer);
void loadURLIntoChild(const WebCore::KURL&, const WebCore::String& referrer, WebFrame* childFrame);
void receivedData(const char*, int, const WebCore::String&);
WebFrame* m_webFrame;
// Points to the plugin view that data should be redirected to.
WebCore::PluginView* m_pluginView;
bool m_hasSentResponseToPlugin;
};
#endif // WebFrameLoaderClient_h
......@@ -224,8 +224,6 @@ public:
: frame(0)
, webView(0)
, m_policyFunction(0)
, m_pluginView(0)
, m_hasSentResponseToPlugin(false)
{
}
......@@ -236,10 +234,6 @@ public:
WebView* webView;
FramePolicyFunction m_policyFunction;
COMPtr<WebFramePolicyListener> m_policyListener;
// Points to the plugin view that data should be redirected to.
PluginView* m_pluginView;
bool m_hasSentResponseToPlugin;
};
// WebFrame ----------------------------------------------------------------
......@@ -1227,21 +1221,6 @@ void WebFrame::didChangeTitle(DocumentLoader*)
notImplemented();
}
void WebFrame::finishedLoading(DocumentLoader* loader)
{
// Telling the frame we received some data and passing 0 as the data is our
// way to get work done that is normally done when the first bit of data is
// received, even for the case of a document with no data (like about:blank)
if (!d->m_pluginView)
committedLoad(loader, 0, 0);
else {
if (d->m_pluginView->status() == PluginStatusLoadedSuccessfully)
d->m_pluginView->didFinishLoading();
d->m_pluginView = 0;
d->m_hasSentResponseToPlugin = false;
}
}
void WebFrame::finalSetupForReplace(DocumentLoader*)
{
notImplemented();
......@@ -1433,16 +1412,6 @@ bool WebFrame::canCachePage() const
return true;
}
void WebFrame::setMainDocumentError(DocumentLoader*, const ResourceError& error)
{
if (d->m_pluginView) {
if (d->m_pluginView->status() == PluginStatusLoadedSuccessfully)
d->m_pluginView->didFail(error);
d->m_pluginView = 0;
d->m_hasSentResponseToPlugin = false;
}
}
ResourceError WebFrame::cancelledError(const ResourceRequest& request)
{
// FIXME: Need ChickenCat to include CFNetwork/CFURLError.h to get these values
......@@ -1485,22 +1454,6 @@ bool WebFrame::shouldFallBack(const ResourceError& error)
return error.errorCode() != WebURLErrorCancelled;
}
void WebFrame::receivedData(const char* data, int length, const String& textEncoding)
{
Frame* coreFrame = core(this);
if (!coreFrame)
return;
// Set the encoding. This only needs to be done once, but it's harmless to do it again later.
String encoding = coreFrame->loader()->documentLoader()->overrideEncoding();
bool userChosen = !encoding.isNull();
if (encoding.isNull())
encoding = textEncoding;
coreFrame->loader()->setEncoding(encoding, userChosen);
coreFrame->loader()->addData(data, length);
}
COMPtr<WebFramePolicyListener> WebFrame::setUpPolicyListener(WebCore::FramePolicyFunction function)
{
// FIXME: <rdar://5634381> We need to support multiple active policy listeners.
......@@ -1533,28 +1486,6 @@ void WebFrame::receivedPolicyDecision(PolicyAction action)
(coreFrame->loader()->*function)(action);
}
void WebFrame::committedLoad(DocumentLoader* loader, const char* data, int length)
{
// FIXME: This should probably go through the data source.
const String& textEncoding = loader->response().textEncodingName();
if (!d->m_pluginView)
receivedData(data, length, textEncoding);
if (d->m_pluginView && d->m_pluginView->status() == PluginStatusLoadedSuccessfully) {
if (!d->m_hasSentResponseToPlugin) {
d->m_pluginView->didReceiveResponse(d->frame->loader()->documentLoader()->response());
// didReceiveResponse sets up a new stream to the plug-in. on a full-page plug-in, a failure in
// setting up this stream can cause the main document load to be cancelled, setting m_pluginView
// to null
if (!d->m_pluginView)
return;
d->m_hasSentResponseToPlugin = true;
}
d->m_pluginView->didReceiveData(data, length);
}
}
void WebFrame::dispatchDecidePolicyForMIMEType(FramePolicyFunction function, const String& mimeType, const ResourceRequest& request)
{
Frame* coreFrame = core(this);
......@@ -1793,76 +1724,6 @@ void WebFrame::dispatchDidCancelAuthenticationChallenge(DocumentLoader* loader,
}
}
Widget* WebFrame::createPlugin(const IntSize& pluginSize, Element* element, const KURL& url, const Vector<String>& paramNames, const Vector<String>& paramValues, const String& mimeType, bool loadManually)
{
PluginView* pluginView = PluginView::create(core(this), pluginSize, element, url, paramNames, paramValues, mimeType, loadManually);
if (pluginView->status() == PluginStatusLoadedSuccessfully)
return pluginView;
COMPtr<IWebResourceLoadDelegate> resourceLoadDelegate;
if (FAILED(d->webView->resourceLoadDelegate(&resourceLoadDelegate)))
return pluginView;
RetainPtr<CFMutableDictionaryRef> userInfo(AdoptCF, CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
unsigned count = (unsigned)paramNames.size();
for (unsigned i = 0; i < count; i++) {
if (paramNames[i] == "pluginspage") {
static CFStringRef key = MarshallingHelpers::LPCOLESTRToCFStringRef(WebKitErrorPlugInPageURLStringKey);
RetainPtr<CFStringRef> str(AdoptCF, paramValues[i].createCFString());
CFDictionarySetValue(userInfo.get(), key, str.get());
break;
}
}
if (!mimeType.isNull()) {
static CFStringRef key = MarshallingHelpers::LPCOLESTRToCFStringRef(WebKitErrorMIMETypeKey);
RetainPtr<CFStringRef> str(AdoptCF, mimeType.createCFString());
CFDictionarySetValue(userInfo.get(), key, str.get());
}
String pluginName;
if (pluginView->plugin())
pluginName = pluginView->plugin()->name();
if (!pluginName.isNull()) {
static CFStringRef key = MarshallingHelpers::LPCOLESTRToCFStringRef(WebKitErrorPlugInNameKey);
RetainPtr<CFStringRef> str(AdoptCF, pluginName.createCFString());
CFDictionarySetValue(userInfo.get(), key, str.get());
}
COMPtr<CFDictionaryPropertyBag> userInfoBag(AdoptCOM, CFDictionaryPropertyBag::createInstance());
userInfoBag->setDictionary(userInfo.get());
int errorCode = 0;
switch (pluginView->status()) {
case PluginStatusCanNotFindPlugin:
errorCode = WebKitErrorCannotFindPlugIn;
break;
case PluginStatusCanNotLoadPlugin:
errorCode = WebKitErrorCannotLoadPlugIn;
break;
default:
ASSERT_NOT_REACHED();
}
ResourceError resourceError(String(WebKitErrorDomain), errorCode, url.string(), String());
COMPtr<IWebError> error(AdoptCOM, WebError::createInstance(resourceError, userInfoBag.get()));
resourceLoadDelegate->plugInFailedWithError(d->webView, error.get(), getWebDataSource(d->frame->loader()->documentLoader()));
return pluginView;
}
void WebFrame::redirectDataToPlugin(Widget* pluginWidget)
{
// Ideally, this function shouldn't be necessary, see <rdar://problem/4852889>
d->m_pluginView = static_cast<PluginView*>(pluginWidget);
}
Widget* WebFrame::createJavaAppletWidget(const IntSize& pluginSize, Element* element, const KURL& /*baseURL*/, const Vector<String>& paramNames, const Vector<String>& paramValues)
{
PluginView* pluginView = PluginView::create(core(this), pluginSize, element, KURL(), paramNames, paramValues, "application/x-java-applet", false);
......
......@@ -231,7 +231,6 @@ public:
virtual void setMainFrameDocumentReady(bool);
virtual void willChangeTitle(WebCore::DocumentLoader*);
virtual void didChangeTitle(WebCore::DocumentLoader*);
virtual void finishedLoading(WebCore::DocumentLoader*);
virtual void finalSetupForReplace(WebCore::DocumentLoader*);
virtual void setDefersLoading(bool);
virtual bool isArchiveLoadPending(WebCore::ResourceLoader*) const;
......@@ -257,7 +256,6 @@ public:
virtual bool shouldGoToHistoryItem(WebCore::HistoryItem *) const;
virtual void saveViewStateToItem(WebCore::HistoryItem *);
virtual bool canCachePage(void) const;
virtual void setMainDocumentError(WebCore::DocumentLoader*, const WebCore::ResourceError&);
virtual WebCore::ResourceError cancelledError(const WebCore::ResourceRequest&);
virtual WebCore::ResourceError blockedError(const WebCore::ResourceRequest&);
virtual WebCore::ResourceError cannotShowURLError(const WebCore::ResourceRequest&);
......@@ -265,7 +263,6 @@ public:
virtual WebCore::ResourceError cannotShowMIMETypeError(const WebCore::ResourceResponse&);
virtual WebCore::ResourceError fileDoesNotExistError(const WebCore::ResourceResponse&);
virtual bool shouldFallBack(const WebCore::ResourceError&);
virtual void committedLoad(WebCore::DocumentLoader*, const char*, int);
virtual void dispatchDecidePolicyForMIMEType(WebCore::FramePolicyFunction, const WebCore::String& MIMEType, const WebCore::ResourceRequest&);
virtual void dispatchDecidePolicyForNewWindowAction(WebCore::FramePolicyFunction, const WebCore::NavigationAction&, const WebCore::ResourceRequest&, const WebCore::String& frameName);
virtual void dispatchDecidePolicyForNavigationAction(WebCore::FramePolicyFunction, const WebCore::NavigationAction&, const WebCore::ResourceRequest&);
......@@ -286,9 +283,6 @@ public:
virtual void startDownload(const WebCore::ResourceRequest&);
virtual void dispatchDidReceiveAuthenticationChallenge(WebCore::DocumentLoader*, unsigned long identifier, const WebCore::AuthenticationChallenge&);
virtual void dispatchDidCancelAuthenticationChallenge(WebCore::DocumentLoader*, unsigned long identifier, const WebCore::AuthenticationChallenge&);
virtual WebCore::Widget* createPlugin(const WebCore::IntSize&, WebCore::Element*, const WebCore::KURL&, const Vector<WebCore::String>&, const Vector<WebCore::String>&, const WebCore::String&, bool loadManually);
virtual void redirectDataToPlugin(WebCore::Widget* pluginWidget);
virtual WebCore::Widget* createJavaAppletWidget(const WebCore::IntSize&, WebCore::Element*, const WebCore::KURL& baseURL, const Vector<WebCore::String>& paramNames, const Vector<WebCore::String>& paramValues);
......@@ -304,7 +298,6 @@ public:
void initWithWebFrameView(IWebFrameView*, IWebView*, WebCore::Page*, WebCore::HTMLFrameOwnerElement*);
WebCore::Frame* impl();
void invalidate();
void receivedData(const char*, int, const WebCore::String&);
void unmarkAllMisspellings();
void unmarkAllBadGrammar();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment