Commit ab64521d authored by Mike Wasserman's avatar Mike Wasserman Committed by Commit Bot

Screen Enumeration: Add a placeholder Screen.id to replace Screen.name

Use placeholder ordinal ids for now (0, 1, 2, ...); update tests.
TODO: generate per-origin UUIDs that reset when cookies are deleted

Test Screen.id values returned via window.getScreens() with:
 chrome://flags#enable-experimental-web-platform-features OR
 $ chrome --enable-blink-features=ScreenEnumeration
Try https://michaelwasserman.github.io/window-placement-demo

Bug: 994889
Test: Automated, Screen.id placeholder values
Change-Id: I0c5b18b92fef251211822f3473ea85472a7ee945
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2155113Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Michael Wasserman <msw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#761040}
parent 0293b88e
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "base/command_line.h"
#include "base/strings/string_number_conversions.h"
#include "build/build_config.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test_utils.h"
......@@ -31,7 +32,7 @@ constexpr char kGetScreensScript[] = R"(
height: s.height,
internal: s.internal,
left: s.left,
name: s.name,
id: s.id,
orientation: s.orientation != null,
pixelDepth: s.pixelDepth,
primary: s.primary,
......@@ -48,6 +49,7 @@ constexpr char kGetScreensScript[] = R"(
base::ListValue GetExpectedScreens() {
base::ListValue expected_screens;
auto* screen = display::Screen::GetScreen();
size_t id = 0;
for (const auto& d : screen->GetAllDisplays()) {
base::DictionaryValue s;
s.SetIntKey("availHeight", d.work_area().height());
......@@ -58,7 +60,7 @@ base::ListValue GetExpectedScreens() {
s.SetIntKey("height", d.bounds().height());
s.SetBoolKey("internal", d.IsInternal());
s.SetIntKey("left", d.bounds().x());
s.SetStringKey("name", "Generic Screen");
s.SetStringKey("id", base::NumberToString(id++));
s.SetBoolKey("orientation", false);
s.SetIntKey("pixelDepth", d.color_depth());
s.SetBoolKey("primary", d.id() == screen->GetPrimaryDisplay().id());
......
......@@ -173,11 +173,13 @@ void Screen::Trace(Visitor* visitor) {
Screen::Screen(display::mojom::blink::DisplayPtr display,
bool internal,
bool primary)
bool primary,
const String& id)
: DOMWindowClient(static_cast<LocalFrame*>(nullptr)),
display_(std::move(display)),
internal_(internal),
primary_(primary) {}
primary_(primary),
id_(id) {}
int Screen::left() const {
if (display_) {
......@@ -244,13 +246,13 @@ float Screen::scaleFactor() const {
return GetScreenInfo(*frame).device_scale_factor;
}
const String Screen::name() const {
// TODO(http://crbug.com/994889): Implement this.
NOTIMPLEMENTED_LOG_ONCE();
const String Screen::id() const {
if (display_) {
DCHECK(RuntimeEnabledFeatures::ScreenEnumerationEnabled());
return "Generic Screen";
return id_;
}
// TODO(http://crbug.com/994889): Implement this for |window.screen|?
NOTIMPLEMENTED_LOG_ONCE();
return String();
}
......
......@@ -67,13 +67,14 @@ class CORE_EXPORT Screen final : public ScriptWrappable,
// TODO(msw): Resolve different info sources, caching, and lifetimes.
Screen(display::mojom::blink::DisplayPtr display,
bool internal,
bool primary);
bool primary,
const String& id);
int left() const;
int top() const;
bool internal() const;
bool primary() const;
float scaleFactor() const;
const String name() const;
const String id() const;
// Not web-exposed; for internal usage only.
static constexpr int64_t kInvalidDisplayId = -1;
......@@ -92,6 +93,10 @@ class CORE_EXPORT Screen final : public ScriptWrappable,
// value provided upon construction. This member is only valid for Screen
// objects obtained via the experimental Screen Enumeration API.
const base::Optional<bool> primary_;
// A web-exposed device id; it is a static value provided upon construction.
// This member is only valid for Screen objects obtained via the experimental
// Screen Enumeration API.
const String id_;
};
} // namespace blink
......
......@@ -49,5 +49,5 @@
[RuntimeEnabled=ScreenEnumeration] readonly attribute boolean internal;
[RuntimeEnabled=ScreenEnumeration] readonly attribute boolean primary;
[RuntimeEnabled=ScreenEnumeration] readonly attribute float scaleFactor;
[RuntimeEnabled=ScreenEnumeration] readonly attribute DOMString name;
[RuntimeEnabled=ScreenEnumeration] readonly attribute DOMString id;
};
......@@ -38,8 +38,12 @@ void DidGetDisplays(
for (display::mojom::blink::DisplayPtr& backend_display : backend_displays) {
const bool internal = backend_display->id == internal_id;
const bool primary = backend_display->id == primary_id;
// TODO(http://crbug.com/994889): Implement temporary, generated per-origin
// unique device IDs that reset when cookies are deleted. See related:
// web_bluetooth_device_id.h, unguessable_token.h, and uuid.h
const String id = String::NumberToStringECMAScript(screens.size());
screens.emplace_back(MakeGarbageCollected<Screen>(
std::move(backend_display), internal, primary));
std::move(backend_display), internal, primary, id));
}
resolver->Resolve(std::move(screens));
}
......
......@@ -25,5 +25,5 @@ promise_test(async testCase => {
assert_equals(typeof screens[0].primary, 'boolean');
assert_equals(typeof screens[0].internal, 'boolean');
assert_equals(typeof screens[0].scaleFactor, 'number');
assert_equals(typeof screens[0].name, 'string');
assert_equals(typeof screens[0].id, 'string');
}, 'self.getScreens returns at least 1 Screen');
\ No newline at end of file
......@@ -102,9 +102,9 @@ PASS window.cached_screen.availTop is 0
PASS window.cached_screen.availWidth is 0
PASS window.cached_screen.colorDepth is 0
PASS window.cached_screen.height is 0
PASS window.cached_screen.id is ''
PASS window.cached_screen.internal is false
PASS window.cached_screen.left is 0
PASS window.cached_screen.name is ''
PASS window.cached_screen.pixelDepth is 0
PASS window.cached_screen.primary is false
PASS window.cached_screen.scaleFactor is 0
......
......@@ -102,9 +102,9 @@ PASS window.cached_screen.availTop is 0
PASS window.cached_screen.availWidth is 0
PASS window.cached_screen.colorDepth is 0
PASS window.cached_screen.height is 0
PASS window.cached_screen.id is ''
PASS window.cached_screen.internal is false
PASS window.cached_screen.left is 0
PASS window.cached_screen.name is ''
PASS window.cached_screen.pixelDepth is 0
PASS window.cached_screen.primary is false
PASS window.cached_screen.scaleFactor is 0
......
......@@ -102,9 +102,9 @@ PASS window.cached_screen.availTop is 0
PASS window.cached_screen.availWidth is 0
PASS window.cached_screen.colorDepth is 0
PASS window.cached_screen.height is 0
PASS window.cached_screen.id is ''
PASS window.cached_screen.internal is false
PASS window.cached_screen.left is 0
PASS window.cached_screen.name is ''
PASS window.cached_screen.pixelDepth is 0
PASS window.cached_screen.primary is false
PASS window.cached_screen.scaleFactor is 0
......
......@@ -233,9 +233,9 @@ PASS oldChildWindow.screen.availTop is newChildWindow.screen.availTop
PASS oldChildWindow.screen.availWidth is newChildWindow.screen.availWidth
PASS oldChildWindow.screen.colorDepth is newChildWindow.screen.colorDepth
PASS oldChildWindow.screen.height is newChildWindow.screen.height
PASS oldChildWindow.screen.id is newChildWindow.screen.id
PASS oldChildWindow.screen.internal is newChildWindow.screen.internal
PASS oldChildWindow.screen.left is newChildWindow.screen.left
PASS oldChildWindow.screen.name is newChildWindow.screen.name
PASS oldChildWindow.screen.orientation.angle is newChildWindow.screen.orientation.angle
PASS oldChildWindow.screen.orientation.onchange is newChildWindow.screen.orientation.onchange
PASS oldChildWindow.screen.orientation.type is newChildWindow.screen.orientation.type
......
......@@ -168,9 +168,9 @@ PASS childWindow.screen.availTop is 0
PASS childWindow.screen.availWidth is 0
PASS childWindow.screen.colorDepth is 0
PASS childWindow.screen.height is 0
PASS childWindow.screen.id is ''
PASS childWindow.screen.internal is false
PASS childWindow.screen.left is 0
PASS childWindow.screen.name is ''
PASS childWindow.screen.pixelDepth is 0
PASS childWindow.screen.primary is false
PASS childWindow.screen.scaleFactor is 0
......
......@@ -168,9 +168,9 @@ PASS childWindow.screen.availTop is 0
PASS childWindow.screen.availWidth is 0
PASS childWindow.screen.colorDepth is 0
PASS childWindow.screen.height is 0
PASS childWindow.screen.id is ''
PASS childWindow.screen.internal is false
PASS childWindow.screen.left is 0
PASS childWindow.screen.name is ''
PASS childWindow.screen.pixelDepth is 0
PASS childWindow.screen.primary is false
PASS childWindow.screen.scaleFactor is 0
......
......@@ -30,9 +30,9 @@ PASS screen.availTop == "LEFTOVER" is false
PASS screen.availWidth == "LEFTOVER" is false
PASS screen.colorDepth == "LEFTOVER" is false
PASS screen.height == "LEFTOVER" is false
PASS screen.id == "LEFTOVER" is false
PASS screen.internal == "LEFTOVER" is false
PASS screen.left == "LEFTOVER" is false
PASS screen.name == "LEFTOVER" is false
PASS screen.orientation == "LEFTOVER" is false
PASS screen.pixelDepth == "LEFTOVER" is false
PASS screen.primary == "LEFTOVER" is false
......
......@@ -7889,9 +7889,9 @@ interface Screen
getter availWidth
getter colorDepth
getter height
getter id
getter internal
getter left
getter name
getter orientation
getter pixelDepth
getter primary
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment