web_view_guest_delegate.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 ATOM_BROWSER_WEB_VIEW_GUEST_DELEGATE_H_
  5. #define ATOM_BROWSER_WEB_VIEW_GUEST_DELEGATE_H_
  6. #include "content/public/browser/browser_plugin_guest_delegate.h"
  7. #include "content/public/browser/web_contents_observer.h"
  8. namespace atom {
  9. namespace api {
  10. class WebContents;
  11. }
  12. // A struct of parameters for SetSize(). The parameters are all declared as
  13. // scoped pointers since they are all optional. Null pointers indicate that the
  14. // parameter has not been provided, and the last used value should be used. Note
  15. // that when |enable_auto_size| is true, providing |normal_size| is not
  16. // meaningful. This is because the normal size of the guestview is overridden
  17. // whenever autosizing occurs.
  18. struct SetSizeParams {
  19. SetSizeParams() {}
  20. ~SetSizeParams() {}
  21. std::unique_ptr<bool> enable_auto_size;
  22. std::unique_ptr<gfx::Size> min_size;
  23. std::unique_ptr<gfx::Size> max_size;
  24. std::unique_ptr<gfx::Size> normal_size;
  25. };
  26. class WebViewGuestDelegate : public content::BrowserPluginGuestDelegate,
  27. public content::WebContentsObserver {
  28. public:
  29. WebViewGuestDelegate();
  30. ~WebViewGuestDelegate() override;
  31. void Initialize(api::WebContents* api_web_contents);
  32. // Called when the WebContents is going to be destroyed.
  33. void Destroy();
  34. // Used to toggle autosize mode for this GuestView, and set both the automatic
  35. // and normal sizes.
  36. void SetSize(const SetSizeParams& params);
  37. protected:
  38. // content::WebContentsObserver:
  39. void DidFinishNavigation(
  40. content::NavigationHandle* navigation_handle) override;
  41. // content::BrowserPluginGuestDelegate:
  42. void DidAttach(int guest_proxy_routing_id) final;
  43. content::WebContents* GetOwnerWebContents() const final;
  44. void GuestSizeChanged(const gfx::Size& new_size) final;
  45. void SetGuestHost(content::GuestHost* guest_host) final;
  46. void WillAttach(content::WebContents* embedder_web_contents,
  47. int element_instance_id,
  48. bool is_full_page_plugin,
  49. const base::Closure& completion_callback) final;
  50. private:
  51. // This method is invoked when the contents auto-resized to give the container
  52. // an opportunity to match it if it wishes.
  53. //
  54. // This gives the derived class an opportunity to inform its container element
  55. // or perform other actions.
  56. void GuestSizeChangedDueToAutoSize(const gfx::Size& old_size,
  57. const gfx::Size& new_size);
  58. // Returns the default size of the guestview.
  59. gfx::Size GetDefaultSize() const;
  60. // The WebContents that attaches this guest view.
  61. content::WebContents* embedder_web_contents_;
  62. // The size of the container element.
  63. gfx::Size element_size_;
  64. // The size of the guest content. Note: In autosize mode, the container
  65. // element may not match the size of the guest.
  66. gfx::Size guest_size_;
  67. // A pointer to the guest_host.
  68. content::GuestHost* guest_host_;
  69. // Indicates whether autosize mode is enabled or not.
  70. bool auto_size_enabled_;
  71. // The maximum size constraints of the container element in autosize mode.
  72. gfx::Size max_auto_size_;
  73. // The minimum size constraints of the container element in autosize mode.
  74. gfx::Size min_auto_size_;
  75. // The size that will be used when autosize mode is disabled.
  76. gfx::Size normal_size_;
  77. // Whether the guest view is inside a plugin document.
  78. bool is_full_page_plugin_;
  79. api::WebContents* api_web_contents_;
  80. DISALLOW_COPY_AND_ASSIGN(WebViewGuestDelegate);
  81. };
  82. } // namespace atom
  83. #endif // ATOM_BROWSER_WEB_VIEW_GUEST_DELEGATE_H_