Skip to content

Commit

Permalink
Merge pull request #123 from tryphotino/debug
Browse files Browse the repository at this point in the history
Merge from Debug
  • Loading branch information
MikeYeager authored Jan 11, 2024
2 parents 9e33f78 + 8f4c107 commit 639b289
Show file tree
Hide file tree
Showing 20 changed files with 173 additions and 62 deletions.
1 change: 1 addition & 0 deletions Photino.Native.sln
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Global
{056ABF92-CFED-4800-8439-ECFA5C55B029}.Debug|x86.Build.0 = Debug|Any CPU
{056ABF92-CFED-4800-8439-ECFA5C55B029}.Release|Any CPU.ActiveCfg = Release|Any CPU
{056ABF92-CFED-4800-8439-ECFA5C55B029}.Release|ARM64.ActiveCfg = Release|ARM64
{056ABF92-CFED-4800-8439-ECFA5C55B029}.Release|ARM64.Build.0 = Release|ARM64
{056ABF92-CFED-4800-8439-ECFA5C55B029}.Release|x64.ActiveCfg = Release|Any CPU
{056ABF92-CFED-4800-8439-ECFA5C55B029}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
Expand Down
5 changes: 5 additions & 0 deletions Photino.Native/Exports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ extern "C"
instance->GetMinimized(isMinimized);
}

EXPORTED void Photino_GetIgnoreCertificateErrorsEnabled(Photino* instance, bool *disabled)
{
instance->GetIgnoreCertificateErrorsEnabled(disabled);
}

EXPORTED void Photino_GetPosition(Photino* instance, int* x, int* y)
{
instance->GetPosition(x, y);
Expand Down
16 changes: 14 additions & 2 deletions Photino.Native/Photino.Linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ Photino::Photino(PhotinoInitParams *initParams) : _webview(nullptr)
_javascriptClipboardAccessEnabled = initParams->JavascriptClipboardAccessEnabled;
_mediaStreamEnabled = initParams->MediaStreamEnabled;
_smoothScrollingEnabled = initParams->SmoothScrollingEnabled;
_ignoreCertificateErrorsEnabled = initParams->IgnoreCertificateErrorsEnabled;

_zoom = initParams->Zoom;
_minWidth = initParams->MinWidth;
Expand Down Expand Up @@ -240,7 +241,7 @@ Photino::Photino(PhotinoInitParams *initParams) : _webview(nullptr)
G_CALLBACK(on_widget_deleted),
this);

Photino::Show();
Photino::Show(false);

g_signal_connect(G_OBJECT(_window), "focus-in-event",
G_CALLBACK(on_focus_in_event),
Expand Down Expand Up @@ -357,6 +358,11 @@ void Photino::GetSmoothScrollingEnabled(bool* enabled)
*enabled = this->_smoothScrollingEnabled;
}

void Photino::GetIgnoreCertificateErrorsEnabled(bool* enabled)
{
*enabled = this->_ignoreCertificateErrorsEnabled;
}

void Photino::GetMaximized(bool *isMaximized)
{
*isMaximized = gtk_window_is_maximized(GTK_WINDOW(_window));
Expand Down Expand Up @@ -697,7 +703,7 @@ void HandleWebMessage(WebKitUserContentManager *contentManager, WebKitJavascript
webkit_javascript_result_unref(jsResult);
}

void Photino::Show()
void Photino::Show(bool isAlreadyShown)
{
if (!_webview)
{
Expand Down Expand Up @@ -821,6 +827,12 @@ void Photino::set_webkit_settings()

if (_browserControlInitParameters != NULL && strlen(_browserControlInitParameters) > 0)
Photino::set_webkit_customsettings(settings); //if any custom init parameters were passed, set them now.

WebKitWebsiteDataManager* manager = webkit_web_view_get_website_data_manager(WEBKIT_WEB_VIEW(_webview));
if (_ignoreCertificateErrorsEnabled)
webkit_website_data_manager_set_tls_errors_policy(manager, WEBKIT_TLS_ERRORS_POLICY_IGNORE);
else
webkit_website_data_manager_set_tls_errors_policy(manager, WEBKIT_TLS_ERRORS_POLICY_FAIL);
}

void Photino::set_webkit_customsettings(WebKitSettings* settings)
Expand Down
5 changes: 4 additions & 1 deletion Photino.Native/Photino.Mac.Dialog.mm
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ifdef __APPLE__
#import "Photino.Dialog.h"

#if defined(VSTGUI_USE_OBJC_UTTYPE)
Expand Down Expand Up @@ -69,6 +70,7 @@
[openDlg setTitle:[NSString stringWithUTF8String:title]];
[openDlg setCanChooseFiles:NO];
[openDlg setCanChooseDirectories:YES];
[openDlg setCanCreateDirectories:YES];
[openDlg setAllowsMultipleSelection:multiSelect];
[openDlg setPrompt:[NSString stringWithUTF8String:"Open"]];
[openDlg setDirectoryURL:[NSURL fileURLWithPath:[NSString stringWithUTF8String:defaultPath]]];
Expand Down Expand Up @@ -226,4 +228,5 @@
}

return DialogResult::Cancel;
}
}
#endif
11 changes: 11 additions & 0 deletions Photino.Native/Photino.Mac.NavigationDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifdef __APPLE__
#pragma once
#include "Photino.h"

