Bug 849607 - Sharing in Metro Firefox start screen should indicate nothing to share instead of error. r=jimm

This commit is contained in:
Brian R. Bondy 2013-03-12 10:11:48 -04:00
parent cec09d76cc
commit e0281ca50c
2 changed files with 44 additions and 15 deletions

View File

@ -18,6 +18,7 @@
#include <printpreview.h> #include <printpreview.h>
#include <D3D10.h> #include <D3D10.h>
#include "MetroUIUtils.h" #include "MetroUIUtils.h"
#include "nsIStringBundle.h"
using namespace mozilla; using namespace mozilla;
using namespace ABI::Windows::Foundation; using namespace ABI::Windows::Foundation;
@ -316,7 +317,7 @@ FrameworkView::OnDataShareRequested(IDataTransferManager* aDTM,
return E_FAIL; return E_FAIL;
} }
// Get the package to share and initialize it // Get the package to share
HRESULT hr; HRESULT hr;
ComPtr<IDataRequest> request; ComPtr<IDataRequest> request;
AssertRetHRESULT(hr = aArg->get_Request(request.GetAddressOf()), hr); AssertRetHRESULT(hr = aArg->get_Request(request.GetAddressOf()), hr);
@ -324,9 +325,6 @@ FrameworkView::OnDataShareRequested(IDataTransferManager* aDTM,
AssertRetHRESULT(hr = request->get_Data(dataPackage.GetAddressOf()), hr); AssertRetHRESULT(hr = request->get_Data(dataPackage.GetAddressOf()), hr);
ComPtr<IDataPackagePropertySet> props; ComPtr<IDataPackagePropertySet> props;
AssertRetHRESULT(hr = dataPackage->get_Properties(props.GetAddressOf()), hr); AssertRetHRESULT(hr = dataPackage->get_Properties(props.GetAddressOf()), hr);
props->put_ApplicationName(HStringReference(L"Firefox").Get());
props->put_Title(HStringReference(title.BeginReading()).Get());
props->put_Description(HStringReference(url.BeginReading()).Get());
// Only add a URI to the package when there is no selected content. // Only add a URI to the package when there is no selected content.
// This is because most programs treat URIs as highest priority to generate // This is because most programs treat URIs as highest priority to generate
@ -336,18 +334,30 @@ FrameworkView::OnDataShareRequested(IDataTransferManager* aDTM,
if (!hasSelectedContent) { if (!hasSelectedContent) {
ComPtr<IUriRuntimeClass> uri; ComPtr<IUriRuntimeClass> uri;
AssertRetHRESULT(hr = MetroUtils::CreateUri(HStringReference(url.BeginReading()).Get(), uri), hr); AssertRetHRESULT(hr = MetroUtils::CreateUri(HStringReference(url.BeginReading()).Get(), uri), hr);
// If there is no selection, then we don't support sharing for sites that
// are not HTTP, HTTPS, FTP, and FILE.
HString schemeHString;
uri->get_SchemeName(schemeHString.GetAddressOf());
unsigned int length;
LPCWSTR scheme = schemeHString.GetRawBuffer(&length);
if (!scheme || wcscmp(scheme, L"http") && wcscmp(scheme, L"https") &&
wcscmp(scheme, L"ftp") && wcscmp(scheme, L"file")) {
return S_OK;
}
AssertRetHRESULT(hr = dataPackage->SetUri(uri.Get()), hr); AssertRetHRESULT(hr = dataPackage->SetUri(uri.Get()), hr);
} }
// Add whatever content metroUIUtils wants us to for the text sharing // Add whatever content metroUIUtils wants us to for the text sharing
nsString shareText; nsString shareText;
if (NS_SUCCEEDED(metroUIUtils->GetShareText(shareText))) { if (NS_SUCCEEDED(metroUIUtils->GetShareText(shareText)) && shareText.Length()) {
AssertRetHRESULT(hr = dataPackage->SetText(HStringReference(shareText.BeginReading()).Get()) ,hr); AssertRetHRESULT(hr = dataPackage->SetText(HStringReference(shareText.BeginReading()).Get()) ,hr);
} }
// Add whatever content metroUIUtils wants us to for the HTML sharing // Add whatever content metroUIUtils wants us to for the HTML sharing
nsString shareHTML; nsString shareHTML;
if (NS_SUCCEEDED(metroUIUtils->GetShareHTML(shareHTML))) { if (NS_SUCCEEDED(metroUIUtils->GetShareHTML(shareHTML)) && shareHTML.Length()) {
// The sharing format needs some special headers, so pass it through Windows // The sharing format needs some special headers, so pass it through Windows
ComPtr<IHtmlFormatHelperStatics> htmlFormatHelper; ComPtr<IHtmlFormatHelperStatics> htmlFormatHelper;
hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_ApplicationModel_DataTransfer_HtmlFormatHelper).Get(), hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_ApplicationModel_DataTransfer_HtmlFormatHelper).Get(),
@ -360,6 +370,31 @@ FrameworkView::OnDataShareRequested(IDataTransferManager* aDTM,
AssertRetHRESULT(hr = dataPackage->SetHtmlFormat(fixedHTML), hr); AssertRetHRESULT(hr = dataPackage->SetHtmlFormat(fixedHTML), hr);
} }
// Obtain the brand name
nsCOMPtr<nsIStringBundleService> bundleService =
do_GetService(NS_STRINGBUNDLE_CONTRACTID);
NS_ENSURE_TRUE(bundleService, E_FAIL);
nsCOMPtr<nsIStringBundle> brandBundle;
nsString brandName;
bundleService->CreateBundle("chrome://branding/locale/brand.properties",
getter_AddRefs(brandBundle));
NS_ENSURE_TRUE(brandBundle, E_FAIL);
if(brandBundle) {
brandBundle->GetStringFromName(NS_LITERAL_STRING("brandFullName").get(),
getter_Copies(brandName));
}
// Set these properties at the end. Otherwise users can get a
// "There was a problem with the data package" error when there
// is simply nothing to share.
props->put_ApplicationName(HStringReference(brandName.BeginReading()).Get());
if (title.Length()) {
props->put_Title(HStringReference(title.BeginReading()).Get());
} else {
props->put_Title(HStringReference(brandName.BeginReading()).Get());
}
props->put_Description(HStringReference(url.BeginReading()).Get());
return S_OK; return S_OK;
} }

