-
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.
Added msbuild target to embed and build composeui-fdc3 package to the…
… Shell project, changed project's files to use filescoped namespace, little refactoring around naming variables
- Loading branch information
Showing
13 changed files
with
167 additions
and
189 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,13 +1,7 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
namespace Shell.Fdc3; | ||
|
||
namespace Shell.Fdc3 | ||
public static class PreloadFdc3 | ||
{ | ||
public static class PreloadFdc3 | ||
{ | ||
public static readonly string Fdc3BundleResourceName = @"Shell.fdc3-iife-bundle.js"; | ||
} | ||
public static readonly string Fdc3BundleResourceName = @"Shell.fdc3-iife-bundle.js"; | ||
|
||
} |
12 changes: 5 additions & 7 deletions
12
src/shell/dotnet/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 |
---|---|---|
@@ -1,13 +1,11 @@ | ||
using System; | ||
|
||
namespace Shell.ImageSource | ||
{ | ||
public sealed class DefaultImageSourcePolicy : IImageSourcePolicy | ||
namespace Shell.ImageSource; | ||
|
||
public sealed class DefaultImageSourcePolicy : IImageSourcePolicy | ||
{ | ||
public bool IsAllowed(Uri uri, Uri appUri) | ||
{ | ||
public bool IsAllowed(Uri uri, Uri appUri) | ||
{ | ||
return uri.Scheme.StartsWith("http") && uri.Host == appUri.Host; | ||
} | ||
return uri.Scheme.StartsWith("http") && uri.Host == appUri.Host; | ||
} | ||
} |
45 changes: 22 additions & 23 deletions
45
src/shell/dotnet/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 |
---|---|---|
@@ -1,32 +1,31 @@ | ||
using System; | ||
using System.Linq; | ||
|
||
namespace Shell.ImageSource | ||
namespace Shell.ImageSource; | ||
|
||
public sealed class EnvironmentImageSourcePolicy : IImageSourcePolicy | ||
{ | ||
public sealed class EnvironmentImageSourcePolicy : IImageSourcePolicy | ||
private const string _allowListEnvVar = "COMPOSE_ALLOWED_IMAGE_SOURCES"; | ||
public bool IsAllowed(Uri uri, Uri appUri) | ||
{ | ||
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 allowListString = Environment.GetEnvironmentVariable(_allowListEnvVar); | ||
|
||
var allowedSources = allowListString.Split(';'); | ||
return allowedSources.Contains(uri.Host); | ||
// 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); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,9 +1,8 @@ | ||
using System; | ||
|
||
namespace Shell.ImageSource | ||
namespace Shell.ImageSource; | ||
|
||
public interface IImageSourcePolicy | ||
{ | ||
public interface IImageSourcePolicy | ||
{ | ||
bool IsAllowed(Uri uri, Uri appUri); | ||
} | ||
bool IsAllowed(Uri uri, Uri appUri); | ||
} |
31 changes: 15 additions & 16 deletions
31
src/shell/dotnet/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 |
---|---|---|
@@ -1,28 +1,27 @@ | ||
using System; | ||
using System.Windows.Media.Imaging; | ||
|
||
namespace Shell.ImageSource | ||
namespace Shell.ImageSource; | ||
|
||
public class ImageSourceProvider | ||
{ | ||
public class ImageSourceProvider | ||
private readonly IImageSourcePolicy _imageSourcePolicy; | ||
public ImageSourceProvider(IImageSourcePolicy imageSourcePolicy) | ||
{ | ||
IImageSourcePolicy _imageSourcePolicy; | ||
public ImageSourceProvider(IImageSourcePolicy imageSourcePolicy) | ||
_imageSourcePolicy = imageSourcePolicy; | ||
} | ||
|
||
public System.Windows.Media.ImageSource? GetImageSource(Uri uri, Uri appUri) | ||
{ | ||
if (!uri.IsAbsoluteUri) | ||
{ | ||
_imageSourcePolicy = imageSourcePolicy; | ||
uri = new Uri(appUri, uri); | ||
} | ||
|
||
public System.Windows.Media.ImageSource? GetImageSource(Uri uri, Uri appUri) | ||
if (_imageSourcePolicy.IsAllowed(uri, appUri)) | ||
{ | ||
if (!uri.IsAbsoluteUri) | ||
{ | ||
uri = new Uri(appUri, uri); | ||
} | ||
|
||
if (_imageSourcePolicy.IsAllowed(uri, appUri)) | ||
{ | ||
return BitmapFrame.Create(uri); | ||
} | ||
return null; | ||
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
Oops, something went wrong.