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