chrome/src/nsChromeRegistry.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim: set ts=2 sw=2 et tw=78: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #include "nsChromeRegistry.h"
michael@0 8 #include "nsChromeRegistryChrome.h"
michael@0 9 #include "nsChromeRegistryContent.h"
michael@0 10
michael@0 11 #include "prprf.h"
michael@0 12
michael@0 13 #include "nsCOMPtr.h"
michael@0 14 #include "nsError.h"
michael@0 15 #include "nsEscape.h"
michael@0 16 #include "nsNetUtil.h"
michael@0 17 #include "nsString.h"
michael@0 18
michael@0 19 #include "nsCSSStyleSheet.h"
michael@0 20 #include "nsIConsoleService.h"
michael@0 21 #include "nsIDocument.h"
michael@0 22 #include "nsIDOMDocument.h"
michael@0 23 #include "nsIDOMLocation.h"
michael@0 24 #include "nsIDOMWindowCollection.h"
michael@0 25 #include "nsIDOMWindow.h"
michael@0 26 #include "nsIObserverService.h"
michael@0 27 #include "nsIPresShell.h"
michael@0 28 #include "nsIScriptError.h"
michael@0 29 #include "nsIWindowMediator.h"
michael@0 30 #include "mozilla/dom/URL.h"
michael@0 31
michael@0 32 nsChromeRegistry* nsChromeRegistry::gChromeRegistry;
michael@0 33 using mozilla::dom::IsChromeURI;
michael@0 34
michael@0 35 ////////////////////////////////////////////////////////////////////////////////
michael@0 36
michael@0 37 void
michael@0 38 nsChromeRegistry::LogMessage(const char* aMsg, ...)
michael@0 39 {
michael@0 40 nsCOMPtr<nsIConsoleService> console
michael@0 41 (do_GetService(NS_CONSOLESERVICE_CONTRACTID));
michael@0 42 if (!console)
michael@0 43 return;
michael@0 44
michael@0 45 va_list args;
michael@0 46 va_start(args, aMsg);
michael@0 47 char* formatted = PR_vsmprintf(aMsg, args);
michael@0 48 va_end(args);
michael@0 49 if (!formatted)
michael@0 50 return;
michael@0 51
michael@0 52 console->LogStringMessage(NS_ConvertUTF8toUTF16(formatted).get());
michael@0 53 PR_smprintf_free(formatted);
michael@0 54 }
michael@0 55
michael@0 56 void
michael@0 57 nsChromeRegistry::LogMessageWithContext(nsIURI* aURL, uint32_t aLineNumber, uint32_t flags,
michael@0 58 const char* aMsg, ...)
michael@0 59 {
michael@0 60 nsresult rv;
michael@0 61
michael@0 62 nsCOMPtr<nsIConsoleService> console
michael@0 63 (do_GetService(NS_CONSOLESERVICE_CONTRACTID));
michael@0 64
michael@0 65 nsCOMPtr<nsIScriptError> error
michael@0 66 (do_CreateInstance(NS_SCRIPTERROR_CONTRACTID));
michael@0 67 if (!console || !error)
michael@0 68 return;
michael@0 69
michael@0 70 va_list args;
michael@0 71 va_start(args, aMsg);
michael@0 72 char* formatted = PR_vsmprintf(aMsg, args);
michael@0 73 va_end(args);
michael@0 74 if (!formatted)
michael@0 75 return;
michael@0 76
michael@0 77 nsCString spec;
michael@0 78 if (aURL)
michael@0 79 aURL->GetSpec(spec);
michael@0 80
michael@0 81 rv = error->Init(NS_ConvertUTF8toUTF16(formatted),
michael@0 82 NS_ConvertUTF8toUTF16(spec),
michael@0 83 EmptyString(),
michael@0 84 aLineNumber, 0, flags, "chrome registration");
michael@0 85 PR_smprintf_free(formatted);
michael@0 86
michael@0 87 if (NS_FAILED(rv))
michael@0 88 return;
michael@0 89
michael@0 90 console->LogMessage(error);
michael@0 91 }
michael@0 92
michael@0 93 nsChromeRegistry::~nsChromeRegistry()
michael@0 94 {
michael@0 95 gChromeRegistry = nullptr;
michael@0 96 }
michael@0 97
michael@0 98 NS_INTERFACE_MAP_BEGIN(nsChromeRegistry)
michael@0 99 NS_INTERFACE_MAP_ENTRY(nsIChromeRegistry)
michael@0 100 NS_INTERFACE_MAP_ENTRY(nsIXULChromeRegistry)
michael@0 101 NS_INTERFACE_MAP_ENTRY(nsIToolkitChromeRegistry)
michael@0 102 #ifdef MOZ_XUL
michael@0 103 NS_INTERFACE_MAP_ENTRY(nsIXULOverlayProvider)
michael@0 104 #endif
michael@0 105 NS_INTERFACE_MAP_ENTRY(nsIObserver)
michael@0 106 NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
michael@0 107 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIChromeRegistry)
michael@0 108 NS_INTERFACE_MAP_END
michael@0 109
michael@0 110 NS_IMPL_ADDREF(nsChromeRegistry)
michael@0 111 NS_IMPL_RELEASE(nsChromeRegistry)
michael@0 112
michael@0 113 ////////////////////////////////////////////////////////////////////////////////
michael@0 114 // nsIChromeRegistry methods:
michael@0 115
michael@0 116 already_AddRefed<nsIChromeRegistry>
michael@0 117 nsChromeRegistry::GetService()
michael@0 118 {
michael@0 119 if (!gChromeRegistry)
michael@0 120 {
michael@0 121 // We don't actually want this ref, we just want the service to
michael@0 122 // initialize if it hasn't already.
michael@0 123 nsCOMPtr<nsIChromeRegistry> reg(
michael@0 124 do_GetService(NS_CHROMEREGISTRY_CONTRACTID));
michael@0 125 if (!gChromeRegistry)
michael@0 126 return nullptr;
michael@0 127 }
michael@0 128 nsCOMPtr<nsIChromeRegistry> registry = gChromeRegistry;
michael@0 129 return registry.forget();
michael@0 130 }
michael@0 131
michael@0 132 nsresult
michael@0 133 nsChromeRegistry::Init()
michael@0 134 {
michael@0 135 // This initialization process is fairly complicated and may cause reentrant
michael@0 136 // getservice calls to resolve chrome URIs (especially locale files). We
michael@0 137 // don't want that, so we inform the protocol handler about our existence
michael@0 138 // before we are actually fully initialized.
michael@0 139 gChromeRegistry = this;
michael@0 140
michael@0 141 mInitialized = true;
michael@0 142
michael@0 143 return NS_OK;
michael@0 144 }
michael@0 145
michael@0 146 nsresult
michael@0 147 nsChromeRegistry::GetProviderAndPath(nsIURL* aChromeURL,
michael@0 148 nsACString& aProvider, nsACString& aPath)
michael@0 149 {
michael@0 150 nsresult rv;
michael@0 151
michael@0 152 #ifdef DEBUG
michael@0 153 bool isChrome;
michael@0 154 aChromeURL->SchemeIs("chrome", &isChrome);
michael@0 155 NS_ASSERTION(isChrome, "Non-chrome URI?");
michael@0 156 #endif
michael@0 157
michael@0 158 nsAutoCString path;
michael@0 159 rv = aChromeURL->GetPath(path);
michael@0 160 NS_ENSURE_SUCCESS(rv, rv);
michael@0 161
michael@0 162 if (path.Length() < 3) {
michael@0 163 LogMessage("Invalid chrome URI: %s", path.get());
michael@0 164 return NS_ERROR_FAILURE;
michael@0 165 }
michael@0 166
michael@0 167 path.SetLength(nsUnescapeCount(path.BeginWriting()));
michael@0 168 NS_ASSERTION(path.First() == '/', "Path should always begin with a slash!");
michael@0 169
michael@0 170 int32_t slash = path.FindChar('/', 1);
michael@0 171 if (slash == 1) {
michael@0 172 LogMessage("Invalid chrome URI: %s", path.get());
michael@0 173 return NS_ERROR_FAILURE;
michael@0 174 }
michael@0 175
michael@0 176 if (slash == -1) {
michael@0 177 aPath.Truncate();
michael@0 178 }
michael@0 179 else {
michael@0 180 if (slash == (int32_t) path.Length() - 1)
michael@0 181 aPath.Truncate();
michael@0 182 else
michael@0 183 aPath.Assign(path.get() + slash + 1, path.Length() - slash - 1);
michael@0 184
michael@0 185 --slash;
michael@0 186 }
michael@0 187
michael@0 188 aProvider.Assign(path.get() + 1, slash);
michael@0 189 return NS_OK;
michael@0 190 }
michael@0 191
michael@0 192
michael@0 193 nsresult
michael@0 194 nsChromeRegistry::Canonify(nsIURL* aChromeURL)
michael@0 195 {
michael@0 196 NS_NAMED_LITERAL_CSTRING(kSlash, "/");
michael@0 197
michael@0 198 nsresult rv;
michael@0 199
michael@0 200 nsAutoCString provider, path;
michael@0 201 rv = GetProviderAndPath(aChromeURL, provider, path);
michael@0 202 NS_ENSURE_SUCCESS(rv, rv);
michael@0 203
michael@0 204 if (path.IsEmpty()) {
michael@0 205 nsAutoCString package;
michael@0 206 rv = aChromeURL->GetHost(package);
michael@0 207 NS_ENSURE_SUCCESS(rv, rv);
michael@0 208
michael@0 209 // we re-use the "path" local string to build a new URL path
michael@0 210 path.Assign(kSlash + provider + kSlash + package);
michael@0 211 if (provider.EqualsLiteral("content")) {
michael@0 212 path.AppendLiteral(".xul");
michael@0 213 }
michael@0 214 else if (provider.EqualsLiteral("locale")) {
michael@0 215 path.AppendLiteral(".dtd");
michael@0 216 }
michael@0 217 else if (provider.EqualsLiteral("skin")) {
michael@0 218 path.AppendLiteral(".css");
michael@0 219 }
michael@0 220 else {
michael@0 221 return NS_ERROR_INVALID_ARG;
michael@0 222 }
michael@0 223 aChromeURL->SetPath(path);
michael@0 224 }
michael@0 225 else {
michael@0 226 // prevent directory traversals ("..")
michael@0 227 // path is already unescaped once, but uris can get unescaped twice
michael@0 228 const char* pos = path.BeginReading();
michael@0 229 const char* end = path.EndReading();
michael@0 230 while (pos < end) {
michael@0 231 switch (*pos) {
michael@0 232 case ':':
michael@0 233 return NS_ERROR_DOM_BAD_URI;
michael@0 234 case '.':
michael@0 235 if (pos[1] == '.')
michael@0 236 return NS_ERROR_DOM_BAD_URI;
michael@0 237 break;
michael@0 238 case '%':
michael@0 239 // chrome: URIs with double-escapes are trying to trick us.
michael@0 240 // watch for %2e, and %25 in case someone triple unescapes
michael@0 241 if (pos[1] == '2' &&
michael@0 242 ( pos[2] == 'e' || pos[2] == 'E' ||
michael@0 243 pos[2] == '5' ))
michael@0 244 return NS_ERROR_DOM_BAD_URI;
michael@0 245 break;
michael@0 246 case '?':
michael@0 247 case '#':
michael@0 248 pos = end;
michael@0 249 continue;
michael@0 250 }
michael@0 251 ++pos;
michael@0 252 }
michael@0 253 }
michael@0 254
michael@0 255 return NS_OK;
michael@0 256 }
michael@0 257
michael@0 258 NS_IMETHODIMP
michael@0 259 nsChromeRegistry::ConvertChromeURL(nsIURI* aChromeURI, nsIURI* *aResult)
michael@0 260 {
michael@0 261 nsresult rv;
michael@0 262 NS_ASSERTION(aChromeURI, "null url!");
michael@0 263
michael@0 264 if (mOverrideTable.Get(aChromeURI, aResult))
michael@0 265 return NS_OK;
michael@0 266
michael@0 267 nsCOMPtr<nsIURL> chromeURL (do_QueryInterface(aChromeURI));
michael@0 268 NS_ENSURE_TRUE(chromeURL, NS_NOINTERFACE);
michael@0 269
michael@0 270 nsAutoCString package, provider, path;
michael@0 271 rv = chromeURL->GetHostPort(package);
michael@0 272 NS_ENSURE_SUCCESS(rv, rv);
michael@0 273
michael@0 274 rv = GetProviderAndPath(chromeURL, provider, path);
michael@0 275 NS_ENSURE_SUCCESS(rv, rv);
michael@0 276
michael@0 277 nsIURI* baseURI = GetBaseURIFromPackage(package, provider, path);
michael@0 278
michael@0 279 uint32_t flags;
michael@0 280 rv = GetFlagsFromPackage(package, &flags);
michael@0 281 if (NS_FAILED(rv))
michael@0 282 return rv;
michael@0 283
michael@0 284 if (flags & PLATFORM_PACKAGE) {
michael@0 285 #if defined(XP_WIN)
michael@0 286 path.Insert("win/", 0);
michael@0 287 #elif defined(XP_MACOSX)
michael@0 288 path.Insert("mac/", 0);
michael@0 289 #else
michael@0 290 path.Insert("unix/", 0);
michael@0 291 #endif
michael@0 292 }
michael@0 293
michael@0 294 if (!baseURI) {
michael@0 295 LogMessage("No chrome package registered for chrome://%s/%s/%s",
michael@0 296 package.get(), provider.get(), path.get());
michael@0 297 return NS_ERROR_FAILURE;
michael@0 298 }
michael@0 299
michael@0 300 return NS_NewURI(aResult, path, nullptr, baseURI);
michael@0 301 }
michael@0 302
michael@0 303 ////////////////////////////////////////////////////////////////////////
michael@0 304
michael@0 305 // theme stuff
michael@0 306
michael@0 307
michael@0 308 static void FlushSkinBindingsForWindow(nsIDOMWindow* aWindow)
michael@0 309 {
michael@0 310 // Get the DOM document.
michael@0 311 nsCOMPtr<nsIDOMDocument> domDocument;
michael@0 312 aWindow->GetDocument(getter_AddRefs(domDocument));
michael@0 313 if (!domDocument)
michael@0 314 return;
michael@0 315
michael@0 316 nsCOMPtr<nsIDocument> document = do_QueryInterface(domDocument);
michael@0 317 if (!document)
michael@0 318 return;
michael@0 319
michael@0 320 // Annihilate all XBL bindings.
michael@0 321 document->FlushSkinBindings();
michael@0 322 }
michael@0 323
michael@0 324 // XXXbsmedberg: move this to nsIWindowMediator
michael@0 325 NS_IMETHODIMP nsChromeRegistry::RefreshSkins()
michael@0 326 {
michael@0 327 nsCOMPtr<nsIWindowMediator> windowMediator
michael@0 328 (do_GetService(NS_WINDOWMEDIATOR_CONTRACTID));
michael@0 329 if (!windowMediator)
michael@0 330 return NS_OK;
michael@0 331
michael@0 332 nsCOMPtr<nsISimpleEnumerator> windowEnumerator;
michael@0 333 windowMediator->GetEnumerator(nullptr, getter_AddRefs(windowEnumerator));
michael@0 334 bool more;
michael@0 335 windowEnumerator->HasMoreElements(&more);
michael@0 336 while (more) {
michael@0 337 nsCOMPtr<nsISupports> protoWindow;
michael@0 338 windowEnumerator->GetNext(getter_AddRefs(protoWindow));
michael@0 339 if (protoWindow) {
michael@0 340 nsCOMPtr<nsIDOMWindow> domWindow = do_QueryInterface(protoWindow);
michael@0 341 if (domWindow)
michael@0 342 FlushSkinBindingsForWindow(domWindow);
michael@0 343 }
michael@0 344 windowEnumerator->HasMoreElements(&more);
michael@0 345 }
michael@0 346
michael@0 347 FlushSkinCaches();
michael@0 348
michael@0 349 windowMediator->GetEnumerator(nullptr, getter_AddRefs(windowEnumerator));
michael@0 350 windowEnumerator->HasMoreElements(&more);
michael@0 351 while (more) {
michael@0 352 nsCOMPtr<nsISupports> protoWindow;
michael@0 353 windowEnumerator->GetNext(getter_AddRefs(protoWindow));
michael@0 354 if (protoWindow) {
michael@0 355 nsCOMPtr<nsIDOMWindow> domWindow = do_QueryInterface(protoWindow);
michael@0 356 if (domWindow)
michael@0 357 RefreshWindow(domWindow);
michael@0 358 }
michael@0 359 windowEnumerator->HasMoreElements(&more);
michael@0 360 }
michael@0 361
michael@0 362 return NS_OK;
michael@0 363 }
michael@0 364
michael@0 365 void
michael@0 366 nsChromeRegistry::FlushSkinCaches()
michael@0 367 {
michael@0 368 nsCOMPtr<nsIObserverService> obsSvc =
michael@0 369 mozilla::services::GetObserverService();
michael@0 370 NS_ASSERTION(obsSvc, "Couldn't get observer service.");
michael@0 371
michael@0 372 obsSvc->NotifyObservers(static_cast<nsIChromeRegistry*>(this),
michael@0 373 NS_CHROME_FLUSH_SKINS_TOPIC, nullptr);
michael@0 374 }
michael@0 375
michael@0 376 // XXXbsmedberg: move this to windowmediator
michael@0 377 nsresult nsChromeRegistry::RefreshWindow(nsIDOMWindow* aWindow)
michael@0 378 {
michael@0 379 // Deal with our subframes first.
michael@0 380 nsCOMPtr<nsIDOMWindowCollection> frames;
michael@0 381 aWindow->GetFrames(getter_AddRefs(frames));
michael@0 382 uint32_t length;
michael@0 383 frames->GetLength(&length);
michael@0 384 uint32_t j;
michael@0 385 for (j = 0; j < length; j++) {
michael@0 386 nsCOMPtr<nsIDOMWindow> childWin;
michael@0 387 frames->Item(j, getter_AddRefs(childWin));
michael@0 388 RefreshWindow(childWin);
michael@0 389 }
michael@0 390
michael@0 391 nsresult rv;
michael@0 392 // Get the DOM document.
michael@0 393 nsCOMPtr<nsIDOMDocument> domDocument;
michael@0 394 aWindow->GetDocument(getter_AddRefs(domDocument));
michael@0 395 if (!domDocument)
michael@0 396 return NS_OK;
michael@0 397
michael@0 398 nsCOMPtr<nsIDocument> document = do_QueryInterface(domDocument);
michael@0 399 if (!document)
michael@0 400 return NS_OK;
michael@0 401
michael@0 402 // Deal with the agent sheets first. Have to do all the style sets by hand.
michael@0 403 nsCOMPtr<nsIPresShell> shell = document->GetShell();
michael@0 404 if (shell) {
michael@0 405 // Reload only the chrome URL agent style sheets.
michael@0 406 nsCOMArray<nsIStyleSheet> agentSheets;
michael@0 407 rv = shell->GetAgentStyleSheets(agentSheets);
michael@0 408 NS_ENSURE_SUCCESS(rv, rv);
michael@0 409
michael@0 410 nsCOMArray<nsIStyleSheet> newAgentSheets;
michael@0 411 for (int32_t l = 0; l < agentSheets.Count(); ++l) {
michael@0 412 nsIStyleSheet *sheet = agentSheets[l];
michael@0 413
michael@0 414 nsIURI* uri = sheet->GetSheetURI();
michael@0 415
michael@0 416 if (IsChromeURI(uri)) {
michael@0 417 // Reload the sheet.
michael@0 418 nsRefPtr<nsCSSStyleSheet> newSheet;
michael@0 419 rv = document->LoadChromeSheetSync(uri, true,
michael@0 420 getter_AddRefs(newSheet));
michael@0 421 if (NS_FAILED(rv)) return rv;
michael@0 422 if (newSheet) {
michael@0 423 rv = newAgentSheets.AppendObject(newSheet) ? NS_OK : NS_ERROR_FAILURE;
michael@0 424 if (NS_FAILED(rv)) return rv;
michael@0 425 }
michael@0 426 }
michael@0 427 else { // Just use the same sheet.
michael@0 428 rv = newAgentSheets.AppendObject(sheet) ? NS_OK : NS_ERROR_FAILURE;
michael@0 429 if (NS_FAILED(rv)) return rv;
michael@0 430 }
michael@0 431 }
michael@0 432
michael@0 433 rv = shell->SetAgentStyleSheets(newAgentSheets);
michael@0 434 NS_ENSURE_SUCCESS(rv, rv);
michael@0 435 }
michael@0 436
michael@0 437 // Build an array of nsIURIs of style sheets we need to load.
michael@0 438 nsCOMArray<nsIStyleSheet> oldSheets;
michael@0 439 nsCOMArray<nsIStyleSheet> newSheets;
michael@0 440
michael@0 441 int32_t count = document->GetNumberOfStyleSheets();
michael@0 442
michael@0 443 // Iterate over the style sheets.
michael@0 444 int32_t i;
michael@0 445 for (i = 0; i < count; i++) {
michael@0 446 // Get the style sheet
michael@0 447 nsIStyleSheet *styleSheet = document->GetStyleSheetAt(i);
michael@0 448
michael@0 449 if (!oldSheets.AppendObject(styleSheet)) {
michael@0 450 return NS_ERROR_OUT_OF_MEMORY;
michael@0 451 }
michael@0 452 }
michael@0 453
michael@0 454 // Iterate over our old sheets and kick off a sync load of the new
michael@0 455 // sheet if and only if it's a chrome URL.
michael@0 456 for (i = 0; i < count; i++) {
michael@0 457 nsRefPtr<nsCSSStyleSheet> sheet = do_QueryObject(oldSheets[i]);
michael@0 458 nsIURI* uri = sheet ? sheet->GetOriginalURI() : nullptr;
michael@0 459
michael@0 460 if (uri && IsChromeURI(uri)) {
michael@0 461 // Reload the sheet.
michael@0 462 nsRefPtr<nsCSSStyleSheet> newSheet;
michael@0 463 // XXX what about chrome sheets that have a title or are disabled? This
michael@0 464 // only works by sheer dumb luck.
michael@0 465 document->LoadChromeSheetSync(uri, false, getter_AddRefs(newSheet));
michael@0 466 // Even if it's null, we put in in there.
michael@0 467 newSheets.AppendObject(newSheet);
michael@0 468 }
michael@0 469 else {
michael@0 470 // Just use the same sheet.
michael@0 471 newSheets.AppendObject(sheet);
michael@0 472 }
michael@0 473 }
michael@0 474
michael@0 475 // Now notify the document that multiple sheets have been added and removed.
michael@0 476 document->UpdateStyleSheets(oldSheets, newSheets);
michael@0 477 return NS_OK;
michael@0 478 }
michael@0 479
michael@0 480 void
michael@0 481 nsChromeRegistry::FlushAllCaches()
michael@0 482 {
michael@0 483 nsCOMPtr<nsIObserverService> obsSvc =
michael@0 484 mozilla::services::GetObserverService();
michael@0 485 NS_ASSERTION(obsSvc, "Couldn't get observer service.");
michael@0 486
michael@0 487 obsSvc->NotifyObservers((nsIChromeRegistry*) this,
michael@0 488 NS_CHROME_FLUSH_TOPIC, nullptr);
michael@0 489 }
michael@0 490
michael@0 491 // xxxbsmedberg Move me to nsIWindowMediator
michael@0 492 NS_IMETHODIMP
michael@0 493 nsChromeRegistry::ReloadChrome()
michael@0 494 {
michael@0 495 UpdateSelectedLocale();
michael@0 496 FlushAllCaches();
michael@0 497 // Do a reload of all top level windows.
michael@0 498 nsresult rv = NS_OK;
michael@0 499
michael@0 500 // Get the window mediator
michael@0 501 nsCOMPtr<nsIWindowMediator> windowMediator
michael@0 502 (do_GetService(NS_WINDOWMEDIATOR_CONTRACTID));
michael@0 503 if (windowMediator) {
michael@0 504 nsCOMPtr<nsISimpleEnumerator> windowEnumerator;
michael@0 505
michael@0 506 rv = windowMediator->GetEnumerator(nullptr, getter_AddRefs(windowEnumerator));
michael@0 507 if (NS_SUCCEEDED(rv)) {
michael@0 508 // Get each dom window
michael@0 509 bool more;
michael@0 510 rv = windowEnumerator->HasMoreElements(&more);
michael@0 511 if (NS_FAILED(rv)) return rv;
michael@0 512 while (more) {
michael@0 513 nsCOMPtr<nsISupports> protoWindow;
michael@0 514 rv = windowEnumerator->GetNext(getter_AddRefs(protoWindow));
michael@0 515 if (NS_SUCCEEDED(rv)) {
michael@0 516 nsCOMPtr<nsIDOMWindow> domWindow = do_QueryInterface(protoWindow);
michael@0 517 if (domWindow) {
michael@0 518 nsCOMPtr<nsIDOMLocation> location;
michael@0 519 domWindow->GetLocation(getter_AddRefs(location));
michael@0 520 if (location) {
michael@0 521 rv = location->Reload(false);
michael@0 522 if (NS_FAILED(rv)) return rv;
michael@0 523 }
michael@0 524 }
michael@0 525 }
michael@0 526 rv = windowEnumerator->HasMoreElements(&more);
michael@0 527 if (NS_FAILED(rv)) return rv;
michael@0 528 }
michael@0 529 }
michael@0 530 }
michael@0 531 return rv;
michael@0 532 }
michael@0 533
michael@0 534 NS_IMETHODIMP
michael@0 535 nsChromeRegistry::AllowScriptsForPackage(nsIURI* aChromeURI, bool *aResult)
michael@0 536 {
michael@0 537 nsresult rv;
michael@0 538 *aResult = false;
michael@0 539
michael@0 540 #ifdef DEBUG
michael@0 541 bool isChrome;
michael@0 542 aChromeURI->SchemeIs("chrome", &isChrome);
michael@0 543 NS_ASSERTION(isChrome, "Non-chrome URI passed to AllowScriptsForPackage!");
michael@0 544 #endif
michael@0 545
michael@0 546 nsCOMPtr<nsIURL> url (do_QueryInterface(aChromeURI));
michael@0 547 NS_ENSURE_TRUE(url, NS_NOINTERFACE);
michael@0 548
michael@0 549 nsAutoCString provider, file;
michael@0 550 rv = GetProviderAndPath(url, provider, file);
michael@0 551 NS_ENSURE_SUCCESS(rv, rv);
michael@0 552
michael@0 553 if (!provider.EqualsLiteral("skin"))
michael@0 554 *aResult = true;
michael@0 555
michael@0 556 return NS_OK;
michael@0 557 }
michael@0 558
michael@0 559 NS_IMETHODIMP
michael@0 560 nsChromeRegistry::AllowContentToAccess(nsIURI *aURI, bool *aResult)
michael@0 561 {
michael@0 562 nsresult rv;
michael@0 563
michael@0 564 *aResult = false;
michael@0 565
michael@0 566 #ifdef DEBUG
michael@0 567 bool isChrome;
michael@0 568 aURI->SchemeIs("chrome", &isChrome);
michael@0 569 NS_ASSERTION(isChrome, "Non-chrome URI passed to AllowContentToAccess!");
michael@0 570 #endif
michael@0 571
michael@0 572 nsCOMPtr<nsIURL> url = do_QueryInterface(aURI);
michael@0 573 if (!url) {
michael@0 574 NS_ERROR("Chrome URL doesn't implement nsIURL.");
michael@0 575 return NS_ERROR_UNEXPECTED;
michael@0 576 }
michael@0 577
michael@0 578 nsAutoCString package;
michael@0 579 rv = url->GetHostPort(package);
michael@0 580 NS_ENSURE_SUCCESS(rv, rv);
michael@0 581
michael@0 582 uint32_t flags;
michael@0 583 rv = GetFlagsFromPackage(package, &flags);
michael@0 584
michael@0 585 if (NS_SUCCEEDED(rv)) {
michael@0 586 *aResult = !!(flags & CONTENT_ACCESSIBLE);
michael@0 587 }
michael@0 588 return NS_OK;
michael@0 589 }
michael@0 590
michael@0 591 NS_IMETHODIMP_(bool)
michael@0 592 nsChromeRegistry::WrappersEnabled(nsIURI *aURI)
michael@0 593 {
michael@0 594 nsCOMPtr<nsIURL> chromeURL (do_QueryInterface(aURI));
michael@0 595 if (!chromeURL)
michael@0 596 return false;
michael@0 597
michael@0 598 bool isChrome = false;
michael@0 599 nsresult rv = chromeURL->SchemeIs("chrome", &isChrome);
michael@0 600 if (NS_FAILED(rv) || !isChrome)
michael@0 601 return false;
michael@0 602
michael@0 603 nsAutoCString package;
michael@0 604 rv = chromeURL->GetHostPort(package);
michael@0 605 if (NS_FAILED(rv))
michael@0 606 return false;
michael@0 607
michael@0 608 uint32_t flags;
michael@0 609 rv = GetFlagsFromPackage(package, &flags);
michael@0 610 return NS_SUCCEEDED(rv) && (flags & XPCNATIVEWRAPPERS);
michael@0 611 }
michael@0 612
michael@0 613 already_AddRefed<nsChromeRegistry>
michael@0 614 nsChromeRegistry::GetSingleton()
michael@0 615 {
michael@0 616 if (gChromeRegistry) {
michael@0 617 nsRefPtr<nsChromeRegistry> registry = gChromeRegistry;
michael@0 618 return registry.forget();
michael@0 619 }
michael@0 620
michael@0 621 nsRefPtr<nsChromeRegistry> cr;
michael@0 622 if (GeckoProcessType_Content == XRE_GetProcessType())
michael@0 623 cr = new nsChromeRegistryContent();
michael@0 624 else
michael@0 625 cr = new nsChromeRegistryChrome();
michael@0 626
michael@0 627 if (NS_FAILED(cr->Init()))
michael@0 628 return nullptr;
michael@0 629
michael@0 630 return cr.forget();
michael@0 631 }

mercurial