15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/* 25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2003, 2006, 2008 Apple Inc. All rights reserved. 35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * This library is free software; you can redistribute it and/or 55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modify it under the terms of the GNU Lesser General Public 65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * License as published by the Free Software Foundation; either 75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * version 2 of the License, or (at your option) any later version. 85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * This library is distributed in the hope that it will be useful, 105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * but WITHOUT ANY WARRANTY; without even the implied warranty of 115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Lesser General Public License for more details. 135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * You should have received a copy of the GNU Lesser General Public 155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * License along with this library; if not, write to the Free Software 165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */ 185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "config.h" 2053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/xml/DOMParser.h" 215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 2253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/dom/DOMImplementation.h" 231e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "core/dom/ExceptionCode.h" 24e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)#include "wtf/text/WTFString.h" 255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 26c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink { 275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 28d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)PassRefPtrWillBeRawPtr<Document> DOMParser::parseFromString(const String& str, const String& contentType, ExceptionState& exceptionState) 295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 301e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) // HTML5 is very explicit about which types we're allowed to support here: 311e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) // http://domparsing.spec.whatwg.org/#the-domparser-interface 321e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) if (contentType != "text/html" 331e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) && contentType != "text/xml" 341e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) && contentType != "application/xml" 351e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) && contentType != "application/xhtml+xml" 361e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) && contentType != "image/svg+xml") { 37d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) exceptionState.throwTypeError("Unsupported mime-type specified."); 38d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) return nullptr; 391e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) } 405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 41d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) RefPtrWillBeRawPtr<Document> doc = DOMImplementation::createDocument(contentType, 0, KURL(), false); 425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) doc->setContent(str); 435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return doc.release(); 445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 46c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink 47