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

Side by Side Diff: mojo/apps/js/js_app.cc

Issue 703023004: Move the JS content handler et al from mojo/apps/js to mojo/services (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Fixed DEPS gl build 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 | « mojo/apps/js/js_app.h ('k') | mojo/apps/js/main.js » ('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 "mojo/apps/js/js_app.h"
6
7 #include "base/bind.h"
8 #include "gin/array_buffer.h"
9 #include "gin/converter.h"
10 #include "mojo/apps/js/mojo_bridge_module.h"
11 #include "mojo/common/data_pipe_utils.h"
12
13 namespace mojo {
14 namespace apps {
15
16 JSApp::JSApp(ShellPtr shell, URLResponsePtr response) : shell_(shell.Pass()) {
17 // TODO(hansmuller): handle load failure here and below.
18 DCHECK(!response.is_null());
19 file_name_ = response->url;
20 bool result = common::BlockingCopyToString(response->body.Pass(), &source_);
21 DCHECK(result);
22
23 runner_delegate.AddBuiltinModule(MojoInternals::kModuleName,
24 base::Bind(MojoInternals::GetModule, this));
25 shell_.set_client(this);
26 }
27
28 JSApp::~JSApp() {
29 }
30
31 void JSApp::Quit() {
32 isolate_holder_.RemoveRunMicrotasksObserver();
33 base::MessageLoop::current()->PostTask(
34 FROM_HERE, base::Bind(&JSApp::QuitInternal, base::Unretained(this)));
35 }
36
37 MessagePipeHandle JSApp::ConnectToApplication(
38 const std::string& application_url) {
39 MessagePipe pipe;
40 InterfaceRequest<ServiceProvider> request =
41 MakeRequest<ServiceProvider>(pipe.handle1.Pass());
42 shell_->ConnectToApplication(application_url, request.Pass());
43 return pipe.handle0.Pass().release();
44 }
45
46 MessagePipeHandle JSApp::RequestorMessagePipeHandle() {
47 return requestor_handle_.get();
48 }
49
50 void JSApp::AcceptConnection(const String& requestor_url,
51 ServiceProviderPtr provider) {
52 requestor_handle_ = provider.PassMessagePipe();
53
54 isolate_holder_.AddRunMicrotasksObserver();
55 shell_runner_.reset(
56 new gin::ShellRunner(&runner_delegate, isolate_holder_.isolate()));
57 gin::Runner::Scope scope(shell_runner_.get());
58 shell_runner_->Run(source_.c_str(), file_name_.c_str());
59 }
60
61 void JSApp::Initialize(Array<String> args) {
62 }
63
64 void JSApp::QuitInternal() {
65 shell_runner_.reset();
66 base::MessageLoop::current()->QuitWhenIdle();
67 }
68
69 } // namespace apps
70 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/apps/js/js_app.h ('k') | mojo/apps/js/main.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698