WebGLWarnings.cs 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright (c) 2024 Vuplex Inc. All rights reserved.
  2. //
  3. // Licensed under the Vuplex Commercial Software Library License, you may
  4. // not use this file except in compliance with the License. You may obtain
  5. // a copy of the License at
  6. //
  7. // https://vuplex.com/commercial-library-license
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #if UNITY_WEBGL
  15. using System;
  16. namespace Vuplex.WebView.Internal {
  17. static class WebGLWarnings {
  18. public static string GetArticleLinkText(bool includeFormatting = true) {
  19. return $" For more info, please see this article: {(includeFormatting ? "<em>" : "")}https://support.vuplex.com/articles/webgl-limitations{(includeFormatting ? "</em>" : "")}";
  20. }
  21. public static void LogCanGoBackOrForwardWarning() {
  22. if (!_hasLoggedBackForwardWarning) {
  23. WebViewLogger.LogWarning("Just a heads-up: due to browser limitations on WebGL, CanGoBack() and CanGoForward() both return whether the webview can either go back *or* forward when running in the browser. In other words, when running in the browser, both methods return true if the webview can go either back or foward, and both return false if the webview can't go back or forward." + GetArticleLinkText());
  24. _hasLoggedBackForwardWarning = true;
  25. }
  26. }
  27. public static void LogCaptureScreenshotError() => _logNotSupportedError("CaptureScreenshot", "taking a screenshot of the web content");
  28. public static void LogCopyError() => _logNotSupportedError("Copy", "manipulating the clipboard");
  29. public static void LogCutError() => _logNotSupportedError("Cut", "manipulating the clipboard");
  30. public static void LogGetRawTextureDataError() => _logNotSupportedError("GetRawTextureData", "rendering web content to a texture");
  31. public static void LogIFrameContentAccessWarning(string methodName) {
  32. #if UNITY_EDITOR
  33. WebViewLogger.LogWarning($"{methodName}() was called but will likely be disabled when running on WebGL due to browser limitations. If the webview's URL is set to a domain that is different than the domain of the Unity app, then 2D WebView is unable to execute {methodName}() due to browser security restrictions." + GetArticleLinkText());
  34. #else
  35. WebViewLogger.LogError($"{methodName}() was called but is currently disabled due to browser limitations. The webview's URL is set to a domain that is different than the domain of the Unity app, so 2D WebView is unable to execute {methodName}() due to browser security restrictions." + GetArticleLinkText());
  36. #endif
  37. }
  38. public static void LogLoadHtmlWarning() {
  39. WebViewLogger.LogWarning("Due to browser limitations on WebGL, most IWebView methods are disabled when HTML is loaded with LoadHtml(). An alternative without this limitation is to load the HTML from StreamingAssets using LoadUrl() instead." + GetArticleLinkText());
  40. }
  41. public static void LogPasteError() => _logNotSupportedError("Paste", "accessing the clipboard");
  42. public static void LogZoomInError() => _logNotSupportedError("ZoomIn", "zooming in");
  43. public static void LogZoomOutError() => _logNotSupportedError("ZoomOut", "zooming out");
  44. static bool _hasLoggedBackForwardWarning;
  45. static void _logNotSupportedError(string methodName, string unsupportedActionDescription) {
  46. WebViewLogger.LogError($"2D WebView for WebGL doesn't support {unsupportedActionDescription} due to browser limitations, so the call to {methodName}() will be ignored when running in the browser." + GetArticleLinkText());
  47. }
  48. }
  49. }
  50. #endif