Skip to content

Commit

Permalink
fix crash when attempting to open docs browser (#14787)
Browse files Browse the repository at this point in the history
* remove IronPython code and extension (#14706)

* remove legacy completion provider

* remove

* remove obsolete -arguable

tests seem to pass going to merge this and cherry pick to 3.0

* fix crash (#14782)
  • Loading branch information
mjkkirschner authored Dec 19, 2023
1 parent 9fe1f83 commit dce2ee7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,21 @@ async void InitializeAsync()

initState = AsyncMethodState.Done;
}
//if we make it this far, for example to do re-entry to to this method, while we're still
//initializing, don't do anything, just bail.
if(initState == AsyncMethodState.Done)
{
if (Directory.Exists(VirtualFolderPath))
{
//Due that the Web Browser(WebView2 - Chromium) security CORS is blocking the load of resources like images then we need to create a virtual folder in which the image are located.
this.documentationBrowser?.CoreWebView2?.SetVirtualHostNameToFolderMapping(VIRTUAL_FOLDER_MAPPING, VirtualFolderPath, CoreWebView2HostResourceAccessKind.DenyCors);
}
string htmlContent = this.viewModel.GetContent();

if(Directory.Exists(VirtualFolderPath))
//Due that the Web Browser(WebView2 - Chromium) security CORS is blocking the load of resources like images then we need to create a virtual folder in which the image are located.
this.documentationBrowser.CoreWebView2.SetVirtualHostNameToFolderMapping(VIRTUAL_FOLDER_MAPPING, VirtualFolderPath, CoreWebView2HostResourceAccessKind.DenyCors);

string htmlContent = this.viewModel.GetContent();

htmlContent = ResourceUtilities.LoadResourceAndReplaceByKey(htmlContent, "#fontStyle", fontStylePath);
htmlContent = ResourceUtilities.LoadResourceAndReplaceByKey(htmlContent, "#fontStyle", fontStylePath);

this.documentationBrowser.NavigateToString(htmlContent);
this.documentationBrowser.NavigateToString(htmlContent);
}
}

private void CoreWebView2OnWebMessageReceived(object sender, CoreWebView2WebMessageReceivedEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,30 @@ public void CanHandleDocsEventTriggeredFromDynamoViewModel()
Assert.IsTrue(htmlContent.Contains(excelDocsFileHtmlHeader));
}

[Test]
public void CanHandleDocsEventTriggeredFromDynamoViewModelMultipleTimes()
{
// Arrange
var docsEvent = new OpenDocumentationLinkEventArgs(new Uri(localDocsFileLink, UriKind.Relative));

// Act
var tabsBeforeExternalEventTrigger = this.ViewModel.SideBarTabItems.Count;
this.ViewModel.OpenDocumentationLinkCommand.Execute(docsEvent);
this.ViewModel.OpenDocumentationLinkCommand.Execute(docsEvent);
this.ViewModel.OpenDocumentationLinkCommand.Execute(docsEvent);

WaitForWebView2Initialization();

var tabsAfterExternalEventTrigger = this.ViewModel.SideBarTabItems.Count;
var htmlContent = GetSidebarDocsBrowserContents();

// Assert
Assert.IsFalse(docsEvent.IsRemoteResource);
Assert.AreEqual(0, tabsBeforeExternalEventTrigger);
Assert.AreEqual(1, tabsAfterExternalEventTrigger);
Assert.IsTrue(htmlContent.Contains(excelDocsFileHtmlHeader));
}

[Test]
public void Displays404PageOnMissingDocFile()
{
Expand Down

0 comments on commit dce2ee7

Please sign in to comment.