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

Side by Side Diff: sky/engine/core/app/ModuleLoader.cpp

Issue 720903002: Script-based imports should basically work (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: 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
« no previous file with comments | « sky/engine/core/app/ModuleLoader.h ('k') | sky/engine/core/core.gni » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
OLDNEW
« no previous file with comments | « sky/engine/core/app/ModuleLoader.h ('k') | sky/engine/core/core.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698