Exemplo n.º 1
0
        /// <summary>
        /// Create a new browser window using the window parameters specified by
        /// |windowInfo|. All values will be copied internally and the actual window
        /// will be created on the UI thread. This method can be called on any browser
        /// process thread and will not block.
        /// </summary>
        public static void CreateBrowser(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings, string url)
        {
            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();

            fixed(char *url_ptr = url)
            {
                cef_string_t n_url     = new cef_string_t(url_ptr, url != null ? url.Length : 0);
                var          n_success = cef_browser_host_t.create_browser(n_windowInfo, n_client, &n_url, n_settings);

                if (n_success != 1)
                {
                    throw ExceptionBuilder.FailedToCreateBrowser();
                }
            }

            // TODO: free n_ structs ?
        }
Exemplo n.º 2
0
        private int on_before_browser(cef_extension_handler_t *self, cef_extension_t *extension, cef_browser_t *browser, cef_browser_t *active_browser, int index, cef_string_t *url, int active, cef_window_info_t *windowInfo, cef_client_t **client, cef_browser_settings_t *settings)
        {
            CheckSelf(self);

            var m_extension     = CefExtension.FromNative(extension);
            var m_browser       = CefBrowser.FromNativeOrNull(browser);
            var m_activeBrowser = CefBrowser.FromNativeOrNull(active_browser);
            var m_url           = cef_string_t.ToString(url);
            var m_active        = active != 0;
            var m_windowInfo    = CefWindowInfo.FromNative(windowInfo);
            var m_client        = CefClient.FromNative(*client);
            var m_settings      = new CefBrowserSettings(settings);

            var o_client = m_client;
            var cancel   = OnBeforeBrowser(m_extension, m_browser, m_activeBrowser, index, m_url, m_active, m_windowInfo, ref m_client, m_settings);

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

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

            return(cancel ? 1 : 0);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Open developer tools (DevTools) in its own browser. The DevTools browser
        /// will remain associated with this browser. If the DevTools browser is
        /// already open then it will be focused, in which case the |windowInfo|,
        /// |client| and |settings| parameters will be ignored. If |inspect_element_at|
        /// is non-empty then the element at the specified (x,y) location will be
        /// inspected. The |windowInfo| parameter will be ignored if this browser is
        /// wrapped in a CefBrowserView.
        /// </summary>
        public void ShowDevTools(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings browserSettings, CefPoint inspectElementAt)
        {
            var n_inspectElementAt = new cef_point_t(inspectElementAt.X, inspectElementAt.Y);

            cef_browser_host_t.show_dev_tools(_self, windowInfo.ToNative(), client.ToNative(), browserSettings.ToNative(),
                                              &n_inspectElementAt);
        }
        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, CefWindowOpenDisposition target_disposition, int user_gesture, 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_userGesture        = user_gesture != 0;
            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, target_disposition, m_userGesture, 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);
        }
Exemplo n.º 5
0
        /// <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 ?
        }
Exemplo n.º 6
0
        internal static CefClient FromNativeOrNull(cef_client_t *ptr)
        {
            CefClient value = null;
            bool      found;

            lock (_roots)
            {
                found = _roots.TryGetValue((IntPtr)ptr, out value);
            }
            return(found ? value : null);
        }
Exemplo n.º 7
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 )
        {
            var e = new BeforePopupEventArgs( frame, targetUrl, targetFrameName, popupFeatures, windowInfo, client, settings,
                     noJavascriptAccess );

            this.owner.OnBeforePopup( e );

            client = e.Client;
            noJavascriptAccess = e.NoJavascriptAccess;

            return e.Handled;
        }
Exemplo n.º 8
0
        public BeforePopupEventArgs(
			CefFrame frame,
			string targetUrl,
			string targetFrameName,
			CefPopupFeatures popupFeatures,
			CefWindowInfo windowInfo,
			CefClient client,
			CefBrowserSettings settings,
			bool noJavascriptAccess)
        {
            Frame = frame;
            TargetUrl = targetUrl;
            TargetFrameName = targetFrameName;
            PopupFeatures = popupFeatures;
            WindowInfo = windowInfo;
            Client = client;
            Settings = settings;
            NoJavascriptAccess = noJavascriptAccess;
        }
Exemplo n.º 9
0
        /// <summary>
        /// Create a new browser window using the window parameters specified by
        /// |windowInfo|. 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)
        {
            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();

            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);
                return CefBrowser.FromNative(n_browser);
            }

            // TODO: free n_ structs ?
        }
