From 9aa285ac8d148e91f295ba8ae0655fc4dfa414c4 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Sat, 16 Oct 2010 19:10:11 +0000 Subject: [PATCH] - Add the CefHandler::HandleDownloadResponse() method and CefDownloadHandler class to support file download in response to 'Content-Disposition' headers (issue #6). - Fix parsing error in cef_parser.py due to space between angle brackets in template type definitions, and add support for int64 type. - Update copyright messages in Python and generated files. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@117 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- cef.gyp | 7 + include/cef.h | 31 +++ include/cef_capi.h | 32 ++- include/cef_types.h | 7 + libcef/browser_resource_loader_bridge.cc | 36 +++ libcef/browser_webkit_glue.cc | 17 ++ libcef/browser_webkit_glue.h | 5 + libcef/browser_webkit_glue_win.cc | 4 - libcef_dll/cpptoc/browser_cpptoc.cc | 2 +- libcef_dll/cpptoc/browser_cpptoc.h | 2 +- libcef_dll/cpptoc/download_handler_cpptoc.cc | 53 ++++ libcef_dll/cpptoc/download_handler_cpptoc.h | 35 +++ libcef_dll/cpptoc/frame_cpptoc.cc | 2 +- libcef_dll/cpptoc/frame_cpptoc.h | 2 +- libcef_dll/cpptoc/handler_cpptoc.cc | 34 ++- libcef_dll/cpptoc/handler_cpptoc.h | 2 +- libcef_dll/cpptoc/post_data_cpptoc.cc | 2 +- libcef_dll/cpptoc/post_data_cpptoc.h | 2 +- libcef_dll/cpptoc/post_data_element_cpptoc.cc | 2 +- libcef_dll/cpptoc/post_data_element_cpptoc.h | 2 +- libcef_dll/cpptoc/read_handler_cpptoc.cc | 2 +- libcef_dll/cpptoc/read_handler_cpptoc.h | 2 +- libcef_dll/cpptoc/request_cpptoc.cc | 2 +- libcef_dll/cpptoc/request_cpptoc.h | 2 +- libcef_dll/cpptoc/scheme_handler_cpptoc.cc | 2 +- libcef_dll/cpptoc/scheme_handler_cpptoc.h | 2 +- .../cpptoc/scheme_handler_factory_cpptoc.cc | 2 +- .../cpptoc/scheme_handler_factory_cpptoc.h | 2 +- libcef_dll/cpptoc/stream_reader_cpptoc.cc | 2 +- libcef_dll/cpptoc/stream_reader_cpptoc.h | 2 +- libcef_dll/cpptoc/stream_writer_cpptoc.cc | 2 +- libcef_dll/cpptoc/stream_writer_cpptoc.h | 2 +- libcef_dll/cpptoc/task_cpptoc.cc | 2 +- libcef_dll/cpptoc/task_cpptoc.h | 2 +- libcef_dll/cpptoc/v8handler_cpptoc.cc | 2 +- libcef_dll/cpptoc/v8handler_cpptoc.h | 2 +- libcef_dll/cpptoc/v8value_cpptoc.cc | 2 +- libcef_dll/cpptoc/v8value_cpptoc.h | 2 +- libcef_dll/cpptoc/write_handler_cpptoc.cc | 2 +- libcef_dll/cpptoc/write_handler_cpptoc.h | 2 +- libcef_dll/ctocpp/browser_ctocpp.cc | 2 +- libcef_dll/ctocpp/browser_ctocpp.h | 2 +- libcef_dll/ctocpp/download_handler_ctocpp.cc | 39 +++ libcef_dll/ctocpp/download_handler_ctocpp.h | 42 ++++ libcef_dll/ctocpp/frame_ctocpp.cc | 2 +- libcef_dll/ctocpp/frame_ctocpp.h | 2 +- libcef_dll/ctocpp/handler_ctocpp.cc | 23 +- libcef_dll/ctocpp/handler_ctocpp.h | 5 +- libcef_dll/ctocpp/post_data_ctocpp.cc | 2 +- libcef_dll/ctocpp/post_data_ctocpp.h | 2 +- libcef_dll/ctocpp/post_data_element_ctocpp.cc | 2 +- libcef_dll/ctocpp/post_data_element_ctocpp.h | 2 +- libcef_dll/ctocpp/read_handler_ctocpp.cc | 2 +- libcef_dll/ctocpp/read_handler_ctocpp.h | 2 +- libcef_dll/ctocpp/request_ctocpp.cc | 2 +- libcef_dll/ctocpp/request_ctocpp.h | 2 +- libcef_dll/ctocpp/scheme_handler_ctocpp.cc | 2 +- libcef_dll/ctocpp/scheme_handler_ctocpp.h | 2 +- .../ctocpp/scheme_handler_factory_ctocpp.cc | 2 +- .../ctocpp/scheme_handler_factory_ctocpp.h | 2 +- libcef_dll/ctocpp/stream_reader_ctocpp.cc | 2 +- libcef_dll/ctocpp/stream_reader_ctocpp.h | 2 +- libcef_dll/ctocpp/stream_writer_ctocpp.cc | 2 +- libcef_dll/ctocpp/stream_writer_ctocpp.h | 2 +- libcef_dll/ctocpp/task_ctocpp.cc | 2 +- libcef_dll/ctocpp/task_ctocpp.h | 2 +- libcef_dll/ctocpp/v8handler_ctocpp.cc | 2 +- libcef_dll/ctocpp/v8handler_ctocpp.h | 2 +- libcef_dll/ctocpp/v8value_ctocpp.cc | 2 +- libcef_dll/ctocpp/v8value_ctocpp.h | 2 +- libcef_dll/ctocpp/write_handler_ctocpp.cc | 2 +- libcef_dll/ctocpp/write_handler_ctocpp.h | 2 +- tests/cefclient/cefclient.cpp | 85 ++++++- tests/cefclient/download_handler.cpp | 229 ++++++++++++++++++ tests/cefclient/download_handler.h | 21 ++ tests/cefclient/resource.h | 6 +- tests/cefclient/resource_util.h | 4 +- tests/cefclient/util.h | 48 ++++ tests/unittests/test_handler.h | 9 + tools/cef_parser.py | 6 +- tools/make_capi_header.py | 4 +- tools/make_cpptoc_header.py | 4 +- tools/make_cpptoc_impl.py | 4 +- tools/make_ctocpp_header.py | 4 +- tools/make_ctocpp_impl.py | 4 +- 85 files changed, 831 insertions(+), 81 deletions(-) create mode 100644 libcef_dll/cpptoc/download_handler_cpptoc.cc create mode 100644 libcef_dll/cpptoc/download_handler_cpptoc.h create mode 100644 libcef_dll/ctocpp/download_handler_ctocpp.cc create mode 100644 libcef_dll/ctocpp/download_handler_ctocpp.h create mode 100644 tests/cefclient/download_handler.cpp create mode 100644 tests/cefclient/download_handler.h create mode 100644 tests/cefclient/util.h diff --git a/cef.gyp b/cef.gyp index 81e3d33e0..9a8a8ab8c 100644 --- a/cef.gyp +++ b/cef.gyp @@ -33,6 +33,8 @@ 'tests/cefclient/cefclient.rc', 'tests/cefclient/clientplugin.cpp', 'tests/cefclient/clientplugin.h', + 'tests/cefclient/download_handler.cpp', + 'tests/cefclient/download_handler.h', 'tests/cefclient/extension_test.cpp', 'tests/cefclient/extension_test.h', 'tests/cefclient/plugin_test.cpp', @@ -52,6 +54,7 @@ 'tests/cefclient/uiplugin.h', 'tests/cefclient/uiplugin_test.cpp', 'tests/cefclient/uiplugin_test.h', + 'tests/cefclient/util.h', ], 'conditions': [ ['OS=="win"', { @@ -214,6 +217,8 @@ 'libcef_dll/cpptoc/v8value_cpptoc.cc', 'libcef_dll/cpptoc/v8value_cpptoc.h', 'libcef_dll/ctocpp/ctocpp.h', + 'libcef_dll/ctocpp/download_handler_ctocpp.cc', + 'libcef_dll/ctocpp/download_handler_ctocpp.h', 'libcef_dll/ctocpp/handler_ctocpp.cc', 'libcef_dll/ctocpp/handler_ctocpp.h', 'libcef_dll/ctocpp/read_handler_ctocpp.cc', @@ -271,6 +276,8 @@ 'sources': [ 'libcef_dll/cef_logging.h', 'libcef_dll/cpptoc/cpptoc.h', + 'libcef_dll/cpptoc/download_handler_cpptoc.cc', + 'libcef_dll/cpptoc/download_handler_cpptoc.h', 'libcef_dll/cpptoc/handler_cpptoc.cc', 'libcef_dll/cpptoc/handler_cpptoc.h', 'libcef_dll/cpptoc/read_handler_cpptoc.cc', diff --git a/include/cef.h b/include/cef.h index e3586ae74..8155c8da9 100644 --- a/include/cef.h +++ b/include/cef.h @@ -45,6 +45,7 @@ #include "cef_types.h" class CefBrowser; +class CefDownloadHandler; class CefFrame; class CefHandler; class CefPostData; @@ -617,6 +618,20 @@ public: std::wstring& mimeType, int loadFlags) =0; + // Called when a server indicates via the 'Content-Disposition' header that a + // response represents a file to download. |mimeType| is the mime type for + // the download, |fileName| is the suggested target file name and + // |contentLength| is either the value of the 'Content-Size' header or -1 if + // no size was provided. Set |handler| to the CefDownloadHandler instance that + // will recieve the file contents. Return RV_CONTINUE to download the file + // or RV_HANDLED to cancel the file download. + /*--cef()--*/ + virtual RetVal HandleDownloadResponse(CefRefPtr browser, + const std::wstring& mimeType, + const std::wstring& fileName, + int64 contentLength, + CefRefPtr& handler) =0; + // Structure representing menu information. typedef cef_handler_menuinfo_t MenuInfo; @@ -1201,4 +1216,20 @@ public: }; +// Class used to handle file downloads. +/*--cef(source=client)--*/ +class CefDownloadHandler : public CefBase +{ +public: + // A portion of the file contents have been received. This method will be + // called multiple times until the download is complete. Return |true| to + // continue receiving data and |false| to cancel. + /*--cef()--*/ + virtual bool ReceivedData(void* data, int data_size) =0; + + // The download is complete. + /*--cef()--*/ + virtual void Complete() =0; +}; + #endif // _CEF_H diff --git a/include/cef_capi.h b/include/cef_capi.h index 5a8ed951f..cfd08d484 100644 --- a/include/cef_capi.h +++ b/include/cef_capi.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 Marshall A. Greenblatt. All rights reserved. +// Copyright (c) 2010 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 @@ -445,6 +445,18 @@ typedef struct _cef_handler_t struct _cef_stream_reader_t** resourceStream, cef_string_t* mimeType, int loadFlags); + // Called when a server indicates via the 'Content-Disposition' header that a + // response represents a file to download. |mimeType| is the mime type for the + // download, |fileName| is the suggested target file name and |contentLength| + // is either the value of the 'Content-Size' header or -1 if no size was + // provided. Set |handler| to the cef_download_handler_t instance that will + // recieve the file contents. Return RV_CONTINUE to download the file or + // RV_HANDLED to cancel the file download. + enum cef_retval_t (CEF_CALLBACK *handle_download_response)( + struct _cef_handler_t* self, struct _cef_browser_t* browser, + const wchar_t* mimeType, const wchar_t* fileName, int64 contentLength, + struct _cef_download_handler_t** handler); + // Event called before a context menu is displayed. To cancel display of the // default context menu return RV_HANDLED. enum cef_retval_t (CEF_CALLBACK *handle_before_menu)( @@ -974,6 +986,24 @@ typedef struct _cef_scheme_handler_t } cef_scheme_handler_t; +// Structure used to handle file downloads. +typedef struct _cef_download_handler_t +{ + // Base structure. + cef_base_t base; + + // A portion of the file contents have been received. This function will be + // called multiple times until the download is complete. Return |true (1)| to + // continue receiving data and |false (0)| to cancel. + int (CEF_CALLBACK *received_data)(struct _cef_download_handler_t* self, + void* data, int data_size); + + // The download is complete. + void (CEF_CALLBACK *complete)(struct _cef_download_handler_t* self); + +} cef_download_handler_t; + + #ifdef __cplusplus } #endif diff --git a/include/cef_types.h b/include/cef_types.h index def9ca800..18ffb4941 100644 --- a/include/cef_types.h +++ b/include/cef_types.h @@ -45,6 +45,13 @@ extern "C" { #include "cef_types_linux.h" #endif +// The NSPR system headers define 64-bit as |long| when possible. In order to +// not have typedef mismatches, we do the same on LP64. +#if __LP64__ +typedef long int64; +#else +typedef long long int64; +#endif // Define handler return value types. Returning RV_HANDLED indicates // that the implementation completely handled the method and that no further diff --git a/libcef/browser_resource_loader_bridge.cc b/libcef/browser_resource_loader_bridge.cc index fba581fde..8fae1dd8a 100644 --- a/libcef/browser_resource_loader_bridge.cc +++ b/libcef/browser_resource_loader_bridge.cc @@ -35,6 +35,7 @@ #include "browser_resource_loader_bridge.h" #include "browser_request_context.h" #include "browser_socket_stream_bridge.h" +#include "browser_webkit_glue.h" #include "browser_impl.h" #include "cef_context.h" #include "cef_process.h" @@ -129,6 +130,11 @@ class RequestProxy : public URLRequest::Delegate, } void Cancel() { + if(download_handler_.get()) { + // WebKit will try to cancel the download but we won't allow it. + return; + } + // proxy over to the io thread CefThread::PostTask(CefThread::IO, FROM_HERE, NewRunnableMethod( this, &RequestProxy::AsyncCancel)); @@ -164,6 +170,22 @@ class RequestProxy : public URLRequest::Delegate, void NotifyReceivedResponse(const ResourceResponseInfo& info, bool content_filtered) { + std::string cd_header, filename; + if (info.headers && browser_.get() && + info.headers->GetNormalizedHeader("Content-Disposition", &cd_header) && + webkit_glue::IsContentDispositionAttachment(cd_header, filename)) { + // The response represents a download request. + CefRefPtr handler = browser_->GetHandler(); + if (handler.get()) { + CefRefPtr dl_handler; + if (handler->HandleDownloadResponse(browser_, + UTF8ToWide(info.mime_type), UTF8ToWide(filename), + info.content_length, dl_handler) == RV_CONTINUE) { + download_handler_ = dl_handler; + } + } + } + if (peer_) peer_->OnReceivedResponse(info, content_filtered); } @@ -186,6 +208,13 @@ class RequestProxy : public URLRequest::Delegate, CefThread::PostTask(CefThread::IO, FROM_HERE, NewRunnableMethod( this, &RequestProxy::AsyncReadData)); + if (download_handler_.get() && + !download_handler_->ReceivedData(buf_copy.get(), bytes_read)) { + // Cancel loading by proxying over to the io thread. + CefThread::PostTask(CefThread::IO, FROM_HERE, NewRunnableMethod( + this, &RequestProxy::AsyncCancel)); + } + peer_->OnReceivedData(buf_copy.get(), bytes_read); } @@ -203,6 +232,11 @@ class RequestProxy : public URLRequest::Delegate, void NotifyCompletedRequest(const URLRequestStatus& status, const std::string& security_info, const base::Time& complete_time) { + if (download_handler_.get()) { + download_handler_->Complete(); + download_handler_ = NULL; + } + if (peer_) { peer_->OnCompletedRequest(status, security_info, complete_time); DropPeer(); // ensure no further notifications @@ -594,6 +628,8 @@ class RequestProxy : public URLRequest::Delegate, // Info used to determine whether or not to send an upload progress update. uint64 last_upload_position_; base::TimeTicks last_upload_ticks_; + + CefRefPtr download_handler_; }; //----------------------------------------------------------------------------- diff --git a/libcef/browser_webkit_glue.cc b/libcef/browser_webkit_glue.cc index a0b9d494a..e302a6901 100644 --- a/libcef/browser_webkit_glue.cc +++ b/libcef/browser_webkit_glue.cc @@ -9,6 +9,7 @@ MSVC_PUSH_WARNING_LEVEL(0); #include "Cache.h" #include "TextEncoding.h" +#include "third_party/WebKit/WebCore/platform/network/HTTPParsers.h" #include "third_party/WebKit/WebKit/chromium/src/WebFrameImpl.h" MSVC_POP_WARNING(); @@ -145,4 +146,20 @@ void EnableSpdy(bool enable) { // Used in benchmarking, Ignored for CEF. } +bool IsContentDispositionAttachment(const std::string& cd_header, + std::string& file_name) { + WTF::String cd_str(cd_header.c_str(), cd_header.length()); + if (WebCore::contentDispositionType(cd_str) == + WebCore::ContentDispositionAttachment) { + WTF::String name_str = + WebCore::filenameFromHTTPContentDisposition(cd_str); + if (!name_str.isEmpty()) { + file_name = WideToUTF8( + std::wstring(name_str.characters(), name_str.length())); + } + return true; + } + return false; +} + } // namespace webkit_glue diff --git a/libcef/browser_webkit_glue.h b/libcef/browser_webkit_glue.h index 7ba641a28..b512546bb 100644 --- a/libcef/browser_webkit_glue.h +++ b/libcef/browser_webkit_glue.h @@ -47,4 +47,9 @@ WebKit::WebString StdWStringToWebString(const std::wstring& str); std::wstring WebStringToStdWString(const WebKit::WebString& str); +// Returns true if the specified 'Content-Disposition' header value represents +// an attachment download. Also returns the file name. +bool IsContentDispositionAttachment(const std::string& cd_header, + std::string& file_name); + } // namespace webkit_glue diff --git a/libcef/browser_webkit_glue_win.cc b/libcef/browser_webkit_glue_win.cc index 20eeb60ac..f51f07823 100644 --- a/libcef/browser_webkit_glue_win.cc +++ b/libcef/browser_webkit_glue_win.cc @@ -74,10 +74,6 @@ bool EnsureFontLoaded(HFONT font) { return true; } -bool DownloadUrl(const std::string& url, HWND caller_window) { - return false; -} - void CaptureWebViewBitmap(HWND mainWnd, WebView* webview, HBITMAP& bitmap, SIZE& size) { diff --git a/libcef_dll/cpptoc/browser_cpptoc.cc b/libcef_dll/cpptoc/browser_cpptoc.cc index a3281c760..c8a447e3c 100644 --- a/libcef_dll/cpptoc/browser_cpptoc.cc +++ b/libcef_dll/cpptoc/browser_cpptoc.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/cpptoc/browser_cpptoc.h b/libcef_dll/cpptoc/browser_cpptoc.h index e0cc26db9..287b15cf8 100644 --- a/libcef_dll/cpptoc/browser_cpptoc.h +++ b/libcef_dll/cpptoc/browser_cpptoc.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/cpptoc/download_handler_cpptoc.cc b/libcef_dll/cpptoc/download_handler_cpptoc.cc new file mode 100644 index 000000000..85cc90ab1 --- /dev/null +++ b/libcef_dll/cpptoc/download_handler_cpptoc.cc @@ -0,0 +1,53 @@ +// Copyright (c) 2010 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. +// +// --------------------------------------------------------------------------- +// +// A portion of this file was generated by the CEF translator tool. When +// making changes by hand only do so within the body of existing function +// implementations. See the translator.README.txt file in the tools directory +// for more information. +// + +#include "libcef_dll/cpptoc/download_handler_cpptoc.h" + + +// MEMBER FUNCTIONS - Body may be edited by hand. + +int CEF_CALLBACK download_handler_received_data( + struct _cef_download_handler_t* self, void* data, int data_size) +{ + DCHECK(self); + if(!self) + return 0; + + return CefDownloadHandlerCppToC::Get(self)->ReceivedData(data, data_size); +} + +void CEF_CALLBACK download_handler_complete( + struct _cef_download_handler_t* self) +{ + DCHECK(self); + if(!self) + return; + + CefDownloadHandlerCppToC::Get(self)->Complete(); +} + + +// CONSTRUCTOR - Do not edit by hand. + +CefDownloadHandlerCppToC::CefDownloadHandlerCppToC(CefDownloadHandler* cls) + : CefCppToC(cls) +{ + struct_.struct_.received_data = download_handler_received_data; + struct_.struct_.complete = download_handler_complete; +} + +#ifdef _DEBUG +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..737aecdf9 --- /dev/null +++ b/libcef_dll/cpptoc/download_handler_cpptoc.h @@ -0,0 +1,35 @@ +// Copyright (c) 2010 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 and should not edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// +#ifndef _DOWNLOADHANDLER_CPPTOC_H +#define _DOWNLOADHANDLER_CPPTOC_H + +#ifndef USING_CEF_SHARED +#pragma message("Warning: "__FILE__" may be accessed wrapper-side only") +#else // USING_CEF_SHARED + +#include "include/cef.h" +#include "include/cef_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: + CefDownloadHandlerCppToC(CefDownloadHandler* cls); + virtual ~CefDownloadHandlerCppToC() {} +}; + +#endif // USING_CEF_SHARED +#endif // _DOWNLOADHANDLER_CPPTOC_H + diff --git a/libcef_dll/cpptoc/frame_cpptoc.cc b/libcef_dll/cpptoc/frame_cpptoc.cc index ad20abbb3..68a37b050 100644 --- a/libcef_dll/cpptoc/frame_cpptoc.cc +++ b/libcef_dll/cpptoc/frame_cpptoc.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/cpptoc/frame_cpptoc.h b/libcef_dll/cpptoc/frame_cpptoc.h index 095ed8e67..e87620e94 100644 --- a/libcef_dll/cpptoc/frame_cpptoc.h +++ b/libcef_dll/cpptoc/frame_cpptoc.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/cpptoc/handler_cpptoc.cc b/libcef_dll/cpptoc/handler_cpptoc.cc index b3b25c01d..da9dac90a 100644 --- a/libcef_dll/cpptoc/handler_cpptoc.cc +++ b/libcef_dll/cpptoc/handler_cpptoc.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // @@ -10,6 +10,7 @@ // for more information. // +#include "libcef_dll/cpptoc/download_handler_cpptoc.h" #include "libcef_dll/cpptoc/handler_cpptoc.h" #include "libcef_dll/ctocpp/browser_ctocpp.h" #include "libcef_dll/ctocpp/frame_ctocpp.h" @@ -228,6 +229,36 @@ enum cef_retval_t CEF_CALLBACK handler_handle_before_resource_load( return rv; } +enum cef_retval_t CEF_CALLBACK handler_handle_download_response( + struct _cef_handler_t* self, cef_browser_t* browser, + const wchar_t* mimeType, const wchar_t* fileName, int64 contentLength, + struct _cef_download_handler_t** handler) +{ + DCHECK(self); + DCHECK(browser); + DCHECK(mimeType); + DCHECK(fileName); + if(!self || !browser || !mimeType || !fileName) + return RV_CONTINUE; + + std::wstring mimeTypeStr, fileNameStr; + CefRefPtr downloadPtr; + + if(mimeType) + mimeTypeStr = mimeType; + if(fileName) + fileNameStr = fileName; + + enum cef_retval_t rv = CefHandlerCppToC::Get(self)-> + HandleDownloadResponse(CefBrowserCToCpp::Wrap(browser), mimeTypeStr, + fileNameStr, contentLength, downloadPtr); + + if(downloadPtr.get()) + *handler = CefDownloadHandlerCppToC::Wrap(downloadPtr); + + return rv; +} + enum cef_retval_t CEF_CALLBACK handler_handle_before_menu( struct _cef_handler_t* self, cef_browser_t* browser, const cef_handler_menuinfo_t* menuInfo) @@ -559,6 +590,7 @@ CefHandlerCppToC::CefHandlerCppToC(CefHandler* cls) struct_.struct_.handle_load_error = handler_handle_load_error; struct_.struct_.handle_before_resource_load = handler_handle_before_resource_load; + struct_.struct_.handle_download_response = handler_handle_download_response; struct_.struct_.handle_before_menu = handler_handle_before_menu; struct_.struct_.handle_get_menu_label = handler_handle_get_menu_label; struct_.struct_.handle_menu_action = handler_handle_menu_action; diff --git a/libcef_dll/cpptoc/handler_cpptoc.h b/libcef_dll/cpptoc/handler_cpptoc.h index 1638f8e70..12a191abf 100644 --- a/libcef_dll/cpptoc/handler_cpptoc.h +++ b/libcef_dll/cpptoc/handler_cpptoc.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/cpptoc/post_data_cpptoc.cc b/libcef_dll/cpptoc/post_data_cpptoc.cc index 2650ba58c..df996243b 100644 --- a/libcef_dll/cpptoc/post_data_cpptoc.cc +++ b/libcef_dll/cpptoc/post_data_cpptoc.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/cpptoc/post_data_cpptoc.h b/libcef_dll/cpptoc/post_data_cpptoc.h index ed72580f7..13a644491 100644 --- a/libcef_dll/cpptoc/post_data_cpptoc.h +++ b/libcef_dll/cpptoc/post_data_cpptoc.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/cpptoc/post_data_element_cpptoc.cc b/libcef_dll/cpptoc/post_data_element_cpptoc.cc index 66efc329f..b53544b0f 100644 --- a/libcef_dll/cpptoc/post_data_element_cpptoc.cc +++ b/libcef_dll/cpptoc/post_data_element_cpptoc.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/cpptoc/post_data_element_cpptoc.h b/libcef_dll/cpptoc/post_data_element_cpptoc.h index 0da1a2706..9be615b65 100644 --- a/libcef_dll/cpptoc/post_data_element_cpptoc.h +++ b/libcef_dll/cpptoc/post_data_element_cpptoc.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/cpptoc/read_handler_cpptoc.cc b/libcef_dll/cpptoc/read_handler_cpptoc.cc index ea9a5a123..b6dc134e2 100644 --- a/libcef_dll/cpptoc/read_handler_cpptoc.cc +++ b/libcef_dll/cpptoc/read_handler_cpptoc.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/cpptoc/read_handler_cpptoc.h b/libcef_dll/cpptoc/read_handler_cpptoc.h index dba1ffd5c..04118b261 100644 --- a/libcef_dll/cpptoc/read_handler_cpptoc.h +++ b/libcef_dll/cpptoc/read_handler_cpptoc.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/cpptoc/request_cpptoc.cc b/libcef_dll/cpptoc/request_cpptoc.cc index 355469497..9420fb296 100644 --- a/libcef_dll/cpptoc/request_cpptoc.cc +++ b/libcef_dll/cpptoc/request_cpptoc.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/cpptoc/request_cpptoc.h b/libcef_dll/cpptoc/request_cpptoc.h index 15688dc3b..7d6165a0a 100644 --- a/libcef_dll/cpptoc/request_cpptoc.h +++ b/libcef_dll/cpptoc/request_cpptoc.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/cpptoc/scheme_handler_cpptoc.cc b/libcef_dll/cpptoc/scheme_handler_cpptoc.cc index bb665a186..8ea6ea691 100644 --- a/libcef_dll/cpptoc/scheme_handler_cpptoc.cc +++ b/libcef_dll/cpptoc/scheme_handler_cpptoc.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/cpptoc/scheme_handler_cpptoc.h b/libcef_dll/cpptoc/scheme_handler_cpptoc.h index 0e1cc55c2..3c4eb9350 100644 --- a/libcef_dll/cpptoc/scheme_handler_cpptoc.h +++ b/libcef_dll/cpptoc/scheme_handler_cpptoc.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/cpptoc/scheme_handler_factory_cpptoc.cc b/libcef_dll/cpptoc/scheme_handler_factory_cpptoc.cc index fc461c6c4..905a26b6a 100644 --- a/libcef_dll/cpptoc/scheme_handler_factory_cpptoc.cc +++ b/libcef_dll/cpptoc/scheme_handler_factory_cpptoc.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/cpptoc/scheme_handler_factory_cpptoc.h b/libcef_dll/cpptoc/scheme_handler_factory_cpptoc.h index e444f0606..7397e4bd1 100644 --- a/libcef_dll/cpptoc/scheme_handler_factory_cpptoc.h +++ b/libcef_dll/cpptoc/scheme_handler_factory_cpptoc.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/cpptoc/stream_reader_cpptoc.cc b/libcef_dll/cpptoc/stream_reader_cpptoc.cc index 814170878..f038e574d 100644 --- a/libcef_dll/cpptoc/stream_reader_cpptoc.cc +++ b/libcef_dll/cpptoc/stream_reader_cpptoc.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/cpptoc/stream_reader_cpptoc.h b/libcef_dll/cpptoc/stream_reader_cpptoc.h index 7e0d5c69f..b5757fb44 100644 --- a/libcef_dll/cpptoc/stream_reader_cpptoc.h +++ b/libcef_dll/cpptoc/stream_reader_cpptoc.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/cpptoc/stream_writer_cpptoc.cc b/libcef_dll/cpptoc/stream_writer_cpptoc.cc index b7b27c0b2..d4efa987f 100644 --- a/libcef_dll/cpptoc/stream_writer_cpptoc.cc +++ b/libcef_dll/cpptoc/stream_writer_cpptoc.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/cpptoc/stream_writer_cpptoc.h b/libcef_dll/cpptoc/stream_writer_cpptoc.h index 719f4c4e2..6d26b597f 100644 --- a/libcef_dll/cpptoc/stream_writer_cpptoc.h +++ b/libcef_dll/cpptoc/stream_writer_cpptoc.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/cpptoc/task_cpptoc.cc b/libcef_dll/cpptoc/task_cpptoc.cc index 212a08bcc..2cbfcd1f6 100644 --- a/libcef_dll/cpptoc/task_cpptoc.cc +++ b/libcef_dll/cpptoc/task_cpptoc.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/cpptoc/task_cpptoc.h b/libcef_dll/cpptoc/task_cpptoc.h index 2515be799..84aa3b5e7 100644 --- a/libcef_dll/cpptoc/task_cpptoc.h +++ b/libcef_dll/cpptoc/task_cpptoc.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/cpptoc/v8handler_cpptoc.cc b/libcef_dll/cpptoc/v8handler_cpptoc.cc index a0bf62e23..928bea6d4 100644 --- a/libcef_dll/cpptoc/v8handler_cpptoc.cc +++ b/libcef_dll/cpptoc/v8handler_cpptoc.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/cpptoc/v8handler_cpptoc.h b/libcef_dll/cpptoc/v8handler_cpptoc.h index b9327cf68..6c69c7287 100644 --- a/libcef_dll/cpptoc/v8handler_cpptoc.h +++ b/libcef_dll/cpptoc/v8handler_cpptoc.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/cpptoc/v8value_cpptoc.cc b/libcef_dll/cpptoc/v8value_cpptoc.cc index f3fbf1f2c..44a55a9b1 100644 --- a/libcef_dll/cpptoc/v8value_cpptoc.cc +++ b/libcef_dll/cpptoc/v8value_cpptoc.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/cpptoc/v8value_cpptoc.h b/libcef_dll/cpptoc/v8value_cpptoc.h index 1b08dd705..ba992302b 100644 --- a/libcef_dll/cpptoc/v8value_cpptoc.h +++ b/libcef_dll/cpptoc/v8value_cpptoc.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/cpptoc/write_handler_cpptoc.cc b/libcef_dll/cpptoc/write_handler_cpptoc.cc index 0e09b9ad9..a7ff0764a 100644 --- a/libcef_dll/cpptoc/write_handler_cpptoc.cc +++ b/libcef_dll/cpptoc/write_handler_cpptoc.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/cpptoc/write_handler_cpptoc.h b/libcef_dll/cpptoc/write_handler_cpptoc.h index 7c3a89a68..328aff966 100644 --- a/libcef_dll/cpptoc/write_handler_cpptoc.h +++ b/libcef_dll/cpptoc/write_handler_cpptoc.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/ctocpp/browser_ctocpp.cc b/libcef_dll/ctocpp/browser_ctocpp.cc index 8b61c3947..1901afef8 100644 --- a/libcef_dll/ctocpp/browser_ctocpp.cc +++ b/libcef_dll/ctocpp/browser_ctocpp.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/ctocpp/browser_ctocpp.h b/libcef_dll/ctocpp/browser_ctocpp.h index c5c800529..a00f08546 100644 --- a/libcef_dll/ctocpp/browser_ctocpp.h +++ b/libcef_dll/ctocpp/browser_ctocpp.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/ctocpp/download_handler_ctocpp.cc b/libcef_dll/ctocpp/download_handler_ctocpp.cc new file mode 100644 index 000000000..23aa30c2d --- /dev/null +++ b/libcef_dll/ctocpp/download_handler_ctocpp.cc @@ -0,0 +1,39 @@ +// Copyright (c) 2010 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. +// +// --------------------------------------------------------------------------- +// +// A portion of this file was generated by the CEF translator tool. When +// making changes by hand only do so within the body of existing static and +// virtual method implementations. See the translator.README.txt file in the +// tools directory for more information. +// + +#include "libcef_dll/ctocpp/download_handler_ctocpp.h" + + +// VIRTUAL METHODS - Body may be edited by hand. + +bool CefDownloadHandlerCToCpp::ReceivedData(void* data, int data_size) +{ + if(CEF_MEMBER_MISSING(struct_, received_data)) + return false; + + return struct_->received_data(struct_, data, data_size) ? true : false; +} + +void CefDownloadHandlerCToCpp::Complete() +{ + if(CEF_MEMBER_MISSING(struct_, complete)) + return; + + return struct_->complete(struct_); +} + + +#ifdef _DEBUG +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..3f48f8c72 --- /dev/null +++ b/libcef_dll/ctocpp/download_handler_ctocpp.h @@ -0,0 +1,42 @@ +// Copyright (c) 2010 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 and should not edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// + +#ifndef _DOWNLOADHANDLER_CTOCPP_H +#define _DOWNLOADHANDLER_CTOCPP_H + +#ifndef BUILDING_CEF_SHARED +#pragma message("Warning: "__FILE__" may be accessed DLL-side only") +#else // BUILDING_CEF_SHARED + +#include "include/cef.h" +#include "include/cef_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: + CefDownloadHandlerCToCpp(cef_download_handler_t* str) + : CefCToCpp(str) {} + virtual ~CefDownloadHandlerCToCpp() {} + + // CefDownloadHandler methods + virtual bool ReceivedData(void* data, int data_size); + virtual void Complete(); +}; + +#endif // BUILDING_CEF_SHARED +#endif // _DOWNLOADHANDLER_CTOCPP_H + diff --git a/libcef_dll/ctocpp/frame_ctocpp.cc b/libcef_dll/ctocpp/frame_ctocpp.cc index 0040210b9..8ede39974 100644 --- a/libcef_dll/ctocpp/frame_ctocpp.cc +++ b/libcef_dll/ctocpp/frame_ctocpp.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/ctocpp/frame_ctocpp.h b/libcef_dll/ctocpp/frame_ctocpp.h index 90d865175..0eb02331d 100644 --- a/libcef_dll/ctocpp/frame_ctocpp.h +++ b/libcef_dll/ctocpp/frame_ctocpp.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/ctocpp/handler_ctocpp.cc b/libcef_dll/ctocpp/handler_ctocpp.cc index 24b27ae07..2a47440c9 100644 --- a/libcef_dll/ctocpp/handler_ctocpp.cc +++ b/libcef_dll/ctocpp/handler_ctocpp.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // @@ -15,6 +15,7 @@ #include "libcef_dll/cpptoc/request_cpptoc.h" #include "libcef_dll/cpptoc/stream_reader_cpptoc.h" #include "libcef_dll/cpptoc/v8value_cpptoc.h" +#include "libcef_dll/ctocpp/download_handler_ctocpp.h" #include "libcef_dll/ctocpp/handler_ctocpp.h" #include "libcef_dll/transfer_util.h" @@ -178,6 +179,26 @@ CefHandler::RetVal CefHandlerCToCpp::HandleBeforeResourceLoad( return rv; } +CefHandler::RetVal CefHandlerCToCpp::HandleDownloadResponse( + CefRefPtr browser, const std::wstring& mimeType, + const std::wstring& fileName, int64 contentLength, + CefRefPtr& handler) +{ + if(CEF_MEMBER_MISSING(struct_, handle_download_response)) + return RV_CONTINUE; + + cef_download_handler_t* handlerRet = NULL; + + cef_retval_t rv = struct_->handle_download_response(struct_, + CefBrowserCppToC::Wrap(browser), mimeType.c_str(), fileName.c_str(), + contentLength, &handlerRet); + + if(handlerRet) + handler = CefDownloadHandlerCToCpp::Wrap(handlerRet); + + return rv; +} + CefHandler::RetVal CefHandlerCToCpp::HandleBeforeMenu( CefRefPtr browser, const MenuInfo& menuInfo) { diff --git a/libcef_dll/ctocpp/handler_ctocpp.h b/libcef_dll/ctocpp/handler_ctocpp.h index 5fdaf5896..ac9600474 100644 --- a/libcef_dll/ctocpp/handler_ctocpp.h +++ b/libcef_dll/ctocpp/handler_ctocpp.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // @@ -53,6 +53,9 @@ public: CefRefPtr request, std::wstring& redirectUrl, CefRefPtr& resourceStream, std::wstring& mimeType, int loadFlags); + virtual RetVal HandleDownloadResponse(CefRefPtr browser, + const std::wstring& mimeType, const std::wstring& fileName, + int64 contentLength, CefRefPtr& handler); virtual RetVal HandleBeforeMenu(CefRefPtr browser, const MenuInfo& menuInfo); virtual RetVal HandleGetMenuLabel(CefRefPtr browser, diff --git a/libcef_dll/ctocpp/post_data_ctocpp.cc b/libcef_dll/ctocpp/post_data_ctocpp.cc index 97e3ba3b2..200838eb2 100644 --- a/libcef_dll/ctocpp/post_data_ctocpp.cc +++ b/libcef_dll/ctocpp/post_data_ctocpp.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/ctocpp/post_data_ctocpp.h b/libcef_dll/ctocpp/post_data_ctocpp.h index ff9d17092..4c591104c 100644 --- a/libcef_dll/ctocpp/post_data_ctocpp.h +++ b/libcef_dll/ctocpp/post_data_ctocpp.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/ctocpp/post_data_element_ctocpp.cc b/libcef_dll/ctocpp/post_data_element_ctocpp.cc index 9323f2ba6..c4e4407a6 100644 --- a/libcef_dll/ctocpp/post_data_element_ctocpp.cc +++ b/libcef_dll/ctocpp/post_data_element_ctocpp.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/ctocpp/post_data_element_ctocpp.h b/libcef_dll/ctocpp/post_data_element_ctocpp.h index 10d566e0f..938957150 100644 --- a/libcef_dll/ctocpp/post_data_element_ctocpp.h +++ b/libcef_dll/ctocpp/post_data_element_ctocpp.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/ctocpp/read_handler_ctocpp.cc b/libcef_dll/ctocpp/read_handler_ctocpp.cc index d0b2cd39c..af18f0459 100644 --- a/libcef_dll/ctocpp/read_handler_ctocpp.cc +++ b/libcef_dll/ctocpp/read_handler_ctocpp.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/ctocpp/read_handler_ctocpp.h b/libcef_dll/ctocpp/read_handler_ctocpp.h index 1ec5b7cc5..4de27653e 100644 --- a/libcef_dll/ctocpp/read_handler_ctocpp.h +++ b/libcef_dll/ctocpp/read_handler_ctocpp.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/ctocpp/request_ctocpp.cc b/libcef_dll/ctocpp/request_ctocpp.cc index 3b3dc03bc..2c22cb97d 100644 --- a/libcef_dll/ctocpp/request_ctocpp.cc +++ b/libcef_dll/ctocpp/request_ctocpp.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/ctocpp/request_ctocpp.h b/libcef_dll/ctocpp/request_ctocpp.h index dcfe7527b..738d017c9 100644 --- a/libcef_dll/ctocpp/request_ctocpp.h +++ b/libcef_dll/ctocpp/request_ctocpp.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/ctocpp/scheme_handler_ctocpp.cc b/libcef_dll/ctocpp/scheme_handler_ctocpp.cc index c013036d5..86622e0fb 100644 --- a/libcef_dll/ctocpp/scheme_handler_ctocpp.cc +++ b/libcef_dll/ctocpp/scheme_handler_ctocpp.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/ctocpp/scheme_handler_ctocpp.h b/libcef_dll/ctocpp/scheme_handler_ctocpp.h index 9d36013f5..ec7e0fb43 100644 --- a/libcef_dll/ctocpp/scheme_handler_ctocpp.h +++ b/libcef_dll/ctocpp/scheme_handler_ctocpp.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/ctocpp/scheme_handler_factory_ctocpp.cc b/libcef_dll/ctocpp/scheme_handler_factory_ctocpp.cc index ff97e6a96..536cfd98d 100644 --- a/libcef_dll/ctocpp/scheme_handler_factory_ctocpp.cc +++ b/libcef_dll/ctocpp/scheme_handler_factory_ctocpp.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/ctocpp/scheme_handler_factory_ctocpp.h b/libcef_dll/ctocpp/scheme_handler_factory_ctocpp.h index e32ca4d24..d291c0492 100644 --- a/libcef_dll/ctocpp/scheme_handler_factory_ctocpp.h +++ b/libcef_dll/ctocpp/scheme_handler_factory_ctocpp.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/ctocpp/stream_reader_ctocpp.cc b/libcef_dll/ctocpp/stream_reader_ctocpp.cc index d21266598..2fcc3ba76 100644 --- a/libcef_dll/ctocpp/stream_reader_ctocpp.cc +++ b/libcef_dll/ctocpp/stream_reader_ctocpp.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/ctocpp/stream_reader_ctocpp.h b/libcef_dll/ctocpp/stream_reader_ctocpp.h index 49cb20e10..5b5efdef5 100644 --- a/libcef_dll/ctocpp/stream_reader_ctocpp.h +++ b/libcef_dll/ctocpp/stream_reader_ctocpp.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/ctocpp/stream_writer_ctocpp.cc b/libcef_dll/ctocpp/stream_writer_ctocpp.cc index 899fec99f..4fea40ea7 100644 --- a/libcef_dll/ctocpp/stream_writer_ctocpp.cc +++ b/libcef_dll/ctocpp/stream_writer_ctocpp.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/ctocpp/stream_writer_ctocpp.h b/libcef_dll/ctocpp/stream_writer_ctocpp.h index eddcc5db7..c979bd677 100644 --- a/libcef_dll/ctocpp/stream_writer_ctocpp.h +++ b/libcef_dll/ctocpp/stream_writer_ctocpp.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/ctocpp/task_ctocpp.cc b/libcef_dll/ctocpp/task_ctocpp.cc index ec1c51bf4..e6dbff581 100644 --- a/libcef_dll/ctocpp/task_ctocpp.cc +++ b/libcef_dll/ctocpp/task_ctocpp.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/ctocpp/task_ctocpp.h b/libcef_dll/ctocpp/task_ctocpp.h index bfdc5fb99..4000ad285 100644 --- a/libcef_dll/ctocpp/task_ctocpp.h +++ b/libcef_dll/ctocpp/task_ctocpp.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/ctocpp/v8handler_ctocpp.cc b/libcef_dll/ctocpp/v8handler_ctocpp.cc index c5af7e9f9..03a35b666 100644 --- a/libcef_dll/ctocpp/v8handler_ctocpp.cc +++ b/libcef_dll/ctocpp/v8handler_ctocpp.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/ctocpp/v8handler_ctocpp.h b/libcef_dll/ctocpp/v8handler_ctocpp.h index c907f9047..9cbc7f724 100644 --- a/libcef_dll/ctocpp/v8handler_ctocpp.h +++ b/libcef_dll/ctocpp/v8handler_ctocpp.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/ctocpp/v8value_ctocpp.cc b/libcef_dll/ctocpp/v8value_ctocpp.cc index 623f5d5bc..152ee01d8 100644 --- a/libcef_dll/ctocpp/v8value_ctocpp.cc +++ b/libcef_dll/ctocpp/v8value_ctocpp.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/ctocpp/v8value_ctocpp.h b/libcef_dll/ctocpp/v8value_ctocpp.h index 7e3c8c9ee..05b23aa25 100644 --- a/libcef_dll/ctocpp/v8value_ctocpp.h +++ b/libcef_dll/ctocpp/v8value_ctocpp.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/ctocpp/write_handler_ctocpp.cc b/libcef_dll/ctocpp/write_handler_ctocpp.cc index 3355972a9..3e732ee13 100644 --- a/libcef_dll/ctocpp/write_handler_ctocpp.cc +++ b/libcef_dll/ctocpp/write_handler_ctocpp.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/libcef_dll/ctocpp/write_handler_ctocpp.h b/libcef_dll/ctocpp/write_handler_ctocpp.h index a5fea1010..23b345dab 100644 --- a/libcef_dll/ctocpp/write_handler_ctocpp.h +++ b/libcef_dll/ctocpp/write_handler_ctocpp.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +// Copyright (c) 2010 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. // diff --git a/tests/cefclient/cefclient.cpp b/tests/cefclient/cefclient.cpp index 7ccf1bd80..7942c4ff9 100644 --- a/tests/cefclient/cefclient.cpp +++ b/tests/cefclient/cefclient.cpp @@ -5,12 +5,14 @@ #include "include/cef.h" #include "cefclient.h" #include "binding_test.h" +#include "download_handler.h" #include "extension_test.h" #include "plugin_test.h" #include "resource_util.h" #include "scheme_test.h" #include "string_util.h" #include "uiplugin_test.h" +#include "util.h" #include #include @@ -191,7 +193,35 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) class ClientHandler : public CefThreadSafeBase { public: + // Implements the DownloadListener interface. + class ClientDownloadListener : public CefThreadSafeBase + { + public: + ClientDownloadListener(ClientHandler* handler) : handler_(handler) {} + + // Called when the download is complete. + virtual void NotifyDownloadComplete(const std::wstring& fileName) + { + handler_->SetLastDownloadFile(fileName); + PostMessage(handler_->GetMainHwnd(), WM_COMMAND, + ID_WARN_DOWNLOADCOMPLETE, 0); + } + + // Called if the download fails. + virtual void NotifyDownloadError(const std::wstring& fileName) + { + handler_->SetLastDownloadFile(fileName); + PostMessage(handler_->GetMainHwnd(), WM_COMMAND, + ID_WARN_DOWNLOADERROR, 0); + } + + private: + ClientHandler* handler_; + }; + ClientHandler() + : ALLOW_THIS_IN_INITIALIZER_LIST( + m_DownloadListener(new ClientDownloadListener(this))) { m_MainHwnd = NULL; m_BrowserHwnd = NULL; @@ -399,6 +429,25 @@ public: return RV_CONTINUE; } + // Called when a server indicates via the 'Content-Disposition' header that a + // response represents a file to download. |mime_type| is the mime type for + // the download, |file_name| is the suggested target file name and + // |content_length| is either the value of the 'Content-Size' header or -1 if + // no size was provided. Set |handler| to the CefDownloadHandler instance that + // will recieve the file contents. Return RV_CONTINUE to download the file + // or RV_HANDLED to cancel the file download. + /*--cef()--*/ + virtual RetVal HandleDownloadResponse(CefRefPtr browser, + const std::wstring& mimeType, + const std::wstring& fileName, + int64 contentLength, + CefRefPtr& handler) + { + // Create the handler for the file download. + handler = CreateDownloadHandler(m_DownloadListener, fileName); + return RV_CONTINUE; + } + // Event called before a context menu is displayed. To cancel display of the // default context menu return RV_HANDLED. virtual RetVal HandleBeforeMenu(CefRefPtr browser, @@ -407,7 +456,6 @@ public: return RV_CONTINUE; } - // Event called to optionally override the default text for a context menu // item. |label| contains the default text and may be modified to substitute // alternate text. The return value is currently ignored. @@ -668,6 +716,22 @@ public: return str; } + void SetLastDownloadFile(const std::wstring& fileName) + { + Lock(); + m_LastDownloadFile = fileName; + Unlock(); + } + + std::wstring GetLastDownloadFile() + { + std::wstring str; + Lock(); + str = m_LastDownloadFile; + Unlock(); + return str; + } + protected: // The child browser window CefRefPtr m_Browser; @@ -689,6 +753,10 @@ protected: bool m_bCanGoForward; std::wstring m_LogFile; + + // Support for downloading files. + CefRefPtr m_DownloadListener; + std::wstring m_LastDownloadFile; }; // global handler instance @@ -941,6 +1009,21 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) MB_OK | MB_ICONINFORMATION); } return 0; + case ID_WARN_DOWNLOADCOMPLETE: + case ID_WARN_DOWNLOADERROR: + if(g_handler.get()) { + std::wstringstream ss; + ss << L"File \"" << g_handler->GetLastDownloadFile() << L"\" "; + + if(wmId == ID_WARN_DOWNLOADCOMPLETE) + ss << L"downloaded successfully."; + else + ss << L"failed to download."; + + MessageBoxW(hWnd, ss.str().c_str(), L"File Download", + MB_OK | MB_ICONINFORMATION); + } + return 0; case ID_FIND: if(!hFindDlg) { diff --git a/tests/cefclient/download_handler.cpp b/tests/cefclient/download_handler.cpp new file mode 100644 index 000000000..d41e28d1c --- /dev/null +++ b/tests/cefclient/download_handler.cpp @@ -0,0 +1,229 @@ +// Copyright (c) 2010 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 "download_handler.h" +#include "util.h" +#ifdef _WIN32 +#include +#include +#include +#endif // _WIN32 +#include +#include + +namespace { + +// Template for creating a task that executes a method with no arguments. +template +class Task : public CefThreadSafeBase +{ +public: + Task(T* object, Method method) + : object_(object), method_(method) {} + + virtual void Execute(CefThreadId threadId) + { + (object_->*method_)(); + } + +protected: + CefRefPtr object_; + Method method_; +}; + +// Helper method for posting a task on a specific thread. +template +inline void PostOnThread(CefThreadId threadId, + T* object, + Method method) { + CefRefPtr task = new Task(object, method); + CefPostTask(threadId, task); +} + +} // namespace + +// Implementation of the CefDownloadHandler interface. +class ClientDownloadHandler : public CefThreadSafeBase +{ +public: + ClientDownloadHandler(CefRefPtr listener, + const std::wstring& fileName) + : listener_(listener), filename_(fileName), file_(NULL) + { + // Open the file on the FILE thread. + PostOnThread(TID_FILE, this, &ClientDownloadHandler::OnOpen); + } + + ~ClientDownloadHandler() + { + ASSERT(pending_data_.empty()); + ASSERT(file_ == NULL); + + if(!pending_data_.empty()) { + // Delete remaining pending data. + std::vector*>::iterator it = pending_data_.begin(); + for(; it != pending_data_.end(); ++it) + delete (*it); + } + + if(file_) { + // Close the dangling file pointer on the FILE thread. + class TaskCloseFile : public CefThreadSafeBase + { + public: + TaskCloseFile(FILE* file) : file_(file) {} + virtual void Execute(CefThreadId threadId) { fclose(file_); } + private: + FILE* file_; + }; + CefPostTask(TID_FILE, new TaskCloseFile(file_)); + + // Notify the listener that the download failed. + listener_->NotifyDownloadError(filename_); + } + } + + // -------------------------------------------------- + // The following methods are called on the UI thread. + // -------------------------------------------------- + + // A portion of the file contents have been received. This method will be + // called multiple times until the download is complete. Return |true| to + // continue receiving data and |false| to cancel. + virtual bool ReceivedData(void* data, int data_size) + { + ASSERT(CefCurrentlyOn(TID_UI)); + + if(data_size == 0) + return true; + + // Create a new vector for the data. + std::vector* buffer = new std::vector(data_size); + memcpy(&(*buffer)[0], data, data_size); + + // Add the new data vector to the pending data queue. + Lock(); + pending_data_.push_back(buffer); + Unlock(); + + // Write data to file on the FILE thread. + PostOnThread(TID_FILE, this, &ClientDownloadHandler::OnReceivedData); + return true; + } + + // The download is complete. + virtual void Complete() + { + ASSERT(CefCurrentlyOn(TID_UI)); + + // Flush and close the file on the FILE thread. + PostOnThread(TID_FILE, this, &ClientDownloadHandler::OnComplete); + } + + // ---------------------------------------------------- + // The following methods are called on the FILE thread. + // ---------------------------------------------------- + + void OnOpen() + { + ASSERT(CefCurrentlyOn(TID_FILE)); + + if(file_) + return; + +#ifdef _WIN32 + TCHAR szFolderPath[MAX_PATH]; + + // Save the file in the user's "My Documents" folder. + if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL|CSIDL_FLAG_CREATE, + NULL, 0, szFolderPath))) { + LPWSTR name = PathFindFileName(filename_.c_str()); + LPWSTR ext = PathFindExtension(filename_.c_str()); + int ct = 0; + std::wstringstream ss; + + if(ext) { + name[ext-name] = 0; + ext++; + } + + // Make sure the file name is unique. + do { + if(ct > 0) + ss.str(L""); + ss << szFolderPath << L"\\" << name; + if(ct > 0) + ss << L" (" << ct << L")"; + if(ext) + ss << L"." << ext; + ct++; + } while(PathFileExists(ss.str().c_str())); + + Lock(); + filename_ = ss.str(); + Unlock(); + + file_ = _wfopen(ss.str().c_str(), L"wb"); + ASSERT(file_ != NULL); + } +#endif // _WIN32 + } + + void OnComplete() + { + ASSERT(CefCurrentlyOn(TID_FILE)); + + if(!file_) + return; + + // Make sure any pending data is written. + OnReceivedData(); + + fclose(file_); + file_ = NULL; + + // Notify the listener that the download completed. + listener_->NotifyDownloadComplete(filename_); + } + + void OnReceivedData() + { + ASSERT(CefCurrentlyOn(TID_FILE)); + + std::vector*> data; + + // Remove all data from the pending data queue. + Lock(); + if(!pending_data_.empty()) { + data = pending_data_; + pending_data_.clear(); + } + Unlock(); + + if(data.empty()) + return; + + // Write all pending data to file. + std::vector*>::iterator it = data.begin(); + for(; it != data.end(); ++it) { + std::vector* buffer = *it; + if(file_) + fwrite(&(*buffer)[0], buffer->size(), 1, file_); + delete buffer; + } + data.clear(); + } + +private: + CefRefPtr listener_; + std::wstring filename_; + FILE* file_; + std::vector*> pending_data_; +}; + +CefRefPtr CreateDownloadHandler( + CefRefPtr listener, const std::wstring& fileName) +{ + return new ClientDownloadHandler(listener, fileName); +} diff --git a/tests/cefclient/download_handler.h b/tests/cefclient/download_handler.h new file mode 100644 index 000000000..aef7b69d9 --- /dev/null +++ b/tests/cefclient/download_handler.h @@ -0,0 +1,21 @@ +// Copyright (c) 2010 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. + +#pragma once +#include "include/cef.h" + +// Implement this interface to receive download notifications. +class DownloadListener : public CefBase +{ +public: + // Called when the download is complete. + virtual void NotifyDownloadComplete(const std::wstring& fileName) =0; + + // Called if the download fails. + virtual void NotifyDownloadError(const std::wstring& fileName) =0; +}; + +// Create a new download handler to manage download of a single file. +CefRefPtr CreateDownloadHandler( + CefRefPtr listener, const std::wstring& fileName); diff --git a/tests/cefclient/resource.h b/tests/cefclient/resource.h index 1fbc4b9e6..fd734a451 100644 --- a/tests/cefclient/resource.h +++ b/tests/cefclient/resource.h @@ -22,8 +22,10 @@ #define IDC_NAV_RELOAD 202 #define IDC_NAV_STOP 203 #define ID_WARN_CONSOLEMESSAGE 32000 -#define ID_FIND 32001 -#define ID_PRINT 32002 +#define ID_WARN_DOWNLOADCOMPLETE 32001 +#define ID_WARN_DOWNLOADERROR 32002 +#define ID_FIND 32101 +#define ID_PRINT 32102 #define ID_TESTS_GETSOURCE 32769 #define ID_TESTS_GETTEXT 32770 #define ID_TESTS_JAVASCRIPT_BINDING 32771 diff --git a/tests/cefclient/resource_util.h b/tests/cefclient/resource_util.h index d60384c85..278d1aa64 100644 --- a/tests/cefclient/resource_util.h +++ b/tests/cefclient/resource_util.h @@ -22,11 +22,11 @@ public: // Read raw binary data. virtual size_t Read(void* ptr, size_t size, size_t n); - + // Seek to the specified offset position. |whence| may be any one of // SEEK_CUR, SEEK_END or SEEK_SET. virtual int Seek(long offset, int whence); - + // Return the current offset position. virtual long Tell(); diff --git a/tests/cefclient/util.h b/tests/cefclient/util.h new file mode 100644 index 000000000..42e93fb25 --- /dev/null +++ b/tests/cefclient/util.h @@ -0,0 +1,48 @@ +// Copyright (c) 2010 The Chromium Embedded Framework Authors. +// Portions copyright (c) 2006-2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#pragma once + +#ifdef _WIN32 + +#include + +#ifdef _DEBUG +#define ASSERT(condition) if(!(condition)) { DebugBreak(); } +#else +#define ASSERT(condition) ((void)0) +#endif + +// MSVC_PUSH_DISABLE_WARNING pushes |n| onto a stack of warnings to be disabled. +// The warning remains disabled until popped by MSVC_POP_WARNING. +#define MSVC_PUSH_DISABLE_WARNING(n) __pragma(warning(push)) \ + __pragma(warning(disable:n)) + +// MSVC_PUSH_WARNING_LEVEL pushes |n| as the global warning level. The level +// remains in effect until popped by MSVC_POP_WARNING(). Use 0 to disable all +// warnings. +#define MSVC_PUSH_WARNING_LEVEL(n) __pragma(warning(push, n)) + +// Pop effects of innermost MSVC_PUSH_* macro. +#define MSVC_POP_WARNING() __pragma(warning(pop)) + +// Allows |this| to be passed as an argument in constructor initializer lists. +// This uses push/pop instead of the seemingly simpler suppress feature to avoid +// having the warning be disabled for more than just |code|. +// +// Example usage: +// Foo::Foo() : x(NULL), ALLOW_THIS_IN_INITIALIZER_LIST(y(this)), z(3) {} +// +// Compiler warning C4355: 'this': used in base member initializer list: +// http://msdn.microsoft.com/en-us/library/3c594ae3(VS.80).aspx +#define ALLOW_THIS_IN_INITIALIZER_LIST(code) MSVC_PUSH_DISABLE_WARNING(4355) \ + code \ + MSVC_POP_WARNING() + +#endif // _WIN32 + +#ifndef min +#define min(a,b) ((a)<(b)?(a):(b)) +#endif diff --git a/tests/unittests/test_handler.h b/tests/unittests/test_handler.h index a6c409978..8dfa6d9f8 100644 --- a/tests/unittests/test_handler.h +++ b/tests/unittests/test_handler.h @@ -110,6 +110,15 @@ public: return RV_CONTINUE; } + virtual RetVal HandleDownloadResponse(CefRefPtr browser, + const std::wstring& mimeType, + const std::wstring& fileName, + int64 contentLength, + CefRefPtr& handler) + { + return RV_CONTINUE; + } + virtual RetVal HandleBeforeMenu(CefRefPtr browser, const MenuInfo& menuInfo) { diff --git a/tools/cef_parser.py b/tools/cef_parser.py index 64524df71..4118d5de7 100644 --- a/tools/cef_parser.py +++ b/tools/cef_parser.py @@ -1,4 +1,4 @@ -# Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +# Copyright (c) 2010 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. @@ -410,6 +410,9 @@ class obj_header: # read the input file into memory data = read_file(filename) + # remove space from between template definition end brackets + data = data.replace("> >", ">>") + # extract global typedefs p = re.compile('\ntypedef'+_cre_space+_cre_retval+ _cre_space+_cre_cfname+';', @@ -1065,6 +1068,7 @@ class obj_analysis: simpletypes = { 'void' : 'void', 'int' : 'int', + 'int64' : 'int64', 'double' : 'double', 'long' : 'long', 'unsigned long' : 'unsigned long', diff --git a/tools/make_capi_header.py b/tools/make_capi_header.py index bc29e8df7..b02b37346 100644 --- a/tools/make_capi_header.py +++ b/tools/make_capi_header.py @@ -1,4 +1,4 @@ -# Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +# Copyright (c) 2010 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. @@ -45,7 +45,7 @@ def make_capi_header(header): # header string result = \ -"""// Copyright (c) 2009 Marshall A. Greenblatt. All rights reserved. +"""// Copyright (c) 2010 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 diff --git a/tools/make_cpptoc_header.py b/tools/make_cpptoc_header.py index 9f2bf7f40..f82461f64 100644 --- a/tools/make_cpptoc_header.py +++ b/tools/make_cpptoc_header.py @@ -1,4 +1,4 @@ -# Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +# Copyright (c) 2010 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. @@ -14,7 +14,7 @@ def make_cpptoc_header(header, clsname): capiname = cls.get_capi_name() result = \ -"""// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +"""// Copyright (c) 2010 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. // diff --git a/tools/make_cpptoc_impl.py b/tools/make_cpptoc_impl.py index 060e9bfe1..5c4c99d01 100644 --- a/tools/make_cpptoc_impl.py +++ b/tools/make_cpptoc_impl.py @@ -1,4 +1,4 @@ -# Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +# Copyright (c) 2010 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. @@ -106,7 +106,7 @@ def make_cpptoc_impl(header, clsname, impl): # build the final output result = \ -"""// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +"""// Copyright (c) 2010 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. // diff --git a/tools/make_ctocpp_header.py b/tools/make_ctocpp_header.py index 84c6479a7..8d3f2eef3 100644 --- a/tools/make_ctocpp_header.py +++ b/tools/make_ctocpp_header.py @@ -1,4 +1,4 @@ -# Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +# Copyright (c) 2010 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. @@ -14,7 +14,7 @@ def make_ctocpp_header(header, clsname): capiname = cls.get_capi_name() result = \ -"""// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +"""// Copyright (c) 2010 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. // diff --git a/tools/make_ctocpp_impl.py b/tools/make_ctocpp_impl.py index 063bb5424..f74e905ce 100644 --- a/tools/make_ctocpp_impl.py +++ b/tools/make_ctocpp_impl.py @@ -1,4 +1,4 @@ -# Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +# Copyright (c) 2010 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. @@ -104,7 +104,7 @@ def make_ctocpp_impl(header, clsname, impl): # build the final output result = \ -"""// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights +"""// Copyright (c) 2010 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. //