if (action
== MediaCapturePickerHeadlessFragment.CaptureAction
.CAPTURE_WINDOW) {
org.chromium.content_public.browser.WebContents tabWebContents =
impl.getPickedWebContents();
if (tabWebContents != null) {
delegate.onPickTab(
tabWebContents,
impl.getPickedAudioSharePreference());
} else {
delegate.onPickWindow();
}
} else if (actionNote: this is the only meaningful action branch for now (other than cancel action), since action is always set to `CAPTURE_WINDOW`, see comment in [the launcher's callback](https://source.chromium.org/chromium/chromium/src/+/main:chrome/android/java/src/org/chromium/chrome/browser/media/MediaCapturePickerHeadlessFragment.java;l=97?q=CaptureAction%20MediaCapture&ss=chromium). I keep the `CAPTURE_SCREEN` action branch like the current [MediaCapturePickerDialog](https://source.chromium.org/chromium/chromium/src/+/main:chrome/android/java/src/org/chromium/chrome/browser/media/MediaCapturePickerDialog.java;l=195).
Please let me know if you think there's a better way to handle this!
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
startAndroidCapturePrompt(delegate, null);```suggestion
startAndroidCapturePrompt(delegate, /* intent= */ null);
```
if (intent != null) {
mLauncher.launch(intent);
} else {
mLauncher.launch(mMediaProjectionManager.createScreenCaptureIntent());
}```suggestion
mLauncher.launch(intent != null ? intent :
mMediaProjectionManager.createScreenCaptureIntent());
```
!= MediaCapturePickerHeadlessFragment.CaptureAction
.CAPTURE_CANCELLED) {statically import.
org.chromium.content_public.browser.media.capture.ScreenCaptureimport this.
== MediaCapturePickerHeadlessFragment.CaptureAction
.CAPTURE_WINDOW) {statically import.
org.chromium.content_public.browser.WebContents tabWebContents =import this.
(action, result) -> {
if (action
!= MediaCapturePickerHeadlessFragment.CaptureAction
.CAPTURE_CANCELLED) {
org.chromium.content_public.browser.media.capture.ScreenCapture
.onPick(params.webContents, result);
}
if (action
== MediaCapturePickerHeadlessFragment.CaptureAction
.CAPTURE_WINDOW) {
org.chromium.content_public.browser.WebContents tabWebContents =
impl.getPickedWebContents();
if (tabWebContents != null) {
delegate.onPickTab(
tabWebContents,
impl.getPickedAudioSharePreference());
} else {
delegate.onPickWindow();
}
} else if (action
== MediaCapturePickerHeadlessFragment.CaptureAction
.CAPTURE_SCREEN) {
delegate.onPickScreen();
} else {
delegate.onCancel();
}Can we pull this out into a helper method as well?
if (impl != null) {
android.content.Intent intent = impl.createScreenCaptureIntent(context, params);
if (intent != null) {
var fragment = MediaCapturePickerHeadlessFragment.getInstanceForCurrentActivity();
if (fragment != null) {
fragment.startAndroidCapturePrompt(
(action, result) -> {
if (action
!= MediaCapturePickerHeadlessFragment.CaptureAction
.CAPTURE_CANCELLED) {
org.chromium.content_public.browser.media.capture.ScreenCapture
.onPick(params.webContents, result);
}
if (action
== MediaCapturePickerHeadlessFragment.CaptureAction
.CAPTURE_WINDOW) {
org.chromium.content_public.browser.WebContents tabWebContents =
impl.getPickedWebContents();
if (tabWebContents != null) {
delegate.onPickTab(
tabWebContents,
impl.getPickedAudioSharePreference());
} else {
delegate.onPickWindow();
}
} else if (action
== MediaCapturePickerHeadlessFragment.CaptureAction
.CAPTURE_SCREEN) {
delegate.onPickScreen();
} else {
delegate.onCancel();
}
},
intent);
return;
}
}
}Please invert some of the nesting so this is more readable. If you need another inner helper function to ensure `delegate.onCancel` is called in error paths please do so.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Is it possible to add tests?
Added tests for MediaCapturePickerInvoker to check that the right function is called depending on the startAndroidCapturePrompt returned action and (fake) delegate state.
I think there's not much we could test with startAndroidCapturePrompt for now. After the UI is stable, we could add an integrated test that checks for UI elements / views and perform clicks on it. WDYT?
```suggestion
startAndroidCapturePrompt(delegate, /* intent= */ null);
```
Done
if (intent != null) {
mLauncher.launch(intent);
} else {
mLauncher.launch(mMediaProjectionManager.createScreenCaptureIntent());
}```suggestion
mLauncher.launch(intent != null ? intent :
mMediaProjectionManager.createScreenCaptureIntent());
```
Done
!= MediaCapturePickerHeadlessFragment.CaptureAction
.CAPTURE_CANCELLED) {Grace Chamstatically import.
Done
org.chromium.content_public.browser.media.capture.ScreenCaptureGrace Chamimport this.
Done
== MediaCapturePickerHeadlessFragment.CaptureAction
.CAPTURE_WINDOW) {Grace Chamstatically import.
Done
org.chromium.content_public.browser.WebContents tabWebContents =Grace Chamimport this.
Done
(action, result) -> {
if (action
!= MediaCapturePickerHeadlessFragment.CaptureAction
.CAPTURE_CANCELLED) {
org.chromium.content_public.browser.media.capture.ScreenCapture
.onPick(params.webContents, result);
}
if (action
== MediaCapturePickerHeadlessFragment.CaptureAction
.CAPTURE_WINDOW) {
org.chromium.content_public.browser.WebContents tabWebContents =
impl.getPickedWebContents();
if (tabWebContents != null) {
delegate.onPickTab(
tabWebContents,
impl.getPickedAudioSharePreference());
} else {
delegate.onPickWindow();
}
} else if (action
== MediaCapturePickerHeadlessFragment.CaptureAction
.CAPTURE_SCREEN) {
delegate.onPickScreen();
} else {
delegate.onCancel();
}Can we pull this out into a helper method as well?
Done
if (impl != null) {Please invert some of the nesting so this is more readable. If you need another inner helper function to ensure `delegate.onCancel` is called in error paths please do so.
Done - please reopen if there's other suggestion for refactoring for readbility!
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |