OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 { | 55 { |
56 } | 56 } |
57 | 57 |
58 HTMLImportsController::~HTMLImportsController() | 58 HTMLImportsController::~HTMLImportsController() |
59 { | 59 { |
60 ASSERT(!m_master); | 60 ASSERT(!m_master); |
61 } | 61 } |
62 | 62 |
63 void HTMLImportsController::clear() | 63 void HTMLImportsController::clear() |
64 { | 64 { |
65 for (size_t i = 0; i < m_imports.size(); ++i) | 65 m_root.clear(); |
66 m_imports[i]->importDestroyed(); | |
67 m_imports.clear(); | |
68 | 66 |
69 for (size_t i = 0; i < m_loaders.size(); ++i) | 67 for (size_t i = 0; i < m_loaders.size(); ++i) |
70 m_loaders[i]->importDestroyed(); | 68 m_loaders[i]->importDestroyed(); |
71 m_loaders.clear(); | 69 m_loaders.clear(); |
72 | 70 |
73 if (m_master) | 71 if (m_master) |
74 m_master->setImportsController(0); | 72 m_master->setImportsController(0); |
75 m_master = 0; | 73 m_master = 0; |
76 | 74 |
77 m_root.clear(); | 75 m_root.clear(); |
78 } | 76 } |
79 | 77 |
80 static bool makesCycle(HTMLImport* parent, const KURL& url) | 78 static bool makesCycle(HTMLImport* parent, const KURL& url) |
81 { | 79 { |
82 for (HTMLImport* ancestor = parent; ancestor; ancestor = ancestor->parent())
{ | 80 for (HTMLImport* ancestor = parent; ancestor; ancestor = ancestor->parent())
{ |
83 if (!ancestor->isRoot() && equalIgnoringFragmentIdentifier(toHTMLImportC
hild(parent)->url(), url)) | 81 if (!ancestor->isRoot() && equalIgnoringFragmentIdentifier(toHTMLImportC
hild(parent)->url(), url)) |
84 return true; | 82 return true; |
85 } | 83 } |
86 | 84 |
87 return false; | 85 return false; |
88 } | 86 } |
89 | 87 |
90 HTMLImportChild* HTMLImportsController::createChild(const KURL& url, HTMLImportL
oader* loader, HTMLImport* parent, HTMLImportChildClient* client) | 88 HTMLImportChild* HTMLImportsController::createChild(const KURL& url, HTMLImportL
oader* loader, HTMLImport* parent, HTMLImportChildClient* client) |
91 { | 89 { |
92 HTMLImport::SyncMode mode = client->isSync() && !makesCycle(parent, url) ? H
TMLImport::Sync : HTMLImport::Async; | 90 HTMLImport::SyncMode mode = client->isSync() && !makesCycle(parent, url) ? H
TMLImport::Sync : HTMLImport::Async; |
93 OwnPtr<HTMLImportChild> child = adoptPtr(new HTMLImportChild(url, loader, mo
de)); | 91 OwnPtr<HTMLImportChild> child = adoptPtr(new HTMLImportChild(url, loader, mo
de)); |
94 child->setClient(client); | 92 child->setClient(client); |
95 parent->appendImport(child.get()); | 93 parent->appendImport(child.get()); |
96 loader->addImport(child.get()); | 94 loader->addImport(child.get()); |
97 m_imports.append(child.release()); | 95 return root()->add(child.release()); |
98 return m_imports.last().get(); | |
99 } | 96 } |
100 | 97 |
101 HTMLImportChild* HTMLImportsController::load(HTMLImport* parent, HTMLImportChild
Client* client, FetchRequest request) | 98 HTMLImportChild* HTMLImportsController::load(HTMLImport* parent, HTMLImportChild
Client* client, FetchRequest request) |
102 { | 99 { |
103 ASSERT(!request.url().isEmpty() && request.url().isValid()); | 100 ASSERT(!request.url().isEmpty() && request.url().isValid()); |
104 ASSERT(parent == root() || toHTMLImportChild(parent)->loader()->isFirstImpor
t(toHTMLImportChild(parent))); | 101 ASSERT(parent == root() || toHTMLImportChild(parent)->loader()->isFirstImpor
t(toHTMLImportChild(parent))); |
105 | 102 |
106 if (HTMLImportChild* childToShareWith = findLinkFor(request.url())) { | 103 if (HTMLImportChild* childToShareWith = root()->find(request.url())) { |
107 HTMLImportLoader* loader = childToShareWith->loader(); | 104 HTMLImportLoader* loader = childToShareWith->loader(); |
108 ASSERT(loader); | 105 ASSERT(loader); |
109 HTMLImportChild* child = createChild(request.url(), loader, parent, clie
nt); | 106 HTMLImportChild* child = createChild(request.url(), loader, parent, clie
nt); |
110 child->didShareLoader(); | 107 child->didShareLoader(); |
111 return child; | 108 return child; |
112 } | 109 } |
113 | 110 |
114 bool sameOriginRequest = securityOrigin()->canRequest(request.url()); | 111 bool sameOriginRequest = securityOrigin()->canRequest(request.url()); |
115 request.setCrossOriginAccessControl( | 112 request.setCrossOriginAccessControl( |
116 securityOrigin(), sameOriginRequest ? AllowStoredCredentials : DoNotAllo
wStoredCredentials, | 113 securityOrigin(), sameOriginRequest ? AllowStoredCredentials : DoNotAllo
wStoredCredentials, |
(...skipping 10 matching lines...) Expand all Loading... |
127 child->didStartLoading(); | 124 child->didStartLoading(); |
128 | 125 |
129 return child; | 126 return child; |
130 } | 127 } |
131 | 128 |
132 void HTMLImportsController::showSecurityErrorMessage(const String& message) | 129 void HTMLImportsController::showSecurityErrorMessage(const String& message) |
133 { | 130 { |
134 m_master->addConsoleMessage(JSMessageSource, ErrorMessageLevel, message); | 131 m_master->addConsoleMessage(JSMessageSource, ErrorMessageLevel, message); |
135 } | 132 } |
136 | 133 |
137 HTMLImportChild* HTMLImportsController::findLinkFor(const KURL& url) const | |
138 { | |
139 for (size_t i = 0; i < m_imports.size(); ++i) { | |
140 HTMLImportChild* candidate = m_imports[i].get(); | |
141 if (equalIgnoringFragmentIdentifier(candidate->url(), url) && candidate-
>loader()) | |
142 return candidate; | |
143 } | |
144 | |
145 return 0; | |
146 } | |
147 | |
148 SecurityOrigin* HTMLImportsController::securityOrigin() const | 134 SecurityOrigin* HTMLImportsController::securityOrigin() const |
149 { | 135 { |
150 return m_master->securityOrigin(); | 136 return m_master->securityOrigin(); |
151 } | 137 } |
152 | 138 |
153 ResourceFetcher* HTMLImportsController::fetcher() const | 139 ResourceFetcher* HTMLImportsController::fetcher() const |
154 { | 140 { |
155 return m_master->fetcher(); | 141 return m_master->fetcher(); |
156 } | 142 } |
157 | 143 |
(...skipping 27 matching lines...) Expand all Loading... |
185 { | 171 { |
186 for (size_t i = 0; i < m_loaders.size(); ++i) { | 172 for (size_t i = 0; i < m_loaders.size(); ++i) { |
187 if (m_loaders[i]->document() == &document) | 173 if (m_loaders[i]->document() == &document) |
188 return m_loaders[i].get(); | 174 return m_loaders[i].get(); |
189 } | 175 } |
190 | 176 |
191 return 0; | 177 return 0; |
192 } | 178 } |
193 | 179 |
194 } // namespace WebCore | 180 } // namespace WebCore |
OLD | NEW |