bool FrameworkView::EnsureAutomationProviderCreated() { #ifdef ACCESSIBILITY if (!mWidget || mShuttingDown) return false; if (mAutomationProvider) { return true; } Accessible *rootAccessible = mWidget->GetRootAccessible(); if (rootAccessible) { IInspectable* inspectable; HRESULT hr; AssertRetHRESULT(hr = UIABridge_CreateInstance(&inspectable), hr); // Addref IUIABridge* bridge = nullptr; inspectable->QueryInterface(IID_IUIABridge, (void**)&bridge); // Addref if (bridge) { bridge->Init(this, mWindow.Get(), (ULONG)rootAccessible); mAutomationProvider = inspectable; inspectable->Release(); return true; } } #endif return false; }
HRESULT FrameworkView::OnSettingsCommandInvoked(IUICommand* aCommand) { LogFunction(); HRESULT hr; uint32_t id; ComPtr<IPropertyValue> prop; AssertRetHRESULT(hr = aCommand->get_Id((IInspectable**)prop.GetAddressOf()), hr); AssertRetHRESULT(hr = prop->GetUInt32(&id), hr); nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService(); if (obs) { NS_ConvertASCIItoUTF16 idStr(nsPrintfCString("%lu", id)); obs->NotifyObservers(nullptr, "metro-settings-entry-selected", idStr.BeginReading()); } return S_OK; }
HRESULT FrameworkView::OnDataShareRequested(IDataTransferManager* aDTM, IDataRequestedEventArgs* aArg) { // Only share pages that contain a title and a URI nsCOMPtr<nsIMetroUIUtils> metroUIUtils = do_CreateInstance("@mozilla.org/metro-ui-utils;1"); if (!metroUIUtils) return E_FAIL; nsString url, title; nsresult rv = metroUIUtils->GetCurrentPageURI(url); nsresult rv2 = metroUIUtils->GetCurrentPageTitle(title); if (NS_FAILED(rv) || NS_FAILED(rv2)) { return E_FAIL; } // Get the package to share HRESULT hr; ComPtr<IDataRequest> request; AssertRetHRESULT(hr = aArg->get_Request(request.GetAddressOf()), hr); ComPtr<IDataPackage> dataPackage; AssertRetHRESULT(hr = request->get_Data(dataPackage.GetAddressOf()), hr); ComPtr<IDataPackagePropertySet> props; AssertRetHRESULT(hr = dataPackage->get_Properties(props.GetAddressOf()), hr); // 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 // their own preview, but we only want the selected content to show up. bool hasSelectedContent = false; metroUIUtils->GetHasSelectedContent(&hasSelectedContent); if (!hasSelectedContent) { ComPtr<IUriRuntimeClass> uri; 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); } // Add whatever content metroUIUtils wants us to for the text sharing nsString shareText; if (NS_SUCCEEDED(metroUIUtils->GetShareText(shareText)) && shareText.Length()) { AssertRetHRESULT(hr = dataPackage->SetText(HStringReference(shareText.BeginReading()).Get()) ,hr); } // Add whatever content metroUIUtils wants us to for the HTML sharing nsString shareHTML; if (NS_SUCCEEDED(metroUIUtils->GetShareHTML(shareHTML)) && shareHTML.Length()) { // The sharing format needs some special headers, so pass it through Windows ComPtr<IHtmlFormatHelperStatics> htmlFormatHelper; hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_ApplicationModel_DataTransfer_HtmlFormatHelper).Get(), htmlFormatHelper.GetAddressOf()); AssertRetHRESULT(hr, hr); HSTRING fixedHTML; htmlFormatHelper->CreateHtmlFormat(HStringReference(shareHTML.BeginReading()).Get(), &fixedHTML); // And now add the fixed HTML to the data package 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(MOZ_UTF16("brandFullName"), 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; }