guest_os_installer_ui.cc 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2022 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ash/webui/guest_os_installer/guest_os_installer_ui.h"
  5. #include "ash/webui/grit/ash_guest_os_installer_resources.h"
  6. #include "ash/webui/grit/ash_guest_os_installer_resources_map.h"
  7. #include "ash/webui/guest_os_installer/url_constants.h"
  8. #include "content/public/browser/web_ui_data_source.h"
  9. namespace ash {
  10. GuestOSInstallerUI::GuestOSInstallerUI(content::WebUI* web_ui,
  11. const GURL& url,
  12. DelegateFactory delegate_factory)
  13. : ui::MojoWebDialogUI(web_ui),
  14. url_(url),
  15. delegate_factory_(delegate_factory) {
  16. auto* source = content::WebUIDataSource::CreateAndAdd(
  17. web_ui->GetWebContents()->GetBrowserContext(),
  18. ash::kChromeUIGuestOSInstallerHost);
  19. source->DisableTrustedTypesCSP();
  20. source->AddResourcePaths(base::make_span(kAshGuestOsInstallerResources,
  21. kAshGuestOsInstallerResourcesSize));
  22. source->SetDefaultResource(IDR_ASH_GUEST_OS_INSTALLER_INDEX_HTML);
  23. }
  24. GuestOSInstallerUI::~GuestOSInstallerUI() = default;
  25. void GuestOSInstallerUI::BindInterface(
  26. mojo::PendingReceiver<ash::guest_os_installer::mojom::PageHandlerFactory>
  27. pending_receiver) {
  28. page_factory_receiver_.Bind(std::move(pending_receiver));
  29. }
  30. void GuestOSInstallerUI::CreatePageHandler(
  31. mojo::PendingRemote<ash::guest_os_installer::mojom::Page> pending_page,
  32. mojo::PendingReceiver<ash::guest_os_installer::mojom::PageHandler>
  33. pending_page_handler) {
  34. // Code under //ash/webui isn't allowed to know about types under //chrome,
  35. // which is where all the actual GuestOS implementations live. To get around
  36. // this we delegate actually picking a backend to this delegate factory
  37. // callback, which lives in //chrome and is passed to us by our constructor
  38. // (which also lives in //chrome).
  39. handler_ = delegate_factory_.Run(this, url_, std::move(pending_page),
  40. std::move(pending_page_handler));
  41. }
  42. WEB_UI_CONTROLLER_TYPE_IMPL(GuestOSInstallerUI)
  43. } // namespace ash