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

Side by Side Diff: sky/engine/v8_inspector/inspector_backend_mojo.cc

Issue 922053002: Remove unused V8 integration code in Sky (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
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/v8_inspector/inspector_backend_mojo.h"
7
8 #include "base/memory/scoped_ptr.h"
9 #include "base/run_loop.h"
10 #include "gen/v8_inspector/InspectorBackendDispatcher.h"
11 #include "mojo/public/cpp/application/connect.h"
12 #include "mojo/public/cpp/application/service_provider_impl.h"
13 #include "mojo/public/interfaces/application/shell.mojom.h"
14 #include "sky/engine/core/inspector/InjectedScriptHost.h"
15 #include "sky/engine/platform/JSONValues.h"
16 #include "sky/engine/v8_inspector/InspectorFrontendChannel.h"
17 #include "sky/engine/v8_inspector/InspectorState.h"
18 #include "sky/engine/v8_inspector/InstrumentingAgents.h"
19 #include "sky/engine/v8_inspector/PageDebuggerAgent.h"
20 #include "sky/engine/v8_inspector/PageScriptDebugServer.h"
21 #include "sky/engine/v8_inspector/inspector_host.h"
22
23 namespace blink {
24
25 class InspectorBackendMojoImpl
26 : public InspectorFrontendChannel,
27 public sky::InspectorBackend,
28 public mojo::InterfaceFactory<sky::InspectorBackend> {
29 public:
30 explicit InspectorBackendMojoImpl(inspector::InspectorHost*);
31 ~InspectorBackendMojoImpl();
32
33 void Connect();
34
35 private:
36 // InspectorBackend:
37 void OnConnect();
38 void OnMessage(const mojo::String& message) override;
39 void OnDisconnect();
40
41 // InspectorFrontendChannel:
42 void sendMessageToFrontend(PassRefPtr<JSONObject> message) override;
43 // TODO(eseidel): Unclear if flush is needed.
44 void flush() override {}
45
46 // mojo::InterfaceFactory<sky::InspectorBackend>
47 void Create(mojo::ApplicationConnection* connection,
48 mojo::InterfaceRequest<sky::InspectorBackend> request) override;
49
50 inspector::InspectorHost* host_;
51 sky::InspectorFrontendPtr frontend_;
52 mojo::ServiceProviderImpl inspector_service_provider_;
53
54 OwnPtr<InspectorFrontend> old_frontend_;
55 RefPtr<InspectorBackendDispatcher> dispatcher_;
56 OwnPtr<PageDebuggerAgent> debugger_agent_;
57 OwnPtr<InjectedScriptManager> script_manager_;
58 OwnPtr<InspectorState> inspector_state_;
59 OwnPtr<InstrumentingAgents> agents_;
60
61 mojo::Binding<sky::InspectorBackend> binding_;
62
63 DISALLOW_COPY_AND_ASSIGN(InspectorBackendMojoImpl);
64 };
65
66 // FIXME: Probably this should be provided by the InspectorHost?
67 class MessageLoopAdaptor : public PageScriptDebugServer::ClientMessageLoop {
68 public:
69 MessageLoopAdaptor() {}
70
71 private:
72 virtual void run(inspector::InspectorHost* host) {
73 run_loop_.reset(new base::RunLoop());
74 run_loop_->Run();
75 }
76
77 virtual void quitNow() {
78 if (run_loop_)
79 run_loop_->Quit();
80 }
81
82 scoped_ptr<base::RunLoop> run_loop_;
83 };
84
85 class InspectorHostResolverImpl : public PageScriptDebugServer::InspectorHostRes olver {
86 public:
87 explicit InspectorHostResolverImpl(inspector::InspectorHost* host) : host_(hos t) { }
88 ~InspectorHostResolverImpl() override { }
89 inspector::InspectorHost* inspectorHostFor(v8::Handle<v8::Context> context) ov erride {
90 if (context == host_->GetContext())
91 return host_;
92 return nullptr;
93 }
94 private:
95 inspector::InspectorHost* host_;
96 };
97
98 InspectorBackendMojoImpl::InspectorBackendMojoImpl(
99 inspector::InspectorHost* host)
100 : host_(host), binding_(this) {
101 inspector_service_provider_.AddService(this);
102 }
103
104 InspectorBackendMojoImpl::~InspectorBackendMojoImpl() {
105 }
106
107 void InspectorBackendMojoImpl::Connect() {
108 mojo::Shell* shell = host_->GetShell();
109
110 mojo::ServiceProviderPtr services;
111 mojo::ServiceProviderPtr exposed_services;
112 inspector_service_provider_.Bind(GetProxy(&exposed_services));
113 shell->ConnectToApplication("mojo:sky_inspector_server", GetProxy(&services),
114 exposed_services.Pass());
115 mojo::ConnectToService(services.get(), &frontend_);
116
117 // Theoretically we should load our state from the inspector cookie.
118 inspector_state_ =
119 adoptPtr(new InspectorState(nullptr, JSONObject::create()));
120 old_frontend_ = adoptPtr(new InspectorFrontend(this));
121
122 PageScriptDebugServer::setMainThreadIsolate(host_->GetIsolate());
123 OwnPtr<MessageLoopAdaptor> message_loop = adoptPtr(new MessageLoopAdaptor);
124 PageScriptDebugServer::shared().setClientMessageLoop(message_loop.release());
125 OwnPtr<InspectorHostResolverImpl> host_resolver =
126 adoptPtr(new InspectorHostResolverImpl(host_));
127 PageScriptDebugServer::shared().setInspectorHostResolver(host_resolver.release ());
128
129 // AgentRegistry used to do this, but we don't need it for one agent.
130 script_manager_ = InjectedScriptManager::createForPage();
131 debugger_agent_ = PageDebuggerAgent::create(&PageScriptDebugServer::shared(),
132 host_, script_manager_.get());
133 agents_ = adoptPtr(new InstrumentingAgents(debugger_agent_.get()));
134 script_manager_->injectedScriptHost()->init(agents_.get(), &PageScriptDebugSer ver::shared());
135 debugger_agent_->init(agents_.get(), inspector_state_.get());
136 debugger_agent_->setFrontend(old_frontend_.get());
137
138 dispatcher_ = InspectorBackendDispatcher::create(this);
139 dispatcher_->registerAgent(debugger_agent_.get());
140 }
141
142 void InspectorBackendMojoImpl::OnConnect() {
143 }
144
145 void InspectorBackendMojoImpl::OnDisconnect() {
146 }
147
148 void InspectorBackendMojoImpl::sendMessageToFrontend(
149 PassRefPtr<JSONObject> message) {
150 frontend_->SendMessage(message->toJSONString().toUTF8());
151 }
152
153 void InspectorBackendMojoImpl::OnMessage(const mojo::String& message) {
154 String wtf_message = String::fromUTF8(message.To<std::string>());
155 String command_name;
156 InspectorBackendDispatcher::getCommandName(wtf_message, &command_name);
157 // InspectorBackendDispatcher will automatically reply with errors
158 // if agents are missing, since we only want this backend to care about
159 // the Debugger agent, we manually filter here.
160 if (command_name.startsWith("Debugger"))
161 dispatcher_->dispatch(wtf_message);
162 }
163
164 void InspectorBackendMojoImpl::Create(
165 mojo::ApplicationConnection* connection,
166 mojo::InterfaceRequest<sky::InspectorBackend> request) {
167 binding_.Bind(request.Pass());
168 }
169
170 } // namespace blink
171
172 namespace inspector {
173
174 InspectorBackendMojo::InspectorBackendMojo(InspectorHost* host)
175 : impl_(new blink::InspectorBackendMojoImpl(host)) {
176 }
177
178 InspectorBackendMojo::~InspectorBackendMojo() {
179 }
180
181 void InspectorBackendMojo::Connect() {
182 impl_->Connect();
183 }
184
185 } // namespace inspector
OLDNEW
« no previous file with comments | « sky/engine/v8_inspector/inspector_backend_mojo.h ('k') | sky/engine/v8_inspector/inspector_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698