@interface NavigationDelegate: NSObject<WKNavigationDelegate>{
@public
NSWindow * window;
Photino * photino;
}
@end
#endif
25 changes: 25 additions & 0 deletions Photino.Native/Photino.Mac.NavigationDelegate.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifdef __APPLE__
#import "Photino.Mac.NavigationDelegate.h"

@implementation NavigationDelegate : NSObject

- (void)webView:(WKWebView *)webView
didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler {
bool ignoreCertificateErrorsEnabled = false;
photino->GetIgnoreCertificateErrorsEnabled(&ignoreCertificateErrorsEnabled);
if(ignoreCertificateErrorsEnabled)
{
SecTrustRef serverTrust = challenge.protectionSpace.serverTrust;
CFDataRef exceptions = SecTrustCopyExceptions(serverTrust);
CFRelease(exceptions);
completionHandler(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:serverTrust]);
}
else
{
completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil);
}
}

@end
#endif
4 changes: 3 additions & 1 deletion Photino.Native/Photino.Mac.UiDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ - (void)webView:(WKWebView *)webView
type:(WKMediaCaptureType)type
decisionHandler:(void (^)(WKPermissionDecision decision))decisionHandler
{
decisionHandler(WKPermissionDecisionPrompt);
bool grantPermissions;
photino->GetGrantBrowserPermissions(&grantPermissions);
decisionHandler(grantPermissions ? WKPermissionDecisionGrant : WKPermissionDecisionPrompt);
}

- (void)windowDidResize:(NSNotification *)notification {
Expand Down
18 changes: 16 additions & 2 deletions Photino.Native/Photino.Mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "Photino.Mac.UiDelegate.h"
#include "Photino.Mac.UrlSchemeHandler.h"
#include "Photino.Mac.NSWindowBorderless.h"
#include "Photino.Mac.NavigationDelegate.h"
#include <vector>

#include "json.hpp"
Expand Down Expand Up @@ -132,8 +133,10 @@
strcpy(_temporaryFilesPath, initParams->TemporaryFilesPath);
}

_ignoreCertificateErrorsEnabled = initParams->IgnoreCertificateErrorsEnabled;
_contextMenuEnabled = true; //not configurable on mac //initParams->ContextMenuEnabled;
// _zoom = initParams->Zoom;
_grantBrowserPermissions = initParams->GrantBrowserPermissions;

//these handlers are ALWAYS hooked up
_webMessageReceivedCallback = (WebMessageReceivedCallback)initParams->WebMessageReceivedHandler;
Expand All @@ -146,6 +149,7 @@
_minimizedCallback = (MinimizedCallback)initParams->MinimizedHandler;
_restoredCallback = (RestoredCallback)initParams->RestoredHandler;
_customSchemeCallback = (WebResourceRequestedCallback)initParams->CustomSchemeHandler;


//copy strings from the fixed size array passed, but only if they have a value.
for (int i = 0; i < 16; ++i)
Expand Down Expand Up @@ -291,7 +295,7 @@

_dialog = new PhotinoDialog();

Show();
Show(false);
SetFullScreen(initParams->FullScreen);
}

Expand Down Expand Up @@ -425,6 +429,11 @@
*resizable = (([_window styleMask] & NSWindowStyleMaskResizable) == NSWindowStyleMaskResizable);
}

