Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added DownloadItem .OriginalUrl #1877

Merged
merged 2 commits into from
Dec 4, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*.swp
*.user
*.xml
*.VC.opendb
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would ideally be in it's own PR, though leave it for now. (Doesn't relate to the feature your adding).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay!

*.VC.db
_ReSharper*

bin/
Expand Down
1 change: 1 addition & 0 deletions CefSharp.Core/Internals/TypeConversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ namespace CefSharp
item->FullPath = StringUtils::ToClr(downloadItem->GetFullPath());
item->Id = downloadItem->GetId();
item->Url = StringUtils::ToClr(downloadItem->GetURL());
item->OriginalUrl = StringUtils::ToClr(downloadItem->GetOriginalUrl());
item->SuggestedFileName = StringUtils::ToClr(downloadItem->GetSuggestedFileName());
item->ContentDisposition = StringUtils::ToClr(downloadItem->GetContentDisposition());
item->MimeType = StringUtils::ToClr(downloadItem->GetMimeType());
Expand Down
1 change: 1 addition & 0 deletions CefSharp.Example/CefExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public static class CefExample
public const string BasicSchemeTestUrl = "custom://cefsharp/SchemeTest.html";
public const string ResponseFilterTestUrl = "custom://cefsharp/ResponseFilterTest.html";
public const string DraggableRegionTestUrl = "custom://cefsharp/DraggableRegionTest.html";
public const string DownloadHandlerTestUrl = "custom://cefsharp/DownloadHandlerTest.html";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, meant to revert this. I had added a new test html file but it didn't turn out to be a very good addition.

public const string TestResourceUrl = "http://test/resource/load";
public const string RenderProcessCrashedUrl = "http://processcrashed";
public const string TestUnicodeResourceUrl = "http://test/resource/loadUnicode";
Expand Down
16 changes: 15 additions & 1 deletion CefSharp.Example/DownloadHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

using System;

