WebGLWebPlugin.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 && !UNITY_EDITOR
  15. using System;
  16. using UnityEngine;
  17. using Vuplex.WebView.Internal;
  18. namespace Vuplex.WebView {
  19. class WebGLWebPlugin : IWebPlugin {
  20. public ICookieManager CookieManager { get; } = null;
  21. public static WebGLWebPlugin Instance {
  22. get {
  23. if (_instance == null) {
  24. _instance = new WebGLWebPlugin();
  25. }
  26. return _instance;
  27. }
  28. }
  29. public WebPluginType Type { get; } = WebPluginType.WebGL;
  30. public void ClearAllData() {
  31. _logNotSupportedWarning("Web.ClearAllData", "clearing browser data");
  32. }
  33. // Deprecated
  34. public void CreateMaterial(Action<Material> callback) => callback(null);
  35. public IWebView CreateWebView() => WebGLWebView.Instantiate();
  36. public void EnableRemoteDebugging() {
  37. WebViewLogger.Log("Remote debugging is enabled for WebGL. For instructions, please see https://support.vuplex.com/articles/how-to-debug-web-content#webgl.");
  38. }
  39. public void SetAutoplayEnabled(bool enabled) {
  40. _logNotSupportedWarning("Web.SetAutoplayEnabled", "enabling autoplay");
  41. }
  42. public void SetCameraAndMicrophoneEnabled(bool enabled) => WebGLWebView.SetCameraAndMicrophoneEnabled(enabled);
  43. public void SetIgnoreCertificateErrors(bool ignore) {
  44. _logNotSupportedWarning("Web.SetIgnoreCertificateErrors", "ignoring certificate errors");
  45. }
  46. public void SetStorageEnabled(bool enabled) {
  47. _logNotSupportedWarning("Web.SetStorageEnabled", "disabling storage");
  48. }
  49. public void SetUserAgent(bool mobile) {
  50. _logNotSupportedWarning("Web.SetUserAgent", "changing the User-Agent");
  51. }
  52. public void SetUserAgent(string userAgent) {
  53. _logNotSupportedWarning("Web.SetUserAgent", "changing the User-Agent");
  54. }
  55. static WebGLWebPlugin _instance;
  56. void _logNotSupportedWarning(string methodName, string unsupportedActionDescription) {
  57. WebViewLogger.LogWarning($"2D WebView for WebGL doesn't support {unsupportedActionDescription} due to browser limitations, so the call to {methodName}() will be ignored.");
  58. }
  59. }
  60. }
  61. #endif