mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 19:04:45 +00:00
Bug 1471877 - Add link to share menu to configuration. r=Gijs,mstange
MozReview-Commit-ID: CCTO9SJJMY6 --HG-- extra : rebase_source : 23daee7ff3550b7613c03f817c2db87aecaf7ec5
This commit is contained in:
parent
7c4c1c603f
commit
dc2a4a2d84
@ -1230,26 +1230,34 @@ BrowserPageActions.shareURL = {
|
||||
let shareProviders = sharingService.getSharingProviders(currentURI);
|
||||
let fragment = document.createDocumentFragment();
|
||||
|
||||
let onCommand = event => {
|
||||
let shareName = event.target.getAttribute("share-name");
|
||||
if (shareName) {
|
||||
sharingService.shareUrl(shareName,
|
||||
currentURI,
|
||||
gBrowser.selectedBrowser.contentTitle);
|
||||
} else if (event.target.classList.contains("share-more-button")) {
|
||||
sharingService.openSharingPreferences();
|
||||
}
|
||||
PanelMultiView.hidePopup(BrowserPageActions.panelNode);
|
||||
};
|
||||
|
||||
shareProviders.forEach(function(share) {
|
||||
let item = document.createElement("toolbarbutton");
|
||||
item.setAttribute("label", share.menuItemTitle);
|
||||
item.setAttribute("share-name", share.name);
|
||||
item.setAttribute("image", share.image);
|
||||
item.classList.add("subviewbutton", "subviewbutton-iconic");
|
||||
|
||||
item.addEventListener("command", event => {
|
||||
let shareName = event.target.getAttribute("share-name");
|
||||
if (shareName) {
|
||||
sharingService.shareUrl(shareName,
|
||||
currentURI,
|
||||
gBrowser.selectedBrowser.contentTitle);
|
||||
}
|
||||
PanelMultiView.hidePopup(BrowserPageActions.panelNode);
|
||||
});
|
||||
|
||||
item.addEventListener("command", onCommand);
|
||||
fragment.appendChild(item);
|
||||
});
|
||||
|
||||
let item = document.createElement("toolbarbutton");
|
||||
item.setAttribute("label", BrowserPageActions.panelNode.getAttribute("shareMore-label"));
|
||||
item.classList.add("subviewbutton", "subviewbutton-iconic", "share-more-button");
|
||||
item.addEventListener("command", onCommand);
|
||||
fragment.appendChild(item);
|
||||
|
||||
while (bodyNode.firstChild) {
|
||||
bodyNode.firstChild.remove();
|
||||
}
|
||||
|
@ -474,7 +474,8 @@
|
||||
emailLink-title="&emailPageCmd.label;"
|
||||
sendToDevice-title="&pageAction.sendTabToDevice.label;"
|
||||
sendToDevice-notReadyTitle="&sendToDevice.syncNotReady.label;"
|
||||
shareURL-title="&pageAction.shareUrl.label;">
|
||||
shareURL-title="&pageAction.shareUrl.label;"
|
||||
shareMore-label="&pageAction.shareMore.label;">
|
||||
<panelmultiview id="pageActionPanelMultiView"
|
||||
mainViewId="pageActionPanelMainView"
|
||||
viewCacheId="appMenu-viewCache">
|
||||
|
@ -10,9 +10,8 @@ Services.scriptloader.loadSubScript("resource://testing-common/sinon-2.3.2.js");
|
||||
const URL = "http://example.org/";
|
||||
|
||||
// Keep track of title of service we chose to share with
|
||||
let serviceName;
|
||||
let sharedUrl;
|
||||
let sharedTitle;
|
||||
let serviceName, sharedUrl, sharedTitle;
|
||||
let sharingPreferencesCalled = false;
|
||||
|
||||
let mockShareData = [{
|
||||
name: "NSA",
|
||||
@ -30,6 +29,9 @@ let stub = sinon.stub(BrowserPageActions.shareURL, "_sharingService").get(() =>
|
||||
serviceName = name;
|
||||
sharedUrl = url;
|
||||
sharedTitle = title;
|
||||
},
|
||||
openSharingPreferences() {
|
||||
sharingPreferencesCalled = true;
|
||||
}
|
||||
};
|
||||
});
|
||||
@ -54,7 +56,8 @@ add_task(async function shareURL() {
|
||||
let view = await viewPromise;
|
||||
let body = document.getElementById(view.id + "-body");
|
||||
|
||||
Assert.equal(body.childNodes.length, 1, "Has correct share receivers");
|
||||
// We should see 1 receiver and one extra node for the "More..." button
|
||||
Assert.equal(body.childNodes.length, 2, "Has correct share receivers");
|
||||
let shareButton = body.childNodes[0];
|
||||
Assert.equal(shareButton.label, mockShareData[0].menuItemTitle);
|
||||
let hiddenPromise = promisePageActionPanelHidden();
|
||||
@ -107,7 +110,8 @@ add_task(async function shareURLAddressBar() {
|
||||
|
||||
// Ensure we have share providers
|
||||
let panel = document.getElementById("pageAction-urlbar-shareURL-subview-body");
|
||||
Assert.equal(panel.childNodes.length, 1, "Has correct share receivers");
|
||||
// We should see 1 receiver and one extra node for the "More..." button
|
||||
Assert.equal(panel.childNodes.length, 2, "Has correct share receivers");
|
||||
|
||||
// Remove the Share URL button from the Address bar so we dont interfere
|
||||
// with future tests
|
||||
@ -125,3 +129,30 @@ add_task(async function shareURLAddressBar() {
|
||||
await contextMenuPromise;
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function openSharingPreferences() {
|
||||
await BrowserTestUtils.withNewTab(URL, async () => {
|
||||
// Open the panel.
|
||||
await promisePageActionPanelOpen();
|
||||
|
||||
// Click Share URL.
|
||||
let shareURLButton = document.getElementById("pageAction-panel-shareURL");
|
||||
let viewPromise = promisePageActionViewShown();
|
||||
EventUtils.synthesizeMouseAtCenter(shareURLButton, {});
|
||||
|
||||
let view = await viewPromise;
|
||||
let body = document.getElementById(view.id + "-body");
|
||||
|
||||
// We should see 1 receiver and one extra node for the "More..." button
|
||||
Assert.equal(body.childNodes.length, 2, "Has correct share receivers");
|
||||
let moreButton = body.childNodes[1];
|
||||
let hiddenPromise = promisePageActionPanelHidden();
|
||||
// Click on the "more" button, panel should hide and we should call
|
||||
// the sharingService function to open preferences
|
||||
EventUtils.synthesizeMouseAtCenter(moreButton, {});
|
||||
await hiddenPromise;
|
||||
|
||||
Assert.equal(sharingPreferencesCalled, true,
|
||||
"We called openSharingPreferences");
|
||||
});
|
||||
});
|
||||
|
@ -1031,6 +1031,7 @@ you can use these alternative items. Otherwise, their values should be empty. -
|
||||
<!ENTITY sendToDevice.syncNotReady.label "Syncing Devices…">
|
||||
|
||||
<!ENTITY pageAction.shareUrl.label "Share">
|
||||
<!ENTITY pageAction.shareMore.label "More…">
|
||||
|
||||
<!ENTITY libraryButton.tooltip "View history, saved bookmarks, and more">
|
||||
|
||||
|
@ -298,7 +298,7 @@
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
#pageActionButton {
|
||||
#pageActionButton, .share-more-button {
|
||||
list-style-image: url("chrome://browser/skin/page-action.svg");
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,16 @@ NSArray *filteredProviderNames = @[
|
||||
NSString* const remindersServiceName =
|
||||
@"com.apple.reminders.RemindersShareExtension";
|
||||
|
||||
// These are some undocumented constants also used by Safari
|
||||
// to let us open the preferences window
|
||||
NSString* const extensionPrefPanePath =
|
||||
@"/System/Library/PreferencePanes/Extensions.prefPane";
|
||||
const UInt32 openSharingSubpaneDescriptorType = 'ptru';
|
||||
NSString* const openSharingSubpaneActionKey = @"action";
|
||||
NSString* const openSharingSubpaneActionValue = @"revealExtensionPoint";
|
||||
NSString* const openSharingSubpaneProtocolKey = @"protocol";
|
||||
NSString* const openSharingSubpaneProtocolValue = @"com.apple.share-services";
|
||||
|
||||
// Expose the id so we can pass reference through to JS and back
|
||||
@interface NSSharingService (ExposeName)
|
||||
- (id)name;
|
||||
@ -128,6 +138,40 @@ nsMacSharingService::GetSharingProviders(const nsAString& aPageUrl,
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMacSharingService::OpenSharingPreferences()
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
NSURL* prefPaneURL =
|
||||
[NSURL fileURLWithPath:extensionPrefPanePath isDirectory:YES];
|
||||
NSDictionary* args = @{
|
||||
openSharingSubpaneActionKey: openSharingSubpaneActionValue,
|
||||
openSharingSubpaneProtocolKey: openSharingSubpaneProtocolValue
|
||||
};
|
||||
NSData* data =
|
||||
[NSPropertyListSerialization
|
||||
dataWithPropertyList:args
|
||||
format:NSPropertyListXMLFormat_v1_0
|
||||
options:0
|
||||
error:nil];
|
||||
NSAppleEventDescriptor* descriptor =
|
||||
[[NSAppleEventDescriptor alloc]
|
||||
initWithDescriptorType:openSharingSubpaneDescriptorType
|
||||
data:data];
|
||||
|
||||
[[NSWorkspace sharedWorkspace] openURLs:@[ prefPaneURL ]
|
||||
withAppBundleIdentifier:nil
|
||||
options:NSWorkspaceLaunchAsync
|
||||
additionalEventParamDescriptor:descriptor
|
||||
launchIdentifiers:NULL];
|
||||
|
||||
[descriptor release];
|
||||
|
||||
return NS_OK;
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMacSharingService::ShareUrl(const nsAString& aServiceName,
|
||||
const nsAString& aPageUrl,
|
||||
|
@ -22,4 +22,9 @@ interface nsIMacSharingService : nsISupports
|
||||
void shareUrl(in AString serviceName,
|
||||
in AString pageUrl,
|
||||
in AString pageTitle);
|
||||
|
||||
/**
|
||||
* Open the MacOS preferences window to the sharing panel
|
||||
*/
|
||||
void openSharingPreferences();
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user