StandaloneWebPlugin.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright (c) 2022 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_STANDALONE_WIN || UNITY_EDITOR_WIN || UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX
  15. using System;
  16. using UnityEngine;
  17. using Vuplex.WebView.Internal;
  18. namespace Vuplex.WebView {
  19. /// <summary>
  20. /// The base class for WindowsWebPlugin and MacWebPlugin.
  21. /// </summary>
  22. public class StandaloneWebPlugin : MonoBehaviour {
  23. public ICookieManager CookieManager { get; } = StandaloneCookieManager.Instance;
  24. public void ClearAllData() => StandaloneWebView.ClearAllData();
  25. // Deprecated
  26. public void CreateMaterial(Action<Material> callback) => callback(VXUtils.CreateDefaultMaterial());
  27. public void EnableRemoteDebugging() {
  28. var platform = Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.WindowsEditor ? "Windows" : "macOS";
  29. StandaloneWebView.EnableRemoteDebugging(8080);
  30. WebViewLogger.Log($"Enabling remote debugging for {platform} on port 8080. Please visit http://localhost:8080 using a Chromium-based browser. For more info, see <em>https://support.vuplex.com/articles/how-to-debug-web-content#standalone</em>.");
  31. }
  32. public void SetAutoplayEnabled(bool enabled) => StandaloneWebView.SetAutoplayEnabled(enabled);
  33. public void SetCameraAndMicrophoneEnabled(bool enabled) => StandaloneWebView.SetCameraAndMicrophoneEnabled(enabled);
  34. public void SetIgnoreCertificateErrors(bool ignore)=> StandaloneWebView.SetIgnoreCertificateErrors(ignore);
  35. public void SetStorageEnabled(bool enabled) => StandaloneWebView.SetStorageEnabled(enabled);
  36. public void SetUserAgent(bool mobile) => StandaloneWebView.GloballySetUserAgent(mobile);
  37. public void SetUserAgent(string userAgent) => StandaloneWebView.GloballySetUserAgent(userAgent);
  38. #if UNITY_2020_3_OR_NEWER
  39. void Start() {
  40. // It's preferable to use Application.quitting instead
  41. // of OnApplicationQuit(), because the latter is called even if
  42. // the quit is cancelled by the application returning false from
  43. // Application.wantsToQuit, and the former is called only when the
  44. // application really quits. Application.quitting was added in 2018.1, but in
  45. // 2020.1 and 2020.2 it has a bug where it isn't raised when the application is
  46. // quit with alt+f4:
  47. // https://issuetracker.unity3d.com/issues/application-dot-quitting-event-is-not-raised-when-closing-build
  48. Application.quitting += () => StandaloneWebView.TerminateBrowserProcess();
  49. }
  50. #else
  51. void OnApplicationQuit() => StandaloneWebView.TerminateBrowserProcess();
  52. #endif
  53. }
  54. }
  55. #endif