Skip to content

Commit c196eab

Browse files
authored
Bug 2005405 - add isPrivate to send-tab (#7133)
1 parent 0d78003 commit c196eab

6 files changed

Lines changed: 47 additions & 10 deletions

File tree

components/fxa-client/android/src/main/java/mozilla/appservices/fxaclient/FxaClient.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,10 +526,12 @@ class FxaClient(inner: FirefoxAccount, persistCallback: PersistCallback?) : Auto
526526
* @param targetDeviceId The target Device ID
527527
* @param title The document title of the tab being sent
528528
* @param url The url of the tab being sent
529+
* @param isPrivate Whether the tab is open as a private tab. Has a default value to help with progressive
530+
* implementation of this new attribute, but the default should be removed at some point.
529531
*/
530-
fun sendSingleTab(targetDeviceId: String, title: String, url: String) {
532+
fun sendSingleTab(targetDeviceId: String, title: String, url: String, isPrivate: Boolean = false) {
531533
withMetrics {
532-
this.inner.sendSingleTab(targetDeviceId, title, url)
534+
this.inner.sendSingleTab(targetDeviceId, title, url, isPrivate)
533535
}
534536
}
535537

components/fxa-client/src/fxa_client.udl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ interface FirefoxAccount {
552552
/// granted the `https:///identity.mozilla.com/apps/oldsync` scope.
553553
///
554554
[Throws=FxaError]
555-
void send_single_tab([ByRef] string target_device_id, [ByRef] string title, [ByRef] string url );
555+
void send_single_tab([ByRef] string target_device_id, [ByRef] string title, [ByRef] string url, optional boolean is_private = false );
556556

557557

558558
/// Use device commands to close one or more tabs on another device.
@@ -930,11 +930,14 @@ dictionary CloseTabsPayload {
930930
sequence<string> urls;
931931
};
932932

933-
/// An individual entry in the navigation history of a sent tab.
933+
/// A received tab. Mis-named as the original intent was to keep
934+
/// the full "back" history for a tab, where this would be one such
935+
/// entry - but that never happened.
934936
///
935937
dictionary TabHistoryEntry {
936938
string title;
937939
string url;
940+
boolean is_private;
938941
};
939942

940943
/// A client connected to the user's account.

components/fxa-client/src/internal/commands/send_tab.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@ impl From<SendTabPayload> for crate::SendTabPayload {
3838
}
3939

4040
impl SendTabPayload {
41-
pub fn single_tab(title: &str, url: &str) -> (Self, telemetry::SentCommand) {
41+
pub fn single_tab(title: &str, url: &str, private: bool) -> (Self, telemetry::SentCommand) {
4242
let sent_telemetry: telemetry::SentCommand = telemetry::SentCommand::for_send_tab();
4343
(
4444
SendTabPayload {
4545
entries: vec![TabHistoryEntry {
4646
title: title.to_string(),
4747
url: url.to_string(),
48+
private,
4849
}],
4950
flow_id: sent_telemetry.flow_id.clone(),
5051
stream_id: sent_telemetry.stream_id.clone(),
@@ -58,13 +59,16 @@ impl SendTabPayload {
5859
pub struct TabHistoryEntry {
5960
pub title: String,
6061
pub url: String,
62+
#[serde(default)]
63+
pub private: bool,
6164
}
6265

6366
impl From<TabHistoryEntry> for crate::TabHistoryEntry {
6467
fn from(e: TabHistoryEntry) -> Self {
6568
crate::TabHistoryEntry {
6669
title: e.title,
6770
url: e.url,
71+
is_private: e.private,
6872
}
6973
}
7074
}
@@ -82,15 +86,35 @@ mod tests {
8286

8387
#[test]
8488
fn test_payload() {
85-
let (payload, telem) = SendTabPayload::single_tab("title", "http://example.com");
89+
let (payload, telem) = SendTabPayload::single_tab("title", "http://example.com", true);
8690
let json = serde_json::to_string(&payload).expect("should work");
8791
assert_eq!(telem.flow_id.len(), 12);
8892
assert_eq!(telem.stream_id.len(), 12);
8993
assert_ne!(telem.flow_id, telem.stream_id);
9094
let p2: SendTabPayload = serde_json::from_str(&json).expect("should work");
9195
// no 'PartialEq' derived so check each field individually...
9296
assert_eq!(payload.entries[0].url, "http://example.com".to_string());
97+
assert!(payload.entries[0].private);
9398
assert_eq!(payload.flow_id, p2.flow_id);
9499
assert_eq!(payload.stream_id, p2.stream_id);
95100
}
101+
102+
#[test]
103+
fn test_raw_payload() {
104+
let json = r#"{"title": "new title", "url": "https://example99.com", "private": true}"#;
105+
let p: TabHistoryEntry = serde_json::from_str(json).expect("should work");
106+
assert_eq!(p.title, "new title");
107+
assert_eq!(p.url, "https://example99.com");
108+
assert!(p.private);
109+
}
110+
111+
#[test]
112+
fn test_raw_payload_without_private() {
113+
// no "private" field
114+
let json = r#"{"title": "the title", "url": "https://example.com"}"#;
115+
let p: TabHistoryEntry = serde_json::from_str(json).expect("should work");
116+
assert_eq!(p.title, "the title");
117+
assert_eq!(p.url, "https://example.com");
118+
assert!(!p.private);
119+
}
96120
}

components/fxa-client/src/internal/send_tab.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,14 @@ impl FirefoxAccount {
4343
target_device_id: &str,
4444
title: &str,
4545
url: &str,
46+
private: bool,
4647
) -> Result<()> {
4748
let devices = self.get_devices(false)?;
4849
let target = devices
4950
.iter()
5051
.find(|d| d.id == target_device_id)
5152
.ok_or_else(|| Error::UnknownTargetDevice(target_device_id.to_owned()))?;
52-
let (payload, sent_telemetry) = SendTabPayload::single_tab(title, url);
53+
let (payload, sent_telemetry) = SendTabPayload::single_tab(title, url, private);
5354
let oldsync_key = self.get_scoped_key(scopes::OLD_SYNC)?;
5455
let command_payload =
5556
encrypt_command(oldsync_key, target, send_tab::COMMAND_NAME, &payload)?;

components/fxa-client/src/push.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,16 @@ impl FirefoxAccount {
9595
/// - Device commands functionality is only available to applications that have been
9696
/// granted the `https://identity.mozilla.com/apps/oldsync` scope.
9797
#[handle_error(Error)]
98-
pub fn send_single_tab(&self, target_device_id: &str, title: &str, url: &str) -> ApiResult<()> {
98+
pub fn send_single_tab(
99+
&self,
100+
target_device_id: &str,
101+
title: &str,
102+
url: &str,
103+
private: bool,
104+
) -> ApiResult<()> {
99105
self.internal
100106
.lock()
101-
.send_single_tab(target_device_id, title, url)
107+
.send_single_tab(target_device_id, title, url, private)
102108
}
103109

104110
/// Use device commands to close one or more tabs on another device.
@@ -240,4 +246,5 @@ pub struct CloseTabsPayload {
240246
pub struct TabHistoryEntry {
241247
pub title: String,
242248
pub url: String,
249+
pub is_private: bool,
243250
}

examples/fxa-client/src/send_tab.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn poll(account: &FirefoxAccount) -> Result<()> {
6868
}
6969

7070
fn send(account: &FirefoxAccount, device_id: String, title: String, url: String) -> Result<()> {
71-
account.send_single_tab(&device_id, &title, &url)?;
71+
account.send_single_tab(&device_id, &title, &url, false)?;
7272
println!("Tab sent!");
7373
Ok(())
7474
}

0 commit comments

Comments
 (0)