2015-07-16 23:40:01 +02:00
|
|
|
// Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
2024-07-02 19:50:48 +02:00
|
|
|
#include "cef/libcef/browser/browser_guest_util.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
|
2019-07-17 20:47:27 +02:00
|
|
|
#include "chrome/browser/browser_process.h"
|
|
|
|
#include "chrome/browser/printing/print_preview_dialog_controller.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "content/browser/browser_plugin/browser_plugin_guest.h"
|
|
|
|
#include "content/browser/web_contents/web_contents_impl.h"
|
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
namespace {
|
2015-08-17 21:48:57 +02:00
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
content::WebContents* GetOwnerForBrowserPluginGuest(
|
|
|
|
const content::WebContents* guest) {
|
|
|
|
auto* guest_impl = static_cast<const content::WebContentsImpl*>(guest);
|
2015-08-17 21:48:57 +02:00
|
|
|
content::BrowserPluginGuest* plugin_guest =
|
|
|
|
guest_impl->GetBrowserPluginGuest();
|
2020-04-02 23:26:14 +02:00
|
|
|
if (plugin_guest) {
|
2020-10-08 21:54:42 +02:00
|
|
|
return plugin_guest->owner_web_contents();
|
2020-04-02 23:26:14 +02:00
|
|
|
}
|
2024-04-17 18:01:26 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
2019-07-17 20:47:27 +02:00
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
content::WebContents* GetInitiatorForPrintPreviewDialog(
|
|
|
|
const content::WebContents* guest) {
|
2019-07-17 20:47:27 +02:00
|
|
|
auto print_preview_controller =
|
|
|
|
g_browser_process->print_preview_dialog_controller();
|
2024-04-17 18:01:26 +02:00
|
|
|
return print_preview_controller->GetInitiator(
|
|
|
|
const_cast<content::WebContents*>(guest));
|
2015-07-16 23:40:01 +02:00
|
|
|
}
|
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
} // namespace
|
2015-10-12 22:45:14 +02:00
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
content::WebContents* GetOwnerForGuestContents(
|
|
|
|
const content::WebContents* guest) {
|
|
|
|
// Maybe it's a guest view. This occurs while loading the PDF viewer.
|
|
|
|
if (auto* owner = GetOwnerForBrowserPluginGuest(guest)) {
|
|
|
|
return owner;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-10-21 20:17:09 +02:00
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
// Maybe it's a print preview dialog. This occurs while loading the print
|
|
|
|
// preview dialog.
|
|
|
|
if (auto* initiator = GetInitiatorForPrintPreviewDialog(guest)) {
|
|
|
|
// Maybe the dialog is parented to a guest view. This occurs while loading
|
|
|
|
// the print preview dialog from inside the PDF viewer.
|
|
|
|
if (auto* owner = GetOwnerForBrowserPluginGuest(initiator)) {
|
|
|
|
return owner;
|
2015-10-21 20:17:09 +02:00
|
|
|
}
|
2024-04-17 18:01:26 +02:00
|
|
|
return initiator;
|
2015-10-12 22:45:14 +02:00
|
|
|
}
|
2024-04-17 18:01:26 +02:00
|
|
|
|
|
|
|
return nullptr;
|
2015-10-12 22:45:14 +02:00
|
|
|
}
|
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
bool IsBrowserPluginGuest(const content::WebContents* web_contents) {
|
|
|
|
return !!GetOwnerForBrowserPluginGuest(web_contents);
|
|
|
|
}
|
2017-01-23 18:36:54 +01:00
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
bool IsPrintPreviewDialog(const content::WebContents* web_contents) {
|
|
|
|
return !!GetInitiatorForPrintPreviewDialog(web_contents);
|
2017-01-23 18:36:54 +01:00
|
|
|
}
|