1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/webui/examples/browser/content_browser_client.h"
#include "components/embedder_support/user_agent_utils.h"
#include "components/guest_view/common/guest_view.mojom.h"
#include "content/public/browser/devtools_manager_delegate.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents_view_delegate.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
#include "ui/webui/examples/browser/browser_main_parts.h"
#include "ui/webui/examples/browser/ui/web/browser.h"
#include "ui/webui/examples/browser/ui/web/browser.mojom.h"
#include "ui/webui/examples/browser/ui/web/webshell_guest_view.h"
namespace webui_examples {
ContentBrowserClient::ContentBrowserClient() = default;
ContentBrowserClient::~ContentBrowserClient() = default;
std::unique_ptr<content::BrowserMainParts>
ContentBrowserClient::CreateBrowserMainParts(bool is_integration_test) {
auto browser_main_parts = BrowserMainParts::Create();
browser_main_parts_ = browser_main_parts.get();
return browser_main_parts;
}
std::unique_ptr<content::WebContentsViewDelegate>
ContentBrowserClient::GetWebContentsViewDelegate(
content::WebContents* web_contents) {
return browser_main_parts_->CreateWebContentsViewDelegate(web_contents);
}
std::unique_ptr<content::DevToolsManagerDelegate>
ContentBrowserClient::CreateDevToolsManagerDelegate() {
return browser_main_parts_->CreateDevToolsManagerDelegate();
}
void ContentBrowserClient::RegisterBrowserInterfaceBindersForFrame(
content::RenderFrameHost* render_frame_host,
mojo::BinderMapWithContext<content::RenderFrameHost*>* map) {
map->Add<webui_examples::mojom::PageHandlerFactory>(base::BindRepeating(
[](content::RenderFrameHost* host,
mojo::PendingReceiver<webui_examples::mojom::PageHandlerFactory>
receiver) {
if (host->GetParent()) {
LOG(ERROR) << "Called for Non-Main Frame!";
return;
}
auto* web_ui = host->GetWebUI();
Browser* browser = web_ui->GetController()->GetAs<Browser>();
if (!browser) {
LOG(ERROR) << "Failed to Get Browser";
return;
}
browser->BindInterface(std::move(receiver));
}));
}
void ContentBrowserClient::RegisterAssociatedInterfaceBindersForRenderFrameHost(
content::RenderFrameHost& render_frame_host,
blink::AssociatedInterfaceRegistry& associated_registry) {
associated_registry.AddInterface<guest_view::mojom::GuestViewHost>(
base::BindRepeating(&WebshellGuestView::Create,
render_frame_host.GetGlobalId()));
}
std::string ContentBrowserClient::GetUserAgent() {
return embedder_support::GetUserAgent();
}
} // namespace webui_examples
|