Commit e6cc2e07 authored by danakj's avatar danakj Committed by Commit Bot

Move BluetoothManualChooser methods from TestRunnerForSpecificView

On reply, run the v8 function in the frame that made the request, not
the main frame.

R=avi@chromium.org

Bug: 866140, 1069111
Change-Id: Ifcc67b8762a2b9160aea7091179c53f5c525739d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2202166Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Commit-Queue: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#768923}
parent 5175b988
......@@ -1478,9 +1478,38 @@ void TestRunnerBindings::SetBluetoothManualChooser(bool enable) {
runner_->blink_test_runner_->SetBluetoothManualChooser(enable);
}
static void GetBluetoothManualChooserEventsReply(
base::WeakPtr<TestRunnerBindings> test_runner,
RenderFrame* frame,
BoundV8Callback callback,
const std::vector<std::string>& events) {
if (!test_runner) // This guards the validity of the |frame|.
return;
v8::Isolate* isolate = blink::MainThreadIsolate();
v8::HandleScope handle_scope(isolate);
// gin::TryConvertToV8() requires a v8::Context.
v8::Local<v8::Context> context =
frame->GetWebFrame()->MainWorldScriptContext();
CHECK(!context.IsEmpty());
v8::Context::Scope context_scope(context);
v8::Local<v8::Value> arg;
bool converted = gin::TryConvertToV8(isolate, events, &arg);
CHECK(converted);
std::move(callback).Run({
arg,
});
}
void TestRunnerBindings::GetBluetoothManualChooserEvents(
v8::Local<v8::Function> callback) {
return view_runner_->GetBluetoothManualChooserEvents(callback);
return runner_->blink_test_runner_->GetBluetoothManualChooserEvents(
base::BindOnce(&GetBluetoothManualChooserEventsReply,
weak_ptr_factory_.GetWeakPtr(), frame_,
WrapV8Callback(std::move(callback))));
}
void TestRunnerBindings::SendBluetoothManualChooserEvent(
......
......@@ -257,36 +257,6 @@ void TestRunnerForSpecificView::RunJSCallbackWithBitmap(
PostV8CallbackWithArgs(std::move(callback), base::size(argv), argv);
}
void TestRunnerForSpecificView::GetBluetoothManualChooserEvents(
v8::Local<v8::Function> callback) {
return blink_test_runner()->GetBluetoothManualChooserEvents(base::BindOnce(
&TestRunnerForSpecificView::GetBluetoothManualChooserEventsCallback,
weak_factory_.GetWeakPtr(),
v8::UniquePersistent<v8::Function>(blink::MainThreadIsolate(),
callback)));
}
void TestRunnerForSpecificView::GetBluetoothManualChooserEventsCallback(
v8::UniquePersistent<v8::Function> callback,
const std::vector<std::string>& events) {
// Build the V8 context.
v8::Isolate* isolate = blink::MainThreadIsolate();
v8::HandleScope handle_scope(isolate);
v8::Local<v8::Context> context =
GetLocalMainFrame()->MainWorldScriptContext();
if (context.IsEmpty())
return;
v8::Context::Scope context_scope(context);
// Convert the argument.
v8::Local<v8::Value> arg;
if (!gin::TryConvertToV8(isolate, events, &arg))
return;
// Call the callback.
PostV8CallbackWithArgs(std::move(callback), 1, &arg);
}
void TestRunnerForSpecificView::SetPageVisibility(
const std::string& new_visibility) {
content::PageVisibilityState visibility;
......
......@@ -81,13 +81,6 @@ class TestRunnerForSpecificView {
int y,
const v8::Local<v8::Function> callback);
// Calls |callback| with a DOMString[] representing the events recorded since
// the last call to this function.
void GetBluetoothManualChooserEvents(v8::Local<v8::Function> callback);
void GetBluetoothManualChooserEventsCallback(
v8::UniquePersistent<v8::Function> callback,
const std::vector<std::string>& events);
// Switch the visibility of the page.
void SetPageVisibility(const std::string& new_visibility);
......
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