2018-03-20 01:25:51 +00:00
|
|
|
// Copyright (c) 2018 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/api/electron_api_web_contents.h"
|
2018-03-20 01:25:51 +00:00
|
|
|
|
2020-09-21 08:00:36 +00:00
|
|
|
#include "content/browser/renderer_host/frame_tree.h" // nogncheck
|
|
|
|
#include "content/browser/renderer_host/frame_tree_node.h" // nogncheck
|
2019-03-05 05:08:55 +00:00
|
|
|
#include "content/browser/web_contents/web_contents_impl.h" // nogncheck
|
2019-01-12 06:50:33 +00:00
|
|
|
|
|
|
|
#if BUILDFLAG(ENABLE_OSR)
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/osr/osr_render_widget_host_view.h"
|
|
|
|
#include "shell/browser/osr/osr_web_contents_view.h"
|
2019-01-12 06:50:33 +00:00
|
|
|
#endif
|
2018-03-20 01:25:51 +00:00
|
|
|
|
|
|
|
// Including both web_contents_impl.h and node.h would introduce a error, we
|
|
|
|
// have to isolate the usage of WebContentsImpl into a clean file to fix it:
|
|
|
|
// error C2371: 'ssize_t': redefinition; different basic types
|
|
|
|
|
2022-06-29 19:55:47 +00:00
|
|
|
namespace electron::api {
|
2018-03-20 01:25:51 +00:00
|
|
|
|
2019-01-12 06:50:33 +00:00
|
|
|
void WebContents::DetachFromOuterFrame() {
|
|
|
|
// See detach_webview_frame.patch on how to detach.
|
2019-02-26 01:47:29 +00:00
|
|
|
int frame_tree_node_id =
|
|
|
|
static_cast<content::WebContentsImpl*>(web_contents())
|
|
|
|
->GetOuterDelegateFrameTreeNodeId();
|
|
|
|
if (frame_tree_node_id != content::FrameTreeNode::kFrameTreeNodeInvalidId) {
|
|
|
|
auto* node = content::FrameTreeNode::GloballyFindByID(frame_tree_node_id);
|
|
|
|
DCHECK(node->parent());
|
|
|
|
node->frame_tree()->RemoveFrame(node);
|
|
|
|
}
|
2019-01-12 06:50:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if BUILDFLAG(ENABLE_OSR)
|
2018-03-20 01:25:51 +00:00
|
|
|
OffScreenWebContentsView* WebContents::GetOffScreenWebContentsView() const {
|
2018-10-11 13:14:01 +00:00
|
|
|
if (IsOffScreen()) {
|
|
|
|
const auto* impl =
|
|
|
|
static_cast<const content::WebContentsImpl*>(web_contents());
|
|
|
|
return static_cast<OffScreenWebContentsView*>(impl->GetView());
|
|
|
|
} else {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-03-20 01:25:51 +00:00
|
|
|
}
|
|
|
|
|
2018-05-15 01:59:22 +00:00
|
|
|
OffScreenRenderWidgetHostView* WebContents::GetOffScreenRenderWidgetHostView()
|
|
|
|
const {
|
2018-10-11 13:14:01 +00:00
|
|
|
if (IsOffScreen()) {
|
|
|
|
return static_cast<OffScreenRenderWidgetHostView*>(
|
|
|
|
web_contents()->GetRenderWidgetHostView());
|
|
|
|
} else {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-05-15 01:59:22 +00:00
|
|
|
}
|
2019-01-12 06:50:33 +00:00
|
|
|
#endif
|
2018-05-15 01:59:22 +00:00
|
|
|
|
2022-06-29 19:55:47 +00:00
|
|
|
} // namespace electron::api
|