<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;
using namespace System::Threading::Tasks;

namespace CefSharp
{
    private ref class ManagedCefBrowserAdapter : public DisposableResource
    {
        MCefRefPtr<RenderClientAdapter> _renderClientAdapter;
        BrowserProcessServiceHost^ _browserProcessServiceHost;
        IWebBrowserInternal^ _webBrowserInternal;
        String^ _address;
        JavascriptObjectRepository^ _javaScriptObjectRepository;
        
    protected:
        virtual void DoDispose(bool isDisposing) override
        {
            Close();

            _renderClientAdapter = nullptr;
            if (_browserProcessServiceHost != nullptr)
            {
                _browserProcessServiceHost->Close();
                _browserProcessServiceHost = nullptr;
            }

            _webBrowserInternal = nullptr;
            _address = nullptr;
            _javaScriptObjectRepository = nullptr;

            DisposableResource::DoDispose(isDisposing);
        };

    public:
        ManagedCefBrowserAdapter(IWebBrowserInternal^ webBrowserInternal)
        {
            _renderClientAdapter = new RenderClientAdapter(webBrowserInternal, gcnew Action<int>(this, &ManagedCefBrowserAdapter::OnAfterBrowserCreated));
            _webBrowserInternal = webBrowserInternal;
            _javaScriptObjectRepository = gcnew JavascriptObjectRepository();
        }

        void CreateOffscreenBrowser(BrowserSettings^ browserSettings)
        {
            HWND hwnd = HWND();
            CefWindowInfo window;
            window.SetAsWindowless(hwnd, 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()
        {<commit_msg>Fixed url load issue when assigning URL before browser is fully loaded<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;
using namespace System::Threading::Tasks;

namespace CefSharp
{
    private ref class ManagedCefBrowserAdapter : public DisposableResource
    {
        MCefRefPtr<RenderClientAdapter> _renderClientAdapter;
        BrowserProcessServiceHost^ _browserProcessServiceHost;
        IWebBrowserInternal^ _webBrowserInternal;
        String^ _address;
        JavascriptObjectRepository^ _javaScriptObjectRepository;
        
    protected:
        virtual void DoDispose(bool isDisposing) override
        {
            Close();

            _renderClientAdapter = nullptr;
            if (_browserProcessServiceHost != nullptr)
            {
                _browserProcessServiceHost->Close();
                _browserProcessServiceHost = nullptr;
            }

            _webBrowserInternal = nullptr;
            _address = nullptr;
            _javaScriptObjectRepository = nullptr;

            DisposableResource::DoDispose(isDisposing);
        };

    public:
        ManagedCefBrowserAdapter(IWebBrowserInternal^ webBrowserInternal)
        {
            _renderClientAdapter = new RenderClientAdapter(webBrowserInternal, gcnew Action<int>(this, &ManagedCefBrowserAdapter::OnAfterBrowserCreated));
            _webBrowserInternal = webBrowserInternal;
            _javaScriptObjectRepository = gcnew JavascriptObjectRepository();
        }

        void CreateOffscreenBrowser(BrowserSettings^ browserSettings)
        {
            HWND hwnd = HWND();
            CefWindowInfo window;
            window.SetAsWindowless(hwnd, TRUE);
			CefString addressNative = StringUtils::ToNative(_address);

            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()
        {
{'fraction_non_alphanumeric': 0.07380436921865774, 'fraction_numerical': 0.003148986419996064, 'mean_word_length': 2.8882938026013774, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '2479516', 'n_tokens_mistral': 1281, 'n_tokens_neox': 1231, 'n_words': 293}