Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * This file is part of the XSL implementation. | 2 * This file is part of the XSL implementation. |
| 3 * | 3 * |
| 4 * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. | 4 * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. |
| 5 * | 5 * |
| 6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
| 7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
| 8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
| 9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
| 10 * | 10 * |
| 11 * This library is distributed in the hope that it will be useful, | 11 * This library is distributed in the hope that it will be useful, |
| 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 * Library General Public License for more details. | 14 * Library General Public License for more details. |
| 15 * | 15 * |
| 16 * You should have received a copy of the GNU Library General Public License | 16 * You should have received a copy of the GNU Library General Public License |
| 17 * along with this library; see the file COPYING.LIB. If not, write to | 17 * along with this library; see the file COPYING.LIB. If not, write to |
| 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 19 * Boston, MA 02110-1301, USA. | 19 * Boston, MA 02110-1301, USA. |
| 20 */ | 20 */ |
| 21 | 21 |
| 22 #include "config.h" | 22 #include "config.h" |
| 23 #include "core/xml/XSLImportRule.h" | 23 #include "core/xml/XSLImportRule.h" |
| 24 | 24 |
| 25 #include "core/FetchInitiatorTypeNames.h" | 25 #include "core/FetchInitiatorTypeNames.h" |
| 26 #include "core/dom/Document.h" | 26 #include "core/dom/Document.h" |
| 27 #include "core/fetch/FetchRequest.h" | 27 #include "core/fetch/FetchRequest.h" |
| 28 #include "core/fetch/ResourceFetcher.h" | 28 #include "core/fetch/ResourceFetcher.h" |
| 29 #include "core/fetch/XSLStyleSheetResource.h" | 29 #include "core/fetch/XSLStyleSheetResource.h" |
| 30 #include "core/html/parser/TextResourceDecoder.h" | |
| 31 #include "platform/SharedBuffer.h" | |
| 30 | 32 |
| 31 namespace blink { | 33 namespace blink { |
| 32 | 34 |
| 33 XSLImportRule::XSLImportRule(XSLStyleSheet* parent, const String& href) | 35 XSLImportRule::XSLImportRule(XSLStyleSheet* parent, const String& href) |
| 34 : m_parentStyleSheet(parent) | 36 : m_parentStyleSheet(parent) |
| 35 , m_strHref(href) | 37 , m_strHref(href) |
| 36 , m_resource(0) | |
| 37 , m_loading(false) | 38 , m_loading(false) |
| 38 { | 39 { |
| 39 } | 40 } |
| 40 | 41 |
| 41 XSLImportRule::~XSLImportRule() | 42 XSLImportRule::~XSLImportRule() |
| 42 { | 43 { |
| 43 #if !ENABLE(OILPAN) | 44 #if !ENABLE(OILPAN) |
| 44 if (m_styleSheet) | 45 if (m_styleSheet) |
| 45 m_styleSheet->setParentStyleSheet(0); | 46 m_styleSheet->setParentStyleSheet(0); |
| 46 #endif | 47 #endif |
| 47 | |
| 48 if (m_resource) | |
| 49 m_resource->removeClient(this); | |
| 50 } | 48 } |
| 51 | 49 |
| 52 void XSLImportRule::setXSLStyleSheet(const String& href, const KURL& baseURL, co nst String& sheet) | 50 void XSLImportRule::setXSLStyleSheet(const String& href, const KURL& baseURL, co nst String& sheet) |
| 53 { | 51 { |
| 54 if (m_styleSheet) | 52 if (m_styleSheet) |
| 55 m_styleSheet->setParentStyleSheet(0); | 53 m_styleSheet->setParentStyleSheet(0); |
| 56 | 54 |
| 57 m_styleSheet = XSLStyleSheet::create(this, href, baseURL); | 55 m_styleSheet = XSLStyleSheet::create(this, href, baseURL); |
| 58 | 56 |
| 59 XSLStyleSheet* parent = parentStyleSheet(); | 57 XSLStyleSheet* parent = parentStyleSheet(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 absHref = KURL(parentSheet->baseURL(), m_strHref).string(); | 90 absHref = KURL(parentSheet->baseURL(), m_strHref).string(); |
| 93 } | 91 } |
| 94 | 92 |
| 95 // Check for a cycle in our import chain. If we encounter a stylesheet in | 93 // Check for a cycle in our import chain. If we encounter a stylesheet in |
| 96 // our parent chain with the same URL, then just bail. | 94 // our parent chain with the same URL, then just bail. |
| 97 for (XSLStyleSheet* parentSheet = parentStyleSheet(); parentSheet; parentShe et = parentSheet->parentStyleSheet()) { | 95 for (XSLStyleSheet* parentSheet = parentStyleSheet(); parentSheet; parentShe et = parentSheet->parentStyleSheet()) { |
| 98 if (absHref == parentSheet->baseURL().string()) | 96 if (absHref == parentSheet->baseURL().string()) |
| 99 return; | 97 return; |
| 100 } | 98 } |
| 101 | 99 |
| 102 FetchRequest request(ResourceRequest(fetcher->document()->completeURL(absHre f)), FetchInitiatorTypeNames::xml); | 100 ResourceLoaderOptions fetchOptions(ResourceFetcher::defaultResourceOptions() ); |
| 103 m_resource = fetcher->fetchXSLStyleSheet(request); | 101 FetchRequest request(ResourceRequest(fetcher->document()->completeURL(absHre f)), FetchInitiatorTypeNames::xml, fetchOptions); |
| 102 request.setOriginRestriction(FetchRequest::RestrictToSameOrigin); | |
| 103 ResourcePtr<Resource> resource = fetcher->fetchSynchronously(request); | |
| 104 if (!resource) | |
| 105 return; | |
| 104 | 106 |
| 105 if (m_resource) { | 107 ASSERT(!m_styleSheet); |
| 106 m_resource->addClient(this); | 108 if (SharedBuffer* data = resource->resourceBuffer()) { |
| 107 | 109 OwnPtr<TextResourceDecoder> decoder = TextResourceDecoder::create("text/ xsl", request.charset()); |
| 108 // If the imported sheet is in the cache, then setXSLStyleSheet gets | 110 String text = decoder->decode(data->data(), resource->encodedSize()); |
| 109 // called, and the sheet even gets parsed (via parseString). In this | 111 text = text + decoder->flush(); |
|
abarth-chromium
2014/09/06 23:13:51
You should just use the UTF-8 encoding directly.
tasak
2014/09/08 04:22:03
I see. Done.
| |
| 110 // case we have loaded (even if our subresources haven't), so if we have | 112 setXSLStyleSheet(absHref, parentSheet->baseURL(), text); |
| 111 // a stylesheet after checking the cache, then we've clearly loaded. | |
| 112 if (!m_styleSheet) | |
| 113 m_loading = true; | |
| 114 } | 113 } |
| 115 } | 114 } |
| 116 | 115 |
| 117 void XSLImportRule::trace(Visitor* visitor) | 116 void XSLImportRule::trace(Visitor* visitor) |
| 118 { | 117 { |
| 119 visitor->trace(m_parentStyleSheet); | 118 visitor->trace(m_parentStyleSheet); |
| 120 visitor->trace(m_styleSheet); | 119 visitor->trace(m_styleSheet); |
| 121 } | 120 } |
| 122 | 121 |
| 123 } // namespace blink | 122 } // namespace blink |
| OLD | NEW |