namespace CefSharp.Example
{
public class DownloadHandler : IDownloadHandler
{
public event EventHandler<DownloadItem> OnBeforeDownloadFired;

public event EventHandler<DownloadItem> OnDownloadUpdatedFired;

public void OnBeforeDownload(IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback)
{
if (this.OnBeforeDownloadFired != null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would prefer firing of event handlers to look like below for consistency and best practice.

var handler = LoadingStateChanged;
if (handler != null)
{
    handler(this, args);
}

I know this is a demo, though I prefer to take a reference to a handler before executing as it's possible in a multithreaded environment for the handler reference to be cleared between the null check and executing. There's no

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I update to match that style. Presumably using a null-conditional would also be okay? E.g.

OnBeforeDownloadFired?.Invoke(this, downloadItem);

{
this.OnBeforeDownloadFired.Invoke(this, downloadItem);
}

if (!callback.IsDisposed)
{
using (callback)
Expand All @@ -19,7 +30,10 @@ public void OnBeforeDownload(IBrowser browser, DownloadItem downloadItem, IBefor

public void OnDownloadUpdated(IBrowser browser, DownloadItem downloadItem, IDownloadItemCallback callback)
{

if (this.OnDownloadUpdatedFired != null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency this has typically only been used when referencing a private variable.

{
this.OnDownloadUpdatedFired.Invoke(this, downloadItem);
}
}
}
}
4 changes: 4 additions & 0 deletions CefSharp.Wpf.Example/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
<MenuItem Header="Zooom Reset" Command="controls:CefSharpCommands.CustomCommand" CommandParameter="ZoomReset"/>
<MenuItem Header="_Exit" Command="controls:CefSharpCommands.Exit"/>
</MenuItem>
<MenuItem Header="_View">
<MenuItem Header="Toggle _Sidebar" Command="controls:CefSharpCommands.CustomCommand" CommandParameter="ToggleSidebar"/>
<MenuItem Header="Toggle _Download Info" Command="controls:CefSharpCommands.CustomCommand" CommandParameter="ToggleDownloadInfo"/>
</MenuItem>
<MenuItem Header="_Tests">
<MenuItem Header="_Binding Test" Command="controls:CefSharpCommands.OpenTabCommand" CommandParameter="{Binding Source={x:Static ex:CefExample.BindingTestUrl}}"/>
<MenuItem Header="_List Plugins" Command="controls:CefSharpCommands.OpenTabCommand" CommandParameter="{Binding Source={x:Static ex:CefExample.PluginsTestUrl}}"/>
Expand Down
10 changes: 10 additions & 0 deletions CefSharp.Wpf.Example/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,16 @@ private void CustomCommandBinding(object sender, ExecutedRoutedEventArgs e)
cmd.Execute(null);
}

if (param == "ToggleSidebar")
{
browserViewModel.ShowSidebar = !browserViewModel.ShowSidebar;
}

if (param == "ToggleDownloadInfo")
{
browserViewModel.ShowDownloadInfo = !browserViewModel.ShowDownloadInfo;
}

//NOTE: Add as required
//else if (param == "CustomRequest123")
//{
Expand Down
21 changes: 21 additions & 0 deletions CefSharp.Wpf.Example/ViewModels/BrowserTabViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,27 @@ public bool ShowSidebar
set { Set(ref showSidebar, value); }
}

private bool showDownloadInfo;
public bool ShowDownloadInfo
{
get { return showDownloadInfo; }
set { Set(ref showDownloadInfo, value); }
}

private string lastDownloadAction;
public string LastDownloadAction
{
get { return lastDownloadAction; }
set { Set(ref lastDownloadAction, value); }
}

private DownloadItem downloadItem;
public DownloadItem DownloadItem
{
get { return downloadItem; }
set { Set(ref downloadItem, value); }
}

public ICommand GoCommand { get; private set; }
public ICommand HomeCommand { get; private set; }
public ICommand ExecuteJavaScriptCommand { get; private set; }
Expand Down
237 changes: 234 additions & 3 deletions CefSharp.Wpf.Example/Views/BrowserTabView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
<ObjectDataProvider x:Key="BitmapScalingModeEnum" MethodName="GetValues" ObjectType="{x:Type system:Enum}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="BitmapScalingMode"/>
<x:Type TypeName="BitmapScalingMode" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert whitespace changes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</UserControl.Resources>
Expand Down Expand Up @@ -44,8 +44,7 @@
GotKeyboardFocus="OnTextBoxGotKeyboardFocus"
GotMouseCapture="OnTextBoxGotMouseCapture">
<TextBox.InputBindings>
<KeyBinding Key="Enter"
Command="{Binding GoCommand}" />
<KeyBinding Key="Enter" Command="{Binding GoCommand}" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert whitespace changes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

</TextBox.InputBindings>
</TextBox>
</DockPanel>
Expand Down Expand Up @@ -154,6 +153,238 @@
</Grid>
</GroupBox>
</StackPanel>
<StackPanel
Margin="6,3"
DockPanel.Dock="Right"
Visibility="{Binding ShowDownloadInfo, Converter={StaticResource BooleanToVisibilityConverter}}"
>
<GroupBox Header="Download info">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" MinWidth="50" />
</Grid.ColumnDefinitions>
<Label
Grid.Row="0"
Grid.Column="0"
Content="Last action:"
/>
<TextBox
Grid.Row="0"
Grid.Column="1"
IsReadOnly="True"
Text="{Binding LastDownloadAction}"
/>
<Label
Grid.Row="1"
Grid.Column="0"
Content="IsInProgress:"
/>
<TextBox
Grid.Row="1"
Grid.Column="1"
IsReadOnly="True"
Text="{Binding DownloadItem.IsInProgress}"
/>
<Label
Grid.Row="2"
Grid.Column="0"
Content="IsComplete:"
/>
<TextBox
Grid.Row="2"
Grid.Column="1"
IsReadOnly="True"
Text="{Binding DownloadItem.IsComplete}"
/>
<Label
Grid.Row="3"
Grid.Column="0"
Content="IsCancelled:"
/>
<TextBox
Grid.Row="3"
Grid.Column="1"
IsReadOnly="True"
Text="{Binding DownloadItem.IsCancelled}"
/>
<Label
Grid.Row="4"
Grid.Column="0"
Content="CurrentSpeed:"
/>
<TextBox
Grid.Row="4"
Grid.Column="1"
IsReadOnly="True"
Text="{Binding DownloadItem.CurrentSpeed}"
/>
<Label
Grid.Row="5"
Grid.Column="0"
Content="PercentComplete:"
/>
<TextBox
Grid.Row="5"
Grid.Column="1"
IsReadOnly="True"
Text="{Binding DownloadItem.PercentComplete}"
/>
<Label
Grid.Row="6"
Grid.Column="0"
Content="TotalBytes:"
/>
<TextBox
Grid.Row="6"
Grid.Column="1"
IsReadOnly="True"
Text="{Binding DownloadItem.TotalBytes}"
/>
<Label
Grid.Row="7"
Grid.Column="0"
Content="ReceivedBytes:"
/>
<TextBox
Grid.Row="7"
Grid.Column="1"
IsReadOnly="True"
Text="{Binding DownloadItem.ReceivedBytes}"
/>
<Label
Grid.Row="8"
Grid.Column="0"
Content="StartTime:"
/>
<TextBox
Grid.Row="8"
Grid.Column="1"
IsReadOnly="True"
Text="{Binding DownloadItem.StartTime}"
/>
<Label
Grid.Row="9"
Grid.Column="0"
Content="EndTime:"
/>
<TextBox
Grid.Row="9"
Grid.Column="1"
IsReadOnly="True"
Text="{Binding DownloadItem.EndTime}"
/>
<Label
Grid.Row="10"
Grid.Column="0"
Content="FullPath:"
/>
<TextBox
Grid.Row="10"
Grid.Column="1"
IsReadOnly="True"
Text="{Binding DownloadItem.FullPath}"
/>
<Label
Grid.Row="11"
Grid.Column="0"
Content="Id:"
/>
<TextBox
Grid.Row="11"
Grid.Column="1"
IsReadOnly="True"
Text="{Binding DownloadItem.Id}"
/>
<Label
Grid.Row="12"
Grid.Column="0"
Content="Url:"
/>
<TextBox
Grid.Row="12"
Grid.Column="1"
IsReadOnly="True"
Text="{Binding DownloadItem.Url}"
/>
<Label
Grid.Row="13"
Grid.Column="0"
Content="OriginalUrl:"
/>
<TextBox
Grid.Row="13"
Grid.Column="1"
IsReadOnly="True"
Text="{Binding DownloadItem.OriginalUrl}"
/>
<Label
Grid.Row="14"
Grid.Column="0"
Content="SuggestedFileName:"
/>
<TextBox
Grid.Row="14"
Grid.Column="1"
IsReadOnly="True"
Text="{Binding DownloadItem.SuggestedFileName}"
/>
<Label
Grid.Row="15"
Grid.Column="0"
Content="ContentDisposition:"
/>
<TextBox
Grid.Row="15"
Grid.Column="1"
IsReadOnly="True"
Text="{Binding DownloadItem.ContentDisposition}"
/>
<Label
Grid.Row="16"
Grid.Column="0"
Content="MimeType:"
/>
<TextBox
Grid.Row="16"
Grid.Column="1"
IsReadOnly="True"
Text="{Binding DownloadItem.MimeType}"
/>
<Label
Grid.Row="17"
Grid.Column="0"
Content="IsValid:"
/>
<TextBox
Grid.Row="17"
Grid.Column="1"
IsReadOnly="True"
Text="{Binding DownloadItem.IsValid}"
/>
</Grid>
</GroupBox>
</StackPanel>
<StatusBar DockPanel.Dock="Bottom">
<ProgressBar HorizontalAlignment="Right"
IsIndeterminate="{Binding WebBrowser.IsLoading}"
Expand Down
Loading