diff options
-rw-r--r-- | chrome_frame/chrome_frame_npapi.cc | 4 | ||||
-rw-r--r-- | chrome_frame/chrome_frame_npapi.h | 4 | ||||
-rw-r--r-- | chrome_frame/npapi_url_request.cc | 58 | ||||
-rw-r--r-- | chrome_frame/npapi_url_request.h | 6 |
4 files changed, 51 insertions, 21 deletions
diff --git a/chrome_frame/chrome_frame_npapi.cc b/chrome_frame/chrome_frame_npapi.cc index 8f21f93..fe734a8c 100644 --- a/chrome_frame/chrome_frame_npapi.cc +++ b/chrome_frame/chrome_frame_npapi.cc @@ -1419,8 +1419,8 @@ bool ChromeFrameNPAPI::HandleContextMenuCommand(UINT cmd, return false; } -bool ChromeFrameNPAPI::NewStream(NPMIMEType type, NPStream* stream, - NPBool seekable, uint16* stream_type) { +NPError ChromeFrameNPAPI::NewStream(NPMIMEType type, NPStream* stream, + NPBool seekable, uint16* stream_type) { return url_fetcher_.NewStream(type, stream, seekable, stream_type); } diff --git a/chrome_frame/chrome_frame_npapi.h b/chrome_frame/chrome_frame_npapi.h index c5e17cb..6ba130e 100644 --- a/chrome_frame/chrome_frame_npapi.h +++ b/chrome_frame/chrome_frame_npapi.h @@ -63,8 +63,8 @@ class ChromeFrameNPAPI bool SetWindow(NPWindow* window_info); void UrlNotify(const char* url, NPReason reason, void* notify_data); - bool NewStream(NPMIMEType type, NPStream* stream, NPBool seekable, - uint16* stream_type); + NPError NewStream(NPMIMEType type, NPStream* stream, NPBool seekable, + uint16* stream_type); int32 WriteReady(NPStream* stream); int32 Write(NPStream* stream, int32 offset, int32 len, void* buffer); NPError DestroyStream(NPStream* stream, NPReason reason); diff --git a/chrome_frame/npapi_url_request.cc b/chrome_frame/npapi_url_request.cc index d7d9a2f..d551901 100644 --- a/chrome_frame/npapi_url_request.cc +++ b/chrome_frame/npapi_url_request.cc @@ -43,7 +43,7 @@ class NPAPIUrlRequest : public PluginUrlRequest { virtual bool Read(int bytes_to_read); // Called from NPAPI - bool OnStreamCreated(const char* mime_type, NPStream* stream); + NPError OnStreamCreated(const char* mime_type, NPStream* stream); NPError OnStreamDestroyed(NPReason reason); int OnWriteReady(); int OnWrite(void* buffer, int len); @@ -54,7 +54,6 @@ class NPAPIUrlRequest : public PluginUrlRequest { virtual unsigned long API_CALL Release(); private: - PluginUrlRequestDelegate* delegate_; unsigned long ref_count_; NPP instance_; NPStream* stream_; @@ -127,7 +126,8 @@ bool NPAPIUrlRequest::Read(int bytes_to_read) { return true; } -bool NPAPIUrlRequest::OnStreamCreated(const char* mime_type, NPStream* stream) { +NPError NPAPIUrlRequest::OnStreamCreated(const char* mime_type, + NPStream* stream) { stream_ = stream; status_.set_status(URLRequestStatus::IO_PENDING); // TODO(iyengar) @@ -136,7 +136,7 @@ bool NPAPIUrlRequest::OnStreamCreated(const char* mime_type, NPStream* stream) { delegate_->OnResponseStarted(id(), mime_type, stream->headers, stream->end, base::Time::FromTimeT(stream->lastmodified), std::string(), std::string(), 0); - return true; + return NPERR_NO_ERROR; } NPError NPAPIUrlRequest::OnStreamDestroyed(NPReason reason) { @@ -207,7 +207,7 @@ void NPAPIUrlRequestManager::StartRequest(int request_id, request_info.extra_request_headers, request_info.upload_data.get(), enable_frame_busting_)) { // Add to map. - DCHECK(NULL == request_map_[request_id].get()); + DCHECK(request_map_.find(request_id) == request_map_.end()); request_map_[request_id] = new_request; if (new_request->Start()) { // Keep additional reference on request for NPSTREAM @@ -218,24 +218,31 @@ void NPAPIUrlRequestManager::StartRequest(int request_id, } void NPAPIUrlRequestManager::ReadRequest(int request_id, int bytes_to_read) { - scoped_refptr<NPAPIUrlRequest> request = request_map_[request_id]; - DCHECK(request.get()); + scoped_refptr<NPAPIUrlRequest> request = LookupRequest(request_id); if (request) request->Read(bytes_to_read); } void NPAPIUrlRequestManager::EndRequest(int request_id) { - scoped_refptr<NPAPIUrlRequest> request = request_map_[request_id]; + scoped_refptr<NPAPIUrlRequest> request = LookupRequest(request_id); if (request) request->Stop(); } void NPAPIUrlRequestManager::StopAll() { - for (RequestMap::iterator index = request_map_.begin(); - index != request_map_.end(); - ++index) { - scoped_refptr<NPAPIUrlRequest> request = (*index).second; - request->Stop(); + std::vector<scoped_refptr<NPAPIUrlRequest> > request_list; + // We copy the pending requests into a temporary vector as the Stop + // function in the request could also try to delete the request from + // the request map and the iterator could end up being invalid. + for (RequestMap::iterator it = request_map_.begin(); + it != request_map_.end(); ++it) { + DCHECK(it->second != NULL); + request_list.push_back(it->second); + } + + for (std::vector<scoped_refptr<NPAPIUrlRequest> >::size_type index = 0; + index < request_list.size(); ++index) { + request_list[index]->Stop(); } } @@ -268,9 +275,14 @@ void NPAPIUrlRequestManager::OnResponseEnd(int request_id, } // Notifications from browser. Find the NPAPIUrlRequest and forward to it. -bool NPAPIUrlRequestManager::NewStream(NPMIMEType type, NPStream* stream, - NPBool seekable, uint16* stream_type) { +NPError NPAPIUrlRequestManager::NewStream(NPMIMEType type, + NPStream* stream, + NPBool seekable, + uint16* stream_type) { NPAPIUrlRequest* request = RequestFromNotifyData(stream->notifyData); + if (!request) + return NPERR_NO_ERROR; + DCHECK(request_map_.find(request->id()) != request_map_.end()); // We need to return the requested stream mode if we are returning a success // code. If we don't do this it causes Opera to blow up. @@ -280,6 +292,8 @@ bool NPAPIUrlRequestManager::NewStream(NPMIMEType type, NPStream* stream, int32 NPAPIUrlRequestManager::WriteReady(NPStream* stream) { NPAPIUrlRequest* request = RequestFromNotifyData(stream->notifyData); + if (!request) + return 0x7FFFFFFF; DCHECK(request_map_.find(request->id()) != request_map_.end()); return request->OnWriteReady(); } @@ -287,6 +301,8 @@ int32 NPAPIUrlRequestManager::WriteReady(NPStream* stream) { int32 NPAPIUrlRequestManager::Write(NPStream* stream, int32 offset, int32 len, void* buffer) { NPAPIUrlRequest* request = RequestFromNotifyData(stream->notifyData); + if (!request) + return len; DCHECK(request_map_.find(request->id()) != request_map_.end()); return request->OnWrite(buffer, len); } @@ -294,6 +310,8 @@ int32 NPAPIUrlRequestManager::Write(NPStream* stream, int32 offset, NPError NPAPIUrlRequestManager::DestroyStream(NPStream* stream, NPReason reason) { NPAPIUrlRequest* request = RequestFromNotifyData(stream->notifyData); + if (!request) + return NPERR_NO_ERROR; DCHECK(request_map_.find(request->id()) != request_map_.end()); return request->OnStreamDestroyed(reason); } @@ -301,8 +319,18 @@ NPError NPAPIUrlRequestManager::DestroyStream(NPStream* stream, void NPAPIUrlRequestManager::UrlNotify(const char* url, NPReason reason, void* notify_data) { NPAPIUrlRequest* request = RequestFromNotifyData(notify_data); + DCHECK(request != NULL); if (request) { request->Stop(); request->Release(); } } + +scoped_refptr<NPAPIUrlRequest> NPAPIUrlRequestManager::LookupRequest( + int request_id) { + RequestMap::iterator index = request_map_.find(request_id); + if (index != request_map_.end()) + return index->second; + return NULL; +} + diff --git a/chrome_frame/npapi_url_request.h b/chrome_frame/npapi_url_request.h index 87e40a9..0fec438 100644 --- a/chrome_frame/npapi_url_request.h +++ b/chrome_frame/npapi_url_request.h @@ -24,8 +24,8 @@ class NPAPIUrlRequestManager : public PluginUrlRequestManager, // Notifications from the browser. We find the appropriate NPAPIUrlRequest // and forward the call. - bool NewStream(NPMIMEType type, NPStream* stream, - NPBool seekable, uint16* stream_type); + NPError NewStream(NPMIMEType type, NPStream* stream, + NPBool seekable, uint16* stream_type); int32 WriteReady(NPStream* stream); int32 Write(NPStream* stream, int32 offset, int32 len, void* buffer); NPError DestroyStream(NPStream* stream, NPReason reason); @@ -44,6 +44,8 @@ class NPAPIUrlRequestManager : public PluginUrlRequestManager, typedef std::map<int, scoped_refptr<NPAPIUrlRequest> > RequestMap; RequestMap request_map_; + scoped_refptr<NPAPIUrlRequest> LookupRequest(int request_id); + // PluginUrlRequestDelegate implementation. Forwards back to delegate. virtual void OnResponseStarted(int request_id, const char* mime_type, const char* headers, int size, |