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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
// 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 "chrome/browser/ui/webui/ash/office_fallback/office_fallback_ui.h"
#include <utility>
#include "base/functional/bind.h"
#include "chrome/browser/chromeos/upload_office_to_cloud/upload_office_to_cloud.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/grit/office_fallback_resources.h"
#include "chrome/grit/office_fallback_resources_map.h"
#include "chromeos/constants/chromeos_features.h"
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_data_source.h"
#include "ui/webui/color_change_listener/color_change_handler.h"
#include "ui/webui/webui_util.h"
namespace ash::office_fallback {
bool OfficeFallbackUIConfig::IsWebUIEnabled(
content::BrowserContext* browser_context) {
return chromeos::IsEligibleAndEnabledUploadOfficeToCloud(
Profile::FromBrowserContext(browser_context));
}
OfficeFallbackUI::OfficeFallbackUI(content::WebUI* web_ui)
: ui::MojoWebDialogUI{web_ui} {
content::WebUIDataSource* source = content::WebUIDataSource::CreateAndAdd(
Profile::FromWebUI(web_ui), chrome::kChromeUIOfficeFallbackHost);
// Set text for dialog buttons.
static constexpr webui::LocalizedString kStrings[] = {
{"officeFallbackCancel", IDS_OFFICE_FALLBACK_CANCEL},
{"officeFallbackTryAgain", IDS_OFFICE_FALLBACK_TRY_AGAIN},
{"officeFallbackOk", IDS_OFFICE_FALLBACK_OK},
{"officeFallbackOpenInBasicEditor",
IDS_OFFICE_FALLBACK_OPEN_IN_BASIC_EDITOR},
};
source->AddLocalizedStrings(kStrings);
webui::SetupWebUIDataSource(source, kOfficeFallbackResources,
IDR_OFFICE_FALLBACK_MAIN_HTML);
}
OfficeFallbackUI::~OfficeFallbackUI() = default;
void OfficeFallbackUI::BindInterface(
mojo::PendingReceiver<mojom::PageHandlerFactory> pending_receiver) {
if (factory_receiver_.is_bound()) {
factory_receiver_.reset();
}
factory_receiver_.Bind(std::move(pending_receiver));
}
void OfficeFallbackUI::CreatePageHandler(
mojo::PendingReceiver<mojom::PageHandler> receiver) {
page_handler_ = std::make_unique<OfficeFallbackPageHandler>(
std::move(receiver),
// base::Unretained() because |page_handler_| will not out-live |this|.
base::BindOnce(&OfficeFallbackUI::CloseDialog, base::Unretained(this)));
}
void OfficeFallbackUI::CloseDialog(mojom::DialogChoice choice) {
base::Value::List args;
switch (choice) {
case mojom::DialogChoice::kCancel:
args.Append(kDialogChoiceCancel);
break;
case mojom::DialogChoice::kOk:
args.Append(kDialogChoiceOk);
break;
case mojom::DialogChoice::kQuickOffice:
args.Append(kDialogChoiceQuickOffice);
break;
case mojom::DialogChoice::kTryAgain:
args.Append(kDialogChoiceTryAgain);
break;
}
ui::MojoWebDialogUI::CloseDialog(args);
}
void OfficeFallbackUI::BindInterface(
mojo::PendingReceiver<color_change_listener::mojom::PageHandler> receiver) {
color_provider_handler_ = std::make_unique<ui::ColorChangeHandler>(
web_ui()->GetWebContents(), std::move(receiver));
}
WEB_UI_CONTROLLER_TYPE_IMPL(OfficeFallbackUI)
} // namespace ash::office_fallback
|