2015-06-25 06:28:13 +00:00
|
|
|
// Copyright (c) 2015 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef ATOM_BROWSER_WEB_VIEW_GUEST_DELEGATE_H_
|
|
|
|
#define ATOM_BROWSER_WEB_VIEW_GUEST_DELEGATE_H_
|
|
|
|
|
2017-01-30 11:18:40 +00:00
|
|
|
#include "atom/browser/web_contents_zoom_controller.h"
|
2015-06-25 06:28:13 +00:00
|
|
|
#include "content/public/browser/browser_plugin_guest_delegate.h"
|
|
|
|
#include "content/public/browser/web_contents_observer.h"
|
|
|
|
|
|
|
|
namespace atom {
|
|
|
|
|
|
|
|
namespace api {
|
|
|
|
class WebContents;
|
|
|
|
}
|
|
|
|
|
|
|
|
// A struct of parameters for SetSize(). The parameters are all declared as
|
|
|
|
// scoped pointers since they are all optional. Null pointers indicate that the
|
|
|
|
// parameter has not been provided, and the last used value should be used. Note
|
|
|
|
// that when |enable_auto_size| is true, providing |normal_size| is not
|
|
|
|
// meaningful. This is because the normal size of the guestview is overridden
|
|
|
|
// whenever autosizing occurs.
|
|
|
|
struct SetSizeParams {
|
2018-04-17 23:37:22 +00:00
|
|
|
SetSizeParams();
|
|
|
|
~SetSizeParams();
|
2015-06-25 06:28:13 +00:00
|
|
|
|
2016-05-23 01:59:39 +00:00
|
|
|
std::unique_ptr<bool> enable_auto_size;
|
|
|
|
std::unique_ptr<gfx::Size> min_size;
|
|
|
|
std::unique_ptr<gfx::Size> max_size;
|
|
|
|
std::unique_ptr<gfx::Size> normal_size;
|
2015-06-25 06:28:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class WebViewGuestDelegate : public content::BrowserPluginGuestDelegate,
|
2017-01-30 11:18:40 +00:00
|
|
|
public content::WebContentsObserver,
|
|
|
|
public WebContentsZoomController::Observer {
|
2015-06-25 06:28:13 +00:00
|
|
|
public:
|
|
|
|
WebViewGuestDelegate();
|
|
|
|
~WebViewGuestDelegate() override;
|
|
|
|
|
|
|
|
void Initialize(api::WebContents* api_web_contents);
|
|
|
|
|
|
|
|
// Called when the WebContents is going to be destroyed.
|
|
|
|
void Destroy();
|
|
|
|
|
|
|
|
// Used to toggle autosize mode for this GuestView, and set both the automatic
|
|
|
|
// and normal sizes.
|
|
|
|
void SetSize(const SetSizeParams& params);
|
|
|
|
|
2018-04-12 11:56:37 +00:00
|
|
|
// Invoked when the contents auto-resized and the container should match it.
|
|
|
|
void ResizeDueToAutoResize(const gfx::Size& new_size);
|
|
|
|
|
2017-06-21 12:17:27 +00:00
|
|
|
// Return true if attached.
|
2017-07-17 13:52:02 +00:00
|
|
|
bool IsAttached() const { return attached_; }
|
2017-06-21 12:17:27 +00:00
|
|
|
|
2015-06-25 06:28:13 +00:00
|
|
|
protected:
|
|
|
|
// content::WebContentsObserver:
|
2016-07-14 00:19:28 +00:00
|
|
|
void DidFinishNavigation(
|
|
|
|
content::NavigationHandle* navigation_handle) override;
|
2015-06-25 06:28:13 +00:00
|
|
|
|
|
|
|
// content::BrowserPluginGuestDelegate:
|
|
|
|
void DidAttach(int guest_proxy_routing_id) final;
|
2017-06-21 12:17:27 +00:00
|
|
|
void DidDetach() final;
|
2015-06-25 06:28:13 +00:00
|
|
|
content::WebContents* GetOwnerWebContents() const final;
|
|
|
|
void SetGuestHost(content::GuestHost* guest_host) final;
|
|
|
|
void WillAttach(content::WebContents* embedder_web_contents,
|
|
|
|
int element_instance_id,
|
2015-08-04 08:46:11 +00:00
|
|
|
bool is_full_page_plugin,
|
|
|
|
const base::Closure& completion_callback) final;
|
2017-01-25 01:44:58 +00:00
|
|
|
bool CanBeEmbeddedInsideCrossProcessFrames() override;
|
|
|
|
content::RenderWidgetHost* GetOwnerRenderWidgetHost() override;
|
|
|
|
content::SiteInstance* GetOwnerSiteInstance() override;
|
2017-05-23 20:26:19 +00:00
|
|
|
content::WebContents* CreateNewGuestWindow(
|
2018-04-18 01:44:10 +00:00
|
|
|
const content::WebContents::CreateParams& create_params) override;
|
2015-06-25 06:28:13 +00:00
|
|
|
|
2017-01-30 11:18:40 +00:00
|
|
|
// WebContentsZoomController::Observer:
|
|
|
|
void OnZoomLevelChanged(content::WebContents* web_contents,
|
2017-01-30 17:06:50 +00:00
|
|
|
double level,
|
|
|
|
bool is_temporary) override;
|
2017-01-30 11:18:40 +00:00
|
|
|
|
2015-06-25 06:28:13 +00:00
|
|
|
private:
|
|
|
|
// This method is invoked when the contents auto-resized to give the container
|
|
|
|
// an opportunity to match it if it wishes.
|
|
|
|
//
|
|
|
|
// This gives the derived class an opportunity to inform its container element
|
|
|
|
// or perform other actions.
|
2018-04-12 11:56:37 +00:00
|
|
|
void UpdateGuestSize(const gfx::Size& new_size, bool due_to_auto_resize);
|
2015-06-25 06:28:13 +00:00
|
|
|
|
|
|
|
// Returns the default size of the guestview.
|
|
|
|
gfx::Size GetDefaultSize() const;
|
|
|
|
|
2017-11-30 15:09:05 +00:00
|
|
|
void ResetZoomController();
|
|
|
|
|
2015-06-25 06:28:13 +00:00
|
|
|
// The WebContents that attaches this guest view.
|
2017-10-11 08:14:03 +00:00
|
|
|
content::WebContents* embedder_web_contents_ = nullptr;
|
2015-06-25 06:28:13 +00:00
|
|
|
|
2017-01-30 11:18:40 +00:00
|
|
|
// The zoom controller of the embedder that is used
|
|
|
|
// to subscribe for zoom changes.
|
2018-05-21 22:18:38 +00:00
|
|
|
WebContentsZoomController* embedder_zoom_controller_ = nullptr;
|
2017-01-30 11:18:40 +00:00
|
|
|
|
2015-06-25 06:28:13 +00:00
|
|
|
// The size of the container element.
|
|
|
|
gfx::Size element_size_;
|
|
|
|
|
|
|
|
// The size of the guest content. Note: In autosize mode, the container
|
|
|
|
// element may not match the size of the guest.
|
|
|
|
gfx::Size guest_size_;
|
|
|
|
|
|
|
|
// A pointer to the guest_host.
|
2018-05-21 22:18:38 +00:00
|
|
|
content::GuestHost* guest_host_ = nullptr;
|
2015-06-25 06:28:13 +00:00
|
|
|
|
|
|
|
// Indicates whether autosize mode is enabled or not.
|
2018-05-21 22:18:38 +00:00
|
|
|
bool auto_size_enabled_ = false;
|
2015-06-25 06:28:13 +00:00
|
|
|
|
|
|
|
// The maximum size constraints of the container element in autosize mode.
|
|
|
|
gfx::Size max_auto_size_;
|
|
|
|
|
|
|
|
// The minimum size constraints of the container element in autosize mode.
|
|
|
|
gfx::Size min_auto_size_;
|
|
|
|
|
|
|
|
// The size that will be used when autosize mode is disabled.
|
|
|
|
gfx::Size normal_size_;
|
|
|
|
|
|
|
|
// Whether the guest view is inside a plugin document.
|
2018-05-21 22:18:38 +00:00
|
|
|
bool is_full_page_plugin_ = false;
|
2015-06-25 06:28:13 +00:00
|
|
|
|
2017-06-21 12:17:27 +00:00
|
|
|
// Whether attached.
|
2018-05-21 22:18:38 +00:00
|
|
|
bool attached_ = false;
|
2017-06-21 12:17:27 +00:00
|
|
|
|
2018-05-21 22:18:38 +00:00
|
|
|
api::WebContents* api_web_contents_ = nullptr;
|
2015-06-25 06:28:13 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(WebViewGuestDelegate);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace atom
|
|
|
|
|
|
|
|
#endif // ATOM_BROWSER_WEB_VIEW_GUEST_DELEGATE_H_
|