Commit 208b92ff authored by andersca@apple.com's avatar andersca@apple.com
Browse files

2008-10-27 Anders Carlsson <andersca@apple.com>

        Reviewed by Dan Bernstein.
        
        Use the C++ stream object in WebBaseNetscapePluginView. Use a HashSet of RefPtrs to keep track of the streams.
        
        * Plugins/WebBaseNetscapePluginStream.mm:
        (WebNetscapePluginStream::~WebNetscapePluginStream):
        (WebNetscapePluginStream::setPlugin):
        (WebNetscapePluginStream::startStream):
        (WebNetscapePluginStream::destroyStream):
        (WebNetscapePluginStream::destroyStreamWithReason):
        (WebNetscapePluginStream::cancelLoadAndDestroyStreamWithError):
        (WebNetscapePluginStream::deliverData):
        * Plugins/WebBaseNetscapePluginView.h:
        * Plugins/WebBaseNetscapePluginView.mm:
        (-[WebBaseNetscapePluginView stop]):
        (-[WebBaseNetscapePluginView initWithFrame:pluginPackage:URL:baseURL:MIMEType:attributeKeys:attributeValues:loadManually:DOMElement:]):
        (-[WebBaseNetscapePluginView disconnectStream:]):
        (-[WebBaseNetscapePluginView dealloc]):
        (-[WebBaseNetscapePluginView pluginView:receivedResponse:]):
        (-[WebBaseNetscapePluginView pluginView:receivedData:]):
        (-[WebBaseNetscapePluginView pluginView:receivedError:]):
        (-[WebBaseNetscapePluginView pluginViewFinishedLoading:]):
        (-[WebBaseNetscapePluginView loadRequest:inTarget:withNotifyData:sendNotification:]):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@37915 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 9c716837
