2 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
31 #ifndef HTMLImportChild_h
32 #define HTMLImportChild_h
34 #include "core/fetch/RawResource.h"
35 #include "core/fetch/ResourceOwner.h"
36 #include "core/html/HTMLImport.h"
37 #include "core/html/HTMLImportLoaderClient.h"
38 #include "platform/weborigin/KURL.h"
39 #include "wtf/Vector.h"
43 class CustomElementMicrotaskImportStep;
44 class HTMLImportLoader;
45 class HTMLImportChildClient;
46 class HTMLLinkElement;
49 // An import tree node subclas to encapsulate imported document
50 // lifecycle. This class is owned by LinkStyle. The actual loading
51 // is done by HTMLImportLoader, which can be shared among multiple
52 // HTMLImportChild of same link URL.
54 // HTMLImportChild implements ResourceClient through ResourceOwner
55 // so that it can speculatively request linked resources while it is unblocked.
57 class HTMLImportChild FINAL : public HTMLImport, public HTMLImportLoaderClient, public ResourceOwner<RawResource> {
59 HTMLImportChild(const KURL&, bool createdByParser);
60 virtual ~HTMLImportChild();
62 HTMLLinkElement* link() const;
63 Document* importedDocument() const;
64 const KURL& url() const { return m_url; }
66 void wasAlreadyLoaded();
67 void startLoading(const ResourcePtr<RawResource>&);
68 void importDestroyed();
71 virtual bool isChild() const OVERRIDE { return true; }
72 virtual HTMLImportRoot* root() OVERRIDE;
73 virtual Document* document() const OVERRIDE;
74 virtual void wasDetachedFromDocument() OVERRIDE;
75 virtual void didFinishParsing() OVERRIDE;
76 virtual bool isDone() const OVERRIDE;
77 virtual bool hasLoader() const OVERRIDE;
78 virtual bool ownsLoader() const OVERRIDE;
79 virtual CustomElementMicrotaskImportStep* customElementMicrotaskStep() const OVERRIDE FINAL { return m_customElementMicrotaskStep; }
80 virtual void stateDidChange() OVERRIDE;
83 virtual void showThis() OVERRIDE;
86 void setClient(HTMLImportChildClient*);
88 bool loaderHasError() const;
91 // RawResourceOwner doing nothing.
92 // HTMLImportChild owns the resource so that the contents of prefetched Resource doesn't go away.
93 virtual void responseReceived(Resource*, const ResourceResponse&) OVERRIDE { }
94 virtual void dataReceived(Resource*, const char*, int) OVERRIDE { }
95 virtual void notifyFinished(Resource*) OVERRIDE { }
97 // HTMLImportLoaderClient
98 virtual void didFinishLoading() OVERRIDE;
102 void shareLoader(HTMLImportChild*);
106 CustomElementMicrotaskImportStep* m_customElementMicrotaskStep;
107 RefPtr<HTMLImportLoader> m_loader;
108 HTMLImportChildClient* m_client;
111 inline HTMLImportChild* toHTMLImportChild(HTMLImport* import)
113 ASSERT(!import || import->isChild());
114 return static_cast<HTMLImportChild*>(import);
117 } // namespace WebCore
119 #endif // HTMLImportChild_h