Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,12 @@ class FxaClient(inner: FirefoxAccount, persistCallback: PersistCallback?) : Auto
* @param targetDeviceId The target Device ID
* @param title The document title of the tab being sent
* @param url The url of the tab being sent
* @param isPrivate Whether the tab is open as a private tab. Has a default value to help with progressive
* implementation of this new attribute, but the default should be removed at some point.
*/
fun sendSingleTab(targetDeviceId: String, title: String, url: String) {
fun sendSingleTab(targetDeviceId: String, title: String, url: String, isPrivate: Boolean = false) {
withMetrics {
this.inner.sendSingleTab(targetDeviceId, title, url)
this.inner.sendSingleTab(targetDeviceId, title, url, isPrivate)
}
}

Expand Down
7 changes: 5 additions & 2 deletions components/fxa-client/src/fxa_client.udl
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ interface FirefoxAccount {
/// granted the `https:///identity.mozilla.com/apps/oldsync` scope.
///
[Throws=FxaError]
void send_single_tab([ByRef] string target_device_id, [ByRef] string title, [ByRef] string url );
void send_single_tab([ByRef] string target_device_id, [ByRef] string title, [ByRef] string url, optional boolean is_private = false );


/// Use device commands to close one or more tabs on another device.
Expand Down Expand Up @@ -929,11 +929,14 @@ dictionary CloseTabsPayload {
sequence<string> urls;
};

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

/// A client connected to the user's account.
Expand Down
8 changes: 6 additions & 2 deletions components/fxa-client/src/internal/commands/send_tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ impl From<SendTabPayload> for crate::SendTabPayload {
}

impl SendTabPayload {
pub fn single_tab(title: &str, url: &str) -> (Self, telemetry::SentCommand) {
pub fn single_tab(title: &str, url: &str, private: bool) -> (Self, telemetry::SentCommand) {
let sent_telemetry: telemetry::SentCommand = telemetry::SentCommand::for_send_tab();
(
SendTabPayload {
entries: vec![TabHistoryEntry {
title: title.to_string(),
url: url.to_string(),
private,
}],
flow_id: sent_telemetry.flow_id.clone(),
stream_id: sent_telemetry.stream_id.clone(),
Expand All @@ -58,13 +59,15 @@ impl SendTabPayload {
pub struct TabHistoryEntry {
pub title: String,
pub url: String,
pub private: bool,
}

impl From<TabHistoryEntry> for crate::TabHistoryEntry {
fn from(e: TabHistoryEntry) -> Self {
crate::TabHistoryEntry {
title: e.title,
url: e.url,
is_private: e.private,
}
}
}
Expand All @@ -82,14 +85,15 @@ mod tests {

#[test]
fn test_payload() {
let (payload, telem) = SendTabPayload::single_tab("title", "http://example.com");
let (payload, telem) = SendTabPayload::single_tab("title", "http://example.com", true);
let json = serde_json::to_string(&payload).expect("should work");
assert_eq!(telem.flow_id.len(), 12);
assert_eq!(telem.stream_id.len(), 12);
assert_ne!(telem.flow_id, telem.stream_id);
let p2: SendTabPayload = serde_json::from_str(&json).expect("should work");
// no 'PartialEq' derived so check each field individually...
assert_eq!(payload.entries[0].url, "http://example.com".to_string());
assert!(payload.entries[0].private);
assert_eq!(payload.flow_id, p2.flow_id);
assert_eq!(payload.stream_id, p2.stream_id);
}
Expand Down
3 changes: 2 additions & 1 deletion components/fxa-client/src/internal/send_tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ impl FirefoxAccount {
target_device_id: &str,
title: &str,
url: &str,
private: bool,
) -> Result<()> {
let devices = self.get_devices(false)?;
let target = devices
.iter()
.find(|d| d.id == target_device_id)
.ok_or_else(|| Error::UnknownTargetDevice(target_device_id.to_owned()))?;
let (payload, sent_telemetry) = SendTabPayload::single_tab(title, url);
let (payload, sent_telemetry) = SendTabPayload::single_tab(title, url, private);
let oldsync_key = self.get_scoped_key(scopes::OLD_SYNC)?;
let command_payload =
encrypt_command(oldsync_key, target, send_tab::COMMAND_NAME, &payload)?;
Expand Down
11 changes: 9 additions & 2 deletions components/fxa-client/src/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,16 @@ impl FirefoxAccount {
/// - Device commands functionality is only available to applications that have been
/// granted the `https://identity.mozilla.com/apps/oldsync` scope.
#[handle_error(Error)]
pub fn send_single_tab(&self, target_device_id: &str, title: &str, url: &str) -> ApiResult<()> {
pub fn send_single_tab(
&self,
target_device_id: &str,
title: &str,
url: &str,
private: bool,
) -> ApiResult<()> {
self.internal
.lock()
.send_single_tab(target_device_id, title, url)
.send_single_tab(target_device_id, title, url, private)
}

/// Use device commands to close one or more tabs on another device.
Expand Down Expand Up @@ -240,4 +246,5 @@ pub struct CloseTabsPayload {
pub struct TabHistoryEntry {
pub title: String,
pub url: String,
pub is_private: bool,
}
2 changes: 1 addition & 1 deletion examples/fxa-client/src/send_tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fn poll(account: &FirefoxAccount) -> Result<()> {
}

fn send(account: &FirefoxAccount, device_id: String, title: String, url: String) -> Result<()> {
account.send_single_tab(&device_id, &title, &url)?;
account.send_single_tab(&device_id, &title, &url, false)?;
println!("Tab sent!");
Ok(())
}
Expand Down