// called after FrameworkView::Run() drops into the event dispatch loop void MetroApp::Initialize() { HRESULT hr; LogThread(); static bool xpcomInit; if (!xpcomInit) { xpcomInit = true; Log(L"XPCOM startup initialization began"); nsresult rv = XRE_metroStartup(); Log(L"XPCOM startup initialization complete"); if (NS_FAILED(rv)) { Log(L"XPCOM startup initialization failed, bailing. rv=%X", rv); CoreExit(); return; } } sFrameworkView->SetupContracts(); hr = sCoreApp->add_Suspending(Callback<__FIEventHandler_1_Windows__CApplicationModel__CSuspendingEventArgs_t>( this, &MetroApp::OnSuspending).Get(), &mSuspendEvent); AssertHRESULT(hr); hr = sCoreApp->add_Resuming(Callback<__FIEventHandler_1_IInspectable_t>( this, &MetroApp::OnResuming).Get(), &mResumeEvent); AssertHRESULT(hr); mozilla::widget::StartAudioSession(); }
void MetroApp::Run() { LogThread(); // Name this thread for debugging and register it with the profiler // as the main gecko thread. char aLocal; PR_SetCurrentThreadName(gGeckoThreadName); profiler_register_thread(gGeckoThreadName, &aLocal); HRESULT hr; hr = sCoreApp->add_Suspending(Callback<__FIEventHandler_1_Windows__CApplicationModel__CSuspendingEventArgs_t>( this, &MetroApp::OnSuspending).Get(), &mSuspendEvent); AssertHRESULT(hr); hr = sCoreApp->add_Resuming(Callback<__FIEventHandler_1_IInspectable_t>( this, &MetroApp::OnResuming).Get(), &mResumeEvent); AssertHRESULT(hr); Log("XPCOM startup initialization began"); nsresult rv = XRE_metroStartup(true); Log("XPCOM startup initialization complete"); if (NS_FAILED(rv)) { Log("XPCOM startup initialization failed, bailing. rv=%X", rv); CoreExit(); } }
void FrameworkView::SetupContracts() { LogFunction(); HRESULT hr; // Add support for the share charm to indicate that we share data to other apps ComPtr<IDataTransferManagerStatics> transStatics; hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_ApplicationModel_DataTransfer_DataTransferManager).Get(), transStatics.GetAddressOf()); AssertHRESULT(hr); ComPtr<IDataTransferManager> trans; AssertHRESULT(transStatics->GetForCurrentView(trans.GetAddressOf())); trans->add_DataRequested(Callback<__FITypedEventHandler_2_Windows__CApplicationModel__CDataTransfer__CDataTransferManager_Windows__CApplicationModel__CDataTransfer__CDataRequestedEventArgs_t>( this, &FrameworkView::OnDataShareRequested).Get(), &mDataTransferRequested); // Add support for the search charm to indicate that you can search using our app. ComPtr<ISearchPaneStatics> searchStatics; hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_ApplicationModel_Search_SearchPane).Get(), searchStatics.GetAddressOf()); AssertHRESULT(hr); ComPtr<ISearchPane> searchPane; AssertHRESULT(searchStatics->GetForCurrentView(searchPane.GetAddressOf())); searchPane->add_QuerySubmitted(Callback<__FITypedEventHandler_2_Windows__CApplicationModel__CSearch__CSearchPane_Windows__CApplicationModel__CSearch__CSearchPaneQuerySubmittedEventArgs_t>( this, &FrameworkView::OnSearchQuerySubmitted).Get(), &mSearchQuerySubmitted); // Add support for the devices play to charm ComPtr<IPlayToManagerStatics> playToStatics; hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_Media_PlayTo_PlayToManager).Get(), playToStatics.GetAddressOf()); AssertHRESULT(hr); ComPtr<IPlayToManager> playTo; AssertHRESULT(playToStatics->GetForCurrentView(playTo.GetAddressOf())); playTo->add_SourceRequested(Callback<__FITypedEventHandler_2_Windows__CMedia__CPlayTo__CPlayToManager_Windows__CMedia__CPlayTo__CPlayToSourceRequestedEventArgs_t>( this, &FrameworkView::OnPlayToSourceRequested).Get(), &mPlayToRequested); // Add support for the settings charm ComPtr<ISettingsPaneStatics> settingsPaneStatics; hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_UI_ApplicationSettings_SettingsPane).Get(), settingsPaneStatics.GetAddressOf()); AssertHRESULT(hr); ComPtr<ISettingsPane> settingsPane; AssertHRESULT(settingsPaneStatics->GetForCurrentView(settingsPane.GetAddressOf())); settingsPane->add_CommandsRequested(Callback<__FITypedEventHandler_2_Windows__CUI__CApplicationSettings__CSettingsPane_Windows__CUI__CApplicationSettings__CSettingsPaneCommandsRequestedEventArgs_t>( this, &FrameworkView::OnSettingsCommandsRequested).Get(), &mSettingsPane); // Add support for the settings print charm ComPtr<IPrintManagerStatic> printStatics; hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_Graphics_Printing_PrintManager).Get(), printStatics.GetAddressOf()); AssertHRESULT(hr); ComPtr<IPrintManager> printManager; AssertHRESULT(printStatics->GetForCurrentView(printManager.GetAddressOf())); printManager->add_PrintTaskRequested(Callback<__FITypedEventHandler_2_Windows__CGraphics__CPrinting__CPrintManager_Windows__CGraphics__CPrinting__CPrintTaskRequestedEventArgs_t>( this, &FrameworkView::OnPrintTaskRequested).Get(), &mPrintManager); }
void FrameworkView::UpdateLogicalDPI() { ComPtr<ABI::Windows::Graphics::Display::IDisplayPropertiesStatics> dispProps; HRESULT hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_Graphics_Display_DisplayProperties).Get(), dispProps.GetAddressOf()); AssertHRESULT(hr); FLOAT value; AssertHRESULT(dispProps->get_LogicalDpi(&value)); SetDpi(value); }
void FrameworkView::SetCursor(CoreCursorType aCursorType, DWORD aCustomId) { if (mShuttingDown) { return; } NS_ASSERTION(mWindow, "SetWindow must be called before SetCursor!"); ComPtr<ABI::Windows::UI::Core::ICoreCursorFactory> factory; AssertHRESULT(GetActivationFactory(HStringReference(RuntimeClass_Windows_UI_Core_CoreCursor).Get(), factory.GetAddressOf())); ComPtr<ABI::Windows::UI::Core::ICoreCursor> cursor; AssertHRESULT(factory->CreateCursor(aCursorType, aCustomId, cursor.GetAddressOf())); mWindow->put_PointerCursor(cursor.Get()); }
void FrameworkView::LaunchActivated(ComPtr<ILaunchActivatedEventArgs>& aArgs, bool aStartup) { if (!aArgs) return; HString data; AssertHRESULT(aArgs->get_Arguments(data.GetAddressOf())); if (WindowsIsStringEmpty(data.Get())) return; // If we're being launched from a secondary tile then we have a 2nd command line param of -url // and a third of the secondary tile. We want it in sActivationURI so that browser.js will // load it in without showing the start UI. int argc; unsigned int length; LPWSTR* argv = CommandLineToArgvW(data.GetRawBuffer(&length), &argc); if (aStartup && argc == 2 && !wcsicmp(argv[0], L"-url")) { WindowsCreateString(argv[1], wcslen(argv[1]), &sActivationURI); } else { // Some other command line or this is not a startup. // If it is startup we process it later when XPCOM is initialilzed. mActivationCommandLine = data.GetRawBuffer(&length); if (!aStartup) { ProcessLaunchArguments(); } } }
void FrameworkView::FileActivated(ComPtr<IFileActivatedEventArgs>& aArgs, bool aStartup) { if (!aArgs) return; ComPtr<IVectorView<ABI::Windows::Storage::IStorageItem*>> list; AssertHRESULT(aArgs->get_Files(list.GetAddressOf())); ComPtr<ABI::Windows::Storage::IStorageItem> item; AssertHRESULT(list->GetAt(0, item.GetAddressOf())); HString filePath; AssertHRESULT(item->get_Path(filePath.GetAddressOf())); if (aStartup) { WindowsDuplicateString(filePath.Get(), &sActivationURI); } else { PerformURILoad(filePath); } }
void FrameworkView::ProcessActivationArgs(IActivatedEventArgs* aArgs, bool aStartup) { ActivationKind kind; if (!aArgs || FAILED(aArgs->get_Kind(&kind))) return; ComPtr<IActivatedEventArgs> args(aArgs); if (kind == ActivationKind::ActivationKind_Protocol) { WinUtils::Log("Activation argument kind: Protocol"); ComPtr<IProtocolActivatedEventArgs> protoArgs; AssertHRESULT(args.As(&protoArgs)); ComPtr<IUriRuntimeClass> uri; AssertHRESULT(protoArgs->get_Uri(uri.GetAddressOf())); if (!uri) return; HString data; AssertHRESULT(uri->get_AbsoluteUri(data.GetAddressOf())); if (WindowsIsStringEmpty(data.Get())) return; if (aStartup) { WindowsDuplicateString(data.Get(), &sActivationURI); } else { PerformURILoad(data); } } else if (kind == ActivationKind::ActivationKind_Search) { WinUtils::Log("Activation argument kind: Search"); ComPtr<ISearchActivatedEventArgs> searchArgs; args.As(&searchArgs); SearchActivated(searchArgs, aStartup); } else if (kind == ActivationKind::ActivationKind_File) { WinUtils::Log("Activation argument kind: File"); ComPtr<IFileActivatedEventArgs> fileArgs; args.As(&fileArgs); FileActivated(fileArgs, aStartup); } else if (kind == ActivationKind::ActivationKind_Launch) { WinUtils::Log("Activation argument kind: Launch"); ComPtr<ILaunchActivatedEventArgs> launchArgs; args.As(&launchArgs); LaunchActivated(launchArgs, aStartup); } }
void FrameworkView::SearchActivated(ComPtr<ISearchActivatedEventArgs>& aArgs, bool aStartup) { if (!aArgs) return; HString data; AssertHRESULT(aArgs->get_QueryText(data.GetAddressOf())); if (WindowsIsStringEmpty(data.Get())) return; unsigned int length; WinUtils::LogW(L"SearchActivated text=%s", data.GetRawBuffer(&length)); if (aStartup) { WindowsDuplicateString(data.Get(), &sActivationURI); } else { PerformURILoadOrSearch(data); } }
void FrameworkView::AddSetting(ISettingsPaneCommandsRequestedEventArgs* aArgs, uint32_t aId, HString& aSettingName) { HRESULT hr; ComPtr<ABI::Windows::UI::ApplicationSettings::ISettingsPaneCommandsRequest> request; AssertHRESULT(aArgs->get_Request(request.GetAddressOf())); // ApplicationCommands - vector that holds SettingsCommand to be invoked ComPtr<IVector<ABI::Windows::UI::ApplicationSettings::SettingsCommand*>> list; AssertHRESULT(request->get_ApplicationCommands(list.GetAddressOf())); ComPtr<IUICommand> command; ComPtr<ISettingsCommandFactory> factory; hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_UI_ApplicationSettings_SettingsCommand).Get(), factory.GetAddressOf()); AssertHRESULT(hr); // Create the IInspectable string property that identifies this command ComPtr<IInspectable> prop; ComPtr<IPropertyValueStatics> propStatics; hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_Foundation_PropertyValue).Get(), propStatics.GetAddressOf()); AssertHRESULT(hr); hr = propStatics->CreateUInt32(aId, prop.GetAddressOf()); AssertHRESULT(hr); // Create the command hr = factory->CreateSettingsCommand(prop.Get(), aSettingName.Get(), Callback<ABI::Windows::UI::Popups::IUICommandInvokedHandler>( this, &FrameworkView::OnSettingsCommandInvoked).Get(), command.GetAddressOf()); AssertHRESULT(hr); // Add it to the list hr = list->Append(command.Get()); AssertHRESULT(hr); }