Skip to content
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
Next Next commit
Start removing IJSUnmarshalledRuntime usage
  • Loading branch information
MackinnonBuck committed Feb 16, 2023
commit 12a4f90dd62b89e048f11dee289b64540435bae0
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ internal static class BrowserNavigationManagerInterop

public const string EnableNavigationInterception = Prefix + "enableNavigationInterception";

public const string GetLocationHref = Prefix + "getUnmarshalledLocationHref";
public const string GetLocationHref = Prefix + "getLocationHref";

public const string GetBaseUri = Prefix + "getUnmarshalledBaseURI";
public const string GetBaseUri = Prefix + "getBaseURI";

public const string NavigateTo = Prefix + "navigateTo";

Expand Down
2 changes: 1 addition & 1 deletion src/Components/Web.JS/dist/Release/blazor.server.js

Large diffs are not rendered by default.

16 changes: 5 additions & 11 deletions src/Components/Web.JS/src/Boot.WebAssembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,6 @@ async function boot(options?: Partial<WebAssemblyStartOptions>): Promise<void> {
}
};

// Configure navigation via JS Interop
const getBaseUri = Blazor._internal.navigationManager.getBaseURI;
const getLocationHref = Blazor._internal.navigationManager.getLocationHref;
Blazor._internal.navigationManager.getUnmarshalledBaseURI = () => BINDING.js_string_to_mono_string(getBaseUri());
Blazor._internal.navigationManager.getUnmarshalledLocationHref = () => BINDING.js_string_to_mono_string(getLocationHref());

Blazor._internal.navigationManager.listenForNavigationEvents(async (uri: string, state: string | undefined, intercepted: boolean): Promise<void> => {
await DotNet.invokeMethodAsync(
'Microsoft.AspNetCore.Components.WebAssembly',
Expand Down Expand Up @@ -114,13 +108,13 @@ async function boot(options?: Partial<WebAssemblyStartOptions>): Promise<void> {
Blazor._internal.registeredComponents = {
getRegisteredComponentsCount: () => componentAttacher.getCount(),
getId: (index) => componentAttacher.getId(index),
getAssembly: (id) => BINDING.js_string_to_mono_string(componentAttacher.getAssembly(id)),
getTypeName: (id) => BINDING.js_string_to_mono_string(componentAttacher.getTypeName(id)),
getParameterDefinitions: (id) => BINDING.js_string_to_mono_string(componentAttacher.getParameterDefinitions(id) || ''),
getParameterValues: (id) => BINDING.js_string_to_mono_string(componentAttacher.getParameterValues(id) || ''),
getAssembly: (id) => componentAttacher.getAssembly(id),
getTypeName: (id) => componentAttacher.getTypeName(id),
getParameterDefinitions: (id) => componentAttacher.getParameterDefinitions(id) || '',
getParameterValues: (id) => componentAttacher.getParameterValues(id) || '',
};

Blazor._internal.getPersistedState = () => BINDING.js_string_to_mono_string(discoverPersistedState(document) || '');
Blazor._internal.getPersistedState = () => discoverPersistedState(document) || '';

Blazor._internal.attachRootComponentToElement = (selector, componentId, rendererId: any) => {
const element = componentAttacher.resolveRegisteredElement(selector);
Expand Down
12 changes: 6 additions & 6 deletions src/Components/Web.JS/src/GlobalExports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ interface IBlazor {
endInvokeDotNetFromJS?: (callId: System_String, success: System_Boolean, resultJsonOrErrorMessage: System_String) => void;
receiveByteArray?: (id: System_Int, data: System_Array<System_Byte>) => void;
retrieveByteArray?: () => System_Object;
getPersistedState?: () => System_String;
getPersistedState?: () => string;
attachRootComponentToElement?: (arg0: any, arg1: any, arg2: any, arg3: any) => void;
registeredComponents?: {
getRegisteredComponentsCount: () => number,
getId: (index) => number,
getAssembly: (id) => System_String,
getTypeName: (id) => System_String,
getParameterDefinitions: (id) => System_String,
getAssembly: (id) => string,
getTypeName: (id) => string,
getParameterDefinitions: (id) => string,
getParameterValues: (id) => any,
};
renderBatch?: (browserRendererId: number, batchAddress: Pointer) => void,
getConfig?: (dotNetFileName: System_String) => System_Object | undefined,
getApplicationEnvironment?: () => System_String,
getConfig?: (fileName: string) => Uint8Array | undefined,
getApplicationEnvironment?: () => string,
dotNetCriticalError?: any
loadLazyAssembly?: any,
loadSatelliteAssemblies?: any,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@

import { BootConfigResult } from './BootConfig';
import { WebAssemblyStartOptions } from './WebAssemblyStartOptions';
import { System_String, System_Object } from './Platform';
import { Blazor } from '../GlobalExports';
import { BINDING } from './Mono/MonoPlatform';

export class WebAssemblyConfigLoader {
static async initAsync(bootConfigResult: BootConfigResult, startOptions: Partial<WebAssemblyStartOptions>): Promise<void> {
Blazor._internal.getApplicationEnvironment = () => BINDING.js_string_to_mono_string(bootConfigResult.applicationEnvironment);
Blazor._internal.getApplicationEnvironment = () => bootConfigResult.applicationEnvironment;

const configFiles = await Promise.all((bootConfigResult.bootConfig.config || [])
.filter(name => name === 'appsettings.json' || name === `appsettings.${bootConfigResult.applicationEnvironment}.json`)
.map(async name => ({ name, content: await getConfigBytes(name) })));

Blazor._internal.getConfig = (dotNetFileName: System_String) : System_Object | undefined => {
const fileName = BINDING.conv_string(dotNetFileName);
Blazor._internal.getConfig = (fileName: string) : Uint8Array | undefined => {
const resolvedFile = configFiles.find(f => f.name === fileName);
return resolvedFile ? BINDING.js_typed_array_to_array(resolvedFile.content) : undefined;
return resolvedFile ? resolvedFile.content : undefined;
};

async function getConfigBytes(file: string): Promise<Uint8Array> {
Expand Down
3 changes: 0 additions & 3 deletions src/Components/Web/src/Forms/InputFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ public class InputFile : ComponentBase, IInputFileJsCallbacks, IDisposable
{
private ElementReference _inputFileElement;

private IJSUnmarshalledRuntime? _jsUnmarshalledRuntime;

private InputFileJsCallbacksRelay? _jsCallbacksRelay;

[Inject]
Expand Down Expand Up @@ -49,7 +47,6 @@ public ElementReference? Element
/// <inheritdoc/>
protected override void OnInitialized()
{
_jsUnmarshalledRuntime = JSRuntime as IJSUnmarshalledRuntime;
}

/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</ItemGroup>

<ItemGroup>
<Compile Include="..\..\WebAssembly\test\TestJSUnmarshalledRuntime.cs" Link="Shared\TestWebAssemblyJSRuntimeInvoker.cs" />
<Compile Include="..\..\WebAssembly\test\TestInternalJSImportMethods.cs" Link="Shared\TestInternalJSImportMethods.cs" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class WebAssemblyAuthenticationServiceCollectionExtensionsTests
[Fact]
public void CanResolve_AccessTokenProvider()
{
var builder = new WebAssemblyHostBuilder(new TestJSUnmarshalledRuntime(), JsonOptions);
var builder = new WebAssemblyHostBuilder(new TestInternalJSImportMethods(), JsonOptions);
builder.Services.AddApiAuthorization();
var host = builder.Build();

Expand All @@ -27,7 +27,7 @@ public void CanResolve_AccessTokenProvider()
[Fact]
public void CanResolve_IRemoteAuthenticationService()
{
var builder = new WebAssemblyHostBuilder(new TestJSUnmarshalledRuntime(), JsonOptions);
var builder = new WebAssemblyHostBuilder(new TestInternalJSImportMethods(), JsonOptions);
builder.Services.AddApiAuthorization();
var host = builder.Build();

Expand All @@ -37,7 +37,7 @@ public void CanResolve_IRemoteAuthenticationService()
[Fact]
public void ApiAuthorizationOptions_ConfigurationDefaultsGetApplied()
{
var builder = new WebAssemblyHostBuilder(new TestJSUnmarshalledRuntime(), JsonOptions);
var builder = new WebAssemblyHostBuilder(new TestInternalJSImportMethods(), JsonOptions);
builder.Services.AddApiAuthorization();
var host = builder.Build();

Expand Down Expand Up @@ -71,7 +71,7 @@ public void ApiAuthorizationOptions_ConfigurationDefaultsGetApplied()
[Fact]
public void ApiAuthorizationOptionsConfigurationCallback_GetsCalledOnce()
{
var builder = new WebAssemblyHostBuilder(new TestJSUnmarshalledRuntime(), JsonOptions);
var builder = new WebAssemblyHostBuilder(new TestInternalJSImportMethods(), JsonOptions);
var calls = 0;
builder.Services.AddApiAuthorization(options =>
{
Expand All @@ -98,7 +98,7 @@ public void ApiAuthorizationOptionsConfigurationCallback_GetsCalledOnce()
[Fact]
public void ApiAuthorizationTestAuthenticationState_SetsUpConfiguration()
{
var builder = new WebAssemblyHostBuilder(new TestJSUnmarshalledRuntime(), JsonOptions);
var builder = new WebAssemblyHostBuilder(new TestInternalJSImportMethods(), JsonOptions);
var calls = 0;
builder.Services.AddApiAuthorization<TestAuthenticationState>(options => calls++);

Expand All @@ -124,7 +124,7 @@ public void ApiAuthorizationTestAuthenticationState_SetsUpConfiguration()
[Fact]
public void ApiAuthorizationTestAuthenticationState_NoCallback_SetsUpConfiguration()
{
var builder = new WebAssemblyHostBuilder(new TestJSUnmarshalledRuntime(), JsonOptions);
var builder = new WebAssemblyHostBuilder(new TestInternalJSImportMethods(), JsonOptions);
builder.Services.AddApiAuthorization<TestAuthenticationState>();

var host = builder.Build();
Expand All @@ -147,7 +147,7 @@ public void ApiAuthorizationTestAuthenticationState_NoCallback_SetsUpConfigurati
[Fact]
public void ApiAuthorizationCustomAuthenticationStateAndAccount_SetsUpConfiguration()
{
var builder = new WebAssemblyHostBuilder(new TestJSUnmarshalledRuntime(), JsonOptions);
var builder = new WebAssemblyHostBuilder(new TestInternalJSImportMethods(), JsonOptions);
var calls = 0;
builder.Services.AddApiAuthorization<TestAuthenticationState, TestAccount>(options => calls++);

Expand All @@ -173,7 +173,7 @@ public void ApiAuthorizationCustomAuthenticationStateAndAccount_SetsUpConfigurat
[Fact]
public void ApiAuthorizationTestAuthenticationStateAndAccount_NoCallback_SetsUpConfiguration()
{
var builder = new WebAssemblyHostBuilder(new TestJSUnmarshalledRuntime(), JsonOptions);
var builder = new WebAssemblyHostBuilder(new TestInternalJSImportMethods(), JsonOptions);
builder.Services.AddApiAuthorization<TestAuthenticationState, TestAccount>();

var host = builder.Build();
Expand All @@ -196,7 +196,7 @@ public void ApiAuthorizationTestAuthenticationStateAndAccount_NoCallback_SetsUpC
[Fact]
public void ApiAuthorizationOptions_DefaultsCanBeOverriden()
{
var builder = new WebAssemblyHostBuilder(new TestJSUnmarshalledRuntime(), JsonOptions);
var builder = new WebAssemblyHostBuilder(new TestInternalJSImportMethods(), JsonOptions);
builder.Services.AddApiAuthorization(options =>
{
options.AuthenticationPaths.LogInPath = "a";
Expand Down Expand Up @@ -247,7 +247,7 @@ public void ApiAuthorizationOptions_DefaultsCanBeOverriden()
[Fact]
public void OidcOptions_ConfigurationDefaultsGetApplied()
{
var builder = new WebAssemblyHostBuilder(new TestJSUnmarshalledRuntime(), JsonOptions);
var builder = new WebAssemblyHostBuilder(new TestInternalJSImportMethods(), JsonOptions);
builder.Services.Replace(ServiceDescriptor.Singleton<NavigationManager, TestNavigationManager>());
builder.Services.AddOidcAuthentication(options => { });
var host = builder.Build();
Expand Down Expand Up @@ -286,7 +286,7 @@ public void OidcOptions_ConfigurationDefaultsGetApplied()
[Fact]
public void OidcOptions_DefaultsCanBeOverriden()
{
var builder = new WebAssemblyHostBuilder(new TestJSUnmarshalledRuntime(), JsonOptions);
var builder = new WebAssemblyHostBuilder(new TestInternalJSImportMethods(), JsonOptions);
builder.Services.AddOidcAuthentication(options =>
{
options.AuthenticationPaths.LogInPath = "a";
Expand Down Expand Up @@ -348,7 +348,7 @@ public void OidcOptions_DefaultsCanBeOverriden()
[Fact]
public void AddOidc_ConfigurationGetsCalledOnce()
{
var builder = new WebAssemblyHostBuilder(new TestJSUnmarshalledRuntime(), JsonOptions);
var builder = new WebAssemblyHostBuilder(new TestInternalJSImportMethods(), JsonOptions);
var calls = 0;

builder.Services.AddOidcAuthentication(options => calls++);
Expand All @@ -365,7 +365,7 @@ public void AddOidc_ConfigurationGetsCalledOnce()
[Fact]
public void AddOidc_CustomState_SetsUpConfiguration()
{
var builder = new WebAssemblyHostBuilder(new TestJSUnmarshalledRuntime(), JsonOptions);
var builder = new WebAssemblyHostBuilder(new TestInternalJSImportMethods(), JsonOptions);
var calls = 0;

builder.Services.AddOidcAuthentication<TestAuthenticationState>(options => options.ProviderOptions.Authority = (++calls).ToString(CultureInfo.InvariantCulture));
Expand All @@ -387,7 +387,7 @@ public void AddOidc_CustomState_SetsUpConfiguration()
[Fact]
public void AddOidc_CustomStateAndAccount_SetsUpConfiguration()
{
var builder = new WebAssemblyHostBuilder(new TestJSUnmarshalledRuntime(), JsonOptions);
var builder = new WebAssemblyHostBuilder(new TestInternalJSImportMethods(), JsonOptions);
var calls = 0;

builder.Services.AddOidcAuthentication<TestAuthenticationState, TestAccount>(options => options.ProviderOptions.Authority = (++calls).ToString(CultureInfo.InvariantCulture));
Expand All @@ -409,7 +409,7 @@ public void AddOidc_CustomStateAndAccount_SetsUpConfiguration()
[Fact]
public void OidcProviderOptionsAndDependencies_NotResolvedFromRootScope()
{
var builder = new WebAssemblyHostBuilder(new TestJSUnmarshalledRuntime(), JsonOptions);
var builder = new WebAssemblyHostBuilder(new TestInternalJSImportMethods(), JsonOptions);

var calls = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
using System.Runtime.InteropServices.JavaScript;
using System.Runtime.Loader;
using System.Runtime.Versioning;
using Microsoft.AspNetCore.Components.WebAssembly.Services;
using Microsoft.JSInterop;

namespace Microsoft.AspNetCore.Components.WebAssembly.Hosting;

Expand All @@ -19,12 +17,9 @@ internal partial class WebAssemblyCultureProvider
internal const string GetSatelliteAssemblies = "window.Blazor._internal.getSatelliteAssemblies";
internal const string ReadSatelliteAssemblies = "window.Blazor._internal.readSatelliteAssemblies";

private readonly IJSUnmarshalledRuntime _invoker;

// For unit testing.
internal WebAssemblyCultureProvider(IJSUnmarshalledRuntime invoker, CultureInfo initialCulture, CultureInfo initialUICulture)
internal WebAssemblyCultureProvider(CultureInfo initialCulture, CultureInfo initialUICulture)
{
_invoker = invoker;
InitialCulture = initialCulture;
InitialUICulture = initialUICulture;
}
Expand All @@ -38,7 +33,6 @@ internal WebAssemblyCultureProvider(IJSUnmarshalledRuntime invoker, CultureInfo
internal static void Initialize()
{
Instance = new WebAssemblyCultureProvider(
DefaultWebAssemblyJSRuntime.Instance,
initialCulture: CultureInfo.CurrentCulture,
initialUICulture: CultureInfo.CurrentUICulture);
}
Expand Down
Loading