mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 20:05:49 +00:00
Bug 1246076 (part 2) - optionally display a remote tab's favicon if available. r=mak
This commit is contained in:
parent
9f175c7457
commit
08e10e83b1
@ -63,7 +63,11 @@ function ensureItems() {
|
||||
return _items;
|
||||
}
|
||||
|
||||
// An observer to invalidate _items.
|
||||
// A preference used to disable the showing of icons in remote tab records.
|
||||
const PREF_SHOW_REMOTE_ICONS = "services.sync.syncedTabs.showRemoteIcons";
|
||||
let showRemoteIcons;
|
||||
|
||||
// An observer to invalidate _items and watch for changed prefs.
|
||||
function observe(subject, topic, data) {
|
||||
switch (topic) {
|
||||
case "weave:engine:sync:finish":
|
||||
@ -80,6 +84,16 @@ function observe(subject, topic, data) {
|
||||
_items = null;
|
||||
break;
|
||||
|
||||
case "nsPref:changed":
|
||||
if (data == PREF_SHOW_REMOTE_ICONS) {
|
||||
try {
|
||||
showRemoteIcons = Services.prefs.getBoolPref(PREF_SHOW_REMOTE_ICONS);
|
||||
} catch(_) {
|
||||
showRemoteIcons = true; // no such pref - default is to show the icons.
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -88,6 +102,10 @@ function observe(subject, topic, data) {
|
||||
Services.obs.addObserver(observe, "weave:engine:sync:finish", false);
|
||||
Services.obs.addObserver(observe, "weave:service:start-over", false);
|
||||
|
||||
// Observe the pref for showing remote icons and prime our bool that reflects its value.
|
||||
Services.prefs.addObserver(PREF_SHOW_REMOTE_ICONS, observe, false);
|
||||
observe(null, "nsPref:changed", PREF_SHOW_REMOTE_ICONS);
|
||||
|
||||
// This public object is a static singleton.
|
||||
this.PlacesRemoteTabsAutocompleteProvider = {
|
||||
// a promise that resolves with an array of matching remote tabs.
|
||||
@ -105,10 +123,10 @@ this.PlacesRemoteTabsAutocompleteProvider = {
|
||||
if (url.match(re) || (title && title.match(re))) {
|
||||
// lookup the client record.
|
||||
let client = clients.get(clientId);
|
||||
let icon = showRemoteIcons ? tab.icon : null;
|
||||
// create the record we return for auto-complete.
|
||||
let record = {
|
||||
url, title,
|
||||
icon: tab.icon,
|
||||
url, title, icon,
|
||||
deviceClass: Weave.Service.clientsEngine.isMobile(clientId) ? "mobile" : "desktop",
|
||||
deviceName: client.clientName,
|
||||
};
|
||||
|
@ -54,6 +54,7 @@ function makeRemoteTabMatch(url, deviceName, extra = {}) {
|
||||
uri: makeActionURI("remotetab", {url, deviceName}),
|
||||
title: extra.title || url,
|
||||
style: [ "action" ],
|
||||
icon: extra.icon,
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,12 +116,39 @@ add_task(function* test_maximal() {
|
||||
matches: [ makeSearchMatch("ex", { heuristic: true }),
|
||||
makeRemoteTabMatch("http://example.com/", "My Phone",
|
||||
{ title: "An Example",
|
||||
icon: "moz-anno:favicon:http://favicon"
|
||||
icon: "moz-anno:favicon:http://favicon/"
|
||||
}),
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
add_task(function* test_noShowIcons() {
|
||||
Services.prefs.setBoolPref("services.sync.syncedTabs.showRemoteIcons", false);
|
||||
configureEngine({
|
||||
guid_mobile: {
|
||||
clientName: "My Phone",
|
||||
tabs: [{
|
||||
urlHistory: ["http://example.com/"],
|
||||
title: "An Example",
|
||||
icon: "http://favicon",
|
||||
}],
|
||||
}
|
||||
});
|
||||
|
||||
yield check_autocomplete({
|
||||
search: "ex",
|
||||
searchParam: "enable-actions",
|
||||
matches: [ makeSearchMatch("ex", { heuristic: true }),
|
||||
makeRemoteTabMatch("http://example.com/", "My Phone",
|
||||
{ title: "An Example",
|
||||
// expecting the default favicon due to that pref.
|
||||
icon: PlacesUtils.favicons.defaultFavicon.spec,
|
||||
}),
|
||||
],
|
||||
});
|
||||
Services.prefs.clearUserPref("services.sync.syncedTabs.showRemoteIcons");
|
||||
});
|
||||
|
||||
add_task(function* test_matches_title() {
|
||||
// URL doesn't match search expression, should still match the title.
|
||||
configureEngine({
|
||||
|
Loading…
Reference in New Issue
Block a user