| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "modules/donottrack/NavigatorDoNotTrack.h" | 32 #include "ViewportAttributes.h" |
| 33 | |
| 34 #include "core/loader/FrameLoader.h" | |
| 35 #include "core/loader/FrameLoaderClient.h" | |
| 36 #include "core/page/Frame.h" | |
| 37 #include "core/page/Navigator.h" | |
| 38 #include "wtf/PassOwnPtr.h" | |
| 39 | 33 |
| 40 namespace WebCore { | 34 namespace WebCore { |
| 41 | 35 |
| 42 NavigatorDoNotTrack::NavigatorDoNotTrack(Frame* frame) | 36 ViewportAttributes::ViewportAttributes() |
| 43 : DOMWindowProperty(frame) | 37 : initialScale(-1), minimumScale(-1), maximumScale(-1) { } |
| 38 |
| 39 ViewportAttributes::ViewportAttributes(float initial, float minimum, float maxim
um) |
| 40 : initialScale(initial), minimumScale(minimum), maximumScale(maximum) { } |
| 41 |
| 42 void ViewportAttributes::overrideWith(const ViewportAttributes& other) |
| 44 { | 43 { |
| 44 if (other.initialScale != -1) { |
| 45 initialScale = other.initialScale; |
| 46 if (minimumScale != -1) |
| 47 minimumScale = std::min(minimumScale, other.initialScale); |
| 48 } |
| 49 if (other.minimumScale != -1) |
| 50 minimumScale = other.minimumScale; |
| 51 if (other.maximumScale != -1) |
| 52 maximumScale = other.maximumScale; |
| 53 if (!other.layoutSize.isEmpty()) |
| 54 layoutSize = other.layoutSize; |
| 55 clampAll(); |
| 45 } | 56 } |
| 46 | 57 |
| 47 NavigatorDoNotTrack::~NavigatorDoNotTrack() | 58 float ViewportAttributes::clampToConstraints(float pageScaleFactor) const |
| 48 { | 59 { |
| 60 if (pageScaleFactor == -1) |
| 61 return pageScaleFactor; |
| 62 if (minimumScale != -1) |
| 63 pageScaleFactor = std::max(pageScaleFactor, minimumScale); |
| 64 if (maximumScale != -1) |
| 65 pageScaleFactor = std::min(pageScaleFactor, maximumScale); |
| 66 return pageScaleFactor; |
| 49 } | 67 } |
| 50 | 68 |
| 51 const char* NavigatorDoNotTrack::supplementName() | 69 void ViewportAttributes::clampAll() |
| 52 { | 70 { |
| 53 return "NavigatorDoNotTrack"; | 71 if (minimumScale != -1 && maximumScale != -1) |
| 72 maximumScale = std::max(minimumScale, maximumScale); |
| 73 initialScale = clampToConstraints(initialScale); |
| 54 } | 74 } |
| 55 | 75 |
| 56 NavigatorDoNotTrack* NavigatorDoNotTrack::from(Navigator* navigator) | 76 bool ViewportAttributes::operator==(const ViewportAttributes& other) const |
| 57 { | 77 { |
| 58 NavigatorDoNotTrack* supplement = static_cast<NavigatorDoNotTrack*>(Suppleme
nt<Navigator>::from(navigator, supplementName())); | 78 return layoutSize == other.layoutSize |
| 59 if (!supplement) { | 79 && initialScale == other.initialScale |
| 60 supplement = new NavigatorDoNotTrack(navigator->frame()); | 80 && minimumScale == other.minimumScale |
| 61 provideTo(navigator, supplementName(), adoptPtr(supplement)); | 81 && maximumScale == other.maximumScale; |
| 62 } | |
| 63 return supplement; | |
| 64 } | |
| 65 | |
| 66 String NavigatorDoNotTrack::doNotTrack(Navigator* navigator) | |
| 67 { | |
| 68 return NavigatorDoNotTrack::from(navigator)->doNotTrack(); | |
| 69 } | |
| 70 | |
| 71 String NavigatorDoNotTrack::doNotTrack() | |
| 72 { | |
| 73 return frame() ? frame()->loader()->client()->doNotTrackValue() : String(); | |
| 74 } | 82 } |
| 75 | 83 |
| 76 } // namespace WebCore | 84 } // namespace WebCore |
| OLD | NEW |