web_worker_observer.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 <set>
  8. #include "v8/include/v8.h"
  9. namespace node {
  10. class Environment;
  11. } // namespace node
  12. namespace electron {
  13. class ElectronBindings;
  14. class NodeBindings;
  15. // Watches for WebWorker and insert node integration to it.
  16. class WebWorkerObserver {
  17. public:
  18. WebWorkerObserver();
  19. ~WebWorkerObserver();
  20. // Returns the WebWorkerObserver for current worker thread.
  21. static WebWorkerObserver* GetCurrent();
  22. // Creates a new WebWorkerObserver for a given context.
  23. static WebWorkerObserver* Create();
  24. // disable copy
  25. WebWorkerObserver(const WebWorkerObserver&) = delete;
  26. WebWorkerObserver& operator=(const WebWorkerObserver&) = delete;
  27. void WorkerScriptReadyForEvaluation(v8::Local<v8::Context> context);
  28. void ContextWillDestroy(v8::Local<v8::Context> context);
  29. private:
  30. std::unique_ptr<NodeBindings> node_bindings_;
  31. std::unique_ptr<ElectronBindings> electron_bindings_;
  32. std::set<std::shared_ptr<node::Environment>> environments_;
  33. };
  34. } // namespace electron
  35. #endif // ELECTRON_SHELL_RENDERER_WEB_WORKER_OBSERVER_H_