web_worker_observer.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright (c) 2017 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef ELECTRON_SHELL_RENDERER_WEB_WORKER_OBSERVER_H_
  5. #define ELECTRON_SHELL_RENDERER_WEB_WORKER_OBSERVER_H_
  6. #include <memory>
  7. #include "v8/include/v8.h"
  8. namespace electron {
  9. class ElectronBindings;
  10. class NodeBindings;
  11. // Watches for WebWorker and insert node integration to it.
  12. class WebWorkerObserver {
  13. public:
  14. WebWorkerObserver();
  15. ~WebWorkerObserver();
  16. // Returns the WebWorkerObserver for current worker thread.
  17. static WebWorkerObserver* GetCurrent();
  18. // Creates a new WebWorkerObserver for a given context.
  19. static WebWorkerObserver* Create();
  20. // disable copy
  21. WebWorkerObserver(const WebWorkerObserver&) = delete;
  22. WebWorkerObserver& operator=(const WebWorkerObserver&) = delete;
  23. void WorkerScriptReadyForEvaluation(v8::Local<v8::Context> context);
  24. void ContextWillDestroy(v8::Local<v8::Context> context);
  25. private:
  26. std::unique_ptr<NodeBindings> node_bindings_;
  27. std::unique_ptr<ElectronBindings> electron_bindings_;
  28. };
  29. } // namespace electron
  30. #endif // ELECTRON_SHELL_RENDERER_WEB_WORKER_OBSERVER_H_