1 /* 2 * Copyright (C) 1999 Lars Knoll (knoll (at) kde.org) 3 * (C) 1999 Antti Koivisto (koivisto (at) kde.org) 4 * (C) 2001 Dirk Mueller (mueller (at) kde.org) 5 * Copyright (C) 2003, 2010 Apple Inc. All rights reserved. 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Library General Public 9 * License as published by the Free Software Foundation; either 10 * version 2 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Library General Public License for more details. 16 * 17 * You should have received a copy of the GNU Library General Public License 18 * along with this library; see the file COPYING.LIB. If not, write to 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 * Boston, MA 02110-1301, USA. 21 */ 22 23 #include "config.h" 24 #include "HTMLMetaElement.h" 25 26 #include "Attribute.h" 27 #include "Document.h" 28 #include "HTMLNames.h" 29 30 #ifdef ANDROID_META_SUPPORT 31 #include "PlatformBridge.h" 32 #include "Settings.h" 33 #endif 34 35 #if ENABLE(ANDROID_INSTALLABLE_WEB_APPS) 36 #include "ChromeClient.h" 37 #endif 38 39 namespace WebCore { 40 41 using namespace HTMLNames; 42 43 inline HTMLMetaElement::HTMLMetaElement(const QualifiedName& tagName, Document* document) 44 : HTMLElement(tagName, document) 45 { 46 ASSERT(hasTagName(metaTag)); 47 } 48 49 PassRefPtr<HTMLMetaElement> HTMLMetaElement::create(const QualifiedName& tagName, Document* document) 50 { 51 return adoptRef(new HTMLMetaElement(tagName, document)); 52 } 53 54 void HTMLMetaElement::parseMappedAttribute(Attribute* attr) 55 { 56 if (attr->name() == http_equivAttr) { 57 m_equiv = attr->value(); 58 process(); 59 } else if (attr->name() == contentAttr) { 60 m_content = attr->value(); 61 process(); 62 } else if (attr->name() == nameAttr) { 63 // Do nothing. 64 } else 65 HTMLElement::parseMappedAttribute(attr); 66 } 67 68 void HTMLMetaElement::insertedIntoDocument() 69 { 70 HTMLElement::insertedIntoDocument(); 71 process(); 72 } 73 74 void HTMLMetaElement::process() 75 { 76 if (!inDocument() || m_content.isNull()) 77 return; 78 if (equalIgnoringCase(name(), "viewport")) 79 document()->processViewport(m_content); 80 #ifdef ANDROID_META_SUPPORT 81 // TODO: Evaluate whether to take upstreamed meta support 82 else if (equalIgnoringCase(name(), "format-detection")) 83 document()->processMetadataSettings(m_content); 84 else if (((equalIgnoringCase(name(), "HandheldFriendly") && equalIgnoringCase(m_content, "true")) || equalIgnoringCase(name(), "MobileOptimized")) 85 && document()->settings() 86 && document()->settings()->viewportWidth() == -1) { 87 // fit mobile sites directly in the screen 88 document()->processViewport("width=device-width"); 89 } 90 #endif 91 92 #if ENABLE(ANDROID_INSTALLABLE_WEB_APPS) 93 // If this web site is informing us it is possible for it to be installed, inform the chrome 94 // client so it can offer this to the user. 95 if (equalIgnoringCase(name(), "fullscreen-web-app-capable") 96 && equalIgnoringCase(m_content, "yes")) { 97 if (Page* page = document()->page()) 98 page->chrome()->client()->webAppCanBeInstalled(); 99 } 100 #endif 101 102 // Get the document to process the tag, but only if we're actually part of DOM tree (changing a meta tag while 103 // it's not in the tree shouldn't have any effect on the document) 104 if (!m_equiv.isNull()) 105 document()->processHttpEquiv(m_equiv, m_content); 106 } 107 108 String HTMLMetaElement::content() const 109 { 110 return getAttribute(contentAttr); 111 } 112 113 String HTMLMetaElement::httpEquiv() const 114 { 115 return getAttribute(http_equivAttr); 116 } 117 118 String HTMLMetaElement::name() const 119 { 120 return getAttribute(nameAttr); 121 } 122 123 } 124