UI Framework-1: Aura Multi-desktop

Multi-desktop

Aura now makes it possible for the same browser process to render to multiple desktops simultaneously (e.g., Native Desktop and Metro Desktop on Windows 8).
 
To enable this, the Chromium codebase had to be made multi-desktop aware (i.e., chrome::HostDesktopType parameters were added in several locations).
 
So... a bunch of methods now take chrome::HostDesktopType, but how do you get the right HostDesktopType when you need to provide one?
There are many ways:
  1. If you have a Browser: take its host_desktop_type() member.
  2. If you have a gfx::NativeView: use chrome::GetHostDesktopTypeForNativeView().
  3. If you have a gfx::NativeWindow: use chrome::GetHostDesktopTypeForNativeWindow().
  4. If you have a WebContents* w: you can use (2) passing in w->GetNativeView()  OR you might be able to get a Browser with chrome::FindBrowserWithWebContents() and use (1)
  5. If all else fails and you have absolutely NO way of getting desktop context (e.g., a background extension that wants to open a new window...): you can use chrome::GetActiveDesktop() to get the type of the last user-activated Chrome desktop, but be aware that this is inherently racy (i.e., the user can switch desktops at any time) -- If you are in a test, it is OK to use GetActiveDesktop() since almost all tests run on a single desktop making GetActiveDesktop() constant.
  6. You should almost never hardcode HOST_DESKTOP_TYPE_X constants.
  7. If you work on Chrome OS and your code is under ash/, please use HOST_DESKTOP_TYPE_ASH (this is the same as HOST_DESKTOP_TYPE_NATIVE on Chrome OS, but not on other platforms).
Most of the methods mentioned above are found in src/chrome/browser/ui/host_desktop.h.
 
Note: If you hardcode HOST_DESKTOP_TYPE_NATIVE it will look like it's working if you're in a single-desktop environment (which most of you are), but what it will really do is: one day someone will trigger your feature from the Ash desktop (e.g., in Windows 8 Metro) and it will open a window/tab on the native desktop (invisible to the user who is immersed in the Ash environment)...

posted on   huangguanyuan  阅读(162)  评论(0编辑  收藏  举报

编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示