void Photino::GetIgnoreCertificateErrorsEnabled(bool* enabled)
{
*enabled = this->_ignoreCertificateErrorsEnabled;
}

unsigned int Photino::GetScreenDpi()
{
//not supported on macOS - _window's devices collection does have dpi
Expand Down Expand Up @@ -866,11 +875,16 @@ void EnsureInvoke(dispatch_block_t block)
uiDelegate->window = _window;
uiDelegate->webMessageReceivedCallback = _webMessageReceivedCallback;

NavigationDelegate *navDelegate = [[[NavigationDelegate alloc] init] autorelease];
navDelegate->photino = this;
navDelegate->window = _window;

[userContentController
addScriptMessageHandler: uiDelegate
name:@"photinointerop"];

_webview.UIDelegate = uiDelegate;
_webview.navigationDelegate = navDelegate;

// TODO: Replace with WindowDelegate
[[NSNotificationCenter defaultCenter]
Expand All @@ -897,7 +911,7 @@ void EnsureInvoke(dispatch_block_t block)
}
}

void Photino::Show()
void Photino::Show(bool isAlreadyShown)
{
if (_webview == nil)
AttachWebView();
Expand Down
18 changes: 12 additions & 6 deletions Photino.Native/Photino.Native.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ COPY .\$(OutDir)WebView2Loader.dll ..\Photino.Test\bin\Win32\Debug\net6.0\</Comm
<PostBuildEvent>
<Message>
</Message>
<Command>COPY .\$(OutDir)Photino.Native.dll ..\Photino.Test\bin\x64\Debug\net6.0\
COPY .\$(OutDir)Photino.Native.pdb ..\Photino.Test\bin\x64\Debug\net6.0\
COPY .\$(OutDir)WebView2Loader.dll ..\Photino.Test\bin\x64\Debug\net6.0\</Command>
<Command>COPY .\$(OutDir)Photino.Native.dll ..\Photino.Test\bin\x64\Debug\net8.0\
COPY .\$(OutDir)Photino.Native.pdb ..\Photino.Test\bin\x64\Debug\net8.0\
COPY .\$(OutDir)WebView2Loader.dll ..\Photino.Test\bin\x64\Debug\net8.0\</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand Down Expand Up @@ -210,9 +210,9 @@ COPY .\$(OutDir)WebView2Loader.dll ..\Photino.Test\bin\x64\Debug\net6.0\</Comman
<PostBuildEvent>
<Message>
</Message>
<Command>COPY .\$(OutDir)Photino.Native.dll ..\Photino.Test\bin\ARM64\Debug\net6.0\
COPY .\$(OutDir)Photino.Native.pdb ..\Photino.Test\bin\ARM64\Debug\net6.0\
COPY .\$(OutDir)WebView2Loader.dll ..\Photino.Test\bin\ARM64\Debug\net6.0\</Command>
<Command>COPY .\$(OutDir)Photino.Native.dll ..\Photino.Test\bin\ARM64\Debug\net8.0\
COPY .\$(OutDir)Photino.Native.pdb ..\Photino.Test\bin\ARM64\Debug\net8.0\
COPY .\$(OutDir)WebView2Loader.dll ..\Photino.Test\bin\ARM64\Debug\net8.0\</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
Expand Down Expand Up @@ -245,8 +245,11 @@ COPY .\$(OutDir)WebView2Loader.dll ..\Photino.Test\bin\ARM64\Debug\net6.0\</Comm
</ItemGroup>
<ItemGroup>
<ClInclude Include="Dependencies\wintoastlib.h" />
<ClInclude Include="json.hpp" />
<ClInclude Include="Photino.h" />
<ClInclude Include="Photino.Mac.AppDelegate.h" />
<ClInclude Include="Photino.Mac.NavigationDelegate.h" />
<ClInclude Include="Photino.Mac.NSWindowBorderless.h" />
<ClInclude Include="Photino.Mac.UiDelegate.h" />
<ClInclude Include="Photino.Mac.UrlSchemeHandler.h" />
<ClInclude Include="Photino.Dialog.h" />
Expand All @@ -256,7 +259,10 @@ COPY .\$(OutDir)WebView2Loader.dll ..\Photino.Test\bin\ARM64\Debug\net6.0\</Comm
<ItemGroup>
<None Include="packages.config" />
<None Include="Photino.Mac.AppDelegate.mm" />
<None Include="Photino.Mac.Dialog.mm" />
<None Include="Photino.Mac.mm" />
<None Include="Photino.Mac.NavigationDelegate.mm" />
<None Include="Photino.Mac.NSWindowBorderless.mm" />
<None Include="Photino.Mac.UiDelegate.mm" />
<None Include="Photino.Mac.UrlSchemeHandler.mm" />
<None Include="Photino.Native.nuspec">
Expand Down
18 changes: 18 additions & 0 deletions Photino.Native/Photino.Native.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@
<None Include="Photino.Mac.UrlSchemeHandler.mm">
<Filter>Source Files</Filter>
</None>
<None Include="Photino.Mac.Dialog.mm">
<Filter>Source Files</Filter>
</None>
<None Include="Photino.Mac.NavigationDelegate.mm">
<Filter>Source Files</Filter>
</None>
<None Include="Photino.Mac.NSWindowBorderless.mm">
<Filter>Source Files</Filter>
</None>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Photino.h">
Expand All @@ -78,6 +87,15 @@
<ClInclude Include="Photino.Dialog.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="json.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Photino.Mac.NavigationDelegate.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Photino.Mac.NSWindowBorderless.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Natvis Include="$(MSBuildThisFileDirectory)..\..\natvis\wil.natvis" />
Expand Down
21 changes: 17 additions & 4 deletions Photino.Native/Photino.Windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ Photino::Photino(PhotinoInitParams* initParams)
_javascriptClipboardAccessEnabled = initParams->JavascriptClipboardAccessEnabled;
_mediaStreamEnabled = initParams->MediaStreamEnabled;
_smoothScrollingEnabled = initParams->SmoothScrollingEnabled;
_ignoreCertificateErrorsEnabled = initParams->IgnoreCertificateErrorsEnabled;

_zoom = initParams->Zoom;
_minWidth = initParams->MinWidth;
Expand Down Expand Up @@ -266,7 +267,9 @@ Photino::Photino(PhotinoInitParams* initParams)
this->_toastHandler = new WinToastHandler(this);
WinToast::instance()->initialize();
_dialog = new PhotinoDialog(this);
Photino::Show();

bool isAlreadyShown = initParams->Minimized || initParams->Maximized;
Photino::Show(isAlreadyShown);
}

