-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
152 additions
and
40 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
Tryouts/Prototypes/Shell/ImageSource/DefaultImageSourcePolicy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
|
||
namespace Shell.ImageSource | ||
{ | ||
public sealed class DefaultImageSourcePolicy : IImageSourcePolicy | ||
|
||
{ | ||
public bool IsAllowed(Uri uri, Uri appUri) | ||
{ | ||
return uri.Scheme.StartsWith("http") && uri.Host == appUri.Host; | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
Tryouts/Prototypes/Shell/ImageSource/EnvironmentImageSourcePolicy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Linq; | ||
|
||
namespace Shell.ImageSource | ||
{ | ||
public sealed class EnvironmentImageSourcePolicy : IImageSourcePolicy | ||
{ | ||
private const string _allowListEnvVar = "COMPOSE_ALLOWED_IMAGE_SOURCES"; | ||
public bool IsAllowed(Uri uri, Uri appUri) | ||
{ | ||
var allowListString = Environment.GetEnvironmentVariable(_allowListEnvVar); | ||
|
||
// Only allow http or https sources. If no sources are allowed, | ||
if (!uri.Scheme.StartsWith("http")) | ||
{ | ||
return false; | ||
} | ||
// If the source host is the same as the app host, allow it. | ||
if (uri.Host == appUri.Host) | ||
{ | ||
return true; | ||
} | ||
if (string.IsNullOrEmpty(allowListString)) | ||
{ | ||
return false; | ||
} | ||
|
||
var allowedSources = allowListString.Split(';'); | ||
return allowedSources.Contains(uri.Host); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
Tryouts/Prototypes/Shell/ImageSource/IImageSourcePolicy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Shell.ImageSource | ||
{ | ||
public interface IImageSourcePolicy | ||
{ | ||
bool IsAllowed(Uri uri, Uri appUri); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
Tryouts/Prototypes/Shell/ImageSource/ImageSourceProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.Windows.Media.Imaging; | ||
|
||
namespace Shell.ImageSource | ||
{ | ||
public class ImageSourceProvider | ||
{ | ||
IImageSourcePolicy _imageSourcePolicy; | ||
public ImageSourceProvider(IImageSourcePolicy imageSourcePolicy) | ||
{ | ||
_imageSourcePolicy = imageSourcePolicy; | ||
} | ||
|
||
public System.Windows.Media.ImageSource? GetImageSource(Uri uri, Uri appUri) | ||
{ | ||
if (_imageSourcePolicy.IsAllowed(uri, appUri)) | ||
{ | ||
return BitmapFrame.Create(uri); | ||
} | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Shell | ||
{ | ||
public sealed class WebContentOptions | ||
{ | ||
public string Title = string.Empty; | ||
public Uri Uri { get; set; } = new Uri("about:blank"); | ||
public Uri? IconUri { get; set; } = null; | ||
} | ||
} |