summaryrefslogtreecommitdiffstats
path: root/WebKit/mac/Plugins/Hosted/NetscapePluginInstanceProxy.mm
diff options
context:
space:
mode:
Diffstat (limited to 'WebKit/mac/Plugins/Hosted/NetscapePluginInstanceProxy.mm')
-rw-r--r--WebKit/mac/Plugins/Hosted/NetscapePluginInstanceProxy.mm109
1 files changed, 89 insertions, 20 deletions
diff --git a/WebKit/mac/Plugins/Hosted/NetscapePluginInstanceProxy.mm b/WebKit/mac/Plugins/Hosted/NetscapePluginInstanceProxy.mm
index 4ae0220..c09e3ea 100644
--- a/WebKit/mac/Plugins/Hosted/NetscapePluginInstanceProxy.mm
+++ b/WebKit/mac/Plugins/Hosted/NetscapePluginInstanceProxy.mm
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2008, 2009, 2010 Apple Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -40,6 +40,7 @@
#import "WebUIDelegate.h"
#import "WebUIDelegatePrivate.h"
#import "WebViewInternal.h"
+#import <JavaScriptCore/Error.h>
#import <JavaScriptCore/JSLock.h>
#import <JavaScriptCore/PropertyNameArray.h>
#import <WebCore/CString.h>
@@ -72,9 +73,20 @@ using namespace WebCore;
namespace WebKit {
-class NetscapePluginInstanceProxy::PluginRequest {
+class NetscapePluginInstanceProxy::PluginRequest : public RefCounted<NetscapePluginInstanceProxy::PluginRequest> {
public:
- PluginRequest(uint32_t requestID, NSURLRequest *request, NSString *frameName, bool allowPopups)
+ static PassRefPtr<PluginRequest> create(uint32_t requestID, NSURLRequest* request, NSString* frameName, bool allowPopups)
+ {
+ return adoptRef(new PluginRequest(requestID, request, frameName, allowPopups));
+ }
+
+ uint32_t requestID() const { return m_requestID; }
+ NSURLRequest* request() const { return m_request.get(); }
+ NSString* frameName() const { return m_frameName.get(); }
+ bool allowPopups() const { return m_allowPopups; }
+
+private:
+ PluginRequest(uint32_t requestID, NSURLRequest* request, NSString* frameName, bool allowPopups)
: m_requestID(requestID)
, m_request(request)
, m_frameName(frameName)
@@ -82,15 +94,9 @@ public:
{
}
- uint32_t requestID() const { return m_requestID; }
- NSURLRequest *request() const { return m_request.get(); }
- NSString *frameName() const { return m_frameName.get(); }
- bool allowPopups() const { return m_allowPopups; }
-
-private:
uint32_t m_requestID;
- RetainPtr<NSURLRequest *> m_request;
- RetainPtr<NSString *> m_frameName;
+ RetainPtr<NSURLRequest*> m_request;
+ RetainPtr<NSString*> m_frameName;
bool m_allowPopups;
};
@@ -121,7 +127,7 @@ NetscapePluginInstanceProxy::NetscapePluginInstanceProxy(NetscapePluginHostProxy
if (fullFramePlugin) {
// For full frame plug-ins, the first requestID will always be the one for the already
// open stream.
- ++m_currentRequestID;
+ ++m_currentURLRequestID;
}
// Assign a plug-in ID.
@@ -212,6 +218,10 @@ void NetscapePluginInstanceProxy::destroy()
m_inDestroy = true;
+ FrameLoadMap::iterator end = m_pendingFrameLoads.end();
+ for (FrameLoadMap::iterator it = m_pendingFrameLoads.begin(); it != end; ++it)
+ [(it->first) _setInternalLoadDelegate:nil];
+
_WKPHDestroyPluginInstance(m_pluginHostProxy->port(), m_pluginID, requestID);
// If the plug-in host crashes while we're waiting for a reply, the last reference to the instance proxy
@@ -252,6 +262,12 @@ bool NetscapePluginInstanceProxy::cancelStreamLoad(uint32_t streamID, NPReason r
void NetscapePluginInstanceProxy::disconnectStream(HostedNetscapePluginStream* stream)
{
+ if (stream == m_manualStream) {
+ m_manualStream = 0;
+ return;
+ }
+
+ ASSERT(m_streams.get(stream->streamID()) == stream);
m_streams.remove(stream->streamID());
}
@@ -517,8 +533,33 @@ void NetscapePluginInstanceProxy::performRequest(PluginRequest* pluginRequest)
if (JSString) {
ASSERT(!frame || [m_pluginView webFrame] == frame);
evaluateJavaScript(pluginRequest);
- } else
+ } else {
[frame loadRequest:request];
+
+ // Check if another plug-in view or even this view is waiting for the frame to load.
+ // If it is, tell it that the load was cancelled because it will be anyway.
+ WebHostedNetscapePluginView *view = [frame _internalLoadDelegate];
+ if (view != nil) {
+ ASSERT([view isKindOfClass:[WebHostedNetscapePluginView class]]);
+ [view webFrame:frame didFinishLoadWithReason:NPRES_USER_BREAK];
+ }
+ m_pendingFrameLoads.set(frame, pluginRequest);
+ [frame _setInternalLoadDelegate:m_pluginView];
+ }
+
+}
+
+void NetscapePluginInstanceProxy::webFrameDidFinishLoadWithReason(WebFrame* webFrame, NPReason reason)
+{
+ FrameLoadMap::iterator it = m_pendingFrameLoads.find(webFrame);
+ ASSERT(it != m_pendingFrameLoads.end());
+
+ PluginRequest* pluginRequest = it->second.get();
+ _WKPHLoadURLNotify(m_pluginHostProxy->port(), m_pluginID, pluginRequest->requestID(), reason);
+
+ m_pendingFrameLoads.remove(it);
+
+ [webFrame _setInternalLoadDelegate:nil];
}
void NetscapePluginInstanceProxy::evaluateJavaScript(PluginRequest* pluginRequest)
@@ -557,14 +598,13 @@ void NetscapePluginInstanceProxy::requestTimerFired(Timer<NetscapePluginInstance
ASSERT(!m_pluginRequests.isEmpty());
ASSERT(m_pluginView);
- PluginRequest* request = m_pluginRequests.first();
+ RefPtr<PluginRequest> request = m_pluginRequests.first();
m_pluginRequests.removeFirst();
if (!m_pluginRequests.isEmpty())
m_requestTimer.startOneShot(0);
- performRequest(request);
- delete request;
+ performRequest(request.get());
}
NPError NetscapePluginInstanceProxy::loadRequest(NSURLRequest *request, const char* cTarget, bool allowPopups, uint32_t& requestID)
@@ -616,12 +656,13 @@ NPError NetscapePluginInstanceProxy::loadRequest(NSURLRequest *request, const ch
return NPERR_INVALID_PARAM;
}
- PluginRequest* pluginRequest = new PluginRequest(requestID, request, target, allowPopups);
- m_pluginRequests.append(pluginRequest);
+ RefPtr<PluginRequest> pluginRequest = PluginRequest::create(requestID, request, target, allowPopups);
+ m_pluginRequests.append(pluginRequest.release());
m_requestTimer.startOneShot(0);
} else {
RefPtr<HostedNetscapePluginStream> stream = HostedNetscapePluginStream::create(this, requestID, request);
+ ASSERT(!m_streams.contains(requestID));
m_streams.add(requestID, stream);
stream->start();
}
@@ -663,7 +704,7 @@ bool NetscapePluginInstanceProxy::getWindowNPObject(uint32_t& objectID)
if (!frame)
return false;
- if (!frame->script()->isEnabled())
+ if (!frame->script()->canExecuteScripts())
objectID = 0;
else
objectID = idForObject(frame->script()->windowShell(pluginWorld())->window());
@@ -1168,7 +1209,7 @@ bool NetscapePluginInstanceProxy::demarshalValueFromArray(ExecState* exec, NSArr
if (!frame)
return false;
- if (!frame->script()->isEnabled())
+ if (!frame->script()->canExecuteScripts())
return false;
RefPtr<RootObject> rootObject = frame->script()->createRootObject(m_pluginView);
@@ -1220,6 +1261,10 @@ PassRefPtr<Instance> NetscapePluginInstanceProxy::createBindingsInstance(PassRef
if (_WKPHGetScriptableNPObject(m_pluginHostProxy->port(), m_pluginID, requestID) != KERN_SUCCESS)
return 0;
+
+ // If the plug-in host crashes while we're waiting for a reply, the last reference to the instance proxy
+ // will go away. Prevent this by protecting it here.
+ RefPtr<NetscapePluginInstanceProxy> protect(this);
auto_ptr<GetScriptableNPObjectReply> reply = waitForReply<GetScriptableNPObjectReply>(requestID);
if (!reply.get())
@@ -1448,6 +1493,30 @@ void NetscapePluginInstanceProxy::privateBrowsingModeDidChange(bool isPrivateBro
_WKPHPluginInstancePrivateBrowsingModeDidChange(m_pluginHostProxy->port(), m_pluginID, isPrivateBrowsingEnabled);
}
+static String& globalExceptionString()
+{
+ DEFINE_STATIC_LOCAL(String, exceptionString, ());
+ return exceptionString;
+}
+
+void NetscapePluginInstanceProxy::setGlobalException(const String& exception)
+{
+ globalExceptionString() = exception;
+}
+
+void NetscapePluginInstanceProxy::moveGlobalExceptionToExecState(ExecState* exec)
+{
+ if (globalExceptionString().isNull())
+ return;
+
+ {
+ JSLock lock(SilenceAssertionsOnly);
+ throwError(exec, GeneralError, globalExceptionString());
+ }
+
+ globalExceptionString() = UString();
+}
+
} // namespace WebKit
#endif // USE(PLUGIN_HOST_PROCESS)