2014-10-31 12:17:05 -06:00
|
|
|
// Copyright (c) 2014 GitHub, Inc.
|
2014-10-22 08:55:13 -06:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 14:46:59 -06:00
|
|
|
#include "shell/browser/web_view_manager.h"
|
2014-10-22 08:55:13 -06:00
|
|
|
|
2016-05-25 11:28:35 -06:00
|
|
|
#include "content/public/browser/web_contents.h"
|
2020-02-04 13:19:40 -07:00
|
|
|
#include "shell/browser/electron_browser_context.h"
|
2014-10-22 08:55:13 -06:00
|
|
|
|
2019-06-19 15:23:04 -06:00
|
|
|
namespace electron {
|
2014-10-22 08:55:13 -06:00
|
|
|
|
2019-09-16 16:12:00 -06:00
|
|
|
WebViewManager::WebViewManager() = default;
|
2014-10-22 08:55:13 -06:00
|
|
|
|
2019-09-16 16:12:00 -06:00
|
|
|
WebViewManager::~WebViewManager() = default;
|
2014-10-22 08:55:13 -06:00
|
|
|
|
2014-10-23 09:08:48 -06:00
|
|
|
void WebViewManager::AddGuest(int guest_instance_id,
|
|
|
|
content::WebContents* embedder,
|
2015-09-02 18:47:58 -06:00
|
|
|
content::WebContents* web_contents) {
|
2018-04-17 19:55:30 -06:00
|
|
|
web_contents_embedder_map_[guest_instance_id] = {web_contents, embedder};
|
2014-10-23 09:08:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebViewManager::RemoveGuest(int guest_instance_id) {
|
2021-05-04 07:59:44 -06:00
|
|
|
web_contents_embedder_map_.erase(guest_instance_id);
|
2014-10-23 09:08:48 -06:00
|
|
|
}
|
|
|
|
|
2023-11-28 14:40:12 -07:00
|
|
|
bool WebViewManager::ForEachGuest(
|
|
|
|
content::WebContents* embedder_web_contents,
|
|
|
|
base::FunctionRef<bool(content::WebContents*)> fn) {
|
2019-11-07 08:39:48 -07:00
|
|
|
for (auto& item : web_contents_embedder_map_) {
|
|
|
|
if (item.second.embedder != embedder_web_contents)
|
|
|
|
continue;
|
|
|
|
|
2023-05-11 14:07:39 -06:00
|
|
|
content::WebContents* guest_web_contents = item.second.web_contents;
|
2023-11-28 14:40:12 -07:00
|
|
|
if (guest_web_contents && fn(guest_web_contents))
|
2014-10-23 09:08:48 -06:00
|
|
|
return true;
|
2019-11-07 08:39:48 -07:00
|
|
|
}
|
2014-10-22 08:55:13 -06:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-05-25 11:13:12 -06:00
|
|
|
// static
|
2016-05-25 11:20:00 -06:00
|
|
|
WebViewManager* WebViewManager::GetWebViewManager(
|
|
|
|
content::WebContents* web_contents) {
|
2018-04-17 16:41:47 -06:00
|
|
|
auto* context = web_contents->GetBrowserContext();
|
2016-05-25 11:13:12 -06:00
|
|
|
if (context) {
|
2018-04-17 16:41:47 -06:00
|
|
|
auto* manager = context->GetGuestManager();
|
2016-05-25 11:22:43 -06:00
|
|
|
return static_cast<WebViewManager*>(manager);
|
2016-05-25 11:13:12 -06:00
|
|
|
} else {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-19 15:23:04 -06:00
|
|
|
} // namespace electron
|