Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 59 additions & 9 deletions rivet/platform/windows/src/row_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,44 @@ pub const ROW_FEATURES: &[RowFeature] = &[
},
];

/// Values the runtime finds in the browser's own memory by Chromium's class names and the shape of
/// the view tree, so a row needs none of them. Where a row has one, the runtime only compares it
/// with what it found. A value no instruction of the new build gave is left out of the row rather
/// than carried from the prior build, and does not stop the row: the browser view, the area below
/// the top row and the view of the pages are the layout's views named `BrowserView`,
/// `MainBackgroundRegionView` and `MultiContentsView`; the frame view's field is the one that holds
/// that same browser view; and a view's widget is the one the root of its view tree names. A
/// runtime from before this cannot read a row without them, so it refuses the row and opens its
/// held build instead of guessing.
pub const REFLECTED: &[&str] = &[
"layout.frame_browser_window_offset",
"side_panel.contents_container",
"side_panel.host_view",
"side_panel.page_area",
"toolbar.get_widget_slot",
];

/// Whether the runtime finds a value by reflection, so a row may leave it out.
pub fn is_reflected(path: &str) -> bool {
REFLECTED.contains(&field_of(path))
}

/// Leaves the field a value path names out of a row's build part.
pub fn leave_out(build: &mut Value, path: &str) {
let field = field_of(path);
let (parent, key) = match field.rsplit_once('.') {
Some((parent, key)) => (Some(parent), key),
None => (None, field),
};
let holder = match parent {
Some(parent) => at_mut(build, parent),
None => Some(build),
};
if let Some(object) = holder.and_then(Value::as_object_mut) {
object.remove(key);
}
}

