private int on_before_popup(cef_life_span_handler_t* self, cef_browser_t* browser, cef_frame_t* frame, cef_string_t* target_url, cef_string_t* target_frame_name, cef_popup_features_t* popupFeatures, cef_window_info_t* windowInfo, cef_client_t** client, cef_browser_settings_t* settings, int* no_javascript_access)
        {
            CheckSelf(self);

            var m_browser = CefBrowser.FromNative(browser);
            var m_frame = CefFrame.FromNative(frame);
            var m_targetUrl = cef_string_t.ToString(target_url);
            var m_targetFrameName = cef_string_t.ToString(target_frame_name);
            var m_popupFeatures = new CefPopupFeatures(popupFeatures);
            var m_windowInfo = CefWindowInfo.FromNative(windowInfo);
            var m_client = CefClient.FromNative(*client);
            var m_settings = new CefBrowserSettings(settings);
            var m_noJavascriptAccess = (*no_javascript_access) != 0;

            var o_client = m_client;
            var result = OnBeforePopup(m_browser, m_frame, m_targetUrl, m_targetFrameName, m_popupFeatures, m_windowInfo, ref m_client, m_settings, ref m_noJavascriptAccess);

            if ((object)o_client != m_client && m_client != null)
            {
                *client = m_client.ToNative();
            }

            *no_javascript_access = m_noJavascriptAccess ? 1 : 0;

            m_popupFeatures.Dispose();
            m_windowInfo.Dispose();
            m_settings.Dispose();

            return result ? 1 : 0;
        }
 protected override bool OnBeforePopup(CefBrowser browser, CefFrame frame, string targetUrl, string targetFrameName, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, ref CefClient client, CefBrowserSettings settings, ref bool noJavascriptAccess)
 {
     bool res = false;
     if (!string.IsNullOrEmpty(targetUrl))
     {
         if (webBrowser.selfRequest != null)
         {
             CefRequest req = CefRequest.Create();
             req.FirstPartyForCookies = webBrowser.selfRequest.FirstPartyForCookies;
             req.Options = webBrowser.selfRequest.Options;
             /*CefPostData postData = CefPostData.Create();
             CefPostDataElement element = CefPostDataElement.Create();
             int index = targetUrl.IndexOf("?");
             string url = targetUrl.Substring(0, index);
             string data = targetUrl.Substring(index + 1);
             byte[] bytes = Encoding.UTF8.GetBytes(data);
             element.SetToBytes(bytes);
             postData.Add(element);
             */
             System.Collections.Specialized.NameValueCollection h = new System.Collections.Specialized.NameValueCollection();
             h.Add("Content-Type", "application/x-www-form-urlencoded");
             req.Set(targetUrl, webBrowser.selfRequest.Method, null, webBrowser.selfRequest.GetHeaderMap());
             webBrowser.selfRequest = req;
         }
         //webBrowser.selfRequest.Set(targetUrl, webBrowser.selfRequest.Method, webBrowser.selfRequest.PostData, webBrowser.selfRequest.GetHeaderMap());
         res = webBrowser.OnNewWindow(targetUrl);
         if (res)
             return res;
     }
     res = base.OnBeforePopup(browser, frame, targetUrl, targetFrameName, popupFeatures, windowInfo, ref client, settings, ref noJavascriptAccess);
     return res;
 }
        private void CreateBrowser()
        {
            CefWindowInfo windowInfo = CefWindowInfo.Create();
            windowInfo.SetAsChild(Handle, new CefRectangle { X = 0, Y = 0, Width = Width, Height = Height });
            if (client == null)
            {
                client = new ClientBrowser(this);
            }
            var settings = new CefBrowserSettings() { };
            settings.AcceleratedCompositing = CefState.Enabled;
            settings.ApplicationCache = CefState.Enabled;
            settings.AuthorAndUserStyles = CefState.Enabled;
            settings.CaretBrowsing = CefState.Enabled;
            settings.Databases = CefState.Enabled;
            settings.FileAccessFromFileUrls = CefState.Enabled;
            settings.ImageLoading = CefState.Enabled;
            settings.ImageShrinkStandaloneToFit = CefState.Enabled;
            settings.Java = CefState.Enabled;
            settings.JavaScript = CefState.Enabled; ;
            settings.JavaScriptAccessClipboard = CefState.Enabled;
            settings.JavaScriptCloseWindows = CefState.Enabled;
            settings.JavaScriptDomPaste = CefState.Enabled; ;
            settings.JavaScriptOpenWindows = CefState.Enabled;
            settings.LocalStorage = CefState.Enabled; ;
            settings.Plugins = CefState.Enabled; ;
            settings.RemoteFonts = CefState.Enabled;
            settings.TabToLinks = CefState.Enabled; ;
            settings.TextAreaResize = CefState.Enabled;
            settings.UniversalAccessFromFileUrls = CefState.Enabled;
            settings.WebGL = CefState.Enabled;
            settings.WebSecurity = CefState.Enabled;

            CefBrowserHost.CreateBrowser(windowInfo, client, settings, browserSettings.DefaultUrl);
            
        }
        /// <summary>
        /// Create a new browser window using the window parameters specified by
        /// |windowInfo|. If |request_context| is empty the global request context
        /// will be used. This method can only be called on the browser process UI
        /// thread.
        /// </summary>
        public static CefBrowser CreateBrowserSync(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings, string url, CefRequestContext requestContext)
        {
            if (windowInfo == null) throw new ArgumentNullException("windowInfo");
            if (client == null) throw new ArgumentNullException("client");
            if (settings == null) throw new ArgumentNullException("settings");
            // TODO: [ApiUsage] if windowInfo.WindowRenderingDisabled && client doesn't provide RenderHandler implementation -> throw exception

            var n_windowInfo = windowInfo.ToNative();
            var n_client = client.ToNative();
            var n_settings = settings.ToNative();
            var n_requestContext = requestContext != null ? requestContext.ToNative() : null;

            fixed (char* url_ptr = url)
            {
                cef_string_t n_url = new cef_string_t(url_ptr, url != null ? url.Length : 0);
                var n_browser = cef_browser_host_t.create_browser_sync(n_windowInfo, n_client, &n_url, n_settings, n_requestContext);
                return CefBrowser.FromNative(n_browser);
            }

            // TODO: free n_ structs ?
        }
 public static CefBrowser CreateBrowserSync(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings, string url)
 {
     return CreateBrowserSync(windowInfo, client, settings, url, null);
 }
 public static void CreateBrowser(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings)
 {
     CreateBrowser(windowInfo, client, settings, string.Empty, null);
 }
 public static void CreateBrowser(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings, CefRequestContext requestContext)
 {
     CreateBrowser(windowInfo, client, settings, string.Empty, requestContext);
 }
 public static void CreateBrowser(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings, Uri url)
 {
     CreateBrowser(windowInfo, client, settings, url, null);
 }
 public static void CreateBrowser(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings, Uri url, CefRequestContext requestContext)
 {
     CreateBrowser(windowInfo, client, settings, url.ToString(), requestContext);
 }
 public static CefBrowser CreateBrowserSync(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings)
 {
     return CreateBrowserSync(windowInfo, client, settings, string.Empty);
 }
 public static CefBrowser CreateBrowserSync(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings, CefRequestContext requestContext)
 {
     return CreateBrowserSync(windowInfo, client, settings, string.Empty, requestContext);
 }
 public static CefBrowser CreateBrowserSync(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings, Uri url, CefRequestContext requestContext)
 {
     return CreateBrowserSync(windowInfo, client, settings, url.ToString(), requestContext);
 }
 /// <summary>
 /// Called on the IO thread before a new popup window is created. The |browser|
 /// and |frame| parameters represent the source of the popup request. The
 /// |target_url| and |target_frame_name| values may be empty if none were
 /// specified with the request. The |popupFeatures| structure contains
 /// information about the requested popup window. To allow creation of the
 /// popup window optionally modify |windowInfo|, |client|, |settings| and
 /// |no_javascript_access| and return false. To cancel creation of the popup
 /// window return true. The |client| and |settings| values will default to the
 /// source browser's values. The |no_javascript_access| value indicates whether
 /// the new browser window should be scriptable and in the same process as the
 /// source browser.
 /// </summary>
 protected virtual bool OnBeforePopup(CefBrowser browser, CefFrame frame, string targetUrl, string targetFrameName, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, ref CefClient client, CefBrowserSettings settings, ref bool noJavascriptAccess)
 {
     return false;
 }