Home | History | Annotate | Download | only in html
      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, 2008, 2009 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 "HTMLBaseElement.h"
     25 
     26 #include "CSSHelper.h"
     27 #include "Document.h"
     28 #include "Frame.h"
     29 #include "HTMLNames.h"
     30 #include "MappedAttribute.h"
     31 #include "XSSAuditor.h"
     32 
     33 namespace WebCore {
     34 
     35 using namespace HTMLNames;
     36 
     37 HTMLBaseElement::HTMLBaseElement(const QualifiedName& qName, Document* document)
     38     : HTMLElement(qName, document)
     39 {
     40     ASSERT(hasTagName(baseTag));
     41 }
     42 
     43 void HTMLBaseElement::parseMappedAttribute(MappedAttribute* attr)
     44 {
     45     if (attr->name() == hrefAttr) {
     46         m_hrefAttrValue = attr->value();
     47         m_href = deprecatedParseURL(attr->value());
     48         process();
     49     } else if (attr->name() == targetAttr) {
     50         m_target = attr->value();
     51         process();
     52     } else
     53         HTMLElement::parseMappedAttribute(attr);
     54 }
     55 
     56 void HTMLBaseElement::insertedIntoDocument()
     57 {
     58     HTMLElement::insertedIntoDocument();
     59     process();
     60 }
     61 
     62 void HTMLBaseElement::removedFromDocument()
     63 {
     64     HTMLElement::removedFromDocument();
     65 
     66     // Since the document doesn't have a base element, clear the base URL and target.
     67     // FIXME: This does not handle the case of multiple base elements correctly.
     68     document()->setBaseElementURL(KURL());
     69     document()->setBaseElementTarget(String());
     70 }
     71 
     72 void HTMLBaseElement::process()
     73 {
     74     if (!inDocument())
     75         return;
     76 
     77     if (!m_href.isEmpty() && (!document()->frame() || document()->frame()->script()->xssAuditor()->canSetBaseElementURL(m_hrefAttrValue)))
     78         document()->setBaseElementURL(KURL(document()->url(), m_href));
     79 
     80     if (!m_target.isEmpty())
     81         document()->setBaseElementTarget(m_target);
     82 
     83     // FIXME: Changing a document's base URL should probably automatically update the resolved relative URLs of all images, stylesheets, etc.
     84 }
     85 
     86 }
     87