Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | #ifndef mozilla_dom_ImageDocument_h |
michael@0 | 6 | #define mozilla_dom_ImageDocument_h |
michael@0 | 7 | |
michael@0 | 8 | #include "mozilla/Attributes.h" |
michael@0 | 9 | #include "imgINotificationObserver.h" |
michael@0 | 10 | #include "MediaDocument.h" |
michael@0 | 11 | #include "nsIDOMEventListener.h" |
michael@0 | 12 | #include "nsIImageDocument.h" |
michael@0 | 13 | |
michael@0 | 14 | namespace mozilla { |
michael@0 | 15 | namespace dom { |
michael@0 | 16 | |
michael@0 | 17 | class ImageDocument MOZ_FINAL : public MediaDocument, |
michael@0 | 18 | public nsIImageDocument, |
michael@0 | 19 | public imgINotificationObserver, |
michael@0 | 20 | public nsIDOMEventListener |
michael@0 | 21 | { |
michael@0 | 22 | public: |
michael@0 | 23 | ImageDocument(); |
michael@0 | 24 | virtual ~ImageDocument(); |
michael@0 | 25 | |
michael@0 | 26 | NS_DECL_ISUPPORTS_INHERITED |
michael@0 | 27 | |
michael@0 | 28 | virtual nsresult Init() MOZ_OVERRIDE; |
michael@0 | 29 | |
michael@0 | 30 | virtual nsresult StartDocumentLoad(const char* aCommand, |
michael@0 | 31 | nsIChannel* aChannel, |
michael@0 | 32 | nsILoadGroup* aLoadGroup, |
michael@0 | 33 | nsISupports* aContainer, |
michael@0 | 34 | nsIStreamListener** aDocListener, |
michael@0 | 35 | bool aReset = true, |
michael@0 | 36 | nsIContentSink* aSink = nullptr) MOZ_OVERRIDE; |
michael@0 | 37 | |
michael@0 | 38 | virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject) MOZ_OVERRIDE; |
michael@0 | 39 | virtual void Destroy() MOZ_OVERRIDE; |
michael@0 | 40 | virtual void OnPageShow(bool aPersisted, |
michael@0 | 41 | EventTarget* aDispatchStartTarget) MOZ_OVERRIDE; |
michael@0 | 42 | |
michael@0 | 43 | NS_DECL_NSIIMAGEDOCUMENT |
michael@0 | 44 | NS_DECL_IMGINOTIFICATIONOBSERVER |
michael@0 | 45 | |
michael@0 | 46 | // nsIDOMEventListener |
michael@0 | 47 | NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) MOZ_OVERRIDE; |
michael@0 | 48 | |
michael@0 | 49 | NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ImageDocument, MediaDocument) |
michael@0 | 50 | |
michael@0 | 51 | friend class ImageListener; |
michael@0 | 52 | |
michael@0 | 53 | void DefaultCheckOverflowing() { CheckOverflowing(mResizeImageByDefault); } |
michael@0 | 54 | |
michael@0 | 55 | // WebIDL API |
michael@0 | 56 | virtual JSObject* WrapNode(JSContext* aCx) |
michael@0 | 57 | MOZ_OVERRIDE; |
michael@0 | 58 | |
michael@0 | 59 | bool ImageResizingEnabled() const |
michael@0 | 60 | { |
michael@0 | 61 | return true; |
michael@0 | 62 | } |
michael@0 | 63 | bool ImageIsOverflowing() const |
michael@0 | 64 | { |
michael@0 | 65 | return mImageIsOverflowing; |
michael@0 | 66 | } |
michael@0 | 67 | bool ImageIsResized() const |
michael@0 | 68 | { |
michael@0 | 69 | return mImageIsResized; |
michael@0 | 70 | } |
michael@0 | 71 | already_AddRefed<imgIRequest> GetImageRequest(ErrorResult& aRv); |
michael@0 | 72 | void ShrinkToFit(); |
michael@0 | 73 | void RestoreImage(); |
michael@0 | 74 | void RestoreImageTo(int32_t aX, int32_t aY) |
michael@0 | 75 | { |
michael@0 | 76 | ScrollImageTo(aX, aY, true); |
michael@0 | 77 | } |
michael@0 | 78 | void ToggleImageSize(); |
michael@0 | 79 | |
michael@0 | 80 | protected: |
michael@0 | 81 | virtual nsresult CreateSyntheticDocument(); |
michael@0 | 82 | |
michael@0 | 83 | nsresult CheckOverflowing(bool changeState); |
michael@0 | 84 | |
michael@0 | 85 | void UpdateTitleAndCharset(); |
michael@0 | 86 | |
michael@0 | 87 | void ScrollImageTo(int32_t aX, int32_t aY, bool restoreImage); |
michael@0 | 88 | |
michael@0 | 89 | float GetRatio() { |
michael@0 | 90 | return std::min(mVisibleWidth / mImageWidth, |
michael@0 | 91 | mVisibleHeight / mImageHeight); |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | void ResetZoomLevel(); |
michael@0 | 95 | float GetZoomLevel(); |
michael@0 | 96 | |
michael@0 | 97 | void UpdateSizeFromLayout(); |
michael@0 | 98 | |
michael@0 | 99 | enum eModeClasses { |
michael@0 | 100 | eNone, |
michael@0 | 101 | eShrinkToFit, |
michael@0 | 102 | eOverflowing |
michael@0 | 103 | }; |
michael@0 | 104 | void SetModeClass(eModeClasses mode); |
michael@0 | 105 | |
michael@0 | 106 | nsresult OnStartContainer(imgIRequest* aRequest, imgIContainer* aImage); |
michael@0 | 107 | nsresult OnStopRequest(imgIRequest *aRequest, nsresult aStatus); |
michael@0 | 108 | |
michael@0 | 109 | nsCOMPtr<nsIContent> mImageContent; |
michael@0 | 110 | |
michael@0 | 111 | float mVisibleWidth; |
michael@0 | 112 | float mVisibleHeight; |
michael@0 | 113 | int32_t mImageWidth; |
michael@0 | 114 | int32_t mImageHeight; |
michael@0 | 115 | |
michael@0 | 116 | bool mResizeImageByDefault; |
michael@0 | 117 | bool mClickResizingEnabled; |
michael@0 | 118 | bool mImageIsOverflowing; |
michael@0 | 119 | // mImageIsResized is true if the image is currently resized |
michael@0 | 120 | bool mImageIsResized; |
michael@0 | 121 | // mShouldResize is true if the image should be resized when it doesn't fit |
michael@0 | 122 | // mImageIsResized cannot be true when this is false, but mImageIsResized |
michael@0 | 123 | // can be false when this is true |
michael@0 | 124 | bool mShouldResize; |
michael@0 | 125 | bool mFirstResize; |
michael@0 | 126 | // mObservingImageLoader is true while the observer is set. |
michael@0 | 127 | bool mObservingImageLoader; |
michael@0 | 128 | |
michael@0 | 129 | float mOriginalZoomLevel; |
michael@0 | 130 | }; |
michael@0 | 131 | |
michael@0 | 132 | } // namespace dom |
michael@0 | 133 | } // namespace mozilla |
michael@0 | 134 | |
michael@0 | 135 | #endif /* mozilla_dom_ImageDocument_h */ |