Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "config.h" | |
| 6 #include "core/app/ModuleLoader.h" | |
| 7 | |
| 8 #include "base/bind.h" | |
| 9 #include "core/app/Application.h" | |
| 10 #include "core/app/Module.h" | |
| 11 #include "core/dom/Document.h" | |
| 12 #include "core/dom/DocumentParser.h" | |
| 13 #include "core/html/HTMLDocument.h" | |
| 14 #include "wtf/text/WTFString.h" | |
| 15 | |
| 16 namespace blink { | |
| 17 | |
| 18 ModuleLoader::Client::~Client() { | |
| 19 } | |
| 20 | |
| 21 ModuleLoader::ModuleLoader(Client* client, | |
| 22 Application* application, | |
| 23 const KURL& url) | |
| 24 : state_(LOADING), | |
| 25 client_(client), | |
| 26 application_(application), | |
| 27 fetcher_(adoptPtr(new MojoFetcher(this, url))), | |
| 28 weak_factory_(this) { | |
| 29 } | |
| 30 | |
| 31 ModuleLoader::~ModuleLoader() { | |
| 32 } | |
| 33 | |
| 34 void ModuleLoader::OnReceivedResponse(mojo::URLResponsePtr response) { | |
| 35 if (response->error || response->status_code >= 400) { | |
| 36 String message = | |
|
eseidel
2014/11/12 19:23:18
I think there is a String::format which will take
abarth-chromium
2014/11/12 21:15:53
Ah, nice!
| |
| 37 "Failed to load resource: the server responded with a status of " + | |
| 38 String::number(response->status_code) + | |
| 39 " (" + response->status_line.data() + ')'; | |
| 40 RefPtr<ConsoleMessage> consoleMessage = ConsoleMessage::create( | |
| 41 NetworkMessageSource, ErrorMessageLevel, message, response->url.data()); | |
| 42 application_->document()->addMessage(consoleMessage); | |
| 43 state_ = COMPLETE; | |
| 44 client_->OnModuleLoadComplete(this, nullptr); | |
| 45 return; | |
| 46 } | |
| 47 | |
| 48 WeakPtr<Document> context = application_->document()->contextDocument(); | |
| 49 ASSERT(context.get()); | |
| 50 KURL url(ParsedURLString, String::fromUTF8(response->url)); | |
| 51 DocumentInit init = DocumentInit(url, 0, context, 0) | |
| 52 .withRegistrationContext(context->registrationContext()); | |
| 53 | |
| 54 RefPtr<Document> document = HTMLDocument::create(init); | |
| 55 document->startParsing()->parse(response->body.Pass(), | |
| 56 base::Bind(&ModuleLoader::OnParsingComplete, weak_factory_.GetWeakPtr())); | |
| 57 | |
| 58 module_ = Module::create(context.get(), | |
| 59 application_, | |
| 60 document.release(), | |
| 61 url.string()); | |
| 62 } | |
| 63 | |
| 64 void ModuleLoader::OnParsingComplete() { | |
| 65 state_ = COMPLETE; | |
| 66 client_->OnModuleLoadComplete(this, module_.get()); | |
| 67 } | |
| 68 | |
| 69 } // namespace blink | |
| OLD | NEW |