<commit_before>// Copyright  2010-2014 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

#pragma once

#include "Stdafx.h"
#include "BrowserSettings.h"
#include "MouseButtonType.h"
#include "Internals/RenderClientAdapter.h"
#include "Internals/MCefRefPtr.h"
#include "Internals/StringVisitor.h"

using namespace CefSharp::Internals;
using namespace System::Diagnostics;
using namespace System::ServiceModel;

namespace CefSharp
{
    private ref class ManagedCefBrowserAdapter : public ObjectBase, ISubProcessCallback
    {
        MCefRefPtr<RenderClientAdapter> _renderClientAdapter;
        ISubProcessProxy^ _javaScriptProxy;
        IWebBrowserInternal^ _webBrowserInternal;
        String^ _address;
        
    protected:
        virtual void DoDispose(bool isDisposing) override
        {
            Close();

            _renderClientAdapter = nullptr;
            _javaScriptProxy = nullptr;
            _webBrowserInternal = nullptr;
            _address = nullptr;

            ObjectBase::DoDispose(isDisposing);
        };

    public:
        ManagedCefBrowserAdapter(IWebBrowserInternal^ webBrowserInternal)
        {
            _webBrowserInternal = webBrowserInternal;
            _renderClientAdapter = new RenderClientAdapter(webBrowserInternal, this);
        }

        void CreateOffscreenBrowser(BrowserSettings^ browserSettings)
        {
            HWND hwnd = HWND();
            CefWindowInfo window;
            window.SetAsOffScreen(hwnd);
            window.SetTransparentPainting(true);
            CefString addressNative = StringUtils::ToNative("about:blank");

            if (!CefBrowserHost::CreateBrowser(window, _renderClientAdapter.get(), addressNative,
                *(CefBrowserSettings*) browserSettings->_internalBrowserSettings, NULL))
            {
                throw gcnew InvalidOperationException( "Failed to create offscreen browser. Call Cef.Initialize() first." );
            }
        }

        void Close()
        {
            auto cefHost = _renderClientAdapter->TryGetCefHost();

            if (cefHost != nullptr)
            {
                cefHost->CloseBrowser(true);
            }
        }

        void LoadUrl(String^ address)
        {
            _address = address;
            auto cefFrame = _renderClientAdapter->TryGetCefMainFrame();

            if (cefFrame != nullptr)
            {
                cefFrame->LoadURL(StringUtils::ToNative(address));
            }
        }


        void OnInitialized()
        {
            _webBrowserInternal->OnInitialized();

            auto address = _address;

            if ( address != nullptr )
            {
                LoadUrl(address);
            }
        };

        void LoadHtml(String^ html, String^ url)
        {
            auto cefFrame = _renderClientAdapter->TryGetCefMainFrame();

            if (cefFrame != nullptr)
            {
                cefFrame->LoadString(StringUtils::ToNative(html), StringUtils::ToNative(url));
            }
        }
<commit_msg>Update ManagedCefBrowserAdapter.h<commit_after>// Copyright © 2010-2014 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

#pragma once

#include "Stdafx.h"
#include "BrowserSettings.h"
#include "MouseButtonType.h"
#include "Internals/RenderClientAdapter.h"
#include "Internals/MCefRefPtr.h"
#include "Internals/StringVisitor.h"

using namespace CefSharp::Internals;
using namespace System::Diagnostics;
using namespace System::ServiceModel;

namespace CefSharp
{
    private ref class ManagedCefBrowserAdapter : public ObjectBase, ISubProcessCallback
    {
        MCefRefPtr<RenderClientAdapter> _renderClientAdapter;
        ISubProcessProxy^ _javaScriptProxy;
        IWebBrowserInternal^ _webBrowserInternal;
        String^ _address;
        
    protected:
        virtual void DoDispose(bool isDisposing) override
        {
            Close();

            _renderClientAdapter = nullptr;
            _javaScriptProxy = nullptr;
            _webBrowserInternal = nullptr;
            _address = nullptr;

            ObjectBase::DoDispose(isDisposing);
        };

    public:
        ManagedCefBrowserAdapter(IWebBrowserInternal^ webBrowserInternal)
        {
            _webBrowserInternal = webBrowserInternal;
            _renderClientAdapter = new RenderClientAdapter(webBrowserInternal, this);
        }

        void CreateOffscreenBrowser(BrowserSettings^ browserSettings)
        {
            HWND hwnd = HWND();
            CefWindowInfo window;
            window.SetAsOffScreen(hwnd);
            window.SetTransparentPainting(true);
            CefString addressNative = StringUtils::ToNative("about:blank");

            if (!CefBrowserHost::CreateBrowser(window, _renderClientAdapter.get(), addressNative,
                *(CefBrowserSettings*) browserSettings->_internalBrowserSettings, NULL))
            {
                throw gcnew InvalidOperationException( "Failed to create offscreen browser. Call Cef.Initialize() first." );
            }
        }

        void Close()
        {
            auto cefHost = _renderClientAdapter->TryGetCefHost();

            if (cefHost != nullptr)
            {
                cefHost->CloseBrowser(true);
            }
        }

        void LoadUrl(String^ address)
        {
            _address = address;
            auto cefFrame = _renderClientAdapter->TryGetCefMainFrame();

            if (cefFrame != nullptr)
            {
                cefFrame->LoadURL(StringUtils::ToNative(address));
            }
        }


        void OnInitialized()
        {
            if(_webBrowserInternal != nullptr)
			{
                _webBrowserInternal->OnInitialized();
    
                auto address = _address;
    
                if ( address != nullptr )
                {
                    LoadUrl(address);
                }
			}
        };

        void LoadHtml(String^ html, String^ url)
        {
            auto cefFrame = _renderClientAdapter->TryGetCefMainFrame();

            if (cefFrame != nullptr)
            {
                cefFrame->LoadString(StringUtils::ToNative(html), StringUtils::ToNative(url));
            }
        }

{'fraction_non_alphanumeric': 0.08351717617396785, 'fraction_numerical': 0.0025212732429877086, 'mean_word_length': 2.0840621963070944, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7646083', 'n_tokens_mistral': 1661, 'n_tokens_neox': 1598, 'n_words': 340}