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

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

Issue 678683004: HTMLImportLoader should talk directly to mojo::NetworkService (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: address reviewer comments Created 6 years, 1 month 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
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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 } 63 }
64 64
65 void HTMLImportLoader::clear() 65 void HTMLImportLoader::clear()
66 { 66 {
67 m_controller = nullptr; 67 m_controller = nullptr;
68 if (m_document) { 68 if (m_document) {
69 m_document->setImportsController(0); 69 m_document->setImportsController(0);
70 m_document->cancelParsing(); 70 m_document->cancelParsing();
71 m_document.clear(); 71 m_document.clear();
72 } 72 }
73 m_fetcher.clear();
74 m_drainer.clear();
73 } 75 }
74 #endif 76 #endif
75 77
76 void HTMLImportLoader::startLoading(const ResourcePtr<RawResource>& resource) 78 void HTMLImportLoader::startLoading(const KURL& url)
77 { 79 {
78 setResource(resource); 80 m_fetcher = adoptPtr(new MojoFetcher(this, url));
79 } 81 }
80 82
81 void HTMLImportLoader::responseReceived(Resource* resource, const ResourceRespon se& response) 83 void HTMLImportLoader::OnReceivedResponse(mojo::URLResponsePtr response)
82 { 84 {
83 // Resource may already have been loaded with the import loader 85 if (response->error || response->status_code >= 400) {
84 // being added as a client later & now being notified. Fail early.
85 if (resource->loadFailedOrCanceled() || response.httpStatusCode() >= 400) {
86 setState(StateError); 86 setState(StateError);
87 return; 87 return;
88 } 88 }
89 setState(startWritingAndParsing(response)); 89 mojo::ScopedDataPipeConsumerHandle body = response->body.Pass();
90 setState(startWritingAndParsing(response.Pass()));
91 m_drainer = adoptPtr(new DataPipeDrainer(this, body.Pass()));
90 } 92 }
91 93
92 void HTMLImportLoader::dataReceived(Resource*, const char* data, int length) 94 void HTMLImportLoader::OnDataAvailable(const void* data, size_t length)
93 { 95 {
94 RefPtrWillBeRawPtr<DocumentWriter> protectingWriter(m_writer.get()); 96 RefPtrWillBeRawPtr<DocumentWriter> protectingWriter(m_writer.get());
95 m_writer->addData(data, length); 97 m_writer->addData(static_cast<const char*>(data), length);
96 } 98 }
97 99
98 void HTMLImportLoader::notifyFinished(Resource* resource) 100 void HTMLImportLoader::OnDataComplete()
99 { 101 {
100 // The writer instance indicates that a part of the document can be already loaded.
101 // We don't take such a case as an error because the partially-loaded docume nt has been visible from script at this point.
102 if (resource->loadFailedOrCanceled() && !m_writer) {
103 setState(StateError);
104 return;
105 }
106
107 setState(finishWriting()); 102 setState(finishWriting());
108 } 103 }
109 104
110 HTMLImportLoader::State HTMLImportLoader::startWritingAndParsing(const ResourceR esponse& response) 105 HTMLImportLoader::State HTMLImportLoader::startWritingAndParsing(mojo::URLRespon sePtr response)
111 { 106 {
112 ASSERT(!m_imports.isEmpty()); 107 ASSERT(!m_imports.isEmpty());
113 DocumentInit init = DocumentInit(response.url(), 0, m_controller->master()-> contextDocument(), m_controller) 108 KURL url(ParsedURLString, String::fromUTF8(response->url));
109 DocumentInit init = DocumentInit(url, 0, m_controller->master()->contextDocu ment(), m_controller)
114 .withRegistrationContext(m_controller->master()->registrationContext()); 110 .withRegistrationContext(m_controller->master()->registrationContext());
115 m_document = HTMLDocument::create(init); 111 m_document = HTMLDocument::create(init);
116 m_writer = DocumentWriter::create(m_document.get()); 112 m_writer = DocumentWriter::create(m_document.get());
117 113
118 return StateLoading; 114 return StateLoading;
119 } 115 }
120 116
121 HTMLImportLoader::State HTMLImportLoader::finishWriting() 117 HTMLImportLoader::State HTMLImportLoader::finishWriting()
122 { 118 {
123 return StateWritten; 119 return StateWritten;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 { 156 {
161 if (m_state == StateParsed) 157 if (m_state == StateParsed)
162 setState(finishLoading()); 158 setState(finishLoading());
163 } 159 }
164 160
165 void HTMLImportLoader::didFinishLoading() 161 void HTMLImportLoader::didFinishLoading()
166 { 162 {
167 for (size_t i = 0; i < m_imports.size(); ++i) 163 for (size_t i = 0; i < m_imports.size(); ++i)
168 m_imports[i]->didFinishLoading(); 164 m_imports[i]->didFinishLoading();
169 165
170 clearResource();
171
172 ASSERT(!m_document || !m_document->parsing()); 166 ASSERT(!m_document || !m_document->parsing());
173 } 167 }
174 168
175 void HTMLImportLoader::moveToFirst(HTMLImportChild* import) 169 void HTMLImportLoader::moveToFirst(HTMLImportChild* import)
176 { 170 {
177 size_t position = m_imports.find(import); 171 size_t position = m_imports.find(import);
178 ASSERT(kNotFound != position); 172 ASSERT(kNotFound != position);
179 m_imports.remove(position); 173 m_imports.remove(position);
180 m_imports.insert(0, import); 174 m_imports.insert(0, import);
181 } 175 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 visitor->trace(m_controller); 207 visitor->trace(m_controller);
214 #if ENABLE(OILPAN) 208 #if ENABLE(OILPAN)
215 visitor->trace(m_imports); 209 visitor->trace(m_imports);
216 #endif 210 #endif
217 visitor->trace(m_document); 211 visitor->trace(m_document);
218 visitor->trace(m_writer); 212 visitor->trace(m_writer);
219 visitor->trace(m_microtaskQueue); 213 visitor->trace(m_microtaskQueue);
220 } 214 }
221 215
222 } // namespace blink 216 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/html/imports/HTMLImportLoader.h ('k') | sky/engine/core/html/imports/HTMLImportsController.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698