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.
widget/xpwidgets/nsTransferable.cpp | file | annotate | diff | comparison | revisions | |
widget/xpwidgets/nsTransferable.h | file | annotate | diff | comparison | revisions |
1.1 --- a/widget/xpwidgets/nsTransferable.cpp Thu Jan 15 15:55:04 2015 +0100 1.2 +++ b/widget/xpwidgets/nsTransferable.cpp Thu Jan 15 15:59:08 2015 +0100 1.3 @@ -55,6 +55,28 @@ 1.4 } 1.5 1.6 //------------------------------------------------------------------------- 1.7 +// The SetData method is overloaded to indicate private browsing mode 1.8 +// while achieving some semblance of (private) interface compatibility. 1.9 +//------------------------------------------------------------------------- 1.10 +void 1.11 +DataStruct::SetData ( nsISupports* aData, uint32_t aDataLen, bool aIsPrivBrowsing ) 1.12 +{ 1.13 + // Now, check to see if we consider the data to be "too large" 1.14 + // as well as ensuring that private browsing mode is disabled 1.15 + if (aDataLen > kLargeDatasetSize && aIsPrivBrowsing == false) { 1.16 + // if so, cache it to disk instead of memory 1.17 + if ( NS_SUCCEEDED(WriteCache(aData, aDataLen)) ) 1.18 + return; 1.19 + else 1.20 + NS_WARNING("Oh no, couldn't write data to the cache file"); 1.21 + } 1.22 + 1.23 + mData = aData; 1.24 + mDataLen = aDataLen; 1.25 +} 1.26 + 1.27 + 1.28 +//------------------------------------------------------------------------- 1.29 void 1.30 DataStruct::SetData ( nsISupports* aData, uint32_t aDataLen ) 1.31 { 1.32 @@ -398,11 +420,17 @@ 1.33 1.34 // first check our intrinsic flavors to see if one has been registered. 1.35 uint32_t i = 0; 1.36 + bool aIsPrivBrowsing = false; 1.37 for (i = 0; i < mDataArray.Length(); ++i) { 1.38 DataStruct& data = mDataArray.ElementAt(i); 1.39 if ( data.GetFlavor().Equals(aFlavor) ) { 1.40 - data.SetData ( aData, aDataLen ); 1.41 - return NS_OK; 1.42 + if ( NS_SUCCEEDED(GetIsPrivateData(&aIsPrivBrowsing)) ) { 1.43 + data.SetData ( aData, aDataLen, aIsPrivBrowsing ); 1.44 + return NS_OK; 1.45 + } 1.46 + else { // call to GetIsPrivateData() failed, 1.47 + return NS_ERROR_FAILURE; // we didn't SetData(), generic error 1.48 + } 1.49 } 1.50 } 1.51
2.1 --- a/widget/xpwidgets/nsTransferable.h Thu Jan 15 15:55:04 2015 +0100 2.2 +++ b/widget/xpwidgets/nsTransferable.h Thu Jan 15 15:59:08 2015 +0100 2.3 @@ -28,6 +28,7 @@ 2.4 2.5 const nsCString& GetFlavor() const { return mFlavor; } 2.6 void SetData( nsISupports* inData, uint32_t inDataLen ); 2.7 + void SetData( nsISupports* inData, uint32_t inDataLen, bool inPrivBrowse ); 2.8 void GetData( nsISupports** outData, uint32_t *outDataLen ); 2.9 already_AddRefed<nsIFile> GetFileSpec(const char* aFileName); 2.10 bool IsDataAvailable() const { return (mData && mDataLen > 0) || (!mData && mCacheFileName); }