Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: Source/core/frame/Screen.cpp

Issue 243173004: Make window.screen property non replaceable (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix clang error Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2007 Apple 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 12 matching lines...) Expand all
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 29
30 #include "config.h" 30 #include "config.h"
31 #include "core/frame/Screen.h" 31 #include "core/frame/Screen.h"
32 32
33 #include "bindings/v8/Dictionary.h"
33 #include "core/frame/FrameHost.h" 34 #include "core/frame/FrameHost.h"
34 #include "core/frame/FrameView.h" 35 #include "core/frame/FrameView.h"
35 #include "core/frame/LocalFrame.h" 36 #include "core/frame/LocalFrame.h"
36 #include "core/frame/Settings.h" 37 #include "core/frame/Settings.h"
37 #include "core/inspector/InspectorInstrumentation.h" 38 #include "core/inspector/InspectorInstrumentation.h"
38 #include "platform/PlatformScreen.h" 39 #include "platform/PlatformScreen.h"
39 #include "platform/geometry/FloatRect.h" 40 #include "platform/geometry/FloatRect.h"
41 #include "wtf/HashMap.h"
40 42
41 namespace WebCore { 43 namespace WebCore {
42 44
45 typedef HashMap<String, String> ScreenOverrideMap;
46
47 static ScreenOverrideMap& overrideScreenData()
48 {
49 DEFINE_STATIC_LOCAL(ScreenOverrideMap, overrideData, ());
50 return overrideData;
51 }
52
53 #define RETURN_OVERRIDE_DATA_IF_EXISTS(name, type) \
54 const ScreenOverrideMap& overrideData = overrideScreenData(); \
55 ScreenOverrideMap::const_iterator it = overrideData.find(name); \
56 if (UNLIKELY(it != overrideData.end())) \
57 return it->value.to##type();
58
43 Screen::Screen(LocalFrame* frame) 59 Screen::Screen(LocalFrame* frame)
44 : DOMWindowProperty(frame) 60 : DOMWindowProperty(frame)
45 { 61 {
46 ScriptWrappable::init(this); 62 ScriptWrappable::init(this);
47 } 63 }
48 64
49 unsigned Screen::height() const 65 unsigned Screen::height() const
50 { 66 {
51 if (!m_frame) 67 if (!m_frame)
52 return 0; 68 return 0;
69 RETURN_OVERRIDE_DATA_IF_EXISTS("height", UInt);
53 FrameHost* host = m_frame->host(); 70 FrameHost* host = m_frame->host();
54 if (host && host->settings().reportScreenSizeInPhysicalPixelsQuirk()) 71 if (host && host->settings().reportScreenSizeInPhysicalPixelsQuirk())
55 return lroundf(screenRect(m_frame->view()).height() * host->deviceScaleF actor()); 72 return lroundf(screenRect(m_frame->view()).height() * host->deviceScaleF actor());
56 return static_cast<unsigned>(screenRect(m_frame->view()).height()); 73 return static_cast<unsigned>(screenRect(m_frame->view()).height());
57 } 74 }
58 75
59 unsigned Screen::width() const 76 unsigned Screen::width() const
60 { 77 {
61 if (!m_frame) 78 if (!m_frame)
62 return 0; 79 return 0;
80 RETURN_OVERRIDE_DATA_IF_EXISTS("width", UInt);
63 FrameHost* host = m_frame->host(); 81 FrameHost* host = m_frame->host();
64 if (host && host->settings().reportScreenSizeInPhysicalPixelsQuirk()) 82 if (host && host->settings().reportScreenSizeInPhysicalPixelsQuirk())
65 return lroundf(screenRect(m_frame->view()).width() * host->deviceScaleFa ctor()); 83 return lroundf(screenRect(m_frame->view()).width() * host->deviceScaleFa ctor());
66 return static_cast<unsigned>(screenRect(m_frame->view()).width()); 84 return static_cast<unsigned>(screenRect(m_frame->view()).width());
67 } 85 }
68 86
69 unsigned Screen::colorDepth() const 87 unsigned Screen::colorDepth() const
70 { 88 {
71 if (!m_frame) 89 if (!m_frame)
72 return 0; 90 return 0;
73 return static_cast<unsigned>(screenDepth(m_frame->view())); 91 return static_cast<unsigned>(screenDepth(m_frame->view()));
74 } 92 }
75 93
76 unsigned Screen::pixelDepth() const 94 unsigned Screen::pixelDepth() const
77 { 95 {
78 if (!m_frame) 96 if (!m_frame)
79 return 0; 97 return 0;
80 return static_cast<unsigned>(screenDepth(m_frame->view())); 98 return static_cast<unsigned>(screenDepth(m_frame->view()));
81 } 99 }
82 100
83 int Screen::availLeft() const 101 int Screen::availLeft() const
84 { 102 {
85 if (!m_frame) 103 if (!m_frame)
86 return 0; 104 return 0;
105 RETURN_OVERRIDE_DATA_IF_EXISTS("availLeft", Int);
87 FrameHost* host = m_frame->host(); 106 FrameHost* host = m_frame->host();
88 if (host && host->settings().reportScreenSizeInPhysicalPixelsQuirk()) 107 if (host && host->settings().reportScreenSizeInPhysicalPixelsQuirk())
89 return lroundf(screenAvailableRect(m_frame->view()).x() * host->deviceSc aleFactor()); 108 return lroundf(screenAvailableRect(m_frame->view()).x() * host->deviceSc aleFactor());
90 return static_cast<int>(screenAvailableRect(m_frame->view()).x()); 109 return static_cast<int>(screenAvailableRect(m_frame->view()).x());
91 } 110 }
92 111
93 int Screen::availTop() const 112 int Screen::availTop() const
94 { 113 {
95 if (!m_frame) 114 if (!m_frame)
96 return 0; 115 return 0;
116 RETURN_OVERRIDE_DATA_IF_EXISTS("availTop", Int);
97 FrameHost* host = m_frame->host(); 117 FrameHost* host = m_frame->host();
98 if (host && host->settings().reportScreenSizeInPhysicalPixelsQuirk()) 118 if (host && host->settings().reportScreenSizeInPhysicalPixelsQuirk())
99 return lroundf(screenAvailableRect(m_frame->view()).y() * host->deviceSc aleFactor()); 119 return lroundf(screenAvailableRect(m_frame->view()).y() * host->deviceSc aleFactor());
100 return static_cast<int>(screenAvailableRect(m_frame->view()).y()); 120 return static_cast<int>(screenAvailableRect(m_frame->view()).y());
101 } 121 }
102 122
103 unsigned Screen::availHeight() const 123 unsigned Screen::availHeight() const
104 { 124 {
105 if (!m_frame) 125 if (!m_frame)
106 return 0; 126 return 0;
127 RETURN_OVERRIDE_DATA_IF_EXISTS("availHeight", UInt);
107 FrameHost* host = m_frame->host(); 128 FrameHost* host = m_frame->host();
108 if (host && host->settings().reportScreenSizeInPhysicalPixelsQuirk()) 129 if (host && host->settings().reportScreenSizeInPhysicalPixelsQuirk())
109 return lroundf(screenAvailableRect(m_frame->view()).height() * host->dev iceScaleFactor()); 130 return lroundf(screenAvailableRect(m_frame->view()).height() * host->dev iceScaleFactor());
110 return static_cast<unsigned>(screenAvailableRect(m_frame->view()).height()); 131 return static_cast<unsigned>(screenAvailableRect(m_frame->view()).height());
111 } 132 }
112 133
113 unsigned Screen::availWidth() const 134 unsigned Screen::availWidth() const
114 { 135 {
115 if (!m_frame) 136 if (!m_frame)
116 return 0; 137 return 0;
138 RETURN_OVERRIDE_DATA_IF_EXISTS("availWidth", UInt);
117 FrameHost* host = m_frame->host(); 139 FrameHost* host = m_frame->host();
118 if (host && host->settings().reportScreenSizeInPhysicalPixelsQuirk()) 140 if (host && host->settings().reportScreenSizeInPhysicalPixelsQuirk())
119 return lroundf(screenAvailableRect(m_frame->view()).width() * host->devi ceScaleFactor()); 141 return lroundf(screenAvailableRect(m_frame->view()).width() * host->devi ceScaleFactor());
120 return static_cast<unsigned>(screenAvailableRect(m_frame->view()).width()); 142 return static_cast<unsigned>(screenAvailableRect(m_frame->view()).width());
121 } 143 }
122 144
123 const AtomicString& Screen::interfaceName() const 145 const AtomicString& Screen::interfaceName() const
124 { 146 {
125 return EventTargetNames::Screen; 147 return EventTargetNames::Screen;
126 } 148 }
127 149
128 ExecutionContext* Screen::executionContext() const 150 ExecutionContext* Screen::executionContext() const
129 { 151 {
130 if (!m_frame) 152 if (!m_frame)
131 return 0; 153 return 0;
132 return m_frame->document(); 154 return m_frame->document();
133 } 155 }
134 156
135 void Screen::trace(Visitor* visitor) 157 void Screen::trace(Visitor* visitor)
136 { 158 {
137 WillBeHeapSupplementable<Screen>::trace(visitor); 159 WillBeHeapSupplementable<Screen>::trace(visitor);
138 } 160 }
139 161
162 void Screen::setOverrideScreenData(const Dictionary& overrideData)
163 {
164 overrideData.getOwnPropertiesAsStringHashMap(overrideScreenData());
165 }
166
167 void Screen::clearOverrideScreenData()
168 {
169 overrideScreenData().clear();
170 }
171
140 } // namespace WebCore 172 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698