Changeset 95593 in webkit
- Timestamp:
- Sep 20, 2011 6:49:03 PM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r95591 r95593 1 2011-09-20 Rachel Blum <groby@chromium.org> 2 3 Support for multiple <link rel="icon"> favicon elements. 4 https://bugs.webkit.org/show_bug.cgi?id=65564 5 6 Reviewed by Darin Fisher. 7 8 No tests - purely an API change. (And API is not exposed to LayoutTests) 9 10 * dom/Document.cpp: 11 (WebCore::Document::iconURLs): 12 (WebCore::Document::addIconURL): 13 * dom/Document.h: 14 * dom/IconURL.cpp: 15 (WebCore::toIconIndex): 16 * dom/IconURL.h: 17 (WebCore::IconURL::IconURL): 18 * html/HTMLLinkElement.cpp: 19 (WebCore::HTMLLinkElement::process): 20 * loader/LinkLoader.cpp: 21 (WebCore::LinkLoader::loadLink): 22 * loader/LinkLoader.h: 23 * loader/icon/IconController.cpp: 24 (WebCore::IconController::urlsForTypes): 25 (WebCore::IconController::appendToIconURLs): 26 (WebCore::IconController::defaultURL): 27 1 28 2011-09-20 Ojan Vafai <ojan@chromium.org> 2 29 -
trunk/Source/WebCore/dom/Document.cpp
r95535 r95593 6 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011 Apple Inc. All rights reserved. 7 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) 8 * Copyright (C) 2008, 2009 Google Inc. All rights reserved.8 * Copyright (C) 2008, 2009, 2011 Google Inc. All rights reserved. 9 9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 10 10 * … … 4431 4431 } 4432 4432 4433 IconURL Document::iconURL(IconType iconType) const 4434 { 4435 return m_iconURLs[toIconIndex(iconType)]; 4436 } 4437 4438 void Document::setIconURL(const String& url, const String& mimeType, IconType iconType) 4439 { 4433 const Vector<IconURL>& Document::iconURLs() const 4434 { 4435 return m_iconURLs; 4436 } 4437 4438 void Document::addIconURL(const String& url, const String& mimeType, const String& sizes, IconType iconType) 4439 { 4440 if (url.isEmpty()) 4441 return; 4442 4440 4443 // FIXME - <rdar://problem/4727645> - At some point in the future, we might actually honor the "mimeType" 4441 IconURL newURL(KURL(ParsedURLString, url), iconType); 4442 if (iconURL(iconType).m_iconURL.isEmpty()) 4443 setIconURL(newURL); 4444 else if (!mimeType.isEmpty()) 4445 setIconURL(newURL); 4446 if (Frame* f = frame()) 4447 f->loader()->icon()->setURL(newURL); 4448 } 4449 4450 void Document::setIconURL(const IconURL& iconURL) 4451 { 4452 m_iconURLs[toIconIndex(iconURL.m_iconType)] = iconURL; 4444 IconURL newURL(KURL(ParsedURLString, url), sizes, mimeType, iconType); 4445 m_iconURLs.append(newURL); 4446 4447 if (Frame* f = frame()) { 4448 IconURL iconURL = f->loader()->icon()->iconURL(iconType); 4449 if (iconURL == newURL) 4450 f->loader()->didChangeIcons(iconType); 4451 } 4453 4452 } 4454 4453 -
trunk/Source/WebCore/dom/Document.h
r95271 r95593 7 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) 8 8 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 9 * Copyright (C) 2011 Google Inc. All rights reserved. 9 10 * 10 11 * This library is free software; you can redistribute it and/or … … 918 919 void setHasNodesWithPlaceholderStyle() { m_hasNodesWithPlaceholderStyle = true; } 919 920 920 IconURL iconURL(IconType) const; 921 void setIconURL(const String&, const String&, IconType); 922 void setIconURL(const IconURL&); 921 const Vector<IconURL>& iconURLs() const; 922 void addIconURL(const String& url, const String& mimeType, const String& size, IconType); 923 923 924 924 void setUseSecureKeyboardEntryWhenActive(bool); … … 1350 1350 bool m_createRenderers; 1351 1351 bool m_inPageCache; 1352 IconURL m_iconURLs[ICON_COUNT];1352 Vector<IconURL> m_iconURLs; 1353 1353 1354 1354 HashSet<Element*> m_documentActivationCallbackElements; -
trunk/Source/WebCore/dom/IconURL.cpp
r85785 r95593 55 55 } 56 56 57 IconURL IconURL::defaultIconURL(const KURL& url, IconType type) 58 { 59 IconURL result(url, emptyString(), emptyString(), type); 60 result.m_isDefaultIcon = true; 61 return result; 57 62 } 58 63 64 bool operator==(const IconURL& lhs, const IconURL& rhs) 65 { 66 return lhs.m_iconType == rhs.m_iconType 67 && lhs.m_isDefaultIcon == rhs.m_isDefaultIcon 68 && lhs.m_iconURL == rhs.m_iconURL 69 && lhs.m_sizes == rhs.m_sizes 70 && lhs.m_mimeType == rhs.m_mimeType; 71 } 72 73 } 74 -
trunk/Source/WebCore/dom/IconURL.h
r85785 r95593 46 46 Favicon = 1, 47 47 TouchIcon = 1 << 1, 48 TouchPrecomposedIcon = 1 << 2 48 TouchPrecomposedIcon = 1 << 2, 49 49 }; 50 50 51 51 struct IconURL { 52 52 IconType m_iconType; 53 String m_sizes; 54 String m_mimeType; 53 55 KURL m_iconURL; 56 bool m_isDefaultIcon; 54 57 55 58 IconURL() 56 59 : m_iconType(InvalidIcon) 60 , m_isDefaultIcon(false) 57 61 { 58 62 } 59 63 60 IconURL(const KURL& url, IconType type)64 IconURL(const KURL& url, const String& sizes, const String& mimeType, IconType type) 61 65 : m_iconType(type) 66 , m_sizes(sizes) 67 , m_mimeType(mimeType) 62 68 , m_iconURL(url) 69 , m_isDefaultIcon(false) 63 70 { 64 71 } 72 73 static IconURL defaultIconURL(const KURL&, IconType); 65 74 }; 75 76 bool operator==(const IconURL&, const IconURL&); 66 77 67 78 typedef Vector<IconURL, ICON_COUNT> IconURLs; -
trunk/Source/WebCore/html/HTMLLinkElement.cpp
r94427 r95593 180 180 String type = m_type.lower(); 181 181 182 if (!m_linkLoader.loadLink(m_relAttribute, type, m_ url, document()))182 if (!m_linkLoader.loadLink(m_relAttribute, type, m_sizes->toString(), m_url, document())) 183 183 return; 184 184 -
trunk/Source/WebCore/loader/DocumentLoader.cpp
r93066 r95593 1 1 /* 2 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. 3 * Copyright (C) 2011 Google Inc. All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 683 684 } 684 685 685 IconURL DocumentLoader::iconURL(IconType iconType) const686 {687 return m_iconURLs[toIconIndex(iconType)];688 }689 690 void DocumentLoader::setIconURL(const IconURL& url)691 {692 if (url.m_iconURL.isEmpty())693 return;694 695 if (iconURL(url.m_iconType).m_iconURL != url.m_iconURL) {696 m_iconURLs[toIconIndex(url.m_iconType)] = url;697 frameLoader()->didChangeIcons(this, url.m_iconType);698 }699 }700 701 686 KURL DocumentLoader::urlForHistory() const 702 687 { -
trunk/Source/WebCore/loader/DocumentLoader.h
r91600 r95593 1 1 /* 2 2 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 3 * Copyright (C) 2011 Google Inc. All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 33 34 #include "DocumentWriter.h" 34 35 #include "IconDatabaseBase.h" 35 #include "IconURL.h"36 36 #include "NavigationAction.h" 37 37 #include "ResourceError.h" … … 129 129 void setPrimaryLoadComplete(bool); 130 130 void setTitle(const StringWithDirection&); 131 void setIconURL(const IconURL&);132 131 const String& overrideEncoding() const { return m_overrideEncoding; } 133 132 … … 176 175 void stopRecordingResponses(); 177 176 const StringWithDirection& title() const { return m_pageTitle; } 178 IconURL iconURL(IconType) const;179 177 180 178 KURL urlForHistory() const; … … 315 313 316 314 StringWithDirection m_pageTitle; 317 IconURL m_iconURLs[ICON_COUNT];318 315 319 316 String m_overrideEncoding; -
trunk/Source/WebCore/loader/FrameLoader.cpp
r95271 r95593 6 6 * Copyright (C) Research In Motion Limited 2009. All rights reserved. 7 7 * Copyright (C) 2011 Kris Jordan <krisjordan@gmail.com> 8 * Copyright (C) 2011 Google Inc. All rights reserved. 8 9 * 9 10 * Redistribution and use in source and binary forms, with or without … … 3229 3230 } 3230 3231 3231 void FrameLoader::didChangeIcons(DocumentLoader* loader, IconType type) 3232 { 3233 if (loader == m_documentLoader) 3234 m_client->dispatchDidChangeIcons(type); 3232 void FrameLoader::didChangeIcons(IconType type) 3233 { 3234 m_client->dispatchDidChangeIcons(type); 3235 3235 } 3236 3236 -
trunk/Source/WebCore/loader/FrameLoader.h
r93886 r95593 3 3 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) 4 4 * Copyright (C) Research In Motion Limited 2009. All rights reserved. 5 * Copyright (C) 2011 Google Inc. All rights reserved. 5 6 * 6 7 * Redistribution and use in source and binary forms, with or without … … 170 171 void willChangeTitle(DocumentLoader*); 171 172 void didChangeTitle(DocumentLoader*); 172 void didChangeIcons( DocumentLoader*,IconType);173 void didChangeIcons(IconType); 173 174 174 175 FrameLoadType loadType() const; -
trunk/Source/WebCore/loader/LinkLoader.cpp
r89719 r95593 86 86 87 87 bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, const String& type, 88 const KURL& href, Document* document)88 const String& sizes, const KURL& href, Document* document) 89 89 { 90 90 // We'll record this URL per document, even if we later only use it in top level frames … … 92 92 if (!m_client->shouldLoadLink()) 93 93 return false; 94 document-> setIconURL(href.string(), type, relAttribute.m_iconType);94 document->addIconURL(href.string(), type, sizes, relAttribute.m_iconType); 95 95 } 96 96 -
trunk/Source/WebCore/loader/LinkLoader.h
r89719 r95593 51 51 virtual void notifyFinished(CachedResource*); 52 52 53 bool loadLink(const LinkRelAttribute&, const String& type, const KURL&, Document*);53 bool loadLink(const LinkRelAttribute&, const String& type, const String& sizes, const KURL&, Document*); 54 54 55 55 private: -
trunk/Source/WebCore/loader/icon/IconController.cpp
r92551 r95593 6 6 * Copyright (C) Research In Motion Limited 2009. All rights reserved. 7 7 * Copyright (C) 2011 Kris Jordan <krisjordan@gmail.com> 8 * Copyright (C) 2011 Google Inc. All rights reserved. 8 9 * 9 10 * Redistribution and use in source and binary forms, with or without … … 65 66 } 66 67 68 IconURL IconController::iconURL(IconType iconType) const 69 { 70 IconURL result; 71 const Vector<IconURL>& iconURLs = m_frame->document()->iconURLs(); 72 Vector<IconURL>::const_iterator iter(iconURLs.begin()); 73 for (; iter != iconURLs.end(); ++iter) { 74 if (iter->m_iconType == iconType) { 75 if (result.m_iconURL.isEmpty() || !iter->m_mimeType.isEmpty()) 76 result = *iter; 77 } 78 } 79 80 return result; 81 } 82 67 83 IconURLs IconController::urlsForTypes(int iconTypes) 68 84 { … … 70 86 if (m_frame->tree() && m_frame->tree()->parent()) 71 87 return iconURLs; 72 88 73 89 if (iconTypes & Favicon && !appendToIconURLs(Favicon, &iconURLs)) 74 90 iconURLs.append(defaultURL(Favicon)); 75 91 76 92 #if ENABLE(TOUCH_ICON_LOADING) 77 bool havePrecomposedIcon = false;93 int missedIcons = 0; 78 94 if (iconTypes & TouchPrecomposedIcon) 79 havePrecomposedIcon = appendToIconURLs(TouchPrecomposedIcon, &iconURLs); 80 81 bool haveTouchIcon = false; 95 missedIcons += appendToIconURLs(TouchPrecomposedIcon, &iconURLs) ? 0:1; 96 82 97 if (iconTypes & TouchIcon) 83 haveTouchIcon = appendToIconURLs(TouchIcon, &iconURLs);98 missedIcons += appendToIconURLs(TouchIcon, &iconURLs) ? 0:1; 84 99 85 100 // Only return the default touch icons when the both were required and neither was gotten. 86 if ( iconTypes & TouchPrecomposedIcon && iconTypes & TouchIcon && !havePrecomposedIcon && !haveTouchIcon) {101 if (missedIcons == 2) { 87 102 iconURLs.append(defaultURL(TouchPrecomposedIcon)); 88 103 iconURLs.append(defaultURL(TouchIcon)); 89 104 } 90 105 #endif 106 107 // Finally, append all remaining icons of this type. 108 const Vector<IconURL>& allIconURLs = m_frame->document()->iconURLs(); 109 for (Vector<IconURL>::const_iterator iter = allIconURLs.begin(); iter != allIconURLs.end(); ++iter) { 110 if (!(iter->m_iconType & iconTypes)) 111 continue; 112 113 int i; 114 int iconCount = iconURLs.size(); 115 for (i = 0; i < iconCount; ++i) { 116 if (*iter == iconURLs.at(i)) 117 break; 118 } 119 if (i == iconCount) 120 iconURLs.append(*iter); 121 } 122 91 123 return iconURLs; 92 124 } … … 97 129 iconDatabase().setIconURLForPageURL(icon.string(), m_frame->document()->url().string()); 98 130 iconDatabase().setIconURLForPageURL(icon.string(), m_frame->loader()->initialRequest().url().string()); 99 }100 101 void IconController::setURL(const IconURL& iconURL)102 {103 m_frame->loader()->documentLoader()->setIconURL(iconURL);104 131 } 105 132 … … 219 246 bool IconController::appendToIconURLs(IconType iconType, IconURLs* iconURLs) 220 247 { 221 IconURL url = m_frame->document()->iconURL(iconType);222 if ( url.m_iconURL.isEmpty())248 IconURL faviconURL = iconURL(iconType); 249 if (faviconURL.m_iconURL.isEmpty()) 223 250 return false; 224 251 225 iconURLs->append( url);252 iconURLs->append(faviconURL); 226 253 return true; 227 254 } … … 240 267 if (documentURL.hasPort()) 241 268 url.setPort(documentURL.port()); 269 242 270 if (iconType == Favicon) { 243 271 url.setPath("/favicon.ico"); 244 return IconURL (url, Favicon);272 return IconURL::defaultIconURL(url, Favicon); 245 273 } 246 274 #if ENABLE(TOUCH_ICON_LOADING) 247 275 if (iconType == TouchPrecomposedIcon) { 248 276 url.setPath("/apple-touch-icon-precomposed.png"); 249 return IconURL (url, TouchPrecomposedIcon);277 return IconURL::defaultIconURL(url, TouchPrecomposedIcon); 250 278 } 251 279 if (iconType == TouchIcon) { 252 280 url.setPath("/apple-touch-icon.png"); 253 return IconURL (url, TouchIcon);281 return IconURL::defaultIconURL(url, TouchIcon); 254 282 } 255 283 #endif -
trunk/Source/WebCore/loader/icon/IconController.h
r88682 r95593 50 50 KURL url(); 51 51 IconURLs urlsForTypes(int iconTypes); 52 53 // FIXME: We should inline this function into its one caller! 54 void setURL(const IconURL&); 52 IconURL iconURL(IconType) const; 55 53 56 54 void startLoader();
Note: See TracChangeset
for help on using the changeset viewer.