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

Side by Side Diff: sky/engine/core/html/imports/HTMLImportLoader.cpp

Issue 1215103007: Remove remaining HTML elements (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 5 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
OLDNEW
(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 #include "sky/engine/core/html/imports/HTMLImportLoader.h"
32
33 #include "base/bind.h"
34 #include "sky/engine/core/app/Module.h"
35 #include "sky/engine/core/dom/Document.h"
36 #include "sky/engine/core/dom/DocumentParser.h"
37 #include "sky/engine/core/dom/StyleEngine.h"
38 #include "sky/engine/core/html/imports/HTMLImportChild.h"
39 #include "sky/engine/core/html/imports/HTMLImportsController.h"
40
41 namespace blink {
42
43 HTMLImportLoader::HTMLImportLoader(HTMLImportsController* controller)
44 : m_controller(controller)
45 , m_state(StateLoading)
46 {
47 }
48
49 HTMLImportLoader::~HTMLImportLoader()
50 {
51 #if !ENABLE(OILPAN)
52 clear();
53 #endif
54 }
55
56 #if !ENABLE(OILPAN)
57 void HTMLImportLoader::importDestroyed()
58 {
59 clear();
60 }
61
62 void HTMLImportLoader::clear()
63 {
64 m_controller = nullptr;
65 m_module.clear();
66 if (m_document) {
67 m_document->setImportsController(0);
68 m_document->cancelParsing();
69 m_document.clear();
70 }
71 m_fetcher.clear();
72 }
73 #endif
74
75 void HTMLImportLoader::startLoading(const KURL& url)
76 {
77 m_fetcher = adoptPtr(new MojoFetcher(this, url));
78 }
79
80 void HTMLImportLoader::OnReceivedResponse(mojo::URLResponsePtr response)
81 {
82 if (response->error || response->status_code >= 400) {
83 // FIXME: Consider refactoring to use FrameConsole::reportResourceRespon seReceived
84 String message = "Failed to load resource: the server responded with a s tatus of " + String::number(response->status_code) + " (" + response->status_lin e.data() + ')';
85 RefPtr<ConsoleMessage> consoleMessage = ConsoleMessage::create(NetworkMe ssageSource, ErrorMessageLevel, message, response->url.data());
86 m_controller->master()->addMessage(consoleMessage);
87 setState(StateError);
88 return;
89 }
90 setState(startWritingAndParsing(response.Pass()));
91 }
92
93 HTMLImportLoader::State HTMLImportLoader::startWritingAndParsing(mojo::URLRespon sePtr response)
94 {
95 ASSERT(!m_imports.isEmpty());
96 WeakPtr<Document> contextDocument = m_controller->master()->contextDocument( );
97 ASSERT(contextDocument.get());
98 KURL url(ParsedURLString, String::fromUTF8(response->url));
99 DocumentInit init = DocumentInit(url, 0, contextDocument, m_controller)
100 .withElementRegistry(m_controller->master()->elementRegistry());
101 m_document = Document::create(init);
102 m_module = Module::create(contextDocument.get(), nullptr, m_document.get(), url.string());
103 m_document->startParsing()->parse(response->body.Pass(), base::Bind(base::Do Nothing));
104 return StateLoading;
105 }
106
107 HTMLImportLoader::State HTMLImportLoader::finishWriting()
108 {
109 return StateWritten;
110 }
111
112 HTMLImportLoader::State HTMLImportLoader::finishParsing()
113 {
114 return StateParsed;
115 }
116
117 HTMLImportLoader::State HTMLImportLoader::finishLoading()
118 {
119 return StateLoaded;
120 }
121
122 void HTMLImportLoader::setState(State state)
123 {
124 if (m_state == state)
125 return;
126
127 m_state = state;
128
129 if (m_state == StateParsed || m_state == StateError || m_state == StateWritt en) {
130 if (m_document)
131 m_document->cancelParsing();
132 }
133
134 // Since DocumentWriter::end() can let setState() reenter, we shouldn't refe r to m_state here.
135 if (state == StateLoaded || state == StateError)
136 didFinishLoading();
137 }
138
139 void HTMLImportLoader::didFinishParsing()
140 {
141 setState(finishParsing());
142 setState(finishLoading());
143 }
144
145 void HTMLImportLoader::didFinishLoading()
146 {
147 for (size_t i = 0; i < m_imports.size(); ++i)
148 m_imports[i]->didFinishLoading();
149
150 ASSERT(!m_document || !m_document->parsing());
151 }
152
153 void HTMLImportLoader::moveToFirst(HTMLImportChild* import)
154 {
155 size_t position = m_imports.find(import);
156 ASSERT(kNotFound != position);
157 m_imports.remove(position);
158 m_imports.insert(0, import);
159 }
160
161 void HTMLImportLoader::addImport(HTMLImportChild* import)
162 {
163 ASSERT(kNotFound == m_imports.find(import));
164
165 m_imports.append(import);
166 import->normalize();
167 if (isDone())
168 import->didFinishLoading();
169 }
170
171 #if !ENABLE(OILPAN)
172 void HTMLImportLoader::removeImport(HTMLImportChild* client)
173 {
174 ASSERT(kNotFound != m_imports.find(client));
175 m_imports.remove(m_imports.find(client));
176 }
177 #endif
178
179 bool HTMLImportLoader::shouldBlockScriptExecution() const
180 {
181 return firstImport()->state().shouldBlockScriptExecution();
182 }
183
184 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/html/imports/HTMLImportLoader.h ('k') | sky/engine/core/html/imports/HTMLImportState.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698