Commit f3330d64 authored by andersca@apple.com's avatar andersca@apple.com

2008-05-21 Anders Carlsson <andersca@apple.com>

        Reviewed by Mitz.

        Add IconFetcher implementation.

        * WebCore.base.exp:
        * WebCore.xcodeproj/project.pbxproj:
        * html/HTMLLinkElement.h:
        (WebCore::HTMLLinkElement::isIcon):
        * loader/icon/IconFetcher.cpp: Added.
        (WebCore::IconLinkEntry::):
        (WebCore::IconLinkEntry::IconLinkEntry):
        (WebCore::IconLinkEntry::type):
        (WebCore::IconLinkEntry::url):
        (WebCore::IconLinkEntry::buffer):
        (WebCore::parseIconLink):
        (WebCore::IconFetcher::create):
        (WebCore::IconFetcher::IconFetcher):
        (WebCore::IconFetcher::~IconFetcher):
        (WebCore::IconFetcher::cancel):
        (WebCore::IconFetcher::createIcon):
        (WebCore::IconFetcher::loadEntry):
        (WebCore::IconFetcher::loadFailed):
        (WebCore::IconFetcher::didReceiveResponse):
        (WebCore::IconFetcher::didReceiveData):
        (WebCore::IconFetcher::didFinishLoading):
        (WebCore::IconFetcher::didFail):
        * loader/icon/IconFetcher.h: Added.
        (WebCore::IconFetcherClient::~IconFetcherClient):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@33978 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 36ebc02c
