widget/windows/winrt/MetroContracts.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "FrameworkView.h"
michael@0 7 #include "MetroUtils.h"
michael@0 8 #include "nsICommandLineRunner.h"
michael@0 9 #include "nsNetUtil.h"
michael@0 10 #include "nsIDOMChromeWindow.h"
michael@0 11 #include "nsIURI.h"
michael@0 12 #include "nsPrintfCString.h"
michael@0 13 #include "mozilla/Services.h"
michael@0 14 #include <wrl/wrappers/corewrappers.h>
michael@0 15 #include <shellapi.h>
michael@0 16 #include <DXGIFormat.h>
michael@0 17 #include <d2d1_1.h>
michael@0 18 #include <printpreview.h>
michael@0 19 #include <D3D10.h>
michael@0 20 #include "MetroUIUtils.h"
michael@0 21 #include "nsIStringBundle.h"
michael@0 22
michael@0 23 using namespace mozilla;
michael@0 24 using namespace ABI::Windows::Foundation;
michael@0 25 using namespace ABI::Windows::Foundation::Collections;
michael@0 26 using namespace Microsoft::WRL;
michael@0 27 using namespace Microsoft::WRL::Wrappers;
michael@0 28
michael@0 29 // Play to contract
michael@0 30 using namespace ABI::Windows::Media::PlayTo;
michael@0 31
michael@0 32 // Activation contracts
michael@0 33 using namespace ABI::Windows::ApplicationModel::Activation;
michael@0 34 using namespace ABI::Windows::ApplicationModel::DataTransfer;
michael@0 35 using namespace ABI::Windows::ApplicationModel::Search;
michael@0 36
michael@0 37 // Settings contract
michael@0 38 using namespace ABI::Windows::UI::ApplicationSettings;
michael@0 39 using namespace ABI::Windows::UI::Popups;
michael@0 40
michael@0 41 // Print contract
michael@0 42 using namespace ABI::Windows::Graphics::Printing;
michael@0 43
michael@0 44 namespace mozilla {
michael@0 45 namespace widget {
michael@0 46 namespace winrt {
michael@0 47
michael@0 48 extern nsTArray<nsString>* sSettingsArray;
michael@0 49
michael@0 50 void
michael@0 51 FrameworkView::SearchActivated(ComPtr<ISearchActivatedEventArgs>& aArgs, bool aStartup)
michael@0 52 {
michael@0 53 if (!aArgs)
michael@0 54 return;
michael@0 55
michael@0 56 HString data;
michael@0 57 AssertHRESULT(aArgs->get_QueryText(data.GetAddressOf()));
michael@0 58 if (WindowsIsStringEmpty(data.Get()))
michael@0 59 return;
michael@0 60
michael@0 61 unsigned int length;
michael@0 62 WinUtils::LogW(L"SearchActivated text=%s", data.GetRawBuffer(&length));
michael@0 63 if (aStartup) {
michael@0 64 WindowsDuplicateString(data.Get(), &sActivationURI);
michael@0 65 } else {
michael@0 66 PerformURILoadOrSearch(data);
michael@0 67 }
michael@0 68 }
michael@0 69
michael@0 70 void
michael@0 71 FrameworkView::FileActivated(ComPtr<IFileActivatedEventArgs>& aArgs, bool aStartup)
michael@0 72 {
michael@0 73 if (!aArgs)
michael@0 74 return;
michael@0 75
michael@0 76 ComPtr<IVectorView<ABI::Windows::Storage::IStorageItem*>> list;
michael@0 77 AssertHRESULT(aArgs->get_Files(list.GetAddressOf()));
michael@0 78 ComPtr<ABI::Windows::Storage::IStorageItem> item;
michael@0 79 AssertHRESULT(list->GetAt(0, item.GetAddressOf()));
michael@0 80 HString filePath;
michael@0 81 AssertHRESULT(item->get_Path(filePath.GetAddressOf()));
michael@0 82
michael@0 83 if (aStartup) {
michael@0 84 WindowsDuplicateString(filePath.Get(), &sActivationURI);
michael@0 85 } else {
michael@0 86 PerformURILoad(filePath);
michael@0 87 }
michael@0 88 }
michael@0 89
michael@0 90 void
michael@0 91 FrameworkView::LaunchActivated(ComPtr<ILaunchActivatedEventArgs>& aArgs, bool aStartup)
michael@0 92 {
michael@0 93 if (!aArgs)
michael@0 94 return;
michael@0 95 HString data;
michael@0 96 AssertHRESULT(aArgs->get_Arguments(data.GetAddressOf()));
michael@0 97 if (WindowsIsStringEmpty(data.Get()))
michael@0 98 return;
michael@0 99
michael@0 100 // If we're being launched from a secondary tile then we have a 2nd command line param of -url
michael@0 101 // and a third of the secondary tile. We want it in sActivationURI so that browser.js will
michael@0 102 // load it in without showing the start UI.
michael@0 103 int argc;
michael@0 104 unsigned int length;
michael@0 105 LPWSTR* argv = CommandLineToArgvW(data.GetRawBuffer(&length), &argc);
michael@0 106 if (aStartup && argc == 2 && !wcsicmp(argv[0], L"-url")) {
michael@0 107 WindowsCreateString(argv[1], wcslen(argv[1]), &sActivationURI);
michael@0 108 } else {
michael@0 109 // Some other command line or this is not a startup.
michael@0 110 // If it is startup we process it later when XPCOM is initialilzed.
michael@0 111 mActivationCommandLine = data.GetRawBuffer(&length);
michael@0 112 if (!aStartup) {
michael@0 113 ProcessLaunchArguments();
michael@0 114 }
michael@0 115 }
michael@0 116 }
michael@0 117
michael@0 118 void
michael@0 119 FrameworkView::ProcessLaunchArguments()
michael@0 120 {
michael@0 121 if (!mActivationCommandLine.Length())
michael@0 122 return;
michael@0 123
michael@0 124 int argc;
michael@0 125 LPWSTR* argv = CommandLineToArgvW(mActivationCommandLine.BeginReading(), &argc);
michael@0 126 nsCOMPtr<nsICommandLineRunner> cmdLine =
michael@0 127 (do_CreateInstance("@mozilla.org/toolkit/command-line;1"));
michael@0 128 if (!cmdLine) {
michael@0 129 NS_WARNING("Unable to instantiate command line runner.");
michael@0 130 return;
michael@0 131 }
michael@0 132
michael@0 133 LPSTR *argvUTF8 = new LPSTR[argc];
michael@0 134 for (int i = 0; i < argc; ++i) {
michael@0 135 NS_ConvertUTF16toUTF8 arg(argv[i]);
michael@0 136 argvUTF8[i] = new char[arg.Length() + 1];
michael@0 137 strcpy(argvUTF8[i], const_cast<char *>(arg.BeginReading()));
michael@0 138 WinUtils::LogW(L"Launch arg[%d]: '%s'", i, argv[i]);
michael@0 139 }
michael@0 140
michael@0 141 nsresult rv = cmdLine->Init(argc,
michael@0 142 argvUTF8,
michael@0 143 nullptr,
michael@0 144 nsICommandLine::STATE_REMOTE_EXPLICIT);
michael@0 145 if (NS_SUCCEEDED(rv)) {
michael@0 146 cmdLine->Run();
michael@0 147 } else {
michael@0 148 NS_WARNING("cmdLine->Init failed.");
michael@0 149 }
michael@0 150
michael@0 151 for (int i = 0; i < argc; ++i) {
michael@0 152 delete[] argvUTF8[i];
michael@0 153 }
michael@0 154 delete[] argvUTF8;
michael@0 155 }
michael@0 156
michael@0 157 void
michael@0 158 FrameworkView::ProcessActivationArgs(IActivatedEventArgs* aArgs, bool aStartup)
michael@0 159 {
michael@0 160 ActivationKind kind;
michael@0 161 if (!aArgs || FAILED(aArgs->get_Kind(&kind)))
michael@0 162 return;
michael@0 163 ComPtr<IActivatedEventArgs> args(aArgs);
michael@0 164 if (kind == ActivationKind::ActivationKind_Protocol) {
michael@0 165 WinUtils::Log("Activation argument kind: Protocol");
michael@0 166 ComPtr<IProtocolActivatedEventArgs> protoArgs;
michael@0 167 AssertHRESULT(args.As(&protoArgs));
michael@0 168 ComPtr<IUriRuntimeClass> uri;
michael@0 169 AssertHRESULT(protoArgs->get_Uri(uri.GetAddressOf()));
michael@0 170 if (!uri)
michael@0 171 return;
michael@0 172
michael@0 173 HString data;
michael@0 174 AssertHRESULT(uri->get_AbsoluteUri(data.GetAddressOf()));
michael@0 175 if (WindowsIsStringEmpty(data.Get()))
michael@0 176 return;
michael@0 177
michael@0 178 if (aStartup) {
michael@0 179 WindowsDuplicateString(data.Get(), &sActivationURI);
michael@0 180 } else {
michael@0 181 PerformURILoad(data);
michael@0 182 }
michael@0 183 } else if (kind == ActivationKind::ActivationKind_Search) {
michael@0 184 WinUtils::Log("Activation argument kind: Search");
michael@0 185 ComPtr<ISearchActivatedEventArgs> searchArgs;
michael@0 186 args.As(&searchArgs);
michael@0 187 SearchActivated(searchArgs, aStartup);
michael@0 188 } else if (kind == ActivationKind::ActivationKind_File) {
michael@0 189 WinUtils::Log("Activation argument kind: File");
michael@0 190 ComPtr<IFileActivatedEventArgs> fileArgs;
michael@0 191 args.As(&fileArgs);
michael@0 192 FileActivated(fileArgs, aStartup);
michael@0 193 } else if (kind == ActivationKind::ActivationKind_Launch) {
michael@0 194 WinUtils::Log("Activation argument kind: Launch");
michael@0 195 ComPtr<ILaunchActivatedEventArgs> launchArgs;
michael@0 196 args.As(&launchArgs);
michael@0 197 LaunchActivated(launchArgs, aStartup);
michael@0 198 }
michael@0 199 }
michael@0 200
michael@0 201 void
michael@0 202 FrameworkView::SetupContracts()
michael@0 203 {
michael@0 204 LogFunction();
michael@0 205 HRESULT hr;
michael@0 206
michael@0 207 // Add support for the share charm to indicate that we share data to other apps
michael@0 208 ComPtr<IDataTransferManagerStatics> transStatics;
michael@0 209 hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_ApplicationModel_DataTransfer_DataTransferManager).Get(),
michael@0 210 transStatics.GetAddressOf());
michael@0 211 AssertHRESULT(hr);
michael@0 212 ComPtr<IDataTransferManager> trans;
michael@0 213 AssertHRESULT(transStatics->GetForCurrentView(trans.GetAddressOf()));
michael@0 214 trans->add_DataRequested(Callback<__FITypedEventHandler_2_Windows__CApplicationModel__CDataTransfer__CDataTransferManager_Windows__CApplicationModel__CDataTransfer__CDataRequestedEventArgs_t>(
michael@0 215 this, &FrameworkView::OnDataShareRequested).Get(), &mDataTransferRequested);
michael@0 216
michael@0 217 // Add support for the search charm to indicate that you can search using our app.
michael@0 218 ComPtr<ISearchPaneStatics> searchStatics;
michael@0 219 hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_ApplicationModel_Search_SearchPane).Get(),
michael@0 220 searchStatics.GetAddressOf());
michael@0 221 AssertHRESULT(hr);
michael@0 222 ComPtr<ISearchPane> searchPane;
michael@0 223 AssertHRESULT(searchStatics->GetForCurrentView(searchPane.GetAddressOf()));
michael@0 224 searchPane->add_QuerySubmitted(Callback<__FITypedEventHandler_2_Windows__CApplicationModel__CSearch__CSearchPane_Windows__CApplicationModel__CSearch__CSearchPaneQuerySubmittedEventArgs_t>(
michael@0 225 this, &FrameworkView::OnSearchQuerySubmitted).Get(), &mSearchQuerySubmitted);
michael@0 226
michael@0 227 // Add support for the devices play to charm
michael@0 228 ComPtr<IPlayToManagerStatics> playToStatics;
michael@0 229 hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_Media_PlayTo_PlayToManager).Get(),
michael@0 230 playToStatics.GetAddressOf());
michael@0 231 AssertHRESULT(hr);
michael@0 232 ComPtr<IPlayToManager> playTo;
michael@0 233 AssertHRESULT(playToStatics->GetForCurrentView(playTo.GetAddressOf()));
michael@0 234 playTo->add_SourceRequested(Callback<__FITypedEventHandler_2_Windows__CMedia__CPlayTo__CPlayToManager_Windows__CMedia__CPlayTo__CPlayToSourceRequestedEventArgs_t>(
michael@0 235 this, &FrameworkView::OnPlayToSourceRequested).Get(), &mPlayToRequested);
michael@0 236
michael@0 237 // Add support for the settings charm
michael@0 238 ComPtr<ISettingsPaneStatics> settingsPaneStatics;
michael@0 239 hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_UI_ApplicationSettings_SettingsPane).Get(),
michael@0 240 settingsPaneStatics.GetAddressOf());
michael@0 241 AssertHRESULT(hr);
michael@0 242 ComPtr<ISettingsPane> settingsPane;
michael@0 243 AssertHRESULT(settingsPaneStatics->GetForCurrentView(settingsPane.GetAddressOf()));
michael@0 244 settingsPane->add_CommandsRequested(Callback<__FITypedEventHandler_2_Windows__CUI__CApplicationSettings__CSettingsPane_Windows__CUI__CApplicationSettings__CSettingsPaneCommandsRequestedEventArgs_t>(
michael@0 245 this, &FrameworkView::OnSettingsCommandsRequested).Get(), &mSettingsPane);
michael@0 246
michael@0 247 // Add support for the settings print charm
michael@0 248 ComPtr<IPrintManagerStatic> printStatics;
michael@0 249 hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_Graphics_Printing_PrintManager).Get(),
michael@0 250 printStatics.GetAddressOf());
michael@0 251 AssertHRESULT(hr);
michael@0 252 ComPtr<IPrintManager> printManager;
michael@0 253 AssertHRESULT(printStatics->GetForCurrentView(printManager.GetAddressOf()));
michael@0 254 printManager->add_PrintTaskRequested(Callback<__FITypedEventHandler_2_Windows__CGraphics__CPrinting__CPrintManager_Windows__CGraphics__CPrinting__CPrintTaskRequestedEventArgs_t>(
michael@0 255 this, &FrameworkView::OnPrintTaskRequested).Get(), &mPrintManager);
michael@0 256 }
michael@0 257
michael@0 258 void
michael@0 259 FrameworkView::PerformURILoad(HString& aURI)
michael@0 260 {
michael@0 261 LogFunction();
michael@0 262
michael@0 263 unsigned int length;
michael@0 264 WinUtils::LogW(L"PerformURILoad uri=%s", aURI.GetRawBuffer(&length));
michael@0 265
michael@0 266 nsCOMPtr<nsICommandLineRunner> cmdLine =
michael@0 267 (do_CreateInstance("@mozilla.org/toolkit/command-line;1"));
michael@0 268 if (!cmdLine) {
michael@0 269 NS_WARNING("Unable to instantiate command line runner.");
michael@0 270 return;
michael@0 271 }
michael@0 272
michael@0 273 nsAutoCString utf8data(NS_ConvertUTF16toUTF8(aURI.GetRawBuffer(&length)));
michael@0 274
michael@0 275 // NB: The first argument gets stripped by nsICommandLineRunner::Init,
michael@0 276 // so it doesn't matter what we pass as the first argument, but we
michael@0 277 // have to pass something.
michael@0 278 const char *argv[] = { "", // This argument gets stripped
michael@0 279 "-url",
michael@0 280 utf8data.BeginReading() };
michael@0 281 nsresult rv = cmdLine->Init(ArrayLength(argv),
michael@0 282 const_cast<char **>(argv), nullptr,
michael@0 283 nsICommandLine::STATE_REMOTE_EXPLICIT);
michael@0 284 if (NS_FAILED(rv)) {
michael@0 285 NS_WARNING("cmdLine->Init failed.");
michael@0 286 return;
michael@0 287 }
michael@0 288 cmdLine->Run();
michael@0 289 }
michael@0 290
michael@0 291 void
michael@0 292 FrameworkView::PerformSearch(HString& aQuery)
michael@0 293 {
michael@0 294 LogFunction();
michael@0 295
michael@0 296 nsCOMPtr<nsICommandLineRunner> cmdLine =
michael@0 297 (do_CreateInstance("@mozilla.org/toolkit/command-line;1"));
michael@0 298 if (!cmdLine) {
michael@0 299 NS_WARNING("Unable to instantiate command line runner.");
michael@0 300 return;
michael@0 301 }
michael@0 302
michael@0 303 nsAutoCString parameter;
michael@0 304 parameter.AppendLiteral("\"");
michael@0 305 unsigned int length;
michael@0 306 parameter.Append(NS_ConvertUTF16toUTF8(aQuery.GetRawBuffer(&length)));
michael@0 307 parameter.AppendLiteral("\"");
michael@0 308
michael@0 309 // NB: The first argument gets stripped by nsICommandLineRunner::Init,
michael@0 310 // so it doesn't matter what we pass as the first argument, but we
michael@0 311 // have to pass something.
michael@0 312 const char *argv[] = { "", // This argument gets stripped
michael@0 313 "-search",
michael@0 314 parameter.BeginReading() };
michael@0 315 nsresult rv = cmdLine->Init(ArrayLength(argv),
michael@0 316 const_cast<char **>(argv), nullptr,
michael@0 317 nsICommandLine::STATE_REMOTE_EXPLICIT);
michael@0 318 if (NS_FAILED(rv)) {
michael@0 319 NS_WARNING("cmdLine->Init failed.");
michael@0 320 return;
michael@0 321 }
michael@0 322 cmdLine->Run();
michael@0 323 }
michael@0 324
michael@0 325 void
michael@0 326 FrameworkView::PerformURILoadOrSearch(HString& aString)
michael@0 327 {
michael@0 328 LogFunction();
michael@0 329
michael@0 330 if (WindowsIsStringEmpty(aString.Get())) {
michael@0 331 WinUtils::Log("Emptry string passed to PerformURILoadOrSearch");
michael@0 332 return;
michael@0 333 }
michael@0 334
michael@0 335 // If we have a URI then devert to load the URI directly
michael@0 336 ComPtr<IUriRuntimeClass> uri;
michael@0 337 MetroUtils::CreateUri(aString.Get(), uri);
michael@0 338 if (uri) {
michael@0 339 PerformURILoad(aString);
michael@0 340 } else {
michael@0 341 PerformSearch(aString);
michael@0 342 }
michael@0 343 }
michael@0 344
michael@0 345 HRESULT
michael@0 346 FrameworkView::OnDataShareRequested(IDataTransferManager* aDTM,
michael@0 347 IDataRequestedEventArgs* aArg)
michael@0 348 {
michael@0 349 // Only share pages that contain a title and a URI
michael@0 350 nsCOMPtr<nsIMetroUIUtils> metroUIUtils = do_CreateInstance("@mozilla.org/metro-ui-utils;1");
michael@0 351 if (!metroUIUtils)
michael@0 352 return E_FAIL;
michael@0 353
michael@0 354 nsString url, title;
michael@0 355 nsresult rv = metroUIUtils->GetCurrentPageURI(url);
michael@0 356 nsresult rv2 = metroUIUtils->GetCurrentPageTitle(title);
michael@0 357 if (NS_FAILED(rv) || NS_FAILED(rv2)) {
michael@0 358 return E_FAIL;
michael@0 359 }
michael@0 360
michael@0 361 // Get the package to share
michael@0 362 HRESULT hr;
michael@0 363 ComPtr<IDataRequest> request;
michael@0 364 AssertRetHRESULT(hr = aArg->get_Request(request.GetAddressOf()), hr);
michael@0 365 ComPtr<IDataPackage> dataPackage;
michael@0 366 AssertRetHRESULT(hr = request->get_Data(dataPackage.GetAddressOf()), hr);
michael@0 367 ComPtr<IDataPackagePropertySet> props;
michael@0 368 AssertRetHRESULT(hr = dataPackage->get_Properties(props.GetAddressOf()), hr);
michael@0 369
michael@0 370 // Only add a URI to the package when there is no selected content.
michael@0 371 // This is because most programs treat URIs as highest priority to generate
michael@0 372 // their own preview, but we only want the selected content to show up.
michael@0 373 bool hasSelectedContent = false;
michael@0 374 metroUIUtils->GetHasSelectedContent(&hasSelectedContent);
michael@0 375 if (!hasSelectedContent) {
michael@0 376 ComPtr<IUriRuntimeClass> uri;
michael@0 377 AssertRetHRESULT(hr = MetroUtils::CreateUri(HStringReference(url.BeginReading()).Get(), uri), hr);
michael@0 378
michael@0 379 // If there is no selection, then we don't support sharing for sites that
michael@0 380 // are not HTTP, HTTPS, FTP, and FILE.
michael@0 381 HString schemeHString;
michael@0 382 uri->get_SchemeName(schemeHString.GetAddressOf());
michael@0 383 unsigned int length;
michael@0 384 LPCWSTR scheme = schemeHString.GetRawBuffer(&length);
michael@0 385 if (!scheme || wcscmp(scheme, L"http") && wcscmp(scheme, L"https") &&
michael@0 386 wcscmp(scheme, L"ftp") && wcscmp(scheme, L"file")) {
michael@0 387 return S_OK;
michael@0 388 }
michael@0 389
michael@0 390 AssertRetHRESULT(hr = dataPackage->SetUri(uri.Get()), hr);
michael@0 391 }
michael@0 392
michael@0 393 // Add whatever content metroUIUtils wants us to for the text sharing
michael@0 394 nsString shareText;
michael@0 395 if (NS_SUCCEEDED(metroUIUtils->GetShareText(shareText)) && shareText.Length()) {
michael@0 396 AssertRetHRESULT(hr = dataPackage->SetText(HStringReference(shareText.BeginReading()).Get()) ,hr);
michael@0 397 }
michael@0 398
michael@0 399 // Add whatever content metroUIUtils wants us to for the HTML sharing
michael@0 400 nsString shareHTML;
michael@0 401 if (NS_SUCCEEDED(metroUIUtils->GetShareHTML(shareHTML)) && shareHTML.Length()) {
michael@0 402 // The sharing format needs some special headers, so pass it through Windows
michael@0 403 ComPtr<IHtmlFormatHelperStatics> htmlFormatHelper;
michael@0 404 hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_ApplicationModel_DataTransfer_HtmlFormatHelper).Get(),
michael@0 405 htmlFormatHelper.GetAddressOf());
michael@0 406 AssertRetHRESULT(hr, hr);
michael@0 407 HSTRING fixedHTML;
michael@0 408 htmlFormatHelper->CreateHtmlFormat(HStringReference(shareHTML.BeginReading()).Get(), &fixedHTML);
michael@0 409
michael@0 410 // And now add the fixed HTML to the data package
michael@0 411 AssertRetHRESULT(hr = dataPackage->SetHtmlFormat(fixedHTML), hr);
michael@0 412 }
michael@0 413
michael@0 414 // Obtain the brand name
michael@0 415 nsCOMPtr<nsIStringBundleService> bundleService =
michael@0 416 do_GetService(NS_STRINGBUNDLE_CONTRACTID);
michael@0 417 NS_ENSURE_TRUE(bundleService, E_FAIL);
michael@0 418 nsCOMPtr<nsIStringBundle> brandBundle;
michael@0 419 nsString brandName;
michael@0 420 bundleService->CreateBundle("chrome://branding/locale/brand.properties",
michael@0 421 getter_AddRefs(brandBundle));
michael@0 422 NS_ENSURE_TRUE(brandBundle, E_FAIL);
michael@0 423 if(brandBundle) {
michael@0 424 brandBundle->GetStringFromName(MOZ_UTF16("brandFullName"),
michael@0 425 getter_Copies(brandName));
michael@0 426 }
michael@0 427
michael@0 428 // Set these properties at the end. Otherwise users can get a
michael@0 429 // "There was a problem with the data package" error when there
michael@0 430 // is simply nothing to share.
michael@0 431 props->put_ApplicationName(HStringReference(brandName.BeginReading()).Get());
michael@0 432 if (title.Length()) {
michael@0 433 props->put_Title(HStringReference(title.BeginReading()).Get());
michael@0 434 } else {
michael@0 435 props->put_Title(HStringReference(brandName.BeginReading()).Get());
michael@0 436 }
michael@0 437 props->put_Description(HStringReference(url.BeginReading()).Get());
michael@0 438
michael@0 439 return S_OK;
michael@0 440 }
michael@0 441
michael@0 442 HRESULT
michael@0 443 FrameworkView::OnSearchQuerySubmitted(ISearchPane* aPane,
michael@0 444 ISearchPaneQuerySubmittedEventArgs* aArgs)
michael@0 445 {
michael@0 446 LogFunction();
michael@0 447 HString aQuery;
michael@0 448 aArgs->get_QueryText(aQuery.GetAddressOf());
michael@0 449 PerformURILoadOrSearch(aQuery);
michael@0 450 return S_OK;
michael@0 451 }
michael@0 452
michael@0 453 HRESULT
michael@0 454 FrameworkView::OnSettingsCommandInvoked(IUICommand* aCommand)
michael@0 455 {
michael@0 456 LogFunction();
michael@0 457 HRESULT hr;
michael@0 458 uint32_t id;
michael@0 459 ComPtr<IPropertyValue> prop;
michael@0 460 AssertRetHRESULT(hr = aCommand->get_Id((IInspectable**)prop.GetAddressOf()), hr);
michael@0 461 AssertRetHRESULT(hr = prop->GetUInt32(&id), hr);
michael@0 462
michael@0 463 nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
michael@0 464 if (obs) {
michael@0 465 NS_ConvertASCIItoUTF16 idStr(nsPrintfCString("%lu", id));
michael@0 466 obs->NotifyObservers(nullptr, "metro-settings-entry-selected", idStr.BeginReading());
michael@0 467 }
michael@0 468
michael@0 469 return S_OK;
michael@0 470 }
michael@0 471
michael@0 472 void
michael@0 473 FrameworkView::AddSetting(ISettingsPaneCommandsRequestedEventArgs* aArgs,
michael@0 474 uint32_t aId, HString& aSettingName)
michael@0 475 {
michael@0 476 HRESULT hr;
michael@0 477
michael@0 478 ComPtr<ABI::Windows::UI::ApplicationSettings::ISettingsPaneCommandsRequest> request;
michael@0 479 AssertHRESULT(aArgs->get_Request(request.GetAddressOf()));
michael@0 480
michael@0 481 // ApplicationCommands - vector that holds SettingsCommand to be invoked
michael@0 482 ComPtr<IVector<ABI::Windows::UI::ApplicationSettings::SettingsCommand*>> list;
michael@0 483 AssertHRESULT(request->get_ApplicationCommands(list.GetAddressOf()));
michael@0 484
michael@0 485 ComPtr<IUICommand> command;
michael@0 486 ComPtr<ISettingsCommandFactory> factory;
michael@0 487 hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_UI_ApplicationSettings_SettingsCommand).Get(),
michael@0 488 factory.GetAddressOf());
michael@0 489 AssertHRESULT(hr);
michael@0 490
michael@0 491 // Create the IInspectable string property that identifies this command
michael@0 492 ComPtr<IInspectable> prop;
michael@0 493 ComPtr<IPropertyValueStatics> propStatics;
michael@0 494 hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_Foundation_PropertyValue).Get(),
michael@0 495 propStatics.GetAddressOf());
michael@0 496 AssertHRESULT(hr);
michael@0 497 hr = propStatics->CreateUInt32(aId, prop.GetAddressOf());
michael@0 498 AssertHRESULT(hr);
michael@0 499
michael@0 500 // Create the command
michael@0 501 hr = factory->CreateSettingsCommand(prop.Get(), aSettingName.Get(),
michael@0 502 Callback<ABI::Windows::UI::Popups::IUICommandInvokedHandler>(
michael@0 503 this, &FrameworkView::OnSettingsCommandInvoked).Get(), command.GetAddressOf());
michael@0 504 AssertHRESULT(hr);
michael@0 505
michael@0 506 // Add it to the list
michael@0 507 hr = list->Append(command.Get());
michael@0 508 AssertHRESULT(hr);
michael@0 509 }
michael@0 510
michael@0 511 HRESULT
michael@0 512 FrameworkView::OnSettingsCommandsRequested(ISettingsPane* aPane,
michael@0 513 ISettingsPaneCommandsRequestedEventArgs* aArgs)
michael@0 514 {
michael@0 515 if (!sSettingsArray)
michael@0 516 return E_FAIL;
michael@0 517 if (!sSettingsArray->Length())
michael@0 518 return S_OK;
michael@0 519 for (uint32_t i = 0; i < sSettingsArray->Length(); i++) {
michael@0 520 HString label;
michael@0 521 label.Set(sSettingsArray->ElementAt(i).BeginReading());
michael@0 522 AddSetting(aArgs, i, label);
michael@0 523 }
michael@0 524 return S_OK;
michael@0 525 }
michael@0 526
michael@0 527 HRESULT
michael@0 528 FrameworkView::OnPlayToSourceRequested(IPlayToManager* aPlayToManager,
michael@0 529 IPlayToSourceRequestedEventArgs* aArgs)
michael@0 530 {
michael@0 531 // TODO: Implement PlayTo, find the element on the page and then do something similar to this:
michael@0 532 // PlayToReceiver::Dispatcher.Helper.BeginInvoke(
michael@0 533 // mMediaElement = ref new Windows::UI::Xaml::Controls::MediaElement();
michael@0 534 // mMediaElement->Source = ref new Uri("http://www.youtube.com/watch?v=2U0NFgoNI7s");
michael@0 535 // aArgs->SourceRequest->SetSource(mMediaElement->PlayToSource);
michael@0 536 return S_OK;
michael@0 537 }
michael@0 538
michael@0 539 HRESULT
michael@0 540 FrameworkView::OnPrintTaskSourceRequested(IPrintTaskSourceRequestedArgs* aArgs)
michael@0 541 {
michael@0 542 return S_OK;
michael@0 543 }
michael@0 544
michael@0 545 HRESULT
michael@0 546 FrameworkView::OnPrintTaskRequested(IPrintManager* aPrintManager,
michael@0 547 IPrintTaskRequestedEventArgs* aArgs)
michael@0 548 {
michael@0 549 return S_OK;
michael@0 550 }
michael@0 551
michael@0 552 void
michael@0 553 FrameworkView::CreatePrintControl(IPrintDocumentPackageTarget* docPackageTarget,
michael@0 554 D2D1_PRINT_CONTROL_PROPERTIES* printControlProperties)
michael@0 555 {
michael@0 556 }
michael@0 557
michael@0 558 HRESULT
michael@0 559 FrameworkView::ClosePrintControl()
michael@0 560 {
michael@0 561 return S_OK;
michael@0 562 }
michael@0 563
michael@0 564 // Print out one page, with the given print ticket.
michael@0 565 // This sample has only one page and we ignore pageNumber below.
michael@0 566 void FrameworkView::PrintPage(uint32_t pageNumber,
michael@0 567 D2D1_RECT_F imageableArea,
michael@0 568 D2D1_SIZE_F pageSize,
michael@0 569 IStream* pagePrintTicketStream)
michael@0 570 {
michael@0 571 }
michael@0 572
michael@0 573 } } }

mercurial