2015-07-16 17:40:01 -04:00
|
|
|
// Copyright 2015 The Chromium Embedded Framework Authors.
|
|
|
|
// Portions copyright 2014 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "libcef/browser/extensions/mime_handler_view_guest_delegate.h"
|
|
|
|
|
2020-09-22 15:54:02 -04:00
|
|
|
#include "libcef/browser/alloy/alloy_browser_host_impl.h"
|
2020-06-28 14:29:44 -04:00
|
|
|
#include "libcef/browser/alloy/alloy_content_browser_client.h"
|
2017-02-14 17:27:19 -05:00
|
|
|
#include "libcef/browser/browser_context.h"
|
2015-07-16 17:40:01 -04:00
|
|
|
#include "libcef/browser/browser_info.h"
|
2015-11-17 13:20:13 -05:00
|
|
|
#include "libcef/browser/osr/web_contents_view_osr.h"
|
2015-07-16 17:40:01 -04:00
|
|
|
|
|
|
|
#include "content/browser/browser_plugin/browser_plugin_guest.h"
|
|
|
|
#include "content/browser/web_contents/web_contents_impl.h"
|
|
|
|
#include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.h"
|
|
|
|
|
|
|
|
namespace extensions {
|
|
|
|
|
|
|
|
CefMimeHandlerViewGuestDelegate::CefMimeHandlerViewGuestDelegate(
|
|
|
|
MimeHandlerViewGuest* guest)
|
2020-01-23 16:58:01 -05:00
|
|
|
: guest_(guest), owner_web_contents_(guest_->owner_web_contents()) {}
|
2015-07-16 17:40:01 -04:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefMimeHandlerViewGuestDelegate::~CefMimeHandlerViewGuestDelegate() {}
|
2015-07-16 17:40:01 -04:00
|
|
|
|
|
|
|
void CefMimeHandlerViewGuestDelegate::OverrideWebContentsCreateParams(
|
|
|
|
content::WebContents::CreateParams* params) {
|
|
|
|
DCHECK(params->guest_delegate);
|
|
|
|
|
2020-09-22 15:54:02 -04:00
|
|
|
CefRefPtr<AlloyBrowserHostImpl> owner_browser =
|
|
|
|
AlloyBrowserHostImpl::GetBrowserForContents(owner_web_contents_);
|
2020-01-23 16:58:01 -05:00
|
|
|
DCHECK(owner_browser);
|
|
|
|
|
2015-07-16 17:40:01 -04:00
|
|
|
if (owner_browser->IsWindowless()) {
|
2018-07-02 19:46:03 -05:00
|
|
|
CefWebContentsViewOSR* view_osr = new CefWebContentsViewOSR(
|
|
|
|
owner_browser->GetBackgroundColor(), false, false);
|
2015-07-16 17:40:01 -04:00
|
|
|
params->view = view_osr;
|
|
|
|
params->delegate_view = view_osr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-23 16:58:01 -05:00
|
|
|
void CefMimeHandlerViewGuestDelegate::OnGuestAttached() {
|
2015-07-16 17:40:01 -04:00
|
|
|
content::WebContents* web_contents = guest_->web_contents();
|
2015-07-23 20:06:56 -04:00
|
|
|
DCHECK(web_contents);
|
2015-07-16 17:40:01 -04:00
|
|
|
|
2020-09-22 15:54:02 -04:00
|
|
|
CefRefPtr<AlloyBrowserHostImpl> owner_browser =
|
|
|
|
AlloyBrowserHostImpl::GetBrowserForContents(owner_web_contents_);
|
2020-01-23 16:58:01 -05:00
|
|
|
DCHECK(owner_browser);
|
|
|
|
|
2015-10-21 14:17:09 -04:00
|
|
|
// Associate guest state information with the owner browser.
|
2020-01-23 16:58:01 -05:00
|
|
|
owner_browser->browser_info()->MaybeCreateFrame(web_contents->GetMainFrame(),
|
|
|
|
true /* is_guest_view */);
|
2015-07-23 20:06:56 -04:00
|
|
|
}
|
|
|
|
|
2020-01-23 16:58:01 -05:00
|
|
|
void CefMimeHandlerViewGuestDelegate::OnGuestDetached() {
|
2015-10-21 14:17:09 -04:00
|
|
|
content::WebContents* web_contents = guest_->web_contents();
|
|
|
|
DCHECK(web_contents);
|
|
|
|
|
2020-09-22 15:54:02 -04:00
|
|
|
CefRefPtr<AlloyBrowserHostImpl> owner_browser =
|
|
|
|
AlloyBrowserHostImpl::GetBrowserForContents(owner_web_contents_);
|
2020-01-23 16:58:01 -05:00
|
|
|
DCHECK(owner_browser);
|
|
|
|
|
2015-10-21 14:17:09 -04:00
|
|
|
// Disassociate guest state information with the owner browser.
|
2020-01-23 16:58:01 -05:00
|
|
|
owner_browser->browser_info()->RemoveFrame(web_contents->GetMainFrame());
|
2015-07-16 17:40:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefMimeHandlerViewGuestDelegate::HandleContextMenu(
|
|
|
|
content::WebContents* web_contents,
|
|
|
|
const content::ContextMenuParams& params) {
|
|
|
|
content::ContextMenuParams new_params = params;
|
|
|
|
|
|
|
|
gfx::Point guest_coordinates =
|
2017-05-17 11:29:28 +02:00
|
|
|
static_cast<content::WebContentsImpl*>(web_contents)
|
|
|
|
->GetBrowserPluginGuest()
|
|
|
|
->GetScreenCoordinates(gfx::Point());
|
2015-07-16 17:40:01 -04:00
|
|
|
|
|
|
|
// Adjust (x,y) position for offset from guest to embedder.
|
|
|
|
new_params.x += guest_coordinates.x();
|
|
|
|
new_params.y += guest_coordinates.y();
|
|
|
|
|
2020-09-22 15:54:02 -04:00
|
|
|
CefRefPtr<AlloyBrowserHostImpl> owner_browser =
|
|
|
|
AlloyBrowserHostImpl::GetBrowserForContents(owner_web_contents_);
|
2020-01-23 16:58:01 -05:00
|
|
|
DCHECK(owner_browser);
|
|
|
|
|
|
|
|
return owner_browser->HandleContextMenu(web_contents, new_params);
|
2015-07-16 17:40:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace extensions
|