|
15 | 15 | # include <unistd.h> // for getpid()
|
16 | 16 | #endif
|
17 | 17 |
|
| 18 | +#if JS_HAS_INTL_API && !MOZ_SYSTEM_ICU |
| 19 | +# include "unicode/locid.h" |
| 20 | +#endif /* JS_HAS_INTL_API && !MOZ_SYSTEM_ICU */ |
| 21 | + |
| 22 | +#include "js/LocaleSensitive.h" |
| 23 | + |
18 | 24 | #include "mozilla/ArrayUtils.h"
|
19 | 25 | #include "mozilla/Attributes.h"
|
20 | 26 | #include "mozilla/AutoRestore.h"
|
|
53 | 59 | #include "mozilla/dom/ContentFrameMessageManager.h"
|
54 | 60 | #include "mozilla/dom/DocGroup.h"
|
55 | 61 | #include "mozilla/dom/Element.h"
|
| 62 | +#include "mozilla/dom/Geolocation.h" |
56 | 63 | #include "mozilla/dom/HTMLAnchorElement.h"
|
57 | 64 | #include "mozilla/dom/PerformanceNavigation.h"
|
58 | 65 | #include "mozilla/dom/PermissionMessageUtils.h"
|
|
71 | 78 | #include "mozilla/dom/nsCSPContext.h"
|
72 | 79 | #include "mozilla/dom/LoadURIOptionsBinding.h"
|
73 | 80 | #include "mozilla/dom/JSWindowActorChild.h"
|
| 81 | +#include "mozilla/dom/WorkerCommon.h" |
74 | 82 |
|
75 | 83 | #include "mozilla/net/DocumentChannel.h"
|
76 | 84 | #include "mozilla/net/DocumentChannelChild.h"
|
|
96 | 104 | #include "nsIDocShellTreeItem.h"
|
97 | 105 | #include "nsIDocShellTreeOwner.h"
|
98 | 106 | #include "mozilla/dom/Document.h"
|
| 107 | +#include "mozilla/dom/Element.h" |
99 | 108 | #include "nsIDocumentLoaderFactory.h"
|
100 | 109 | #include "nsIDOMWindow.h"
|
101 | 110 | #include "nsIEditingSession.h"
|
|
183 | 192 | #include "nsGlobalWindow.h"
|
184 | 193 | #include "nsISearchService.h"
|
185 | 194 | #include "nsJSEnvironment.h"
|
| 195 | +#include "nsJSUtils.h" |
186 | 196 | #include "nsNetCID.h"
|
187 | 197 | #include "nsNetUtil.h"
|
188 | 198 | #include "nsObjectLoadingContent.h"
|
@@ -350,6 +360,10 @@ nsDocShell::nsDocShell(BrowsingContext* aBrowsingContext,
|
350 | 360 | mUseErrorPages(false),
|
351 | 361 | mObserveErrorPages(true),
|
352 | 362 | mCSSErrorReportingEnabled(false),
|
| 363 | + mFileInputInterceptionEnabled(false), |
| 364 | + mBypassCSPEnabled(false), |
| 365 | + mOnlineOverride(nsIDocShell::ONLINE_OVERRIDE_NONE), |
| 366 | + mColorSchemeOverride(COLOR_SCHEME_OVERRIDE_NONE), |
353 | 367 | mAllowAuth(mItemType == typeContent),
|
354 | 368 | mAllowKeywordFixup(false),
|
355 | 369 | mIsOffScreenBrowser(false),
|
@@ -1219,6 +1233,7 @@ bool nsDocShell::SetCurrentURI(nsIURI* aURI, nsIRequest* aRequest,
|
1219 | 1233 | isSubFrame = mLSHE->GetIsSubFrame();
|
1220 | 1234 | }
|
1221 | 1235 |
|
| 1236 | + FireOnFrameLocationChange(this, aRequest, aURI, aLocationFlags); |
1222 | 1237 | if (!isSubFrame && !isRoot) {
|
1223 | 1238 | /*
|
1224 | 1239 | * We don't want to send OnLocationChange notifications when
|
@@ -3340,6 +3355,167 @@ nsDocShell::GetMessageManager(ContentFrameMessageManager** aMessageManager) {
|
3340 | 3355 | return NS_OK;
|
3341 | 3356 | }
|
3342 | 3357 |
|
| 3358 | +// =============== Juggler Begin ======================= |
| 3359 | + |
| 3360 | +nsDocShell* nsDocShell::GetRootDocShell() { |
| 3361 | + nsCOMPtr<nsIDocShellTreeItem> rootAsItem; |
| 3362 | + GetInProcessSameTypeRootTreeItem(getter_AddRefs(rootAsItem)); |
| 3363 | + nsCOMPtr<nsIDocShell> rootShell = do_QueryInterface(rootAsItem); |
| 3364 | + return nsDocShell::Cast(rootShell); |
| 3365 | +} |
| 3366 | + |
| 3367 | +NS_IMETHODIMP |
| 3368 | +nsDocShell::GetBypassCSPEnabled(bool* aEnabled) { |
| 3369 | + MOZ_ASSERT(aEnabled); |
| 3370 | + *aEnabled = mBypassCSPEnabled; |
| 3371 | + return NS_OK; |
| 3372 | +} |
| 3373 | + |
| 3374 | +NS_IMETHODIMP |
| 3375 | +nsDocShell::SetBypassCSPEnabled(bool aEnabled) { |
| 3376 | + mBypassCSPEnabled = aEnabled; |
| 3377 | + return NS_OK; |
| 3378 | +} |
| 3379 | + |
| 3380 | +bool nsDocShell::IsBypassCSPEnabled() { |
| 3381 | + return GetRootDocShell()->mBypassCSPEnabled; |
| 3382 | +} |
| 3383 | + |
| 3384 | +NS_IMETHODIMP |
| 3385 | +nsDocShell::GetLanguageOverride(nsAString& aLanguageOverride) { |
| 3386 | + MOZ_ASSERT(aEnabled); |
| 3387 | + aLanguageOverride = GetRootDocShell()->mLanguageOverride; |
| 3388 | + return NS_OK; |
| 3389 | +} |
| 3390 | + |
| 3391 | + |
| 3392 | +static void SetIcuLocale(const nsAString& aLanguageOverride) { |
| 3393 | + icu::Locale locale(NS_LossyConvertUTF16toASCII(aLanguageOverride).get()); |
| 3394 | + if (icu::Locale::getDefault() == locale) |
| 3395 | + return; |
| 3396 | + UErrorCode error_code = U_ZERO_ERROR; |
| 3397 | + const char* lang = locale.getLanguage(); |
| 3398 | + if (lang != nullptr && *lang != '\0') { |
| 3399 | + icu::Locale::setDefault(locale, error_code); |
| 3400 | + } else { |
| 3401 | + fprintf(stderr, "SetIcuLocale Failed to set the ICU default locale to %s\n", NS_LossyConvertUTF16toASCII(aLanguageOverride).get()); |
| 3402 | + } |
| 3403 | + |
| 3404 | + AutoJSAPI jsapi; |
| 3405 | + jsapi.Init(); |
| 3406 | + JSContext* cx = jsapi.cx(); |
| 3407 | + JS_ResetDefaultLocale(JS_GetRuntime(cx)); |
| 3408 | + |
| 3409 | + ResetDefaultLocaleInAllWorkers(); |
| 3410 | +} |
| 3411 | + |
| 3412 | +NS_IMETHODIMP |
| 3413 | +nsDocShell::SetLanguageOverride(const nsAString& aLanguageOverride) { |
| 3414 | + mLanguageOverride = aLanguageOverride; |
| 3415 | + SetIcuLocale(aLanguageOverride); |
| 3416 | + return NS_OK; |
| 3417 | +} |
| 3418 | + |
| 3419 | +NS_IMETHODIMP |
| 3420 | +nsDocShell::OverrideTimezone(const nsAString& aTimezoneOverride, |
| 3421 | + bool* aSuccess) { |
| 3422 | + NS_ENSURE_ARG(aSuccess); |
| 3423 | + NS_LossyConvertUTF16toASCII timeZoneId(aTimezoneOverride); |
| 3424 | + *aSuccess = nsJSUtils::SetTimeZoneOverride(timeZoneId.get()); |
| 3425 | + |
| 3426 | + // Set TZ which affects localtime_s(). |
| 3427 | + auto setTimeZoneEnv = [](const char* value) { |
| 3428 | +#if defined(_WIN32) |
| 3429 | + return _putenv_s("TZ", value) == 0; |
| 3430 | +#else |
| 3431 | + return setenv("TZ", value, true) == 0; |
| 3432 | +#endif /* _WIN32 */ |
| 3433 | + }; |
| 3434 | + if (*aSuccess) { |
| 3435 | + *aSuccess = setTimeZoneEnv(timeZoneId.get()); |
| 3436 | + if (!*aSuccess) { |
| 3437 | + fprintf(stderr, "Failed to set 'TZ' to '%s'\n", timeZoneId.get()); |
| 3438 | + } |
| 3439 | + } |
| 3440 | + return NS_OK; |
| 3441 | +} |
| 3442 | + |
| 3443 | +NS_IMETHODIMP |
| 3444 | +nsDocShell::GetFileInputInterceptionEnabled(bool* aEnabled) { |
| 3445 | + MOZ_ASSERT(aEnabled); |
| 3446 | + *aEnabled = GetRootDocShell()->mFileInputInterceptionEnabled; |
| 3447 | + return NS_OK; |
| 3448 | +} |
| 3449 | + |
| 3450 | +NS_IMETHODIMP |
| 3451 | +nsDocShell::SetFileInputInterceptionEnabled(bool aEnabled) { |
| 3452 | + mFileInputInterceptionEnabled = aEnabled; |
| 3453 | + return NS_OK; |
| 3454 | +} |
| 3455 | + |
| 3456 | +bool nsDocShell::IsFileInputInterceptionEnabled() { |
| 3457 | + return GetRootDocShell()->mFileInputInterceptionEnabled; |
| 3458 | +} |
| 3459 | + |
| 3460 | +void nsDocShell::FilePickerShown(mozilla::dom::Element* element) { |
| 3461 | + nsCOMPtr<nsIObserverService> observerService = |
| 3462 | + mozilla::services::GetObserverService(); |
| 3463 | + observerService->NotifyObservers( |
| 3464 | + ToSupports(element), "juggler-file-picker-shown", nullptr); |
| 3465 | +} |
| 3466 | + |
| 3467 | +RefPtr<nsGeolocationService> nsDocShell::GetGeolocationServiceOverride() { |
| 3468 | + return GetRootDocShell()->mGeolocationServiceOverride; |
| 3469 | +} |
| 3470 | + |
| 3471 | +NS_IMETHODIMP |
| 3472 | +nsDocShell::SetGeolocationOverride(nsIDOMGeoPosition* aGeolocationOverride) { |
| 3473 | + if (aGeolocationOverride) { |
| 3474 | + if (!mGeolocationServiceOverride) { |
| 3475 | + mGeolocationServiceOverride = new nsGeolocationService(); |
| 3476 | + mGeolocationServiceOverride->Init(); |
| 3477 | + } |
| 3478 | + mGeolocationServiceOverride->Update(aGeolocationOverride); |
| 3479 | + } else { |
| 3480 | + mGeolocationServiceOverride = nullptr; |
| 3481 | + } |
| 3482 | + return NS_OK; |
| 3483 | +} |
| 3484 | + |
| 3485 | +NS_IMETHODIMP |
| 3486 | +nsDocShell::GetOnlineOverride(OnlineOverride* aOnlineOverride) { |
| 3487 | + *aOnlineOverride = GetRootDocShell()->mOnlineOverride; |
| 3488 | + return NS_OK; |
| 3489 | +} |
| 3490 | + |
| 3491 | +NS_IMETHODIMP |
| 3492 | +nsDocShell::SetOnlineOverride(OnlineOverride aOnlineOverride) { |
| 3493 | + // We don't have a way to verify this coming from Javascript, so this check is |
| 3494 | + // still needed. |
| 3495 | + if (!(aOnlineOverride == ONLINE_OVERRIDE_NONE || |
| 3496 | + aOnlineOverride == ONLINE_OVERRIDE_ONLINE || |
| 3497 | + aOnlineOverride == ONLINE_OVERRIDE_OFFLINE)) { |
| 3498 | + return NS_ERROR_INVALID_ARG; |
| 3499 | + } |
| 3500 | + |
| 3501 | + mOnlineOverride = aOnlineOverride; |
| 3502 | + return NS_OK; |
| 3503 | +} |
| 3504 | + |
| 3505 | +NS_IMETHODIMP |
| 3506 | +nsDocShell::GetColorSchemeOverride(ColorSchemeOverride* aColorSchemeOverride) { |
| 3507 | + *aColorSchemeOverride = GetRootDocShell()->mColorSchemeOverride; |
| 3508 | + return NS_OK; |
| 3509 | +} |
| 3510 | + |
| 3511 | +NS_IMETHODIMP |
| 3512 | +nsDocShell::SetColorSchemeOverride(ColorSchemeOverride aColorSchemeOverride) { |
| 3513 | + mColorSchemeOverride = aColorSchemeOverride; |
| 3514 | + return NS_OK; |
| 3515 | +} |
| 3516 | + |
| 3517 | +// =============== Juggler End ======================= |
| 3518 | + |
3343 | 3519 | NS_IMETHODIMP
|
3344 | 3520 | nsDocShell::GetIsNavigating(bool* aOut) {
|
3345 | 3521 | *aOut = mIsNavigating;
|
@@ -12137,6 +12313,9 @@ class OnLinkClickEvent : public Runnable {
|
12137 | 12313 | mNoOpenerImplied, nullptr, nullptr,
|
12138 | 12314 | mIsUserTriggered, mTriggeringPrincipal, mCsp);
|
12139 | 12315 | }
|
| 12316 | + nsCOMPtr<nsIObserverService> observerService = mozilla::services::GetObserverService(); |
| 12317 | + observerService->NotifyObservers(ToSupports(mContent), "juggler-link-click-sync", nullptr); |
| 12318 | + |
12140 | 12319 | return NS_OK;
|
12141 | 12320 | }
|
12142 | 12321 |
|
@@ -12226,6 +12405,9 @@ nsresult nsDocShell::OnLinkClick(
|
12226 | 12405 | this, aContent, aURI, target, aFileName, aPostDataStream,
|
12227 | 12406 | aHeadersDataStream, noOpenerImplied, aIsUserTriggered, aIsTrusted,
|
12228 | 12407 | aTriggeringPrincipal, aCsp);
|
| 12408 | + |
| 12409 | + nsCOMPtr<nsIObserverService> observerService = mozilla::services::GetObserverService(); |
| 12410 | + observerService->NotifyObservers(ToSupports(aContent), "juggler-link-click", nullptr); |
12229 | 12411 | return DispatchToTabGroup(TaskCategory::UI, ev.forget());
|
12230 | 12412 | }
|
12231 | 12413 |
|
|
0 commit comments