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 #ifndef HTMLImportsController_h |
| 32 #define HTMLImportsController_h |
| 33 |
| 34 #include "core/html/LinkResource.h" |
| 35 #include "core/loader/cache/CachedResourceClient.h" |
| 36 #include "core/loader/cache/CachedResourceHandle.h" |
| 37 #include "wtf/FastAllocBase.h" |
| 38 #include "wtf/PassOwnPtr.h" |
| 39 #include "wtf/Vector.h" |
| 40 |
| 41 namespace WebCore { |
| 42 |
| 43 class DocumentFragment; |
| 44 class HTMLImportsController; |
| 45 |
| 46 // |
| 47 // A LinkResource subclasss used for @rel=import. |
| 48 // |
| 49 class LinkImport : public LinkResource, CachedResourceClient { |
| 50 WTF_MAKE_FAST_ALLOCATED; |
| 51 public: |
| 52 enum State { |
| 53 StatePreparing, |
| 54 StateStarted, |
| 55 StateError, |
| 56 StateReady |
| 57 }; |
| 58 |
| 59 static PassRefPtr<LinkImport> create(HTMLLinkElement* owner); |
| 60 |
| 61 explicit LinkImport(HTMLLinkElement* owner); |
| 62 virtual ~LinkImport(); |
| 63 |
| 64 // LinkResource |
| 65 virtual void process() OVERRIDE; |
| 66 virtual Type type() const OVERRIDE { return Import; } |
| 67 virtual void ownerRemoved() OVERRIDE; |
| 68 |
| 69 DocumentFragment* importedFragment() const; |
| 70 const KURL& url() const { return m_url; } |
| 71 void importDestroyed(); |
| 72 bool isDone() const { return m_state == StateReady || m_state == StateError;
} |
| 73 |
| 74 private: |
| 75 State startRequest(); |
| 76 State finish(); |
| 77 void setState(State); |
| 78 |
| 79 // CachedResourceClient |
| 80 virtual void notifyFinished(CachedResource*) OVERRIDE; |
| 81 |
| 82 HTMLImportsController* m_controller; |
| 83 LinkImport* m_ofSameLocation; |
| 84 KURL m_url; |
| 85 State m_state; |
| 86 CachedResourceHandle<CachedScript> m_resource; |
| 87 RefPtr<DocumentFragment> m_importedFragment; |
| 88 }; |
| 89 |
| 90 |
| 91 class HTMLImportsController { |
| 92 WTF_MAKE_FAST_ALLOCATED; |
| 93 public: |
| 94 static PassOwnPtr<HTMLImportsController> create(Document*); |
| 95 |
| 96 explicit HTMLImportsController(Document*); |
| 97 virtual ~HTMLImportsController(); |
| 98 |
| 99 void addImport(PassRefPtr<LinkImport>); |
| 100 void showSecurityErrorMessage(const String&); |
| 101 PassRefPtr<DocumentFragment> createDocumentFragment() const; |
| 102 PassRefPtr<LinkImport> findLinkFor(const KURL&) const; |
| 103 SecurityOrigin* securityOrigin() const; |
| 104 bool haveLoaded() const; |
| 105 void didLoad(); |
| 106 |
| 107 private: |
| 108 |
| 109 Document* m_master; |
| 110 RefPtr<Document> m_importedFragmentOwner; |
| 111 |
| 112 // List of import which has been loaded or being loaded. |
| 113 typedef Vector<RefPtr<LinkImport> > ImportList; |
| 114 ImportList m_imports; |
| 115 }; |
| 116 |
| 117 } // namespace WebCore |
| 118 |
| 119 #endif // HTMLImportsController_h |
OLD | NEW |