-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow backend to send commands to execute preamble scripts. #1122
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
#include "base/record_replay.h" | ||
#include "content/public/renderer/render_thread.h" | ||
#include "content/public/renderer/v8_value_converter.h" | ||
#include "third_party/blink/renderer/bindings/core/v8/local_window_proxy.h" | ||
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h" | ||
#include "third_party/blink/renderer/bindings/core/v8/v8_document.h" | ||
#include "third_party/blink/renderer/bindings/core/v8/v8_node.h" | ||
|
@@ -823,6 +824,10 @@ const char* gOnNewWindowScript = R""""( | |
// __RECORD_REPLAY__? | ||
window.__RECORD_REPLAY__ = window.top.__RECORD_REPLAY__; | ||
window.__RECORD_REPLAY_ARGUMENTS__ = window.top.__RECORD_REPLAY_ARGUMENTS__; | ||
|
||
for (g of window.top.__RECORD_REPLAY_GLOBALS__) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
window[g] = window.top[g]; | ||
} | ||
})() | ||
)""""; | ||
|
||
|
@@ -2350,6 +2355,46 @@ static void fromJsEndReplayCode( | |
recordreplay::ExitReplayCode(); | ||
} | ||
|
||
// Connects replay globals that must be accessible from all contexts; MUST be called | ||
// with AutoMarkReplayCode. | ||
static void ConnectPreambleGlobals(LocalFrame* frame, v8::Isolate *isolate) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you pass in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ehh, I waffled on this, due to recursion (it just looks distasteful/re-entrant to me); once we fix our context handling, I think we'll end up with a set of Conexts we can just safely iterate over, rather than this traversal. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: maybe name should be |
||
for (Frame* child = frame->Tree().FirstChild(); child != nullptr; child = child->Tree().NextSibling()) { | ||
auto* child_local_frame = DynamicTo<LocalFrame>(child); | ||
if (child_local_frame != nullptr) { | ||
v8::Local<v8::Context> frameContext = child_local_frame->WindowProxy(DOMWrapperWorld::MainWorld())->ContextIfInitialized(); | ||
if (!frameContext.IsEmpty()) { | ||
RunScript(isolate, frameContext, gOnNewWindowScript, | ||
"record-replay-OnNewWindow"); | ||
} | ||
ConnectPreambleGlobals(child_local_frame, isolate); | ||
} | ||
} | ||
} | ||
|
||
|
||
// Executes the provided script in the root context, and then propagates all registered globals | ||
// throughout all descendent contexts. | ||
static void loadPreambleScript( | ||
const v8::FunctionCallbackInfo<v8::Value>& args) { | ||
CHECK(args.Length() == 1 && args[0]->IsString() && | ||
"[RuntimeError] must be called with a string"); | ||
|
||
v8::String::Utf8Value script(args.GetIsolate(), args[0]); | ||
|
||
recordreplay::AutoMarkReplayCode amrc; | ||
|
||
LocalFrame* rootFrame = GetLocalFrameRoot(args.GetIsolate()); | ||
v8::Local<v8::Context> rootContext = rootFrame->WindowProxy(DOMWrapperWorld::MainWorld())->ContextIfInitialized(); | ||
|
||
if (!rootContext.IsEmpty()) { | ||
RunScript(args.GetIsolate(), rootContext, *script, "record-replay-preambleScript"); | ||
|
||
ConnectPreambleGlobals(rootFrame, args.GetIsolate()); | ||
} else { | ||
recordreplay::Warning("loadPreambleScript: no root context found. Skipping."); | ||
} | ||
} | ||
|
||
/** ########################################################################### | ||
* misc | ||
* ##########################################################################*/ | ||
|
@@ -2502,6 +2547,10 @@ static void InitializeRecordReplayApiObjects(v8::Isolate* isolate, LocalFrame* l | |
DefineProperty(isolate, context->Global(), "__RECORD_REPLAY_ARGUMENTS__", | ||
args); | ||
|
||
v8::Local<v8::Object> globals = v8::Object::New(isolate); | ||
DefineProperty(isolate, context->Global(), "__RECORD_REPLAY_GLOBALS__", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will reset the globals on every root-level navigation. We probably want to keep them around or re-run the preamble. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, I was also confused about this. do we need to store the scripts somewhere so we can rerun them? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Domi and I have been chatting about our context handling, which is a tad naiive to say the least; we aren't going to worry about it in this PR, but rather address it wholly in another. |
||
globals); | ||
|
||
DefineProperty(isolate, args, "REPLAY_CDT_PAUSE_OBJECT_GROUP", | ||
ToV8String(isolate, REPLAY_CDT_PAUSE_OBJECT_GROUP)); | ||
|
||
|
@@ -2570,6 +2619,8 @@ static void InitializeRecordReplayApiObjects(v8::Isolate* isolate, LocalFrame* l | |
fromJsBeginReplayCode); | ||
SetFunctionProperty(isolate, args, "endReplayCode", | ||
fromJsEndReplayCode); | ||
SetFunctionProperty(isolate, args, "loadPreambleScript", | ||
loadPreambleScript); | ||
|
||
// unsorted Replay stuff | ||
SetFunctionProperty( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is intended to be called by the preamble script, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup--the PR description shows a hypothetical usage.