Index: sky/engine/core/app/ModuleLoader.cpp |
diff --git a/sky/engine/core/app/ModuleLoader.cpp b/sky/engine/core/app/ModuleLoader.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..045bc104f207d41f5ceb026545a4947dd3d67714 |
--- /dev/null |
+++ b/sky/engine/core/app/ModuleLoader.cpp |
@@ -0,0 +1,69 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "config.h" |
+#include "core/app/ModuleLoader.h" |
+ |
+#include "base/bind.h" |
+#include "core/app/Application.h" |
+#include "core/app/Module.h" |
+#include "core/dom/Document.h" |
+#include "core/dom/DocumentParser.h" |
+#include "core/html/HTMLDocument.h" |
+#include "wtf/text/WTFString.h" |
+ |
+namespace blink { |
+ |
+ModuleLoader::Client::~Client() { |
+} |
+ |
+ModuleLoader::ModuleLoader(Client* client, |
+ Application* application, |
+ const KURL& url) |
+ : state_(LOADING), |
+ client_(client), |
+ application_(application), |
+ fetcher_(adoptPtr(new MojoFetcher(this, url))), |
+ weak_factory_(this) { |
+} |
+ |
+ModuleLoader::~ModuleLoader() { |
+} |
+ |
+void ModuleLoader::OnReceivedResponse(mojo::URLResponsePtr response) { |
+ if (response->error || response->status_code >= 400) { |
+ 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!
|
+ "Failed to load resource: the server responded with a status of " + |
+ String::number(response->status_code) + |
+ " (" + response->status_line.data() + ')'; |
+ RefPtr<ConsoleMessage> consoleMessage = ConsoleMessage::create( |
+ NetworkMessageSource, ErrorMessageLevel, message, response->url.data()); |
+ application_->document()->addMessage(consoleMessage); |
+ state_ = COMPLETE; |
+ client_->OnModuleLoadComplete(this, nullptr); |
+ return; |
+ } |
+ |
+ WeakPtr<Document> context = application_->document()->contextDocument(); |
+ ASSERT(context.get()); |
+ KURL url(ParsedURLString, String::fromUTF8(response->url)); |
+ DocumentInit init = DocumentInit(url, 0, context, 0) |
+ .withRegistrationContext(context->registrationContext()); |
+ |
+ RefPtr<Document> document = HTMLDocument::create(init); |
+ document->startParsing()->parse(response->body.Pass(), |
+ base::Bind(&ModuleLoader::OnParsingComplete, weak_factory_.GetWeakPtr())); |
+ |
+ module_ = Module::create(context.get(), |
+ application_, |
+ document.release(), |
+ url.string()); |
+} |
+ |
+void ModuleLoader::OnParsingComplete() { |
+ state_ = COMPLETE; |
+ client_->OnModuleLoadComplete(this, module_.get()); |
+} |
+ |
+} // namespace blink |