Exemplo n.º 10
0
        private int on_before_background_browser(cef_extension_handler_t *self, cef_extension_t *extension, cef_string_t *url, cef_client_t **client, cef_browser_settings_t *settings)
        {
            CheckSelf(self);

            var m_extension = CefExtension.FromNative(extension);
            var m_url       = cef_string_t.ToString(url);
            var m_client    = CefClient.FromNative(*client);
            var m_settings  = new CefBrowserSettings(settings);

            var o_client = m_client;
            var cancel   = OnBeforeBackgroundBrowser(m_extension, m_url, ref m_client, m_settings);

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

            m_settings.Dispose();

            return(cancel ? 1 : 0);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Create a new browser window using the window parameters specified by
        /// |windowInfo|. All values will be copied internally and the actual window
        /// will be created on the UI thread. If |request_context| is empty the
        /// global request context will be used. This method can be called on any
        /// browser process thread and will not block.
        /// </summary>
        public static void CreateBrowser(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_success = cef_browser_host_t.create_browser(n_windowInfo, n_client, &n_url, n_settings, n_requestContext);
                if (n_success != 1) throw ExceptionBuilder.FailedToCreateBrowser();
            }

            // TODO: free n_ structs ?
        }
Exemplo n.º 12
0
 public static CefBrowser CreateBrowserSync(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings, Uri url, CefRequestContext requestContext)
 {
     return(CreateBrowserSync(windowInfo, client, settings, url.ToString(), requestContext));
 }
Exemplo n.º 13
0
 public static CefBrowser CreateBrowserSync(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings, Uri url)
 {
     return CreateBrowserSync(windowInfo, client, settings, url.ToString());
 }
Exemplo n.º 14
0
 /// <summary>
 /// Open developer tools in its own window.
 /// </summary>
 public void ShowDevTools(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings browserSettings)
 {
     cef_browser_host_t.show_dev_tools(_self, windowInfo.ToNative(), client.ToNative(), browserSettings.ToNative());
 }
Exemplo n.º 15
0
 public static void CreateBrowser(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings)
 {
     CreateBrowser(windowInfo, client, settings, string.Empty, null);
 }
Exemplo n.º 16
0
 public static void CreateBrowser(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings, Uri url)
 {
     CreateBrowser(windowInfo, client, settings, url, null);
 }
Exemplo n.º 17
0
 public static CefBrowser CreateBrowserSync(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings)
 {
     return(CreateBrowserSync(windowInfo, client, settings, string.Empty));
 }
Exemplo n.º 18
0
 public static void CreateBrowser(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings, Uri url, CefRequestContext requestContext)
 {
     CreateBrowser(windowInfo, client, settings, url.ToString(), requestContext);
 }
Exemplo n.º 19
0
 /// <summary>
 /// Open developer tools in its own window.
 /// </summary>
 public void ShowDevTools(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings browserSettings)
 {
     cef_browser_host_t.show_dev_tools(_self, windowInfo.ToNative(), client.ToNative(), browserSettings.ToNative());
 }
Exemplo n.º 20
0
 public static CefBrowser CreateBrowserSync(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings)
 {
     return CreateBrowserSync(windowInfo, client, settings, string.Empty);
 }
Exemplo n.º 21
0
 public static CefBrowser CreateBrowserSync(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings, CefRequestContext requestContext)
 {
     return CreateBrowserSync(windowInfo, client, settings, string.Empty, requestContext);
 }
Exemplo n.º 22
0
 public static CefBrowser CreateBrowserSync(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings, Uri url, CefRequestContext requestContext)
 {
     return CreateBrowserSync(windowInfo, client, settings, url.ToString(), requestContext);
 }
Exemplo n.º 23
0
 /// <summary>
 /// Open developer tools in its own window. If |inspect_element_at| is non-
 /// empty the element at the specified (x,y) location will be inspected.
 /// </summary>
 public void ShowDevTools(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings browserSettings, CefPoint inspectElementAt)
 {
     var n_inspectElementAt = new cef_point_t(inspectElementAt.X, inspectElementAt.Y);
     cef_browser_host_t.show_dev_tools(_self, windowInfo.ToNative(), client.ToNative(), browserSettings.ToNative(),
         &n_inspectElementAt);
 }
Exemplo n.º 24
0
 public static CefBrowser CreateBrowserSync(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings, Uri url)
 {
     return(CreateBrowserSync(windowInfo, client, settings, url, null));
 }
Exemplo n.º 25
0
 public static CefBrowser CreateBrowserSync(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings, CefRequestContext requestContext)
 {
     return(CreateBrowserSync(windowInfo, client, settings, string.Empty, requestContext));
 }
