Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: Source/core/html/imports/HTMLImportsController.cpp

Issue 305723004: Make HTMLImportTreeNode own the whole import tree. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 = 0;
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
77 m_root = 0;
78 } 74 }
79 75
80 static bool makesCycle(HTMLImport* parent, const KURL& url) 76 static bool makesCycle(HTMLImport* parent, const KURL& url)
81 { 77 {
82 for (HTMLImport* ancestor = parent; ancestor; ancestor = ancestor->parent()) { 78 for (HTMLImport* ancestor = parent; ancestor; ancestor = ancestor->parent()) {
83 if (!ancestor->isRoot() && equalIgnoringFragmentIdentifier(toHTMLImportC hild(parent)->url(), url)) 79 if (!ancestor->isRoot() && equalIgnoringFragmentIdentifier(toHTMLImportC hild(parent)->url(), url))
84 return true; 80 return true;
85 } 81 }
86 82
87 return false; 83 return false;
88 } 84 }
89 85
90 HTMLImportChild* HTMLImportsController::createChild(const KURL& url, HTMLImportL oader* loader, HTMLImport* parent, HTMLImportChildClient* client) 86 HTMLImportChild* HTMLImportsController::createChild(const KURL& url, HTMLImportL oader* loader, HTMLImport* parent, HTMLImportChildClient* client)
91 { 87 {
92 HTMLImport::SyncMode mode = client->isSync() && !makesCycle(parent, url) ? H TMLImport::Sync : HTMLImport::Async; 88 HTMLImport::SyncMode mode = client->isSync() && !makesCycle(parent, url) ? H TMLImport::Sync : HTMLImport::Async;
93 OwnPtr<HTMLImportChild> child = adoptPtr(new HTMLImportChild(url, loader, mo de)); 89 OwnPtr<HTMLImportChild> child = adoptPtr(new HTMLImportChild(url, loader, mo de));
94 child->setClient(client); 90 child->setClient(client);
95 parent->appendImport(child.get()); 91 parent->appendImport(child.get());
96 loader->addImport(child.get()); 92 loader->addImport(child.get());
97 m_imports.append(child.release()); 93 return root()->keep(child.release());
98 return m_imports.last().get();
99 } 94 }
100 95
101 HTMLImportChild* HTMLImportsController::load(HTMLImport* parent, HTMLImportChild Client* client, FetchRequest request) 96 HTMLImportChild* HTMLImportsController::load(HTMLImport* parent, HTMLImportChild Client* client, FetchRequest request)
102 { 97 {
103 ASSERT(!request.url().isEmpty() && request.url().isValid()); 98 ASSERT(!request.url().isEmpty() && request.url().isValid());
104 ASSERT(parent == root() || toHTMLImportChild(parent)->loader()->isFirstImpor t(toHTMLImportChild(parent))); 99 ASSERT(parent == root() || toHTMLImportChild(parent)->loader()->isFirstImpor t(toHTMLImportChild(parent)));
105 100
106 if (HTMLImportChild* childToShareWith = findLinkFor(request.url())) { 101 if (HTMLImportChild* childToShareWith = root()->find(request.url())) {
107 HTMLImportLoader* loader = childToShareWith->loader(); 102 HTMLImportLoader* loader = childToShareWith->loader();
108 ASSERT(loader); 103 ASSERT(loader);
109 HTMLImportChild* child = createChild(request.url(), loader, parent, clie nt); 104 HTMLImportChild* child = createChild(request.url(), loader, parent, clie nt);
110 child->didShareLoader(); 105 child->didShareLoader();
111 return child; 106 return child;
112 } 107 }
113 108
114 bool sameOriginRequest = securityOrigin()->canRequest(request.url()); 109 bool sameOriginRequest = securityOrigin()->canRequest(request.url());
115 request.setCrossOriginAccessControl( 110 request.setCrossOriginAccessControl(
116 securityOrigin(), sameOriginRequest ? AllowStoredCredentials : DoNotAllo wStoredCredentials, 111 securityOrigin(), sameOriginRequest ? AllowStoredCredentials : DoNotAllo wStoredCredentials,
(...skipping 10 matching lines...) Expand all
127 child->didStartLoading(); 122 child->didStartLoading();
128 123
129 return child; 124 return child;
130 } 125 }
131 126
132 void HTMLImportsController::showSecurityErrorMessage(const String& message) 127 void HTMLImportsController::showSecurityErrorMessage(const String& message)
133 { 128 {
134 m_master->addConsoleMessage(JSMessageSource, ErrorMessageLevel, message); 129 m_master->addConsoleMessage(JSMessageSource, ErrorMessageLevel, message);
135 } 130 }
136 131
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 132 SecurityOrigin* HTMLImportsController::securityOrigin() const
149 { 133 {
150 return m_master->securityOrigin(); 134 return m_master->securityOrigin();
151 } 135 }
152 136
153 ResourceFetcher* HTMLImportsController::fetcher() const 137 ResourceFetcher* HTMLImportsController::fetcher() const
154 { 138 {
155 return m_master->fetcher(); 139 return m_master->fetcher();
156 } 140 }
157 141
(...skipping 27 matching lines...) Expand all
185 { 169 {
186 for (size_t i = 0; i < m_loaders.size(); ++i) { 170 for (size_t i = 0; i < m_loaders.size(); ++i) {
187 if (m_loaders[i]->document() == &document) 171 if (m_loaders[i]->document() == &document)
188 return m_loaders[i].get(); 172 return m_loaders[i].get();
189 } 173 }
190 174
191 return 0; 175 return 0;
192 } 176 }
193 177
194 } // namespace WebCore 178 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698