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

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

Issue 922893002: Merge the Sky Engine changes from the SkyDart branch (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 months 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 "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
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