web_view_guest_delegate.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright (c) 2015 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_BROWSER_WEB_VIEW_GUEST_DELEGATE_H_
  5. #define SHELL_BROWSER_WEB_VIEW_GUEST_DELEGATE_H_
  6. #include "content/public/browser/browser_plugin_guest_delegate.h"
  7. #include "shell/browser/web_contents_zoom_controller.h"
  8. namespace electron {
  9. namespace api {
  10. class WebContents;
  11. }
  12. class WebViewGuestDelegate : public content::BrowserPluginGuestDelegate,
  13. public WebContentsZoomController::Observer {
  14. public:
  15. WebViewGuestDelegate(content::WebContents* embedder,
  16. api::WebContents* api_web_contents);
  17. ~WebViewGuestDelegate() override;
  18. // Attach to the iframe.
  19. void AttachToIframe(content::WebContents* embedder_web_contents,
  20. int embedder_frame_id);
  21. protected:
  22. // content::BrowserPluginGuestDelegate:
  23. void DidDetach() final;
  24. content::WebContents* GetOwnerWebContents() final;
  25. content::RenderWidgetHost* GetOwnerRenderWidgetHost() final;
  26. content::SiteInstance* GetOwnerSiteInstance() final;
  27. content::WebContents* CreateNewGuestWindow(
  28. const content::WebContents::CreateParams& create_params) final;
  29. // WebContentsZoomController::Observer:
  30. void OnZoomLevelChanged(content::WebContents* web_contents,
  31. double level,
  32. bool is_temporary) override;
  33. void OnZoomControllerWebContentsDestroyed() override;
  34. private:
  35. void ResetZoomController();
  36. // The WebContents that attaches this guest view.
  37. content::WebContents* embedder_web_contents_ = nullptr;
  38. // The zoom controller of the embedder that is used
  39. // to subscribe for zoom changes.
  40. WebContentsZoomController* embedder_zoom_controller_ = nullptr;
  41. api::WebContents* api_web_contents_ = nullptr;
  42. DISALLOW_COPY_AND_ASSIGN(WebViewGuestDelegate);
  43. };
  44. } // namespace electron
  45. #endif // SHELL_BROWSER_WEB_VIEW_GUEST_DELEGATE_H_