What about doing `resource.getResourceResolver().adaptTo(PageManager.class).getContainingPage(resource)` instead?

That does something broader - it will return the page for any resource within the page - so I'm not sure if that's appropriate. But it is less code :)