Commit afda6dd7 authored by Staphany Park's avatar Staphany Park Committed by Commit Bot

Screen Enumeration: Basic implementation.

This CL exposes a subset of the screen properties outlined in the Screen
Enumeration API explainer:
https://github.com/spark008/screen-enumeration/blob/master/EXPLAINER.md.
The API is gated behind the experimental flag "ScreenEnumeration".

Bug: 994889
Change-Id: I3cd52f0bbfd4df11cd999bf1d21059bf298109f2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1759890Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Commit-Queue: Staphany Park <staphany@chromium.org>
Cr-Commit-Position: refs/heads/master@{#692420}
parent c9f4757c
...@@ -1639,6 +1639,8 @@ jumbo_source_set("browser") { ...@@ -1639,6 +1639,8 @@ jumbo_source_set("browser") {
"scheduler/scoped_do_not_use_ui_default_queue_from_io.h", "scheduler/scoped_do_not_use_ui_default_queue_from_io.h",
"scoped_active_url.cc", "scoped_active_url.cc",
"scoped_active_url.h", "scoped_active_url.h",
"screen_enumeration/screen_enumeration_impl.cc",
"screen_enumeration/screen_enumeration_impl.h",
"screen_orientation/screen_orientation_provider.cc", "screen_orientation/screen_orientation_provider.cc",
"screen_orientation/screen_orientation_provider.h", "screen_orientation/screen_orientation_provider.h",
"screenlock_monitor/screenlock_monitor.cc", "screenlock_monitor/screenlock_monitor.cc",
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "content/browser/background_fetch/background_fetch_service_impl.h" #include "content/browser/background_fetch/background_fetch_service_impl.h"
#include "content/browser/frame_host/render_frame_host_impl.h" #include "content/browser/frame_host/render_frame_host_impl.h"
#include "content/browser/renderer_host/render_process_host_impl.h" #include "content/browser/renderer_host/render_process_host_impl.h"
#include "content/browser/screen_enumeration/screen_enumeration_impl.h"
#include "content/browser/service_worker/service_worker_provider_host.h" #include "content/browser/service_worker/service_worker_provider_host.h"
#include "content/browser/worker_host/dedicated_worker_host.h" #include "content/browser/worker_host/dedicated_worker_host.h"
#include "content/browser/worker_host/shared_worker_host.h" #include "content/browser/worker_host/shared_worker_host.h"
...@@ -31,6 +32,9 @@ void PopulateFrameBinders(RenderFrameHostImpl* host, ...@@ -31,6 +32,9 @@ void PopulateFrameBinders(RenderFrameHostImpl* host,
map->Add<blink::mojom::IdleManager>(base::BindRepeating( map->Add<blink::mojom::IdleManager>(base::BindRepeating(
&RenderFrameHostImpl::GetIdleManager, base::Unretained(host))); &RenderFrameHostImpl::GetIdleManager, base::Unretained(host)));
map->Add<blink::mojom::ScreenEnumeration>(
base::BindRepeating(&ScreenEnumerationImpl::Create));
} }
void PopulateBinderMapWithContext( void PopulateBinderMapWithContext(
...@@ -63,6 +67,8 @@ void PopulateDedicatedWorkerBinders(DedicatedWorkerHost* host, ...@@ -63,6 +67,8 @@ void PopulateDedicatedWorkerBinders(DedicatedWorkerHost* host,
&DedicatedWorkerHost::BindFileSystemManager, base::Unretained(host))); &DedicatedWorkerHost::BindFileSystemManager, base::Unretained(host)));
map->Add<blink::mojom::IdleManager>(base::BindRepeating( map->Add<blink::mojom::IdleManager>(base::BindRepeating(
&DedicatedWorkerHost::CreateIdleManager, base::Unretained(host))); &DedicatedWorkerHost::CreateIdleManager, base::Unretained(host)));
map->Add<blink::mojom::ScreenEnumeration>(
base::BindRepeating(&ScreenEnumerationImpl::Create));
} }
void PopulateBinderMapWithContext( void PopulateBinderMapWithContext(
...@@ -86,6 +92,8 @@ void PopulateSharedWorkerBinders(SharedWorkerHost* host, ...@@ -86,6 +92,8 @@ void PopulateSharedWorkerBinders(SharedWorkerHost* host,
// |SharedWorkerHost::broker_|. // |SharedWorkerHost::broker_|.
map->Add<blink::mojom::AppCacheBackend>(base::BindRepeating( map->Add<blink::mojom::AppCacheBackend>(base::BindRepeating(
&SharedWorkerHost::CreateAppCacheBackend, base::Unretained(host))); &SharedWorkerHost::CreateAppCacheBackend, base::Unretained(host)));
map->Add<blink::mojom::ScreenEnumeration>(
base::BindRepeating(&ScreenEnumerationImpl::Create));
} }
void PopulateBinderMapWithContext( void PopulateBinderMapWithContext(
...@@ -114,6 +122,8 @@ ServiceWorkerRunningInfo GetContextForHost(ServiceWorkerProviderHost* host) { ...@@ -114,6 +122,8 @@ ServiceWorkerRunningInfo GetContextForHost(ServiceWorkerProviderHost* host) {
void PopulateServiceWorkerBinders(ServiceWorkerProviderHost* host, void PopulateServiceWorkerBinders(ServiceWorkerProviderHost* host,
service_manager::BinderMap* map) { service_manager::BinderMap* map) {
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId()); DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
map->Add<blink::mojom::ScreenEnumeration>(
base::BindRepeating(&ScreenEnumerationImpl::Create));
} }
void PopulateBinderMapWithContext( void PopulateBinderMapWithContext(
......
msw@chromium.org
staphany@chromium.org
# TEAM: storage-dev@chromium.org
# COMPONENT: Blink>Storage
\ No newline at end of file
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/screen_enumeration/screen_enumeration_impl.h"
#include <memory>
#include "content/public/browser/render_frame_host.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "url/origin.h"
namespace content {
// static
void ScreenEnumerationImpl::Create(
mojo::PendingReceiver<blink::mojom::ScreenEnumeration> receiver) {
mojo::MakeSelfOwnedReceiver(std::make_unique<ScreenEnumerationImpl>(),
std::move(receiver));
}
ScreenEnumerationImpl::ScreenEnumerationImpl() = default;
ScreenEnumerationImpl::~ScreenEnumerationImpl() = default;
void ScreenEnumerationImpl::RequestDisplays(RequestDisplaysCallback callback) {
display::Screen* screen = display::Screen::GetScreen();
std::vector<display::Display> displays = screen->GetAllDisplays();
int64_t primary_id = screen->GetPrimaryDisplay().id();
std::vector<blink::mojom::DisplayPtr> result;
for (const display::Display& display : displays) {
const gfx::Rect& bounds = display.bounds();
auto mojo_display = blink::mojom::Display::New();
// TODO(staphany): Get actual display name instead of hardcoded value.
mojo_display->name = "Generic Display";
mojo_display->scale_factor = display.device_scale_factor();
mojo_display->width = bounds.width();
mojo_display->height = bounds.height();
mojo_display->left = bounds.x();
mojo_display->top = bounds.y();
mojo_display->color_depth = display.color_depth();
mojo_display->is_primary = (display.id() == primary_id);
mojo_display->is_internal = display.IsInternal();
result.emplace_back(std::move(mojo_display));
}
// TODO(staphany): Add a permission prompt, and return empty |result| and
// |false| if the permission check fails.
std::move(callback).Run(std::move(result), true);
}
} // namespace content
\ No newline at end of file
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_SCREEN_ENUMERATION_SCREEN_ENUMERATION_IMPL_H_
#define CONTENT_BROWSER_SCREEN_ENUMERATION_SCREEN_ENUMERATION_IMPL_H_
#include "third_party/blink/public/mojom/screen_enumeration/screen_enumeration.mojom.h"
namespace content {
class ScreenEnumerationImpl : public blink::mojom::ScreenEnumeration {
public:
static void Create(
mojo::PendingReceiver<blink::mojom::ScreenEnumeration> receiver);
ScreenEnumerationImpl();
~ScreenEnumerationImpl() override;
ScreenEnumerationImpl(const ScreenEnumerationImpl&) = delete;
ScreenEnumerationImpl& operator=(const ScreenEnumerationImpl&) = delete;
// blink::mojom::ScreenEnumeration:
void RequestDisplays(RequestDisplaysCallback callback) override;
};
} // namespace content
#endif // CONTENT_BROWSER_SCREEN_ENUMERATION_SCREEN_ENUMERATION_IMPL_H_
\ No newline at end of file
...@@ -103,6 +103,7 @@ mojom("mojom_platform") { ...@@ -103,6 +103,7 @@ mojom("mojom_platform") {
"renderer_preference_watcher.mojom", "renderer_preference_watcher.mojom",
"renderer_preferences.mojom", "renderer_preferences.mojom",
"reporting/reporting.mojom", "reporting/reporting.mojom",
"screen_enumeration/screen_enumeration.mojom",
"script/script_type.mojom", "script/script_type.mojom",
"selection_menu/selection_menu_behavior.mojom", "selection_menu/selection_menu_behavior.mojom",
"service_worker/controller_service_worker_mode.mojom", "service_worker/controller_service_worker_mode.mojom",
......
file://content/browser/screen_enumeration/OWNERS
per-file *.mojom=set noparent
per-file *.mojom=file://ipc/SECURITY_OWNERS
# TEAM: storage-dev@chromium.org
# COMPONENT: Blink>Storage
\ No newline at end of file
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module blink.mojom;
// A physical or virtual unit of rendering space connected to the device.
//
// Display structures typically correspond 1:1 with internal laptop/phone/tablet
// screens and externally-connected monitors.
//
// Properties are populated from the corresponding display::Display object and
// Web-exposed through the Display object in the Screen Enumeration API. The
// following properties should be equivalent to those in the Screen interface:
// width, height, colorDepth.
struct Display {
// A human-readable name for the display.
string name;
// The number of hardware pixels per CSS pixel.
float scale_factor;
// The full width of the display, in CSS pixels.
int32 width;
// The full height of the display, in CSS pixels.
int32 height;
// The x-coordinate of the display's left edge in the screen's coordinate
// system (top-left corner of the primary display is the origin).
int32 left;
// The y-coordinate of the display's top edge in the screen's coordinate
// system (top-left corner of the primary display is the origin).
int32 top;
// The number of bits allocated to pixel color.
int32 color_depth;
// Whether the display is the primary display.
bool is_primary;
// Whether the display is internal (built-in) or external.
bool is_internal;
};
// This interface is implemented by the browser process to pass screen data to
// window and worker processes.
interface ScreenEnumeration {
// If success is false, |displays| is meaningless. Otherwise, |displays| is
// the list of all the device's Displays.
RequestDisplays() => (array<Display> displays, bool success);
};
...@@ -148,6 +148,7 @@ target("jumbo_" + modules_target_type, "modules") { ...@@ -148,6 +148,7 @@ target("jumbo_" + modules_target_type, "modules") {
"//third_party/blink/renderer/modules/quota", "//third_party/blink/renderer/modules/quota",
"//third_party/blink/renderer/modules/remoteplayback", "//third_party/blink/renderer/modules/remoteplayback",
"//third_party/blink/renderer/modules/scheduler", "//third_party/blink/renderer/modules/scheduler",
"//third_party/blink/renderer/modules/screen_enumeration",
"//third_party/blink/renderer/modules/screen_orientation", "//third_party/blink/renderer/modules/screen_orientation",
"//third_party/blink/renderer/modules/sensor", "//third_party/blink/renderer/modules/sensor",
"//third_party/blink/renderer/modules/service_worker", "//third_party/blink/renderer/modules/service_worker",
......
...@@ -299,6 +299,7 @@ modules_idl_files = ...@@ -299,6 +299,7 @@ modules_idl_files =
"scheduler/scheduler.idl", "scheduler/scheduler.idl",
"scheduler/task.idl", "scheduler/task.idl",
"scheduler/task_queue.idl", "scheduler/task_queue.idl",
"screen_enumeration/screen_manager.idl",
"screen_orientation/screen_orientation.idl", "screen_orientation/screen_orientation.idl",
"sensor/absolute_orientation_sensor.idl", "sensor/absolute_orientation_sensor.idl",
"sensor/accelerometer.idl", "sensor/accelerometer.idl",
...@@ -776,6 +777,7 @@ modules_dictionary_idl_files = ...@@ -776,6 +777,7 @@ modules_dictionary_idl_files =
"quota/storage_usage_details.idl", "quota/storage_usage_details.idl",
"scheduler/scheduler_post_task_options.idl", "scheduler/scheduler_post_task_options.idl",
"scheduler/task_queue_post_task_options.idl", "scheduler/task_queue_post_task_options.idl",
"screen_enumeration/display.idl",
"sensor/sensor_error_event_init.idl", "sensor/sensor_error_event_init.idl",
"sensor/sensor_options.idl", "sensor/sensor_options.idl",
"sensor/spatial_sensor_options.idl", "sensor/spatial_sensor_options.idl",
...@@ -991,6 +993,8 @@ modules_dependency_idl_files = ...@@ -991,6 +993,8 @@ modules_dependency_idl_files =
"quota/worker_navigator_storage_quota.idl", "quota/worker_navigator_storage_quota.idl",
"remoteplayback/html_media_element_remote_playback.idl", "remoteplayback/html_media_element_remote_playback.idl",
"scheduler/window_scheduler.idl", "scheduler/window_scheduler.idl",
"screen_enumeration/navigator_screen_manager.idl",
"screen_enumeration/worker_navigator_screen_manager.idl",
"screen_orientation/screen_screen_orientation.idl", "screen_orientation/screen_screen_orientation.idl",
"service_worker/navigator_service_worker.idl", "service_worker/navigator_service_worker.idl",
"sms/navigator_sms.idl", "sms/navigator_sms.idl",
......
# Copyright 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//third_party/blink/renderer/modules/modules.gni")
blink_modules_sources("screen_enumeration") {
sources = [
"navigator_screen_manager.cc",
"navigator_screen_manager.h",
"screen_manager.cc",
"screen_manager.h",
]
deps = [
"//third_party/blink/renderer/platform",
]
}
file://content/browser/screen_enumeration/OWNERS
# TEAM: storage-dev@chromium.org
# COMPONENT: Blink>Storage
\ No newline at end of file
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// https://github.com/spark008/screen-enumeration/blob/master/EXPLAINER.md
// TODO(staphany): Add working-area versions of width, height, left, and top
// (e.g. like availWidth in the Screen interface).
// TODO(staphany): Add orientation.
dictionary Display {
required DOMString name;
required float scaleFactor;
required long width;
required long height;
required long left;
required long top;
required long colorDepth;
required boolean isPrimary;
required boolean isInternal;
};
\ No newline at end of file
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/modules/screen_enumeration/navigator_screen_manager.h"
#include "services/service_manager/public/cpp/interface_provider.h"
#include "third_party/blink/public/common/browser_interface_broker_proxy.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/navigator.h"
#include "third_party/blink/renderer/core/workers/worker_navigator.h"
#include "third_party/blink/renderer/modules/screen_enumeration/screen_manager.h"
#include "third_party/blink/renderer/platform/supplementable.h"
namespace blink {
namespace {
template <typename T>
class NavigatorScreenManagerImpl final
: public GarbageCollectedFinalized<NavigatorScreenManagerImpl<T>>,
public Supplement<T> {
USING_GARBAGE_COLLECTED_MIXIN(NavigatorScreenManagerImpl<T>);
public:
static const char kSupplementName[];
static NavigatorScreenManagerImpl<T>& From(T& supplementable) {
NavigatorScreenManagerImpl<T>* supplement =
Supplement<T>::template From<NavigatorScreenManagerImpl<T>>(
supplementable);
if (!supplement) {
supplement =
MakeGarbageCollected<NavigatorScreenManagerImpl<T>>(supplementable);
Supplement<T>::ProvideTo(supplementable, supplement);
}
return *supplement;
}
explicit NavigatorScreenManagerImpl(T& supplementable)
: Supplement<T>(supplementable) {}
NavigatorScreenManagerImpl(const NavigatorScreenManagerImpl&) = delete;
NavigatorScreenManagerImpl& operator=(const NavigatorScreenManagerImpl&) =
delete;
ScreenManager* GetScreen(ExecutionContext* execution_context) {
if (!screen_manager_) {
auto* browser_interface_broker_proxy =
execution_context->GetBrowserInterfaceBrokerProxy();
if (!browser_interface_broker_proxy)
return nullptr;
mojo::Remote<mojom::blink::ScreenEnumeration> backend;
browser_interface_broker_proxy->GetInterface(
backend.BindNewPipeAndPassReceiver());
screen_manager_ = MakeGarbageCollected<ScreenManager>(std::move(backend));
}
return screen_manager_;
}
void Trace(blink::Visitor* visitor) override {
visitor->Trace(screen_manager_);
Supplement<T>::Trace(visitor);
}
private:
Member<ScreenManager> screen_manager_;
};
// static
template <typename T>
const char NavigatorScreenManagerImpl<T>::kSupplementName[] =
"NavigatorScreenManager";
} // namespace
// static
ScreenManager* NavigatorScreenManager::screen(Navigator& navigator) {
LocalFrame* local_frame = navigator.GetFrame();
if (!local_frame) {
return nullptr;
}
ExecutionContext* execution_context =
local_frame->DomWindow()->GetExecutionContext();
return NavigatorScreenManagerImpl<Navigator>::From(navigator).GetScreen(
execution_context);
}
// static
ScreenManager* NavigatorScreenManager::screen(ScriptState* script_state,
WorkerNavigator& navigator) {
return NavigatorScreenManagerImpl<WorkerNavigator>::From(navigator).GetScreen(
ExecutionContext::From(script_state));
}
} // namespace blink
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_SCREEN_ENUMERATION_NAVIGATOR_SCREEN_MANAGER_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_SCREEN_ENUMERATION_NAVIGATOR_SCREEN_MANAGER_H_
#include "third_party/blink/renderer/modules/modules_export.h"
namespace blink {
class Navigator;
class ScreenManager;
class ScriptState;
class WorkerNavigator;
// Exposes the ScreenManager interface on both the Navigator and
// WorkerNavigator interfaces.
class MODULES_EXPORT NavigatorScreenManager {
public:
// The ScreenManager exposed in the Navigator execution context.
static ScreenManager* screen(Navigator&);
// The ScreenManager exposed in the WorkerNavigator execution context.
static ScreenManager* screen(ScriptState*, WorkerNavigator&);
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_SCREEN_ENUMERATION_NAVIGATOR_SCREEN_MANAGER_H_
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// https://github.com/spark008/screen-enumeration/blob/master/EXPLAINER.md
[
ImplementedAs=NavigatorScreenManager,
SecureContext,
RuntimeEnabled=ScreenEnumeration
] partial interface Navigator {
[SameObject] readonly attribute ScreenManager screen;
};
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/modules/screen_enumeration/screen_manager.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/modules/screen_enumeration/display.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"
#include "third_party/blink/renderer/platform/bindings/v8_throw_exception.h"
#include "third_party/blink/renderer/platform/heap/heap.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
namespace blink {
namespace {
void DidReceiveDisplays(ScriptPromiseResolver* resolver,
WTF::Vector<mojom::blink::DisplayPtr> backend_displays,
bool success) {
ScriptState* script_state = resolver->GetScriptState();
if (!script_state->ContextIsValid())
return;
HeapVector<Member<Display>> displays;
displays.ReserveInitialCapacity(backend_displays.size());
for (const auto& backend_display : backend_displays) {
auto* display = MakeGarbageCollected<Display>();
display->setName(backend_display->name);
display->setScaleFactor(backend_display->scale_factor);
display->setWidth(backend_display->width);
display->setHeight(backend_display->height);
display->setLeft(backend_display->left);
display->setTop(backend_display->top);
display->setColorDepth(backend_display->color_depth);
display->setIsPrimary(backend_display->is_primary);
display->setIsInternal(backend_display->is_internal);
displays.emplace_back(display);
}
resolver->Resolve(std::move(displays));
}
} // namespace
ScreenManager::ScreenManager(
mojo::Remote<mojom::blink::ScreenEnumeration> backend)
: backend_(std::move(backend)) {
backend_.set_disconnect_handler(WTF::Bind(
&ScreenManager::OnBackendDisconnected, WrapWeakPersistent(this)));
}
ScriptPromise ScreenManager::requestDisplays(ScriptState* script_state,
ExceptionState& exception_state) {
if (!backend_) {
exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError,
"ScreenManager backend went away");
return ScriptPromise();
}
auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state);
backend_->RequestDisplays(
WTF::Bind(&DidReceiveDisplays, WrapPersistent(resolver)));
return resolver->Promise();
}
void ScreenManager::OnBackendDisconnected() {
backend_.reset();
}
} // namespace blink
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_SCREEN_ENUMERATION_SCREEN_MANAGER_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_SCREEN_ENUMERATION_SCREEN_MANAGER_H_
#include "mojo/public/cpp/bindings/remote.h"
#include "third_party/blink/public/mojom/screen_enumeration/screen_enumeration.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
namespace blink {
class ScriptState;
// An interface for querying the state of the device's screen space.
//
// The interface is available in both window and service worker execution
// contexts.
class ScreenManager final : public ScriptWrappable {
DEFINE_WRAPPERTYPEINFO();
public:
// Creates a ScreenManager and binds it to the browser-side implementation.
explicit ScreenManager(mojo::Remote<mojom::blink::ScreenEnumeration> backend);
// Resolves to the list of |Display| objects in the device's screen space.
ScriptPromise requestDisplays(ScriptState*, ExceptionState&);
// Called if the backend is disconnected, e.g. during renderer shutdown.
void OnBackendDisconnected();
private:
// Connection to the ScreenEnumeration implementation in the browser process.
mojo::Remote<mojom::blink::ScreenEnumeration> backend_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_SCREEN_ENUMERATION_SCREEN_MANAGER_H_
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// https://github.com/spark008/screen-enumeration/blob/master/EXPLAINER.md
[
SecureContext,
Exposed=(Window,Worker),
RuntimeEnabled=ScreenEnumeration
] interface ScreenManager {
[CallWith=ScriptState, RaisesException] Promise<sequence<Display>> requestDisplays();
};
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// https://github.com/spark008/screen-enumeration/blob/master/EXPLAINER.md
[
ImplementedAs=NavigatorScreenManager,
SecureContext,
RuntimeEnabled=ScreenEnumeration
] partial interface WorkerNavigator {
[CallWith=ScriptState, SameObject] readonly attribute ScreenManager screen;
};
...@@ -1420,6 +1420,12 @@ ...@@ -1420,6 +1420,12 @@
name: "SameSiteByDefaultCookies", name: "SameSiteByDefaultCookies",
status: "experimental", status: "experimental",
}, },
// Exposes the displays connected to the device and provides the display
// properties needed for window placement features.
{
name: "ScreenEnumeration",
status: "experimental",
},
// WebSpeech API with both speech recognition and synthesis functionality // WebSpeech API with both speech recognition and synthesis functionality
// is not fully enabled on all platforms. // is not fully enabled on all platforms.
{ {
......
// META: global=window,dedicatedworker,sharedworker,serviceworker
'use strict';
promise_test(async testCase => {
assert_class_string(navigator.screen, 'ScreenManager');
assert_equals(typeof navigator.screen.requestDisplays, 'function');
}, 'navigator.screen.requestDisplays is present');
promise_test(async testCase => {
const displays = await navigator.screen.requestDisplays();
assert_greater_than(displays.length, 0);
assert_equals(typeof displays[0].name, 'string');
assert_equals(typeof displays[0].scaleFactor, 'number');
assert_equals(typeof displays[0].width, 'number');
assert_equals(typeof displays[0].height, 'number');
assert_equals(typeof displays[0].left, 'number');
assert_equals(typeof displays[0].top, 'number');
assert_equals(typeof displays[0].colorDepth, 'number');
assert_equals(typeof displays[0].isPrimary, 'boolean');
assert_equals(typeof displays[0].isInternal, 'boolean');
}, 'navigator.screen.requestDisplays returns at least 1 Display');
\ No newline at end of file
...@@ -1232,6 +1232,10 @@ interface Response ...@@ -1232,6 +1232,10 @@ interface Response
method formData method formData
method json method json
method text method text
interface ScreenManager
attribute @@toStringTag
method constructor
method requestDisplays
interface SecurityPolicyViolationEvent : Event interface SecurityPolicyViolationEvent : Event
attribute @@toStringTag attribute @@toStringTag
getter blockedURI getter blockedURI
...@@ -3688,6 +3692,7 @@ interface WorkerNavigator ...@@ -3688,6 +3692,7 @@ interface WorkerNavigator
getter permissions getter permissions
getter platform getter platform
getter product getter product
getter screen
getter serial getter serial
getter storage getter storage
getter usb getter usb
......
...@@ -1175,6 +1175,10 @@ Starting worker: resources/global-interface-listing-worker.js ...@@ -1175,6 +1175,10 @@ Starting worker: resources/global-interface-listing-worker.js
[Worker] attribute @@toStringTag [Worker] attribute @@toStringTag
[Worker] getter content [Worker] getter content
[Worker] method constructor [Worker] method constructor
[Worker] interface ScreenManager
[Worker] attribute @@toStringTag
[Worker] method constructor
[Worker] method requestDisplays
[Worker] interface SecurityPolicyViolationEvent : Event [Worker] interface SecurityPolicyViolationEvent : Event
[Worker] attribute @@toStringTag [Worker] attribute @@toStringTag
[Worker] getter blockedURI [Worker] getter blockedURI
...@@ -3742,6 +3746,7 @@ Starting worker: resources/global-interface-listing-worker.js ...@@ -3742,6 +3746,7 @@ Starting worker: resources/global-interface-listing-worker.js
[Worker] getter permissions [Worker] getter permissions
[Worker] getter platform [Worker] getter platform
[Worker] getter product [Worker] getter product
[Worker] getter screen
[Worker] getter serial [Worker] getter serial
[Worker] getter storage [Worker] getter storage
[Worker] getter usb [Worker] getter usb
......
...@@ -5114,6 +5114,7 @@ interface Navigator ...@@ -5114,6 +5114,7 @@ interface Navigator
getter product getter product
getter productSub getter productSub
getter scheduling getter scheduling
getter screen
getter serial getter serial
getter serviceWorker getter serviceWorker
getter sms getter sms
...@@ -7457,6 +7458,10 @@ interface Screen ...@@ -7457,6 +7458,10 @@ interface Screen
getter pixelDepth getter pixelDepth
getter width getter width
method constructor method constructor
interface ScreenManager
attribute @@toStringTag
method constructor
method requestDisplays
interface ScreenOrientation : EventTarget interface ScreenOrientation : EventTarget
attribute @@toStringTag attribute @@toStringTag
getter angle getter angle
......
...@@ -1153,6 +1153,10 @@ Starting worker: resources/global-interface-listing-worker.js ...@@ -1153,6 +1153,10 @@ Starting worker: resources/global-interface-listing-worker.js
[Worker] method formData [Worker] method formData
[Worker] method json [Worker] method json
[Worker] method text [Worker] method text
[Worker] interface ScreenManager
[Worker] attribute @@toStringTag
[Worker] method constructor
[Worker] method requestDisplays
[Worker] interface SecurityPolicyViolationEvent : Event [Worker] interface SecurityPolicyViolationEvent : Event
[Worker] attribute @@toStringTag [Worker] attribute @@toStringTag
[Worker] getter blockedURI [Worker] getter blockedURI
...@@ -3591,6 +3595,7 @@ Starting worker: resources/global-interface-listing-worker.js ...@@ -3591,6 +3595,7 @@ Starting worker: resources/global-interface-listing-worker.js
[Worker] getter permissions [Worker] getter permissions
[Worker] getter platform [Worker] getter platform
[Worker] getter product [Worker] getter product
[Worker] getter screen
[Worker] getter serial [Worker] getter serial
[Worker] getter storage [Worker] getter storage
[Worker] getter usb [Worker] getter usb
......
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