2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #import "WebDocumentLoaderMac.h"
31 #import "WebKitVersionChecks.h"
34 using namespace WebCore;
36 WebDocumentLoaderMac::WebDocumentLoaderMac(const ResourceRequest& request, const SubstituteData& substituteData)
37 : DocumentLoader(request, substituteData)
39 , m_isDataSourceRetained(false)
43 static inline bool needsDataLoadWorkaround(WebView *webView)
45 static bool needsWorkaround = !WebKitLinkedOnOrAfter(WEBKIT_FIRST_VERSION_WITHOUT_ADOBE_INSTALLER_QUIRK)
46 && [[[NSBundle mainBundle] bundleIdentifier] isEqualToString:@"com.adobe.Installers.Setup"];
47 return needsWorkaround;
50 void WebDocumentLoaderMac::setDataSource(WebDataSource *dataSource, WebView *webView)
52 ASSERT(!m_dataSource);
53 ASSERT(!m_isDataSourceRetained);
55 m_dataSource = dataSource;
58 m_resourceLoadDelegate = [webView resourceLoadDelegate];
59 m_downloadDelegate = [webView downloadDelegate];
61 // Some clients run the run loop in a way that prevents the data load timer
62 // from firing. We work around that issue here. See <rdar://problem/5266289>
63 // and <rdar://problem/5049509>.
64 if (needsDataLoadWorkaround(webView))
65 m_deferMainResourceDataLoad = false;
68 WebDataSource *WebDocumentLoaderMac::dataSource() const
73 void WebDocumentLoaderMac::attachToFrame()
75 DocumentLoader::attachToFrame();
80 void WebDocumentLoaderMac::detachFromFrame()
82 DocumentLoader::detachFromFrame();
84 if (m_loadingResources.isEmpty())
87 // FIXME: What prevents the data source from getting deallocated while the
88 // frame is not attached?
91 void WebDocumentLoaderMac::increaseLoadCount(unsigned long identifier)
95 if (m_loadingResources.contains(identifier))
97 m_loadingResources.add(identifier);
102 void WebDocumentLoaderMac::decreaseLoadCount(unsigned long identifier)
104 HashSet<unsigned long>::iterator it = m_loadingResources.find(identifier);
106 // It is valid for a load to be cancelled before it's started.
107 if (it == m_loadingResources.end())
110 m_loadingResources.remove(it);
112 if (m_loadingResources.isEmpty()) {
113 m_resourceLoadDelegate = 0;
114 m_downloadDelegate = 0;
120 void WebDocumentLoaderMac::retainDataSource()
122 if (m_isDataSourceRetained || !m_dataSource)
124 m_isDataSourceRetained = true;
125 CFRetain(m_dataSource);
128 void WebDocumentLoaderMac::releaseDataSource()
130 if (!m_isDataSourceRetained)
132 ASSERT(m_dataSource);
133 m_isDataSourceRetained = false;
134 CFRelease(m_dataSource);
137 void WebDocumentLoaderMac::detachDataSource()
139 ASSERT(!m_isDataSourceRetained);