Bug 1455304 - Filter unwanted sharing providers. r=mstange
MozReview-Commit-ID: 5FKHWzcJDYk
--- a/widget/cocoa/nsMacSharingService.mm
+++ b/widget/cocoa/nsMacSharingService.mm
@@ -4,16 +4,21 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#import <Cocoa/Cocoa.h>
#include "nsMacSharingService.h"
#include "nsCocoaUtils.h"
#include "mozilla/MacStringHelpers.h"
+// List of sharingProviders that we do not want to expose to
+// the user, because they are duplicates or do not work correctly
+// within the context
+NSArray *filteredProviderTitles = @[@"Add to Reading List", @"Mail"];
+
NS_IMPL_ISUPPORTS(nsMacSharingService, nsIMacSharingService)
static NSString*
NSImageToBase64(const NSImage* aImage)
{
[aImage lockFocus];
NSBitmapImageRep* bitmapRep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:NSMakeRect(0, 0, aImage.size.width, aImage.size.height)];
[aImage unlockFocus];
@@ -45,25 +50,26 @@ nsMacSharingService::GetSharingProviders
JS::Rooted<JSObject*> array(aCx, JS_NewArrayObject(aCx, 0));
NSURL* url = [NSURL URLWithString:nsCocoaUtils::ToNSString(aUrlToShare)];
NSArray* sharingService = [NSSharingService
sharingServicesForItems:[NSArray arrayWithObject:url]];
int32_t serviceCount = 0;
for (NSSharingService *currentService in sharingService) {
-
- JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
+ if (![filteredProviderTitles containsObject:currentService.title]) {
+ JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
- SetStrAttribute(aCx, obj, "title", currentService.title);
- SetStrAttribute(aCx, obj, "menuItemTitle", currentService.menuItemTitle);
- SetStrAttribute(aCx, obj, "image", NSImageToBase64(currentService.image));
+ SetStrAttribute(aCx, obj, "title", currentService.title);
+ SetStrAttribute(aCx, obj, "menuItemTitle", currentService.menuItemTitle);
+ SetStrAttribute(aCx, obj, "image", NSImageToBase64(currentService.image));
- JS::Rooted<JS::Value> element(aCx, JS::ObjectValue(*obj));
- JS_SetElement(aCx, array, serviceCount++, element);
+ JS::Rooted<JS::Value> element(aCx, JS::ObjectValue(*obj));
+ JS_SetElement(aCx, array, serviceCount++, element);
+ }
}
aResult.setObject(*array);
return NS_OK;
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}
--- a/widget/tests/unit/test_macsharingservice.js
+++ b/widget/tests/unit/test_macsharingservice.js
@@ -13,15 +13,17 @@ function test_getSharingProviders()
let sharingService = Cc["@mozilla.org/widget/macsharingservice;1"].
getService(Ci.nsIMacSharingService);
let providers = sharingService.getSharingProviders("http://example.org");
Assert.ok(providers.length > 1, "There are providers returned");
providers.forEach(provider => {
Assert.ok("title" in provider, "Provider has title");
Assert.ok("menuItemTitle" in provider, "Provider has menuItemTitle");
Assert.ok("image" in provider, "Provider has image");
+
+ Assert.notEqual(provider.title, "Mail", "Known filtered provider not returned");
});
}
function run_test()
{
test_getSharingProviders();
}