diff --git a/cef.gyp b/cef.gyp index 5ca6b1558..46d8014d5 100644 --- a/cef.gyp +++ b/cef.gyp @@ -770,6 +770,8 @@ 'libcef/browser/devtools_delegate.h', 'libcef/browser/devtools_scheme_handler.cc', 'libcef/browser/devtools_scheme_handler.h', + 'libcef/browser/download_item_impl.cc', + 'libcef/browser/download_item_impl.h', 'libcef/browser/download_manager_delegate.cc', 'libcef/browser/download_manager_delegate.h', 'libcef/browser/frame_host_impl.cc', @@ -804,6 +806,8 @@ 'libcef/browser/url_request_context_getter.h', 'libcef/browser/url_request_context_getter_proxy.cc', 'libcef/browser/url_request_context_getter_proxy.h', + 'libcef/browser/url_request_context_proxy.cc', + 'libcef/browser/url_request_context_proxy.h', 'libcef/browser/url_request_interceptor.cc', 'libcef/browser/url_request_interceptor.h', 'libcef/browser/web_plugin_impl.cc', diff --git a/cef_paths.gypi b/cef_paths.gypi index fadb0b106..a450bd61c 100644 --- a/cef_paths.gypi +++ b/cef_paths.gypi @@ -22,6 +22,8 @@ 'include/cef_cookie.h', 'include/cef_display_handler.h', 'include/cef_dom.h', + 'include/cef_download_handler.h', + 'include/cef_download_item.h', 'include/cef_focus_handler.h', 'include/cef_frame.h', 'include/cef_geolocation_handler.h', @@ -64,6 +66,8 @@ 'include/capi/cef_cookie_capi.h', 'include/capi/cef_display_handler_capi.h', 'include/capi/cef_dom_capi.h', + 'include/capi/cef_download_handler_capi.h', + 'include/capi/cef_download_item_capi.h', 'include/capi/cef_focus_handler_capi.h', 'include/capi/cef_frame_capi.h', 'include/capi/cef_geolocation_handler_capi.h', @@ -100,6 +104,8 @@ 'libcef_dll/ctocpp/app_ctocpp.h', 'libcef_dll/cpptoc/auth_callback_cpptoc.cc', 'libcef_dll/cpptoc/auth_callback_cpptoc.h', + 'libcef_dll/cpptoc/before_download_callback_cpptoc.cc', + 'libcef_dll/cpptoc/before_download_callback_cpptoc.h', 'libcef_dll/cpptoc/binary_value_cpptoc.cc', 'libcef_dll/cpptoc/binary_value_cpptoc.h', 'libcef_dll/cpptoc/browser_cpptoc.cc', @@ -136,6 +142,12 @@ 'libcef_dll/cpptoc/dictionary_value_cpptoc.h', 'libcef_dll/ctocpp/display_handler_ctocpp.cc', 'libcef_dll/ctocpp/display_handler_ctocpp.h', + 'libcef_dll/ctocpp/download_handler_ctocpp.cc', + 'libcef_dll/ctocpp/download_handler_ctocpp.h', + 'libcef_dll/cpptoc/download_item_cpptoc.cc', + 'libcef_dll/cpptoc/download_item_cpptoc.h', + 'libcef_dll/cpptoc/download_item_callback_cpptoc.cc', + 'libcef_dll/cpptoc/download_item_callback_cpptoc.h', 'libcef_dll/ctocpp/focus_handler_ctocpp.cc', 'libcef_dll/ctocpp/focus_handler_ctocpp.h', 'libcef_dll/cpptoc/frame_cpptoc.cc', @@ -222,6 +234,8 @@ 'libcef_dll/cpptoc/app_cpptoc.h', 'libcef_dll/ctocpp/auth_callback_ctocpp.cc', 'libcef_dll/ctocpp/auth_callback_ctocpp.h', + 'libcef_dll/ctocpp/before_download_callback_ctocpp.cc', + 'libcef_dll/ctocpp/before_download_callback_ctocpp.h', 'libcef_dll/ctocpp/binary_value_ctocpp.cc', 'libcef_dll/ctocpp/binary_value_ctocpp.h', 'libcef_dll/ctocpp/browser_ctocpp.cc', @@ -258,6 +272,12 @@ 'libcef_dll/ctocpp/dictionary_value_ctocpp.h', 'libcef_dll/cpptoc/display_handler_cpptoc.cc', 'libcef_dll/cpptoc/display_handler_cpptoc.h', + 'libcef_dll/cpptoc/download_handler_cpptoc.cc', + 'libcef_dll/cpptoc/download_handler_cpptoc.h', + 'libcef_dll/ctocpp/download_item_ctocpp.cc', + 'libcef_dll/ctocpp/download_item_ctocpp.h', + 'libcef_dll/ctocpp/download_item_callback_ctocpp.cc', + 'libcef_dll/ctocpp/download_item_callback_ctocpp.h', 'libcef_dll/cpptoc/focus_handler_cpptoc.cc', 'libcef_dll/cpptoc/focus_handler_cpptoc.h', 'libcef_dll/ctocpp/frame_ctocpp.cc', diff --git a/include/capi/cef_client_capi.h b/include/capi/cef_client_capi.h index 7bb4f4510..f3fd271fb 100644 --- a/include/capi/cef_client_capi.h +++ b/include/capi/cef_client_capi.h @@ -67,6 +67,13 @@ typedef struct _cef_client_t { struct _cef_display_handler_t* (CEF_CALLBACK *get_display_handler)( struct _cef_client_t* self); + /// + // Return the handler for download events. If no handler is returned downloads + // will not be allowed. + /// + struct _cef_download_handler_t* (CEF_CALLBACK *get_download_handler)( + struct _cef_client_t* self); + /// // Return the handler for focus events. /// diff --git a/include/capi/cef_download_handler_capi.h b/include/capi/cef_download_handler_capi.h new file mode 100644 index 000000000..ef0821c27 --- /dev/null +++ b/include/capi/cef_download_handler_capi.h @@ -0,0 +1,124 @@ +// Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#ifndef CEF_INCLUDE_CAPI_CEF_DOWNLOAD_HANDLER_CAPI_H_ +#define CEF_INCLUDE_CAPI_CEF_DOWNLOAD_HANDLER_CAPI_H_ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include "include/capi/cef_base_capi.h" + + +/// +// Callback structure used to asynchronously continue a download. +/// +typedef struct _cef_before_download_callback_t { + /// + // Base structure. + /// + cef_base_t base; + + /// + // Call to continue the download. Set |download_path| to the full file path + // for the download including the file name or leave blank to use the + // suggested name and the default temp directory. Set |show_dialog| to true + // (1) if you do wish to show the default "Save As" dialog. + /// + void (CEF_CALLBACK *cont)(struct _cef_before_download_callback_t* self, + const cef_string_t* download_path, int show_dialog); +} cef_before_download_callback_t; + + +/// +// Callback structure used to asynchronously cancel a download. +/// +typedef struct _cef_download_item_callback_t { + /// + // Base structure. + /// + cef_base_t base; + + /// + // Call to cancel the download. + /// + void (CEF_CALLBACK *cancel)(struct _cef_download_item_callback_t* self); +} cef_download_item_callback_t; + + +/// +// Structure used to handle file downloads. The functions of this structure will +// called on the browser process UI thread. +/// +typedef struct _cef_download_handler_t { + /// + // Base structure. + /// + cef_base_t base; + + /// + // Called before a download begins. |suggested_name| is the suggested name for + // the download file. By default the download will be canceled. Execute + // |callback| either asynchronously or in this function to continue the + // download if desired. Do not keep a reference to |download_item| outside of + // this function. + /// + void (CEF_CALLBACK *on_before_download)(struct _cef_download_handler_t* self, + struct _cef_browser_t* browser, + struct _cef_download_item_t* download_item, + const cef_string_t* suggested_name, + struct _cef_before_download_callback_t* callback); + + /// + // Called when a download's status or progress information has been updated. + // Execute |callback| either asynchronously or in this function to cancel the + // download if desired. Do not keep a reference to |download_item| outside of + // this function. + /// + void (CEF_CALLBACK *on_download_updated)(struct _cef_download_handler_t* self, + struct _cef_browser_t* browser, + struct _cef_download_item_t* download_item, + struct _cef_download_item_callback_t* callback); +} cef_download_handler_t; + + +#ifdef __cplusplus +} +#endif + +#endif // CEF_INCLUDE_CAPI_CEF_DOWNLOAD_HANDLER_CAPI_H_ diff --git a/include/capi/cef_download_item_capi.h b/include/capi/cef_download_item_capi.h new file mode 100644 index 000000000..c5ac8b5c5 --- /dev/null +++ b/include/capi/cef_download_item_capi.h @@ -0,0 +1,162 @@ +// Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#ifndef CEF_INCLUDE_CAPI_CEF_DOWNLOAD_ITEM_CAPI_H_ +#define CEF_INCLUDE_CAPI_CEF_DOWNLOAD_ITEM_CAPI_H_ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include "include/capi/cef_base_capi.h" + + +/// +// Structure used to represent a download item. +/// +typedef struct _cef_download_item_t { + /// + // Base structure. + /// + cef_base_t base; + + /// + // Returns true (1) if this object is valid. Do not call any other functions + // if this function returns false (0). + /// + int (CEF_CALLBACK *is_valid)(struct _cef_download_item_t* self); + + /// + // Returns true (1) if the download is in progress. + /// + int (CEF_CALLBACK *is_in_progress)(struct _cef_download_item_t* self); + + /// + // Returns true (1) if the download is complete. + /// + int (CEF_CALLBACK *is_complete)(struct _cef_download_item_t* self); + + /// + // Returns true (1) if the download has been canceled or interrupted. + /// + int (CEF_CALLBACK *is_canceled)(struct _cef_download_item_t* self); + + /// + // Returns a simple speed estimate in bytes/s. + /// + int64 (CEF_CALLBACK *get_current_speed)(struct _cef_download_item_t* self); + + /// + // Returns the rough percent complete or -1 if the receive total size is + // unknown. + /// + int (CEF_CALLBACK *get_percent_complete)(struct _cef_download_item_t* self); + + /// + // Returns the total number of bytes. + /// + int64 (CEF_CALLBACK *get_total_bytes)(struct _cef_download_item_t* self); + + /// + // Returns the number of received bytes. + /// + int64 (CEF_CALLBACK *get_received_bytes)(struct _cef_download_item_t* self); + + /// + // Returns the time that the download started. + /// + cef_time_t (CEF_CALLBACK *get_start_time)(struct _cef_download_item_t* self); + + /// + // Returns the time that the download ended. + /// + cef_time_t (CEF_CALLBACK *get_end_time)(struct _cef_download_item_t* self); + + /// + // Returns the full path to the downloaded or downloading file. + /// + // The resulting string must be freed by calling cef_string_userfree_free(). + cef_string_userfree_t (CEF_CALLBACK *get_full_path)( + struct _cef_download_item_t* self); + + /// + // Returns the unique identifier for this download. + /// + int32 (CEF_CALLBACK *get_id)(struct _cef_download_item_t* self); + + /// + // Returns the URL. + /// + // The resulting string must be freed by calling cef_string_userfree_free(). + cef_string_userfree_t (CEF_CALLBACK *get_url)( + struct _cef_download_item_t* self); + + /// + // Returns the suggested file name. + /// + // The resulting string must be freed by calling cef_string_userfree_free(). + cef_string_userfree_t (CEF_CALLBACK *get_suggested_file_name)( + struct _cef_download_item_t* self); + + /// + // Returns the content disposition. + /// + // The resulting string must be freed by calling cef_string_userfree_free(). + cef_string_userfree_t (CEF_CALLBACK *get_content_disposition)( + struct _cef_download_item_t* self); + + /// + // Returns the mime type. + /// + // The resulting string must be freed by calling cef_string_userfree_free(). + cef_string_userfree_t (CEF_CALLBACK *get_mime_type)( + struct _cef_download_item_t* self); + + /// + // Returns the referrer character set. + /// + // The resulting string must be freed by calling cef_string_userfree_free(). + cef_string_userfree_t (CEF_CALLBACK *get_referrer_charset)( + struct _cef_download_item_t* self); +} cef_download_item_t; + + +#ifdef __cplusplus +} +#endif + +#endif // CEF_INCLUDE_CAPI_CEF_DOWNLOAD_ITEM_CAPI_H_ diff --git a/include/cef_client.h b/include/cef_client.h index 4afaead78..2614fc39a 100644 --- a/include/cef_client.h +++ b/include/cef_client.h @@ -41,6 +41,7 @@ #include "include/cef_base.h" #include "include/cef_context_menu_handler.h" #include "include/cef_display_handler.h" +#include "include/cef_download_handler.h" #include "include/cef_focus_handler.h" #include "include/cef_geolocation_handler.h" #include "include/cef_jsdialog_handler.h" @@ -73,6 +74,15 @@ class CefClient : public virtual CefBase { return NULL; } + /// + // Return the handler for download events. If no handler is returned downloads + // will not be allowed. + /// + /*--cef()--*/ + virtual CefRefPtr GetDownloadHandler() { + return NULL; + } + /// // Return the handler for focus events. /// diff --git a/include/cef_download_handler.h b/include/cef_download_handler.h new file mode 100644 index 000000000..77a2384fc --- /dev/null +++ b/include/cef_download_handler.h @@ -0,0 +1,111 @@ +// Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// The contents of this file must follow a specific format in order to +// support the CEF translator tool. See the translator.README.txt file in the +// tools directory for more information. +// + +#ifndef CEF_INCLUDE_CEF_DOWNLOAD_HANDLER_H_ +#define CEF_INCLUDE_CEF_DOWNLOAD_HANDLER_H_ +#pragma once + +#include "include/cef_base.h" +#include "include/cef_browser.h" +#include "include/cef_download_item.h" + + +/// +// Callback interface used to asynchronously continue a download. +/// +/*--cef(source=library)--*/ +class CefBeforeDownloadCallback : public virtual CefBase { + public: + /// + // Call to continue the download. Set |download_path| to the full file path + // for the download including the file name or leave blank to use the + // suggested name and the default temp directory. Set |show_dialog| to true + // if you do wish to show the default "Save As" dialog. + /// + /*--cef(capi_name=cont)--*/ + virtual void Continue(const CefString& download_path, bool show_dialog) =0; +}; + + +/// +// Callback interface used to asynchronously cancel a download. +/// +/*--cef(source=library)--*/ +class CefDownloadItemCallback : public virtual CefBase { + public: + /// + // Call to cancel the download. + /// + /*--cef()--*/ + virtual void Cancel() =0; +}; + + +/// +// Class used to handle file downloads. The methods of this class will called +// on the browser process UI thread. +/// +/*--cef(source=client)--*/ +class CefDownloadHandler : public virtual CefBase { + public: + /// + // Called before a download begins. |suggested_name| is the suggested name for + // the download file. By default the download will be canceled. Execute + // |callback| either asynchronously or in this method to continue the download + // if desired. Do not keep a reference to |download_item| outside of this + // method. + /// + /*--cef()--*/ + virtual void OnBeforeDownload( + CefRefPtr browser, + CefRefPtr download_item, + const CefString& suggested_name, + CefRefPtr callback) =0; + + /// + // Called when a download's status or progress information has been updated. + // Execute |callback| either asynchronously or in this method to cancel the + // download if desired. Do not keep a reference to |download_item| outside of + // this method. + /// + /*--cef()--*/ + virtual void OnDownloadUpdated( + CefRefPtr browser, + CefRefPtr download_item, + CefRefPtr callback) {} +}; + +#endif // CEF_INCLUDE_CEF_DOWNLOAD_HANDLER_H_ diff --git a/include/cef_download_item.h b/include/cef_download_item.h new file mode 100644 index 000000000..01988bfd5 --- /dev/null +++ b/include/cef_download_item.h @@ -0,0 +1,154 @@ +// Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// The contents of this file must follow a specific format in order to +// support the CEF translator tool. See the translator.README.txt file in the +// tools directory for more information. +// + +#ifndef CEF_INCLUDE_CEF_DOWNLOAD_ITEM_H_ +#define CEF_INCLUDE_CEF_DOWNLOAD_ITEM_H_ +#pragma once + +#include "include/cef_base.h" + +/// +// Class used to represent a download item. +/// +/*--cef(source=library)--*/ +class CefDownloadItem : public virtual CefBase { + public: + /// + // Returns true if this object is valid. Do not call any other methods if this + // function returns false. + /// + /*--cef()--*/ + virtual bool IsValid() =0; + + /// + // Returns true if the download is in progress. + /// + /*--cef()--*/ + virtual bool IsInProgress() =0; + + /// + // Returns true if the download is complete. + /// + /*--cef()--*/ + virtual bool IsComplete() =0; + + /// + // Returns true if the download has been canceled or interrupted. + /// + /*--cef()--*/ + virtual bool IsCanceled() =0; + + /// + // Returns a simple speed estimate in bytes/s. + /// + /*--cef()--*/ + virtual int64 GetCurrentSpeed() =0; + + /// + // Returns the rough percent complete or -1 if the receive total size is + // unknown. + /// + /*--cef()--*/ + virtual int GetPercentComplete() =0; + + /// + // Returns the total number of bytes. + /// + /*--cef()--*/ + virtual int64 GetTotalBytes() =0; + + /// + // Returns the number of received bytes. + /// + /*--cef()--*/ + virtual int64 GetReceivedBytes() =0; + + /// + // Returns the time that the download started. + /// + /*--cef()--*/ + virtual CefTime GetStartTime() =0; + + /// + // Returns the time that the download ended. + /// + /*--cef()--*/ + virtual CefTime GetEndTime() =0; + + /// + // Returns the full path to the downloaded or downloading file. + /// + /*--cef()--*/ + virtual CefString GetFullPath() =0; + + /// + // Returns the unique identifier for this download. + /// + /*--cef()--*/ + virtual int32 GetId() =0; + + /// + // Returns the URL. + /// + /*--cef()--*/ + virtual CefString GetURL() =0; + + /// + // Returns the suggested file name. + /// + /*--cef()--*/ + virtual CefString GetSuggestedFileName() =0; + + /// + // Returns the content disposition. + /// + /*--cef()--*/ + virtual CefString GetContentDisposition() =0; + + /// + // Returns the mime type. + /// + /*--cef()--*/ + virtual CefString GetMimeType() =0; + + /// + // Returns the referrer character set. + /// + /*--cef()--*/ + virtual CefString GetReferrerCharset() =0; +}; + +#endif // CEF_INCLUDE_CEF_DOWNLOAD_ITEM_H_ diff --git a/libcef/browser/browser_context.cc b/libcef/browser/browser_context.cc index dcfb56951..56e53d58e 100644 --- a/libcef/browser/browser_context.cc +++ b/libcef/browser/browser_context.cc @@ -181,12 +181,14 @@ CefBrowserContext::CefBrowserContext() { } CefBrowserContext::~CefBrowserContext() { - if (download_manager_.get()) - download_manager_->Shutdown(); + // Clear the download manager delegate here because otherwise we'll crash + // when it's accessed from the content::BrowserContext destructor. + if (download_manager_delegate_.get()) + BrowserContext::GetDownloadManager(this)->SetDelegate(NULL); if (resource_context_.get()) { BrowserThread::DeleteSoon( - BrowserThread::IO, FROM_HERE, resource_context_.release()); + BrowserThread::IO, FROM_HERE, resource_context_.release()); } } @@ -200,6 +202,8 @@ bool CefBrowserContext::IsOffTheRecord() const { content::DownloadManagerDelegate* CefBrowserContext::GetDownloadManagerDelegate() { + DCHECK(!download_manager_delegate_.get()); + download_manager_delegate_ = new CefDownloadManagerDelegate(); return download_manager_delegate_.get(); } diff --git a/libcef/browser/browser_context.h b/libcef/browser/browser_context.h index 3367e680c..771f59fea 100644 --- a/libcef/browser/browser_context.h +++ b/libcef/browser/browser_context.h @@ -14,11 +14,11 @@ namespace content { class DownloadManagerDelegate; -class ResourceContext; class SpeechRecognitionPreferences; } class CefDownloadManagerDelegate; +class CefResourceContext; class CefBrowserContext : public content::BrowserContext { public: @@ -43,9 +43,8 @@ class CefBrowserContext : public content::BrowserContext { private: - scoped_ptr resource_context_; + scoped_ptr resource_context_; scoped_refptr download_manager_delegate_; - scoped_refptr download_manager_; scoped_refptr url_request_getter_; scoped_refptr geolocation_permission_context_; diff --git a/libcef/browser/browser_host_impl.cc b/libcef/browser/browser_host_impl.cc index 56d8284eb..6317296ed 100644 --- a/libcef/browser/browser_host_impl.cc +++ b/libcef/browser/browser_host_impl.cc @@ -13,6 +13,8 @@ #include "libcef/browser/devtools_delegate.h" #include "libcef/browser/navigate_params.h" #include "libcef/browser/thread_util.h" +#include "libcef/browser/url_request_context_getter.h" +#include "libcef/browser/url_request_context_getter_proxy.h" #include "libcef/common/cef_messages.h" #include "libcef/common/http_header_utils.h" #include "libcef/common/main_delegate.h" @@ -600,7 +602,8 @@ net::URLRequestContextGetter* CefBrowserHostImpl::GetRequestContext() { if (!request_context_proxy_) { request_context_proxy_ = new CefURLRequestContextGetterProxy(this, - _Context->browser_context()->GetRequestContext()); + static_cast( + _Context->browser_context()->GetRequestContext())); } return request_context_proxy_.get(); } @@ -1128,19 +1131,13 @@ void CefBrowserHostImpl::RequestMediaAccessPermission( void CefBrowserHostImpl::RenderViewCreated( content::RenderViewHost* render_view_host) { - base::AutoLock lock_scope(state_lock_); + SetRenderViewHost(render_view_host); +} - render_view_id_ = render_view_host->GetRoutingID(); - render_process_id_ = render_view_host->GetProcess()->GetID(); - - // Update the DevTools URLs, if any. - CefDevToolsDelegate* devtools_delegate = _Context->devtools_delegate(); - if (devtools_delegate) { - devtools_url_http_ = devtools_delegate->GetDevToolsURL(render_view_host, - true); - devtools_url_chrome_ = devtools_delegate->GetDevToolsURL(render_view_host, - false); - } +void CefBrowserHostImpl::RenderViewDeleted( + content::RenderViewHost* render_view_host) { + registrar_->Remove(this, content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE, + content::Source(render_view_host)); } void CefBrowserHostImpl::RenderViewReady() { @@ -1368,8 +1365,8 @@ CefBrowserHostImpl::CefBrowserHostImpl(const CefWindowInfo& window_info, settings_(settings), client_(client), opener_(opener), - render_process_id_(web_contents->GetRenderProcessHost()->GetID()), - render_view_id_(routing_id()), + render_process_id_(0), + render_view_id_(0), unique_id_(0), received_page_title_(false), is_loading_(false), @@ -1387,21 +1384,35 @@ CefBrowserHostImpl::CefBrowserHostImpl(const CefWindowInfo& window_info, registrar_.reset(new content::NotificationRegistrar); registrar_->Add(this, content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED, content::Source(web_contents)); - registrar_->Add(this, content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE, - content::Source( - web_contents->GetRenderViewHost())); + response_manager_.reset(new CefResponseManager); placeholder_frame_ = new CefFrameHostImpl(this, CefFrameHostImpl::kInvalidFrameId, true); - // Retrieve the DevTools URLs, if any. - CefDevToolsDelegate* devtools_delegate = _Context->devtools_delegate(); - if (devtools_delegate) { - devtools_url_http_ = devtools_delegate->GetDevToolsURL( - web_contents->GetRenderViewHost(), true); - devtools_url_chrome_ = devtools_delegate->GetDevToolsURL( - web_contents->GetRenderViewHost(), false); + SetRenderViewHost(web_contents->GetRenderViewHost()); +} + +void CefBrowserHostImpl::SetRenderViewHost(content::RenderViewHost* rvh) { + { + base::AutoLock lock_scope(state_lock_); + + render_view_id_ = rvh->GetRoutingID(); + render_process_id_ = rvh->GetProcess()->GetID(); + + // Update the DevTools URLs, if any. + CefDevToolsDelegate* devtools_delegate = _Context->devtools_delegate(); + if (devtools_delegate) { + devtools_url_http_ = devtools_delegate->GetDevToolsURL(rvh, true); + devtools_url_chrome_ = devtools_delegate->GetDevToolsURL(rvh, false); + } + } + + if (!registrar_->IsRegistered( + this, content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE, + content::Source(rvh))) { + registrar_->Add(this, content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE, + content::Source(rvh)); } } diff --git a/libcef/browser/browser_host_impl.h b/libcef/browser/browser_host_impl.h index d89d168bd..960b77834 100644 --- a/libcef/browser/browser_host_impl.h +++ b/libcef/browser/browser_host_impl.h @@ -18,7 +18,6 @@ #include "libcef/browser/frame_host_impl.h" #include "libcef/browser/javascript_dialog_creator.h" #include "libcef/browser/menu_creator.h" -#include "libcef/browser/url_request_context_getter_proxy.h" #include "libcef/common/response_manager.h" #include "base/memory/scoped_ptr.h" @@ -29,6 +28,7 @@ #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_delegate.h" #include "content/public/browser/web_contents_observer.h" +#include "net/url_request/url_request_context_getter.h" namespace content { struct NativeWebKeyboardEvent; @@ -239,8 +239,10 @@ class CefBrowserHostImpl : public CefBrowserHost, const content::MediaResponseCallback& callback) OVERRIDE; // content::WebContentsObserver methods. - virtual void RenderViewCreated(content::RenderViewHost* render_view_host) - OVERRIDE; + virtual void RenderViewCreated( + content::RenderViewHost* render_view_host) OVERRIDE; + virtual void RenderViewDeleted( + content::RenderViewHost* render_view_host) OVERRIDE; virtual void RenderViewReady() OVERRIDE; virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; virtual void DidCommitProvisionalLoadForFrame( @@ -288,6 +290,9 @@ class CefBrowserHostImpl : public CefBrowserHost, content::WebContents* web_contents, CefWindowHandle opener); + // Initialize settings based on the specified RenderViewHost. + void SetRenderViewHost(content::RenderViewHost* rvh); + // Updates and returns an existing frame or creates a new frame. Pass // CefFrameHostImpl::kUnspecifiedFrameId for |parent_frame_id| if unknown. CefRefPtr GetOrCreateFrame(int64 frame_id, @@ -404,7 +409,7 @@ class CefBrowserHostImpl : public CefBrowserHost, scoped_ptr registrar_; // Used for proxying cookie requests. - scoped_refptr request_context_proxy_; + scoped_refptr request_context_proxy_; // Manages response registrations. scoped_ptr response_manager_; diff --git a/libcef/browser/browser_main.cc b/libcef/browser/browser_main.cc index 867d65d5d..18074fbc8 100644 --- a/libcef/browser/browser_main.cc +++ b/libcef/browser/browser_main.cc @@ -54,18 +54,19 @@ void CefBrowserMainParts::PreMainMessageLoopStart() { } int CefBrowserMainParts::PreCreateThreads() { + PlatformInitialize(); + net::NetModule::SetResourceProvider(&ResourceProvider); + + // Initialize the GpuDataManager before IO access restrictions are applied and + // before the IO thread is started. + content::GpuDataManager::GetInstance(); + return 0; } void CefBrowserMainParts::PreMainMessageLoopRun() { browser_context_.reset(new CefBrowserContext()); - PlatformInitialize(); - net::NetModule::SetResourceProvider(&ResourceProvider); - - // Initialize the GpuDataManager before IO access restrictions are applied. - content::GpuDataManager::GetInstance(); - const CommandLine& command_line = *CommandLine::ForCurrentProcess(); if (command_line.HasSwitch(switches::kRemoteDebuggingPort)) { std::string port_str = @@ -82,13 +83,11 @@ void CefBrowserMainParts::PreMainMessageLoopRun() { } void CefBrowserMainParts::PostMainMessageLoopRun() { - PlatformCleanup(); - if (devtools_delegate_) devtools_delegate_->Stop(); browser_context_.reset(); } -bool CefBrowserMainParts::MainMessageLoopRun(int* result_code) { - return false; +void CefBrowserMainParts::PostDestroyThreads() { + PlatformCleanup(); } diff --git a/libcef/browser/browser_main.h b/libcef/browser/browser_main.h index 7b277d083..ffbad5d32 100644 --- a/libcef/browser/browser_main.h +++ b/libcef/browser/browser_main.h @@ -31,8 +31,8 @@ class CefBrowserMainParts : public content::BrowserMainParts { virtual void PreMainMessageLoopStart() OVERRIDE; virtual int PreCreateThreads() OVERRIDE; virtual void PreMainMessageLoopRun() OVERRIDE; - virtual bool MainMessageLoopRun(int* result_code) OVERRIDE; virtual void PostMainMessageLoopRun() OVERRIDE; + virtual void PostDestroyThreads() OVERRIDE; CefBrowserContext* browser_context() const { return browser_context_.get(); } CefDevToolsDelegate* devtools_delegate() const { return devtools_delegate_; } diff --git a/libcef/browser/download_item_impl.cc b/libcef/browser/download_item_impl.cc new file mode 100644 index 000000000..826bea231 --- /dev/null +++ b/libcef/browser/download_item_impl.cc @@ -0,0 +1,107 @@ +// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights +// reserved. Use of this source code is governed by a BSD-style license that +// can be found in the LICENSE file. + +#include "libcef/browser/download_item_impl.h" + +#include "libcef/common/time_util.h" + +#include "content/public/browser/download_item.h" +#include "googleurl/src/gurl.h" + + +CefDownloadItemImpl::CefDownloadItemImpl(content::DownloadItem* value) + : CefValueBase( + value, NULL, kOwnerNoDelete, true, + new CefValueControllerNonThreadSafe()) { + // Indicate that this object owns the controller. + SetOwnsController(); +} + +bool CefDownloadItemImpl::IsValid() { + return !detached(); +} + +bool CefDownloadItemImpl::IsInProgress() { + CEF_VALUE_VERIFY_RETURN(false, false); + return const_value().IsInProgress(); +} + +bool CefDownloadItemImpl::IsComplete() { + CEF_VALUE_VERIFY_RETURN(false, false); + return const_value().IsComplete(); +} + +bool CefDownloadItemImpl::IsCanceled() { + CEF_VALUE_VERIFY_RETURN(false, false); + return const_value().IsCancelled(); +} + +int64 CefDownloadItemImpl::GetCurrentSpeed() { + CEF_VALUE_VERIFY_RETURN(false, 0); + return const_value().CurrentSpeed(); +} + +int CefDownloadItemImpl::GetPercentComplete() { + CEF_VALUE_VERIFY_RETURN(false, -1); + return const_value().PercentComplete(); +} + +int64 CefDownloadItemImpl::GetTotalBytes() { + CEF_VALUE_VERIFY_RETURN(false, 0); + return const_value().GetTotalBytes(); +} + +int64 CefDownloadItemImpl::GetReceivedBytes() { + CEF_VALUE_VERIFY_RETURN(false, 0); + return const_value().GetReceivedBytes(); +} + +CefTime CefDownloadItemImpl::GetStartTime() { + CefTime time; + CEF_VALUE_VERIFY_RETURN(false, time); + cef_time_from_basetime(const_value().GetStartTime(), time); + return time; +} + +CefTime CefDownloadItemImpl::GetEndTime() { + CefTime time; + CEF_VALUE_VERIFY_RETURN(false, time); + cef_time_from_basetime(const_value().GetEndTime(), time); + return time; +} + +CefString CefDownloadItemImpl::GetFullPath() { + CEF_VALUE_VERIFY_RETURN(false, CefString()); + return const_value().GetFullPath().value(); +} + +int32 CefDownloadItemImpl::GetId() { + CEF_VALUE_VERIFY_RETURN(false, 0); + return const_value().GetId(); +} + +CefString CefDownloadItemImpl::GetURL() { + CEF_VALUE_VERIFY_RETURN(false, CefString()); + return const_value().GetURL().spec(); +} + +CefString CefDownloadItemImpl::GetSuggestedFileName() { + CEF_VALUE_VERIFY_RETURN(false, CefString()); + return const_value().GetSuggestedFilename(); +} + +CefString CefDownloadItemImpl::GetContentDisposition() { + CEF_VALUE_VERIFY_RETURN(false, CefString()); + return const_value().GetContentDisposition(); +} + +CefString CefDownloadItemImpl::GetMimeType() { + CEF_VALUE_VERIFY_RETURN(false, CefString()); + return const_value().GetMimeType(); +} + +CefString CefDownloadItemImpl::GetReferrerCharset() { + CEF_VALUE_VERIFY_RETURN(false, CefString()); + return const_value().GetReferrerCharset(); +} diff --git a/libcef/browser/download_item_impl.h b/libcef/browser/download_item_impl.h new file mode 100644 index 000000000..30016f74b --- /dev/null +++ b/libcef/browser/download_item_impl.h @@ -0,0 +1,45 @@ +// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights +// reserved. Use of this source code is governed by a BSD-style license that +// can be found in the LICENSE file. + +#ifndef CEF_LIBCEF_BROWSER_DOWNLOAD_ITEM_IMPL_H_ +#define CEF_LIBCEF_BROWSER_DOWNLOAD_ITEM_IMPL_H_ +#pragma once + +#include "include/cef_download_item.h" +#include "libcef/common/value_base.h" + +namespace content { +class DownloadItem; +} + +// CefDownloadItem implementation +class CefDownloadItemImpl + : public CefValueBase { + public: + explicit CefDownloadItemImpl(content::DownloadItem* value); + + // CefDownloadItem methods. + virtual bool IsValid() OVERRIDE; + virtual bool IsInProgress() OVERRIDE; + virtual bool IsComplete() OVERRIDE; + virtual bool IsCanceled() OVERRIDE; + virtual int64 GetCurrentSpeed() OVERRIDE; + virtual int GetPercentComplete() OVERRIDE; + virtual int64 GetTotalBytes() OVERRIDE; + virtual int64 GetReceivedBytes() OVERRIDE; + virtual CefTime GetStartTime() OVERRIDE; + virtual CefTime GetEndTime() OVERRIDE; + virtual CefString GetFullPath() OVERRIDE; + virtual int32 GetId() OVERRIDE; + virtual CefString GetURL() OVERRIDE; + virtual CefString GetSuggestedFileName() OVERRIDE; + virtual CefString GetContentDisposition() OVERRIDE; + virtual CefString GetMimeType() OVERRIDE; + virtual CefString GetReferrerCharset() OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(CefDownloadItemImpl); +}; + +#endif // CEF_LIBCEF_BROWSER_DOWNLOAD_ITEM_IMPL_H_ diff --git a/libcef/browser/download_manager_delegate.cc b/libcef/browser/download_manager_delegate.cc index 7b8dfc7ab..702897d14 100644 --- a/libcef/browser/download_manager_delegate.cc +++ b/libcef/browser/download_manager_delegate.cc @@ -4,65 +4,226 @@ #include "libcef/browser/download_manager_delegate.h" -#if defined(OS_WIN) -#include -#include -#endif +#include "include/cef_download_handler.h" +#include "libcef/browser/browser_context.h" +#include "libcef/browser/browser_host_impl.h" +#include "libcef/browser/context.h" +#include "libcef/browser/download_item_impl.h" +#include "libcef/browser/thread_util.h" #include "base/bind.h" #include "base/file_util.h" #include "base/logging.h" +#include "base/path_service.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" #include "content/public/browser/browser_context.h" -#include "content/public/browser/browser_thread.h" #include "content/public/browser/download_manager.h" #include "content/public/browser/web_contents.h" #include "net/base/net_util.h" -using content::BrowserThread; using content::DownloadItem; using content::DownloadManager; using content::WebContents; -CefDownloadManagerDelegate::CefDownloadManagerDelegate() - : download_manager_(NULL) { + +namespace { + +// Helper function to retrieve the CefBrowserHostImpl. +CefRefPtr GetBrowser(DownloadItem* item) { + content::WebContents* contents = item->GetWebContents(); + if (!contents) + return NULL; + + return CefBrowserHostImpl::GetBrowserForContents(contents).get(); +} + +// Helper function to retrieve the CefDownloadHandler. +CefRefPtr GetDownloadHandler( + CefRefPtr browser) { + CefRefPtr client = browser->GetClient(); + if (client.get()) + return client->GetDownloadHandler(); + return NULL; +} + +// Helper function to retrieve the DownloadManager. +scoped_refptr GetDownloadManager() { + return content::BrowserContext::GetDownloadManager( + _Context->browser_context()); +} + + +// CefBeforeDownloadCallback implementation. +class CefBeforeDownloadCallbackImpl : public CefBeforeDownloadCallback { + public: + CefBeforeDownloadCallbackImpl(int32 download_id, + const FilePath& suggested_name) + : download_id_(download_id), + suggested_name_(suggested_name) { + } + + virtual void Continue(const CefString& download_path, + bool show_dialog) OVERRIDE { + if (CEF_CURRENTLY_ON_UIT()) { + if (download_id_ <= 0) + return; + + scoped_refptr manager = GetDownloadManager(); + if (manager) { + FilePath path = FilePath(download_path); + CEF_POST_TASK(CEF_FILET, + base::Bind(&CefBeforeDownloadCallbackImpl::GenerateFilename, + download_id_, suggested_name_, path, show_dialog)); + } + + download_id_ = 0; + } else { + CEF_POST_TASK(CEF_UIT, + base::Bind(&CefBeforeDownloadCallbackImpl::Continue, this, + download_path, show_dialog)); + } + } + + private: + static void GenerateFilename(int32 download_id, + const FilePath& suggested_name, + const FilePath& download_path, + bool show_dialog) { + FilePath suggested_path = download_path; + if (!suggested_path.empty()) { + // Create the directory if necessary. + FilePath dir_path = suggested_path.DirName(); + if (!file_util::DirectoryExists(dir_path) && + !file_util::CreateDirectory(dir_path)) { + NOTREACHED() << "failed to create the download directory"; + suggested_path.clear(); + } + } + + if (suggested_path.empty()) { + if (PathService::Get(base::DIR_TEMP, &suggested_path)) { + // Use the temp directory. + suggested_path = suggested_path.Append(suggested_name); + } else { + // Use the current working directory. + suggested_path = suggested_name; + } + } + + content::DownloadItem::TargetDisposition disposition = show_dialog ? + DownloadItem::TARGET_DISPOSITION_PROMPT : + DownloadItem::TARGET_DISPOSITION_OVERWRITE; + + CEF_POST_TASK(CEF_UIT, + base::Bind(&CefBeforeDownloadCallbackImpl::RestartDownload, + download_id, suggested_path, disposition)); + } + + static void RestartDownload(int32 download_id, + const FilePath& suggested_path, + DownloadItem::TargetDisposition disposition) { + scoped_refptr manager = GetDownloadManager(); + if (!manager) + return; + + DownloadItem* item = manager->GetActiveDownloadItem(download_id); + if (!item) + return; + + item->OnTargetPathDetermined(suggested_path, + disposition, + content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); + manager->RestartDownload(download_id); + } + + int32 download_id_; + FilePath suggested_name_; + + IMPLEMENT_REFCOUNTING(CefBeforeDownloadCallbackImpl); + DISALLOW_COPY_AND_ASSIGN(CefBeforeDownloadCallbackImpl); +}; + + +// CefDownloadItemCallback implementation. +class CefDownloadItemCallbackImpl : public CefDownloadItemCallback { + public: + explicit CefDownloadItemCallbackImpl(int32 download_id) + : download_id_(download_id) { + } + + virtual void Cancel() OVERRIDE { + CEF_POST_TASK(CEF_UIT, + base::Bind(&CefDownloadItemCallbackImpl::DoCancel, this)); + } + + private: + void DoCancel() { + if (download_id_ <= 0) + return; + + scoped_refptr manager = GetDownloadManager(); + if (manager) { + content::DownloadItem* item = + manager->GetActiveDownloadItem(download_id_); + if (item && item->IsInProgress()) + item->Cancel(true); + } + + download_id_ = 0; + } + + int32 download_id_; + + IMPLEMENT_REFCOUNTING(CefDownloadItemCallbackImpl); + DISALLOW_COPY_AND_ASSIGN(CefDownloadItemCallbackImpl); +}; + +} // namespace + + +CefDownloadManagerDelegate::CefDownloadManagerDelegate() { } CefDownloadManagerDelegate::~CefDownloadManagerDelegate() { } -void CefDownloadManagerDelegate::SetDownloadManager( - DownloadManager* download_manager) { - download_manager_ = download_manager; -} - bool CefDownloadManagerDelegate::ShouldStartDownload(int32 download_id) { - DownloadItem* download = - download_manager_->GetActiveDownloadItem(download_id); + scoped_refptr manager = GetDownloadManager(); + DownloadItem* item = manager->GetActiveDownloadItem(download_id); - if (!download->GetForcedFilePath().empty()) { - download->OnTargetPathDetermined( - download->GetForcedFilePath(), + if (!item->GetForcedFilePath().empty()) { + item->OnTargetPathDetermined( + item->GetForcedFilePath(), DownloadItem::TARGET_DISPOSITION_OVERWRITE, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); return true; } - FilePath generated_name = net::GenerateFileName( - download->GetURL(), - download->GetContentDisposition(), - download->GetReferrerCharset(), - download->GetSuggestedFilename(), - download->GetMimeType(), - "download"); + CefRefPtr browser = GetBrowser(item); + CefRefPtr handler; + if (browser.get()) + handler = GetDownloadHandler(browser); + + if (handler.get()) { + FilePath suggested_name = net::GenerateFileName( + item->GetURL(), + item->GetContentDisposition(), + item->GetReferrerCharset(), + item->GetSuggestedFilename(), + item->GetMimeType(), + "download"); + + CefRefPtr download_item(new CefDownloadItemImpl(item)); + CefRefPtr callback( + new CefBeforeDownloadCallbackImpl(download_id, suggested_name)); + + handler->OnBeforeDownload(browser.get(), download_item.get(), + suggested_name.value(), callback); + + download_item->Detach(NULL); + } - BrowserThread::PostTask( - BrowserThread::FILE, - FROM_HERE, - base::Bind( - &CefDownloadManagerDelegate::GenerateFilename, - this, download_id, generated_name)); return false; } @@ -77,47 +238,35 @@ void CefDownloadManagerDelegate::ChooseDownloadPath( NOTIMPLEMENTED(); #endif + scoped_refptr manager = GetDownloadManager(); if (result.empty()) { - download_manager_->FileSelectionCanceled(item->GetId()); + manager->FileSelectionCanceled(item->GetId()); } else { - download_manager_->FileSelected(result, item->GetId()); + manager->FileSelected(result, item->GetId()); } } void CefDownloadManagerDelegate::AddItemToPersistentStore( - content::DownloadItem* item) { + DownloadItem* item) { static int next_id; - download_manager_->OnItemAddedToPersistentStore(item->GetId(), ++next_id); + scoped_refptr manager = GetDownloadManager(); + manager->OnItemAddedToPersistentStore(item->GetId(), ++next_id); } -void CefDownloadManagerDelegate::GenerateFilename( - int32 download_id, - const FilePath& generated_name) { - FilePath suggested_path = download_manager_->GetBrowserContext()->GetPath(). - Append(FILE_PATH_LITERAL("Downloads")); - if (!file_util::DirectoryExists(suggested_path)) - file_util::CreateDirectory(suggested_path); +void CefDownloadManagerDelegate::UpdateItemInPersistentStore( + DownloadItem* item) { + CefRefPtr browser = GetBrowser(item); + CefRefPtr handler; + if (browser.get()) + handler = GetDownloadHandler(browser); - suggested_path = suggested_path.Append(generated_name); - BrowserThread::PostTask( - BrowserThread::UI, - FROM_HERE, - base::Bind( - &CefDownloadManagerDelegate::RestartDownload, - this, download_id, suggested_path)); -} - -void CefDownloadManagerDelegate::RestartDownload( - int32 download_id, - const FilePath& suggested_path) { - DownloadItem* download = - download_manager_->GetActiveDownloadItem(download_id); - if (!download) - return; - - // Since we have no download UI, show the user a dialog always. - download->OnTargetPathDetermined(suggested_path, - DownloadItem::TARGET_DISPOSITION_PROMPT, - content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); - download_manager_->RestartDownload(download_id); + if (handler.get()) { + CefRefPtr download_item(new CefDownloadItemImpl(item)); + CefRefPtr callback( + new CefDownloadItemCallbackImpl(item->GetId())); + + handler->OnDownloadUpdated(browser.get(), download_item.get(), callback); + + download_item->Detach(NULL); + } } diff --git a/libcef/browser/download_manager_delegate.h b/libcef/browser/download_manager_delegate.h index 09212e244..29d5b6589 100644 --- a/libcef/browser/download_manager_delegate.h +++ b/libcef/browser/download_manager_delegate.h @@ -22,28 +22,21 @@ class CefDownloadManagerDelegate public: CefDownloadManagerDelegate(); - void SetDownloadManager(content::DownloadManager* manager); - // DownloadManagerDelegate methods. virtual bool ShouldStartDownload(int32 download_id) OVERRIDE; virtual void ChooseDownloadPath(content::DownloadItem* item) OVERRIDE; virtual void AddItemToPersistentStore(content::DownloadItem* item) OVERRIDE; + virtual void UpdateItemInPersistentStore( + content::DownloadItem* item) OVERRIDE; private: friend class base::RefCountedThreadSafe; virtual ~CefDownloadManagerDelegate(); - void GenerateFilename(int32 download_id, - const FilePath& generated_name); - void RestartDownload(int32 download_id, - const FilePath& suggested_path); - FilePath PlatformChooseDownloadPath(content::WebContents* web_contents, const FilePath& suggested_path); - content::DownloadManager* download_manager_; - DISALLOW_COPY_AND_ASSIGN(CefDownloadManagerDelegate); }; diff --git a/libcef/browser/resource_context.cc b/libcef/browser/resource_context.cc index 133ced125..1bf0908d1 100644 --- a/libcef/browser/resource_context.cc +++ b/libcef/browser/resource_context.cc @@ -12,6 +12,11 @@ CefResourceContext::CefResourceContext( } CefResourceContext::~CefResourceContext() { + // Destroy the getter after content::ResourceContext has finished destructing. + // Otherwise, the URLRequestContext objects will be deleted before + // ResourceDispatcherHost has canceled any pending URLRequests. + content::BrowserThread::ReleaseSoon( + content::BrowserThread::IO, FROM_HERE, getter_.release()); } net::HostResolver* CefResourceContext::GetHostResolver() { diff --git a/libcef/browser/url_request_context_getter.cc b/libcef/browser/url_request_context_getter.cc index f7740dd5c..7d48032ce 100644 --- a/libcef/browser/url_request_context_getter.cc +++ b/libcef/browser/url_request_context_getter.cc @@ -13,10 +13,12 @@ #include "libcef/browser/context.h" #include "libcef/browser/thread_util.h" #include "libcef/browser/url_network_delegate.h" +#include "libcef/browser/url_request_context_proxy.h" #include "libcef/browser/url_request_interceptor.h" #include "base/file_util.h" #include "base/logging.h" +#include "base/stl_util.h" #include "base/string_split.h" #include "base/threading/thread_restrictions.h" #include "base/threading/worker_pool.h" @@ -137,6 +139,7 @@ CefURLRequestContextGetter::CefURLRequestContextGetter( } CefURLRequestContextGetter::~CefURLRequestContextGetter() { + STLDeleteElements(&url_request_context_proxies_); } net::URLRequestContext* CefURLRequestContextGetter::GetURLRequestContext() { @@ -353,6 +356,51 @@ void CefURLRequestContextGetter::SetCookieSupportedSchemes( delete [] arr; } +CefURLRequestContextProxy* + CefURLRequestContextGetter::CreateURLRequestContextProxy() { + CEF_REQUIRE_IOT(); + CefURLRequestContextProxy* proxy = new CefURLRequestContextProxy(this); + url_request_context_proxies_.insert(proxy); + return proxy; +} + +void CefURLRequestContextGetter::ReleaseURLRequestContextProxy( + CefURLRequestContextProxy* proxy) { + CEF_REQUIRE_IOT(); + + // Don't do anything if we're currently shutting down. The proxy objects will + // be deleted when this object is destroyed. + if (_Context->shutting_down()) + return; + + if (proxy->url_requests()->size() == 0) { + // Safe to delete the proxy. + RequestContextProxySet::iterator it = + url_request_context_proxies_.find(proxy); + DCHECK(it != url_request_context_proxies_.end()); + url_request_context_proxies_.erase(it); + delete proxy; + } else { + proxy->increment_delete_try_count(); + if (proxy->delete_try_count() <= 1) { + // Cancel the pending requests. This may result in additional tasks being + // posted on the IO thread. + std::set::iterator it = + proxy->url_requests()->begin(); + for (; it != proxy->url_requests()->end(); ++it) + const_cast(*it)->Cancel(); + + // Try to delete the proxy again later. + CEF_POST_TASK(CEF_IOT, + base::Bind(&CefURLRequestContextGetter::ReleaseURLRequestContextProxy, + this, proxy)); + } else { + NOTREACHED() << + "too many retries to delete URLRequestContext proxy object"; + } + } +} + void CefURLRequestContextGetter::CreateProxyConfigService() { if (proxy_config_service_.get()) return; diff --git a/libcef/browser/url_request_context_getter.h b/libcef/browser/url_request_context_getter.h index 1ee5c3e0a..659b0d1f8 100644 --- a/libcef/browser/url_request_context_getter.h +++ b/libcef/browser/url_request_context_getter.h @@ -6,6 +6,7 @@ #define CEF_LIBCEF_BROWSER_URL_REQUEST_CONTEXT_GETTER_H_ #pragma once +#include #include #include @@ -16,6 +17,7 @@ #include "net/url_request/url_request_context_getter.h" class CefRequestInterceptor; +class CefURLRequestContextProxy; class MessageLoop; namespace net { @@ -44,6 +46,12 @@ class CefURLRequestContextGetter : public net::URLRequestContextGetter { void SetCookieStoragePath(const FilePath& path); void SetCookieSupportedSchemes(const std::vector& schemes); + // Manage URLRequestContext proxy objects. It's important that proxy objects + // not be destroyed while any in-flight URLRequests exist. These methods + // manage that requirement. + CefURLRequestContextProxy* CreateURLRequestContextProxy(); + void ReleaseURLRequestContextProxy(CefURLRequestContextProxy* proxy); + private: void CreateProxyConfigService(); @@ -57,6 +65,9 @@ class CefURLRequestContextGetter : public net::URLRequestContextGetter { scoped_ptr url_request_context_; scoped_ptr url_security_manager_; + typedef std::set RequestContextProxySet; + RequestContextProxySet url_request_context_proxies_; + FilePath cookie_store_path_; std::vector cookie_supported_schemes_; diff --git a/libcef/browser/url_request_context_getter_proxy.cc b/libcef/browser/url_request_context_getter_proxy.cc index a94dcf47e..4284ffaf8 100644 --- a/libcef/browser/url_request_context_getter_proxy.cc +++ b/libcef/browser/url_request_context_getter_proxy.cc @@ -9,6 +9,8 @@ #include "libcef/browser/browser_host_impl.h" #include "libcef/browser/cookie_manager_impl.h" #include "libcef/browser/thread_util.h" +#include "libcef/browser/url_request_context_getter.h" +#include "libcef/browser/url_request_context_proxy.h" #include "base/logging.h" #include "base/message_loop_proxy.h" @@ -117,69 +119,32 @@ class CefCookieStoreProxy : public net::CookieStore { DISALLOW_COPY_AND_ASSIGN(CefCookieStoreProxy); }; -class CefRequestContextProxy : public net::URLRequestContext { - public: - CefRequestContextProxy(CefBrowserHostImpl* browser, - net::URLRequestContextGetter* parent) - : parent_(parent) { - net::URLRequestContext* context = parent->GetURLRequestContext(); - - // Cookie store that proxies to the browser implementation. - cookie_store_proxy_ = new CefCookieStoreProxy(browser, context); - set_cookie_store(cookie_store_proxy_); - - // All other values refer to the parent request context. - set_net_log(context->net_log()); - set_host_resolver(context->host_resolver()); - set_cert_verifier(context->cert_verifier()); - set_server_bound_cert_service(context->server_bound_cert_service()); - set_fraudulent_certificate_reporter( - context->fraudulent_certificate_reporter()); - set_proxy_service(context->proxy_service()); - set_ssl_config_service(context->ssl_config_service()); - set_http_auth_handler_factory(context->http_auth_handler_factory()); - set_http_transaction_factory(context->http_transaction_factory()); - set_ftp_transaction_factory(context->ftp_transaction_factory()); - set_network_delegate(context->network_delegate()); - set_http_server_properties(context->http_server_properties()); - set_transport_security_state(context->transport_security_state()); - set_accept_charset(context->accept_charset()); - set_accept_language(context->accept_language()); - set_referrer_charset(context->referrer_charset()); - set_job_factory(context->job_factory()); - } - - virtual const std::string& GetUserAgent(const GURL& url) const OVERRIDE { - return parent_->GetURLRequestContext()->GetUserAgent(url); - } - - private: - net::URLRequestContextGetter* parent_; - scoped_refptr cookie_store_proxy_; - - DISALLOW_COPY_AND_ASSIGN(CefRequestContextProxy); -}; - } // namespace CefURLRequestContextGetterProxy::CefURLRequestContextGetterProxy( CefBrowserHostImpl* browser, - net::URLRequestContextGetter* parent) + CefURLRequestContextGetter* parent) : browser_(browser), - parent_(parent) { + parent_(parent), + context_proxy_(NULL) { DCHECK(browser); DCHECK(parent); } +CefURLRequestContextGetterProxy::~CefURLRequestContextGetterProxy() { + if (context_proxy_) + parent_->ReleaseURLRequestContextProxy(context_proxy_); +} + net::URLRequestContext* CefURLRequestContextGetterProxy::GetURLRequestContext() { CEF_REQUIRE_IOT(); - if (!context_proxy_.get()) { - context_proxy_.reset( - new CefRequestContextProxy(browser_, parent_)); + if (!context_proxy_) { + context_proxy_ = parent_->CreateURLRequestContextProxy(); + context_proxy_->Initialize(browser_); } - return context_proxy_.get(); + return context_proxy_; } scoped_refptr diff --git a/libcef/browser/url_request_context_getter_proxy.h b/libcef/browser/url_request_context_getter_proxy.h index 2e4faa190..ec6555145 100644 --- a/libcef/browser/url_request_context_getter_proxy.h +++ b/libcef/browser/url_request_context_getter_proxy.h @@ -10,11 +10,14 @@ #include "net/url_request/url_request_context_getter.h" class CefBrowserHostImpl; +class CefURLRequestContextGetter; +class CefURLRequestContextProxy; class CefURLRequestContextGetterProxy : public net::URLRequestContextGetter { public: CefURLRequestContextGetterProxy(CefBrowserHostImpl* browser, - net::URLRequestContextGetter* parent); + CefURLRequestContextGetter* parent); + virtual ~CefURLRequestContextGetterProxy(); // net::URLRequestContextGetter implementation. virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE; @@ -23,8 +26,10 @@ class CefURLRequestContextGetterProxy : public net::URLRequestContextGetter { private: CefBrowserHostImpl* browser_; - scoped_refptr parent_; - scoped_ptr context_proxy_; + scoped_refptr parent_; + + // The |context_proxy_| object is owned by |parent_|. + CefURLRequestContextProxy* context_proxy_; DISALLOW_COPY_AND_ASSIGN(CefURLRequestContextGetterProxy); }; diff --git a/libcef/browser/url_request_context_proxy.cc b/libcef/browser/url_request_context_proxy.cc new file mode 100644 index 000000000..c2fa68093 --- /dev/null +++ b/libcef/browser/url_request_context_proxy.cc @@ -0,0 +1,164 @@ +// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights +// reserved. Use of this source code is governed by a BSD-style license that can +// be found in the LICENSE file. + +#include "libcef/browser/url_request_context_proxy.h" + +#include + +#include "libcef/browser/browser_host_impl.h" +#include "libcef/browser/cookie_manager_impl.h" +#include "libcef/browser/thread_util.h" + +#include "base/logging.h" +#include "base/message_loop_proxy.h" +#include "net/cookies/cookie_store.h" +#include "net/url_request/url_request_context_getter.h" + +namespace { + +class CefCookieStoreProxy : public net::CookieStore { + public: + explicit CefCookieStoreProxy(CefBrowserHostImpl* browser, + net::URLRequestContext* parent) + : parent_(parent), + browser_(browser) { + } + + // net::CookieStore methods. + virtual void SetCookieWithOptionsAsync( + const GURL& url, + const std::string& cookie_line, + const net::CookieOptions& options, + const SetCookiesCallback& callback) OVERRIDE { + scoped_refptr cookie_store = GetCookieStore(); + cookie_store->SetCookieWithOptionsAsync(url, cookie_line, options, + callback); + } + + virtual void GetCookiesWithOptionsAsync( + const GURL& url, const net::CookieOptions& options, + const GetCookiesCallback& callback) OVERRIDE { + scoped_refptr cookie_store = GetCookieStore(); + cookie_store->GetCookiesWithOptionsAsync(url, options, callback); + } + + void GetCookiesWithInfoAsync( + const GURL& url, + const net::CookieOptions& options, + const GetCookieInfoCallback& callback) OVERRIDE { + scoped_refptr cookie_store = GetCookieStore(); + cookie_store->GetCookiesWithInfoAsync(url, options, callback); + } + + virtual void DeleteCookieAsync(const GURL& url, + const std::string& cookie_name, + const base::Closure& callback) OVERRIDE { + scoped_refptr cookie_store = GetCookieStore(); + cookie_store->DeleteCookieAsync(url, cookie_name, callback); + } + + virtual void DeleteAllCreatedBetweenAsync(const base::Time& delete_begin, + const base::Time& delete_end, + const DeleteCallback& callback) + OVERRIDE { + scoped_refptr cookie_store = GetCookieStore(); + cookie_store->DeleteAllCreatedBetweenAsync(delete_begin, delete_end, + callback); + } + + virtual void DeleteSessionCookiesAsync(const DeleteCallback& callback) + OVERRIDE { + scoped_refptr cookie_store = GetCookieStore(); + cookie_store->DeleteSessionCookiesAsync(callback); + } + + virtual net::CookieMonster* GetCookieMonster() OVERRIDE { + scoped_refptr cookie_store = GetCookieStore(); + return cookie_store->GetCookieMonster(); + } + + private: + net::CookieStore* GetCookieStore() { + CEF_REQUIRE_IOT(); + + scoped_refptr cookie_store; + + CefRefPtr client = browser_->GetClient(); + if (client.get()) { + CefRefPtr handler = client->GetRequestHandler(); + if (handler.get()) { + // Get the manager from the handler. + CefRefPtr manager = + handler->GetCookieManager(browser_, + browser_->GetLoadingURL().spec()); + if (manager.get()) { + cookie_store = + reinterpret_cast( + manager.get())->cookie_monster(); + DCHECK(cookie_store); + } + } + } + + if (!cookie_store) { + // Use the global cookie store. + cookie_store = parent_->cookie_store(); + } + + DCHECK(cookie_store); + return cookie_store; + } + + // This pointer is guaranteed by the CefRequestContextProxy object. + net::URLRequestContext* parent_; + CefBrowserHostImpl* browser_; + + DISALLOW_COPY_AND_ASSIGN(CefCookieStoreProxy); +}; + +} // namespace + + +CefURLRequestContextProxy::CefURLRequestContextProxy( + net::URLRequestContextGetter* parent) + : parent_(parent), + delete_try_count_(0) { +} + +CefURLRequestContextProxy::~CefURLRequestContextProxy() { +} + +const std::string& CefURLRequestContextProxy::GetUserAgent(const GURL& url) const { + return parent_->GetURLRequestContext()->GetUserAgent(url); +} + +void CefURLRequestContextProxy::Initialize(CefBrowserHostImpl* browser) { + CEF_REQUIRE_IOT(); + + net::URLRequestContext* context = parent_->GetURLRequestContext(); + + // Cookie store that proxies to the browser implementation. + cookie_store_proxy_ = new CefCookieStoreProxy(browser, context); + set_cookie_store(cookie_store_proxy_); + + // All other values refer to the parent request context. + set_net_log(context->net_log()); + set_host_resolver(context->host_resolver()); + set_cert_verifier(context->cert_verifier()); + set_server_bound_cert_service(context->server_bound_cert_service()); + set_fraudulent_certificate_reporter( + context->fraudulent_certificate_reporter()); + set_proxy_service(context->proxy_service()); + set_ssl_config_service(context->ssl_config_service()); + set_http_auth_handler_factory(context->http_auth_handler_factory()); + set_http_transaction_factory(context->http_transaction_factory()); + set_ftp_transaction_factory(context->ftp_transaction_factory()); + set_network_delegate(context->network_delegate()); + set_http_server_properties(context->http_server_properties()); + set_transport_security_state(context->transport_security_state()); + set_accept_charset(context->accept_charset()); + set_accept_language(context->accept_language()); + set_referrer_charset(context->referrer_charset()); + set_job_factory(context->job_factory()); +} diff --git a/libcef/browser/url_request_context_proxy.h b/libcef/browser/url_request_context_proxy.h new file mode 100644 index 000000000..bde5fc21a --- /dev/null +++ b/libcef/browser/url_request_context_proxy.h @@ -0,0 +1,43 @@ +// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights +// reserved. Use of this source code is governed by a BSD-style license that can +// be found in the LICENSE file. + +#ifndef CEF_LIBCEF_BROWSER_URL_REQUEST_CONTEXT_PROXY_H_ +#define CEF_LIBCEF_BROWSER_URL_REQUEST_CONTEXT_PROXY_H_ +#pragma once + +#include "base/memory/scoped_ptr.h" +#include "net/url_request/url_request_context.h" + +class CefBrowserHostImpl; + +namespace net { +class CookieStore; +class URLRequestContextGetter; +} + +class CefURLRequestContextProxy : public net::URLRequestContext { + public: + explicit CefURLRequestContextProxy(net::URLRequestContextGetter* parent); + virtual ~CefURLRequestContextProxy(); + + virtual const std::string& GetUserAgent(const GURL& url) const OVERRIDE; + + void Initialize(CefBrowserHostImpl* browser); + + // We may try to delete this proxy multiple times if URLRequests are still + // pending. Keep track of the number of tries so that they don't become + // excessive. + int delete_try_count() const { return delete_try_count_; } + void increment_delete_try_count() { delete_try_count_++; } + + private: + net::URLRequestContextGetter* parent_; + scoped_refptr cookie_store_proxy_; + + int delete_try_count_; + + DISALLOW_COPY_AND_ASSIGN(CefURLRequestContextProxy); +}; + +#endif // CEF_LIBCEF_BROWSER_URL_REQUEST_CONTEXT_PROXY_H_ diff --git a/libcef_dll/cpptoc/before_download_callback_cpptoc.cc b/libcef_dll/cpptoc/before_download_callback_cpptoc.cc new file mode 100644 index 000000000..f1a690a2f --- /dev/null +++ b/libcef_dll/cpptoc/before_download_callback_cpptoc.cc @@ -0,0 +1,52 @@ +// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights +// reserved. Use of this source code is governed by a BSD-style license that +// can be found in the LICENSE file. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool. If making changes by +// hand only do so within the body of existing method and function +// implementations. See the translator.README.txt file in the tools directory +// for more information. +// + +#include "libcef_dll/cpptoc/before_download_callback_cpptoc.h" + + +// MEMBER FUNCTIONS - Body may be edited by hand. + +void CEF_CALLBACK before_download_callback_cont( + struct _cef_before_download_callback_t* self, + const cef_string_t* download_path, int show_dialog) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return; + // Verify param: download_path; type: string_byref_const + DCHECK(download_path); + if (!download_path) + return; + + // Execute + CefBeforeDownloadCallbackCppToC::Get(self)->Continue( + CefString(download_path), + show_dialog?true:false); +} + + +// CONSTRUCTOR - Do not edit by hand. + +CefBeforeDownloadCallbackCppToC::CefBeforeDownloadCallbackCppToC( + CefBeforeDownloadCallback* cls) + : CefCppToC(cls) { + struct_.struct_.cont = before_download_callback_cont; +} + +#ifndef NDEBUG +template<> long CefCppToC::DebugObjCt = + 0; +#endif + diff --git a/libcef_dll/cpptoc/before_download_callback_cpptoc.h b/libcef_dll/cpptoc/before_download_callback_cpptoc.h new file mode 100644 index 000000000..a4bea8390 --- /dev/null +++ b/libcef_dll/cpptoc/before_download_callback_cpptoc.h @@ -0,0 +1,37 @@ +// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights +// reserved. Use of this source code is governed by a BSD-style license that +// can be found in the LICENSE file. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool. If making changes by +// hand only do so within the body of existing method and function +// implementations. See the translator.README.txt file in the tools directory +// for more information. +// + +#ifndef CEF_LIBCEF_DLL_CPPTOC_BEFORE_DOWNLOAD_CALLBACK_CPPTOC_H_ +#define CEF_LIBCEF_DLL_CPPTOC_BEFORE_DOWNLOAD_CALLBACK_CPPTOC_H_ +#pragma once + +#ifndef BUILDING_CEF_SHARED +#pragma message("Warning: "__FILE__" may be accessed DLL-side only") +#else // BUILDING_CEF_SHARED + +#include "include/cef_download_handler.h" +#include "include/capi/cef_download_handler_capi.h" +#include "libcef_dll/cpptoc/cpptoc.h" + +// Wrap a C++ class with a C structure. +// This class may be instantiated and accessed DLL-side only. +class CefBeforeDownloadCallbackCppToC + : public CefCppToC { + public: + explicit CefBeforeDownloadCallbackCppToC(CefBeforeDownloadCallback* cls); + virtual ~CefBeforeDownloadCallbackCppToC() {} +}; + +#endif // BUILDING_CEF_SHARED +#endif // CEF_LIBCEF_DLL_CPPTOC_BEFORE_DOWNLOAD_CALLBACK_CPPTOC_H_ + diff --git a/libcef_dll/cpptoc/client_cpptoc.cc b/libcef_dll/cpptoc/client_cpptoc.cc index 2bd3641e1..14a894155 100644 --- a/libcef_dll/cpptoc/client_cpptoc.cc +++ b/libcef_dll/cpptoc/client_cpptoc.cc @@ -13,6 +13,7 @@ #include "libcef_dll/cpptoc/client_cpptoc.h" #include "libcef_dll/cpptoc/context_menu_handler_cpptoc.h" #include "libcef_dll/cpptoc/display_handler_cpptoc.h" +#include "libcef_dll/cpptoc/download_handler_cpptoc.h" #include "libcef_dll/cpptoc/focus_handler_cpptoc.h" #include "libcef_dll/cpptoc/geolocation_handler_cpptoc.h" #include "libcef_dll/cpptoc/jsdialog_handler_cpptoc.h" @@ -58,6 +59,22 @@ struct _cef_display_handler_t* CEF_CALLBACK client_get_display_handler( return CefDisplayHandlerCppToC::Wrap(_retval); } +struct _cef_download_handler_t* CEF_CALLBACK client_get_download_handler( + struct _cef_client_t* self) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return NULL; + + // Execute + CefRefPtr _retval = CefClientCppToC::Get( + self)->GetDownloadHandler(); + + // Return type: refptr_same + return CefDownloadHandlerCppToC::Wrap(_retval); +} + struct _cef_focus_handler_t* CEF_CALLBACK client_get_focus_handler( struct _cef_client_t* self) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING @@ -204,6 +221,7 @@ CefClientCppToC::CefClientCppToC(CefClient* cls) : CefCppToC(cls) { struct_.struct_.get_context_menu_handler = client_get_context_menu_handler; struct_.struct_.get_display_handler = client_get_display_handler; + struct_.struct_.get_download_handler = client_get_download_handler; struct_.struct_.get_focus_handler = client_get_focus_handler; struct_.struct_.get_geolocation_handler = client_get_geolocation_handler; struct_.struct_.get_jsdialog_handler = client_get_jsdialog_handler; diff --git a/libcef_dll/cpptoc/download_handler_cpptoc.cc b/libcef_dll/cpptoc/download_handler_cpptoc.cc new file mode 100644 index 000000000..28113de7c --- /dev/null +++ b/libcef_dll/cpptoc/download_handler_cpptoc.cc @@ -0,0 +1,100 @@ +// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights +// reserved. Use of this source code is governed by a BSD-style license that +// can be found in the LICENSE file. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool. If making changes by +// hand only do so within the body of existing method and function +// implementations. See the translator.README.txt file in the tools directory +// for more information. +// + +#include "libcef_dll/cpptoc/download_handler_cpptoc.h" +#include "libcef_dll/ctocpp/before_download_callback_ctocpp.h" +#include "libcef_dll/ctocpp/browser_ctocpp.h" +#include "libcef_dll/ctocpp/download_item_ctocpp.h" +#include "libcef_dll/ctocpp/download_item_callback_ctocpp.h" + + +// MEMBER FUNCTIONS - Body may be edited by hand. + +void CEF_CALLBACK download_handler_on_before_download( + struct _cef_download_handler_t* self, cef_browser_t* browser, + struct _cef_download_item_t* download_item, + const cef_string_t* suggested_name, + cef_before_download_callback_t* callback) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return; + // Verify param: browser; type: refptr_diff + DCHECK(browser); + if (!browser) + return; + // Verify param: download_item; type: refptr_diff + DCHECK(download_item); + if (!download_item) + return; + // Verify param: suggested_name; type: string_byref_const + DCHECK(suggested_name); + if (!suggested_name) + return; + // Verify param: callback; type: refptr_diff + DCHECK(callback); + if (!callback) + return; + + // Execute + CefDownloadHandlerCppToC::Get(self)->OnBeforeDownload( + CefBrowserCToCpp::Wrap(browser), + CefDownloadItemCToCpp::Wrap(download_item), + CefString(suggested_name), + CefBeforeDownloadCallbackCToCpp::Wrap(callback)); +} + +void CEF_CALLBACK download_handler_on_download_updated( + struct _cef_download_handler_t* self, cef_browser_t* browser, + struct _cef_download_item_t* download_item, + cef_download_item_callback_t* callback) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return; + // Verify param: browser; type: refptr_diff + DCHECK(browser); + if (!browser) + return; + // Verify param: download_item; type: refptr_diff + DCHECK(download_item); + if (!download_item) + return; + // Verify param: callback; type: refptr_diff + DCHECK(callback); + if (!callback) + return; + + // Execute + CefDownloadHandlerCppToC::Get(self)->OnDownloadUpdated( + CefBrowserCToCpp::Wrap(browser), + CefDownloadItemCToCpp::Wrap(download_item), + CefDownloadItemCallbackCToCpp::Wrap(callback)); +} + + +// CONSTRUCTOR - Do not edit by hand. + +CefDownloadHandlerCppToC::CefDownloadHandlerCppToC(CefDownloadHandler* cls) + : CefCppToC(cls) { + struct_.struct_.on_before_download = download_handler_on_before_download; + struct_.struct_.on_download_updated = download_handler_on_download_updated; +} + +#ifndef NDEBUG +template<> long CefCppToC::DebugObjCt = 0; +#endif + diff --git a/libcef_dll/cpptoc/download_handler_cpptoc.h b/libcef_dll/cpptoc/download_handler_cpptoc.h new file mode 100644 index 000000000..f659d613d --- /dev/null +++ b/libcef_dll/cpptoc/download_handler_cpptoc.h @@ -0,0 +1,37 @@ +// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights +// reserved. Use of this source code is governed by a BSD-style license that +// can be found in the LICENSE file. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool. If making changes by +// hand only do so within the body of existing method and function +// implementations. See the translator.README.txt file in the tools directory +// for more information. +// + +#ifndef CEF_LIBCEF_DLL_CPPTOC_DOWNLOAD_HANDLER_CPPTOC_H_ +#define CEF_LIBCEF_DLL_CPPTOC_DOWNLOAD_HANDLER_CPPTOC_H_ +#pragma once + +#ifndef USING_CEF_SHARED +#pragma message("Warning: "__FILE__" may be accessed wrapper-side only") +#else // USING_CEF_SHARED + +#include "include/cef_download_handler.h" +#include "include/capi/cef_download_handler_capi.h" +#include "libcef_dll/cpptoc/cpptoc.h" + +// Wrap a C++ class with a C structure. +// This class may be instantiated and accessed wrapper-side only. +class CefDownloadHandlerCppToC + : public CefCppToC { + public: + explicit CefDownloadHandlerCppToC(CefDownloadHandler* cls); + virtual ~CefDownloadHandlerCppToC() {} +}; + +#endif // USING_CEF_SHARED +#endif // CEF_LIBCEF_DLL_CPPTOC_DOWNLOAD_HANDLER_CPPTOC_H_ + diff --git a/libcef_dll/cpptoc/download_item_callback_cpptoc.cc b/libcef_dll/cpptoc/download_item_callback_cpptoc.cc new file mode 100644 index 000000000..241c1b53a --- /dev/null +++ b/libcef_dll/cpptoc/download_item_callback_cpptoc.cc @@ -0,0 +1,44 @@ +// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights +// reserved. Use of this source code is governed by a BSD-style license that +// can be found in the LICENSE file. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool. If making changes by +// hand only do so within the body of existing method and function +// implementations. See the translator.README.txt file in the tools directory +// for more information. +// + +#include "libcef_dll/cpptoc/download_item_callback_cpptoc.h" + + +// MEMBER FUNCTIONS - Body may be edited by hand. + +void CEF_CALLBACK download_item_callback_cancel( + struct _cef_download_item_callback_t* self) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return; + + // Execute + CefDownloadItemCallbackCppToC::Get(self)->Cancel(); +} + + +// CONSTRUCTOR - Do not edit by hand. + +CefDownloadItemCallbackCppToC::CefDownloadItemCallbackCppToC( + CefDownloadItemCallback* cls) + : CefCppToC(cls) { + struct_.struct_.cancel = download_item_callback_cancel; +} + +#ifndef NDEBUG +template<> long CefCppToC::DebugObjCt = 0; +#endif + diff --git a/libcef_dll/cpptoc/download_item_callback_cpptoc.h b/libcef_dll/cpptoc/download_item_callback_cpptoc.h new file mode 100644 index 000000000..1afc07b93 --- /dev/null +++ b/libcef_dll/cpptoc/download_item_callback_cpptoc.h @@ -0,0 +1,37 @@ +// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights +// reserved. Use of this source code is governed by a BSD-style license that +// can be found in the LICENSE file. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool. If making changes by +// hand only do so within the body of existing method and function +// implementations. See the translator.README.txt file in the tools directory +// for more information. +// + +#ifndef CEF_LIBCEF_DLL_CPPTOC_DOWNLOAD_ITEM_CALLBACK_CPPTOC_H_ +#define CEF_LIBCEF_DLL_CPPTOC_DOWNLOAD_ITEM_CALLBACK_CPPTOC_H_ +#pragma once + +#ifndef BUILDING_CEF_SHARED +#pragma message("Warning: "__FILE__" may be accessed DLL-side only") +#else // BUILDING_CEF_SHARED + +#include "include/cef_download_handler.h" +#include "include/capi/cef_download_handler_capi.h" +#include "libcef_dll/cpptoc/cpptoc.h" + +// Wrap a C++ class with a C structure. +// This class may be instantiated and accessed DLL-side only. +class CefDownloadItemCallbackCppToC + : public CefCppToC { + public: + explicit CefDownloadItemCallbackCppToC(CefDownloadItemCallback* cls); + virtual ~CefDownloadItemCallbackCppToC() {} +}; + +#endif // BUILDING_CEF_SHARED +#endif // CEF_LIBCEF_DLL_CPPTOC_DOWNLOAD_ITEM_CALLBACK_CPPTOC_H_ + diff --git a/libcef_dll/cpptoc/download_item_cpptoc.cc b/libcef_dll/cpptoc/download_item_cpptoc.cc new file mode 100644 index 000000000..923e64467 --- /dev/null +++ b/libcef_dll/cpptoc/download_item_cpptoc.cc @@ -0,0 +1,300 @@ +// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights +// reserved. Use of this source code is governed by a BSD-style license that +// can be found in the LICENSE file. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool. If making changes by +// hand only do so within the body of existing method and function +// implementations. See the translator.README.txt file in the tools directory +// for more information. +// + +#include "libcef_dll/cpptoc/download_item_cpptoc.h" + + +// MEMBER FUNCTIONS - Body may be edited by hand. + +int CEF_CALLBACK download_item_is_valid(struct _cef_download_item_t* self) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return 0; + + // Execute + bool _retval = CefDownloadItemCppToC::Get(self)->IsValid(); + + // Return type: bool + return _retval; +} + +int CEF_CALLBACK download_item_is_in_progress( + struct _cef_download_item_t* self) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return 0; + + // Execute + bool _retval = CefDownloadItemCppToC::Get(self)->IsInProgress(); + + // Return type: bool + return _retval; +} + +int CEF_CALLBACK download_item_is_complete(struct _cef_download_item_t* self) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return 0; + + // Execute + bool _retval = CefDownloadItemCppToC::Get(self)->IsComplete(); + + // Return type: bool + return _retval; +} + +int CEF_CALLBACK download_item_is_canceled(struct _cef_download_item_t* self) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return 0; + + // Execute + bool _retval = CefDownloadItemCppToC::Get(self)->IsCanceled(); + + // Return type: bool + return _retval; +} + +int64 CEF_CALLBACK download_item_get_current_speed( + struct _cef_download_item_t* self) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return 0; + + // Execute + int64 _retval = CefDownloadItemCppToC::Get(self)->GetCurrentSpeed(); + + // Return type: simple + return _retval; +} + +int CEF_CALLBACK download_item_get_percent_complete( + struct _cef_download_item_t* self) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return 0; + + // Execute + int _retval = CefDownloadItemCppToC::Get(self)->GetPercentComplete(); + + // Return type: simple + return _retval; +} + +int64 CEF_CALLBACK download_item_get_total_bytes( + struct _cef_download_item_t* self) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return 0; + + // Execute + int64 _retval = CefDownloadItemCppToC::Get(self)->GetTotalBytes(); + + // Return type: simple + return _retval; +} + +int64 CEF_CALLBACK download_item_get_received_bytes( + struct _cef_download_item_t* self) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return 0; + + // Execute + int64 _retval = CefDownloadItemCppToC::Get(self)->GetReceivedBytes(); + + // Return type: simple + return _retval; +} + +cef_time_t CEF_CALLBACK download_item_get_start_time( + struct _cef_download_item_t* self) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return CefTime(); + + // Execute + cef_time_t _retval = CefDownloadItemCppToC::Get(self)->GetStartTime(); + + // Return type: simple + return _retval; +} + +cef_time_t CEF_CALLBACK download_item_get_end_time( + struct _cef_download_item_t* self) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return CefTime(); + + // Execute + cef_time_t _retval = CefDownloadItemCppToC::Get(self)->GetEndTime(); + + // Return type: simple + return _retval; +} + +cef_string_userfree_t CEF_CALLBACK download_item_get_full_path( + struct _cef_download_item_t* self) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return NULL; + + // Execute + CefString _retval = CefDownloadItemCppToC::Get(self)->GetFullPath(); + + // Return type: string + return _retval.DetachToUserFree(); +} + +int32 CEF_CALLBACK download_item_get_id(struct _cef_download_item_t* self) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return 0; + + // Execute + int32 _retval = CefDownloadItemCppToC::Get(self)->GetId(); + + // Return type: simple + return _retval; +} + +cef_string_userfree_t CEF_CALLBACK download_item_get_url( + struct _cef_download_item_t* self) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return NULL; + + // Execute + CefString _retval = CefDownloadItemCppToC::Get(self)->GetURL(); + + // Return type: string + return _retval.DetachToUserFree(); +} + +cef_string_userfree_t CEF_CALLBACK download_item_get_suggested_file_name( + struct _cef_download_item_t* self) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return NULL; + + // Execute + CefString _retval = CefDownloadItemCppToC::Get(self)->GetSuggestedFileName(); + + // Return type: string + return _retval.DetachToUserFree(); +} + +cef_string_userfree_t CEF_CALLBACK download_item_get_content_disposition( + struct _cef_download_item_t* self) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return NULL; + + // Execute + CefString _retval = CefDownloadItemCppToC::Get(self)->GetContentDisposition(); + + // Return type: string + return _retval.DetachToUserFree(); +} + +cef_string_userfree_t CEF_CALLBACK download_item_get_mime_type( + struct _cef_download_item_t* self) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return NULL; + + // Execute + CefString _retval = CefDownloadItemCppToC::Get(self)->GetMimeType(); + + // Return type: string + return _retval.DetachToUserFree(); +} + +cef_string_userfree_t CEF_CALLBACK download_item_get_referrer_charset( + struct _cef_download_item_t* self) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return NULL; + + // Execute + CefString _retval = CefDownloadItemCppToC::Get(self)->GetReferrerCharset(); + + // Return type: string + return _retval.DetachToUserFree(); +} + + +// CONSTRUCTOR - Do not edit by hand. + +CefDownloadItemCppToC::CefDownloadItemCppToC(CefDownloadItem* cls) + : CefCppToC( + cls) { + struct_.struct_.is_valid = download_item_is_valid; + struct_.struct_.is_in_progress = download_item_is_in_progress; + struct_.struct_.is_complete = download_item_is_complete; + struct_.struct_.is_canceled = download_item_is_canceled; + struct_.struct_.get_current_speed = download_item_get_current_speed; + struct_.struct_.get_percent_complete = download_item_get_percent_complete; + struct_.struct_.get_total_bytes = download_item_get_total_bytes; + struct_.struct_.get_received_bytes = download_item_get_received_bytes; + struct_.struct_.get_start_time = download_item_get_start_time; + struct_.struct_.get_end_time = download_item_get_end_time; + struct_.struct_.get_full_path = download_item_get_full_path; + struct_.struct_.get_id = download_item_get_id; + struct_.struct_.get_url = download_item_get_url; + struct_.struct_.get_suggested_file_name = + download_item_get_suggested_file_name; + struct_.struct_.get_content_disposition = + download_item_get_content_disposition; + struct_.struct_.get_mime_type = download_item_get_mime_type; + struct_.struct_.get_referrer_charset = download_item_get_referrer_charset; +} + +#ifndef NDEBUG +template<> long CefCppToC::DebugObjCt = 0; +#endif + diff --git a/libcef_dll/cpptoc/download_item_cpptoc.h b/libcef_dll/cpptoc/download_item_cpptoc.h new file mode 100644 index 000000000..c19ac48a2 --- /dev/null +++ b/libcef_dll/cpptoc/download_item_cpptoc.h @@ -0,0 +1,37 @@ +// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights +// reserved. Use of this source code is governed by a BSD-style license that +// can be found in the LICENSE file. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool. If making changes by +// hand only do so within the body of existing method and function +// implementations. See the translator.README.txt file in the tools directory +// for more information. +// + +#ifndef CEF_LIBCEF_DLL_CPPTOC_DOWNLOAD_ITEM_CPPTOC_H_ +#define CEF_LIBCEF_DLL_CPPTOC_DOWNLOAD_ITEM_CPPTOC_H_ +#pragma once + +#ifndef BUILDING_CEF_SHARED +#pragma message("Warning: "__FILE__" may be accessed DLL-side only") +#else // BUILDING_CEF_SHARED + +#include "include/cef_download_item.h" +#include "include/capi/cef_download_item_capi.h" +#include "libcef_dll/cpptoc/cpptoc.h" + +// Wrap a C++ class with a C structure. +// This class may be instantiated and accessed DLL-side only. +class CefDownloadItemCppToC + : public CefCppToC { + public: + explicit CefDownloadItemCppToC(CefDownloadItem* cls); + virtual ~CefDownloadItemCppToC() {} +}; + +#endif // BUILDING_CEF_SHARED +#endif // CEF_LIBCEF_DLL_CPPTOC_DOWNLOAD_ITEM_CPPTOC_H_ + diff --git a/libcef_dll/ctocpp/before_download_callback_ctocpp.cc b/libcef_dll/ctocpp/before_download_callback_ctocpp.cc new file mode 100644 index 000000000..6cf38bf9e --- /dev/null +++ b/libcef_dll/ctocpp/before_download_callback_ctocpp.cc @@ -0,0 +1,42 @@ +// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights +// reserved. Use of this source code is governed by a BSD-style license that +// can be found in the LICENSE file. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool. If making changes by +// hand only do so within the body of existing method and function +// implementations. See the translator.README.txt file in the tools directory +// for more information. +// + +#include "libcef_dll/ctocpp/before_download_callback_ctocpp.h" + + +// VIRTUAL METHODS - Body may be edited by hand. + +void CefBeforeDownloadCallbackCToCpp::Continue(const CefString& download_path, + bool show_dialog) { + if (CEF_MEMBER_MISSING(struct_, cont)) + return; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Verify param: download_path; type: string_byref_const + DCHECK(!download_path.empty()); + if (download_path.empty()) + return; + + // Execute + struct_->cont(struct_, + download_path.GetStruct(), + show_dialog); +} + + +#ifndef NDEBUG +template<> long CefCToCpp::DebugObjCt = + 0; +#endif + diff --git a/libcef_dll/ctocpp/before_download_callback_ctocpp.h b/libcef_dll/ctocpp/before_download_callback_ctocpp.h new file mode 100644 index 000000000..ad8106a2b --- /dev/null +++ b/libcef_dll/ctocpp/before_download_callback_ctocpp.h @@ -0,0 +1,43 @@ +// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights +// reserved. Use of this source code is governed by a BSD-style license that +// can be found in the LICENSE file. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool. If making changes by +// hand only do so within the body of existing method and function +// implementations. See the translator.README.txt file in the tools directory +// for more information. +// + +#ifndef CEF_LIBCEF_DLL_CTOCPP_BEFORE_DOWNLOAD_CALLBACK_CTOCPP_H_ +#define CEF_LIBCEF_DLL_CTOCPP_BEFORE_DOWNLOAD_CALLBACK_CTOCPP_H_ +#pragma once + +#ifndef USING_CEF_SHARED +#pragma message("Warning: "__FILE__" may be accessed wrapper-side only") +#else // USING_CEF_SHARED + +#include "include/cef_download_handler.h" +#include "include/capi/cef_download_handler_capi.h" +#include "libcef_dll/ctocpp/ctocpp.h" + +// Wrap a C structure with a C++ class. +// This class may be instantiated and accessed wrapper-side only. +class CefBeforeDownloadCallbackCToCpp + : public CefCToCpp { + public: + explicit CefBeforeDownloadCallbackCToCpp(cef_before_download_callback_t* str) + : CefCToCpp(str) {} + virtual ~CefBeforeDownloadCallbackCToCpp() {} + + // CefBeforeDownloadCallback methods + virtual void Continue(const CefString& download_path, + bool show_dialog) OVERRIDE; +}; + +#endif // USING_CEF_SHARED +#endif // CEF_LIBCEF_DLL_CTOCPP_BEFORE_DOWNLOAD_CALLBACK_CTOCPP_H_ + diff --git a/libcef_dll/ctocpp/client_ctocpp.cc b/libcef_dll/ctocpp/client_ctocpp.cc index 591f038c8..2d3b7a60c 100644 --- a/libcef_dll/ctocpp/client_ctocpp.cc +++ b/libcef_dll/ctocpp/client_ctocpp.cc @@ -15,6 +15,7 @@ #include "libcef_dll/ctocpp/client_ctocpp.h" #include "libcef_dll/ctocpp/context_menu_handler_ctocpp.h" #include "libcef_dll/ctocpp/display_handler_ctocpp.h" +#include "libcef_dll/ctocpp/download_handler_ctocpp.h" #include "libcef_dll/ctocpp/focus_handler_ctocpp.h" #include "libcef_dll/ctocpp/geolocation_handler_ctocpp.h" #include "libcef_dll/ctocpp/jsdialog_handler_ctocpp.h" @@ -53,6 +54,19 @@ CefRefPtr CefClientCToCpp::GetDisplayHandler() { return CefDisplayHandlerCToCpp::Wrap(_retval); } +CefRefPtr CefClientCToCpp::GetDownloadHandler() { + if (CEF_MEMBER_MISSING(struct_, get_download_handler)) + return NULL; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + cef_download_handler_t* _retval = struct_->get_download_handler(struct_); + + // Return type: refptr_same + return CefDownloadHandlerCToCpp::Wrap(_retval); +} + CefRefPtr CefClientCToCpp::GetFocusHandler() { if (CEF_MEMBER_MISSING(struct_, get_focus_handler)) return NULL; diff --git a/libcef_dll/ctocpp/client_ctocpp.h b/libcef_dll/ctocpp/client_ctocpp.h index dfcc96fe2..c2cf17c8e 100644 --- a/libcef_dll/ctocpp/client_ctocpp.h +++ b/libcef_dll/ctocpp/client_ctocpp.h @@ -34,6 +34,7 @@ class CefClientCToCpp // CefClient methods virtual CefRefPtr GetContextMenuHandler() OVERRIDE; virtual CefRefPtr GetDisplayHandler() OVERRIDE; + virtual CefRefPtr GetDownloadHandler() OVERRIDE; virtual CefRefPtr GetFocusHandler() OVERRIDE; virtual CefRefPtr GetGeolocationHandler() OVERRIDE; virtual CefRefPtr GetJSDialogHandler() OVERRIDE; diff --git a/libcef_dll/ctocpp/download_handler_ctocpp.cc b/libcef_dll/ctocpp/download_handler_ctocpp.cc new file mode 100644 index 000000000..102e2be5b --- /dev/null +++ b/libcef_dll/ctocpp/download_handler_ctocpp.cc @@ -0,0 +1,88 @@ +// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights +// reserved. Use of this source code is governed by a BSD-style license that +// can be found in the LICENSE file. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool. If making changes by +// hand only do so within the body of existing method and function +// implementations. See the translator.README.txt file in the tools directory +// for more information. +// + +#include "libcef_dll/cpptoc/before_download_callback_cpptoc.h" +#include "libcef_dll/cpptoc/browser_cpptoc.h" +#include "libcef_dll/cpptoc/download_item_cpptoc.h" +#include "libcef_dll/cpptoc/download_item_callback_cpptoc.h" +#include "libcef_dll/ctocpp/download_handler_ctocpp.h" + + +// VIRTUAL METHODS - Body may be edited by hand. + +void CefDownloadHandlerCToCpp::OnBeforeDownload(CefRefPtr browser, + CefRefPtr download_item, const CefString& suggested_name, + CefRefPtr callback) { + if (CEF_MEMBER_MISSING(struct_, on_before_download)) + return; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Verify param: browser; type: refptr_diff + DCHECK(browser.get()); + if (!browser.get()) + return; + // Verify param: download_item; type: refptr_diff + DCHECK(download_item.get()); + if (!download_item.get()) + return; + // Verify param: suggested_name; type: string_byref_const + DCHECK(!suggested_name.empty()); + if (suggested_name.empty()) + return; + // Verify param: callback; type: refptr_diff + DCHECK(callback.get()); + if (!callback.get()) + return; + + // Execute + struct_->on_before_download(struct_, + CefBrowserCppToC::Wrap(browser), + CefDownloadItemCppToC::Wrap(download_item), + suggested_name.GetStruct(), + CefBeforeDownloadCallbackCppToC::Wrap(callback)); +} + +void CefDownloadHandlerCToCpp::OnDownloadUpdated(CefRefPtr browser, + CefRefPtr download_item, + CefRefPtr callback) { + if (CEF_MEMBER_MISSING(struct_, on_download_updated)) + return; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Verify param: browser; type: refptr_diff + DCHECK(browser.get()); + if (!browser.get()) + return; + // Verify param: download_item; type: refptr_diff + DCHECK(download_item.get()); + if (!download_item.get()) + return; + // Verify param: callback; type: refptr_diff + DCHECK(callback.get()); + if (!callback.get()) + return; + + // Execute + struct_->on_download_updated(struct_, + CefBrowserCppToC::Wrap(browser), + CefDownloadItemCppToC::Wrap(download_item), + CefDownloadItemCallbackCppToC::Wrap(callback)); +} + + +#ifndef NDEBUG +template<> long CefCToCpp::DebugObjCt = 0; +#endif + diff --git a/libcef_dll/ctocpp/download_handler_ctocpp.h b/libcef_dll/ctocpp/download_handler_ctocpp.h new file mode 100644 index 000000000..f4f0f24c9 --- /dev/null +++ b/libcef_dll/ctocpp/download_handler_ctocpp.h @@ -0,0 +1,48 @@ +// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights +// reserved. Use of this source code is governed by a BSD-style license that +// can be found in the LICENSE file. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool. If making changes by +// hand only do so within the body of existing method and function +// implementations. See the translator.README.txt file in the tools directory +// for more information. +// + +#ifndef CEF_LIBCEF_DLL_CTOCPP_DOWNLOAD_HANDLER_CTOCPP_H_ +#define CEF_LIBCEF_DLL_CTOCPP_DOWNLOAD_HANDLER_CTOCPP_H_ +#pragma once + +#ifndef BUILDING_CEF_SHARED +#pragma message("Warning: "__FILE__" may be accessed DLL-side only") +#else // BUILDING_CEF_SHARED + +#include "include/cef_download_handler.h" +#include "include/capi/cef_download_handler_capi.h" +#include "libcef_dll/ctocpp/ctocpp.h" + +// Wrap a C structure with a C++ class. +// This class may be instantiated and accessed DLL-side only. +class CefDownloadHandlerCToCpp + : public CefCToCpp { + public: + explicit CefDownloadHandlerCToCpp(cef_download_handler_t* str) + : CefCToCpp(str) {} + virtual ~CefDownloadHandlerCToCpp() {} + + // CefDownloadHandler methods + virtual void OnBeforeDownload(CefRefPtr browser, + CefRefPtr download_item, + const CefString& suggested_name, + CefRefPtr callback) OVERRIDE; + virtual void OnDownloadUpdated(CefRefPtr browser, + CefRefPtr download_item, + CefRefPtr callback) OVERRIDE; +}; + +#endif // BUILDING_CEF_SHARED +#endif // CEF_LIBCEF_DLL_CTOCPP_DOWNLOAD_HANDLER_CTOCPP_H_ + diff --git a/libcef_dll/ctocpp/download_item_callback_ctocpp.cc b/libcef_dll/ctocpp/download_item_callback_ctocpp.cc new file mode 100644 index 000000000..99981cf0a --- /dev/null +++ b/libcef_dll/ctocpp/download_item_callback_ctocpp.cc @@ -0,0 +1,33 @@ +// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights +// reserved. Use of this source code is governed by a BSD-style license that +// can be found in the LICENSE file. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool. If making changes by +// hand only do so within the body of existing method and function +// implementations. See the translator.README.txt file in the tools directory +// for more information. +// + +#include "libcef_dll/ctocpp/download_item_callback_ctocpp.h" + + +// VIRTUAL METHODS - Body may be edited by hand. + +void CefDownloadItemCallbackCToCpp::Cancel() { + if (CEF_MEMBER_MISSING(struct_, cancel)) + return; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + struct_->cancel(struct_); +} + + +#ifndef NDEBUG +template<> long CefCToCpp::DebugObjCt = 0; +#endif + diff --git a/libcef_dll/ctocpp/download_item_callback_ctocpp.h b/libcef_dll/ctocpp/download_item_callback_ctocpp.h new file mode 100644 index 000000000..1a05a07d4 --- /dev/null +++ b/libcef_dll/ctocpp/download_item_callback_ctocpp.h @@ -0,0 +1,42 @@ +// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights +// reserved. Use of this source code is governed by a BSD-style license that +// can be found in the LICENSE file. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool. If making changes by +// hand only do so within the body of existing method and function +// implementations. See the translator.README.txt file in the tools directory +// for more information. +// + +#ifndef CEF_LIBCEF_DLL_CTOCPP_DOWNLOAD_ITEM_CALLBACK_CTOCPP_H_ +#define CEF_LIBCEF_DLL_CTOCPP_DOWNLOAD_ITEM_CALLBACK_CTOCPP_H_ +#pragma once + +#ifndef USING_CEF_SHARED +#pragma message("Warning: "__FILE__" may be accessed wrapper-side only") +#else // USING_CEF_SHARED + +#include "include/cef_download_handler.h" +#include "include/capi/cef_download_handler_capi.h" +#include "libcef_dll/ctocpp/ctocpp.h" + +// Wrap a C structure with a C++ class. +// This class may be instantiated and accessed wrapper-side only. +class CefDownloadItemCallbackCToCpp + : public CefCToCpp { + public: + explicit CefDownloadItemCallbackCToCpp(cef_download_item_callback_t* str) + : CefCToCpp(str) {} + virtual ~CefDownloadItemCallbackCToCpp() {} + + // CefDownloadItemCallback methods + virtual void Cancel() OVERRIDE; +}; + +#endif // USING_CEF_SHARED +#endif // CEF_LIBCEF_DLL_CTOCPP_DOWNLOAD_ITEM_CALLBACK_CTOCPP_H_ + diff --git a/libcef_dll/ctocpp/download_item_ctocpp.cc b/libcef_dll/ctocpp/download_item_ctocpp.cc new file mode 100644 index 000000000..f49712d37 --- /dev/null +++ b/libcef_dll/ctocpp/download_item_ctocpp.cc @@ -0,0 +1,256 @@ +// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights +// reserved. Use of this source code is governed by a BSD-style license that +// can be found in the LICENSE file. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool. If making changes by +// hand only do so within the body of existing method and function +// implementations. See the translator.README.txt file in the tools directory +// for more information. +// + +#include "libcef_dll/ctocpp/download_item_ctocpp.h" + + +// VIRTUAL METHODS - Body may be edited by hand. + +bool CefDownloadItemCToCpp::IsValid() { + if (CEF_MEMBER_MISSING(struct_, is_valid)) + return false; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + int _retval = struct_->is_valid(struct_); + + // Return type: bool + return _retval?true:false; +} + +bool CefDownloadItemCToCpp::IsInProgress() { + if (CEF_MEMBER_MISSING(struct_, is_in_progress)) + return false; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + int _retval = struct_->is_in_progress(struct_); + + // Return type: bool + return _retval?true:false; +} + +bool CefDownloadItemCToCpp::IsComplete() { + if (CEF_MEMBER_MISSING(struct_, is_complete)) + return false; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + int _retval = struct_->is_complete(struct_); + + // Return type: bool + return _retval?true:false; +} + +bool CefDownloadItemCToCpp::IsCanceled() { + if (CEF_MEMBER_MISSING(struct_, is_canceled)) + return false; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + int _retval = struct_->is_canceled(struct_); + + // Return type: bool + return _retval?true:false; +} + +int64 CefDownloadItemCToCpp::GetCurrentSpeed() { + if (CEF_MEMBER_MISSING(struct_, get_current_speed)) + return 0; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + int64 _retval = struct_->get_current_speed(struct_); + + // Return type: simple + return _retval; +} + +int CefDownloadItemCToCpp::GetPercentComplete() { + if (CEF_MEMBER_MISSING(struct_, get_percent_complete)) + return 0; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + int _retval = struct_->get_percent_complete(struct_); + + // Return type: simple + return _retval; +} + +int64 CefDownloadItemCToCpp::GetTotalBytes() { + if (CEF_MEMBER_MISSING(struct_, get_total_bytes)) + return 0; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + int64 _retval = struct_->get_total_bytes(struct_); + + // Return type: simple + return _retval; +} + +int64 CefDownloadItemCToCpp::GetReceivedBytes() { + if (CEF_MEMBER_MISSING(struct_, get_received_bytes)) + return 0; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + int64 _retval = struct_->get_received_bytes(struct_); + + // Return type: simple + return _retval; +} + +CefTime CefDownloadItemCToCpp::GetStartTime() { + if (CEF_MEMBER_MISSING(struct_, get_start_time)) + return CefTime(); + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + cef_time_t _retval = struct_->get_start_time(struct_); + + // Return type: simple + return _retval; +} + +CefTime CefDownloadItemCToCpp::GetEndTime() { + if (CEF_MEMBER_MISSING(struct_, get_end_time)) + return CefTime(); + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + cef_time_t _retval = struct_->get_end_time(struct_); + + // Return type: simple + return _retval; +} + +CefString CefDownloadItemCToCpp::GetFullPath() { + if (CEF_MEMBER_MISSING(struct_, get_full_path)) + return CefString(); + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + cef_string_userfree_t _retval = struct_->get_full_path(struct_); + + // Return type: string + CefString _retvalStr; + _retvalStr.AttachToUserFree(_retval); + return _retvalStr; +} + +int32 CefDownloadItemCToCpp::GetId() { + if (CEF_MEMBER_MISSING(struct_, get_id)) + return 0; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + int32 _retval = struct_->get_id(struct_); + + // Return type: simple + return _retval; +} + +CefString CefDownloadItemCToCpp::GetURL() { + if (CEF_MEMBER_MISSING(struct_, get_url)) + return CefString(); + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + cef_string_userfree_t _retval = struct_->get_url(struct_); + + // Return type: string + CefString _retvalStr; + _retvalStr.AttachToUserFree(_retval); + return _retvalStr; +} + +CefString CefDownloadItemCToCpp::GetSuggestedFileName() { + if (CEF_MEMBER_MISSING(struct_, get_suggested_file_name)) + return CefString(); + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + cef_string_userfree_t _retval = struct_->get_suggested_file_name(struct_); + + // Return type: string + CefString _retvalStr; + _retvalStr.AttachToUserFree(_retval); + return _retvalStr; +} + +CefString CefDownloadItemCToCpp::GetContentDisposition() { + if (CEF_MEMBER_MISSING(struct_, get_content_disposition)) + return CefString(); + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + cef_string_userfree_t _retval = struct_->get_content_disposition(struct_); + + // Return type: string + CefString _retvalStr; + _retvalStr.AttachToUserFree(_retval); + return _retvalStr; +} + +CefString CefDownloadItemCToCpp::GetMimeType() { + if (CEF_MEMBER_MISSING(struct_, get_mime_type)) + return CefString(); + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + cef_string_userfree_t _retval = struct_->get_mime_type(struct_); + + // Return type: string + CefString _retvalStr; + _retvalStr.AttachToUserFree(_retval); + return _retvalStr; +} + +CefString CefDownloadItemCToCpp::GetReferrerCharset() { + if (CEF_MEMBER_MISSING(struct_, get_referrer_charset)) + return CefString(); + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + cef_string_userfree_t _retval = struct_->get_referrer_charset(struct_); + + // Return type: string + CefString _retvalStr; + _retvalStr.AttachToUserFree(_retval); + return _retvalStr; +} + + +#ifndef NDEBUG +template<> long CefCToCpp::DebugObjCt = 0; +#endif + diff --git a/libcef_dll/ctocpp/download_item_ctocpp.h b/libcef_dll/ctocpp/download_item_ctocpp.h new file mode 100644 index 000000000..ff42472ba --- /dev/null +++ b/libcef_dll/ctocpp/download_item_ctocpp.h @@ -0,0 +1,58 @@ +// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights +// reserved. Use of this source code is governed by a BSD-style license that +// can be found in the LICENSE file. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool. If making changes by +// hand only do so within the body of existing method and function +// implementations. See the translator.README.txt file in the tools directory +// for more information. +// + +#ifndef CEF_LIBCEF_DLL_CTOCPP_DOWNLOAD_ITEM_CTOCPP_H_ +#define CEF_LIBCEF_DLL_CTOCPP_DOWNLOAD_ITEM_CTOCPP_H_ +#pragma once + +#ifndef USING_CEF_SHARED +#pragma message("Warning: "__FILE__" may be accessed wrapper-side only") +#else // USING_CEF_SHARED + +#include "include/cef_download_item.h" +#include "include/capi/cef_download_item_capi.h" +#include "libcef_dll/ctocpp/ctocpp.h" + +// Wrap a C structure with a C++ class. +// This class may be instantiated and accessed wrapper-side only. +class CefDownloadItemCToCpp + : public CefCToCpp { + public: + explicit CefDownloadItemCToCpp(cef_download_item_t* str) + : CefCToCpp( + str) {} + virtual ~CefDownloadItemCToCpp() {} + + // CefDownloadItem methods + virtual bool IsValid() OVERRIDE; + virtual bool IsInProgress() OVERRIDE; + virtual bool IsComplete() OVERRIDE; + virtual bool IsCanceled() OVERRIDE; + virtual int64 GetCurrentSpeed() OVERRIDE; + virtual int GetPercentComplete() OVERRIDE; + virtual int64 GetTotalBytes() OVERRIDE; + virtual int64 GetReceivedBytes() OVERRIDE; + virtual CefTime GetStartTime() OVERRIDE; + virtual CefTime GetEndTime() OVERRIDE; + virtual CefString GetFullPath() OVERRIDE; + virtual int32 GetId() OVERRIDE; + virtual CefString GetURL() OVERRIDE; + virtual CefString GetSuggestedFileName() OVERRIDE; + virtual CefString GetContentDisposition() OVERRIDE; + virtual CefString GetMimeType() OVERRIDE; + virtual CefString GetReferrerCharset() OVERRIDE; +}; + +#endif // USING_CEF_SHARED +#endif // CEF_LIBCEF_DLL_CTOCPP_DOWNLOAD_ITEM_CTOCPP_H_ + diff --git a/libcef_dll/libcef_dll.cc b/libcef_dll/libcef_dll.cc index c7e1af4ec..342fa2260 100644 --- a/libcef_dll/libcef_dll.cc +++ b/libcef_dll/libcef_dll.cc @@ -29,6 +29,7 @@ #include "include/cef_web_plugin.h" #include "include/capi/cef_web_plugin_capi.h" #include "libcef_dll/cpptoc/auth_callback_cpptoc.h" +#include "libcef_dll/cpptoc/before_download_callback_cpptoc.h" #include "libcef_dll/cpptoc/binary_value_cpptoc.h" #include "libcef_dll/cpptoc/browser_cpptoc.h" #include "libcef_dll/cpptoc/browser_host_cpptoc.h" @@ -40,6 +41,8 @@ #include "libcef_dll/cpptoc/domevent_cpptoc.h" #include "libcef_dll/cpptoc/domnode_cpptoc.h" #include "libcef_dll/cpptoc/dictionary_value_cpptoc.h" +#include "libcef_dll/cpptoc/download_item_cpptoc.h" +#include "libcef_dll/cpptoc/download_item_callback_cpptoc.h" #include "libcef_dll/cpptoc/frame_cpptoc.h" #include "libcef_dll/cpptoc/geolocation_callback_cpptoc.h" #include "libcef_dll/cpptoc/jsdialog_callback_cpptoc.h" @@ -63,6 +66,7 @@ #include "libcef_dll/ctocpp/domevent_listener_ctocpp.h" #include "libcef_dll/ctocpp/domvisitor_ctocpp.h" #include "libcef_dll/ctocpp/display_handler_ctocpp.h" +#include "libcef_dll/ctocpp/download_handler_ctocpp.h" #include "libcef_dll/ctocpp/focus_handler_ctocpp.h" #include "libcef_dll/ctocpp/geolocation_handler_ctocpp.h" #include "libcef_dll/ctocpp/jsdialog_handler_ctocpp.h" @@ -153,6 +157,7 @@ CEF_EXPORT void cef_shutdown() { #ifndef NDEBUG // Check that all wrapper objects have been destroyed DCHECK_EQ(CefAuthCallbackCppToC::DebugObjCt, 0); + DCHECK_EQ(CefBeforeDownloadCallbackCppToC::DebugObjCt, 0); DCHECK_EQ(CefBinaryValueCppToC::DebugObjCt, 0); DCHECK_EQ(CefBrowserCppToC::DebugObjCt, 0); DCHECK_EQ(CefBrowserHostCppToC::DebugObjCt, 0); @@ -169,6 +174,9 @@ CEF_EXPORT void cef_shutdown() { DCHECK_EQ(CefDOMVisitorCToCpp::DebugObjCt, 0); DCHECK_EQ(CefDictionaryValueCppToC::DebugObjCt, 0); DCHECK_EQ(CefDisplayHandlerCToCpp::DebugObjCt, 0); + DCHECK_EQ(CefDownloadHandlerCToCpp::DebugObjCt, 0); + DCHECK_EQ(CefDownloadItemCallbackCppToC::DebugObjCt, 0); + DCHECK_EQ(CefDownloadItemCppToC::DebugObjCt, 0); DCHECK_EQ(CefFocusHandlerCToCpp::DebugObjCt, 0); DCHECK_EQ(CefFrameCppToC::DebugObjCt, 0); DCHECK_EQ(CefGeolocationCallbackCppToC::DebugObjCt, 0); diff --git a/libcef_dll/wrapper/libcef_dll_wrapper.cc b/libcef_dll/wrapper/libcef_dll_wrapper.cc index ef5a0aebc..87e9973a5 100644 --- a/libcef_dll/wrapper/libcef_dll_wrapper.cc +++ b/libcef_dll/wrapper/libcef_dll_wrapper.cc @@ -36,6 +36,7 @@ #include "libcef_dll/cpptoc/domevent_listener_cpptoc.h" #include "libcef_dll/cpptoc/domvisitor_cpptoc.h" #include "libcef_dll/cpptoc/display_handler_cpptoc.h" +#include "libcef_dll/cpptoc/download_handler_cpptoc.h" #include "libcef_dll/cpptoc/focus_handler_cpptoc.h" #include "libcef_dll/cpptoc/geolocation_handler_cpptoc.h" #include "libcef_dll/cpptoc/jsdialog_handler_cpptoc.h" @@ -57,6 +58,7 @@ #include "libcef_dll/cpptoc/web_plugin_info_visitor_cpptoc.h" #include "libcef_dll/cpptoc/write_handler_cpptoc.h" #include "libcef_dll/ctocpp/auth_callback_ctocpp.h" +#include "libcef_dll/ctocpp/before_download_callback_ctocpp.h" #include "libcef_dll/ctocpp/binary_value_ctocpp.h" #include "libcef_dll/ctocpp/browser_ctocpp.h" #include "libcef_dll/ctocpp/browser_host_ctocpp.h" @@ -68,6 +70,8 @@ #include "libcef_dll/ctocpp/domevent_ctocpp.h" #include "libcef_dll/ctocpp/domnode_ctocpp.h" #include "libcef_dll/ctocpp/dictionary_value_ctocpp.h" +#include "libcef_dll/ctocpp/download_item_ctocpp.h" +#include "libcef_dll/ctocpp/download_item_callback_ctocpp.h" #include "libcef_dll/ctocpp/frame_ctocpp.h" #include "libcef_dll/ctocpp/geolocation_callback_ctocpp.h" #include "libcef_dll/ctocpp/jsdialog_callback_ctocpp.h" @@ -145,6 +149,7 @@ CEF_GLOBAL void CefShutdown() { #ifndef NDEBUG // Check that all wrapper objects have been destroyed DCHECK_EQ(CefAuthCallbackCToCpp::DebugObjCt, 0); + DCHECK_EQ(CefBeforeDownloadCallbackCToCpp::DebugObjCt, 0); DCHECK_EQ(CefBinaryValueCToCpp::DebugObjCt, 0); DCHECK_EQ(CefBrowserCToCpp::DebugObjCt, 0); DCHECK_EQ(CefBrowserHostCToCpp::DebugObjCt, 0); @@ -161,6 +166,9 @@ CEF_GLOBAL void CefShutdown() { DCHECK_EQ(CefDOMVisitorCppToC::DebugObjCt, 0); DCHECK_EQ(CefDictionaryValueCToCpp::DebugObjCt, 0); DCHECK_EQ(CefDisplayHandlerCppToC::DebugObjCt, 0); + DCHECK_EQ(CefDownloadHandlerCppToC::DebugObjCt, 0); + DCHECK_EQ(CefDownloadItemCToCpp::DebugObjCt, 0); + DCHECK_EQ(CefDownloadItemCallbackCToCpp::DebugObjCt, 0); DCHECK_EQ(CefFocusHandlerCppToC::DebugObjCt, 0); DCHECK_EQ(CefFrameCToCpp::DebugObjCt, 0); DCHECK_EQ(CefGeolocationCallbackCToCpp::DebugObjCt, 0); diff --git a/tests/cefclient/client_handler.cpp b/tests/cefclient/client_handler.cpp index d09669150..e65bd98d3 100644 --- a/tests/cefclient/client_handler.cpp +++ b/tests/cefclient/client_handler.cpp @@ -179,6 +179,27 @@ bool ClientHandler::OnConsoleMessage(CefRefPtr browser, return false; } +void ClientHandler::OnBeforeDownload( + CefRefPtr browser, + CefRefPtr download_item, + const CefString& suggested_name, + CefRefPtr callback) { + REQUIRE_UI_THREAD(); + // Continue the download and show the "Save As" dialog. + callback->Continue(GetDownloadPath(suggested_name), true); +} + +void ClientHandler::OnDownloadUpdated( + CefRefPtr browser, + CefRefPtr download_item, + CefRefPtr callback) { + REQUIRE_UI_THREAD(); + if (download_item->IsComplete()) { + SetLastDownloadFile(download_item->GetFullPath()); + SendNotification(NOTIFY_DOWNLOAD_COMPLETE); + } +} + void ClientHandler::OnRequestGeolocationPermission( CefRefPtr browser, const CefString& requesting_url, diff --git a/tests/cefclient/client_handler.h b/tests/cefclient/client_handler.h index edd1c710a..52c04e618 100644 --- a/tests/cefclient/client_handler.h +++ b/tests/cefclient/client_handler.h @@ -22,6 +22,7 @@ class ClientHandler : public CefClient, public CefContextMenuHandler, public CefDisplayHandler, + public CefDownloadHandler, public CefGeolocationHandler, public CefKeyboardHandler, public CefLifeSpanHandler, @@ -74,6 +75,9 @@ class ClientHandler : public CefClient, virtual CefRefPtr GetDisplayHandler() OVERRIDE { return this; } + virtual CefRefPtr GetDownloadHandler() OVERRIDE { + return this; + } virtual CefRefPtr GetGeolocationHandler() OVERRIDE { return this; } @@ -120,6 +124,17 @@ class ClientHandler : public CefClient, const CefString& source, int line) OVERRIDE; + // CefDownloadHandler methods + virtual void OnBeforeDownload( + CefRefPtr browser, + CefRefPtr download_item, + const CefString& suggested_name, + CefRefPtr callback) OVERRIDE; + virtual void OnDownloadUpdated( + CefRefPtr browser, + CefRefPtr download_item, + CefRefPtr callback) OVERRIDE; + // CefGeolocationHandler methods virtual void OnRequestGeolocationPermission( CefRefPtr browser, @@ -215,6 +230,10 @@ class ClientHandler : public CefClient, int radio_item; } m_TestMenuState; + // Returns the full download path for the specified file, or an empty path to + // use the default temp directory. + std::string GetDownloadPath(const std::string& file_name); + // The child browser window CefRefPtr m_Browser; diff --git a/tests/cefclient/client_handler_gtk.cpp b/tests/cefclient/client_handler_gtk.cpp index 1b60df7e6..a35b04e61 100644 --- a/tests/cefclient/client_handler_gtk.cpp +++ b/tests/cefclient/client_handler_gtk.cpp @@ -57,3 +57,7 @@ void ClientHandler::SetNavState(bool canGoBack, bool canGoForward) { void ClientHandler::CloseMainWindow() { // TODO(port): Close main window. } + +std::string ClientHandler::GetDownloadPath(const std::string& file_name) { + return std::string(); +} diff --git a/tests/cefclient/client_handler_mac.mm b/tests/cefclient/client_handler_mac.mm index 8df19d0c7..fba1ddd2c 100644 --- a/tests/cefclient/client_handler_mac.mm +++ b/tests/cefclient/client_handler_mac.mm @@ -68,3 +68,7 @@ void ClientHandler::SetNavState(bool canGoBack, bool canGoForward) { void ClientHandler::CloseMainWindow() { // TODO(port): Close window } + +std::string ClientHandler::GetDownloadPath(const std::string& file_name) { + return std::string(); +} diff --git a/tests/cefclient/client_handler_win.cpp b/tests/cefclient/client_handler_win.cpp index 7be458666..fe9944255 100644 --- a/tests/cefclient/client_handler_win.cpp +++ b/tests/cefclient/client_handler_win.cpp @@ -3,7 +3,11 @@ // can be found in the LICENSE file. #include "cefclient/client_handler.h" + #include +#include +#include + #include "include/cef_browser.h" #include "include/cef_frame.h" #include "cefclient/resource.h" @@ -66,3 +70,17 @@ void ClientHandler::SetNavState(bool canGoBack, bool canGoForward) { void ClientHandler::CloseMainWindow() { ::PostMessage(m_MainHwnd, WM_CLOSE, 0, 0); } + +std::string ClientHandler::GetDownloadPath(const std::string& file_name) { + TCHAR szFolderPath[MAX_PATH]; + std::string path; + + // Save the file in the user's "My Documents" folder. + if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL | CSIDL_FLAG_CREATE, + NULL, 0, szFolderPath))) { + path = CefString(szFolderPath); + path += "\\" + file_name; + } + + return path; +}