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

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

Issue 746713002: Move InspectorBackendMojo out of the blink namespace (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: 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
OLDNEW
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 "v8_inspector/inspector_backend_mojo.h" 6 #include "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 "bindings/core/v8/PageScriptDebugServer.h"
11 #include "bindings/core/v8/ScriptController.h"
12 #include "gen/sky/core/InspectorBackendDispatcher.h" 10 #include "gen/sky/core/InspectorBackendDispatcher.h"
13 #include "mojo/public/cpp/application/connect.h" 11 #include "mojo/public/cpp/application/connect.h"
14 #include "mojo/public/cpp/application/service_provider_impl.h" 12 #include "mojo/public/cpp/application/service_provider_impl.h"
15 #include "mojo/public/interfaces/application/shell.mojom.h" 13 #include "mojo/public/interfaces/application/shell.mojom.h"
16 #include "sky/engine/core/frame/FrameHost.h" 14 #include "sky/engine/bindings/core/v8/PageScriptDebugServer.h"
15 #include "sky/engine/core/inspector/InspectorFrontendChannel.h"
17 #include "sky/engine/core/inspector/InspectorState.h" 16 #include "sky/engine/core/inspector/InspectorState.h"
18 #include "sky/engine/core/inspector/InstrumentingAgents.h" 17 #include "sky/engine/core/inspector/InstrumentingAgents.h"
19 #include "sky/engine/core/inspector/PageDebuggerAgent.h" 18 #include "sky/engine/core/inspector/PageDebuggerAgent.h"
20 #include "sky/engine/core/page/Page.h"
21 #include "sky/engine/platform/JSONValues.h" 19 #include "sky/engine/platform/JSONValues.h"
22 #include "sky/engine/public/platform/ServiceProvider.h" 20 #include "sky/engine/v8_inspector/inspector_host.h"
23 21
24 namespace blink { 22 namespace blink {
25 23
24 class InspectorBackendMojoImpl
25 : public InspectorFrontendChannel,
26 public mojo::InterfaceImpl<sky::InspectorBackend> {
27 public:
28 explicit InspectorBackendMojoImpl(inspector::InspectorHost*);
29 ~InspectorBackendMojoImpl();
30
31 void Connect();
32
33 // InspectorBackend:
34 void OnConnect();
35 void OnMessage(const mojo::String& message) override;
36 void OnDisconnect();
37
38 // InspectorFrontendChannel:
39 void sendMessageToFrontend(PassRefPtr<JSONObject> message) override;
40 // TODO(eseidel): Unclear if flush is needed.
41 void flush() override {}
42
43 inspector::InspectorHost* host_;
44 sky::InspectorFrontendPtr frontend_;
45
46 OwnPtr<InspectorFrontend> old_frontend_;
47 RefPtr<InspectorBackendDispatcher> dispatcher_;
48 OwnPtr<PageDebuggerAgent> debugger_agent_;
49 OwnPtr<InjectedScriptManager> script_manager_;
50 OwnPtr<InspectorState> inspector_state_;
51 OwnPtr<InstrumentingAgents> agents_;
52
53 DISALLOW_COPY_AND_ASSIGN(InspectorBackendMojoImpl);
54 };
55
56 // FIXME: Probably this should be provided by the InspectorHost?
26 class MessageLoopAdaptor : public PageScriptDebugServer::ClientMessageLoop { 57 class MessageLoopAdaptor : public PageScriptDebugServer::ClientMessageLoop {
27 public: 58 public:
28 MessageLoopAdaptor() {} 59 MessageLoopAdaptor() {}
29 60
30 private: 61 private:
31 virtual void run(Page* page) { 62 virtual void run(inspector::InspectorHost* host) {
32 run_loop_.reset(new base::RunLoop()); 63 run_loop_.reset(new base::RunLoop());
33 run_loop_->Run(); 64 run_loop_->Run();
34 } 65 }
35 66
36 virtual void quitNow() { 67 virtual void quitNow() {
37 if (run_loop_) 68 if (run_loop_)
38 run_loop_->Quit(); 69 run_loop_->Quit();
39 } 70 }
40 71
41 scoped_ptr<base::RunLoop> run_loop_; 72 scoped_ptr<base::RunLoop> run_loop_;
42 }; 73 };
43 74
44 InspectorBackendMojo::InspectorBackendMojo(const FrameHost& frame_host) 75 InspectorBackendMojoImpl::InspectorBackendMojoImpl(
45 : frame_host_(frame_host) { 76 inspector::InspectorHost* host)
77 : host_(host) {
46 } 78 }
47 79
48 InspectorBackendMojo::~InspectorBackendMojo() { 80 InspectorBackendMojoImpl::~InspectorBackendMojoImpl() {
49 } 81 }
50 82
51 void InspectorBackendMojo::Connect() { 83 void InspectorBackendMojoImpl::Connect() {
52 mojo::Shell* shell = frame_host_.services().Shell(); 84 mojo::Shell* shell = host_->GetShell();
53 mojo::ServiceProviderPtr inspector_service_provider; 85 mojo::ServiceProviderPtr inspector_service_provider;
54 shell->ConnectToApplication("mojo:sky_inspector_server", 86 shell->ConnectToApplication("mojo:sky_inspector_server",
55 GetProxy(&inspector_service_provider)); 87 GetProxy(&inspector_service_provider));
56 mojo::ConnectToService(inspector_service_provider.get(), &frontend_); 88 mojo::ConnectToService(inspector_service_provider.get(), &frontend_);
57 frontend_.set_client(this); 89 frontend_.set_client(this);
58 90
59 // Theoretically we should load our state from the inspector cookie. 91 // Theoretically we should load our state from the inspector cookie.
60 inspector_state_ = 92 inspector_state_ =
61 adoptPtr(new InspectorState(nullptr, JSONObject::create())); 93 adoptPtr(new InspectorState(nullptr, JSONObject::create()));
62 old_frontend_ = adoptPtr(new InspectorFrontend(this)); 94 old_frontend_ = adoptPtr(new InspectorFrontend(this));
63 95
64 v8::Isolate* isolate = frame_host_.page().mainFrame()->script().isolate(); 96 PageScriptDebugServer::setMainThreadIsolate(host_->GetIsolate());
65 PageScriptDebugServer::setMainThreadIsolate(isolate);
66 OwnPtr<MessageLoopAdaptor> message_loop = adoptPtr(new MessageLoopAdaptor); 97 OwnPtr<MessageLoopAdaptor> message_loop = adoptPtr(new MessageLoopAdaptor);
67 PageScriptDebugServer::shared().setClientMessageLoop(message_loop.release()); 98 PageScriptDebugServer::shared().setClientMessageLoop(message_loop.release());
68 99
69 // AgentRegistry used to do this, but we don't need it for one agent. 100 // AgentRegistry used to do this, but we don't need it for one agent.
70 script_manager_ = InjectedScriptManager::createForPage(); 101 script_manager_ = InjectedScriptManager::createForPage();
71 debugger_agent_ = 102 debugger_agent_ = PageDebuggerAgent::create(&PageScriptDebugServer::shared(),
72 PageDebuggerAgent::create(&PageScriptDebugServer::shared(), 103 host_, script_manager_.get());
73 &frame_host_.page(), script_manager_.get());
74 agents_ = adoptPtr(new InstrumentingAgents(debugger_agent_.get())); 104 agents_ = adoptPtr(new InstrumentingAgents(debugger_agent_.get()));
75 debugger_agent_->init(agents_.get(), inspector_state_.get()); 105 debugger_agent_->init(agents_.get(), inspector_state_.get());
76 debugger_agent_->setFrontend(old_frontend_.get()); 106 debugger_agent_->setFrontend(old_frontend_.get());
77 107
78 dispatcher_ = InspectorBackendDispatcher::create(this); 108 dispatcher_ = InspectorBackendDispatcher::create(this);
79 dispatcher_->registerAgent(debugger_agent_.get()); 109 dispatcher_->registerAgent(debugger_agent_.get());
80 } 110 }
81 111
82 void InspectorBackendMojo::sendMessageToFrontend( 112 void InspectorBackendMojoImpl::OnConnect() {
113 }
114
115 void InspectorBackendMojoImpl::OnDisconnect() {
116 }
117
118 void InspectorBackendMojoImpl::sendMessageToFrontend(
83 PassRefPtr<JSONObject> message) { 119 PassRefPtr<JSONObject> message) {
84 frontend_->SendMessage(message->toJSONString().toUTF8()); 120 frontend_->SendMessage(message->toJSONString().toUTF8());
85 } 121 }
86 122
87 void InspectorBackendMojo::flush() { 123 void InspectorBackendMojoImpl::OnMessage(const mojo::String& message) {
88 // TODO(eseidel): Unclear if this is needed.
89 }
90
91 void InspectorBackendMojo::OnConnect() {
92 }
93
94 void InspectorBackendMojo::OnDisconnect() {
95 }
96
97 void InspectorBackendMojo::OnMessage(const mojo::String& message) {
98 String wtf_message = String::fromUTF8(message.To<std::string>()); 124 String wtf_message = String::fromUTF8(message.To<std::string>());
99 String command_name; 125 String command_name;
100 InspectorBackendDispatcher::getCommandName(wtf_message, &command_name); 126 InspectorBackendDispatcher::getCommandName(wtf_message, &command_name);
101 // InspectorBackendDispatcher will automatically reply with errors 127 // InspectorBackendDispatcher will automatically reply with errors
102 // if agents are missing, since we only want this backend to care about 128 // if agents are missing, since we only want this backend to care about
103 // the Debugger agent, we manually filter here. 129 // the Debugger agent, we manually filter here.
104 if (command_name.startsWith("Debugger")) 130 if (command_name.startsWith("Debugger"))
105 dispatcher_->dispatch(wtf_message); 131 dispatcher_->dispatch(wtf_message);
106 } 132 }
107 133
108 } // namespace blink 134 } // namespace blink
135
136 namespace inspector {
137
138 InspectorBackendMojo::InspectorBackendMojo(InspectorHost* host)
139 : impl_(new blink::InspectorBackendMojoImpl(host)) {
140 }
141
142 InspectorBackendMojo::~InspectorBackendMojo() {
143 }
144
145 void InspectorBackendMojo::Connect() {
146 impl_->Connect();
147 }
148
149 } // namespace inspector
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698