summaryrefslogtreecommitdiffstats
path: root/WebCore/loader/mac
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-03-03 19:30:52 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2009-03-03 19:30:52 -0800
commit8e35f3cfc7fba1d1c829dc557ebad6409cbe16a2 (patch)
tree11425ea0b299d6fb89c6d3618a22d97d5bf68d0f /WebCore/loader/mac
parent648161bb0edfc3d43db63caed5cc5213bc6cb78f (diff)
downloadexternal_webkit-8e35f3cfc7fba1d1c829dc557ebad6409cbe16a2.zip
external_webkit-8e35f3cfc7fba1d1c829dc557ebad6409cbe16a2.tar.gz
external_webkit-8e35f3cfc7fba1d1c829dc557ebad6409cbe16a2.tar.bz2
auto import from //depot/cupcake/@135843
Diffstat (limited to 'WebCore/loader/mac')
-rw-r--r--WebCore/loader/mac/DocumentLoaderMac.cpp79
-rw-r--r--WebCore/loader/mac/LoaderNSURLExtras.h39
-rw-r--r--WebCore/loader/mac/LoaderNSURLExtras.mm102
-rw-r--r--WebCore/loader/mac/ResourceLoaderMac.mm43
4 files changed, 263 insertions, 0 deletions
diff --git a/WebCore/loader/mac/DocumentLoaderMac.cpp b/WebCore/loader/mac/DocumentLoaderMac.cpp
new file mode 100644
index 0000000..05c6e26
--- /dev/null
+++ b/WebCore/loader/mac/DocumentLoaderMac.cpp
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2008 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.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE 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 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 "DocumentLoader.h"
+#include "MainResourceLoader.h"
+#include "ResourceHandle.h"
+#include "ResourceLoader.h"
+
+namespace WebCore {
+
+#ifndef BUILDING_ON_TIGER
+static void scheduleAll(const ResourceLoaderSet& loaders, SchedulePair* pair)
+{
+ const ResourceLoaderSet copy = loaders;
+ ResourceLoaderSet::const_iterator end = copy.end();
+ for (ResourceLoaderSet::const_iterator it = copy.begin(); it != end; ++it)
+ if (ResourceHandle* handle = (*it)->handle())
+ handle->schedule(pair);
+}
+
+static void unscheduleAll(const ResourceLoaderSet& loaders, SchedulePair* pair)
+{
+ const ResourceLoaderSet copy = loaders;
+ ResourceLoaderSet::const_iterator end = copy.end();
+ for (ResourceLoaderSet::const_iterator it = copy.begin(); it != end; ++it)
+ if (ResourceHandle* handle = (*it)->handle())
+ handle->unschedule(pair);
+}
+#endif
+
+void DocumentLoader::schedule(SchedulePair* pair)
+{
+#ifndef BUILDING_ON_TIGER
+ if (m_mainResourceLoader && m_mainResourceLoader->handle())
+ m_mainResourceLoader->handle()->schedule(pair);
+ scheduleAll(m_subresourceLoaders, pair);
+ scheduleAll(m_plugInStreamLoaders, pair);
+ scheduleAll(m_multipartSubresourceLoaders, pair);
+#endif
+}
+
+void DocumentLoader::unschedule(SchedulePair* pair)
+{
+#ifndef BUILDING_ON_TIGER
+ if (m_mainResourceLoader && m_mainResourceLoader->handle())
+ m_mainResourceLoader->handle()->unschedule(pair);
+ unscheduleAll(m_subresourceLoaders, pair);
+ unscheduleAll(m_plugInStreamLoaders, pair);
+ unscheduleAll(m_multipartSubresourceLoaders, pair);
+#endif
+}
+
+} // namespace
diff --git a/WebCore/loader/mac/LoaderNSURLExtras.h b/WebCore/loader/mac/LoaderNSURLExtras.h
new file mode 100644
index 0000000..ce5a490
--- /dev/null
+++ b/WebCore/loader/mac/LoaderNSURLExtras.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2005, 2006 Apple Computer, 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.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE 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 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 <Foundation/Foundation.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+NSString *suggestedFilenameWithMIMEType(NSURL *url, NSString *MIMEType);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/WebCore/loader/mac/LoaderNSURLExtras.mm b/WebCore/loader/mac/LoaderNSURLExtras.mm
new file mode 100644
index 0000000..9a507f5
--- /dev/null
+++ b/WebCore/loader/mac/LoaderNSURLExtras.mm
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2005, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com)
+ *
+ * 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.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE 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 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 "LoaderNSURLExtras.h"
+
+#import <wtf/Assertions.h>
+#import <wtf/Vector.h>
+#import "KURL.h"
+#import "LocalizedStrings.h"
+#import "MIMETypeRegistry.h"
+#import "PlatformString.h"
+#import "WebCoreNSStringExtras.h"
+
+using namespace WebCore;
+
+static bool vectorContainsString(const Vector<String>& vector, const String& string)
+{
+ int size = vector.size();
+ for (int i = 0; i < size; i++)
+ if (vector[i] == string)
+ return true;
+ return false;
+}
+
+NSString *suggestedFilenameWithMIMEType(NSURL *url, NSString *MIMEType)
+{
+ // Get the filename from the URL. Try the lastPathComponent first.
+ NSString *lastPathComponent = [[url path] lastPathComponent];
+ NSString *filename = filenameByFixingIllegalCharacters(lastPathComponent);
+ NSString *extension = nil;
+
+ if ([filename length] == 0 || [lastPathComponent isEqualToString:@"/"]) {
+ // lastPathComponent is no good, try the host.
+ NSString *host = KURL(url).host();
+ filename = filenameByFixingIllegalCharacters(host);
+ if ([filename length] == 0) {
+ // Can't make a filename using this URL, use "unknown".
+ filename = copyImageUnknownFileLabel();
+ }
+ } else {
+ // Save the extension for later correction. Only correct the extension of the lastPathComponent.
+ // For example, if the filename ends up being the host, we wouldn't want to correct ".com" in "www.apple.com".
+ extension = [filename pathExtension];
+ }
+
+ // No mime type reported. Just return the filename we have now.
+ if (!MIMEType) {
+ return filename;
+ }
+
+ // Do not correct filenames that are reported with a mime type of tar, and
+ // have a filename which has .tar in it or ends in .tgz
+ if (([MIMEType isEqualToString:@"application/tar"] || [MIMEType isEqualToString:@"application/x-tar"])
+ && (hasCaseInsensitiveSubstring(filename, @".tar")
+ || hasCaseInsensitiveSuffix(filename, @".tgz"))) {
+ return filename;
+ }
+
+ // I don't think we need to worry about this for the image case
+ // If the type is known, check the extension and correct it if necessary.
+ if (![MIMEType isEqualToString:@"application/octet-stream"] && ![MIMEType isEqualToString:@"text/plain"]) {
+ Vector<String> extensions = MIMETypeRegistry::getExtensionsForMIMEType(MIMEType);
+
+ if (extensions.isEmpty() || !vectorContainsString(extensions, extension)) {
+ // The extension doesn't match the MIME type. Correct this.
+ NSString *correctExtension = MIMETypeRegistry::getPreferredExtensionForMIMEType(MIMEType);
+ if ([correctExtension length] != 0) {
+ // Append the correct extension.
+ filename = [filename stringByAppendingPathExtension:correctExtension];
+ }
+ }
+ }
+
+ return filename;
+}
diff --git a/WebCore/loader/mac/ResourceLoaderMac.mm b/WebCore/loader/mac/ResourceLoaderMac.mm
new file mode 100644
index 0000000..9769ac9
--- /dev/null
+++ b/WebCore/loader/mac/ResourceLoaderMac.mm
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2007 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.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE 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 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 "ResourceLoader.h"
+
+#include "FrameLoader.h"
+#include "FrameLoaderClient.h"
+#include "ResourceHandle.h"
+
+namespace WebCore {
+
+NSCachedURLResponse* ResourceLoader::willCacheResponse(ResourceHandle* handle, NSCachedURLResponse* response)
+{
+ return frameLoader()->client()->willCacheResponse(documentLoader(), identifier(), response);
+}
+
+}