| 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 "sky/engine/config.h" | 5 #include "sky/engine/config.h" |
| 6 #include "sky/engine/v8_inspector/inspector_backend_mojo.h" | 6 #include "sky/engine/v8_inspector/inspector_backend_mojo.h" |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "gen/v8_inspector/InspectorBackendDispatcher.h" | 10 #include "gen/v8_inspector/InspectorBackendDispatcher.h" |
| 11 #include "mojo/public/cpp/application/connect.h" | 11 #include "mojo/public/cpp/application/connect.h" |
| 12 #include "mojo/public/cpp/application/service_provider_impl.h" | 12 #include "mojo/public/cpp/application/service_provider_impl.h" |
| 13 #include "mojo/public/interfaces/application/shell.mojom.h" | 13 #include "mojo/public/interfaces/application/shell.mojom.h" |
| 14 #include "sky/engine/core/inspector/InjectedScriptHost.h" | 14 #include "sky/engine/core/inspector/InjectedScriptHost.h" |
| 15 #include "sky/engine/platform/JSONValues.h" | 15 #include "sky/engine/platform/JSONValues.h" |
| 16 #include "sky/engine/v8_inspector/InspectorFrontendChannel.h" | 16 #include "sky/engine/v8_inspector/InspectorFrontendChannel.h" |
| 17 #include "sky/engine/v8_inspector/InspectorState.h" | 17 #include "sky/engine/v8_inspector/InspectorState.h" |
| 18 #include "sky/engine/v8_inspector/InstrumentingAgents.h" | 18 #include "sky/engine/v8_inspector/InstrumentingAgents.h" |
| 19 #include "sky/engine/v8_inspector/PageDebuggerAgent.h" | 19 #include "sky/engine/v8_inspector/PageDebuggerAgent.h" |
| 20 #include "sky/engine/v8_inspector/PageScriptDebugServer.h" | 20 #include "sky/engine/v8_inspector/PageScriptDebugServer.h" |
| 21 #include "sky/engine/v8_inspector/inspector_host.h" | 21 #include "sky/engine/v8_inspector/inspector_host.h" |
| 22 | 22 |
| 23 namespace blink { | 23 namespace blink { |
| 24 | 24 |
| 25 class InspectorBackendMojoImpl | 25 class InspectorBackendMojoImpl |
| 26 : public InspectorFrontendChannel, | 26 : public InspectorFrontendChannel, |
| 27 public mojo::InterfaceImpl<sky::InspectorBackend> { | 27 public sky::InspectorBackend, |
| 28 public mojo::InterfaceFactory<sky::InspectorBackend> { |
| 28 public: | 29 public: |
| 29 explicit InspectorBackendMojoImpl(inspector::InspectorHost*); | 30 explicit InspectorBackendMojoImpl(inspector::InspectorHost*); |
| 30 ~InspectorBackendMojoImpl(); | 31 ~InspectorBackendMojoImpl(); |
| 31 | 32 |
| 32 void Connect(); | 33 void Connect(); |
| 33 | 34 |
| 35 private: |
| 34 // InspectorBackend: | 36 // InspectorBackend: |
| 35 void OnConnect(); | 37 void OnConnect(); |
| 36 void OnMessage(const mojo::String& message) override; | 38 void OnMessage(const mojo::String& message) override; |
| 37 void OnDisconnect(); | 39 void OnDisconnect(); |
| 38 | 40 |
| 39 // InspectorFrontendChannel: | 41 // InspectorFrontendChannel: |
| 40 void sendMessageToFrontend(PassRefPtr<JSONObject> message) override; | 42 void sendMessageToFrontend(PassRefPtr<JSONObject> message) override; |
| 41 // TODO(eseidel): Unclear if flush is needed. | 43 // TODO(eseidel): Unclear if flush is needed. |
| 42 void flush() override {} | 44 void flush() override {} |
| 43 | 45 |
| 46 // mojo::InterfaceFactory<sky::InspectorBackend> |
| 47 void Create(mojo::ApplicationConnection* connection, |
| 48 mojo::InterfaceRequest<sky::InspectorBackend> request) override; |
| 49 |
| 44 inspector::InspectorHost* host_; | 50 inspector::InspectorHost* host_; |
| 45 sky::InspectorFrontendPtr frontend_; | 51 sky::InspectorFrontendPtr frontend_; |
| 52 mojo::ServiceProviderImpl inspector_service_provider_; |
| 46 | 53 |
| 47 OwnPtr<InspectorFrontend> old_frontend_; | 54 OwnPtr<InspectorFrontend> old_frontend_; |
| 48 RefPtr<InspectorBackendDispatcher> dispatcher_; | 55 RefPtr<InspectorBackendDispatcher> dispatcher_; |
| 49 OwnPtr<PageDebuggerAgent> debugger_agent_; | 56 OwnPtr<PageDebuggerAgent> debugger_agent_; |
| 50 OwnPtr<InjectedScriptManager> script_manager_; | 57 OwnPtr<InjectedScriptManager> script_manager_; |
| 51 OwnPtr<InspectorState> inspector_state_; | 58 OwnPtr<InspectorState> inspector_state_; |
| 52 OwnPtr<InstrumentingAgents> agents_; | 59 OwnPtr<InstrumentingAgents> agents_; |
| 53 | 60 |
| 61 mojo::Binding<sky::InspectorBackend> binding_; |
| 62 |
| 54 DISALLOW_COPY_AND_ASSIGN(InspectorBackendMojoImpl); | 63 DISALLOW_COPY_AND_ASSIGN(InspectorBackendMojoImpl); |
| 55 }; | 64 }; |
| 56 | 65 |
| 57 // FIXME: Probably this should be provided by the InspectorHost? | 66 // FIXME: Probably this should be provided by the InspectorHost? |
| 58 class MessageLoopAdaptor : public PageScriptDebugServer::ClientMessageLoop { | 67 class MessageLoopAdaptor : public PageScriptDebugServer::ClientMessageLoop { |
| 59 public: | 68 public: |
| 60 MessageLoopAdaptor() {} | 69 MessageLoopAdaptor() {} |
| 61 | 70 |
| 62 private: | 71 private: |
| 63 virtual void run(inspector::InspectorHost* host) { | 72 virtual void run(inspector::InspectorHost* host) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 81 if (context == host_->GetContext()) | 90 if (context == host_->GetContext()) |
| 82 return host_; | 91 return host_; |
| 83 return nullptr; | 92 return nullptr; |
| 84 } | 93 } |
| 85 private: | 94 private: |
| 86 inspector::InspectorHost* host_; | 95 inspector::InspectorHost* host_; |
| 87 }; | 96 }; |
| 88 | 97 |
| 89 InspectorBackendMojoImpl::InspectorBackendMojoImpl( | 98 InspectorBackendMojoImpl::InspectorBackendMojoImpl( |
| 90 inspector::InspectorHost* host) | 99 inspector::InspectorHost* host) |
| 91 : host_(host) { | 100 : host_(host), binding_(this) { |
| 101 inspector_service_provider_.AddService(this); |
| 92 } | 102 } |
| 93 | 103 |
| 94 InspectorBackendMojoImpl::~InspectorBackendMojoImpl() { | 104 InspectorBackendMojoImpl::~InspectorBackendMojoImpl() { |
| 95 } | 105 } |
| 96 | 106 |
| 97 void InspectorBackendMojoImpl::Connect() { | 107 void InspectorBackendMojoImpl::Connect() { |
| 98 mojo::Shell* shell = host_->GetShell(); | 108 mojo::Shell* shell = host_->GetShell(); |
| 99 mojo::ServiceProviderPtr inspector_service_provider; | 109 mojo::InterfaceRequest<mojo::ServiceProvider> service_provider_request; |
| 110 mojo::MessagePipe pipe; |
| 111 service_provider_request.Bind(pipe.handle0.Pass()); |
| 112 inspector_service_provider_.BindToHandle(pipe.handle1.Pass()); |
| 100 shell->ConnectToApplication("mojo:sky_inspector_server", | 113 shell->ConnectToApplication("mojo:sky_inspector_server", |
| 101 GetProxy(&inspector_service_provider)); | 114 service_provider_request.Pass()); |
| 102 mojo::ConnectToService(inspector_service_provider.get(), &frontend_); | 115 mojo::ConnectToService(&inspector_service_provider_, &frontend_); |
| 103 frontend_.set_client(this); | |
| 104 | 116 |
| 105 // Theoretically we should load our state from the inspector cookie. | 117 // Theoretically we should load our state from the inspector cookie. |
| 106 inspector_state_ = | 118 inspector_state_ = |
| 107 adoptPtr(new InspectorState(nullptr, JSONObject::create())); | 119 adoptPtr(new InspectorState(nullptr, JSONObject::create())); |
| 108 old_frontend_ = adoptPtr(new InspectorFrontend(this)); | 120 old_frontend_ = adoptPtr(new InspectorFrontend(this)); |
| 109 | 121 |
| 110 PageScriptDebugServer::setMainThreadIsolate(host_->GetIsolate()); | 122 PageScriptDebugServer::setMainThreadIsolate(host_->GetIsolate()); |
| 111 OwnPtr<MessageLoopAdaptor> message_loop = adoptPtr(new MessageLoopAdaptor); | 123 OwnPtr<MessageLoopAdaptor> message_loop = adoptPtr(new MessageLoopAdaptor); |
| 112 PageScriptDebugServer::shared().setClientMessageLoop(message_loop.release()); | 124 PageScriptDebugServer::shared().setClientMessageLoop(message_loop.release()); |
| 113 OwnPtr<InspectorHostResolverImpl> host_resolver = | 125 OwnPtr<InspectorHostResolverImpl> host_resolver = |
| (...skipping 28 matching lines...) Expand all Loading... |
| 142 String wtf_message = String::fromUTF8(message.To<std::string>()); | 154 String wtf_message = String::fromUTF8(message.To<std::string>()); |
| 143 String command_name; | 155 String command_name; |
| 144 InspectorBackendDispatcher::getCommandName(wtf_message, &command_name); | 156 InspectorBackendDispatcher::getCommandName(wtf_message, &command_name); |
| 145 // InspectorBackendDispatcher will automatically reply with errors | 157 // InspectorBackendDispatcher will automatically reply with errors |
| 146 // if agents are missing, since we only want this backend to care about | 158 // if agents are missing, since we only want this backend to care about |
| 147 // the Debugger agent, we manually filter here. | 159 // the Debugger agent, we manually filter here. |
| 148 if (command_name.startsWith("Debugger")) | 160 if (command_name.startsWith("Debugger")) |
| 149 dispatcher_->dispatch(wtf_message); | 161 dispatcher_->dispatch(wtf_message); |
| 150 } | 162 } |
| 151 | 163 |
| 164 void InspectorBackendMojoImpl::Create( |
| 165 mojo::ApplicationConnection* connection, |
| 166 mojo::InterfaceRequest<sky::InspectorBackend> request) { |
| 167 binding_.Bind(request.Pass()); |
| 168 } |
| 169 |
| 152 } // namespace blink | 170 } // namespace blink |
| 153 | 171 |
| 154 namespace inspector { | 172 namespace inspector { |
| 155 | 173 |
| 156 InspectorBackendMojo::InspectorBackendMojo(InspectorHost* host) | 174 InspectorBackendMojo::InspectorBackendMojo(InspectorHost* host) |
| 157 : impl_(new blink::InspectorBackendMojoImpl(host)) { | 175 : impl_(new blink::InspectorBackendMojoImpl(host)) { |
| 158 } | 176 } |
| 159 | 177 |
| 160 InspectorBackendMojo::~InspectorBackendMojo() { | 178 InspectorBackendMojo::~InspectorBackendMojo() { |
| 161 } | 179 } |
| 162 | 180 |
| 163 void InspectorBackendMojo::Connect() { | 181 void InspectorBackendMojo::Connect() { |
| 164 impl_->Connect(); | 182 impl_->Connect(); |
| 165 } | 183 } |
| 166 | 184 |
| 167 } // namespace inspector | 185 } // namespace inspector |
| OLD | NEW |