OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project 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 "test/inspector/inspector-impl.h" | 5 #include "test/inspector/inspector-impl.h" |
6 | 6 |
7 #include "include/v8.h" | 7 #include "include/v8.h" |
8 | 8 |
9 #include "src/vector.h" | 9 #include "src/vector.h" |
10 | 10 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 v8::Local<v8::Context> context = global_context.Get(isolate); | 101 v8::Local<v8::Context> context = global_context.Get(isolate); |
102 client_->connect(context); | 102 client_->connect(context); |
103 if (ready_semaphore_) ready_semaphore_->Signal(); | 103 if (ready_semaphore_) ready_semaphore_->Signal(); |
104 } | 104 } |
105 | 105 |
106 private: | 106 private: |
107 InspectorClientImpl* client_; | 107 InspectorClientImpl* client_; |
108 v8::base::Semaphore* ready_semaphore_; | 108 v8::base::Semaphore* ready_semaphore_; |
109 }; | 109 }; |
110 | 110 |
| 111 class DisconnectTask : public TaskRunner::Task { |
| 112 public: |
| 113 explicit DisconnectTask(InspectorClientImpl* client) : client_(client) {} |
| 114 virtual ~DisconnectTask() = default; |
| 115 |
| 116 bool is_inspector_task() final { return true; } |
| 117 |
| 118 void Run(v8::Isolate* isolate, |
| 119 const v8::Global<v8::Context>& global_context) { |
| 120 client_->disconnect(); |
| 121 } |
| 122 |
| 123 private: |
| 124 InspectorClientImpl* client_; |
| 125 }; |
| 126 |
111 InspectorClientImpl::InspectorClientImpl(TaskRunner* task_runner, | 127 InspectorClientImpl::InspectorClientImpl(TaskRunner* task_runner, |
112 FrontendChannel* frontend_channel, | 128 FrontendChannel* frontend_channel, |
113 v8::base::Semaphore* ready_semaphore) | 129 v8::base::Semaphore* ready_semaphore) |
114 : isolate_(nullptr), | 130 : isolate_(nullptr), |
115 task_runner_(task_runner), | 131 task_runner_(task_runner), |
116 frontend_channel_(frontend_channel) { | 132 frontend_channel_(frontend_channel) { |
117 task_runner_->Append(new ConnectTask(this, ready_semaphore)); | 133 task_runner_->Append(new ConnectTask(this, ready_semaphore)); |
118 } | 134 } |
119 | 135 |
120 InspectorClientImpl::~InspectorClientImpl() {} | 136 InspectorClientImpl::~InspectorClientImpl() {} |
121 | 137 |
122 void InspectorClientImpl::connect(v8::Local<v8::Context> context) { | 138 void InspectorClientImpl::connect(v8::Local<v8::Context> context) { |
123 isolate_ = context->GetIsolate(); | 139 isolate_ = context->GetIsolate(); |
124 isolate_->AddMessageListener(MessageHandler); | 140 isolate_->AddMessageListener(MessageHandler); |
125 channel_.reset(new ChannelImpl(frontend_channel_)); | 141 channel_.reset(new ChannelImpl(frontend_channel_)); |
126 | 142 |
127 inspector_ = v8_inspector::V8Inspector::create(isolate_, this); | 143 inspector_ = v8_inspector::V8Inspector::create(isolate_, this); |
128 session_ = inspector_->connect(1, channel_.get(), v8_inspector::StringView()); | 144 v8_inspector::StringView state = |
| 145 state_ ? state_->string() : v8_inspector::StringView(); |
| 146 session_ = inspector_->connect(1, channel_.get(), state); |
129 | 147 |
130 context->SetAlignedPointerInEmbedderData(kInspectorClientIndex, this); | 148 context->SetAlignedPointerInEmbedderData(kInspectorClientIndex, this); |
131 inspector_->contextCreated( | 149 inspector_->contextCreated( |
132 v8_inspector::V8ContextInfo(context, 1, v8_inspector::StringView())); | 150 v8_inspector::V8ContextInfo(context, 1, v8_inspector::StringView())); |
133 context_.Reset(isolate_, context); | 151 context_.Reset(isolate_, context); |
134 } | 152 } |
135 | 153 |
| 154 void InspectorClientImpl::scheduleReconnect( |
| 155 v8::base::Semaphore* ready_semaphore) { |
| 156 task_runner_->Append(new DisconnectTask(this)); |
| 157 task_runner_->Append(new ConnectTask(this, ready_semaphore)); |
| 158 } |
| 159 |
| 160 void InspectorClientImpl::disconnect() { |
| 161 state_ = session_->stateJSON(); |
| 162 session_.reset(); |
| 163 } |
| 164 |
136 v8::Local<v8::Context> InspectorClientImpl::ensureDefaultContextInGroup(int) { | 165 v8::Local<v8::Context> InspectorClientImpl::ensureDefaultContextInGroup(int) { |
137 CHECK(isolate_); | 166 CHECK(isolate_); |
138 return context_.Get(isolate_); | 167 return context_.Get(isolate_); |
139 } | 168 } |
140 | 169 |
141 void InspectorClientImpl::setCurrentTimeMSForTest(double time) { | 170 void InspectorClientImpl::setCurrentTimeMSForTest(double time) { |
142 current_time_ = time; | 171 current_time_ = time; |
143 current_time_set_for_test_ = true; | 172 current_time_set_for_test_ = true; |
144 } | 173 } |
145 | 174 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 isolate, SendMessageToBackendExtension::SendMessageToBackend); | 229 isolate, SendMessageToBackendExtension::SendMessageToBackend); |
201 } | 230 } |
202 | 231 |
203 void SendMessageToBackendExtension::SendMessageToBackend( | 232 void SendMessageToBackendExtension::SendMessageToBackend( |
204 const v8::FunctionCallbackInfo<v8::Value>& args) { | 233 const v8::FunctionCallbackInfo<v8::Value>& args) { |
205 CHECK(backend_task_runner_); | 234 CHECK(backend_task_runner_); |
206 CHECK(args.Length() == 1 && args[0]->IsString()); | 235 CHECK(args.Length() == 1 && args[0]->IsString()); |
207 v8::Local<v8::String> message = args[0].As<v8::String>(); | 236 v8::Local<v8::String> message = args[0].As<v8::String>(); |
208 backend_task_runner_->Append(new SendMessageToBackendTask(ToVector(message))); | 237 backend_task_runner_->Append(new SendMessageToBackendTask(ToVector(message))); |
209 } | 238 } |
OLD | NEW |