Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* vim: se cin sw=2 ts=2 et : */ |
michael@0 | 2 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 3 | * |
michael@0 | 4 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 7 | |
michael@0 | 8 | #include "WinTaskbar.h" |
michael@0 | 9 | #include "TaskbarPreview.h" |
michael@0 | 10 | #include <nsITaskbarPreviewController.h> |
michael@0 | 11 | |
michael@0 | 12 | #include <nsError.h> |
michael@0 | 13 | #include <nsCOMPtr.h> |
michael@0 | 14 | #include <nsIWidget.h> |
michael@0 | 15 | #include <nsIBaseWindow.h> |
michael@0 | 16 | #include <nsIObserverService.h> |
michael@0 | 17 | #include <nsServiceManagerUtils.h> |
michael@0 | 18 | #include <nsAutoPtr.h> |
michael@0 | 19 | #include "nsIXULAppInfo.h" |
michael@0 | 20 | #include "nsIJumpListBuilder.h" |
michael@0 | 21 | #include "nsUXThemeData.h" |
michael@0 | 22 | #include "nsWindow.h" |
michael@0 | 23 | #include "WinUtils.h" |
michael@0 | 24 | #include "TaskbarTabPreview.h" |
michael@0 | 25 | #include "TaskbarWindowPreview.h" |
michael@0 | 26 | #include "JumpListBuilder.h" |
michael@0 | 27 | #include "nsWidgetsCID.h" |
michael@0 | 28 | #include "nsPIDOMWindow.h" |
michael@0 | 29 | #include "nsAppDirectoryServiceDefs.h" |
michael@0 | 30 | #include "mozilla/Preferences.h" |
michael@0 | 31 | #include "mozilla/WindowsVersion.h" |
michael@0 | 32 | #include <io.h> |
michael@0 | 33 | #include <propvarutil.h> |
michael@0 | 34 | #include <propkey.h> |
michael@0 | 35 | #include <shellapi.h> |
michael@0 | 36 | |
michael@0 | 37 | const wchar_t kShellLibraryName[] = L"shell32.dll"; |
michael@0 | 38 | |
michael@0 | 39 | static NS_DEFINE_CID(kJumpListBuilderCID, NS_WIN_JUMPLISTBUILDER_CID); |
michael@0 | 40 | |
michael@0 | 41 | namespace { |
michael@0 | 42 | |
michael@0 | 43 | HWND |
michael@0 | 44 | GetHWNDFromDocShell(nsIDocShell *aShell) { |
michael@0 | 45 | nsCOMPtr<nsIBaseWindow> baseWindow(do_QueryInterface(reinterpret_cast<nsISupports*>(aShell))); |
michael@0 | 46 | |
michael@0 | 47 | if (!baseWindow) |
michael@0 | 48 | return nullptr; |
michael@0 | 49 | |
michael@0 | 50 | nsCOMPtr<nsIWidget> widget; |
michael@0 | 51 | baseWindow->GetMainWidget(getter_AddRefs(widget)); |
michael@0 | 52 | |
michael@0 | 53 | return widget ? (HWND)widget->GetNativeData(NS_NATIVE_WINDOW) : nullptr; |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | HWND |
michael@0 | 57 | GetHWNDFromDOMWindow(nsIDOMWindow *dw) { |
michael@0 | 58 | nsCOMPtr<nsIWidget> widget; |
michael@0 | 59 | |
michael@0 | 60 | nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(dw); |
michael@0 | 61 | if (!window) |
michael@0 | 62 | return nullptr; |
michael@0 | 63 | |
michael@0 | 64 | return GetHWNDFromDocShell(window->GetDocShell()); |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | nsresult |
michael@0 | 68 | SetWindowAppUserModelProp(nsIDOMWindow *aParent, |
michael@0 | 69 | const nsString & aIdentifier) { |
michael@0 | 70 | NS_ENSURE_ARG_POINTER(aParent); |
michael@0 | 71 | |
michael@0 | 72 | if (aIdentifier.IsEmpty()) |
michael@0 | 73 | return NS_ERROR_INVALID_ARG; |
michael@0 | 74 | |
michael@0 | 75 | HWND toplevelHWND = ::GetAncestor(GetHWNDFromDOMWindow(aParent), GA_ROOT); |
michael@0 | 76 | |
michael@0 | 77 | if (!toplevelHWND) |
michael@0 | 78 | return NS_ERROR_INVALID_ARG; |
michael@0 | 79 | |
michael@0 | 80 | typedef HRESULT (WINAPI * SHGetPropertyStoreForWindowPtr) |
michael@0 | 81 | (HWND hwnd, REFIID riid, void** ppv); |
michael@0 | 82 | SHGetPropertyStoreForWindowPtr funcGetProStore = nullptr; |
michael@0 | 83 | |
michael@0 | 84 | HMODULE hDLL = ::LoadLibraryW(kShellLibraryName); |
michael@0 | 85 | funcGetProStore = (SHGetPropertyStoreForWindowPtr) |
michael@0 | 86 | GetProcAddress(hDLL, "SHGetPropertyStoreForWindow"); |
michael@0 | 87 | |
michael@0 | 88 | if (!funcGetProStore) { |
michael@0 | 89 | FreeLibrary(hDLL); |
michael@0 | 90 | return NS_ERROR_NO_INTERFACE; |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | IPropertyStore* pPropStore; |
michael@0 | 94 | if (FAILED(funcGetProStore(toplevelHWND, |
michael@0 | 95 | IID_PPV_ARGS(&pPropStore)))) { |
michael@0 | 96 | FreeLibrary(hDLL); |
michael@0 | 97 | return NS_ERROR_INVALID_ARG; |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | PROPVARIANT pv; |
michael@0 | 101 | if (FAILED(InitPropVariantFromString(aIdentifier.get(), &pv))) { |
michael@0 | 102 | pPropStore->Release(); |
michael@0 | 103 | FreeLibrary(hDLL); |
michael@0 | 104 | return NS_ERROR_UNEXPECTED; |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | nsresult rv = NS_OK; |
michael@0 | 108 | if (FAILED(pPropStore->SetValue(PKEY_AppUserModel_ID, pv)) || |
michael@0 | 109 | FAILED(pPropStore->Commit())) { |
michael@0 | 110 | rv = NS_ERROR_FAILURE; |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | PropVariantClear(&pv); |
michael@0 | 114 | pPropStore->Release(); |
michael@0 | 115 | FreeLibrary(hDLL); |
michael@0 | 116 | |
michael@0 | 117 | return rv; |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 121 | // default nsITaskbarPreviewController |
michael@0 | 122 | |
michael@0 | 123 | class DefaultController MOZ_FINAL : public nsITaskbarPreviewController |
michael@0 | 124 | { |
michael@0 | 125 | HWND mWnd; |
michael@0 | 126 | public: |
michael@0 | 127 | DefaultController(HWND hWnd) |
michael@0 | 128 | : mWnd(hWnd) |
michael@0 | 129 | { |
michael@0 | 130 | } |
michael@0 | 131 | |
michael@0 | 132 | NS_DECL_ISUPPORTS |
michael@0 | 133 | NS_DECL_NSITASKBARPREVIEWCONTROLLER |
michael@0 | 134 | }; |
michael@0 | 135 | |
michael@0 | 136 | NS_IMETHODIMP |
michael@0 | 137 | DefaultController::GetWidth(uint32_t *aWidth) |
michael@0 | 138 | { |
michael@0 | 139 | RECT r; |
michael@0 | 140 | ::GetClientRect(mWnd, &r); |
michael@0 | 141 | *aWidth = r.right; |
michael@0 | 142 | return NS_OK; |
michael@0 | 143 | } |
michael@0 | 144 | |
michael@0 | 145 | NS_IMETHODIMP |
michael@0 | 146 | DefaultController::GetHeight(uint32_t *aHeight) |
michael@0 | 147 | { |
michael@0 | 148 | RECT r; |
michael@0 | 149 | ::GetClientRect(mWnd, &r); |
michael@0 | 150 | *aHeight = r.bottom; |
michael@0 | 151 | return NS_OK; |
michael@0 | 152 | } |
michael@0 | 153 | |
michael@0 | 154 | NS_IMETHODIMP |
michael@0 | 155 | DefaultController::GetThumbnailAspectRatio(float *aThumbnailAspectRatio) { |
michael@0 | 156 | uint32_t width, height; |
michael@0 | 157 | GetWidth(&width); |
michael@0 | 158 | GetHeight(&height); |
michael@0 | 159 | if (!height) |
michael@0 | 160 | height = 1; |
michael@0 | 161 | |
michael@0 | 162 | *aThumbnailAspectRatio = width/float(height); |
michael@0 | 163 | return NS_OK; |
michael@0 | 164 | } |
michael@0 | 165 | |
michael@0 | 166 | NS_IMETHODIMP |
michael@0 | 167 | DefaultController::DrawPreview(nsISupports *ctx, bool *rDrawFrame) { |
michael@0 | 168 | *rDrawFrame = true; |
michael@0 | 169 | return NS_OK; |
michael@0 | 170 | } |
michael@0 | 171 | |
michael@0 | 172 | NS_IMETHODIMP |
michael@0 | 173 | DefaultController::DrawThumbnail(nsISupports *ctx, uint32_t width, uint32_t height, bool *rDrawFrame) { |
michael@0 | 174 | *rDrawFrame = false; |
michael@0 | 175 | return NS_OK; |
michael@0 | 176 | } |
michael@0 | 177 | |
michael@0 | 178 | NS_IMETHODIMP |
michael@0 | 179 | DefaultController::OnClose(void) { |
michael@0 | 180 | NS_NOTREACHED("OnClose should not be called for TaskbarWindowPreviews"); |
michael@0 | 181 | return NS_OK; |
michael@0 | 182 | } |
michael@0 | 183 | |
michael@0 | 184 | NS_IMETHODIMP |
michael@0 | 185 | DefaultController::OnActivate(bool *rAcceptActivation) { |
michael@0 | 186 | *rAcceptActivation = true; |
michael@0 | 187 | NS_NOTREACHED("OnActivate should not be called for TaskbarWindowPreviews"); |
michael@0 | 188 | return NS_OK; |
michael@0 | 189 | } |
michael@0 | 190 | |
michael@0 | 191 | NS_IMETHODIMP |
michael@0 | 192 | DefaultController::OnClick(nsITaskbarPreviewButton *button) { |
michael@0 | 193 | return NS_OK; |
michael@0 | 194 | } |
michael@0 | 195 | |
michael@0 | 196 | NS_IMPL_ISUPPORTS(DefaultController, nsITaskbarPreviewController) |
michael@0 | 197 | } |
michael@0 | 198 | |
michael@0 | 199 | namespace mozilla { |
michael@0 | 200 | namespace widget { |
michael@0 | 201 | |
michael@0 | 202 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 203 | // nsIWinTaskbar |
michael@0 | 204 | |
michael@0 | 205 | NS_IMPL_ISUPPORTS(WinTaskbar, nsIWinTaskbar) |
michael@0 | 206 | |
michael@0 | 207 | bool |
michael@0 | 208 | WinTaskbar::Initialize() { |
michael@0 | 209 | if (mTaskbar) |
michael@0 | 210 | return true; |
michael@0 | 211 | |
michael@0 | 212 | ::CoInitialize(nullptr); |
michael@0 | 213 | HRESULT hr = ::CoCreateInstance(CLSID_TaskbarList, |
michael@0 | 214 | nullptr, |
michael@0 | 215 | CLSCTX_INPROC_SERVER, |
michael@0 | 216 | IID_ITaskbarList4, |
michael@0 | 217 | (void**)&mTaskbar); |
michael@0 | 218 | if (FAILED(hr)) |
michael@0 | 219 | return false; |
michael@0 | 220 | |
michael@0 | 221 | hr = mTaskbar->HrInit(); |
michael@0 | 222 | if (FAILED(hr)) { |
michael@0 | 223 | // This may fail with shell extensions like blackbox installed. |
michael@0 | 224 | NS_WARNING("Unable to initialize taskbar"); |
michael@0 | 225 | NS_RELEASE(mTaskbar); |
michael@0 | 226 | return false; |
michael@0 | 227 | } |
michael@0 | 228 | return true; |
michael@0 | 229 | } |
michael@0 | 230 | |
michael@0 | 231 | WinTaskbar::WinTaskbar() |
michael@0 | 232 | : mTaskbar(nullptr) { |
michael@0 | 233 | } |
michael@0 | 234 | |
michael@0 | 235 | WinTaskbar::~WinTaskbar() { |
michael@0 | 236 | if (mTaskbar) { // match successful Initialize() call |
michael@0 | 237 | NS_RELEASE(mTaskbar); |
michael@0 | 238 | ::CoUninitialize(); |
michael@0 | 239 | } |
michael@0 | 240 | } |
michael@0 | 241 | |
michael@0 | 242 | // static |
michael@0 | 243 | bool |
michael@0 | 244 | WinTaskbar::GetAppUserModelID(nsAString & aDefaultGroupId) { |
michael@0 | 245 | // For win8 metro builds, we can't set this. The value is static |
michael@0 | 246 | // for the app. |
michael@0 | 247 | if (XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Metro) { |
michael@0 | 248 | return false; |
michael@0 | 249 | } |
michael@0 | 250 | // If marked as such in prefs, use a hash of the profile path for the id |
michael@0 | 251 | // instead of the install path hash setup by the installer. |
michael@0 | 252 | bool useProfile = |
michael@0 | 253 | Preferences::GetBool("taskbar.grouping.useprofile", false); |
michael@0 | 254 | if (useProfile) { |
michael@0 | 255 | nsCOMPtr<nsIFile> profileDir; |
michael@0 | 256 | NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, |
michael@0 | 257 | getter_AddRefs(profileDir)); |
michael@0 | 258 | bool exists = false; |
michael@0 | 259 | if (profileDir && NS_SUCCEEDED(profileDir->Exists(&exists)) && exists) { |
michael@0 | 260 | nsAutoCString path; |
michael@0 | 261 | if (NS_SUCCEEDED(profileDir->GetNativePath(path))) { |
michael@0 | 262 | nsAutoString id; |
michael@0 | 263 | id.AppendInt(HashString(path)); |
michael@0 | 264 | if (!id.IsEmpty()) { |
michael@0 | 265 | aDefaultGroupId.Assign(id); |
michael@0 | 266 | return true; |
michael@0 | 267 | } |
michael@0 | 268 | } |
michael@0 | 269 | } |
michael@0 | 270 | } |
michael@0 | 271 | |
michael@0 | 272 | // The default value is set by the installer and is stored in the registry |
michael@0 | 273 | // under (HKLM||HKCU)/Software/Mozilla/Firefox/TaskBarIDs. If for any reason |
michael@0 | 274 | // hash generation operation fails, the installer will not store a value in |
michael@0 | 275 | // the registry or set ids on shortcuts. A lack of an id can also occur for |
michael@0 | 276 | // zipped builds. We skip setting the global id in this case as well. |
michael@0 | 277 | nsCOMPtr<nsIXULAppInfo> appInfo = |
michael@0 | 278 | do_GetService("@mozilla.org/xre/app-info;1"); |
michael@0 | 279 | if (!appInfo) |
michael@0 | 280 | return false; |
michael@0 | 281 | |
michael@0 | 282 | nsCString appName; |
michael@0 | 283 | if (NS_FAILED(appInfo->GetName(appName))) { |
michael@0 | 284 | // We just won't register then, let Windows handle it. |
michael@0 | 285 | return false; |
michael@0 | 286 | } |
michael@0 | 287 | |
michael@0 | 288 | nsAutoString regKey; |
michael@0 | 289 | regKey.AssignLiteral("Software\\Mozilla\\"); |
michael@0 | 290 | AppendASCIItoUTF16(appName, regKey); |
michael@0 | 291 | regKey.AppendLiteral("\\TaskBarIDs"); |
michael@0 | 292 | |
michael@0 | 293 | WCHAR path[MAX_PATH]; |
michael@0 | 294 | if (GetModuleFileNameW(nullptr, path, MAX_PATH)) { |
michael@0 | 295 | wchar_t* slash = wcsrchr(path, '\\'); |
michael@0 | 296 | if (!slash) |
michael@0 | 297 | return false; |
michael@0 | 298 | *slash = '\0'; // no trailing slash |
michael@0 | 299 | |
michael@0 | 300 | // The hash is short, but users may customize this, so use a respectable |
michael@0 | 301 | // string buffer. |
michael@0 | 302 | wchar_t buf[256]; |
michael@0 | 303 | if (WinUtils::GetRegistryKey(HKEY_LOCAL_MACHINE, |
michael@0 | 304 | regKey.get(), |
michael@0 | 305 | path, |
michael@0 | 306 | buf, |
michael@0 | 307 | sizeof buf)) { |
michael@0 | 308 | aDefaultGroupId.Assign(buf); |
michael@0 | 309 | } else if (WinUtils::GetRegistryKey(HKEY_CURRENT_USER, |
michael@0 | 310 | regKey.get(), |
michael@0 | 311 | path, |
michael@0 | 312 | buf, |
michael@0 | 313 | sizeof buf)) { |
michael@0 | 314 | aDefaultGroupId.Assign(buf); |
michael@0 | 315 | } |
michael@0 | 316 | } |
michael@0 | 317 | |
michael@0 | 318 | return !aDefaultGroupId.IsEmpty(); |
michael@0 | 319 | |
michael@0 | 320 | return true; |
michael@0 | 321 | } |
michael@0 | 322 | |
michael@0 | 323 | /* readonly attribute AString defaultGroupId; */ |
michael@0 | 324 | NS_IMETHODIMP |
michael@0 | 325 | WinTaskbar::GetDefaultGroupId(nsAString & aDefaultGroupId) { |
michael@0 | 326 | if (!GetAppUserModelID(aDefaultGroupId)) |
michael@0 | 327 | return NS_ERROR_UNEXPECTED; |
michael@0 | 328 | |
michael@0 | 329 | return NS_OK; |
michael@0 | 330 | } |
michael@0 | 331 | |
michael@0 | 332 | // (static) Called from AppShell |
michael@0 | 333 | bool |
michael@0 | 334 | WinTaskbar::RegisterAppUserModelID() { |
michael@0 | 335 | if (!IsWin7OrLater()) |
michael@0 | 336 | return false; |
michael@0 | 337 | |
michael@0 | 338 | if (XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Metro) { |
michael@0 | 339 | return false; |
michael@0 | 340 | } |
michael@0 | 341 | |
michael@0 | 342 | SetCurrentProcessExplicitAppUserModelIDPtr funcAppUserModelID = nullptr; |
michael@0 | 343 | bool retVal = false; |
michael@0 | 344 | |
michael@0 | 345 | nsAutoString uid; |
michael@0 | 346 | if (!GetAppUserModelID(uid)) |
michael@0 | 347 | return false; |
michael@0 | 348 | |
michael@0 | 349 | HMODULE hDLL = ::LoadLibraryW(kShellLibraryName); |
michael@0 | 350 | |
michael@0 | 351 | funcAppUserModelID = (SetCurrentProcessExplicitAppUserModelIDPtr) |
michael@0 | 352 | GetProcAddress(hDLL, "SetCurrentProcessExplicitAppUserModelID"); |
michael@0 | 353 | |
michael@0 | 354 | if (!funcAppUserModelID) { |
michael@0 | 355 | ::FreeLibrary(hDLL); |
michael@0 | 356 | return false; |
michael@0 | 357 | } |
michael@0 | 358 | |
michael@0 | 359 | if (SUCCEEDED(funcAppUserModelID(uid.get()))) |
michael@0 | 360 | retVal = true; |
michael@0 | 361 | |
michael@0 | 362 | if (hDLL) |
michael@0 | 363 | ::FreeLibrary(hDLL); |
michael@0 | 364 | |
michael@0 | 365 | return retVal; |
michael@0 | 366 | } |
michael@0 | 367 | |
michael@0 | 368 | NS_IMETHODIMP |
michael@0 | 369 | WinTaskbar::GetAvailable(bool *aAvailable) { |
michael@0 | 370 | // ITaskbarList4::HrInit() may fail with shell extensions like blackbox |
michael@0 | 371 | // installed. Initialize early to return available=false in those cases. |
michael@0 | 372 | *aAvailable = IsWin7OrLater() && Initialize(); |
michael@0 | 373 | |
michael@0 | 374 | return NS_OK; |
michael@0 | 375 | } |
michael@0 | 376 | |
michael@0 | 377 | NS_IMETHODIMP |
michael@0 | 378 | WinTaskbar::CreateTaskbarTabPreview(nsIDocShell *shell, nsITaskbarPreviewController *controller, nsITaskbarTabPreview **_retval) { |
michael@0 | 379 | if (!Initialize()) |
michael@0 | 380 | return NS_ERROR_NOT_AVAILABLE; |
michael@0 | 381 | |
michael@0 | 382 | NS_ENSURE_ARG_POINTER(shell); |
michael@0 | 383 | NS_ENSURE_ARG_POINTER(controller); |
michael@0 | 384 | |
michael@0 | 385 | HWND toplevelHWND = ::GetAncestor(GetHWNDFromDocShell(shell), GA_ROOT); |
michael@0 | 386 | |
michael@0 | 387 | if (!toplevelHWND) |
michael@0 | 388 | return NS_ERROR_INVALID_ARG; |
michael@0 | 389 | |
michael@0 | 390 | nsRefPtr<TaskbarTabPreview> preview(new TaskbarTabPreview(mTaskbar, controller, toplevelHWND, shell)); |
michael@0 | 391 | if (!preview) |
michael@0 | 392 | return NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 393 | |
michael@0 | 394 | preview.forget(_retval); |
michael@0 | 395 | |
michael@0 | 396 | return NS_OK; |
michael@0 | 397 | } |
michael@0 | 398 | |
michael@0 | 399 | NS_IMETHODIMP |
michael@0 | 400 | WinTaskbar::GetTaskbarWindowPreview(nsIDocShell *shell, nsITaskbarWindowPreview **_retval) { |
michael@0 | 401 | if (!Initialize()) |
michael@0 | 402 | return NS_ERROR_NOT_AVAILABLE; |
michael@0 | 403 | |
michael@0 | 404 | NS_ENSURE_ARG_POINTER(shell); |
michael@0 | 405 | |
michael@0 | 406 | HWND toplevelHWND = ::GetAncestor(GetHWNDFromDocShell(shell), GA_ROOT); |
michael@0 | 407 | |
michael@0 | 408 | if (!toplevelHWND) |
michael@0 | 409 | return NS_ERROR_INVALID_ARG; |
michael@0 | 410 | |
michael@0 | 411 | nsWindow *window = WinUtils::GetNSWindowPtr(toplevelHWND); |
michael@0 | 412 | |
michael@0 | 413 | if (!window) |
michael@0 | 414 | return NS_ERROR_FAILURE; |
michael@0 | 415 | |
michael@0 | 416 | nsCOMPtr<nsITaskbarWindowPreview> preview = window->GetTaskbarPreview(); |
michael@0 | 417 | if (!preview) { |
michael@0 | 418 | nsRefPtr<DefaultController> defaultController = new DefaultController(toplevelHWND); |
michael@0 | 419 | preview = new TaskbarWindowPreview(mTaskbar, defaultController, toplevelHWND, shell); |
michael@0 | 420 | if (!preview) |
michael@0 | 421 | return NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 422 | window->SetTaskbarPreview(preview); |
michael@0 | 423 | } |
michael@0 | 424 | |
michael@0 | 425 | preview.forget(_retval); |
michael@0 | 426 | |
michael@0 | 427 | return NS_OK; |
michael@0 | 428 | } |
michael@0 | 429 | |
michael@0 | 430 | NS_IMETHODIMP |
michael@0 | 431 | WinTaskbar::GetTaskbarProgress(nsIDocShell *shell, nsITaskbarProgress **_retval) { |
michael@0 | 432 | nsCOMPtr<nsITaskbarWindowPreview> preview; |
michael@0 | 433 | nsresult rv = GetTaskbarWindowPreview(shell, getter_AddRefs(preview)); |
michael@0 | 434 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 435 | |
michael@0 | 436 | return CallQueryInterface(preview, _retval); |
michael@0 | 437 | } |
michael@0 | 438 | |
michael@0 | 439 | NS_IMETHODIMP |
michael@0 | 440 | WinTaskbar::GetOverlayIconController(nsIDocShell *shell, |
michael@0 | 441 | nsITaskbarOverlayIconController **_retval) { |
michael@0 | 442 | nsCOMPtr<nsITaskbarWindowPreview> preview; |
michael@0 | 443 | nsresult rv = GetTaskbarWindowPreview(shell, getter_AddRefs(preview)); |
michael@0 | 444 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 445 | |
michael@0 | 446 | return CallQueryInterface(preview, _retval); |
michael@0 | 447 | } |
michael@0 | 448 | |
michael@0 | 449 | /* nsIJumpListBuilder createJumpListBuilder(); */ |
michael@0 | 450 | NS_IMETHODIMP |
michael@0 | 451 | WinTaskbar::CreateJumpListBuilder(nsIJumpListBuilder * *aJumpListBuilder) { |
michael@0 | 452 | nsresult rv; |
michael@0 | 453 | |
michael@0 | 454 | if (JumpListBuilder::sBuildingList) |
michael@0 | 455 | return NS_ERROR_ALREADY_INITIALIZED; |
michael@0 | 456 | |
michael@0 | 457 | nsCOMPtr<nsIJumpListBuilder> builder = |
michael@0 | 458 | do_CreateInstance(kJumpListBuilderCID, &rv); |
michael@0 | 459 | if (NS_FAILED(rv)) |
michael@0 | 460 | return NS_ERROR_UNEXPECTED; |
michael@0 | 461 | |
michael@0 | 462 | NS_IF_ADDREF(*aJumpListBuilder = builder); |
michael@0 | 463 | |
michael@0 | 464 | return NS_OK; |
michael@0 | 465 | } |
michael@0 | 466 | |
michael@0 | 467 | /* void setGroupIdForWindow (in nsIDOMWindow aParent, in AString aIdentifier); */ |
michael@0 | 468 | NS_IMETHODIMP |
michael@0 | 469 | WinTaskbar::SetGroupIdForWindow(nsIDOMWindow *aParent, |
michael@0 | 470 | const nsAString & aIdentifier) { |
michael@0 | 471 | return SetWindowAppUserModelProp(aParent, nsString(aIdentifier)); |
michael@0 | 472 | } |
michael@0 | 473 | |
michael@0 | 474 | /* void prepareFullScreen(in nsIDOMWindow aWindow, in boolean aFullScreen); */ |
michael@0 | 475 | NS_IMETHODIMP |
michael@0 | 476 | WinTaskbar::PrepareFullScreen(nsIDOMWindow *aWindow, bool aFullScreen) { |
michael@0 | 477 | NS_ENSURE_ARG_POINTER(aWindow); |
michael@0 | 478 | |
michael@0 | 479 | HWND toplevelHWND = ::GetAncestor(GetHWNDFromDOMWindow(aWindow), GA_ROOT); |
michael@0 | 480 | if (!toplevelHWND) |
michael@0 | 481 | return NS_ERROR_INVALID_ARG; |
michael@0 | 482 | |
michael@0 | 483 | return PrepareFullScreenHWND(toplevelHWND, aFullScreen); |
michael@0 | 484 | } |
michael@0 | 485 | |
michael@0 | 486 | /* void prepareFullScreen(in voidPtr aWindow, in boolean aFullScreen); */ |
michael@0 | 487 | NS_IMETHODIMP |
michael@0 | 488 | WinTaskbar::PrepareFullScreenHWND(void *aHWND, bool aFullScreen) { |
michael@0 | 489 | if (!Initialize()) |
michael@0 | 490 | return NS_ERROR_NOT_AVAILABLE; |
michael@0 | 491 | |
michael@0 | 492 | NS_ENSURE_ARG_POINTER(aHWND); |
michael@0 | 493 | |
michael@0 | 494 | if (!::IsWindow((HWND)aHWND)) |
michael@0 | 495 | return NS_ERROR_INVALID_ARG; |
michael@0 | 496 | |
michael@0 | 497 | HRESULT hr = mTaskbar->MarkFullscreenWindow((HWND)aHWND, aFullScreen); |
michael@0 | 498 | if (FAILED(hr)) { |
michael@0 | 499 | return NS_ERROR_UNEXPECTED; |
michael@0 | 500 | } |
michael@0 | 501 | |
michael@0 | 502 | return NS_OK; |
michael@0 | 503 | } |
michael@0 | 504 | |
michael@0 | 505 | } // namespace widget |
michael@0 | 506 | } // namespace mozilla |
michael@0 | 507 |