Exemplo n.º 26
0
 /// <summary>
 /// Called when an extension API (e.g. chrome.tabs.create) requests creation of
 /// a new browser. |extension| and |browser| are the source of the API call.
 /// |active_browser| may optionally be specified via the windowId property or
 /// returned via the GetActiveBrowser() callback and provides the default
 /// |client| and |settings| values for the new browser. |index| is the position
 /// value optionally specified via the index property. |url| is the URL that
 /// will be loaded in the browser. |active| is true if the new browser should
 /// be active when opened.  To allow creation of the browser optionally modify
 /// |windowInfo|, |client| and |settings| and return false. To cancel creation
 /// of the browser return true. Successful creation will be indicated by a call
 /// to CefLifeSpanHandler::OnAfterCreated. Any modifications to |windowInfo|
 /// will be ignored if |active_browser| is wrapped in a CefBrowserView.
 /// </summary>
 protected virtual bool OnBeforeBrowser(CefExtension extension, CefBrowser browser, CefBrowser activeBrowser, int index, string url, bool active, CefWindowInfo windowInfo, ref CefClient client, CefBrowserSettings settings)
 {
     return(false);
 }
Exemplo n.º 27
0
 /// <summary>
 /// Returns the client for this browser.
 /// </summary>
 public CefClient GetClient()
 {
     return(CefClient.FromNative(
                cef_browser_host_t.get_client(_self)
                ));
 }
Exemplo n.º 28
0
 /// <summary>
 /// Called when an extension needs a browser to host a background script
 /// specified via the "background" manifest key. The browser will have no
 /// visible window and cannot be displayed. |extension| is the extension that
 /// is loading the background script. |url| is an internally generated
 /// reference to an HTML page that will be used to load the background script
 /// via a &lt;script&gt; src attribute. To allow creation of the browser optionally
 /// modify |client| and |settings| and return false. To cancel creation of the
 /// browser (and consequently cancel load of the background script) return
 /// true. Successful creation will be indicated by a call to
 /// CefLifeSpanHandler::OnAfterCreated, and CefBrowserHost::IsBackgroundHost
 /// will return true for the resulting browser. See
 /// https://developer.chrome.com/extensions/event_pages for more information
 /// about extension background script usage.
 /// </summary>
 protected virtual bool OnBeforeBackgroundBrowser(CefExtension extension, string url, ref CefClient client, CefBrowserSettings settings)
 {
     return(false);
 }
Exemplo n.º 29
0
 public static void CreateBrowser(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings, Uri url, CefRequestContext requestContext)
 {
     CreateBrowser(windowInfo, client, settings, url.ToString(), requestContext);
 }
Exemplo n.º 30
0
 public static void CreateBrowser(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings)
 {
     CreateBrowser(windowInfo, client, settings, string.Empty, null);
 }
Exemplo n.º 31
0
 public static void CreateBrowser(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings, CefRequestContext requestContext)
 {
     CreateBrowser(windowInfo, client, settings, string.Empty, requestContext);
 }
Exemplo n.º 32
0
 public static CefBrowser CreateBrowserSync(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings, string url)
 {
     return CreateBrowserSync(windowInfo, client, settings, url, null);
 }
Exemplo n.º 33
0
 public static void CreateBrowser(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings, Uri url)
 {
     CreateBrowser(windowInfo, client, settings, url, null);
 }
Exemplo n.º 34
0
 /// <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;
 }
Exemplo n.º 35
0
 /// <summary>
 /// Called on the IO thread before a new popup browser is created. The
 /// |browser| and |frame| values represent the source of the popup request. The
 /// |target_url| and |target_frame_name| values indicate where the popup
 /// browser should navigate and may be empty if not specified with the request.
 /// The |target_disposition| value indicates where the user intended to open
 /// the popup (e.g. current tab, new tab, etc). The |user_gesture| value will
 /// be true if the popup was opened via explicit user gesture (e.g. clicking a
 /// link) or false if the popup opened automatically (e.g. via the
 /// DomContentLoaded event). The |popupFeatures| structure contains additional
 /// information about the requested popup window. To allow creation of the
 /// popup browser optionally modify |windowInfo|, |client|, |settings| and
 /// |no_javascript_access| and return false. To cancel creation of the popup
 /// browser return true. The |client| and |settings| values will default to the
 /// source browser's values. If the |no_javascript_access| value is set to
 /// false the new browser will not be scriptable and may not be hosted in the
 /// same renderer process as the source browser. Any modifications to
 /// |windowInfo| will be ignored if the parent browser is wrapped in a
 /// CefBrowserView.
 /// </summary>
 protected virtual bool OnBeforePopup(CefBrowser browser, CefFrame frame, string targetUrl, string targetFrameName, CefWindowOpenDisposition targetDisposition, bool userGesture, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, ref CefClient client, CefBrowserSettings settings, ref bool noJavascriptAccess)
 {
     return(false);
 }
Exemplo n.º 36
0
 public static void CreateBrowser(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings, CefRequestContext requestContext)
 {
     CreateBrowser(windowInfo, client, settings, string.Empty, requestContext);
 }