<commit_before>//! ========================================================================================
//!  ExecutionGraph
//!  Copyright (C) 2014 by <NAME> <gnuetzi (at) gmail (døt) com>
//!
//!  @date Mon Jan 08 2018
//!  @author <NAME>, <gnuetzi (at) gmail (døt) com>
//!
//!  This Source Code Form is subject to the terms of the Mozilla Public
//!  License, v. 2.0. If a copy of the MPL was not distributed with this
//!  file, You can obtain one at http://mozilla.org/MPL/2.0/.
//! ========================================================================================

#include "AppHandler.hpp"

#include <sstream>
#include <string>

#include <base/cef_bind.h>
#include <cef_app.h>
#include <views/cef_browser_view.h>
#include <views/cef_window.h>
#include <wrapper/cef_closure_task.h>
#include <wrapper/cef_helpers.h>

namespace
{
    AppHandler* g_instance = nullptr;
}

AppHandler::AppHandler(bool use_views)
    : m_useViews(use_views), m_isClosing(false)
{
    DCHECK(!g_instance);
    g_instance = this;
}

AppHandler::~AppHandler()
{
    g_instance = nullptr;
}

// static
AppHandler* AppHandler::GetInstance()
{
    return g_instance;
}

void AppHandler::OnTitleChange(CefRefPtr<CefBrowser> browser,
                               const CefString& title)
{
    CEF_REQUIRE_UI_THREAD();

    if(m_useViews)
    {
        // Set the title of the window using the Views framework.
        CefRefPtr<CefBrowserView> browser_view =
            CefBrowserView::GetForBrowser(browser);
        if(browser_view)
        {
            CefRefPtr<CefWindow> window = browser_view->GetWindow();
            if(window)
                window->SetTitle(title);
        }
    }
    else
    {
        // Set the title of the window using platform APIs.
        PlatformTitleChange(browser, title);
    }
}

void AppHandler::OnAfterCreated(CefRefPtr<CefBrowser> browser)
{
    CEF_REQUIRE_UI_THREAD();
    if(!m_router)
    {
        CefMessageRouterConfig config;
        m_router = CefMessageRouterBrowserSide::Create(config);
        m_router->AddHandler(&m_messageHandler, true);
    }
    // Add to the list of existing browsers.
    m_browserList.push_back(browser);
}

bool AppHandler::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,
                                          CefProcessId source_process,
                                          CefRefPtr<CefProcessMessage> message)
{
    CEF_REQUIRE_UI_THREAD();
    DCHECK(!m_router);
    return m_router->OnProcessMessageReceived(browser, source_process, message);
}

bool AppHandler::DoClose(CefRefPtr<CefBrowser> browser)
{
    CEF_REQUIRE_UI_THREAD();

    // Closing the main window requires special handling. See the DoClose()
    // documentation in the CEF header for a detailed destription of this
    // process.
    if(m_browserList.size() == 1)
    {
        // Set a flag to indicate that the window close should be allowed.
        m_isClosing = true;
    }

    // Allow the close. For windowed browsers this will result in the OS close
    // event being sent.
    return false;
}

void AppHandler::OnBeforeClose(CefRefPtr<CefBrowser> browser)
{
    CEF_REQUIRE_UI_THREAD();
<commit_msg>path typo in scheme handler<commit_after>//! ========================================================================================
//!  ExecutionGraph
//!  Copyright (C) 2014 by <NAME> <gnuetzi (at) gmail (døt) com>
//!
//!  @date Mon Jan 08 2018
//!  @author <NAME>, <gnuetzi (at) gmail (døt) com>
//!
//!  This Source Code Form is subject to the terms of the Mozilla Public
//!  License, v. 2.0. If a copy of the MPL was not distributed with this
//!  file, You can obtain one at http://mozilla.org/MPL/2.0/.
//! ========================================================================================

#include "AppHandler.hpp"

#include <sstream>
#include <string>

#include <base/cef_bind.h>
#include <cef_app.h>
#include <views/cef_browser_view.h>
#include <views/cef_window.h>
#include <wrapper/cef_closure_task.h>
#include <wrapper/cef_helpers.h>

namespace
{
    AppHandler* g_instance = nullptr;
}

AppHandler::AppHandler(bool use_views)
    : m_useViews(use_views), m_isClosing(false)
{
    DCHECK(!g_instance);
    g_instance = this;
}

AppHandler::~AppHandler()
{
    g_instance = nullptr;
}

// static
AppHandler* AppHandler::GetInstance()
{
    return g_instance;
}

void AppHandler::OnTitleChange(CefRefPtr<CefBrowser> browser,
                               const CefString& title)
{
    CEF_REQUIRE_UI_THREAD();

    if(m_useViews)
    {
        // Set the title of the window using the Views framework.
        CefRefPtr<CefBrowserView> browser_view =
            CefBrowserView::GetForBrowser(browser);
        if(browser_view)
        {
            CefRefPtr<CefWindow> window = browser_view->GetWindow();
            if(window)
                window->SetTitle(title);
        }
    }
    else
    {
        // Set the title of the window using platform APIs.
        PlatformTitleChange(browser, title);
    }
}

void AppHandler::OnAfterCreated(CefRefPtr<CefBrowser> browser)
{
    CEF_REQUIRE_UI_THREAD();
    if(!m_router)
    {
        CefMessageRouterConfig config;
        m_router = CefMessageRouterBrowserSide::Create(config);
        m_router->AddHandler(&m_messageHandler, true);
    }
    // Add to the list of existing browsers.
    m_browserList.push_back(browser);
}

bool AppHandler::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,
                                          CefProcessId source_process,
                                          CefRefPtr<CefProcessMessage> message)
{
    CEF_REQUIRE_UI_THREAD();
    DCHECK(m_router);
    return m_router->OnProcessMessageReceived(browser, source_process, message);
}

bool AppHandler::DoClose(CefRefPtr<CefBrowser> browser)
{
    CEF_REQUIRE_UI_THREAD();

    // Closing the main window requires special handling. See the DoClose()
    // documentation in the CEF header for a detailed destription of this
    // process.
    if(m_browserList.size() == 1)
    {
        // Set a flag to indicate that the window close should be allowed.
        m_isClosing = true;
    }

    // Allow the close. For windowed browsers this will result in the OS close
    // event being sent.
    return false;
}

void AppHandler::OnBeforeClose(CefRefPtr<CefBrowser> browser)
{
    CEF_REQUIRE_UI_THREAD();

{'fraction_non_alphanumeric': 0.15658866027956653, 'fraction_numerical': 0.004711795193968902, 'mean_word_length': 3.048315321042594, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1876380', 'n_tokens_mistral': 1990, 'n_tokens_neox': 1913, 'n_words': 464}