diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2012-11-22 09:09:45 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@digia.com> | 2012-11-22 09:10:13 +0100 |
commit | 470286ecfe79d59df14944e5b5d34630fc739391 (patch) | |
tree | 43983212872e06cebefd2ae474418fa2908ca54c /Source/WebKit2/UIProcess/Network | |
parent | 23037105e948c2065da5a937d3a2396b0ff45c1e (diff) | |
download | qtwebkit-470286ecfe79d59df14944e5b5d34630fc739391.tar.gz |
Imported WebKit commit e89504fa9195b2063b2530961d4b73dd08de3242 (http://svn.webkit.org/repository/webkit/trunk@135485)
Change-Id: I03774e5ac79721c13ffa30d152537a74d0b12e66
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'Source/WebKit2/UIProcess/Network')
3 files changed, 258 insertions, 0 deletions
diff --git a/Source/WebKit2/UIProcess/Network/CustomProtocols/CustomProtocolManagerProxy.h b/Source/WebKit2/UIProcess/Network/CustomProtocols/CustomProtocolManagerProxy.h new file mode 100644 index 000000000..aba9577f2 --- /dev/null +++ b/Source/WebKit2/UIProcess/Network/CustomProtocols/CustomProtocolManagerProxy.h @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2012 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef CustomProtocolManagerProxy_h +#define CustomProtocolManagerProxy_h + +#if ENABLE(CUSTOM_PROTOCOLS) + +#include "MessageID.h" + +#if PLATFORM(MAC) +#include <wtf/HashMap.h> +#include <wtf/RetainPtr.h> +OBJC_CLASS WKCustomProtocolLoader; +#endif + +namespace CoreIPC { +class Connection; +class MessageDecoder; +} // namespace CoreIPC + +namespace WebCore { +class ResourceRequest; +} // namespace WebCore + +namespace WebKit { + +class WebProcessProxy; + +class CustomProtocolManagerProxy { +public: + explicit CustomProtocolManagerProxy(WebProcessProxy*); + + void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&); + void startLoading(uint64_t customProtocolID, const WebCore::ResourceRequest&); + void stopLoading(uint64_t customProtocolID); + +private: + void didReceiveCustomProtocolManagerProxyMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&); + + WebProcessProxy* m_webProcessProxy; + +#if PLATFORM(MAC) + typedef HashMap<uint64_t, RetainPtr<WKCustomProtocolLoader> > LoaderMap; + LoaderMap m_loaderMap; +#endif +}; + +} // namespace WebKit + +#endif // ENABLE(CUSTOM_PROTOCOLS) + +#endif // CustomProtocolManagerProxy_h diff --git a/Source/WebKit2/UIProcess/Network/CustomProtocols/CustomProtocolManagerProxy.messages.in b/Source/WebKit2/UIProcess/Network/CustomProtocols/CustomProtocolManagerProxy.messages.in new file mode 100644 index 000000000..7aef0e0e7 --- /dev/null +++ b/Source/WebKit2/UIProcess/Network/CustomProtocols/CustomProtocolManagerProxy.messages.in @@ -0,0 +1,30 @@ +# Copyright (C) 2012 Apple Inc. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#if ENABLE(CUSTOM_PROTOCOLS) + +messages -> CustomProtocolManagerProxy { + StartLoading(uint64_t customProtocolID, WebCore::ResourceRequest request) + StopLoading(uint64_t customProtocolID) +} + +#endif // ENABLE(CUSTOM_PROTOCOLS) diff --git a/Source/WebKit2/UIProcess/Network/CustomProtocols/mac/CustomProtocolManagerProxyMac.mm b/Source/WebKit2/UIProcess/Network/CustomProtocols/mac/CustomProtocolManagerProxyMac.mm new file mode 100644 index 000000000..5c4aa03f3 --- /dev/null +++ b/Source/WebKit2/UIProcess/Network/CustomProtocols/mac/CustomProtocolManagerProxyMac.mm @@ -0,0 +1,153 @@ +/* + * Copyright (C) 2012 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#import "config.h" +#import "CustomProtocolManagerProxy.h" + +#if ENABLE(CUSTOM_PROTOCOLS) + +#import "Connection.h" +#import "CustomProtocolManagerMessages.h" +#import "DataReference.h" +#import "WebProcessProxy.h" +#import <WebCore/ResourceError.h> +#import <WebCore/ResourceResponse.h> + +using namespace CoreIPC; +using namespace WebCore; +using namespace WebKit; + +@interface WKCustomProtocolLoader : NSObject <NSURLConnectionDelegate> { +@private + CustomProtocolManagerProxy* _customProtocolManagerProxy; + uint64_t _customProtocolID; + RefPtr<Connection> _connection; + NSURLCacheStoragePolicy _storagePolicy; + NSURLConnection *_urlConnection; +} +- (id)initWithCustomProtocolManagerProxy:(CustomProtocolManagerProxy*)customProtocolManagerProxy customProtocolID:(uint64_t)customProtocolID request:(NSURLRequest *)request connection:(Connection *)connection; +@end + +@implementation WKCustomProtocolLoader + +- (id)initWithCustomProtocolManagerProxy:(CustomProtocolManagerProxy*)customProtocolManagerProxy customProtocolID:(uint64_t)customProtocolID request:(NSURLRequest *)request connection:(Connection *)connection +{ + self = [super init]; + if (!self) + return nil; + + ASSERT(customProtocolManagerProxy); + ASSERT(request); + ASSERT(connection); + _customProtocolManagerProxy = customProtocolManagerProxy; + _customProtocolID = customProtocolID; + _connection = connection; + _storagePolicy = NSURLCacheStorageNotAllowed; + _urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES]; + + return self; +} + +- (void)dealloc +{ + _connection.clear(); + [_urlConnection cancel]; + [_urlConnection release]; + [super dealloc]; +} + +- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error +{ + ResourceError coreError(error); + _connection->send(Messages::CustomProtocolManager::DidFailWithError(_customProtocolID, coreError), 0); + _customProtocolManagerProxy->stopLoading(_customProtocolID); +} + +- (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse +{ + ASSERT(_storagePolicy == NSURLCacheStorageNotAllowed); + _storagePolicy = [cachedResponse storagePolicy]; + return cachedResponse; +} + +- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response +{ + ResourceResponse coreResponse(response); + _connection->send(Messages::CustomProtocolManager::DidReceiveResponse(_customProtocolID, coreResponse, _storagePolicy), 0); +} + +- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data +{ + CoreIPC::DataReference coreData(static_cast<const uint8_t*>([data bytes]), [data length]); + _connection->send(Messages::CustomProtocolManager::DidLoadData(_customProtocolID, coreData), 0); +} + +- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse +{ + return request; +} + +- (void)connectionDidFinishLoading:(NSURLConnection *)connection +{ + _connection->send(Messages::CustomProtocolManager::DidFinishLoading(_customProtocolID), 0); + _customProtocolManagerProxy->stopLoading(_customProtocolID); +} + +@end + +namespace WebKit { + +CustomProtocolManagerProxy::CustomProtocolManagerProxy(WebProcessProxy* webProcessProxy) + : m_webProcessProxy(webProcessProxy) +{ + ASSERT(m_webProcessProxy); +} + +void CustomProtocolManagerProxy::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::MessageDecoder& decoder) +{ + didReceiveCustomProtocolManagerProxyMessage(connection, messageID, decoder); +} + +void CustomProtocolManagerProxy::startLoading(uint64_t customProtocolID, const ResourceRequest& coreRequest) +{ + NSURLRequest *request = coreRequest.nsURLRequest(); + if (!request) + return; + + WKCustomProtocolLoader *loader = [[WKCustomProtocolLoader alloc] initWithCustomProtocolManagerProxy:this customProtocolID:customProtocolID request:request connection:m_webProcessProxy->connection()]; + ASSERT(loader); + ASSERT(!m_loaderMap.contains(customProtocolID)); + m_loaderMap.add(customProtocolID, loader); + [loader release]; +} + +void CustomProtocolManagerProxy::stopLoading(uint64_t customProtocolID) +{ + m_loaderMap.remove(customProtocolID); +} + +} // namespace WebKit + +#endif // ENABLE(CUSTOM_PROTOCOLS) |