| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 */ | |
| 30 | |
| 31 #include "config.h" | |
| 32 #include "core/html/imports/LinkImport.h" | |
| 33 | |
| 34 #include "core/dom/Document.h" | |
| 35 #include "core/html/HTMLLinkElement.h" | |
| 36 #include "core/html/imports/HTMLImportChild.h" | |
| 37 #include "core/html/imports/HTMLImportLoader.h" | |
| 38 #include "core/html/imports/HTMLImportTreeRoot.h" | |
| 39 #include "core/html/imports/HTMLImportsController.h" | |
| 40 | |
| 41 namespace blink { | |
| 42 | |
| 43 PassOwnPtr<LinkImport> LinkImport::create(HTMLLinkElement* owner) | |
| 44 { | |
| 45 return adoptPtr(new LinkImport(owner)); | |
| 46 } | |
| 47 | |
| 48 LinkImport::LinkImport(HTMLLinkElement* owner) | |
| 49 : LinkResource(owner) | |
| 50 , m_child(nullptr) | |
| 51 { | |
| 52 } | |
| 53 | |
| 54 LinkImport::~LinkImport() | |
| 55 { | |
| 56 #if !ENABLE(OILPAN) | |
| 57 if (m_child) { | |
| 58 m_child->clearClient(); | |
| 59 m_child = nullptr; | |
| 60 } | |
| 61 #endif | |
| 62 } | |
| 63 | |
| 64 Document* LinkImport::importedDocument() const | |
| 65 { | |
| 66 if (!m_child || !m_owner || !m_owner->inDocument()) | |
| 67 return 0; | |
| 68 if (m_child->loader()->hasError()) | |
| 69 return 0; | |
| 70 return m_child->document(); | |
| 71 } | |
| 72 | |
| 73 void LinkImport::process() | |
| 74 { | |
| 75 if (m_child) | |
| 76 return; | |
| 77 if (!m_owner) | |
| 78 return; | |
| 79 if (!shouldLoadResource()) | |
| 80 return; | |
| 81 | |
| 82 if (!m_owner->document().importsController()) { | |
| 83 ASSERT(m_owner->document().frame()); // The document should be the maste
r. | |
| 84 HTMLImportsController::provideTo(m_owner->document()); | |
| 85 } | |
| 86 | |
| 87 LinkRequestBuilder builder(m_owner); | |
| 88 if (!builder.isValid()) { | |
| 89 didFinish(); | |
| 90 return; | |
| 91 } | |
| 92 | |
| 93 m_child = m_owner->document().importsController()->load(m_owner->document().
import(), this, builder.build(true)); | |
| 94 if (!m_child) { | |
| 95 didFinish(); | |
| 96 return; | |
| 97 } | |
| 98 } | |
| 99 | |
| 100 void LinkImport::didFinish() | |
| 101 { | |
| 102 if (!m_owner || !m_owner->inDocument()) | |
| 103 return; | |
| 104 m_owner->scheduleEvent(); | |
| 105 } | |
| 106 | |
| 107 #if !ENABLE(OILPAN) | |
| 108 void LinkImport::importChildWasDestroyed(HTMLImportChild* child) | |
| 109 { | |
| 110 ASSERT(m_child == child); | |
| 111 m_child = nullptr; | |
| 112 m_owner = nullptr; | |
| 113 } | |
| 114 #endif | |
| 115 | |
| 116 bool LinkImport::isSync() const | |
| 117 { | |
| 118 return m_owner && !m_owner->async(); | |
| 119 } | |
| 120 | |
| 121 Element* LinkImport::link() | |
| 122 { | |
| 123 return m_owner; | |
| 124 } | |
| 125 | |
| 126 bool LinkImport::hasLoaded() const | |
| 127 { | |
| 128 // Should never be called after importChildWasDestroyed was called. | |
| 129 ASSERT(m_owner); | |
| 130 return m_child && m_child->isDone() && !m_child->loader()->hasError(); | |
| 131 } | |
| 132 | |
| 133 void LinkImport::ownerInserted() | |
| 134 { | |
| 135 if (m_child) | |
| 136 m_child->ownerInserted(); | |
| 137 } | |
| 138 | |
| 139 void LinkImport::trace(Visitor* visitor) | |
| 140 { | |
| 141 visitor->trace(m_child); | |
| 142 HTMLImportChildClient::trace(visitor); | |
| 143 LinkResource::trace(visitor); | |
| 144 } | |
| 145 | |
| 146 } // namespace blink | |
| OLD | NEW |