Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / html / HTMLImportChild.h
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 HTMLImportChild_h
32 #define HTMLImportChild_h
33
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"
40
41 namespace WebCore {
42
43 class CustomElementMicrotaskImportStep;
44 class HTMLImportLoader;
45 class HTMLImportChildClient;
46 class HTMLLinkElement;
47
48 //
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.
53 //
54 // HTMLImportChild implements ResourceClient through ResourceOwner
55 // so that it can speculatively request linked resources while it is unblocked.
56 //
57 class HTMLImportChild FINAL : public HTMLImport, public HTMLImportLoaderClient, public ResourceOwner<RawResource> {
58 public:
59     HTMLImportChild(const KURL&, bool createdByParser);
60     virtual ~HTMLImportChild();
61
62     HTMLLinkElement* link() const;
63     Document* importedDocument() const;
64     const KURL& url() const { return m_url; }
65
66     void wasAlreadyLoaded();
67     void startLoading(const ResourcePtr<RawResource>&);
68     void importDestroyed();
69
70     // HTMLImport
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;
81
82 #if !defined(NDEBUG)
83     virtual void showThis() OVERRIDE;
84 #endif
85
86     void setClient(HTMLImportChildClient*);
87     void clearClient();
88     bool loaderHasError() const;
89
90 private:
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 { }
96
97     // HTMLImportLoaderClient
98     virtual void didFinishLoading() OVERRIDE;
99
100     void didFinish();
101     void createLoader();
102     void shareLoader(HTMLImportChild*);
103     void ensureLoader();
104
105     KURL m_url;
106     CustomElementMicrotaskImportStep* m_customElementMicrotaskStep;
107     RefPtr<HTMLImportLoader> m_loader;
108     HTMLImportChildClient* m_client;
109 };
110
111 inline HTMLImportChild* toHTMLImportChild(HTMLImport* import)
112 {
113     ASSERT(!import || import->isChild());
114     return static_cast<HTMLImportChild*>(import);
115 }
116
117 } // namespace WebCore
118
119 #endif // HTMLImportChild_h