| 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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 client_->disconnect(); | 139 client_->disconnect(); |
| 140 } | 140 } |
| 141 | 141 |
| 142 private: | 142 private: |
| 143 InspectorClientImpl* client_; | 143 InspectorClientImpl* client_; |
| 144 }; | 144 }; |
| 145 | 145 |
| 146 class CreateContextGroupTask : public TaskRunner::Task { | 146 class CreateContextGroupTask : public TaskRunner::Task { |
| 147 public: | 147 public: |
| 148 CreateContextGroupTask(InspectorClientImpl* client, | 148 CreateContextGroupTask(InspectorClientImpl* client, |
| 149 v8::ExtensionConfiguration* extensions, | 149 TaskRunner::SetupGlobalTasks setup_global_tasks, |
| 150 v8::base::Semaphore* ready_semaphore, | 150 v8::base::Semaphore* ready_semaphore, |
| 151 int* context_group_id) | 151 int* context_group_id) |
| 152 : client_(client), | 152 : client_(client), |
| 153 extensions_(extensions), | 153 setup_global_tasks_(std::move(setup_global_tasks)), |
| 154 ready_semaphore_(ready_semaphore), | 154 ready_semaphore_(ready_semaphore), |
| 155 context_group_id_(context_group_id) {} | 155 context_group_id_(context_group_id) {} |
| 156 virtual ~CreateContextGroupTask() = default; | 156 virtual ~CreateContextGroupTask() = default; |
| 157 | 157 |
| 158 bool is_inspector_task() final { return true; } | 158 bool is_inspector_task() final { return true; } |
| 159 | 159 |
| 160 void Run(v8::Isolate* isolate, | 160 void Run(v8::Isolate* isolate, |
| 161 const v8::Global<v8::Context>& global_context) { | 161 const v8::Global<v8::Context>& global_context) { |
| 162 *context_group_id_ = client_->createContextGroup(extensions_); | 162 *context_group_id_ = client_->createContextGroup(setup_global_tasks_); |
| 163 if (ready_semaphore_) ready_semaphore_->Signal(); | 163 if (ready_semaphore_) ready_semaphore_->Signal(); |
| 164 } | 164 } |
| 165 | 165 |
| 166 private: | 166 private: |
| 167 InspectorClientImpl* client_; | 167 InspectorClientImpl* client_; |
| 168 v8::ExtensionConfiguration* extensions_; | 168 TaskRunner::SetupGlobalTasks setup_global_tasks_; |
| 169 v8::base::Semaphore* ready_semaphore_; | 169 v8::base::Semaphore* ready_semaphore_; |
| 170 int* context_group_id_; | 170 int* context_group_id_; |
| 171 }; | 171 }; |
| 172 | 172 |
| 173 InspectorClientImpl::InspectorClientImpl(TaskRunner* task_runner, | 173 InspectorClientImpl::InspectorClientImpl(TaskRunner* task_runner, |
| 174 FrontendChannel* frontend_channel, | 174 FrontendChannel* frontend_channel, |
| 175 v8::base::Semaphore* ready_semaphore) | 175 v8::base::Semaphore* ready_semaphore) |
| 176 : isolate_(nullptr), | 176 : isolate_(nullptr), |
| 177 task_runner_(task_runner), | 177 task_runner_(task_runner), |
| 178 frontend_channel_(frontend_channel) { | 178 frontend_channel_(frontend_channel) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 | 223 |
| 224 void InspectorClientImpl::disconnect() { | 224 void InspectorClientImpl::disconnect() { |
| 225 for (const auto& it : sessions_) { | 225 for (const auto& it : sessions_) { |
| 226 states_[it.first] = it.second->stateJSON(); | 226 states_[it.first] = it.second->stateJSON(); |
| 227 } | 227 } |
| 228 sessions_.clear(); | 228 sessions_.clear(); |
| 229 inspector_.reset(); | 229 inspector_.reset(); |
| 230 } | 230 } |
| 231 | 231 |
| 232 void InspectorClientImpl::scheduleCreateContextGroup( | 232 void InspectorClientImpl::scheduleCreateContextGroup( |
| 233 v8::ExtensionConfiguration* extensions, | 233 TaskRunner::SetupGlobalTasks setup_global_tasks, |
| 234 v8::base::Semaphore* ready_semaphore, int* context_group_id) { | 234 v8::base::Semaphore* ready_semaphore, int* context_group_id) { |
| 235 task_runner_->Append(new CreateContextGroupTask( | 235 task_runner_->Append(new CreateContextGroupTask( |
| 236 this, extensions, ready_semaphore, context_group_id)); | 236 this, std::move(setup_global_tasks), ready_semaphore, context_group_id)); |
| 237 } | 237 } |
| 238 | 238 |
| 239 int InspectorClientImpl::createContextGroup( | 239 int InspectorClientImpl::createContextGroup( |
| 240 v8::ExtensionConfiguration* extensions) { | 240 const TaskRunner::SetupGlobalTasks& setup_global_tasks) { |
| 241 v8::HandleScope handle_scope(isolate_); | 241 v8::HandleScope handle_scope(isolate_); |
| 242 v8::Local<v8::Context> context = task_runner_->NewContextGroup(); | 242 v8::Local<v8::Context> context = |
| 243 task_runner_->NewContextGroup(setup_global_tasks); |
| 243 context->SetAlignedPointerInEmbedderData(kInspectorClientIndex, this); | 244 context->SetAlignedPointerInEmbedderData(kInspectorClientIndex, this); |
| 244 int context_group_id = TaskRunner::GetContextGroupId(context); | 245 int context_group_id = TaskRunner::GetContextGroupId(context); |
| 245 v8_inspector::StringView state; | 246 v8_inspector::StringView state; |
| 246 sessions_[context_group_id] = | 247 sessions_[context_group_id] = |
| 247 inspector_->connect(context_group_id, channel_.get(), state); | 248 inspector_->connect(context_group_id, channel_.get(), state); |
| 248 inspector_->contextCreated(v8_inspector::V8ContextInfo( | 249 inspector_->contextCreated(v8_inspector::V8ContextInfo( |
| 249 context, context_group_id, v8_inspector::StringView())); | 250 context, context_group_id, v8_inspector::StringView())); |
| 250 return context_group_id; | 251 return context_group_id; |
| 251 } | 252 } |
| 252 | 253 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 session->dispatchProtocolMessage(message_view); | 365 session->dispatchProtocolMessage(message_view); |
| 365 } | 366 } |
| 366 | 367 |
| 367 private: | 368 private: |
| 368 v8::internal::Vector<uint16_t> message_; | 369 v8::internal::Vector<uint16_t> message_; |
| 369 int context_group_id_; | 370 int context_group_id_; |
| 370 }; | 371 }; |
| 371 | 372 |
| 372 TaskRunner* SendMessageToBackendExtension::backend_task_runner_ = nullptr; | 373 TaskRunner* SendMessageToBackendExtension::backend_task_runner_ = nullptr; |
| 373 | 374 |
| 374 v8::Local<v8::FunctionTemplate> | 375 void SendMessageToBackendExtension::Run(v8::Isolate* isolate, |
| 375 SendMessageToBackendExtension::GetNativeFunctionTemplate( | 376 v8::Local<v8::ObjectTemplate> global) { |
| 376 v8::Isolate* isolate, v8::Local<v8::String> name) { | 377 global->Set( |
| 377 return v8::FunctionTemplate::New( | 378 v8::String::NewFromUtf8(isolate, "sendMessageToBackend", |
| 378 isolate, SendMessageToBackendExtension::SendMessageToBackend); | 379 v8::NewStringType::kNormal) |
| 380 .ToLocalChecked(), |
| 381 v8::FunctionTemplate::New( |
| 382 isolate, &SendMessageToBackendExtension::SendMessageToBackend)); |
| 379 } | 383 } |
| 380 | 384 |
| 381 void SendMessageToBackendExtension::SendMessageToBackend( | 385 void SendMessageToBackendExtension::SendMessageToBackend( |
| 382 const v8::FunctionCallbackInfo<v8::Value>& args) { | 386 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 383 CHECK(backend_task_runner_); | 387 CHECK(backend_task_runner_); |
| 384 CHECK(args.Length() == 2 && args[0]->IsString() && args[1]->IsInt32()); | 388 CHECK(args.Length() == 2 && args[0]->IsString() && args[1]->IsInt32()); |
| 385 v8::Local<v8::String> message = args[0].As<v8::String>(); | 389 v8::Local<v8::String> message = args[0].As<v8::String>(); |
| 386 backend_task_runner_->Append(new SendMessageToBackendTask( | 390 backend_task_runner_->Append(new SendMessageToBackendTask( |
| 387 ToVector(message), args[1].As<v8::Int32>()->Value())); | 391 ToVector(message), args[1].As<v8::Int32>()->Value())); |
| 388 } | 392 } |
| OLD | NEW |