1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/windows/winrt/MetroContracts.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,573 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "FrameworkView.h" 1.10 +#include "MetroUtils.h" 1.11 +#include "nsICommandLineRunner.h" 1.12 +#include "nsNetUtil.h" 1.13 +#include "nsIDOMChromeWindow.h" 1.14 +#include "nsIURI.h" 1.15 +#include "nsPrintfCString.h" 1.16 +#include "mozilla/Services.h" 1.17 +#include <wrl/wrappers/corewrappers.h> 1.18 +#include <shellapi.h> 1.19 +#include <DXGIFormat.h> 1.20 +#include <d2d1_1.h> 1.21 +#include <printpreview.h> 1.22 +#include <D3D10.h> 1.23 +#include "MetroUIUtils.h" 1.24 +#include "nsIStringBundle.h" 1.25 + 1.26 +using namespace mozilla; 1.27 +using namespace ABI::Windows::Foundation; 1.28 +using namespace ABI::Windows::Foundation::Collections; 1.29 +using namespace Microsoft::WRL; 1.30 +using namespace Microsoft::WRL::Wrappers; 1.31 + 1.32 +// Play to contract 1.33 +using namespace ABI::Windows::Media::PlayTo; 1.34 + 1.35 +// Activation contracts 1.36 +using namespace ABI::Windows::ApplicationModel::Activation; 1.37 +using namespace ABI::Windows::ApplicationModel::DataTransfer; 1.38 +using namespace ABI::Windows::ApplicationModel::Search; 1.39 + 1.40 +// Settings contract 1.41 +using namespace ABI::Windows::UI::ApplicationSettings; 1.42 +using namespace ABI::Windows::UI::Popups; 1.43 + 1.44 +// Print contract 1.45 +using namespace ABI::Windows::Graphics::Printing; 1.46 + 1.47 +namespace mozilla { 1.48 +namespace widget { 1.49 +namespace winrt { 1.50 + 1.51 +extern nsTArray<nsString>* sSettingsArray; 1.52 + 1.53 +void 1.54 +FrameworkView::SearchActivated(ComPtr<ISearchActivatedEventArgs>& aArgs, bool aStartup) 1.55 +{ 1.56 + if (!aArgs) 1.57 + return; 1.58 + 1.59 + HString data; 1.60 + AssertHRESULT(aArgs->get_QueryText(data.GetAddressOf())); 1.61 + if (WindowsIsStringEmpty(data.Get())) 1.62 + return; 1.63 + 1.64 + unsigned int length; 1.65 + WinUtils::LogW(L"SearchActivated text=%s", data.GetRawBuffer(&length)); 1.66 + if (aStartup) { 1.67 + WindowsDuplicateString(data.Get(), &sActivationURI); 1.68 + } else { 1.69 + PerformURILoadOrSearch(data); 1.70 + } 1.71 +} 1.72 + 1.73 +void 1.74 +FrameworkView::FileActivated(ComPtr<IFileActivatedEventArgs>& aArgs, bool aStartup) 1.75 +{ 1.76 + if (!aArgs) 1.77 + return; 1.78 + 1.79 + ComPtr<IVectorView<ABI::Windows::Storage::IStorageItem*>> list; 1.80 + AssertHRESULT(aArgs->get_Files(list.GetAddressOf())); 1.81 + ComPtr<ABI::Windows::Storage::IStorageItem> item; 1.82 + AssertHRESULT(list->GetAt(0, item.GetAddressOf())); 1.83 + HString filePath; 1.84 + AssertHRESULT(item->get_Path(filePath.GetAddressOf())); 1.85 + 1.86 + if (aStartup) { 1.87 + WindowsDuplicateString(filePath.Get(), &sActivationURI); 1.88 + } else { 1.89 + PerformURILoad(filePath); 1.90 + } 1.91 +} 1.92 + 1.93 +void 1.94 +FrameworkView::LaunchActivated(ComPtr<ILaunchActivatedEventArgs>& aArgs, bool aStartup) 1.95 +{ 1.96 + if (!aArgs) 1.97 + return; 1.98 + HString data; 1.99 + AssertHRESULT(aArgs->get_Arguments(data.GetAddressOf())); 1.100 + if (WindowsIsStringEmpty(data.Get())) 1.101 + return; 1.102 + 1.103 + // If we're being launched from a secondary tile then we have a 2nd command line param of -url 1.104 + // and a third of the secondary tile. We want it in sActivationURI so that browser.js will 1.105 + // load it in without showing the start UI. 1.106 + int argc; 1.107 + unsigned int length; 1.108 + LPWSTR* argv = CommandLineToArgvW(data.GetRawBuffer(&length), &argc); 1.109 + if (aStartup && argc == 2 && !wcsicmp(argv[0], L"-url")) { 1.110 + WindowsCreateString(argv[1], wcslen(argv[1]), &sActivationURI); 1.111 + } else { 1.112 + // Some other command line or this is not a startup. 1.113 + // If it is startup we process it later when XPCOM is initialilzed. 1.114 + mActivationCommandLine = data.GetRawBuffer(&length); 1.115 + if (!aStartup) { 1.116 + ProcessLaunchArguments(); 1.117 + } 1.118 + } 1.119 +} 1.120 + 1.121 +void 1.122 +FrameworkView::ProcessLaunchArguments() 1.123 +{ 1.124 + if (!mActivationCommandLine.Length()) 1.125 + return; 1.126 + 1.127 + int argc; 1.128 + LPWSTR* argv = CommandLineToArgvW(mActivationCommandLine.BeginReading(), &argc); 1.129 + nsCOMPtr<nsICommandLineRunner> cmdLine = 1.130 + (do_CreateInstance("@mozilla.org/toolkit/command-line;1")); 1.131 + if (!cmdLine) { 1.132 + NS_WARNING("Unable to instantiate command line runner."); 1.133 + return; 1.134 + } 1.135 + 1.136 + LPSTR *argvUTF8 = new LPSTR[argc]; 1.137 + for (int i = 0; i < argc; ++i) { 1.138 + NS_ConvertUTF16toUTF8 arg(argv[i]); 1.139 + argvUTF8[i] = new char[arg.Length() + 1]; 1.140 + strcpy(argvUTF8[i], const_cast<char *>(arg.BeginReading())); 1.141 + WinUtils::LogW(L"Launch arg[%d]: '%s'", i, argv[i]); 1.142 + } 1.143 + 1.144 + nsresult rv = cmdLine->Init(argc, 1.145 + argvUTF8, 1.146 + nullptr, 1.147 + nsICommandLine::STATE_REMOTE_EXPLICIT); 1.148 + if (NS_SUCCEEDED(rv)) { 1.149 + cmdLine->Run(); 1.150 + } else { 1.151 + NS_WARNING("cmdLine->Init failed."); 1.152 + } 1.153 + 1.154 + for (int i = 0; i < argc; ++i) { 1.155 + delete[] argvUTF8[i]; 1.156 + } 1.157 + delete[] argvUTF8; 1.158 +} 1.159 + 1.160 +void 1.161 +FrameworkView::ProcessActivationArgs(IActivatedEventArgs* aArgs, bool aStartup) 1.162 +{ 1.163 + ActivationKind kind; 1.164 + if (!aArgs || FAILED(aArgs->get_Kind(&kind))) 1.165 + return; 1.166 + ComPtr<IActivatedEventArgs> args(aArgs); 1.167 + if (kind == ActivationKind::ActivationKind_Protocol) { 1.168 + WinUtils::Log("Activation argument kind: Protocol"); 1.169 + ComPtr<IProtocolActivatedEventArgs> protoArgs; 1.170 + AssertHRESULT(args.As(&protoArgs)); 1.171 + ComPtr<IUriRuntimeClass> uri; 1.172 + AssertHRESULT(protoArgs->get_Uri(uri.GetAddressOf())); 1.173 + if (!uri) 1.174 + return; 1.175 + 1.176 + HString data; 1.177 + AssertHRESULT(uri->get_AbsoluteUri(data.GetAddressOf())); 1.178 + if (WindowsIsStringEmpty(data.Get())) 1.179 + return; 1.180 + 1.181 + if (aStartup) { 1.182 + WindowsDuplicateString(data.Get(), &sActivationURI); 1.183 + } else { 1.184 + PerformURILoad(data); 1.185 + } 1.186 + } else if (kind == ActivationKind::ActivationKind_Search) { 1.187 + WinUtils::Log("Activation argument kind: Search"); 1.188 + ComPtr<ISearchActivatedEventArgs> searchArgs; 1.189 + args.As(&searchArgs); 1.190 + SearchActivated(searchArgs, aStartup); 1.191 + } else if (kind == ActivationKind::ActivationKind_File) { 1.192 + WinUtils::Log("Activation argument kind: File"); 1.193 + ComPtr<IFileActivatedEventArgs> fileArgs; 1.194 + args.As(&fileArgs); 1.195 + FileActivated(fileArgs, aStartup); 1.196 + } else if (kind == ActivationKind::ActivationKind_Launch) { 1.197 + WinUtils::Log("Activation argument kind: Launch"); 1.198 + ComPtr<ILaunchActivatedEventArgs> launchArgs; 1.199 + args.As(&launchArgs); 1.200 + LaunchActivated(launchArgs, aStartup); 1.201 + } 1.202 +} 1.203 + 1.204 +void 1.205 +FrameworkView::SetupContracts() 1.206 +{ 1.207 + LogFunction(); 1.208 + HRESULT hr; 1.209 + 1.210 + // Add support for the share charm to indicate that we share data to other apps 1.211 + ComPtr<IDataTransferManagerStatics> transStatics; 1.212 + hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_ApplicationModel_DataTransfer_DataTransferManager).Get(), 1.213 + transStatics.GetAddressOf()); 1.214 + AssertHRESULT(hr); 1.215 + ComPtr<IDataTransferManager> trans; 1.216 + AssertHRESULT(transStatics->GetForCurrentView(trans.GetAddressOf())); 1.217 + trans->add_DataRequested(Callback<__FITypedEventHandler_2_Windows__CApplicationModel__CDataTransfer__CDataTransferManager_Windows__CApplicationModel__CDataTransfer__CDataRequestedEventArgs_t>( 1.218 + this, &FrameworkView::OnDataShareRequested).Get(), &mDataTransferRequested); 1.219 + 1.220 + // Add support for the search charm to indicate that you can search using our app. 1.221 + ComPtr<ISearchPaneStatics> searchStatics; 1.222 + hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_ApplicationModel_Search_SearchPane).Get(), 1.223 + searchStatics.GetAddressOf()); 1.224 + AssertHRESULT(hr); 1.225 + ComPtr<ISearchPane> searchPane; 1.226 + AssertHRESULT(searchStatics->GetForCurrentView(searchPane.GetAddressOf())); 1.227 + searchPane->add_QuerySubmitted(Callback<__FITypedEventHandler_2_Windows__CApplicationModel__CSearch__CSearchPane_Windows__CApplicationModel__CSearch__CSearchPaneQuerySubmittedEventArgs_t>( 1.228 + this, &FrameworkView::OnSearchQuerySubmitted).Get(), &mSearchQuerySubmitted); 1.229 + 1.230 + // Add support for the devices play to charm 1.231 + ComPtr<IPlayToManagerStatics> playToStatics; 1.232 + hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_Media_PlayTo_PlayToManager).Get(), 1.233 + playToStatics.GetAddressOf()); 1.234 + AssertHRESULT(hr); 1.235 + ComPtr<IPlayToManager> playTo; 1.236 + AssertHRESULT(playToStatics->GetForCurrentView(playTo.GetAddressOf())); 1.237 + playTo->add_SourceRequested(Callback<__FITypedEventHandler_2_Windows__CMedia__CPlayTo__CPlayToManager_Windows__CMedia__CPlayTo__CPlayToSourceRequestedEventArgs_t>( 1.238 + this, &FrameworkView::OnPlayToSourceRequested).Get(), &mPlayToRequested); 1.239 + 1.240 + // Add support for the settings charm 1.241 + ComPtr<ISettingsPaneStatics> settingsPaneStatics; 1.242 + hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_UI_ApplicationSettings_SettingsPane).Get(), 1.243 + settingsPaneStatics.GetAddressOf()); 1.244 + AssertHRESULT(hr); 1.245 + ComPtr<ISettingsPane> settingsPane; 1.246 + AssertHRESULT(settingsPaneStatics->GetForCurrentView(settingsPane.GetAddressOf())); 1.247 + settingsPane->add_CommandsRequested(Callback<__FITypedEventHandler_2_Windows__CUI__CApplicationSettings__CSettingsPane_Windows__CUI__CApplicationSettings__CSettingsPaneCommandsRequestedEventArgs_t>( 1.248 + this, &FrameworkView::OnSettingsCommandsRequested).Get(), &mSettingsPane); 1.249 + 1.250 + // Add support for the settings print charm 1.251 + ComPtr<IPrintManagerStatic> printStatics; 1.252 + hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_Graphics_Printing_PrintManager).Get(), 1.253 + printStatics.GetAddressOf()); 1.254 + AssertHRESULT(hr); 1.255 + ComPtr<IPrintManager> printManager; 1.256 + AssertHRESULT(printStatics->GetForCurrentView(printManager.GetAddressOf())); 1.257 + printManager->add_PrintTaskRequested(Callback<__FITypedEventHandler_2_Windows__CGraphics__CPrinting__CPrintManager_Windows__CGraphics__CPrinting__CPrintTaskRequestedEventArgs_t>( 1.258 + this, &FrameworkView::OnPrintTaskRequested).Get(), &mPrintManager); 1.259 +} 1.260 + 1.261 +void 1.262 +FrameworkView::PerformURILoad(HString& aURI) 1.263 +{ 1.264 + LogFunction(); 1.265 + 1.266 + unsigned int length; 1.267 + WinUtils::LogW(L"PerformURILoad uri=%s", aURI.GetRawBuffer(&length)); 1.268 + 1.269 + nsCOMPtr<nsICommandLineRunner> cmdLine = 1.270 + (do_CreateInstance("@mozilla.org/toolkit/command-line;1")); 1.271 + if (!cmdLine) { 1.272 + NS_WARNING("Unable to instantiate command line runner."); 1.273 + return; 1.274 + } 1.275 + 1.276 + nsAutoCString utf8data(NS_ConvertUTF16toUTF8(aURI.GetRawBuffer(&length))); 1.277 + 1.278 + // NB: The first argument gets stripped by nsICommandLineRunner::Init, 1.279 + // so it doesn't matter what we pass as the first argument, but we 1.280 + // have to pass something. 1.281 + const char *argv[] = { "", // This argument gets stripped 1.282 + "-url", 1.283 + utf8data.BeginReading() }; 1.284 + nsresult rv = cmdLine->Init(ArrayLength(argv), 1.285 + const_cast<char **>(argv), nullptr, 1.286 + nsICommandLine::STATE_REMOTE_EXPLICIT); 1.287 + if (NS_FAILED(rv)) { 1.288 + NS_WARNING("cmdLine->Init failed."); 1.289 + return; 1.290 + } 1.291 + cmdLine->Run(); 1.292 +} 1.293 + 1.294 +void 1.295 +FrameworkView::PerformSearch(HString& aQuery) 1.296 +{ 1.297 + LogFunction(); 1.298 + 1.299 + nsCOMPtr<nsICommandLineRunner> cmdLine = 1.300 + (do_CreateInstance("@mozilla.org/toolkit/command-line;1")); 1.301 + if (!cmdLine) { 1.302 + NS_WARNING("Unable to instantiate command line runner."); 1.303 + return; 1.304 + } 1.305 + 1.306 + nsAutoCString parameter; 1.307 + parameter.AppendLiteral("\""); 1.308 + unsigned int length; 1.309 + parameter.Append(NS_ConvertUTF16toUTF8(aQuery.GetRawBuffer(&length))); 1.310 + parameter.AppendLiteral("\""); 1.311 + 1.312 + // NB: The first argument gets stripped by nsICommandLineRunner::Init, 1.313 + // so it doesn't matter what we pass as the first argument, but we 1.314 + // have to pass something. 1.315 + const char *argv[] = { "", // This argument gets stripped 1.316 + "-search", 1.317 + parameter.BeginReading() }; 1.318 + nsresult rv = cmdLine->Init(ArrayLength(argv), 1.319 + const_cast<char **>(argv), nullptr, 1.320 + nsICommandLine::STATE_REMOTE_EXPLICIT); 1.321 + if (NS_FAILED(rv)) { 1.322 + NS_WARNING("cmdLine->Init failed."); 1.323 + return; 1.324 + } 1.325 + cmdLine->Run(); 1.326 +} 1.327 + 1.328 +void 1.329 +FrameworkView::PerformURILoadOrSearch(HString& aString) 1.330 +{ 1.331 + LogFunction(); 1.332 + 1.333 + if (WindowsIsStringEmpty(aString.Get())) { 1.334 + WinUtils::Log("Emptry string passed to PerformURILoadOrSearch"); 1.335 + return; 1.336 + } 1.337 + 1.338 + // If we have a URI then devert to load the URI directly 1.339 + ComPtr<IUriRuntimeClass> uri; 1.340 + MetroUtils::CreateUri(aString.Get(), uri); 1.341 + if (uri) { 1.342 + PerformURILoad(aString); 1.343 + } else { 1.344 + PerformSearch(aString); 1.345 + } 1.346 +} 1.347 + 1.348 +HRESULT 1.349 +FrameworkView::OnDataShareRequested(IDataTransferManager* aDTM, 1.350 + IDataRequestedEventArgs* aArg) 1.351 +{ 1.352 + // Only share pages that contain a title and a URI 1.353 + nsCOMPtr<nsIMetroUIUtils> metroUIUtils = do_CreateInstance("@mozilla.org/metro-ui-utils;1"); 1.354 + if (!metroUIUtils) 1.355 + return E_FAIL; 1.356 + 1.357 + nsString url, title; 1.358 + nsresult rv = metroUIUtils->GetCurrentPageURI(url); 1.359 + nsresult rv2 = metroUIUtils->GetCurrentPageTitle(title); 1.360 + if (NS_FAILED(rv) || NS_FAILED(rv2)) { 1.361 + return E_FAIL; 1.362 + } 1.363 + 1.364 + // Get the package to share 1.365 + HRESULT hr; 1.366 + ComPtr<IDataRequest> request; 1.367 + AssertRetHRESULT(hr = aArg->get_Request(request.GetAddressOf()), hr); 1.368 + ComPtr<IDataPackage> dataPackage; 1.369 + AssertRetHRESULT(hr = request->get_Data(dataPackage.GetAddressOf()), hr); 1.370 + ComPtr<IDataPackagePropertySet> props; 1.371 + AssertRetHRESULT(hr = dataPackage->get_Properties(props.GetAddressOf()), hr); 1.372 + 1.373 + // Only add a URI to the package when there is no selected content. 1.374 + // This is because most programs treat URIs as highest priority to generate 1.375 + // their own preview, but we only want the selected content to show up. 1.376 + bool hasSelectedContent = false; 1.377 + metroUIUtils->GetHasSelectedContent(&hasSelectedContent); 1.378 + if (!hasSelectedContent) { 1.379 + ComPtr<IUriRuntimeClass> uri; 1.380 + AssertRetHRESULT(hr = MetroUtils::CreateUri(HStringReference(url.BeginReading()).Get(), uri), hr); 1.381 + 1.382 + // If there is no selection, then we don't support sharing for sites that 1.383 + // are not HTTP, HTTPS, FTP, and FILE. 1.384 + HString schemeHString; 1.385 + uri->get_SchemeName(schemeHString.GetAddressOf()); 1.386 + unsigned int length; 1.387 + LPCWSTR scheme = schemeHString.GetRawBuffer(&length); 1.388 + if (!scheme || wcscmp(scheme, L"http") && wcscmp(scheme, L"https") && 1.389 + wcscmp(scheme, L"ftp") && wcscmp(scheme, L"file")) { 1.390 + return S_OK; 1.391 + } 1.392 + 1.393 + AssertRetHRESULT(hr = dataPackage->SetUri(uri.Get()), hr); 1.394 + } 1.395 + 1.396 + // Add whatever content metroUIUtils wants us to for the text sharing 1.397 + nsString shareText; 1.398 + if (NS_SUCCEEDED(metroUIUtils->GetShareText(shareText)) && shareText.Length()) { 1.399 + AssertRetHRESULT(hr = dataPackage->SetText(HStringReference(shareText.BeginReading()).Get()) ,hr); 1.400 + } 1.401 + 1.402 + // Add whatever content metroUIUtils wants us to for the HTML sharing 1.403 + nsString shareHTML; 1.404 + if (NS_SUCCEEDED(metroUIUtils->GetShareHTML(shareHTML)) && shareHTML.Length()) { 1.405 + // The sharing format needs some special headers, so pass it through Windows 1.406 + ComPtr<IHtmlFormatHelperStatics> htmlFormatHelper; 1.407 + hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_ApplicationModel_DataTransfer_HtmlFormatHelper).Get(), 1.408 + htmlFormatHelper.GetAddressOf()); 1.409 + AssertRetHRESULT(hr, hr); 1.410 + HSTRING fixedHTML; 1.411 + htmlFormatHelper->CreateHtmlFormat(HStringReference(shareHTML.BeginReading()).Get(), &fixedHTML); 1.412 + 1.413 + // And now add the fixed HTML to the data package 1.414 + AssertRetHRESULT(hr = dataPackage->SetHtmlFormat(fixedHTML), hr); 1.415 + } 1.416 + 1.417 + // Obtain the brand name 1.418 + nsCOMPtr<nsIStringBundleService> bundleService = 1.419 + do_GetService(NS_STRINGBUNDLE_CONTRACTID); 1.420 + NS_ENSURE_TRUE(bundleService, E_FAIL); 1.421 + nsCOMPtr<nsIStringBundle> brandBundle; 1.422 + nsString brandName; 1.423 + bundleService->CreateBundle("chrome://branding/locale/brand.properties", 1.424 + getter_AddRefs(brandBundle)); 1.425 + NS_ENSURE_TRUE(brandBundle, E_FAIL); 1.426 + if(brandBundle) { 1.427 + brandBundle->GetStringFromName(MOZ_UTF16("brandFullName"), 1.428 + getter_Copies(brandName)); 1.429 + } 1.430 + 1.431 + // Set these properties at the end. Otherwise users can get a 1.432 + // "There was a problem with the data package" error when there 1.433 + // is simply nothing to share. 1.434 + props->put_ApplicationName(HStringReference(brandName.BeginReading()).Get()); 1.435 + if (title.Length()) { 1.436 + props->put_Title(HStringReference(title.BeginReading()).Get()); 1.437 + } else { 1.438 + props->put_Title(HStringReference(brandName.BeginReading()).Get()); 1.439 + } 1.440 + props->put_Description(HStringReference(url.BeginReading()).Get()); 1.441 + 1.442 + return S_OK; 1.443 +} 1.444 + 1.445 +HRESULT 1.446 +FrameworkView::OnSearchQuerySubmitted(ISearchPane* aPane, 1.447 + ISearchPaneQuerySubmittedEventArgs* aArgs) 1.448 +{ 1.449 + LogFunction(); 1.450 + HString aQuery; 1.451 + aArgs->get_QueryText(aQuery.GetAddressOf()); 1.452 + PerformURILoadOrSearch(aQuery); 1.453 + return S_OK; 1.454 +} 1.455 + 1.456 +HRESULT 1.457 +FrameworkView::OnSettingsCommandInvoked(IUICommand* aCommand) 1.458 +{ 1.459 + LogFunction(); 1.460 + HRESULT hr; 1.461 + uint32_t id; 1.462 + ComPtr<IPropertyValue> prop; 1.463 + AssertRetHRESULT(hr = aCommand->get_Id((IInspectable**)prop.GetAddressOf()), hr); 1.464 + AssertRetHRESULT(hr = prop->GetUInt32(&id), hr); 1.465 + 1.466 + nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService(); 1.467 + if (obs) { 1.468 + NS_ConvertASCIItoUTF16 idStr(nsPrintfCString("%lu", id)); 1.469 + obs->NotifyObservers(nullptr, "metro-settings-entry-selected", idStr.BeginReading()); 1.470 + } 1.471 + 1.472 + return S_OK; 1.473 +} 1.474 + 1.475 +void 1.476 +FrameworkView::AddSetting(ISettingsPaneCommandsRequestedEventArgs* aArgs, 1.477 + uint32_t aId, HString& aSettingName) 1.478 +{ 1.479 + HRESULT hr; 1.480 + 1.481 + ComPtr<ABI::Windows::UI::ApplicationSettings::ISettingsPaneCommandsRequest> request; 1.482 + AssertHRESULT(aArgs->get_Request(request.GetAddressOf())); 1.483 + 1.484 + // ApplicationCommands - vector that holds SettingsCommand to be invoked 1.485 + ComPtr<IVector<ABI::Windows::UI::ApplicationSettings::SettingsCommand*>> list; 1.486 + AssertHRESULT(request->get_ApplicationCommands(list.GetAddressOf())); 1.487 + 1.488 + ComPtr<IUICommand> command; 1.489 + ComPtr<ISettingsCommandFactory> factory; 1.490 + hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_UI_ApplicationSettings_SettingsCommand).Get(), 1.491 + factory.GetAddressOf()); 1.492 + AssertHRESULT(hr); 1.493 + 1.494 + // Create the IInspectable string property that identifies this command 1.495 + ComPtr<IInspectable> prop; 1.496 + ComPtr<IPropertyValueStatics> propStatics; 1.497 + hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_Foundation_PropertyValue).Get(), 1.498 + propStatics.GetAddressOf()); 1.499 + AssertHRESULT(hr); 1.500 + hr = propStatics->CreateUInt32(aId, prop.GetAddressOf()); 1.501 + AssertHRESULT(hr); 1.502 + 1.503 + // Create the command 1.504 + hr = factory->CreateSettingsCommand(prop.Get(), aSettingName.Get(), 1.505 + Callback<ABI::Windows::UI::Popups::IUICommandInvokedHandler>( 1.506 + this, &FrameworkView::OnSettingsCommandInvoked).Get(), command.GetAddressOf()); 1.507 + AssertHRESULT(hr); 1.508 + 1.509 + // Add it to the list 1.510 + hr = list->Append(command.Get()); 1.511 + AssertHRESULT(hr); 1.512 +} 1.513 + 1.514 +HRESULT 1.515 +FrameworkView::OnSettingsCommandsRequested(ISettingsPane* aPane, 1.516 + ISettingsPaneCommandsRequestedEventArgs* aArgs) 1.517 +{ 1.518 + if (!sSettingsArray) 1.519 + return E_FAIL; 1.520 + if (!sSettingsArray->Length()) 1.521 + return S_OK; 1.522 + for (uint32_t i = 0; i < sSettingsArray->Length(); i++) { 1.523 + HString label; 1.524 + label.Set(sSettingsArray->ElementAt(i).BeginReading()); 1.525 + AddSetting(aArgs, i, label); 1.526 + } 1.527 + return S_OK; 1.528 +} 1.529 + 1.530 +HRESULT 1.531 +FrameworkView::OnPlayToSourceRequested(IPlayToManager* aPlayToManager, 1.532 + IPlayToSourceRequestedEventArgs* aArgs) 1.533 +{ 1.534 + // TODO: Implement PlayTo, find the element on the page and then do something similar to this: 1.535 + // PlayToReceiver::Dispatcher.Helper.BeginInvoke( 1.536 + // mMediaElement = ref new Windows::UI::Xaml::Controls::MediaElement(); 1.537 + // mMediaElement->Source = ref new Uri("http://www.youtube.com/watch?v=2U0NFgoNI7s"); 1.538 + // aArgs->SourceRequest->SetSource(mMediaElement->PlayToSource); 1.539 + return S_OK; 1.540 +} 1.541 + 1.542 +HRESULT 1.543 +FrameworkView::OnPrintTaskSourceRequested(IPrintTaskSourceRequestedArgs* aArgs) 1.544 +{ 1.545 + return S_OK; 1.546 +} 1.547 + 1.548 +HRESULT 1.549 +FrameworkView::OnPrintTaskRequested(IPrintManager* aPrintManager, 1.550 + IPrintTaskRequestedEventArgs* aArgs) 1.551 +{ 1.552 + return S_OK; 1.553 +} 1.554 + 1.555 +void 1.556 +FrameworkView::CreatePrintControl(IPrintDocumentPackageTarget* docPackageTarget, 1.557 + D2D1_PRINT_CONTROL_PROPERTIES* printControlProperties) 1.558 +{ 1.559 +} 1.560 + 1.561 +HRESULT 1.562 +FrameworkView::ClosePrintControl() 1.563 +{ 1.564 + return S_OK; 1.565 +} 1.566 + 1.567 +// Print out one page, with the given print ticket. 1.568 +// This sample has only one page and we ignore pageNumber below. 1.569 +void FrameworkView::PrintPage(uint32_t pageNumber, 1.570 + D2D1_RECT_F imageableArea, 1.571 + D2D1_SIZE_F pageSize, 1.572 + IStream* pagePrintTicketStream) 1.573 +{ 1.574 +} 1.575 + 1.576 +} } }