atom_render_frame_observer.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 SHELL_RENDERER_ATOM_RENDER_FRAME_OBSERVER_H_
  5. #define SHELL_RENDERER_ATOM_RENDER_FRAME_OBSERVER_H_
  6. #include <string>
  7. #include "base/strings/string16.h"
  8. #include "content/public/renderer/render_frame_observer.h"
  9. #include "ipc/ipc_platform_file.h"
  10. #include "shell/renderer/renderer_client_base.h"
  11. #include "third_party/blink/public/platform/web_isolated_world_ids.h"
  12. #include "third_party/blink/public/web/web_local_frame.h"
  13. namespace base {
  14. class ListValue;
  15. }
  16. namespace electron {
  17. enum World {
  18. MAIN_WORLD = 0,
  19. // Use a high number far away from 0 to not collide with any other world
  20. // IDs created internally by Chrome.
  21. ISOLATED_WORLD = 999,
  22. // Numbers for isolated worlds for extensions are set in
  23. // lib/renderer/content-script-injector.ts, and are greater than or equal to
  24. // this number, up to ISOLATED_WORLD_EXTENSIONS_END.
  25. ISOLATED_WORLD_EXTENSIONS = 1 << 20,
  26. // Last valid isolated world ID.
  27. ISOLATED_WORLD_EXTENSIONS_END =
  28. blink::IsolatedWorldId::kEmbedderWorldIdLimit - 1
  29. };
  30. // Helper class to forward the messages to the client.
  31. class AtomRenderFrameObserver : public content::RenderFrameObserver {
  32. public:
  33. AtomRenderFrameObserver(content::RenderFrame* frame,
  34. RendererClientBase* renderer_client);
  35. // content::RenderFrameObserver:
  36. void DidClearWindowObject() override;
  37. void DidCreateScriptContext(v8::Handle<v8::Context> context,
  38. int world_id) override;
  39. void DraggableRegionsChanged() override;
  40. void WillReleaseScriptContext(v8::Local<v8::Context> context,
  41. int world_id) override;
  42. void OnDestruct() override;
  43. private:
  44. bool ShouldNotifyClient(int world_id);
  45. void CreateIsolatedWorldContext();
  46. bool IsMainWorld(int world_id);
  47. bool IsIsolatedWorld(int world_id);
  48. void OnTakeHeapSnapshot(IPC::PlatformFileForTransit file_handle,
  49. const std::string& channel);
  50. content::RenderFrame* render_frame_;
  51. RendererClientBase* renderer_client_;
  52. DISALLOW_COPY_AND_ASSIGN(AtomRenderFrameObserver);
  53. };
  54. } // namespace electron
  55. #endif // SHELL_RENDERER_ATOM_RENDER_FRAME_OBSERVER_H_