Skip to content

Commit

Permalink
Bug 1258033 - Part 1: Add IsTrackingProtectionOn for nsILoadContext. …
Browse files Browse the repository at this point in the history
…r=smaug

MozReview-Commit-ID: 2eQzO6KDLyX

--HG--
extra : rebase_source : 1f5c1c7b250336ff4ecf1e5b3949a532b7bb9144
  • Loading branch information
DimiDL committed Jun 2, 2016
1 parent ef4eead commit 8d44df2
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 0 deletions.
18 changes: 18 additions & 0 deletions docshell/base/LoadContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "mozilla/Assertions.h"
#include "mozilla/BasePrincipal.h"
#include "mozilla/LoadContext.h"
#include "mozilla/Preferences.h"
#include "mozilla/dom/ScriptSettings.h" // for AutoJSAPI
#include "nsContentUtils.h"
#include "xpcpublic.h"
Expand Down Expand Up @@ -202,6 +203,23 @@ LoadContext::GetOriginAttributes(JS::MutableHandleValue aAttrs)
return NS_OK;
}

NS_IMETHODIMP
LoadContext::IsTrackingProtectionOn(bool* aIsTrackingProtectionOn)
{
MOZ_ASSERT(mIsNotNull);

if (Preferences::GetBool("privacy.trackingprotection.enabled", false)) {
*aIsTrackingProtectionOn = true;
} else if (mUsePrivateBrowsing &&
Preferences::GetBool("privacy.trackingprotection.pbmode.enabled", false)) {
*aIsTrackingProtectionOn = true;
} else {
*aIsTrackingProtectionOn = false;
}

return NS_OK;
}

//-----------------------------------------------------------------------------
// LoadContext::nsIInterfaceRequestor
//-----------------------------------------------------------------------------
Expand Down
15 changes: 15 additions & 0 deletions docshell/base/nsDocShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13375,6 +13375,21 @@ nsDocShell::IsAppOfType(uint32_t aAppType, bool* aIsOfType)
return NS_OK;
}

NS_IMETHODIMP
nsDocShell::IsTrackingProtectionOn(bool* aIsTrackingProtectionOn)
{
if (Preferences::GetBool("privacy.trackingprotection.enabled", false)) {
*aIsTrackingProtectionOn = true;
} else if (mInPrivateBrowsing &&
Preferences::GetBool("privacy.trackingprotection.pbmode.enabled", false)) {
*aIsTrackingProtectionOn = true;
} else {
*aIsTrackingProtectionOn = false;
}

return NS_OK;
}

NS_IMETHODIMP
nsDocShell::GetIsContent(bool* aIsContent)
{
Expand Down
1 change: 1 addition & 0 deletions docshell/base/nsDocShell.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ class nsDocShell final
NS_IMETHOD GetUseRemoteTabs(bool*) override;
NS_IMETHOD SetRemoteTabs(bool) override;
NS_IMETHOD GetOriginAttributes(JS::MutableHandle<JS::Value>) override;
NS_IMETHOD IsTrackingProtectionOn(bool*) override;

// Restores a cached presentation from history (mLSHE).
// This method swaps out the content viewer and simulates loads for
Expand Down
16 changes: 16 additions & 0 deletions docshell/base/nsILoadContext.idl
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,21 @@ interface nsILoadContext : nsISupports
*/
bool GetOriginAttributes(mozilla::DocShellOriginAttributes& aAttrs);
#endif
%}

/**
* Returns true if tracking protection is enabled for the load context.
*/
boolean IsTrackingProtectionOn();

%{C++
/**
* De-XPCOMed getter to make call-sites cleaner.
*/
bool UseTrackingProtection() {
bool usingTP;
IsTrackingProtectionOn(&usingTP);
return usingTP;
}
%}
};
1 change: 1 addition & 0 deletions dom/ipc/TabParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3186,6 +3186,7 @@ class FakeChannel final : public nsIChannel,
NS_IMETHOD GetOriginAttributes(JS::MutableHandleValue) NO_IMPL
NS_IMETHOD GetUseRemoteTabs(bool*) NO_IMPL
NS_IMETHOD SetRemoteTabs(bool) NO_IMPL
NS_IMETHOD IsTrackingProtectionOn(bool*) NO_IMPL
#undef NO_IMPL

protected:
Expand Down
6 changes: 6 additions & 0 deletions uriloader/prefetch/OfflineCacheUpdateParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,5 +290,11 @@ OfflineCacheUpdateParent::GetOriginAttributes(JS::MutableHandleValue aAttrs)
return NS_OK;
}

NS_IMETHODIMP
OfflineCacheUpdateParent::IsTrackingProtectionOn(bool* aIsTrackingProtectionOn)
{
return NS_ERROR_NOT_IMPLEMENTED;
}

} // namespace docshell
} // namespace mozilla

0 comments on commit 8d44df2

Please sign in to comment.