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 namespace WebCore { 36 37 using namespace HTMLNames; 38 39 inline HTMLMetaElement::HTMLMetaElement(const QualifiedName& tagName, Document* document) 40 : HTMLElement(tagName, document) 41 { 42 ASSERT(hasTagName(metaTag)); 43 } 44 45 PassRefPtr<HTMLMetaElement> HTMLMetaElement::create(const QualifiedName& tagName, Document* document) 46 { 47 return adoptRef(new HTMLMetaElement(tagName, document)); 48 } 49 50 void HTMLMetaElement::parseMappedAttribute(Attribute* attr) 51 { 52 if (attr->name() == http_equivAttr) { 53 m_equiv = attr->value(); 54 process(); 55 } else if (attr->name() == contentAttr) { 56 m_content = attr->value(); 57 process(); 58 } else if (attr->name() == nameAttr) { 59 // Do nothing. 60 } else 61 HTMLElement::parseMappedAttribute(attr); 62 } 63 64 void HTMLMetaElement::insertedIntoDocument() 65 { 66 HTMLElement::insertedIntoDocument(); 67 process(); 68 } 69 70 void HTMLMetaElement::process() 71 { 72 if (!inDocument() || m_content.isNull()) 73 return; 74 if (equalIgnoringCase(name(), "viewport")) 75 document()->processViewport(m_content); 76 #ifdef ANDROID_META_SUPPORT 77 // TODO: Evaluate whether to take upstreamed meta support 78 else if (equalIgnoringCase(name(), "format-detection")) 79 document()->processMetadataSettings(m_content); 80 else if (((equalIgnoringCase(name(), "HandheldFriendly") && equalIgnoringCase(m_content, "true")) || equalIgnoringCase(name(), "MobileOptimized")) 81 && document()->settings() 82 && document()->settings()->viewportWidth() == -1) { 83 // fit mobile sites directly in the screen 84 document()->processViewport("width=device-width"); 85 } 86 #endif 87 88 // Get the document to process the tag, but only if we're actually part of DOM tree (changing a meta tag while 89 // it's not in the tree shouldn't have any effect on the document) 90 if (!m_equiv.isNull()) 91 document()->processHttpEquiv(m_equiv, m_content); 92 } 93 94 String HTMLMetaElement::content() const 95 { 96 return getAttribute(contentAttr); 97 } 98 99 String HTMLMetaElement::httpEquiv() const 100 { 101 return getAttribute(http_equivAttr); 102 } 103 104 String HTMLMetaElement::name() const 105 { 106 return getAttribute(nameAttr); 107 } 108 109 } 110