Photino::~Photino()
Expand Down Expand Up @@ -508,6 +511,11 @@ void Photino::GetSmoothScrollingEnabled(bool* enabled)
*enabled = this->_smoothScrollingEnabled;
}

void Photino::GetIgnoreCertificateErrorsEnabled(bool* enabled)
{
*enabled = this->_ignoreCertificateErrorsEnabled;
}

AutoString Photino::GetIconFileName()
{
return this->_iconFileName;
Expand Down Expand Up @@ -748,7 +756,8 @@ void Photino::ShowNotification(AutoString title, AutoString body)
WinToastTemplate toast = WinToastTemplate(WinToastTemplate::ImageAndText02);
toast.setTextField(title, WinToastTemplate::FirstLine);
toast.setTextField(body, WinToastTemplate::SecondLine);
toast.setImagePath(this->_iconFileName);
if (this->_iconFileName != NULL)
toast.setImagePath(this->_iconFileName);
WinToast::instance()->showToast(toast, _toastHandler);
}
}
Expand Down Expand Up @@ -841,6 +850,8 @@ void Photino::AttachWebView()
startupString += L"--enable-usermedia-screen-capturing ";
if (!_smoothScrollingEnabled)
startupString += L"--disable-smooth-scrolling ";
if (_ignoreCertificateErrorsEnabled)
startupString += L"--ignore-certificate-errors ";
if (_browserControlInitParameters != NULL)
startupString += _browserControlInitParameters; //e.g.--hide-scrollbars

Expand Down Expand Up @@ -1080,9 +1091,11 @@ void Photino::SetWebView2RuntimePath(AutoString pathToWebView2)
}
}

void Photino::Show()
void Photino::Show(bool isAlreadyShown)
{
ShowWindow(_hWnd, SW_SHOWDEFAULT);
if (!isAlreadyShown)
ShowWindow(_hWnd, SW_SHOWDEFAULT); //causes maximized and minimized to not work

UpdateWindow(_hWnd);

// Strangely, it only works to create the webview2 *after* the window has been shown,
Expand Down
Loading

0 comments on commit 639b289

Please sign in to comment.