OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "test/inspector-protocol/inspector-extension.h" |
| 6 |
| 7 #include "src/inspector/string-util.h" |
| 8 #include "test/inspector-protocol/inspector-client-impl.h" |
| 9 #include "test/inspector-protocol/task-queue.h" |
| 10 #include "test/inspector-protocol/task.h" |
| 11 |
| 12 namespace v8_inspector { |
| 13 |
| 14 TaskQueue* BackendExtension::frontend_queue_ = NULL; |
| 15 |
| 16 v8::Local<v8::FunctionTemplate> BackendExtension::GetNativeFunctionTemplate( |
| 17 v8::Isolate* isolate, v8::Local<v8::String> name) { |
| 18 return v8::FunctionTemplate::New(isolate, |
| 19 BackendExtension::EvaluateInFrontend); |
| 20 } |
| 21 |
| 22 void BackendExtension::EvaluateInFrontend( |
| 23 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 24 CHECK(frontend_queue_); |
| 25 CHECK(args.Length() == 1 && args[0]->IsString()); |
| 26 frontend_queue_->Append(new ExecuteStringTask( |
| 27 toStringView(toProtocolString(v8::Local<v8::String>::Cast(args[0]))))); |
| 28 } |
| 29 |
| 30 namespace { |
| 31 |
| 32 class ProcessMessageOnBackend : public v8_inspector::Task { |
| 33 public: |
| 34 ProcessMessageOnBackend(const StringView& message) |
| 35 : message_(toString16(message)) {} |
| 36 |
| 37 bool is_protocol_task() final { return true; } |
| 38 |
| 39 void Run(v8::Isolate* isolate, |
| 40 const v8::Global<v8::Context>& global_context) override { |
| 41 v8_inspector::TaskScope task_scope(isolate, global_context); |
| 42 v8::Local<v8::Context> context = task_scope.context(); |
| 43 V8InspectorSession* session = |
| 44 V8InspectorClientImpl::SessionFromContext(context); |
| 45 session->dispatchProtocolMessage(toStringView(message_)); |
| 46 } |
| 47 |
| 48 private: |
| 49 String16 message_; |
| 50 }; |
| 51 |
| 52 } // namespace |
| 53 |
| 54 TaskQueue* FrontendExtension::backend_queue_ = NULL; |
| 55 |
| 56 v8::Local<v8::FunctionTemplate> FrontendExtension::GetNativeFunctionTemplate( |
| 57 v8::Isolate* isolate, v8::Local<v8::String> name) { |
| 58 return v8::FunctionTemplate::New(isolate, |
| 59 FrontendExtension::SendMessageToBackend); |
| 60 } |
| 61 |
| 62 void FrontendExtension::SendMessageToBackend( |
| 63 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 64 CHECK(backend_queue_); |
| 65 CHECK(args.Length() == 1 && args[0]->IsString()); |
| 66 backend_queue_->Append(new ProcessMessageOnBackend( |
| 67 toStringView(toProtocolString(v8::Local<v8::String>::Cast(args[0]))))); |
| 68 } |
| 69 |
| 70 } // namespace v8 |
OLD | NEW |