| 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 } // namespace | 107 } // namespace |
| 108 | 108 |
| 109 class ConnectTask : public TaskRunner::Task { | 109 class ConnectTask : public TaskRunner::Task { |
| 110 public: | 110 public: |
| 111 ConnectTask(InspectorClientImpl* client, v8::base::Semaphore* ready_semaphore) | 111 ConnectTask(InspectorClientImpl* client, v8::base::Semaphore* ready_semaphore) |
| 112 : client_(client), ready_semaphore_(ready_semaphore) {} | 112 : client_(client), ready_semaphore_(ready_semaphore) {} |
| 113 virtual ~ConnectTask() = default; | 113 virtual ~ConnectTask() = default; |
| 114 | 114 |
| 115 bool is_inspector_task() final { return true; } | 115 bool is_inspector_task() final { return true; } |
| 116 | 116 |
| 117 void Run(v8::Isolate* isolate, | 117 private: |
| 118 const v8::Global<v8::Context>& global_context) { | 118 void Run() override { |
| 119 v8::HandleScope handle_scope(isolate); | 119 v8::HandleScope handle_scope(isolate()); |
| 120 v8::Local<v8::Context> context = global_context.Get(isolate); | 120 client_->connect(default_context()); |
| 121 client_->connect(context); | |
| 122 if (ready_semaphore_) ready_semaphore_->Signal(); | 121 if (ready_semaphore_) ready_semaphore_->Signal(); |
| 123 } | 122 } |
| 124 | 123 |
| 125 private: | |
| 126 InspectorClientImpl* client_; | 124 InspectorClientImpl* client_; |
| 127 v8::base::Semaphore* ready_semaphore_; | 125 v8::base::Semaphore* ready_semaphore_; |
| 128 }; | 126 }; |
| 129 | 127 |
| 130 class DisconnectTask : public TaskRunner::Task { | 128 class DisconnectTask : public TaskRunner::Task { |
| 131 public: | 129 public: |
| 132 explicit DisconnectTask(InspectorClientImpl* client, bool reset_inspector, | 130 explicit DisconnectTask(InspectorClientImpl* client, bool reset_inspector, |
| 133 v8::base::Semaphore* ready_semaphore) | 131 v8::base::Semaphore* ready_semaphore) |
| 134 : client_(client), | 132 : client_(client), |
| 135 reset_inspector_(reset_inspector), | 133 reset_inspector_(reset_inspector), |
| 136 ready_semaphore_(ready_semaphore) {} | 134 ready_semaphore_(ready_semaphore) {} |
| 137 virtual ~DisconnectTask() = default; | 135 virtual ~DisconnectTask() = default; |
| 138 | 136 |
| 139 bool is_inspector_task() final { return true; } | 137 bool is_inspector_task() final { return true; } |
| 140 | 138 |
| 141 void Run(v8::Isolate* isolate, | 139 private: |
| 142 const v8::Global<v8::Context>& global_context) { | 140 void Run() override { |
| 143 client_->disconnect(reset_inspector_); | 141 client_->disconnect(reset_inspector_); |
| 144 if (ready_semaphore_) ready_semaphore_->Signal(); | 142 if (ready_semaphore_) ready_semaphore_->Signal(); |
| 145 } | 143 } |
| 146 | 144 |
| 147 private: | |
| 148 InspectorClientImpl* client_; | 145 InspectorClientImpl* client_; |
| 149 bool reset_inspector_; | 146 bool reset_inspector_; |
| 150 v8::base::Semaphore* ready_semaphore_; | 147 v8::base::Semaphore* ready_semaphore_; |
| 151 }; | 148 }; |
| 152 | 149 |
| 153 class CreateContextGroupTask : public TaskRunner::Task { | 150 class CreateContextGroupTask : public TaskRunner::Task { |
| 154 public: | 151 public: |
| 155 CreateContextGroupTask(InspectorClientImpl* client, | 152 CreateContextGroupTask(InspectorClientImpl* client, |
| 156 TaskRunner::SetupGlobalTasks setup_global_tasks, | 153 TaskRunner::SetupGlobalTasks setup_global_tasks, |
| 157 v8::base::Semaphore* ready_semaphore, | 154 v8::base::Semaphore* ready_semaphore, |
| 158 int* context_group_id) | 155 int* context_group_id) |
| 159 : client_(client), | 156 : client_(client), |
| 160 setup_global_tasks_(std::move(setup_global_tasks)), | 157 setup_global_tasks_(std::move(setup_global_tasks)), |
| 161 ready_semaphore_(ready_semaphore), | 158 ready_semaphore_(ready_semaphore), |
| 162 context_group_id_(context_group_id) {} | 159 context_group_id_(context_group_id) {} |
| 163 virtual ~CreateContextGroupTask() = default; | 160 virtual ~CreateContextGroupTask() = default; |
| 164 | 161 |
| 165 bool is_inspector_task() final { return true; } | 162 bool is_inspector_task() final { return true; } |
| 166 | 163 |
| 167 void Run(v8::Isolate* isolate, | 164 private: |
| 168 const v8::Global<v8::Context>& global_context) { | 165 void Run() override { |
| 169 *context_group_id_ = client_->createContextGroup(setup_global_tasks_); | 166 *context_group_id_ = client_->createContextGroup(setup_global_tasks_); |
| 170 if (ready_semaphore_) ready_semaphore_->Signal(); | 167 if (ready_semaphore_) ready_semaphore_->Signal(); |
| 171 } | 168 } |
| 172 | 169 |
| 173 private: | |
| 174 InspectorClientImpl* client_; | 170 InspectorClientImpl* client_; |
| 175 TaskRunner::SetupGlobalTasks setup_global_tasks_; | 171 TaskRunner::SetupGlobalTasks setup_global_tasks_; |
| 176 v8::base::Semaphore* ready_semaphore_; | 172 v8::base::Semaphore* ready_semaphore_; |
| 177 int* context_group_id_; | 173 int* context_group_id_; |
| 178 }; | 174 }; |
| 179 | 175 |
| 180 InspectorClientImpl::InspectorClientImpl(TaskRunner* task_runner, | 176 InspectorClientImpl::InspectorClientImpl(TaskRunner* task_runner, |
| 181 FrontendChannel* frontend_channel, | 177 FrontendChannel* frontend_channel, |
| 182 v8::base::Semaphore* ready_semaphore) | 178 v8::base::Semaphore* ready_semaphore) |
| 183 : isolate_(nullptr), | 179 : isolate_(nullptr), |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 } | 349 } |
| 354 | 350 |
| 355 class SendMessageToBackendTask : public TaskRunner::Task { | 351 class SendMessageToBackendTask : public TaskRunner::Task { |
| 356 public: | 352 public: |
| 357 explicit SendMessageToBackendTask( | 353 explicit SendMessageToBackendTask( |
| 358 const v8::internal::Vector<uint16_t>& message, int context_group_id) | 354 const v8::internal::Vector<uint16_t>& message, int context_group_id) |
| 359 : message_(message), context_group_id_(context_group_id) {} | 355 : message_(message), context_group_id_(context_group_id) {} |
| 360 | 356 |
| 361 bool is_inspector_task() final { return true; } | 357 bool is_inspector_task() final { return true; } |
| 362 | 358 |
| 363 void Run(v8::Isolate* isolate, | 359 private: |
| 364 const v8::Global<v8::Context>& global_context) override { | 360 void Run() override { |
| 365 v8_inspector::V8InspectorSession* session = nullptr; | 361 v8_inspector::V8InspectorSession* session = nullptr; |
| 366 { | 362 { |
| 367 v8::HandleScope handle_scope(isolate); | 363 v8::HandleScope handle_scope(isolate()); |
| 368 v8::Local<v8::Context> context = global_context.Get(isolate); | |
| 369 if (!context_group_id_) { | 364 if (!context_group_id_) { |
| 370 session = InspectorClientImpl::SessionFromContext(context); | 365 session = InspectorClientImpl::SessionFromContext(default_context()); |
| 371 } else { | 366 } else { |
| 372 session = InspectorClientFromContext(context) | 367 session = InspectorClientFromContext(default_context()) |
| 373 ->sessions_[context_group_id_] | 368 ->sessions_[context_group_id_] |
| 374 .get(); | 369 .get(); |
| 375 } | 370 } |
| 376 if (!session) return; | 371 if (!session) return; |
| 377 } | 372 } |
| 378 v8_inspector::StringView message_view(message_.start(), message_.length()); | 373 v8_inspector::StringView message_view(message_.start(), message_.length()); |
| 379 session->dispatchProtocolMessage(message_view); | 374 session->dispatchProtocolMessage(message_view); |
| 380 } | 375 } |
| 381 | 376 |
| 382 private: | |
| 383 v8::internal::Vector<uint16_t> message_; | 377 v8::internal::Vector<uint16_t> message_; |
| 384 int context_group_id_; | 378 int context_group_id_; |
| 385 }; | 379 }; |
| 386 | 380 |
| 387 TaskRunner* SendMessageToBackendExtension::backend_task_runner_ = nullptr; | 381 TaskRunner* SendMessageToBackendExtension::backend_task_runner_ = nullptr; |
| 388 | 382 |
| 389 void SendMessageToBackendExtension::Run(v8::Isolate* isolate, | 383 void SendMessageToBackendExtension::Run(v8::Isolate* isolate, |
| 390 v8::Local<v8::ObjectTemplate> global) { | 384 v8::Local<v8::ObjectTemplate> global) { |
| 391 global->Set( | 385 global->Set( |
| 392 v8::String::NewFromUtf8(isolate, "sendMessageToBackend", | 386 v8::String::NewFromUtf8(isolate, "sendMessageToBackend", |
| 393 v8::NewStringType::kNormal) | 387 v8::NewStringType::kNormal) |
| 394 .ToLocalChecked(), | 388 .ToLocalChecked(), |
| 395 v8::FunctionTemplate::New( | 389 v8::FunctionTemplate::New( |
| 396 isolate, &SendMessageToBackendExtension::SendMessageToBackend)); | 390 isolate, &SendMessageToBackendExtension::SendMessageToBackend)); |
| 397 } | 391 } |
| 398 | 392 |
| 399 void SendMessageToBackendExtension::SendMessageToBackend( | 393 void SendMessageToBackendExtension::SendMessageToBackend( |
| 400 const v8::FunctionCallbackInfo<v8::Value>& args) { | 394 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 401 CHECK(backend_task_runner_); | 395 CHECK(backend_task_runner_); |
| 402 CHECK(args.Length() == 2 && args[0]->IsString() && args[1]->IsInt32()); | 396 CHECK(args.Length() == 2 && args[0]->IsString() && args[1]->IsInt32()); |
| 403 v8::Local<v8::String> message = args[0].As<v8::String>(); | 397 v8::Local<v8::String> message = args[0].As<v8::String>(); |
| 404 backend_task_runner_->Append(new SendMessageToBackendTask( | 398 backend_task_runner_->Append(new SendMessageToBackendTask( |
| 405 ToVector(message), args[1].As<v8::Int32>()->Value())); | 399 ToVector(message), args[1].As<v8::Int32>()->Value())); |
| 406 } | 400 } |
| OLD | NEW |