diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2012-11-07 11:22:47 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@digia.com> | 2012-11-07 11:22:47 +0100 |
commit | cfd86b747d32ac22246a1aa908eaa720c63a88c1 (patch) | |
tree | 24d68c6f61c464ecba1e05670b80390ea3b0e50c /Source/WebKit2/NetworkProcess | |
parent | 69d7c744c9de19d152dbe2d8e46eb7dfd4511d1a (diff) | |
download | qtwebkit-cfd86b747d32ac22246a1aa908eaa720c63a88c1.tar.gz |
Imported WebKit commit 20271caf2e2c016d5cef40184cddeefeac4f1876 (http://svn.webkit.org/repository/webkit/trunk@133733)
New snapshot that contains all previous fixes as well as build fix for latest QtMultimedia API changes.
Diffstat (limited to 'Source/WebKit2/NetworkProcess')
16 files changed, 935 insertions, 12 deletions
diff --git a/Source/WebKit2/NetworkProcess/HostRecord.cpp b/Source/WebKit2/NetworkProcess/HostRecord.cpp new file mode 100644 index 000000000..32ba59638 --- /dev/null +++ b/Source/WebKit2/NetworkProcess/HostRecord.cpp @@ -0,0 +1,107 @@ +/* + * 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. + */ + +#include "config.h" +#include "HostRecord.h" + +#include "Logging.h" +#include "NetworkConnectionToWebProcess.h" +#include "NetworkProcess.h" +#include "NetworkRequest.h" +#include "NetworkResourceLoadScheduler.h" + +#if ENABLE(NETWORK_PROCESS) + +using namespace WebCore; + +namespace WebKit { + +HostRecord::HostRecord(const String& name, int maxRequestsInFlight) + : m_name(name) + , m_maxRequestsInFlight(maxRequestsInFlight) +{ +} + +HostRecord::~HostRecord() +{ +#ifndef NDEBUG + ASSERT(m_requestsLoading.isEmpty()); + for (unsigned p = 0; p <= ResourceLoadPriorityHighest; p++) + ASSERT(m_requestsPending[p].isEmpty()); +#endif +} + +void HostRecord::schedule(PassRefPtr<NetworkRequest> record, ResourceLoadPriority priority) +{ + m_requestsPending[priority].append(record); +} + +void HostRecord::addLoadInProgress(ResourceLoadIdentifier identifier) +{ + m_requestsLoading.add(identifier); +} + +void HostRecord::remove(ResourceLoadIdentifier identifier) +{ + if (m_requestsLoading.contains(identifier)) { + m_requestsLoading.remove(identifier); + return; + } + + for (int priority = ResourceLoadPriorityHighest; priority >= ResourceLoadPriorityLowest; --priority) { + RequestQueue::iterator end = m_requestsPending[priority].end(); + for (RequestQueue::iterator it = m_requestsPending[priority].begin(); it != end; ++it) { + if (it->get()->identifier() == identifier) { + m_requestsPending[priority].remove(it); + return; + } + } + } +} + +bool HostRecord::hasRequests() const +{ + if (!m_requestsLoading.isEmpty()) + return true; + + for (unsigned p = 0; p <= ResourceLoadPriorityHighest; p++) { + if (!m_requestsPending[p].isEmpty()) + return true; + } + + return false; +} + +bool HostRecord::limitRequests(ResourceLoadPriority priority, bool serialLoadingEnabled) const +{ + if (priority == ResourceLoadPriorityVeryLow && !m_requestsLoading.isEmpty()) + return true; + + return m_requestsLoading.size() >= (serialLoadingEnabled ? 1 : m_maxRequestsInFlight); +} + +} // namespace WebKit + +#endif // ENABLE(NETWORK_PROCESS) diff --git a/Source/WebKit2/NetworkProcess/HostRecord.h b/Source/WebKit2/NetworkProcess/HostRecord.h new file mode 100644 index 000000000..bed5df522 --- /dev/null +++ b/Source/WebKit2/NetworkProcess/HostRecord.h @@ -0,0 +1,70 @@ +/* + * 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 HostRecord_h +#define HostRecord_h + +#if ENABLE(NETWORK_PROCESS) + +#include <WebCore/ResourceRequest.h> +#include <wtf/Deque.h> +#include <wtf/HashSet.h> +#include <wtf/text/WTFString.h> + +namespace WebKit { + +class NetworkRequest; +typedef uint64_t ResourceLoadIdentifier; + +class HostRecord { + WTF_MAKE_NONCOPYABLE(HostRecord); WTF_MAKE_FAST_ALLOCATED; +public: + HostRecord(const String& name, int maxRequestsInFlight); + ~HostRecord(); + + const String& name() const { return m_name; } + void schedule(PassRefPtr<NetworkRequest>, WebCore::ResourceLoadPriority = WebCore::ResourceLoadPriorityVeryLow); + void addLoadInProgress(ResourceLoadIdentifier); + void remove(ResourceLoadIdentifier); + bool hasRequests() const; + bool limitRequests(WebCore::ResourceLoadPriority, bool serialLoadingEnabled) const; + + typedef Deque<RefPtr<NetworkRequest> > RequestQueue; + RequestQueue& requestsPending(WebCore::ResourceLoadPriority priority) { return m_requestsPending[priority]; } + +private: + RequestQueue m_requestsPending[WebCore::ResourceLoadPriorityHighest + 1]; + typedef HashSet<ResourceLoadIdentifier> RequestIdentifierMap; + RequestIdentifierMap m_requestsLoading; + + const String m_name; + int m_maxRequestsInFlight; +}; + +} // namespace WebKit + +#endif // ENABLE(NETWORK_PROCESS) + +#endif // #ifndef HostRecord_h diff --git a/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.cpp b/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.cpp index 1fdce180b..f9bd5af55 100644 --- a/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.cpp +++ b/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.cpp @@ -28,6 +28,7 @@ #include "ConnectionStack.h" #include "NetworkProcess.h" +#include <WebCore/ResourceRequest.h> #include <WebCore/RunLoop.h> #if ENABLE(NETWORK_PROCESS) @@ -42,6 +43,7 @@ PassRefPtr<NetworkConnectionToWebProcess> NetworkConnectionToWebProcess::create( } NetworkConnectionToWebProcess::NetworkConnectionToWebProcess(CoreIPC::Connection::Identifier connectionIdentifier) + : m_serialLoadingEnabled(false) { m_connection = CoreIPC::Connection::createServerConnection(connectionIdentifier, this, RunLoop::main()); m_connection->setOnlySendMessagesAsDispatchWhenWaitingForSyncReplyWhenProcessingSuchAMessage(true); @@ -51,22 +53,36 @@ NetworkConnectionToWebProcess::NetworkConnectionToWebProcess(CoreIPC::Connection NetworkConnectionToWebProcess::~NetworkConnectionToWebProcess() { ASSERT(!m_connection); + ASSERT(m_observers.isEmpty()); } -void NetworkConnectionToWebProcess::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::MessageDecoder& decoder) +void NetworkConnectionToWebProcess::registerObserver(NetworkConnectionToWebProcessObserver* observer) { - ConnectionStack::CurrentConnectionPusher currentConnection(ConnectionStack::shared(), connection); + ASSERT(!m_observers.contains(observer)); + m_observers.add(observer); +} +void NetworkConnectionToWebProcess::unregisterObserver(NetworkConnectionToWebProcessObserver* observer) +{ + ASSERT(m_observers.contains(observer)); + m_observers.remove(observer); +} + +void NetworkConnectionToWebProcess::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::MessageDecoder& decoder) +{ if (messageID.is<CoreIPC::MessageClassNetworkConnectionToWebProcess>()) { didReceiveNetworkConnectionToWebProcessMessage(connection, messageID, decoder); return; } - ASSERT_NOT_REACHED(); } -void NetworkConnectionToWebProcess::didReceiveSyncMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::MessageDecoder& arguments, OwnPtr<CoreIPC::MessageEncoder>& reply) +void NetworkConnectionToWebProcess::didReceiveSyncMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::MessageDecoder& decoder, OwnPtr<CoreIPC::MessageEncoder>& reply) { + if (messageID.is<CoreIPC::MessageClassNetworkConnectionToWebProcess>()) { + didReceiveSyncNetworkConnectionToWebProcessMessage(connection, messageID, decoder, reply); + return; + } ASSERT_NOT_REACHED(); } @@ -77,16 +93,59 @@ void NetworkConnectionToWebProcess::didClose(CoreIPC::Connection*) NetworkProcess::shared().removeNetworkConnectionToWebProcess(this); + Vector<NetworkConnectionToWebProcessObserver*> observers; + copyToVector(m_observers, observers); + for (size_t i = 0; i < observers.size(); ++i) + observers[i]->connectionToWebProcessDidClose(this); + + // FIXME (NetworkProcess): We might consider actively clearing out all requests for this connection. + // But that might not be necessary as the observer mechanism used above is much more direct. + m_connection = 0; } -void NetworkConnectionToWebProcess::didReceiveInvalidMessage(CoreIPC::Connection*, CoreIPC::MessageID) +void NetworkConnectionToWebProcess::didReceiveInvalidMessage(CoreIPC::Connection*, CoreIPC::StringReference, CoreIPC::StringReference) +{ +} + +void NetworkConnectionToWebProcess::scheduleNetworkRequest(const ResourceRequest& request, uint32_t resourceLoadPriority, ResourceLoadIdentifier& resourceLoadIdentifier) +{ + resourceLoadIdentifier = NetworkProcess::shared().networkResourceLoadScheduler().scheduleNetworkRequest(request, static_cast<ResourceLoadPriority>(resourceLoadPriority), this); +} + +void NetworkConnectionToWebProcess::addLoadInProgress(const WebCore::KURL& url, ResourceLoadIdentifier& identifier) +{ + identifier = NetworkProcess::shared().networkResourceLoadScheduler().addLoadInProgress(url); +} + +void NetworkConnectionToWebProcess::removeLoadIdentifier(ResourceLoadIdentifier identifier) +{ + NetworkProcess::shared().networkResourceLoadScheduler().removeLoadIdentifier(identifier); +} + +void NetworkConnectionToWebProcess::crossOriginRedirectReceived(ResourceLoadIdentifier identifier, const KURL& redirectURL) +{ + NetworkProcess::shared().networkResourceLoadScheduler().crossOriginRedirectReceived(identifier, redirectURL); +} + +void NetworkConnectionToWebProcess::servePendingRequests(uint32_t resourceLoadPriority) +{ + NetworkProcess::shared().networkResourceLoadScheduler().servePendingRequests(static_cast<ResourceLoadPriority>(resourceLoadPriority)); +} + +void NetworkConnectionToWebProcess::suspendPendingRequests() +{ + NetworkProcess::shared().networkResourceLoadScheduler().suspendPendingRequests(); +} + +void NetworkConnectionToWebProcess::resumePendingRequests() { + NetworkProcess::shared().networkResourceLoadScheduler().resumePendingRequests(); } -void NetworkConnectionToWebProcess::didReceiveNetworkConnectionToWebProcessMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&) +void NetworkConnectionToWebProcess::setSerialLoadingEnabled(bool enabled) { - // Empty for now - There are no messages to handle. + m_serialLoadingEnabled = enabled; } } // namespace WebKit diff --git a/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.h b/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.h index 635136094..23ee9846e 100644 --- a/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.h +++ b/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.h @@ -30,17 +30,36 @@ #include "Connection.h" #include "NetworkConnectionToWebProcessMessages.h" +#include <WebCore/ResourceLoadPriority.h> #include <wtf/HashSet.h> #include <wtf/RefCounted.h> +namespace WebCore { +class ResourceRequest; +} + namespace WebKit { +class NetworkConnectionToWebProcess; +typedef uint64_t ResourceLoadIdentifier; + +class NetworkConnectionToWebProcessObserver { +public: + virtual ~NetworkConnectionToWebProcessObserver() { } + virtual void connectionToWebProcessDidClose(NetworkConnectionToWebProcess*) = 0; +}; + class NetworkConnectionToWebProcess : public RefCounted<NetworkConnectionToWebProcess>, CoreIPC::Connection::Client { public: static PassRefPtr<NetworkConnectionToWebProcess> create(CoreIPC::Connection::Identifier); virtual ~NetworkConnectionToWebProcess(); CoreIPC::Connection* connection() const { return m_connection.get(); } + + void registerObserver(NetworkConnectionToWebProcessObserver*); + void unregisterObserver(NetworkConnectionToWebProcessObserver*); + + bool isSerialLoadingEnabled() const { return m_serialLoadingEnabled; } private: NetworkConnectionToWebProcess(CoreIPC::Connection::Identifier); @@ -49,12 +68,26 @@ private: virtual void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&); virtual void didReceiveSyncMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&, OwnPtr<CoreIPC::MessageEncoder>&); virtual void didClose(CoreIPC::Connection*); - virtual void didReceiveInvalidMessage(CoreIPC::Connection*, CoreIPC::MessageID); + virtual void didReceiveInvalidMessage(CoreIPC::Connection*, CoreIPC::StringReference messageReceiverName, CoreIPC::StringReference messageName); // Message handlers. void didReceiveNetworkConnectionToWebProcessMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&); - + void didReceiveSyncNetworkConnectionToWebProcessMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&, OwnPtr<CoreIPC::MessageEncoder>&); + + void scheduleNetworkRequest(const WebCore::ResourceRequest&, uint32_t resourceLoadPriority, ResourceLoadIdentifier&); + void addLoadInProgress(const WebCore::KURL&, ResourceLoadIdentifier&); + void removeLoadIdentifier(ResourceLoadIdentifier); + void crossOriginRedirectReceived(ResourceLoadIdentifier, const WebCore::KURL& redirectURL); + void servePendingRequests(uint32_t resourceLoadPriority); + void suspendPendingRequests(); + void resumePendingRequests(); + void setSerialLoadingEnabled(bool); + RefPtr<CoreIPC::Connection> m_connection; + + HashSet<NetworkConnectionToWebProcessObserver*> m_observers; + + bool m_serialLoadingEnabled; }; } // namespace WebKit diff --git a/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.messages.in b/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.messages.in index a1047c83a..df785a1b6 100644 --- a/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.messages.in +++ b/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.messages.in @@ -24,6 +24,24 @@ messages -> NetworkConnectionToWebProcess { + // FIXME (NetworkProcess): At least some of these synchronous messages are synchronous due to the requirement + // that we synchronously get an identifier for new ResourceLoaders as they are created. + // There's possible ResourceLoader identifier refactoring that can remove that requirement. + // We might also have the NetworkProcess divvy up identifiers in blocks to each WebProcess beforehand. + ScheduleNetworkRequest(WebCore::ResourceRequest request, uint32_t resourceLoadPriority) -> (uint64_t resourceLoadIdentifier) + AddLoadInProgress(WebCore::KURL url) -> (uint64_t resourceLoadIdentifier) + RemoveLoadIdentifier(uint64_t resourceLoadIdentifier) + + // It's possible that we will be able to do away with this message and have the NetworkProcess + // manage it internally. + crossOriginRedirectReceived(uint64_t resourceLoadIdentifier, WebCore::KURL redirectURL) -> () + + ServePendingRequests(uint32_t resourceLoadPriority) + + SuspendPendingRequests() -> () + ResumePendingRequests() -> () + + SetSerialLoadingEnabled(bool enabled) -> () } #endif // ENABLE(NETWORK_PROCESS) diff --git a/Source/WebKit2/NetworkProcess/NetworkProcess.cpp b/Source/WebKit2/NetworkProcess/NetworkProcess.cpp index 5be2e9b21..634333559 100644 --- a/Source/WebKit2/NetworkProcess/NetworkProcess.cpp +++ b/Source/WebKit2/NetworkProcess/NetworkProcess.cpp @@ -87,7 +87,7 @@ void NetworkProcess::didClose(CoreIPC::Connection*) RunLoop::current()->stop(); } -void NetworkProcess::didReceiveInvalidMessage(CoreIPC::Connection*, CoreIPC::MessageID) +void NetworkProcess::didReceiveInvalidMessage(CoreIPC::Connection*, CoreIPC::StringReference, CoreIPC::StringReference) { RunLoop::current()->stop(); } diff --git a/Source/WebKit2/NetworkProcess/NetworkProcess.h b/Source/WebKit2/NetworkProcess/NetworkProcess.h index 5828e1f5e..66a1185e9 100644 --- a/Source/WebKit2/NetworkProcess/NetworkProcess.h +++ b/Source/WebKit2/NetworkProcess/NetworkProcess.h @@ -29,6 +29,7 @@ #if ENABLE(NETWORK_PROCESS) #include "ChildProcess.h" +#include "NetworkResourceLoadScheduler.h" #include <wtf/Forward.h> namespace WebCore { @@ -49,6 +50,8 @@ public: void removeNetworkConnectionToWebProcess(NetworkConnectionToWebProcess*); + NetworkResourceLoadScheduler& networkResourceLoadScheduler() { return m_networkResourceLoadScheduler; } + private: NetworkProcess(); ~NetworkProcess(); @@ -61,7 +64,7 @@ private: // CoreIPC::Connection::Client virtual void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&); virtual void didClose(CoreIPC::Connection*); - virtual void didReceiveInvalidMessage(CoreIPC::Connection*, CoreIPC::MessageID); + virtual void didReceiveInvalidMessage(CoreIPC::Connection*, CoreIPC::StringReference messageReceiverName, CoreIPC::StringReference messageName); virtual void syncMessageSendTimedOut(CoreIPC::Connection*); // Message Handlers @@ -75,6 +78,7 @@ private: // Connections to WebProcesses. Vector<RefPtr<NetworkConnectionToWebProcess> > m_webProcessConnections; + NetworkResourceLoadScheduler m_networkResourceLoadScheduler; }; } // namespace WebKit diff --git a/Source/WebKit2/NetworkProcess/NetworkProcess.messages.in b/Source/WebKit2/NetworkProcess/NetworkProcess.messages.in index 029536a34..d243bd44f 100644 --- a/Source/WebKit2/NetworkProcess/NetworkProcess.messages.in +++ b/Source/WebKit2/NetworkProcess/NetworkProcess.messages.in @@ -28,6 +28,10 @@ messages -> NetworkProcess { # Creates a connection for communication with a WebProcess CreateNetworkConnectionToWebProcess() + +#if PLATFORM(MAC) + SetApplicationIsOccluded(bool flag) +#endif } #endif // ENABLE(NETWORK_PROCESS) diff --git a/Source/WebKit2/NetworkProcess/NetworkRequest.cpp b/Source/WebKit2/NetworkProcess/NetworkRequest.cpp new file mode 100644 index 000000000..79e74cf19 --- /dev/null +++ b/Source/WebKit2/NetworkProcess/NetworkRequest.cpp @@ -0,0 +1,58 @@ +/* + * 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. + */ + +#include "config.h" +#include "NetworkRequest.h" + +#if ENABLE(NETWORK_PROCESS) + +#include "NetworkConnectionToWebProcess.h" + +namespace WebKit { + +NetworkRequest::NetworkRequest(const WebCore::ResourceRequest& request, ResourceLoadIdentifier identifier, NetworkConnectionToWebProcess* connection) + : m_request(request) + , m_identifier(identifier) + , m_connection(connection) +{ + connection->registerObserver(this); +} + +NetworkRequest::~NetworkRequest() +{ + if (m_connection) + m_connection->unregisterObserver(this); +} + +void NetworkRequest::connectionToWebProcessDidClose(NetworkConnectionToWebProcess* connection) +{ + ASSERT_ARG(connection, connection == m_connection.get()); + m_connection->unregisterObserver(this); + m_connection = 0; +} + +} // namespace WebKit + +#endif // ENABLE(NETWORK_PROCESS) diff --git a/Source/WebKit2/NetworkProcess/NetworkRequest.h b/Source/WebKit2/NetworkProcess/NetworkRequest.h new file mode 100644 index 000000000..683e832c2 --- /dev/null +++ b/Source/WebKit2/NetworkProcess/NetworkRequest.h @@ -0,0 +1,66 @@ +/* + * 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 NetworkRequest_h +#define NetworkRequest_h + +#if ENABLE(NETWORK_PROCESS) + +#include "NetworkConnectionToWebProcess.h" +#include <WebCore/ResourceRequest.h> + +namespace WebKit { + +typedef uint64_t ResourceLoadIdentifier; + +class NetworkRequest : public RefCounted<NetworkRequest>, public NetworkConnectionToWebProcessObserver { +public: + static RefPtr<NetworkRequest> create(const WebCore::ResourceRequest& request, ResourceLoadIdentifier identifier, NetworkConnectionToWebProcess* connection) + { + return adoptRef(new NetworkRequest(request, identifier, connection)); + } + + ~NetworkRequest(); + + void connectionToWebProcessDidClose(NetworkConnectionToWebProcess*); + + ResourceLoadIdentifier identifier() { return m_identifier; } + + NetworkConnectionToWebProcess* connectionToWebProcess() { return m_connection.get(); } + +private: + NetworkRequest(const WebCore::ResourceRequest&, ResourceLoadIdentifier, NetworkConnectionToWebProcess*); + + WebCore::ResourceRequest m_request; + ResourceLoadIdentifier m_identifier; + + RefPtr<NetworkConnectionToWebProcess> m_connection; +}; + +} // namespace WebKit + +#endif // ENABLE(NETWORK_PROCESS) + +#endif // NetworkRequest_h diff --git a/Source/WebKit2/NetworkProcess/NetworkResourceLoadScheduler.cpp b/Source/WebKit2/NetworkProcess/NetworkResourceLoadScheduler.cpp new file mode 100644 index 000000000..ccc3d76b9 --- /dev/null +++ b/Source/WebKit2/NetworkProcess/NetworkResourceLoadScheduler.cpp @@ -0,0 +1,205 @@ +#include "config.h" +#include "NetworkResourceLoadScheduler.h" + +#include "HostRecord.h" +#include "Logging.h" +#include "NetworkConnectionToWebProcess.h" +#include "NetworkProcessconnectionMessages.h" +#include "NetworkRequest.h" +#include <wtf/text/CString.h> + +#if ENABLE(NETWORK_PROCESS) + +using namespace WebCore; + +namespace WebKit { + +static const unsigned maxRequestsInFlightForNonHTTPProtocols = 20; +static unsigned maxRequestsInFlightPerHost; +static ResourceLoadIdentifier s_currentResourceLoadIdentifier; + +NetworkResourceLoadScheduler::NetworkResourceLoadScheduler() + : m_nonHTTPProtocolHost(new HostRecord(String(), maxRequestsInFlightForNonHTTPProtocols)) + , m_requestTimer(this, &NetworkResourceLoadScheduler::requestTimerFired) + +{ + maxRequestsInFlightPerHost = platformInitializeMaximumHTTPConnectionCountPerHost(); +} + +void NetworkResourceLoadScheduler::scheduleServePendingRequests() +{ + if (!m_requestTimer.isActive()) + m_requestTimer.startOneShot(0); +} + +void NetworkResourceLoadScheduler::requestTimerFired(WebCore::Timer<NetworkResourceLoadScheduler>*) +{ + servePendingRequests(); +} + +ResourceLoadIdentifier NetworkResourceLoadScheduler::scheduleNetworkRequest(const ResourceRequest& request, ResourceLoadPriority priority, NetworkConnectionToWebProcess* connection) +{ + ResourceLoadIdentifier identifier = ++s_currentResourceLoadIdentifier; + + LOG(Network, "(NetworkProcess) NetworkResourceLoadScheduler::scheduleNetworkRequest resource %llu '%s'", identifier, request.url().string().utf8().data()); + + HostRecord* host = hostForURL(request.url(), CreateIfNotFound); + bool hadRequests = host->hasRequests(); + host->schedule(NetworkRequest::create(request, identifier, connection), priority); + m_identifiers.add(identifier, host); + + if (priority > ResourceLoadPriorityLow || !request.url().protocolIsInHTTPFamily() || (priority == ResourceLoadPriorityLow && !hadRequests)) { + // Try to request important resources immediately. + servePendingRequestsForHost(host, priority); + return identifier; + } + + // Handle asynchronously so early low priority requests don't get scheduled before later high priority ones. + scheduleServePendingRequests(); + return identifier; +} + +ResourceLoadIdentifier NetworkResourceLoadScheduler::addLoadInProgress(const WebCore::KURL& url) +{ + ResourceLoadIdentifier identifier = ++s_currentResourceLoadIdentifier; + + LOG(Network, "(NetworkProcess) NetworkResourceLoadScheduler::addLoadInProgress resource %llu with url '%s'", identifier, url.string().utf8().data()); + + HostRecord* host = hostForURL(url, CreateIfNotFound); + host->addLoadInProgress(identifier); + m_identifiers.add(identifier, host); + + return identifier; +} + +HostRecord* NetworkResourceLoadScheduler::hostForURL(const WebCore::KURL& url, CreateHostPolicy createHostPolicy) +{ + if (!url.protocolIsInHTTPFamily()) + return m_nonHTTPProtocolHost; + + m_hosts.checkConsistency(); + String hostName = url.host(); + HostRecord* host = m_hosts.get(hostName); + if (!host && createHostPolicy == CreateIfNotFound) { + host = new HostRecord(hostName, maxRequestsInFlightPerHost); + m_hosts.add(hostName, host); + } + + return host; +} + +void NetworkResourceLoadScheduler::removeLoadIdentifier(ResourceLoadIdentifier identifier) +{ + ASSERT(identifier); + + LOG(Network, "(NetworkProcess) NetworkResourceLoadScheduler::removeLoadIdentifier removing load identifier %llu", identifier); + + HostRecord* host = m_identifiers.take(identifier); + ASSERT(host); + if (host) + host->remove(identifier); + + scheduleServePendingRequests(); +} + +void NetworkResourceLoadScheduler::crossOriginRedirectReceived(ResourceLoadIdentifier identifier, const WebCore::KURL& redirectURL) +{ + LOG(Network, "(NetworkProcess) NetworkResourceLoadScheduler::crossOriginRedirectReceived resource %llu redirected to '%s'", identifier, redirectURL.string().utf8().data()); + + HostRecord* oldHost = m_identifiers.get(identifier); + HostRecord* newHost = hostForURL(redirectURL, CreateIfNotFound); + ASSERT(oldHost); + + if (oldHost->name() == newHost->name()) + return; + + newHost->addLoadInProgress(identifier); + m_identifiers.set(identifier, newHost); + + oldHost->remove(identifier); +} + +void NetworkResourceLoadScheduler::servePendingRequests(ResourceLoadPriority minimumPriority) +{ + if (m_suspendPendingRequestsCount) + return; + + LOG(Network, "(NetworkProcess) NetworkResourceLoadScheduler::servePendingRequests Serving requests for up to %i hosts", m_hosts.size()); + + m_requestTimer.stop(); + + servePendingRequestsForHost(m_nonHTTPProtocolHost, minimumPriority); + + m_hosts.checkConsistency(); + Vector<HostRecord*> hostsToServe; + copyValuesToVector(m_hosts, hostsToServe); + + size_t size = hostsToServe.size(); + for (size_t i = 0; i < size; ++i) { + HostRecord* host = hostsToServe[i]; + if (host->hasRequests()) + servePendingRequestsForHost(host, minimumPriority); + else + delete m_hosts.take(host->name()); + } +} + +void NetworkResourceLoadScheduler::servePendingRequestsForHost(HostRecord* host, ResourceLoadPriority minimumPriority) +{ + LOG(Network, "NetworkResourceLoadScheduler::servePendingRequests Host name='%s'", host->name().utf8().data()); + + for (int priority = ResourceLoadPriorityHighest; priority >= minimumPriority; --priority) { + HostRecord::RequestQueue& requestsPending = host->requestsPending(ResourceLoadPriority(priority)); + + while (!requestsPending.isEmpty()) { + RefPtr<NetworkRequest> request = requestsPending.first(); + + // This request might be from WebProcess we've lost our connection to. + // If so we should just skip it. + if (!request->connectionToWebProcess()) { + requestsPending.removeFirst(); + continue; + } + + // For named hosts - which are only http(s) hosts - we should always enforce the connection limit. + // For non-named hosts - everything but http(s) - we should only enforce the limit if the document + // isn't done parsing and we don't know all stylesheets yet. + + // FIXME (NetworkProcess): The above comment about document parsing and stylesheets is a holdover + // from the WebCore::ResourceLoadScheduler. + // The behavior described was at one time important for WebCore's single threadedness. + // It's possible that we don't care about it with the NetworkProcess. + // We should either decide it's not important and change the above comment, or decide it is + // still important and somehow account for it. + + bool shouldLimitRequests = !host->name().isNull(); + if (shouldLimitRequests && host->limitRequests(ResourceLoadPriority(priority), request->connectionToWebProcess()->isSerialLoadingEnabled())) + return; + + requestsPending.removeFirst(); + host->addLoadInProgress(request->identifier()); + + request->connectionToWebProcess()->connection()->send(Messages::NetworkProcessConnection::StartResourceLoad(request->identifier()), 0); + } + } +} + +void NetworkResourceLoadScheduler::suspendPendingRequests() +{ + ++m_suspendPendingRequestsCount; +} + +void NetworkResourceLoadScheduler::resumePendingRequests() +{ + ASSERT(m_suspendPendingRequestsCount); + --m_suspendPendingRequestsCount; + if (m_suspendPendingRequestsCount) + return; + + if (!m_hosts.isEmpty() || m_nonHTTPProtocolHost->hasRequests()) + scheduleServePendingRequests(); +} + +} // namespace WebKit + +#endif // ENABLE(NETWORK_PROCESS) diff --git a/Source/WebKit2/NetworkProcess/NetworkResourceLoadScheduler.h b/Source/WebKit2/NetworkProcess/NetworkResourceLoadScheduler.h new file mode 100644 index 000000000..a16a38847 --- /dev/null +++ b/Source/WebKit2/NetworkProcess/NetworkResourceLoadScheduler.h @@ -0,0 +1,93 @@ +/* + * 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 NetworkResourceLoadScheduler_h +#define NetworkResourceLoadScheduler_h + +#include <WebCore/ResourceRequest.h> +#include <WebCore/Timer.h> + +#if ENABLE(NETWORK_PROCESS) + +namespace WebKit { + +class HostRecord; +class NetworkConnectionToWebProcess; +typedef uint64_t ResourceLoadIdentifier; + +class NetworkResourceLoadScheduler { + WTF_MAKE_NONCOPYABLE(NetworkResourceLoadScheduler); WTF_MAKE_FAST_ALLOCATED; + +public: + NetworkResourceLoadScheduler(); + + // Adds the request to the queue for its host and create a unique identifier for it. + ResourceLoadIdentifier scheduleNetworkRequest(const WebCore::ResourceRequest&, WebCore::ResourceLoadPriority, NetworkConnectionToWebProcess*); + + // Creates a unique identifier for an already-in-progress load. + ResourceLoadIdentifier addLoadInProgress(const WebCore::KURL&); + + // Called by the WebProcess when a ResourceLoader is being cleaned up. + void removeLoadIdentifier(ResourceLoadIdentifier); + + void crossOriginRedirectReceived(ResourceLoadIdentifier, const WebCore::KURL& redirectURL); + void servePendingRequests(WebCore::ResourceLoadPriority = WebCore::ResourceLoadPriorityVeryLow); + void suspendPendingRequests(); + void resumePendingRequests(); + +private: + enum CreateHostPolicy { + CreateIfNotFound, + FindOnly + }; + + HostRecord* hostForURL(const WebCore::KURL&, CreateHostPolicy = FindOnly); + + void scheduleServePendingRequests(); + void requestTimerFired(WebCore::Timer<NetworkResourceLoadScheduler>*); + + void servePendingRequestsForHost(HostRecord*, WebCore::ResourceLoadPriority); + + unsigned platformInitializeMaximumHTTPConnectionCountPerHost(); + + typedef HashMap<String, HostRecord*, StringHash> HostMap; + HostMap m_hosts; + + typedef HashMap<ResourceLoadIdentifier, HostRecord*> IdentifierHostMap; + IdentifierHostMap m_identifiers; + + HostRecord* m_nonHTTPProtocolHost; + + unsigned m_suspendPendingRequestsCount; + bool m_isSerialLoadingEnabled; + + WebCore::Timer<NetworkResourceLoadScheduler> m_requestTimer; +}; + +} // namespace WebKit + +#endif // ENABLE(NETWORK_PROCESS) + +#endif // NetworkResourceLoadScheduler_h diff --git a/Source/WebKit2/NetworkProcess/mac/NetworkProcessMainMac.mm b/Source/WebKit2/NetworkProcess/mac/NetworkProcessMainMac.mm index 537126f66..c56f80a2a 100644 --- a/Source/WebKit2/NetworkProcess/mac/NetworkProcessMainMac.mm +++ b/Source/WebKit2/NetworkProcess/mac/NetworkProcessMainMac.mm @@ -33,6 +33,7 @@ #import "NetworkProcess.h" #import <WebCore/RunLoop.h> #import <WebKitSystemInterface.h> +#import <WebSystemInterface.h> #import <mach/mach_error.h> #import <runtime/InitializeThreading.h> #import <servers/bootstrap.h> @@ -78,7 +79,7 @@ int NetworkProcessMain(const CommandLine& commandLine) signal(SIGSEGV, _exit); #endif - + InitWebCoreSystemInterface(); JSC::initializeThreading(); WTF::initializeMainThread(); RunLoop::initializeMainRunLoop(); diff --git a/Source/WebKit2/NetworkProcess/mac/NetworkResourceLoadSchedulerMac.mm b/Source/WebKit2/NetworkProcess/mac/NetworkResourceLoadSchedulerMac.mm new file mode 100644 index 000000000..14b3657b9 --- /dev/null +++ b/Source/WebKit2/NetworkProcess/mac/NetworkResourceLoadSchedulerMac.mm @@ -0,0 +1,71 @@ +/* + * 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 "NetworkResourceLoadScheduler.h" + +#import <WebCore/ResourceRequest.h> +#import <WebCore/ResourceRequestCFNet.h> +#import <WebCore/WebCoreSystemInterface.h> +#import <WebKitSystemInterface.h> + +#if ENABLE(NETWORK_PROCESS) + +using namespace WebCore; + +namespace WebKit { + +unsigned NetworkResourceLoadScheduler::platformInitializeMaximumHTTPConnectionCountPerHost() +{ + wkInitializeMaximumHTTPConnectionCountPerHost = WKInitializeMaximumHTTPConnectionCountPerHost; + wkSetHTTPPipeliningMaximumPriority = WKSetHTTPPipeliningMaximumPriority; + wkSetHTTPPipeliningMinimumFastLanePriority = WKSetHTTPPipeliningMinimumFastLanePriority; + + static const unsigned preferredConnectionCount = 6; + static const unsigned unlimitedConnectionCount = 10000; + + // Always set the connection count per host, even when pipelining. + unsigned maximumHTTPConnectionCountPerHost = wkInitializeMaximumHTTPConnectionCountPerHost(preferredConnectionCount); + + Boolean keyExistsAndHasValidFormat = false; + Boolean prefValue = CFPreferencesGetAppBooleanValue(CFSTR("WebKitEnableHTTPPipelining"), kCFPreferencesCurrentApplication, &keyExistsAndHasValidFormat); + + if (keyExistsAndHasValidFormat) + ResourceRequest::setHTTPPipeliningEnabled(prefValue); + + if (ResourceRequest::httpPipeliningEnabled()) { + wkSetHTTPPipeliningMaximumPriority(toHTTPPipeliningPriority(ResourceLoadPriorityHighest)); + wkSetHTTPPipeliningMinimumFastLanePriority(toHTTPPipeliningPriority(ResourceLoadPriorityMedium)); + + // When pipelining do not rate-limit requests sent from WebCore since CFNetwork handles that. + return unlimitedConnectionCount; + } + + return maximumHTTPConnectionCountPerHost; +} + +} // namespace WebKit + +#endif // ENABLE(NETWORK_PROCESS) diff --git a/Source/WebKit2/NetworkProcess/mac/RemoteNetworkingContext.h b/Source/WebKit2/NetworkProcess/mac/RemoteNetworkingContext.h new file mode 100644 index 000000000..2c1827861 --- /dev/null +++ b/Source/WebKit2/NetworkProcess/mac/RemoteNetworkingContext.h @@ -0,0 +1,57 @@ +/* + * 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 RemoteNetworkingContext_h +#define RemoteNetworkingContext_h + +#include <WebCore/NetworkingContext.h> + +namespace WebKit { + +class RemoteNetworkingContext : public WebCore::NetworkingContext { +public: + static PassRefPtr<RemoteNetworkingContext> create(bool needsSiteSpecificQuirks, bool localFileContentSniffingEnabled) + { + return adoptRef(new RemoteNetworkingContext(needsSiteSpecificQuirks, localFileContentSniffingEnabled)); + } + virtual ~RemoteNetworkingContext(); + +private: + RemoteNetworkingContext(bool needsSiteSpecificQuirks, bool localFileContentSniffingEnabled); + + virtual bool isValid() const OVERRIDE; + + virtual bool needsSiteSpecificQuirks() const OVERRIDE; + virtual bool localFileContentSniffingEnabled() const OVERRIDE; + virtual NSOperationQueue *scheduledOperationQueue() const OVERRIDE; + virtual WebCore::ResourceError blockedError(const WebCore::ResourceRequest&) const OVERRIDE; + + bool m_needsSiteSpecificQuirks; + bool m_localFileContentSniffingEnabled; +}; + +} + +#endif // RemoteNetworkingContext_h diff --git a/Source/WebKit2/NetworkProcess/mac/RemoteNetworkingContext.mm b/Source/WebKit2/NetworkProcess/mac/RemoteNetworkingContext.mm new file mode 100644 index 000000000..7b29773cf --- /dev/null +++ b/Source/WebKit2/NetworkProcess/mac/RemoteNetworkingContext.mm @@ -0,0 +1,77 @@ +/* + * 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 "RemoteNetworkingContext.h" + +#import "WebCore/ResourceError.h" +#import "WebErrors.h" + +using namespace WebCore; + +namespace WebKit { + +RemoteNetworkingContext::RemoteNetworkingContext(bool needsSiteSpecificQuirks, bool localFileContentSniffingEnabled) + : m_needsSiteSpecificQuirks(needsSiteSpecificQuirks) + , m_localFileContentSniffingEnabled(localFileContentSniffingEnabled) +{ +} + +RemoteNetworkingContext::~RemoteNetworkingContext() +{ +} + +bool RemoteNetworkingContext::isValid() const +{ + return true; +} + +bool RemoteNetworkingContext::needsSiteSpecificQuirks() const +{ + return m_needsSiteSpecificQuirks; +} + +bool RemoteNetworkingContext::localFileContentSniffingEnabled() const +{ + return m_localFileContentSniffingEnabled; +} + +NSOperationQueue *RemoteNetworkingContext::scheduledOperationQueue() const +{ + static NSOperationQueue *queue; + if (!queue) { + queue = [[NSOperationQueue alloc] init]; + // Default concurrent operation count depends on current system workload, but delegate methods are mostly idling in IPC, so we can run as many as needed. + [queue setMaxConcurrentOperationCount:NSIntegerMax]; + } + return queue; +} + +ResourceError RemoteNetworkingContext::blockedError(const ResourceRequest& request) const +{ + return WebKit::blockedError(request); +} + +} |