#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "chrome/browser/ui/webui/browser_switch/browser_switch_ui.h"
#include <memory>
#include <string_view>
#include "base/functional/bind.h"
#include "base/metrics/histogram_macros.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "base/values.h"
#include "chrome/browser/browser_switcher/alternative_browser_driver.h"
#include "chrome/browser/browser_switcher/browser_switcher_service.h"
#include "chrome/browser/browser_switcher/browser_switcher_service_factory.h"
#include "chrome/browser/browser_switcher/browser_switcher_sitelist.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/webui/webui_util.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/grit/branded_strings.h"
#include "chrome/grit/browser_switch_resources.h"
#include "chrome/grit/browser_switch_resources_map.h"
#include "chrome/grit/generated_resources.h"
#include "components/grit/components_resources.h"
#include "content/public/browser/page_navigator.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_data_source.h"
#include "content/public/browser/web_ui_message_handler.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/page_transition_types.h"
#include "url/gurl.h"
namespace {
void GotoNewTabPage(content::WebContents* web_contents) { … }
bool IsLastTab(const Profile* profile) { … }
base::Value::Dict RuleSetToDict(const browser_switcher::RuleSet& ruleset) { … }
browser_switcher::BrowserSwitcherService* GetBrowserSwitcherService(
content::WebUI* web_ui) { … }
void CreateAndAddBrowserSwitchUIHTMLSource(content::WebUI* web_ui) { … }
}
class BrowserSwitchHandler : public content::WebUIMessageHandler { … };
BrowserSwitchHandler::BrowserSwitchHandler() { … }
BrowserSwitchHandler::~BrowserSwitchHandler() = default;
void BrowserSwitchHandler::RegisterMessages() { … }
void BrowserSwitchHandler::OnJavascriptAllowed() { … }
void BrowserSwitchHandler::OnJavascriptDisallowed() { … }
void BrowserSwitchHandler::OnAllRulesetsParsed(
browser_switcher::BrowserSwitcherService* service) { … }
void BrowserSwitchHandler::OnBrowserSwitcherPrefsChanged(
browser_switcher::BrowserSwitcherPrefs* prefs,
const std::vector<std::string>& changed_prefs) { … }
void BrowserSwitchHandler::SendDataChangedEvent() { … }
void BrowserSwitchHandler::HandleLaunchAlternativeBrowserAndCloseTab(
const base::Value::List& args) { … }
void BrowserSwitchHandler::OnLaunchFinished(base::TimeTicks start,
std::string callback_id,
bool success) { … }
void BrowserSwitchHandler::HandleGotoNewTabPage(const base::Value::List& args) { … }
void BrowserSwitchHandler::HandleGetAllRulesets(const base::Value::List& args) { … }
void BrowserSwitchHandler::HandleGetDecision(const base::Value::List& args) { … }
void BrowserSwitchHandler::HandleGetTimestamps(const base::Value::List& args) { … }
void BrowserSwitchHandler::HandleGetRulesetSources(
const base::Value::List& args) { … }
void BrowserSwitchHandler::HandleRefreshXml(const base::Value::List& args) { … }
void BrowserSwitchHandler::HandleIsBrowserSwitchEnabled(
const base::Value::List& args) { … }
BrowserSwitchUI::BrowserSwitchUI(content::WebUI* web_ui)
: … { … }