View File

@ -97,11 +97,9 @@ MetroUIUtils.prototype = {
let browserWin = Services.wm.getMostRecentWindow("navigator:browser"); let browserWin = Services.wm.getMostRecentWindow("navigator:browser");
let tabBrowser = browserWin.getBrowser(); let tabBrowser = browserWin.getBrowser();
if (browserWin && tabBrowser && tabBrowser.contentWindow) { if (browserWin && tabBrowser && tabBrowser.contentWindow) {
return tabBrowser.contentWindow.getSelection() || ""; let sel = tabBrowser.contentWindow.getSelection();
} if (sel && sel.rangeCount)
else if (browserWin && browserWin.content && browserWin.document) { return sel;
return browserWin.content.document.URL ||
browserWin.content.document.title || "";
} }
throw Cr.NS_ERROR_FAILURE; throw Cr.NS_ERROR_FAILURE;
@ -168,10 +166,6 @@ MetroUIUtils.prototype = {
this._expandURLs(tabBrowser.contentWindow.document, div); this._expandURLs(tabBrowser.contentWindow.document, div);
return div.outerHTML; return div.outerHTML;
} }
else if (browserWin && browserWin.content && browserWin.document) {
return browserWin.content.document.URL ||
browserWin.content.document.title || "";
}
throw Cr.NS_ERROR_FAILURE; throw Cr.NS_ERROR_FAILURE;
} }