2008-10-27 Anders Carlsson <andersca@apple.com>
Reviewed by Mitz Pettel.
Reviewed by Dan Bernstein.
Use the C++ stream object in WebBaseNetscapePluginView. Use a HashSet of RefPtrs to keep track of the streams.
* Plugins/WebBaseNetscapePluginStream.mm:
(WebNetscapePluginStream::~WebNetscapePluginStream):
(WebNetscapePluginStream::setPlugin):
(WebNetscapePluginStream::startStream):
(WebNetscapePluginStream::destroyStream):
(WebNetscapePluginStream::destroyStreamWithReason):
(WebNetscapePluginStream::cancelLoadAndDestroyStreamWithError):
(WebNetscapePluginStream::deliverData):
* Plugins/WebBaseNetscapePluginView.h:
* Plugins/WebBaseNetscapePluginView.mm:
(-[WebBaseNetscapePluginView stop]):
(-[WebBaseNetscapePluginView initWithFrame:pluginPackage:URL:baseURL:MIMEType:attributeKeys:attributeValues:loadManually:DOMElement:]):
(-[WebBaseNetscapePluginView disconnectStream:]):
(-[WebBaseNetscapePluginView dealloc]):
(-[WebBaseNetscapePluginView pluginView:receivedResponse:]):
(-[WebBaseNetscapePluginView pluginView:receivedData:]):
(-[WebBaseNetscapePluginView pluginView:receivedError:]):
(-[WebBaseNetscapePluginView pluginViewFinishedLoading:]):
(-[WebBaseNetscapePluginView loadRequest:inTarget:withNotifyData:sendNotification:]):
2008-10-27 Anders Carlsson <andersca@apple.com>
Reviewed by Dan Bernstein.
Move code from dealloc and finalize to the WebNetscapePluginStream destructor.
......
......@@ -196,7 +196,7 @@ WebNetscapePluginStream::~WebNetscapePluginStream()
{
ASSERT(!m_plugin);
ASSERT(m_isTerminated);
ASSERT(m_stream.ndata == nil);
ASSERT(!m_stream.ndata);
// The stream file should have been deleted, and the path freed, in -_destroyStream
ASSERT(!m_path);
......@@ -241,7 +241,7 @@ void WebNetscapePluginStream::setPlugin(NPP plugin)
m_plugin = 0;
m_pluginFuncs = 0;
[view disconnectStream:m_pluginStream];
[view disconnectStream:this];
m_pluginView = 0;
}
}
......@@ -256,7 +256,7 @@ void WebNetscapePluginStream::startStream(NSURL *url, long long expectedContentL
free((void *)m_stream.url);
m_stream.url = strdup([m_responseURL.get() _web_URLCString]);
m_stream.ndata = m_pluginStream;
m_stream.ndata = this;
m_stream.end = expectedContentLength > 0 ? (uint32)expectedContentLength : 0;
m_stream.lastmodified = (uint32)[lastModifiedDate timeIntervalSince1970];
m_stream.notifyData = m_notifyData;
......@@ -412,14 +412,14 @@ void WebNetscapePluginStream::destroyStream()
if (m_isTerminated)
return;
RetainPtr<WebBaseNetscapePluginStream> protect(m_pluginStream);
RefPtr<WebNetscapePluginStream> protect(this);
ASSERT(m_reason != WEB_REASON_NONE);
ASSERT([m_deliveryData.get() length] == 0);
m_deliverDataTimer.stop();
if (m_stream.ndata != nil) {
if (m_stream.ndata) {
if (m_reason == NPRES_DONE && (m_transferMode == NP_ASFILE || m_transferMode == NP_ASFILEONLY)) {
ASSERT(m_fileDescriptor == -1);
ASSERT(m_path);
......@@ -463,7 +463,7 @@ void WebNetscapePluginStream::destroyStream()
m_headers = NULL;
m_stream.headers = NULL;
m_stream.ndata = nil;
m_stream.ndata = 0;
if (m_isTerminated)
return;
......@@ -493,7 +493,7 @@ void WebNetscapePluginStream::destroyStreamWithReason(NPReason reason)
return;
}
destroyStream();
ASSERT(m_stream.ndata == nil);
ASSERT(!m_stream.ndata);
}
void WebNetscapePluginStream::cancelLoadWithError(NSError *error)
......@@ -525,7 +525,7 @@ void WebNetscapePluginStream::didFail(WebCore::NetscapePlugInStreamLoader*, cons
void WebNetscapePluginStream::cancelLoadAndDestroyStreamWithError(NSError *error)
{
RetainPtr<WebBaseNetscapePluginStream> protect(m_pluginStream);
RefPtr<WebNetscapePluginStream> protect(this);
cancelLoadWithError(error);
destroyStreamWithError(error);
setPlugin(0);
......@@ -536,7 +536,7 @@ void WebNetscapePluginStream::deliverData()
if (!m_stream.ndata || [m_deliveryData.get() length] == 0)
return;
RetainPtr<WebBaseNetscapePluginStream> protect(m_pluginStream);
RefPtr<WebNetscapePluginStream> protect(this);
int32 totalBytes = [m_deliveryData.get() length];
int32 totalBytesDelivered = 0;
......
......@@ -33,16 +33,17 @@
#import <WebKit/npapi.h>
#import <WebKit/WebBasePluginPackage.h>
#import <wtf/HashMap.h>
#import <wtf/HashSet.h>
@class DOMElement;
@class WebDataSource;
@class WebFrame;
@class WebNetscapePluginPackage;
@class WebNetscapePluginNullEventSender;
@class WebBaseNetscapePluginStream;
@class WebView;
class PluginTimer;
class WebNetscapePluginStream;
class WebNetscapePluginEventHandler;
typedef union PluginPort {
......@@ -62,7 +63,7 @@ typedef struct _NPPluginTextInputFuncs NPPluginTextInputFuncs;
WebFrame *_webFrame;
BOOL _loadManually;
WebBaseNetscapePluginStream *_manualStream;
RefPtr<WebNetscapePluginStream> _manualStream;
unsigned _dataLengthReceived;
NSError *_error;
......@@ -109,7 +110,8 @@ typedef struct _NPPluginTextInputFuncs NPPluginTextInputFuncs;
NSString *MIMEType;
NSURL *baseURL;
NSTrackingRectTag trackingTag;
NSMutableArray *streams;
HashSet<RefPtr<WebNetscapePluginStream> > streams;
NSMutableDictionary *pendingFrameLoads;
NPPluginTextInputFuncs *textInputFuncs;
......@@ -164,7 +166,7 @@ typedef struct _NPPluginTextInputFuncs NPPluginTextInputFuncs;
- (void)setMode:(int)theMode;
- (void)viewWillMoveToHostWindow:(NSWindow *)hostWindow;
- (void)viewDidMoveToHostWindow;
- (void)disconnectStream:(WebBaseNetscapePluginStream*)stream;
- (void)disconnectStream:(WebNetscapePluginStream*)stream;
// Returns the NPObject that represents the plugin interface.
// The return value is expected to be retained.
......
......@@ -1251,12 +1251,14 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr)
[[self webView] removePluginInstanceView:self];
// To stop active streams it's necessary to invoke makeObjectsPerformSelector on a copy
// of streams. This is because calling -[WebNetscapePluginStream stop] also has the side effect
// of removing a stream from this collection.
NSArray *streamsCopy = [streams copy];
[streamsCopy makeObjectsPerformSelector:@selector(stop)];
[streamsCopy release];
// To stop active streams it's necessary to invoke stop() on a copy
// of streams. This is because calling WebNetscapePluginStream::stop() also has the side effect
// of removing a stream from this hash set.
Vector<RefPtr<WebNetscapePluginStream> > streamsCopy;
copyToVector(streams, streamsCopy);
for (size_t i = 0; i < streamsCopy.size(); i++)
streamsCopy[i]->stop();
// Stop the timers
[self stopTimers];
......@@ -1416,7 +1418,6 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr)
{
[super initWithFrame:frame];
streams = [[NSMutableArray alloc] init];
pendingFrameLoads = [[NSMutableDictionary alloc] init];
// load the plug-in if it is not already loaded
......@@ -1471,9 +1472,9 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr)
}
}
- (void)disconnectStream:(WebBaseNetscapePluginStream*)stream
- (void)disconnectStream:(WebNetscapePluginStream*)stream
{
[streams removeObjectIdenticalTo:stream];
streams.remove(stream);
}
- (void)dealloc
......@@ -1481,11 +1482,9 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr)
ASSERT(!isStarted);
[sourceURL release];
[_manualStream release];
[_error release];
[pluginPackage release];
[streams release];
[MIMEType release];
[baseURL release];
[pendingFrameLoads release];
......@@ -1756,8 +1755,8 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr)
{
ASSERT(_loadManually);
ASSERT(!_manualStream);
_manualStream = [[WebBaseNetscapePluginStream alloc] initWithFrameLoader:core([self webFrame])->loader()];
_manualStream = WebNetscapePluginStream::create(0, core([self webFrame])->loader());
}
- (void)pluginView:(NSView *)pluginView receivedData:(NSData *)data
......@@ -1770,19 +1769,17 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr)
if (![self isStarted])
return;
WebNetscapePluginStream *manualStream = [_manualStream impl];
if (!manualStream->plugin()) {
if (!_manualStream->plugin()) {
manualStream->setRequestURL([[[self dataSource] request] URL]);
manualStream->setPlugin([self plugin]);
ASSERT(manualStream->plugin());
_manualStream->setRequestURL([[[self dataSource] request] URL]);
_manualStream->setPlugin([self plugin]);
ASSERT(_manualStream->plugin());
manualStream->startStreamWithResponse([[self dataSource] response]);
_manualStream->startStreamWithResponse([[self dataSource] response]);
}
if (manualStream->plugin())
manualStream->didReceiveData(0, static_cast<const char *>([data bytes]), [data length]);
if (_manualStream->plugin())
_manualStream->didReceiveData(0, static_cast<const char *>([data bytes]), [data length]);
}
- (void)pluginView:(NSView *)pluginView receivedError:(NSError *)error
......@@ -1797,7 +1794,7 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr)
return;
}
[_manualStream impl]->destroyStreamWithError(error);
_manualStream->destroyStreamWithError(error);
}
- (void)pluginViewFinishedLoading:(NSView *)pluginView
......@@ -1806,7 +1803,7 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr)
ASSERT(_manualStream);
if ([self isStarted])
[_manualStream impl]->didFinishLoading(0);
_manualStream->didFinishLoading(0);
}
#pragma mark NSTextInput implementation
......@@ -2188,16 +2185,10 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr)
[self performSelector:@selector(loadPluginRequest:) withObject:pluginRequest afterDelay:0];
[pluginRequest release];
} else {
WebBaseNetscapePluginStream *stream = [[WebBaseNetscapePluginStream alloc] initWithRequest:request
plugin:plugin
notifyData:notifyData
sendNotification:sendNotification];
if (!stream)
return NPERR_INVALID_URL;
[streams addObject:stream];
[stream impl]->start();
[stream release];
RefPtr<WebNetscapePluginStream> stream = WebNetscapePluginStream::create(0, request, plugin, sendNotification, notifyData);
streams.add(stream.get());
stream->start();
}
return NPERR_NO_ERROR;
......
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