| 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 "sky/engine/config.h" | |
| 6 #include "sky/engine/core/app/ModuleLoader.h" | |
| 7 | |
| 8 #include "base/bind.h" | |
| 9 #include "sky/engine/core/app/Application.h" | |
| 10 #include "sky/engine/core/app/Module.h" | |
| 11 #include "sky/engine/core/dom/Document.h" | |
| 12 #include "sky/engine/core/dom/DocumentParser.h" | |
| 13 #include "sky/engine/wtf/text/WTFString.h" | |
| 14 | |
| 15 namespace blink { | |
| 16 | |
| 17 ModuleLoader::Client::~Client() { | |
| 18 } | |
| 19 | |
| 20 ModuleLoader::ModuleLoader(Client* client, | |
| 21 Application* application, | |
| 22 const KURL& url) | |
| 23 : state_(LOADING), | |
| 24 client_(client), | |
| 25 application_(application), | |
| 26 fetcher_(adoptPtr(new MojoFetcher(this, url))), | |
| 27 weak_factory_(this) { | |
| 28 } | |
| 29 | |
| 30 ModuleLoader::~ModuleLoader() { | |
| 31 } | |
| 32 | |
| 33 void ModuleLoader::OnReceivedResponse(mojo::URLResponsePtr response) { | |
| 34 if (response->error || response->status_code >= 400) { | |
| 35 String message = String::format( | |
| 36 "Failed to load resource: Server responded with a status of %d (%s)", | |
| 37 response->status_code, response->status_line.data()); | |
| 38 RefPtr<ConsoleMessage> consoleMessage = ConsoleMessage::create( | |
| 39 NetworkMessageSource, ErrorMessageLevel, message, response->url.data()); | |
| 40 application_->document()->addMessage(consoleMessage); | |
| 41 state_ = COMPLETE; | |
| 42 client_->OnModuleLoadComplete(this, nullptr); | |
| 43 return; | |
| 44 } | |
| 45 | |
| 46 WeakPtr<Document> context = application_->document()->contextDocument(); | |
| 47 ASSERT(context.get()); | |
| 48 KURL url(ParsedURLString, String::fromUTF8(response->url)); | |
| 49 DocumentInit init = DocumentInit(url, 0, context, 0) | |
| 50 .withRegistrationContext(context->registrationContext()); | |
| 51 | |
| 52 RefPtr<Document> document = Document::create(init); | |
| 53 document->startParsing()->parse(response->body.Pass(), | |
| 54 base::Bind(&ModuleLoader::OnParsingComplete, weak_factory_.GetWeakPtr())); | |
| 55 | |
| 56 module_ = Module::create( | |
| 57 context.get(), application_, document.release(), url.string()); | |
| 58 } | |
| 59 | |
| 60 void ModuleLoader::OnParsingComplete() { | |
| 61 state_ = COMPLETE; | |
| 62 client_->OnModuleLoadComplete(this, module_.get()); | |
| 63 } | |
| 64 | |
| 65 } // namespace blink | |
| OLD | NEW |