Index: Source/core/frame/Screen.cpp |
diff --git a/Source/core/frame/Screen.cpp b/Source/core/frame/Screen.cpp |
index 7a258ebf77e354fafcb70a318c2f1aa0f15e8067..5a0cf9d769490d5643401aef07481bcfe36411f6 100644 |
--- a/Source/core/frame/Screen.cpp |
+++ b/Source/core/frame/Screen.cpp |
@@ -30,6 +30,7 @@ |
#include "config.h" |
#include "core/frame/Screen.h" |
+#include "bindings/v8/Dictionary.h" |
#include "core/frame/FrameHost.h" |
#include "core/frame/FrameView.h" |
#include "core/frame/LocalFrame.h" |
@@ -37,9 +38,24 @@ |
#include "core/inspector/InspectorInstrumentation.h" |
#include "platform/PlatformScreen.h" |
#include "platform/geometry/FloatRect.h" |
+#include "wtf/HashMap.h" |
namespace WebCore { |
+typedef HashMap<String, String> ScreenOverrideMap; |
+ |
+static ScreenOverrideMap& overrideScreenData() |
+{ |
+ DEFINE_STATIC_LOCAL(ScreenOverrideMap, overrideData, ()); |
+ return overrideData; |
+} |
+ |
+#define RETURN_OVERRIDE_DATA_IF_EXISTS(name, type) \ |
+ const ScreenOverrideMap& overrideData = overrideScreenData(); \ |
+ ScreenOverrideMap::const_iterator it = overrideData.find(name); \ |
+ if (UNLIKELY(it != overrideData.end())) \ |
+ return it->value.to##type(); |
+ |
Screen::Screen(LocalFrame* frame) |
: DOMWindowProperty(frame) |
{ |
@@ -50,6 +66,7 @@ unsigned Screen::height() const |
{ |
if (!m_frame) |
return 0; |
+ RETURN_OVERRIDE_DATA_IF_EXISTS("height", UInt); |
FrameHost* host = m_frame->host(); |
if (host && host->settings().reportScreenSizeInPhysicalPixelsQuirk()) |
return lroundf(screenRect(m_frame->view()).height() * host->deviceScaleFactor()); |
@@ -60,6 +77,7 @@ unsigned Screen::width() const |
{ |
if (!m_frame) |
return 0; |
+ RETURN_OVERRIDE_DATA_IF_EXISTS("width", UInt); |
FrameHost* host = m_frame->host(); |
if (host && host->settings().reportScreenSizeInPhysicalPixelsQuirk()) |
return lroundf(screenRect(m_frame->view()).width() * host->deviceScaleFactor()); |
@@ -84,6 +102,7 @@ int Screen::availLeft() const |
{ |
if (!m_frame) |
return 0; |
+ RETURN_OVERRIDE_DATA_IF_EXISTS("availLeft", Int); |
FrameHost* host = m_frame->host(); |
if (host && host->settings().reportScreenSizeInPhysicalPixelsQuirk()) |
return lroundf(screenAvailableRect(m_frame->view()).x() * host->deviceScaleFactor()); |
@@ -94,6 +113,7 @@ int Screen::availTop() const |
{ |
if (!m_frame) |
return 0; |
+ RETURN_OVERRIDE_DATA_IF_EXISTS("availTop", Int); |
FrameHost* host = m_frame->host(); |
if (host && host->settings().reportScreenSizeInPhysicalPixelsQuirk()) |
return lroundf(screenAvailableRect(m_frame->view()).y() * host->deviceScaleFactor()); |
@@ -104,6 +124,7 @@ unsigned Screen::availHeight() const |
{ |
if (!m_frame) |
return 0; |
+ RETURN_OVERRIDE_DATA_IF_EXISTS("availHeight", UInt); |
FrameHost* host = m_frame->host(); |
if (host && host->settings().reportScreenSizeInPhysicalPixelsQuirk()) |
return lroundf(screenAvailableRect(m_frame->view()).height() * host->deviceScaleFactor()); |
@@ -114,6 +135,7 @@ unsigned Screen::availWidth() const |
{ |
if (!m_frame) |
return 0; |
+ RETURN_OVERRIDE_DATA_IF_EXISTS("availWidth", UInt); |
FrameHost* host = m_frame->host(); |
if (host && host->settings().reportScreenSizeInPhysicalPixelsQuirk()) |
return lroundf(screenAvailableRect(m_frame->view()).width() * host->deviceScaleFactor()); |
@@ -137,4 +159,14 @@ void Screen::trace(Visitor* visitor) |
WillBeHeapSupplementable<Screen>::trace(visitor); |
} |
+void Screen::setOverrideScreenData(const Dictionary& overrideData) |
+{ |
+ overrideData.getOwnPropertiesAsStringHashMap(overrideScreenData()); |
+} |
+ |
+void Screen::clearOverrideScreenData() |
+{ |
+ overrideScreenData().clear(); |
+} |
+ |
} // namespace WebCore |