/// Values the runtime does not read while another value of the row says so: then they are not
/// values of the build at all, and a row holds zero for them.
pub struct UnusedWhen {
Expand Down Expand Up @@ -303,21 +341,33 @@ mod tests {
assert_eq!(feature_of("layout.frame_ids[1]").unwrap().name, "frame colour");
assert_eq!(feature_of("omnibox.match_size").unwrap().name, "address suggestions");
// The frame and the page area layout have no switch: the window cannot do without them.
for core in [
"layout.view_bounds_offset",
"layout.frame_browser_window_offset",
"side_panel.page_area",
"side_panel.host_view",
"side_panel.contents_container",
"side_panel.toolbar",
"toolbar.get_widget_slot",
] {
for core in ["layout.view_bounds_offset", "side_panel.toolbar"] {
assert!(feature_of(core).is_none(), "{core}");
assert!(!is_reflected(core), "{core}");
}
// The window's views and widget have no switch either; the runtime finds them itself.
for reflected in REFLECTED {
assert!(feature_of(reflected).is_none(), "{reflected}");
assert!(is_reflected(reflected), "{reflected}");
}
// A value that only looks like a section's name is not in it.
assert!(feature_of("splitter.width").is_none());
}

#[test]
fn nfr6_a_reflected_value_is_left_out_of_the_row() {
let mut build = json!({
"layout": {"frame_browser_window_offset": "0x340", "view_bounds_offset": "0x1c8"},
"toolbar": {"get_widget_slot": "0xb"},
});
leave_out(&mut build, "layout.frame_browser_window_offset");
leave_out(&mut build, "toolbar.get_widget_slot");
assert_eq!(
build,
json!({"layout": {"view_bounds_offset": "0x1c8"}, "toolbar": {}})
);
}

#[test]
fn nfr6_a_value_the_runtime_does_not_read_is_not_a_value_of_the_build() {
let build = json!({
Expand Down
41 changes: 38 additions & 3 deletions rivet/platform/windows/src/row_port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ pub struct PortReport {
pub switched_off: Vec<String>,
/// Values the runtime does not read in this row, written as zero, with the reason.
pub unused: Vec<String>,
/// Values no instruction of the new build gave that the runtime finds by reflection, so the
/// row leaves them out instead of carrying them.
pub reflected: Vec<String>,
/// Whether every carried value must be settled: the milestone changed, or values were read.
#[serde(skip)]
must_check: bool,
Expand Down Expand Up @@ -1005,8 +1008,9 @@ pub fn port_row(
(row, report)
}

/// Settles each value no recipe or instruction read from the new build. A value the runtime does
/// not read in this row is written as zero. A value of a feature the runtime can do without turns
/// Settles each value no recipe or instruction read from the new build. A value the runtime finds
/// by reflection is left out of the row. A value the runtime does not read in this row is written
/// as zero. A value of a feature the runtime can do without turns
/// that feature off for this build and is cleared, so the rest of the row is not held back by it.
/// Any other value stops the row with its reason, since no feature may run on a value of another
/// build.
Expand All @@ -1021,7 +1025,13 @@ fn settle_carried(row: &mut Value, report: &mut PortReport) {
let mut left = Vec::new();
let mut off: BTreeMap<&'static str, (&'static RowFeature, Vec<String>)> = BTreeMap::new();
for path in std::mem::take(&mut report.carried) {
if let Some(why) = row_features::unused(&row["build"], &path) {
if row_features::is_reflected(&path) {
row_features::leave_out(&mut row["build"], &path);
report.unread.remove(&path);
report
.reflected
.push(format!("{path}: left out, the runtime finds it by reflection"));
} else if let Some(why) = row_features::unused(&row["build"], &path) {
row_features::clear(&mut row["build"], &path, Clear::Zero);
report.unused.push(format!("{path}: {why}"));
report.unread.remove(&path);
Expand Down Expand Up @@ -2325,6 +2335,31 @@ mod tests {
assert_eq!(build["tabs"]["tab_at"], "0x101300");
}

#[test]
fn nfr6_a_row_without_window_offsets_is_not_blocked() {
// Edge 157's row stopped on exactly these values. The runtime finds them by class name and
// the view tree, so the new row leaves them out and nothing holds it back.
let mut prior = prior_with_features();
prior["build"]["layout"] = json!({"frame_browser_window_offset": "0x3b0"});
prior["build"]["side_panel"] =
json!({"host_view": "0x38", "page_area": "0x0", "contents_container": "0xd8"});
prior["build"]["toolbar"]["get_widget_slot"] = json!("0xa");
let code = new_code();
let (row, report) = port(&prior, NEW_SYMBOLS, &code_refs(&code), "2.0.0.1");
assert_eq!(report.review, Vec::<String>::new());
assert!(report.carried.is_empty(), "{:?}", report.carried);
assert_eq!(report.reflected.len(), 5, "{:?}", report.reflected);
let build = &row["build"];
assert!(build["layout"].get("frame_browser_window_offset").is_none());
assert_eq!(build["side_panel"], json!({}));
assert!(build["toolbar"].get("get_widget_slot").is_none());
// No feature went off for them.
assert!(!report
.switched_off
.iter()
.any(|line| line.contains("side_panel.") || line.contains("get_widget_slot")));
}

#[test]
fn nfr6_a_value_the_window_cannot_do_without_still_stops_the_row() {
let mut prior = prior_with_features();
Expand Down
18 changes: 12 additions & 6 deletions rivet/runtime/windows/src/browsers/chromium/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,12 @@ pub(crate) unsafe extern "system" fn proposed_layout(
) -> *mut c_void {
let original: ProposedLayout = std::mem::transmute(page_area::original());
let result = original(this, out, params);
let host = *(this
.cast::<u8>()
.add(crate::builds::get().side_panel.host_view) as *const usize);
// The layout keeps the view it lays out in `BrowserViewLayoutViews::browser_view`, found by
// the class name of the view it holds.
let Some(host_field) = crate::chromium::window_views::host_field(this as usize) else {
return result;
};
let host = *(this.cast::<u8>().add(host_field) as *const usize);
crate::trace::trace_changed(
"layout hook",
&format!(
Expand All @@ -115,9 +118,12 @@ unsafe extern "system" fn app_proposed_layout(
let original: ProposedLayout =
std::mem::transmute(APP_ORIGINAL.load(std::sync::atomic::Ordering::Acquire));
let result = original(this, out, params);
let host = *(this
.cast::<u8>()
.add(crate::builds::get().side_panel.host_view) as *const usize);
// The layout keeps the view it lays out in `BrowserViewLayoutViews::browser_view`, found by
// the class name of the view it holds.
let Some(host_field) = crate::chromium::window_views::host_field(this as usize) else {
return result;
};
let host = *(this.cast::<u8>().add(host_field) as *const usize);
crate::trace::trace_changed(
"layout hook",
&format!(
Expand Down
4 changes: 2 additions & 2 deletions rivet/runtime/windows/src/browsers/chromium/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ pub(crate) unsafe fn on_page_area(area: &mut crate::hooks::page_area::PageArea)
let row = &crate::builds::get().side_panel;
if let (Some(toolbar), Some(contents)) = (
area.bounds(row.toolbar),
area.bounds(row.contents_container),
area.contents(),
) {
if area.rail == 0 && active_is_split(area.window) {
if let Some(page) = area.bounds(row.page_area) {
if let Some(page) = area.page() {
fill_area(&mut *contents, &*page);
}
}
Expand Down
30 changes: 15 additions & 15 deletions rivet/runtime/windows/src/builds/brave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub static BRAVE: Build = Build {
module: "chrome.dll",
version: [156, 1, 98, 62],
toolbar: Toolbar {
get_widget_slot: 11,
get_widget_slot: Some(11),
dev: DEV_BRAVE_156,
get_color: 0x06A9A890, // ?GetColor@ColorProvider@ui@@QEBAIH@Z
get_color_bytes: &[
Expand Down Expand Up @@ -236,9 +236,9 @@ pub static BRAVE: Build = Build {
coordinator_browser: None,
entry_key_size: None,
extensions_by_toggle: None,
host_view: 0x38,
page_area: 0x50,
contents_container: 0xb8,
host_view: Some(0x38),
page_area: Some(0x50),
contents_container: Some(0xb8),
vertical_tabs: 0x80,
toolbar: 0x60,
contents_outline: 0x58,
Expand Down Expand Up @@ -295,7 +295,7 @@ pub static BRAVE: Build = Build {
stack_at_top_prologue: &[0x41, 0x57, 0x41, 0x56, 0x56, 0x57],
set_opaque: 0x02322E10, // ?SetFillsBoundsOpaquely@Layer@ui@@QEAAX_N@Z
set_opaque_prologue: &[0x56, 0x48, 0x83, 0xEC, 0x20],
frame_browser_window_offset: 0x340,
frame_browser_window_offset: Some(0x340),
browser_window_in_view: 0x1F0,
caption_ink_ids: &[0x67D, 0x67E, 0x67F],
top_inset_adjust: -12,
Expand Down Expand Up @@ -380,7 +380,7 @@ pub static BRAVE_63: Build = Build {
module: "chrome.dll",
version: [156, 1, 98, 63],
toolbar: Toolbar {
get_widget_slot: 11,
get_widget_slot: Some(11),
dev: DEV_BRAVE_156,
get_color: 0x06A5CB00, // ?GetColor@ColorProvider@ui@@QEBAIH@Z
get_color_bytes: &[
Expand Down Expand Up @@ -604,9 +604,9 @@ pub static BRAVE_63: Build = Build {
coordinator_browser: None,
entry_key_size: None,
extensions_by_toggle: None,
host_view: 0x38,
page_area: 0x50,
contents_container: 0xb8,
host_view: Some(0x38),
page_area: Some(0x50),
contents_container: Some(0xb8),
vertical_tabs: 0x80,
toolbar: 0x60,
contents_outline: 0x58,
Expand Down Expand Up @@ -663,7 +663,7 @@ pub static BRAVE_63: Build = Build {
stack_at_top_prologue: &[0x41, 0x57, 0x41, 0x56, 0x56, 0x57],
set_opaque: 0x0244FE30, // ?SetFillsBoundsOpaquely@Layer@ui@@QEAAX_N@Z
set_opaque_prologue: &[0x56, 0x48, 0x83, 0xEC, 0x20],
frame_browser_window_offset: 0x340,
frame_browser_window_offset: Some(0x340),
browser_window_in_view: 0x1F0,
caption_ink_ids: &[0x67D, 0x67E, 0x67F],
top_inset_adjust: 0, // Chromium's own GetTopInset, as on Chrome
Expand Down Expand Up @@ -782,7 +782,7 @@ pub static BRAVE_157_55: Build = Build {
module: "chrome.dll",
version: [157, 1, 99, 55],
toolbar: Toolbar {
get_widget_slot: 11,
get_widget_slot: Some(11),
dev: DEV_BRAVE_157,
get_color: 0x05B6CB30, // ?GetColor@ColorProvider@ui@@QEBAIH@Z
get_color_bytes: &[
Expand Down Expand Up @@ -1006,9 +1006,9 @@ pub static BRAVE_157_55: Build = Build {
coordinator_browser: None,
entry_key_size: None,
extensions_by_toggle: None,
host_view: 0x38,
page_area: 0x50,
contents_container: 0xb8,
host_view: Some(0x38),
page_area: Some(0x50),
contents_container: Some(0xb8),
vertical_tabs: 0x80,
toolbar: 0x60,
contents_outline: 0x58,
Expand Down Expand Up @@ -1065,7 +1065,7 @@ pub static BRAVE_157_55: Build = Build {
stack_at_top_prologue: &[0x41, 0x57, 0x41, 0x56, 0x56, 0x57],
set_opaque: 0x0080EA30, // ?SetFillsBoundsOpaquely@Layer@ui@@UEAAX_N@Z
set_opaque_prologue: &[0x56, 0x48, 0x83, 0xEC, 0x20],
frame_browser_window_offset: 0x338,
frame_browser_window_offset: Some(0x338),
browser_window_in_view: 0x1F0,
caption_ink_ids: &[0x684, 0x685, 0x686],
top_inset_adjust: 0, // Chromium's own GetTopInset, as on Chrome
Expand Down
Loading
Loading