OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "mojo/apps/js/js_app.h" | 5 #include "mojo/apps/js/js_app.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "gin/array_buffer.h" | 8 #include "gin/array_buffer.h" |
9 #include "gin/converter.h" | 9 #include "gin/converter.h" |
10 #include "mojo/apps/js/application_delegate_impl.h" | 10 #include "mojo/apps/js/application_delegate_impl.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 | 41 |
42 void JSApp::Quit() { | 42 void JSApp::Quit() { |
43 CHECK(on_js_app_thread()); | 43 CHECK(on_js_app_thread()); |
44 | 44 |
45 // The terminate operation is posted to the message_loop so that | 45 // The terminate operation is posted to the message_loop so that |
46 // the shell_runner isn't destroyed before this JS function returns. | 46 // the shell_runner isn't destroyed before this JS function returns. |
47 thread_.message_loop()->PostTask( | 47 thread_.message_loop()->PostTask( |
48 FROM_HERE, base::Bind(&JSApp::Terminate, base::Unretained(this))); | 48 FROM_HERE, base::Bind(&JSApp::Terminate, base::Unretained(this))); |
49 } | 49 } |
50 | 50 |
51 Handle JSApp::ConnectToService(const std::string& application_url, | 51 MessagePipeHandle JSApp::ConnectToApplication( |
52 const std::string& interface_name) { | 52 const std::string& application_url) { |
53 CHECK(on_js_app_thread()); | 53 CHECK(on_js_app_thread()); |
54 MessagePipe pipe; | 54 MessagePipe pipe; |
| 55 InterfaceRequest<ServiceProvider> request = |
| 56 MakeRequest<ServiceProvider>(pipe.handle1.Pass()); |
55 | 57 |
56 app_delegate_impl_task_runner_->PostTask( | 58 app_delegate_impl_task_runner_->PostTask( |
57 FROM_HERE, | 59 FROM_HERE, |
58 base::Bind(&ApplicationDelegateImpl::ConnectToService, | 60 base::Bind(&ApplicationDelegateImpl::ConnectToApplication, |
59 base::Unretained(app_delegate_impl_), | 61 base::Unretained(app_delegate_impl_), |
60 base::Passed(pipe.handle1.Pass()), | |
61 application_url, | 62 application_url, |
62 interface_name)); | 63 base::Passed(request.Pass()))); |
63 | 64 |
64 return pipe.handle0.release(); | 65 return pipe.handle0.Pass().release(); |
65 } | 66 } |
66 | 67 |
| 68 |
67 void JSApp::Run() { | 69 void JSApp::Run() { |
68 CHECK(!js_app_task_runner_.get() && !on_app_delegate_impl_thread()); | 70 CHECK(!js_app_task_runner_.get() && !on_app_delegate_impl_thread()); |
69 js_app_task_runner_ = base::MessageLoop::current()->task_runner(); | 71 js_app_task_runner_ = base::MessageLoop::current()->task_runner(); |
70 | 72 |
71 std::string source; | 73 std::string source; |
72 std::string file_name; | 74 std::string file_name; |
73 Load(&source, &file_name); // TODO(hansmuller): handle Load() failure. | 75 Load(&source, &file_name); // TODO(hansmuller): handle Load() failure. |
74 | 76 |
75 isolate_holder_.reset(new gin::IsolateHolder()); | 77 isolate_holder_.reset(new gin::IsolateHolder()); |
76 isolate_holder_->AddRunMicrotasksObserver(); | 78 isolate_holder_->AddRunMicrotasksObserver(); |
(...skipping 26 matching lines...) Expand all Loading... |
103 } | 105 } |
104 | 106 |
105 bool JSApp::on_js_app_thread() const { | 107 bool JSApp::on_js_app_thread() const { |
106 return js_app_task_runner_.get() && | 108 return js_app_task_runner_.get() && |
107 js_app_task_runner_.get() == | 109 js_app_task_runner_.get() == |
108 base::MessageLoop::current()->task_runner().get(); | 110 base::MessageLoop::current()->task_runner().get(); |
109 } | 111 } |
110 | 112 |
111 } // namespace apps | 113 } // namespace apps |
112 } // namespace mojo | 114 } // namespace mojo |
OLD | NEW |