2008-05-21 Anders Carlsson <andersca@apple.com>
Reviewed by Mitz.
Add IconFetcher implementation.
* WebCore.base.exp:
* WebCore.xcodeproj/project.pbxproj:
* html/HTMLLinkElement.h:
(WebCore::HTMLLinkElement::isIcon):
* loader/icon/IconFetcher.cpp: Added.
(WebCore::IconLinkEntry::):
(WebCore::IconLinkEntry::IconLinkEntry):
(WebCore::IconLinkEntry::type):
(WebCore::IconLinkEntry::url):
(WebCore::IconLinkEntry::buffer):
(WebCore::parseIconLink):
(WebCore::IconFetcher::create):
(WebCore::IconFetcher::IconFetcher):
(WebCore::IconFetcher::~IconFetcher):
(WebCore::IconFetcher::cancel):
(WebCore::IconFetcher::createIcon):
(WebCore::IconFetcher::loadEntry):
(WebCore::IconFetcher::loadFailed):
(WebCore::IconFetcher::didReceiveResponse):
(WebCore::IconFetcher::didReceiveData):
(WebCore::IconFetcher::didFinishLoading):
(WebCore::IconFetcher::didFail):
* loader/icon/IconFetcher.h: Added.
(WebCore::IconFetcherClient::~IconFetcherClient):
2008-05-21 Dan Bernstein <mitz@apple.com>
Reviewed by Dave Hyatt.
......@@ -76,6 +76,8 @@ __ZN7WebCore11HistoryItemC1ERKNS_6StringES3_d
__ZN7WebCore11HistoryItemC1ERKNS_6StringES3_S3_d
__ZN7WebCore11HistoryItemC1Ev
__ZN7WebCore11HistoryItemD1Ev
__ZN7WebCore11IconFetcher6cancelEv
__ZN7WebCore11IconFetcher6createEPNS_5FrameEPNS_17IconFetcherClientE
__ZN7WebCore11RenderLayer18gAlignCenterAlwaysE
__ZN7WebCore11RenderLayer19scrollRectToVisibleERKNS_7IntRectERKNS0_15ScrollAlignmentES6_
__ZN7WebCore11RenderLayer20gAlignToEdgeIfNeededE
......
......@@ -92,6 +92,8 @@
1A2A68240B5BEDE70002A480 /* ProgressTracker.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A2A68220B5BEDE70002A480 /* ProgressTracker.h */; settings = {ATTRIBUTES = (Private, ); }; };
1A2AAC580DC2A3B100A20D9A /* ApplicationCacheStorage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A2AAC560DC2A3B100A20D9A /* ApplicationCacheStorage.cpp */; };
1A2AAC590DC2A3B100A20D9A /* ApplicationCacheStorage.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A2AAC570DC2A3B100A20D9A /* ApplicationCacheStorage.h */; settings = {ATTRIBUTES = (Private, ); }; };
1A2D753D0DE47FAB00F0A648 /* IconFetcher.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A2D753B0DE47FAB00F0A648 /* IconFetcher.h */; settings = {ATTRIBUTES = (Private, ); }; };
1A2D753E0DE47FAB00F0A648 /* IconFetcher.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A2D753C0DE47FAB00F0A648 /* IconFetcher.cpp */; };
1A2E6E590CC55213004A2062 /* SQLValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A2E6E570CC55213004A2062 /* SQLValue.cpp */; };
1A2E6E5A0CC55213004A2062 /* SQLValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A2E6E580CC55213004A2062 /* SQLValue.h */; };
1A2E6E7A0CC556D5004A2062 /* SQLiteAuthorizer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A2E6E780CC556D5004A2062 /* SQLiteAuthorizer.cpp */; };
......@@ -4542,6 +4544,8 @@
1A2A68220B5BEDE70002A480 /* ProgressTracker.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ProgressTracker.h; sourceTree = "<group>"; };
1A2AAC560DC2A3B100A20D9A /* ApplicationCacheStorage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ApplicationCacheStorage.cpp; sourceTree = "<group>"; };
1A2AAC570DC2A3B100A20D9A /* ApplicationCacheStorage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ApplicationCacheStorage.h; sourceTree = "<group>"; };
1A2D753B0DE47FAB00F0A648 /* IconFetcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IconFetcher.h; sourceTree = "<group>"; };
1A2D753C0DE47FAB00F0A648 /* IconFetcher.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IconFetcher.cpp; sourceTree = "<group>"; };
1A2E6E570CC55213004A2062 /* SQLValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SQLValue.cpp; path = sql/SQLValue.cpp; sourceTree = "<group>"; };
1A2E6E580CC55213004A2062 /* SQLValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SQLValue.h; path = sql/SQLValue.h; sourceTree = "<group>"; };
1A2E6E780CC556D5004A2062 /* SQLiteAuthorizer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SQLiteAuthorizer.cpp; path = sql/SQLiteAuthorizer.cpp; sourceTree = "<group>"; };
......@@ -8625,6 +8629,7 @@
1A8F6BB00DB55CDC001DB794 /* appcache */ = {
isa = PBXGroup;
children = (
5126E6B60A2E3AEF005C29FA /* icon */,
1A8F6BB10DB55CDC001DB794 /* ApplicationCache.cpp */,
1A8F6BB20DB55CDC001DB794 /* ApplicationCache.h */,
1A8F6BB30DB55CDC001DB794 /* ApplicationCacheGroup.cpp */,
......@@ -8763,6 +8768,8 @@
5126E6B90A2E3B12005C29FA /* IconDatabase.cpp */,
5126E6BA0A2E3B12005C29FA /* IconDatabase.h */,
51E1ECB80C91C90400DC255B /* IconDatabaseClient.h */,
1A2D753C0DE47FAB00F0A648 /* IconFetcher.cpp */,
1A2D753B0DE47FAB00F0A648 /* IconFetcher.h */,
513F14510AB634C400094DDF /* IconLoader.cpp */,
513F14520AB634C400094DDF /* IconLoader.h */,
51E1ECBA0C91C90400DC255B /* IconRecord.cpp */,
......@@ -8770,7 +8777,8 @@
51E1ECBC0C91C90400DC255B /* PageURLRecord.cpp */,
51E1ECBD0C91C90400DC255B /* PageURLRecord.h */,
);
path = icon;
name = icon;
path = ../icon;
sourceTree = "<group>";
};
512DD8E80D91E691000F89EE /* archive */ = {
......@@ -12361,7 +12369,6 @@
1A8F6BB00DB55CDC001DB794 /* appcache */,
512DD8E80D91E691000F89EE /* archive */,
93A1EAA20A5634D8006960A0 /* mac */,
5126E6B60A2E3AEF005C29FA /* icon */,
BCB16BFE0979C3BD00467741 /* Cache.cpp */,
BCB16BFF0979C3BD00467741 /* Cache.h */,
BCB16C000979C3BD00467741 /* CachedCSSStyleSheet.cpp */,
......@@ -15119,6 +15126,7 @@
95969B4A0DD8D21B00F653EE /* JavaScriptProfile.h in Headers */,
1A7FA6190DDA3B3A0028F8A5 /* NetworkStateNotifier.h in Headers */,
9362640B0DE1137D009D5A00 /* CSSReflectionDirection.h in Headers */,
1A2D753D0DE47FAB00F0A648 /* IconFetcher.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -16837,6 +16845,7 @@
95969B490DD8D21B00F653EE /* JavaScriptProfile.cpp in Sources */,
1A7FA61B0DDA3BBE0028F8A5 /* NetworkStateNotifier.cpp in Sources */,
1A7FA6490DDA3CBA0028F8A5 /* NetworkStateNotifierMac.cpp in Sources */,
1A2D753E0DE47FAB00F0A648 /* IconFetcher.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -85,7 +85,8 @@ public:
bool isAlternate() const { return m_disabledState == 0 && m_alternate; }
bool isDisabled() const { return m_disabledState == 2; }
bool isEnabledViaScript() const { return m_disabledState == 1; }
bool isIcon() const { return m_isIcon; }
int disabledState() { return m_disabledState; }
void setDisabledState(bool _disabled);
......
/*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``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
* 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 "IconFetcher.h"
#include "Document.h"
#include "Frame.h"
#include "HTMLHeadElement.h"
#include "HTMLLinkElement.h"
#include "HTMLNames.h"
#include "MIMETypeRegistry.h"
#include "ResourceHandle.h"
#include "ResourceRequest.h"
#include "SharedBuffer.h"
#include <wtf/PassRefPtr.h>
namespace WebCore {
using namespace HTMLNames;
struct IconLinkEntry {
public:
enum IconType {
Unknown,
ICNS,
ICO,
};
IconLinkEntry(IconType type, const KURL& url)
: m_type(type)
, m_url(url)
{
}
IconType type() const { return m_type; }
const KURL& url() const { return m_url; }
SharedBuffer* buffer()
{
if (!m_buffer)
m_buffer = SharedBuffer::create();
return m_buffer.get();
}
private:
RefPtr<SharedBuffer> m_buffer;
IconType m_type;
KURL m_url;
};
#if PLATFORM(MAC)
static const IconLinkEntry::IconType NativeIconType = IconLinkEntry::ICNS;
#elif PLATFORM(WIN)
static const IconLinkEntry::IconType NativeIconType = IconLinkEntry::ICO;
#else
static const IconLinkEntry::IconType NativeIconType = IconLinkEntry::Unknown;
#endif
static void parseIconLink(HTMLLinkElement* link, Vector<IconLinkEntry>& entries)
{
// FIXME: Parse the size attribute too.
IconLinkEntry::IconType type = IconLinkEntry::Unknown;
const KURL& url = link->href();
// Try to determine the file type.
String path = url.path();
int pos = path.reverseFind('.');
if (pos >= 0) {
String extension = path.substring(pos + 1);
if (equalIgnoringCase(extension, "icns"))
type = IconLinkEntry::ICNS;
else if (equalIgnoringCase(extension, "ico"))
type = IconLinkEntry::ICO;
}
entries.append(IconLinkEntry(type, url));
}
PassRefPtr<IconFetcher> IconFetcher::create(Frame* frame, IconFetcherClient* client)
{
Document* document = frame->document();
if (!document)
return 0;
HTMLHeadElement* head = document->head();
if (!head)
return 0;
Vector<IconLinkEntry> entries;
for (Node* n = head; n; n = n->traverseNextNode()) {
if (!n->hasTagName(linkTag))
continue;
HTMLLinkElement* link = static_cast<HTMLLinkElement*>(n);
if (!link->isIcon())
continue;
parseIconLink(link, entries);
}
if (entries.isEmpty())
return 0;
// Check if any of the entries have the same type as the native icon type.
// FIXME: This should be way more sophisticated, and handle conversion
// of multisize formats for example.
for (unsigned i = 0; i < entries.size(); i++) {
const IconLinkEntry& entry = entries[i];
if (entry.type() == NativeIconType) {
RefPtr<IconFetcher> iconFetcher = adoptRef(new IconFetcher(frame, client));
iconFetcher->m_entries.append(entry);
iconFetcher->loadEntry();
return iconFetcher.release();
}
}
return 0;
}
IconFetcher::IconFetcher(Frame* frame, IconFetcherClient* client)
: m_frame(frame)
, m_client(client)
, m_currentEntry(0)
{
}
IconFetcher::~IconFetcher()
{
cancel();
}
void IconFetcher::cancel()
{
if (m_handle)
m_handle->cancel();
}
PassRefPtr<SharedBuffer> IconFetcher::createIcon()
{
ASSERT(!m_entries.isEmpty());
// For now, just return the data of the first entry.
return m_entries.first().buffer();
}
void IconFetcher::loadEntry()
{
ASSERT(m_currentEntry < m_entries.size());
ASSERT(!m_handle);
m_handle = ResourceHandle::create(m_entries[m_currentEntry].url(), this, m_frame, false, false);
}
void IconFetcher::loadFailed()
{
m_handle = 0;
m_client->finishedFetchingIcon(0);
}
void IconFetcher::didReceiveResponse(ResourceHandle* handle, const ResourceResponse& response)
{
ASSERT(m_handle == handle);
int statusCode = response.httpStatusCode() / 100;
if (statusCode == 4 || statusCode == 5) {
loadFailed();
return;
}
}
void IconFetcher::didReceiveData(ResourceHandle* handle, const char* data, int length, int lengthReceived)
{
ASSERT(m_handle == handle);
m_entries[m_currentEntry].buffer()->append(data, length);
}
void IconFetcher::didFinishLoading(ResourceHandle* handle)
{
ASSERT(m_handle == handle);
if (m_currentEntry == m_entries.size() - 1) {
// We finished loading, create the icon
RefPtr<SharedBuffer> iconData = createIcon();
m_client->finishedFetchingIcon(iconData.release());
return;
}
// Load the next entry
m_currentEntry++;
loadEntry();
}
void IconFetcher::didFail(ResourceHandle* handle, const ResourceError&)
{
ASSERT(m_handle == handle);
loadFailed();
}
} // namespace WebCore
/*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``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
* 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 IconFetcher_h
#define IconFetcher_h
#include <wtf/RefCounted.h>
#include <wtf/Forward.h>
#include <wtf/Vector.h>
#include "ResourceHandleClient.h"
namespace WebCore {
class Frame;
struct IconLinkEntry;
class ResourceHandle;
class SharedBuffer;
class IconFetcherClient {
public:
virtual void finishedFetchingIcon(PassRefPtr<SharedBuffer> iconData) = 0;
virtual ~IconFetcherClient() { }
};
class IconFetcher : public RefCounted<IconFetcher>, ResourceHandleClient {
public:
static PassRefPtr<IconFetcher> create(Frame*, IconFetcherClient*);
~IconFetcher();
void cancel();
private:
IconFetcher(Frame*, IconFetcherClient*);
void loadEntry();
void loadFailed();
PassRefPtr<SharedBuffer> createIcon();
virtual void didReceiveResponse(ResourceHandle*, const ResourceResponse&);
virtual void didReceiveData(ResourceHandle*, const char*, int, int lengthReceived);
virtual void didFinishLoading(ResourceHandle*);
virtual void didFail(ResourceHandle*, const ResourceError&);
Frame* m_frame;
IconFetcherClient* m_client;
unsigned m_currentEntry;
RefPtr<ResourceHandle> m_handle;
Vector<IconLinkEntry> m_entries;
};
} // namespace WebCore
#endif // IconFetcher_h
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment