From 32292ea47df5724985edf89b1fd11d34dfb0117c Mon Sep 17 00:00:00 2001 From: amaitland Date: Fri, 6 Jun 2014 11:26:27 +1000 Subject: [PATCH 01/11] Implement DownloadHandler based on current Cef API. Still needs some work --- CefSharp.Core/Internals/DownloadAdapter.h | 36 ++++++++++++++++------- CefSharp.Example/DownloadHandler.cs | 18 ++++-------- CefSharp/CefSharp.csproj | 1 + CefSharp/DownloadItem.cs | 19 ++++++++++++ CefSharp/IDownloadHandler.cs | 6 ++-- 5 files changed, 54 insertions(+), 26 deletions(-) create mode 100644 CefSharp/DownloadItem.cs diff --git a/CefSharp.Core/Internals/DownloadAdapter.h b/CefSharp.Core/Internals/DownloadAdapter.h index cebd153f3..3ee59a712 100644 --- a/CefSharp.Core/Internals/DownloadAdapter.h +++ b/CefSharp.Core/Internals/DownloadAdapter.h @@ -31,28 +31,44 @@ namespace CefSharp virtual void OnBeforeDownload(CefRefPtr browser, CefRefPtr download_item, const CefString& suggested_name, CefRefPtr callback) OVERRIDE { - // TODO: Could consider making more of the stuff in CefDownloadItem available here to the OnBeforeDownload - // handler. String^ download_path; bool show_dialog; + auto downloadItem = GetDownloadItem(download_item); + downloadItem->SuggestedFileName = StringUtils::ToClr(suggested_name); - if (_handler->OnBeforeDownload(StringUtils::ToClr(suggested_name), download_path, show_dialog)) + if (_handler->OnBeforeDownload(downloadItem, download_path, show_dialog)) { callback->Continue(StringUtils::ToNative(download_path), show_dialog); } }; - virtual bool ReceivedData(void* data, int data_size) + virtual void OnDownloadUpdated(CefRefPtr browser, CefRefPtr download_item, CefRefPtr callback) OVERRIDE { - array^ bytes = gcnew array(data_size); - Marshal::Copy(IntPtr(data), bytes, 0, data_size); - - return _handler->ReceivedData(bytes); + + if (_handler->OnDownloadUpdated(GetDownloadItem(download_item))) + { + callback->Cancel(); + } } - virtual void Complete() + private: + CefSharp::DownloadItem^ GetDownloadItem(CefRefPtr download_item) { - _handler->Complete(); + auto item = gcnew CefSharp::DownloadItem(); + item->Id = download_item->GetId(); + item->Url = StringUtils::ToClr(download_item->GetURL()); + item->MimeType = StringUtils::ToClr(download_item->GetMimeType()); + item->ContentDisposition = StringUtils::ToClr(download_item->GetContentDisposition()); + item->TotalBytes = download_item->GetTotalBytes(); + item->IsComplete = download_item->IsComplete(); + item->IsInProgress = download_item->IsInProgress(); + item->IsCancelled = download_item->IsCanceled(); + item->PercentComplete = download_item->GetPercentComplete(); + item->SuggestedFileName = StringUtils::ToClr(download_item->GetSuggestedFileName()); + item->FullPath = StringUtils::ToClr(download_item->GetFullPath()); + + + return item; } IMPLEMENT_REFCOUNTING(DownloadAdapter); diff --git a/CefSharp.Example/DownloadHandler.cs b/CefSharp.Example/DownloadHandler.cs index 335a9e8cd..3b1963d2e 100644 --- a/CefSharp.Example/DownloadHandler.cs +++ b/CefSharp.Example/DownloadHandler.cs @@ -1,26 +1,18 @@ -using System; -using System.IO; - -namespace CefSharp.Example +namespace CefSharp.Example { internal class DownloadHandler : IDownloadHandler { - public bool OnBeforeDownload(string suggestedName, out string downloadPath, out bool showDialog) + public bool OnBeforeDownload(DownloadItem downloadItem, out string downloadPath, out bool showDialog) { - downloadPath = Path.GetTempPath(); + downloadPath = downloadItem.SuggestedFileName; showDialog = true; return true; } - public bool ReceivedData(byte[] data) + public bool OnDownloadUpdated(DownloadItem downloadItem) { - throw new NotImplementedException(); - } - - public void Complete() - { - throw new NotImplementedException(); + return false; } } } diff --git a/CefSharp/CefSharp.csproj b/CefSharp/CefSharp.csproj index e8085026a..071ce7c44 100644 --- a/CefSharp/CefSharp.csproj +++ b/CefSharp/CefSharp.csproj @@ -89,6 +89,7 @@ + diff --git a/CefSharp/DownloadItem.cs b/CefSharp/DownloadItem.cs new file mode 100644 index 000000000..ad318cfd9 --- /dev/null +++ b/CefSharp/DownloadItem.cs @@ -0,0 +1,19 @@ +using System; + +namespace CefSharp +{ + public class DownloadItem + { + public int Id { get; set; } + public string Url { get; set; } + public string MimeType { get; set; } + public string ContentDisposition { get; set; } + public Int64 TotalBytes { get; set; } + public int PercentComplete { get; set; } + public bool IsCancelled { get; set; } + public bool IsComplete { get; set; } + public bool IsInProgress { get; set; } + public string SuggestedFileName { get; set; } + public string FullPath { get; set; } + } +} diff --git a/CefSharp/IDownloadHandler.cs b/CefSharp/IDownloadHandler.cs index 79bdd55bd..f49da0e09 100644 --- a/CefSharp/IDownloadHandler.cs +++ b/CefSharp/IDownloadHandler.cs @@ -2,8 +2,8 @@ { public interface IDownloadHandler { - bool OnBeforeDownload(string suggestedName, out string downloadPath, out bool showDialog); - bool ReceivedData(byte[] data); - void Complete(); + bool OnBeforeDownload(DownloadItem downloadItem, out string downloadPath, out bool showDialog); + + bool OnDownloadUpdated(DownloadItem downloadItem); } } From 8a12566b8a89a2f8f9cbafe685e0979f0e5a8541 Mon Sep 17 00:00:00 2001 From: amaitland Date: Wed, 11 Jun 2014 13:56:57 +1000 Subject: [PATCH 02/11] Split DownloadAdapter into cpp and h file --- CefSharp.Core/CefSharp.Core.vcxproj | 1 + CefSharp.Core/CefSharp.Core.vcxproj.filters | 3 + CefSharp.Core/Internals/DownloadAdapter.cpp | 63 +++++++++++++++++++++ CefSharp.Core/Internals/DownloadAdapter.h | 63 ++++----------------- 4 files changed, 77 insertions(+), 53 deletions(-) create mode 100644 CefSharp.Core/Internals/DownloadAdapter.cpp diff --git a/CefSharp.Core/CefSharp.Core.vcxproj b/CefSharp.Core/CefSharp.Core.vcxproj index 8fd4292b5..77da727f9 100644 --- a/CefSharp.Core/CefSharp.Core.vcxproj +++ b/CefSharp.Core/CefSharp.Core.vcxproj @@ -217,6 +217,7 @@ + diff --git a/CefSharp.Core/CefSharp.Core.vcxproj.filters b/CefSharp.Core/CefSharp.Core.vcxproj.filters index af68469fc..591e0962e 100644 --- a/CefSharp.Core/CefSharp.Core.vcxproj.filters +++ b/CefSharp.Core/CefSharp.Core.vcxproj.filters @@ -53,6 +53,9 @@ Source Files + + Source Files + diff --git a/CefSharp.Core/Internals/DownloadAdapter.cpp b/CefSharp.Core/Internals/DownloadAdapter.cpp new file mode 100644 index 000000000..f3b533903 --- /dev/null +++ b/CefSharp.Core/Internals/DownloadAdapter.cpp @@ -0,0 +1,63 @@ +// Copyright © 2010-2014 The CefSharp Authors. All rights reserved. +// +// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. + +#pragma once + +#include "Stdafx.h" +#include "include/cef_download_handler.h" +#include "DownloadAdapter.h" + +using namespace CefSharp; + +namespace CefSharp +{ + namespace Internals + { + DownloadAdapter::~DownloadAdapter() + { + _handler = nullptr; + } + + void DownloadAdapter::OnBeforeDownload(CefRefPtr browser, CefRefPtr download_item, + const CefString& suggested_name, CefRefPtr callback) + { + String^ download_path; + bool show_dialog; + auto downloadItem = GetDownloadItem(download_item); + downloadItem->SuggestedFileName = StringUtils::ToClr(suggested_name); + + if (_handler->OnBeforeDownload(downloadItem, download_path, show_dialog)) + { + callback->Continue(StringUtils::ToNative(download_path), show_dialog); + } + }; + + void DownloadAdapter::OnDownloadUpdated(CefRefPtr browser, CefRefPtr download_item, + CefRefPtr callback) + { + if (_handler->OnDownloadUpdated(GetDownloadItem(download_item))) + { + callback->Cancel(); + } + } + + CefSharp::DownloadItem^ DownloadAdapter::GetDownloadItem(CefRefPtr download_item) + { + auto item = gcnew CefSharp::DownloadItem(); + item->Id = download_item->GetId(); + item->Url = StringUtils::ToClr(download_item->GetURL()); + item->MimeType = StringUtils::ToClr(download_item->GetMimeType()); + item->ContentDisposition = StringUtils::ToClr(download_item->GetContentDisposition()); + item->TotalBytes = download_item->GetTotalBytes(); + item->IsComplete = download_item->IsComplete(); + item->IsInProgress = download_item->IsInProgress(); + item->IsCancelled = download_item->IsCanceled(); + item->PercentComplete = download_item->GetPercentComplete(); + item->SuggestedFileName = StringUtils::ToClr(download_item->GetSuggestedFileName()); + item->FullPath = StringUtils::ToClr(download_item->GetFullPath()); + + return item; + } + } +} diff --git a/CefSharp.Core/Internals/DownloadAdapter.h b/CefSharp.Core/Internals/DownloadAdapter.h index 3ee59a712..35f09ff01 100644 --- a/CefSharp.Core/Internals/DownloadAdapter.h +++ b/CefSharp.Core/Internals/DownloadAdapter.h @@ -7,7 +7,7 @@ #include "Stdafx.h" #include "include/cef_download_handler.h" -using namespace System::Runtime::InteropServices; +using namespace CefSharp; namespace CefSharp { @@ -15,63 +15,20 @@ namespace CefSharp { private class DownloadAdapter : public CefDownloadHandler { + private: gcroot _handler; + DownloadItem^ DownloadAdapter::GetDownloadItem(CefRefPtr download_item); public: - DownloadAdapter(IDownloadHandler^ handler) : - _handler(handler) - { - } - - ~DownloadAdapter() - { - _handler = nullptr; - } + DownloadAdapter(IDownloadHandler^ handler) : _handler(handler) { } + ~DownloadAdapter(); virtual void OnBeforeDownload(CefRefPtr browser, CefRefPtr download_item, - const CefString& suggested_name, CefRefPtr callback) OVERRIDE - { - String^ download_path; - bool show_dialog; - auto downloadItem = GetDownloadItem(download_item); - downloadItem->SuggestedFileName = StringUtils::ToClr(suggested_name); - - if (_handler->OnBeforeDownload(downloadItem, download_path, show_dialog)) - { - callback->Continue(StringUtils::ToNative(download_path), show_dialog); - } - }; - - virtual void OnDownloadUpdated(CefRefPtr browser, CefRefPtr download_item, CefRefPtr callback) OVERRIDE - { - - if (_handler->OnDownloadUpdated(GetDownloadItem(download_item))) - { - callback->Cancel(); - } - } - - private: - CefSharp::DownloadItem^ GetDownloadItem(CefRefPtr download_item) - { - auto item = gcnew CefSharp::DownloadItem(); - item->Id = download_item->GetId(); - item->Url = StringUtils::ToClr(download_item->GetURL()); - item->MimeType = StringUtils::ToClr(download_item->GetMimeType()); - item->ContentDisposition = StringUtils::ToClr(download_item->GetContentDisposition()); - item->TotalBytes = download_item->GetTotalBytes(); - item->IsComplete = download_item->IsComplete(); - item->IsInProgress = download_item->IsInProgress(); - item->IsCancelled = download_item->IsCanceled(); - item->PercentComplete = download_item->GetPercentComplete(); - item->SuggestedFileName = StringUtils::ToClr(download_item->GetSuggestedFileName()); - item->FullPath = StringUtils::ToClr(download_item->GetFullPath()); - - - return item; - } - + const CefString& suggested_name, CefRefPtr callback) OVERRIDE; + virtual void OnDownloadUpdated(CefRefPtr browser, CefRefPtr download_item, + CefRefPtr callback) OVERRIDE; + IMPLEMENT_REFCOUNTING(DownloadAdapter); }; } -} +} \ No newline at end of file From 8c97e29e2a23db230d5b6b4d06db0aaabce2a4ca Mon Sep 17 00:00:00 2001 From: amaitland Date: Wed, 11 Jun 2014 14:47:19 +1000 Subject: [PATCH 03/11] Move DownloadHandler from IRequestHandler to directly on IWebBrowser --- CefSharp.Core/Internals/ClientAdapter.cpp | 18 ++++-------------- CefSharp.Example/ExamplePresenter.cs | 6 ------ CefSharp.WinForms/ChromiumWebBrowser.cs | 1 + CefSharp.Wpf/ChromiumWebBrowser.cs | 1 + CefSharp/IRequestHandler.cs | 8 -------- CefSharp/IWebBrowser.cs | 2 ++ 6 files changed, 8 insertions(+), 28 deletions(-) diff --git a/CefSharp.Core/Internals/ClientAdapter.cpp b/CefSharp.Core/Internals/ClientAdapter.cpp index a72ee41b3..8f9f62f3f 100644 --- a/CefSharp.Core/Internals/ClientAdapter.cpp +++ b/CefSharp.Core/Internals/ClientAdapter.cpp @@ -262,23 +262,13 @@ namespace CefSharp CefRefPtr ClientAdapter::GetDownloadHandler() { - IRequestHandler^ requestHandler = _browserControl->RequestHandler; - if (requestHandler == nullptr) - { - return false; - } - - IDownloadHandler^ downloadHandler; - bool ret = requestHandler->GetDownloadHandler(_browserControl, downloadHandler); - - if (ret) - { - return new DownloadAdapter(downloadHandler); - } - else + IDownloadHandler^ downloadHandler = _browserControl->DownloadHandler; + if (downloadHandler == nullptr) { return nullptr; } + + return new DownloadAdapter(downloadHandler); } bool ClientAdapter::GetAuthCredentials(CefRefPtr browser, CefRefPtr frame, bool isProxy, diff --git a/CefSharp.Example/ExamplePresenter.cs b/CefSharp.Example/ExamplePresenter.cs index c2fb0c09a..bfb7d6a81 100644 --- a/CefSharp.Example/ExamplePresenter.cs +++ b/CefSharp.Example/ExamplePresenter.cs @@ -296,12 +296,6 @@ namespace CefSharp.Example } - bool IRequestHandler.GetDownloadHandler(IWebBrowser browser, out IDownloadHandler handler) - { - handler = new DownloadHandler(); - return true; - } - bool IRequestHandler.GetAuthCredentials(IWebBrowser browser, bool isProxy, string host, int port, string realm, string scheme, ref string username, ref string password) { return false; diff --git a/CefSharp.WinForms/ChromiumWebBrowser.cs b/CefSharp.WinForms/ChromiumWebBrowser.cs index 1923f3347..b1e7b6bc4 100644 --- a/CefSharp.WinForms/ChromiumWebBrowser.cs +++ b/CefSharp.WinForms/ChromiumWebBrowser.cs @@ -25,6 +25,7 @@ namespace CefSharp.WinForms public IJsDialogHandler JsDialogHandler { get; set; } public IKeyboardHandler KeyboardHandler { get; set; } public IRequestHandler RequestHandler { get; set; } + public IDownloadHandler DownloadHandler { get; set; } public ILifeSpanHandler LifeSpanHandler { get; set; } public IMenuHandler MenuHandler { get; set; } diff --git a/CefSharp.Wpf/ChromiumWebBrowser.cs b/CefSharp.Wpf/ChromiumWebBrowser.cs index 886190ea0..9bf5dc4ea 100644 --- a/CefSharp.Wpf/ChromiumWebBrowser.cs +++ b/CefSharp.Wpf/ChromiumWebBrowser.cs @@ -47,6 +47,7 @@ namespace CefSharp.Wpf public IJsDialogHandler JsDialogHandler { get; set; } public IKeyboardHandler KeyboardHandler { get; set; } public IRequestHandler RequestHandler { get; set; } + public IDownloadHandler DownloadHandler { get; set; } public ILifeSpanHandler LifeSpanHandler { get; set; } public event ConsoleMessageEventHandler ConsoleMessage; diff --git a/CefSharp/IRequestHandler.cs b/CefSharp/IRequestHandler.cs index 044cb00a1..c07c75ba7 100644 --- a/CefSharp/IRequestHandler.cs +++ b/CefSharp/IRequestHandler.cs @@ -43,14 +43,6 @@ namespace CefSharp void OnResourceResponse(IWebBrowser browser, string url, int status, string statusText, string mimeType, WebHeaderCollection headers); - /// - /// Called when a server indicates via the 'Content-Disposition' header that a response represents a file to download. - /// - /// the browser object - /// Set instance of IDownloadHandler that will recieve the file contents - /// Return true to download the file or false to cancel the file download - bool GetDownloadHandler(IWebBrowser browser, out IDownloadHandler handler); - /// /// Called when the browser needs credentials from the user. /// diff --git a/CefSharp/IWebBrowser.cs b/CefSharp/IWebBrowser.cs index 6c0d542b6..73d088524 100644 --- a/CefSharp/IWebBrowser.cs +++ b/CefSharp/IWebBrowser.cs @@ -74,6 +74,8 @@ namespace CefSharp IDialogHandler DialogHandler { get; set; } IRequestHandler RequestHandler { get; set; } + IDownloadHandler DownloadHandler { get; set; } + bool IsBrowserInitialized { get; } /// From 6aff137a8a165fc9f5443414c3ab6ee011d29d5d Mon Sep 17 00:00:00 2001 From: amaitland Date: Wed, 11 Jun 2014 15:31:36 +1000 Subject: [PATCH 04/11] Make example DownloadHandler public --- CefSharp.Example/DownloadHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CefSharp.Example/DownloadHandler.cs b/CefSharp.Example/DownloadHandler.cs index 3b1963d2e..2ab419824 100644 --- a/CefSharp.Example/DownloadHandler.cs +++ b/CefSharp.Example/DownloadHandler.cs @@ -1,6 +1,6 @@ namespace CefSharp.Example { - internal class DownloadHandler : IDownloadHandler + public class DownloadHandler : IDownloadHandler { public bool OnBeforeDownload(DownloadItem downloadItem, out string downloadPath, out bool showDialog) { From 5fe3f16502b8f6e64a50feb5cf08eb84d351efed Mon Sep 17 00:00:00 2001 From: amaitland Date: Wed, 11 Jun 2014 15:38:15 +1000 Subject: [PATCH 05/11] Complete implementation of DownloadItem --- CefSharp.Core/Internals/DownloadAdapter.cpp | 42 +++++++--- CefSharp.Core/Internals/DownloadAdapter.h | 2 + CefSharp/DownloadItem.cs | 86 ++++++++++++++++++--- 3 files changed, 110 insertions(+), 20 deletions(-) diff --git a/CefSharp.Core/Internals/DownloadAdapter.cpp b/CefSharp.Core/Internals/DownloadAdapter.cpp index f3b533903..ff81a7e04 100644 --- a/CefSharp.Core/Internals/DownloadAdapter.cpp +++ b/CefSharp.Core/Internals/DownloadAdapter.cpp @@ -8,6 +8,7 @@ #include "include/cef_download_handler.h" #include "DownloadAdapter.h" +using namespace System; using namespace CefSharp; namespace CefSharp @@ -45,19 +46,38 @@ namespace CefSharp CefSharp::DownloadItem^ DownloadAdapter::GetDownloadItem(CefRefPtr download_item) { auto item = gcnew CefSharp::DownloadItem(); - item->Id = download_item->GetId(); - item->Url = StringUtils::ToClr(download_item->GetURL()); - item->MimeType = StringUtils::ToClr(download_item->GetMimeType()); - item->ContentDisposition = StringUtils::ToClr(download_item->GetContentDisposition()); - item->TotalBytes = download_item->GetTotalBytes(); - item->IsComplete = download_item->IsComplete(); - item->IsInProgress = download_item->IsInProgress(); - item->IsCancelled = download_item->IsCanceled(); - item->PercentComplete = download_item->GetPercentComplete(); - item->SuggestedFileName = StringUtils::ToClr(download_item->GetSuggestedFileName()); - item->FullPath = StringUtils::ToClr(download_item->GetFullPath()); + item->IsValid = download_item->IsValid(); + //NOTE: Description for IsValid says `Do not call any other methods if this function returns false.` so only load if IsValid = true + if(item->IsValid) + { + item->IsInProgress = download_item->IsInProgress(); + item->IsComplete = download_item->IsComplete(); + item->IsCancelled = download_item->IsCanceled(); + item->CurrentSpeed = download_item->GetCurrentSpeed(); + item->PercentComplete = download_item->GetPercentComplete(); + item->TotalBytes = download_item->GetTotalBytes(); + item->ReceivedBytes = download_item->GetReceivedBytes(); + item->StartTime = ConvertCefTimeToNullableDateTime(download_item->GetStartTime()); + item->EndTime = ConvertCefTimeToNullableDateTime(download_item->GetEndTime()); + item->FullPath = StringUtils::ToClr(download_item->GetFullPath()); + item->Id = download_item->GetId(); + item->Url = StringUtils::ToClr(download_item->GetURL()); + item->SuggestedFileName = StringUtils::ToClr(download_item->GetSuggestedFileName()); + item->ContentDisposition = StringUtils::ToClr(download_item->GetContentDisposition()); + item->MimeType = StringUtils::ToClr(download_item->GetMimeType()); + } return item; } + + Nullable DownloadAdapter::ConvertCefTimeToNullableDateTime(CefTime time) + { + auto epoch = time.GetDoubleT(); + if(epoch == 0) + { + return Nullable(); + } + return Nullable(DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(epoch)); + } } } diff --git a/CefSharp.Core/Internals/DownloadAdapter.h b/CefSharp.Core/Internals/DownloadAdapter.h index 35f09ff01..752929a9b 100644 --- a/CefSharp.Core/Internals/DownloadAdapter.h +++ b/CefSharp.Core/Internals/DownloadAdapter.h @@ -7,6 +7,7 @@ #include "Stdafx.h" #include "include/cef_download_handler.h" +using namespace System; using namespace CefSharp; namespace CefSharp @@ -18,6 +19,7 @@ namespace CefSharp private: gcroot _handler; DownloadItem^ DownloadAdapter::GetDownloadItem(CefRefPtr download_item); + Nullable ConvertCefTimeToNullableDateTime(CefTime time); public: DownloadAdapter(IDownloadHandler^ handler) : _handler(handler) { } diff --git a/CefSharp/DownloadItem.cs b/CefSharp/DownloadItem.cs index ad318cfd9..13cb97dc8 100644 --- a/CefSharp/DownloadItem.cs +++ b/CefSharp/DownloadItem.cs @@ -4,16 +4,84 @@ namespace CefSharp { public class DownloadItem { - public int Id { get; set; } - public string Url { get; set; } - public string MimeType { get; set; } - public string ContentDisposition { get; set; } - public Int64 TotalBytes { get; set; } - public int PercentComplete { get; set; } - public bool IsCancelled { get; set; } - public bool IsComplete { get; set; } + /// + /// Returns true if this object is valid. Do not call any other methods if this function returns false. + /// + public bool IsValid { get; set; } + + /// + /// Returns true if the download is in progress. + /// public bool IsInProgress { get; set; } - public string SuggestedFileName { get; set; } + + /// + /// Returns true if the download is complete. + /// + public bool IsComplete { get; set; } + + /// + /// Returns true if the download has been canceled or interrupted. + /// + public bool IsCancelled { get; set; } + + /// + /// Returns a simple speed estimate in bytes/s. + /// + public Int64 CurrentSpeed { get; set; } + + /// + /// Returns the rough percent complete or -1 if the receive total size is unknown. + /// + public int PercentComplete { get; set; } + + /// + /// Returns the total number of bytes. + /// + public Int64 TotalBytes { get; set; } + + /// + /// Returns the number of received bytes. + /// + public Int64 ReceivedBytes { get; set; } + + /// + /// Returns the time that the download started + /// + public DateTime? StartTime { get; set; } + + /// + /// Returns the time that the download ended + /// + public DateTime? EndTime { get; set; } + + /// + /// Returns the full path to the downloaded or downloading file. + /// public string FullPath { get; set; } + + /// + /// Returns the unique identifier for this download. + /// + public int Id { get; set; } + + /// + /// Returns the URL. + /// + public string Url { get; set; } + + /// + /// Returns the suggested file name. + /// + public string SuggestedFileName { get; set; } + + /// + /// Returns the content disposition. + /// + public string ContentDisposition { get; set; } + + /// + /// Returns the mime type. + /// + public string MimeType { get; set; } } } From dcba2d6065e79742fddab8a189dbf4a81c98739b Mon Sep 17 00:00:00 2001 From: amaitland Date: Wed, 11 Jun 2014 15:45:16 +1000 Subject: [PATCH 06/11] Modify DownloadAdapter::ConvertCefTimeToNullableDateTime to return local time --- CefSharp.Core/Internals/DownloadAdapter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CefSharp.Core/Internals/DownloadAdapter.cpp b/CefSharp.Core/Internals/DownloadAdapter.cpp index ff81a7e04..c9ecaaa71 100644 --- a/CefSharp.Core/Internals/DownloadAdapter.cpp +++ b/CefSharp.Core/Internals/DownloadAdapter.cpp @@ -77,7 +77,7 @@ namespace CefSharp { return Nullable(); } - return Nullable(DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(epoch)); + return Nullable(DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(epoch).ToLocalTime()); } } } From 876f34b324c7cfb6dbb64f1ba34fa928fc7c3dfd Mon Sep 17 00:00:00 2001 From: amaitland Date: Wed, 11 Jun 2014 15:45:39 +1000 Subject: [PATCH 07/11] Add Example DownloadHandler to WinForms Example --- CefSharp.WinForms.Example/BrowserForm.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CefSharp.WinForms.Example/BrowserForm.cs b/CefSharp.WinForms.Example/BrowserForm.cs index 4201cd6d1..6d01ab3e4 100644 --- a/CefSharp.WinForms.Example/BrowserForm.cs +++ b/CefSharp.WinForms.Example/BrowserForm.cs @@ -25,7 +25,8 @@ namespace CefSharp.WinForms.Example }; toolStripContainer.ContentPanel.Controls.Add(browser); - browser.MenuHandler = new MenuHandler(); + browser.DownloadHandler = new DownloadHandler(); + browser.MenuHandler = new MenuHandler(); browser.NavStateChanged += OnBrowserNavStateChanged; browser.ConsoleMessage += OnBrowserConsoleMessage; browser.TitleChanged += OnBrowserTitleChanged; From 5995026acd3120da7155eaa0e410dfa0e8bfd366 Mon Sep 17 00:00:00 2001 From: amaitland Date: Wed, 11 Jun 2014 16:26:52 +1000 Subject: [PATCH 08/11] Amend Xml documentation for IDownloadHandler --- CefSharp/IDownloadHandler.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CefSharp/IDownloadHandler.cs b/CefSharp/IDownloadHandler.cs index f49da0e09..004d68842 100644 --- a/CefSharp/IDownloadHandler.cs +++ b/CefSharp/IDownloadHandler.cs @@ -2,8 +2,20 @@ { public interface IDownloadHandler { + /// + /// Called before a download begins. + /// + /// Represents the file being downloaded. + /// Path where the file will be saved if is False. + /// Display a dialog allowing the user to specify a custom path and filename. + /// Return True to continue the download otherwise return False to cancel the download bool OnBeforeDownload(DownloadItem downloadItem, out string downloadPath, out bool showDialog); + /// + /// Called when a download's status or progress information has been updated. This may be called multiple times before and after . + /// + /// Represents the file being downloaded. + /// Return True to cancel, otherwise False to allow the download to continue. bool OnDownloadUpdated(DownloadItem downloadItem); } } From 7185574cca969c98fffb959a868c9b3940c3e43e Mon Sep 17 00:00:00 2001 From: amaitland Date: Wed, 11 Jun 2014 16:28:32 +1000 Subject: [PATCH 09/11] Fix formatting --- CefSharp.WinForms.Example/BrowserForm.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CefSharp.WinForms.Example/BrowserForm.cs b/CefSharp.WinForms.Example/BrowserForm.cs index 6d01ab3e4..e929df099 100644 --- a/CefSharp.WinForms.Example/BrowserForm.cs +++ b/CefSharp.WinForms.Example/BrowserForm.cs @@ -25,8 +25,8 @@ namespace CefSharp.WinForms.Example }; toolStripContainer.ContentPanel.Controls.Add(browser); - browser.DownloadHandler = new DownloadHandler(); - browser.MenuHandler = new MenuHandler(); + browser.DownloadHandler = new DownloadHandler(); + browser.MenuHandler = new MenuHandler(); browser.NavStateChanged += OnBrowserNavStateChanged; browser.ConsoleMessage += OnBrowserConsoleMessage; browser.TitleChanged += OnBrowserTitleChanged; From 959f4320302f8e397cc5406bc7974704a0d69a40 Mon Sep 17 00:00:00 2001 From: amaitland Date: Thu, 12 Jun 2014 12:24:45 +1000 Subject: [PATCH 10/11] Manually fix some merge issues --- CefSharp.Example/RequestHandler.cs | 7 ------- CefSharp.Wpf.Example/Views/BrowserTabView.xaml.cs | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/CefSharp.Example/RequestHandler.cs b/CefSharp.Example/RequestHandler.cs index fd1b8b4af..2ada2e881 100644 --- a/CefSharp.Example/RequestHandler.cs +++ b/CefSharp.Example/RequestHandler.cs @@ -34,13 +34,6 @@ namespace CefSharp.Example return false; } - bool IRequestHandler.GetDownloadHandler(IWebBrowser browser, out IDownloadHandler handler) - { - handler = new DownloadHandler(); - - return true; - } - bool IRequestHandler.GetAuthCredentials(IWebBrowser browser, bool isProxy, string host, int port, string realm, string scheme, ref string username, ref string password) { return false; diff --git a/CefSharp.Wpf.Example/Views/BrowserTabView.xaml.cs b/CefSharp.Wpf.Example/Views/BrowserTabView.xaml.cs index 35eef5abc..1b8ba0940 100644 --- a/CefSharp.Wpf.Example/Views/BrowserTabView.xaml.cs +++ b/CefSharp.Wpf.Example/Views/BrowserTabView.xaml.cs @@ -14,7 +14,7 @@ namespace CefSharp.Wpf.Example.Views { InitializeComponent(); - webView.RequestHandler = new RequestHandler(); + browser.RequestHandler = new RequestHandler(); } private void OnTextBoxGotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) From 3941b32f4b06f6498e94e112658d2c0e4bb6e581 Mon Sep 17 00:00:00 2001 From: jornh Date: Mon, 23 Jun 2014 23:16:42 +0200 Subject: [PATCH 11/11] Fix on of those pesky (c) chars in copyright line --- CefSharp.Core/Internals/DownloadAdapter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CefSharp.Core/Internals/DownloadAdapter.cpp b/CefSharp.Core/Internals/DownloadAdapter.cpp index c9ecaaa71..274aa8010 100644 --- a/CefSharp.Core/Internals/DownloadAdapter.cpp +++ b/CefSharp.Core/Internals/DownloadAdapter.cpp @@ -1,4 +1,4 @@ -// Copyright © 2010-2014 The CefSharp Authors. All rights reserved. +// Copyright © 2010-2014 The CefSharp Authors. All rights reserved. // // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.