diff --git mime_handler_view_guest.cc mime_handler_view_guest.cc index dcf7527..46fe51e 100644 --- mime_handler_view_guest.cc +++ mime_handler_view_guest.cc @@ -138,6 +138,8 @@ void MimeHandlerViewGuest::CreateWebContents( WebContents::CreateParams params(browser_context(), guest_site_instance.get()); params.guest_delegate = this; + if (delegate_) + delegate_->OverrideWebContentsCreateParams(¶ms); callback.Run(WebContents::Create(params)); } @@ -162,6 +164,30 @@ bool MimeHandlerViewGuest::ZoomPropagatesFromEmbedderToGuest() const { return false; } +void MimeHandlerViewGuest::OnGuestAttached( + content::WebContentsView* guest_view, + content::WebContentsView* parent_view) { + if (!delegate_ || !delegate_->OnGuestAttached(guest_view, parent_view)) + BrowserPluginGuestDelegate::OnGuestAttached(guest_view, parent_view); +} + +void MimeHandlerViewGuest::OnGuestDetached( + content::WebContentsView* guest_view, + content::WebContentsView* parent_view) { + if (!delegate_ || !delegate_->OnGuestDetached(guest_view, parent_view)) + BrowserPluginGuestDelegate::OnGuestDetached(guest_view, parent_view); +} + +void MimeHandlerViewGuest::CreateViewForWidget( + content::WebContentsView* guest_view, + content::RenderWidgetHost* render_widget_host) { + if (!delegate_ || + !delegate_->CreateViewForWidget(guest_view, render_widget_host)) { + BrowserPluginGuestDelegate::CreateViewForWidget(guest_view, + render_widget_host); + } +} + WebContents* MimeHandlerViewGuest::OpenURLFromTab( WebContents* source, const content::OpenURLParams& params) { diff --git mime_handler_view_guest.h mime_handler_view_guest.h index 87d249e..c6a8ad3 100644 --- mime_handler_view_guest.h +++ mime_handler_view_guest.h @@ -77,6 +77,15 @@ class MimeHandlerViewGuest : bool ShouldHandleFindRequestsForEmbedder() const final; bool ZoomPropagatesFromEmbedderToGuest() const final; + // content::BrowserPluginGuestDelegate implementation + void OnGuestAttached(content::WebContentsView* guest_view, + content::WebContentsView* parent_view) override; + void OnGuestDetached(content::WebContentsView* guest_view, + content::WebContentsView* parent_view) override; + void CreateViewForWidget( + content::WebContentsView* guest_view, + content::RenderWidgetHost* render_widget_host) override; + // WebContentsDelegate implementation. content::WebContents* OpenURLFromTab( content::WebContents* source, diff --git mime_handler_view_guest_delegate.cc mime_handler_view_guest_delegate.cc index 63b81b8..0f63f48 100644 --- mime_handler_view_guest_delegate.cc +++ mime_handler_view_guest_delegate.cc @@ -6,6 +6,24 @@ namespace extensions { +bool MimeHandlerViewGuestDelegate::OnGuestAttached( + content::WebContentsView* guest_view, + content::WebContentsView* parent_view) { + return false; +} + +bool MimeHandlerViewGuestDelegate::OnGuestDetached( + content::WebContentsView* guest_view, + content::WebContentsView* parent_view) { + return false; +} + +bool MimeHandlerViewGuestDelegate::CreateViewForWidget( + content::WebContentsView* guest_view, + content::RenderWidgetHost* render_widget_host) { + return false; +} + bool MimeHandlerViewGuestDelegate::HandleContextMenu( content::WebContents* web_contents, const content::ContextMenuParams& params) { diff --git mime_handler_view_guest_delegate.h mime_handler_view_guest_delegate.h index e065104d..f68b66c 100644 --- mime_handler_view_guest_delegate.h +++ mime_handler_view_guest_delegate.h @@ -6,10 +6,11 @@ #define EXTENSIONS_BROWSER_GUEST_VIEW_MIME_HANDLER_VIEW_MIME_HANDLER_VIEW_GUEST_DELEGATE_H_ #include "base/macros.h" +#include "content/public/browser/web_contents.h" namespace content { -class WebContents; struct ContextMenuParams; +class RenderWidgetHost; } // namespace content namespace extensions { @@ -21,6 +22,21 @@ class MimeHandlerViewGuestDelegate { public: MimeHandlerViewGuestDelegate() {} virtual ~MimeHandlerViewGuestDelegate() {} + + // Provides an opportunity to supply a custom view implementation. + virtual void OverrideWebContentsCreateParams( + content::WebContents::CreateParams* params) {} + + // Called when a guest is attached or detached. + virtual bool OnGuestAttached(content::WebContentsView* guest_view, + content::WebContentsView* parent_view); + virtual bool OnGuestDetached(content::WebContentsView* guest_view, + content::WebContentsView* parent_view); + + // Called to create the view for the widget. + virtual bool CreateViewForWidget( + content::WebContentsView* guest_view, + content::RenderWidgetHost* render_widget_host); // Handles context menu, or returns false if unhandled. virtual bool HandleContextMenu(content::WebContents* web_contents,