Commit 05ab1c1c authored by Doug Turner's avatar Doug Turner Committed by Commit Bot

WebBluetooth - Bail early if there is a null frame.

If we find a null frame, we reject with a "Document not active"
exception.

Bug: 916656
Change-Id: If76de22eb1fd977571bb7517e6d745e3ad9077e9
Reviewed-on: https://chromium-review.googlesource.com/c/1391773
Commit-Queue: Doug Turner <dougt@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#619867}
parent 91904a4f
...@@ -177,7 +177,14 @@ ScriptPromise Bluetooth::requestDevice(ScriptState* script_state, ...@@ -177,7 +177,14 @@ ScriptPromise Bluetooth::requestDevice(ScriptState* script_state,
// If the algorithm is not allowed to show a popup, reject promise with a // If the algorithm is not allowed to show a popup, reject promise with a
// SecurityError and abort these steps. // SecurityError and abort these steps.
auto& doc = *To<Document>(context); auto& doc = *To<Document>(context);
if (!LocalFrame::HasTransientUserActivation(doc.GetFrame())) { auto* frame = doc.GetFrame();
if (!frame) {
return ScriptPromise::Reject(
script_state, V8ThrowException::CreateTypeError(
script_state->GetIsolate(), "Document not active"));
}
if (!LocalFrame::HasTransientUserActivation(frame)) {
return ScriptPromise::RejectWithDOMException( return ScriptPromise::RejectWithDOMException(
script_state, script_state,
DOMException::Create( DOMException::Create(
...@@ -186,18 +193,9 @@ ScriptPromise Bluetooth::requestDevice(ScriptState* script_state, ...@@ -186,18 +193,9 @@ ScriptPromise Bluetooth::requestDevice(ScriptState* script_state,
} }
if (!service_) { if (!service_) {
LocalFrame* frame = doc.GetFrame();
if (frame) {
// See https://bit.ly/2S0zRAS for task types. // See https://bit.ly/2S0zRAS for task types.
frame->GetInterfaceProvider().GetInterface(mojo::MakeRequest( frame->GetInterfaceProvider().GetInterface(mojo::MakeRequest(
&service_, context->GetTaskRunner(TaskType::kMiscPlatformAPI))); &service_, context->GetTaskRunner(TaskType::kMiscPlatformAPI)));
}
}
if (!service_) {
return ScriptPromise::RejectWithDOMException(
script_state,
DOMException::Create(DOMExceptionCode::kNotSupportedError));
} }
// In order to convert the arguments from service names and aliases to just // In order to convert the arguments from service names and aliases to just
...@@ -261,7 +259,14 @@ ScriptPromise Bluetooth::requestLEScan(ScriptState* script_state, ...@@ -261,7 +259,14 @@ ScriptPromise Bluetooth::requestLEScan(ScriptState* script_state,
// If the algorithm is not allowed to show a popup, reject promise with a // If the algorithm is not allowed to show a popup, reject promise with a
// SecurityError and abort these steps. // SecurityError and abort these steps.
auto& doc = *To<Document>(context); auto& doc = *To<Document>(context);
if (!LocalFrame::HasTransientUserActivation(doc.GetFrame())) { auto* frame = doc.GetFrame();
if (!frame) {
return ScriptPromise::Reject(
script_state, V8ThrowException::CreateTypeError(
script_state->GetIsolate(), "Document not active"));
}
if (!LocalFrame::HasTransientUserActivation(frame)) {
return ScriptPromise::RejectWithDOMException( return ScriptPromise::RejectWithDOMException(
script_state, script_state,
DOMException::Create( DOMException::Create(
...@@ -270,16 +275,9 @@ ScriptPromise Bluetooth::requestLEScan(ScriptState* script_state, ...@@ -270,16 +275,9 @@ ScriptPromise Bluetooth::requestLEScan(ScriptState* script_state,
} }
if (!service_) { if (!service_) {
LocalFrame* frame = doc.GetFrame(); // See https://bit.ly/2S0zRAS for task types.
if (frame) { frame->GetInterfaceProvider().GetInterface(mojo::MakeRequest(
frame->GetInterfaceProvider().GetInterface(mojo::MakeRequest(&service_)); &service_, context->GetTaskRunner(TaskType::kMiscPlatformAPI)));
}
}
if (!service_) {
return ScriptPromise::RejectWithDOMException(
script_state,
DOMException::Create(DOMExceptionCode::kNotSupportedError));
} }
// TODO(dougt) deal with |options| here. // TODO(dougt) deal with |options| here.
......
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