Пример #1
0
void
DisableBatteryNotifications()
{
  if (IsVistaOrLater()) {
    if (sPowerHandle) {
      sUnregisterPowerSettingNotification(sPowerHandle);
      sPowerHandle = nullptr;
    }

    if (sCapacityHandle) {
      sUnregisterPowerSettingNotification(sCapacityHandle);
      sCapacityHandle = nullptr;
    }

    if (sHWnd) {
      DestroyWindow(sHWnd);
      sHWnd = nullptr;
    }
  } else
  {
    if (sUpdateTimer) {
      sUpdateTimer->Cancel();
      sUpdateTimer = nullptr;
    }
  }
}
Пример #2
0
/* static */
bool
MediaKeySystemAccess::IsKeySystemSupported(const nsAString& aKeySystem)
{
  nsCOMPtr<mozIGeckoMediaPluginService> mps =
    do_GetService("@mozilla.org/gecko-media-plugin-service;1");
  if (NS_WARN_IF(!mps)) {
    return false;
  }

  if (aKeySystem.EqualsLiteral("org.w3.clearkey") &&
      HaveGMPFor(mps,
                 NS_LITERAL_CSTRING("org.w3.clearkey"),
                 NS_LITERAL_CSTRING(GMP_API_DECRYPTOR))) {
    return true;
  }

#ifdef XP_WIN
  if ((aKeySystem.EqualsLiteral("com.adobe.access") ||
       aKeySystem.EqualsLiteral("com.adobe.primetime")) &&
      Preferences::GetBool("media.eme.adobe-access.enabled", false) &&
      IsVistaOrLater() && // Win Vista and later only.
      HaveGMPFor(mps,
                 NS_ConvertUTF16toUTF8(aKeySystem),
                 NS_LITERAL_CSTRING(GMP_API_DECRYPTOR))) {
      return true;
  }
#endif

  return false;
}
Пример #3
0
void
DisableBatteryNotifications()
{
#if MOZ_WINSDK_TARGETVER >= MOZ_NTDDI_LONGHORN
  if (IsVistaOrLater()) {
    if (sPowerHandle) {
      sUnregisterPowerSettingNotification(sPowerHandle);
      sPowerHandle = nsnull;
    }

    if (sCapacityHandle) {
      sUnregisterPowerSettingNotification(sCapacityHandle);
      sCapacityHandle = nsnull;
    }

    if (sHWnd) {
      DestroyWindow(sHWnd);
      sHWnd = nsnull;
    }
  } else
#endif
  {
    if (sUpdateTimer) {
      sUpdateTimer->Cancel();
      sUpdateTimer = nsnull;
    }
  }
}
Пример #4
0
UINT CGitExtensionsShellEx::AddMenuItem(HMENU hMenu, LPTSTR text, int resource, UINT uidFirstCmd, UINT id, UINT position, bool isSubMenu)
{
    MENUITEMINFO mii;
    memset(&mii, 0, sizeof(mii));
    mii.cbSize = sizeof(mii);
    mii.fMask = MIIM_STRING | MIIM_ID;
    if (resource)
    {
        mii.fMask |= MIIM_BITMAP;
        mii.hbmpItem = IsVistaOrLater() ? IconToBitmapPARGB32(resource) : HBMMENU_CALLBACK;
        myIDMap[id] = resource;
        myIDMap[uidFirstCmd + id] = resource;
    }
    mii.wID	= uidFirstCmd + id;
    std::wstring textEx;
    if (isSubMenu)
        mii.dwTypeData = text;
    else
    {
        textEx = std::wstring(L"GitEx ") + text;
        mii.dwTypeData = &textEx[0];
    }

    InsertMenuItem(hMenu, position, TRUE, &mii);
    return id;
}
Пример #5
0
/* static */
bool
WMFDecoder::IsEnabled()
{
  // We only use WMF on Windows Vista and up
  return IsVistaOrLater() &&
         Preferences::GetBool("media.windows-media-foundation.enabled");
}
Пример #6
0
static bool
IsSandboxTempDirRequired()
{
  // On Windows, a sandbox-writable temp directory is only used
  // for Vista or later with sandbox pref level >= 1.
  return (IsVistaOrLater() &&
    (Preferences::GetInt("security.sandbox.content.level") >= 1));
}
Пример #7
0
bool
MediaEngineWebRTC::SupportsDuplex()
{
#ifndef XP_WIN
  return mFullDuplex;
#else
  return IsVistaOrLater() && mFullDuplex;
#endif
}
/* static */
MediaKeySystemStatus
MediaKeySystemAccess::GetKeySystemStatus(const nsAString& aKeySystem,
                                         int32_t aMinCdmVersion)
{
  MOZ_ASSERT(Preferences::GetBool("media.eme.enabled", false));
  nsCOMPtr<mozIGeckoMediaPluginService> mps =
    do_GetService("@mozilla.org/gecko-media-plugin-service;1");
  if (NS_WARN_IF(!mps)) {
    return MediaKeySystemStatus::Error;
  }

  if (aKeySystem.EqualsLiteral("org.w3.clearkey")) {
    if (!Preferences::GetBool("media.eme.clearkey.enabled", true)) {
      return MediaKeySystemStatus::Cdm_disabled;
    }
    if (!HaveGMPFor(mps,
                    NS_LITERAL_CSTRING("org.w3.clearkey"),
                    NS_LITERAL_CSTRING(GMP_API_DECRYPTOR))) {
      return MediaKeySystemStatus::Cdm_not_installed;
    }
    return EnsureMinCDMVersion(mps, aKeySystem, aMinCdmVersion);
  }

#ifdef XP_WIN
  if ((aKeySystem.EqualsLiteral("com.adobe.access") ||
       aKeySystem.EqualsLiteral("com.adobe.primetime"))) {
    // Win Vista and later only.
    if (!IsVistaOrLater()) {
      return MediaKeySystemStatus::Cdm_not_supported;
    }
    if (!Preferences::GetBool("media.gmp-eme-adobe.enabled", false)) {
      return MediaKeySystemStatus::Cdm_disabled;
    }
    if ((!WMFDecoderModule::HasH264() || !WMFDecoderModule::HasAAC()) ||
        !EMEVoucherFileExists()) {
      // The system doesn't have the codecs that Adobe EME relies
      // on installed, or doesn't have a voucher for the plugin-container.
      // Adobe EME isn't going to work, so don't advertise that it will.
      return MediaKeySystemStatus::Cdm_not_supported;
    }
    if (!HaveGMPFor(mps,
                    NS_ConvertUTF16toUTF8(aKeySystem),
                    NS_LITERAL_CSTRING(GMP_API_DECRYPTOR)) &&
        // XXX to be removed later in bug 1147692
        !HaveGMPFor(mps,
                    NS_ConvertUTF16toUTF8(aKeySystem),
                    NS_LITERAL_CSTRING(GMP_API_DECRYPTOR_COMPAT))) {
      return MediaKeySystemStatus::Cdm_not_installed;
    }
    return EnsureMinCDMVersion(mps, aKeySystem, aMinCdmVersion);
  }
#endif

  return MediaKeySystemStatus::Cdm_not_supported;
}
Пример #9
0
CGitExtensionsShellEx::CGitExtensionsShellEx()
{
    if (IsVistaOrLater())
    {
        HMODULE hUxTheme = ::GetModuleHandle (_T("UXTHEME.DLL"));

        pfnGetBufferedPaintBits = (FN_GetBufferedPaintBits)::GetProcAddress(hUxTheme, "GetBufferedPaintBits");
        pfnBeginBufferedPaint = (FN_BeginBufferedPaint)::GetProcAddress(hUxTheme, "BeginBufferedPaint");
        pfnEndBufferedPaint = (FN_EndBufferedPaint)::GetProcAddress(hUxTheme, "EndBufferedPaint");
    }
}
Пример #10
0
static bool
IsSupportedKeySystem(const nsAString& aKeySystem)
{
  return aKeySystem.EqualsASCII("org.w3.clearkey") ||
#ifdef XP_WIN
         (aKeySystem.EqualsASCII("com.adobe.access") &&
          IsVistaOrLater() &&
          Preferences::GetBool("media.eme.adobe-access.enabled", false)) ||
#endif
         false;
}
Пример #11
0
/* static */
MediaKeySystemStatus
MediaKeySystemAccess::GetKeySystemStatus(const nsAString& aKeySystem,
                                         int32_t aMinCdmVersion,
                                         nsACString& aOutMessage,
                                         nsACString& aOutCdmVersion)
{
  MOZ_ASSERT(Preferences::GetBool("media.eme.enabled", false));
  nsCOMPtr<mozIGeckoMediaPluginService> mps =
    do_GetService("@mozilla.org/gecko-media-plugin-service;1");
  if (NS_WARN_IF(!mps)) {
    aOutMessage = NS_LITERAL_CSTRING("Failed to get GMP service");
    return MediaKeySystemStatus::Error;
  }

  if (aKeySystem.EqualsLiteral("org.w3.clearkey")) {
    if (!Preferences::GetBool("media.eme.clearkey.enabled", true)) {
      aOutMessage = NS_LITERAL_CSTRING("ClearKey was disabled");
      return MediaKeySystemStatus::Cdm_disabled;
    }
    return EnsureMinCDMVersion(mps, aKeySystem, aMinCdmVersion, aOutMessage, aOutCdmVersion);
  }

#ifdef PRIMETIME_EME_SUPPORTED
  if (aKeySystem.EqualsLiteral("com.adobe.primetime")) {
    if (!Preferences::GetBool("media.gmp-eme-adobe.enabled", false)) {
      aOutMessage = NS_LITERAL_CSTRING("Adobe EME disabled");
      return MediaKeySystemStatus::Cdm_disabled;
    }
#ifdef XP_WIN
    // Win Vista and later only.
    if (!IsVistaOrLater()) {
      aOutMessage = NS_LITERAL_CSTRING("Minimum Windows version not met for Adobe EME");
      return MediaKeySystemStatus::Cdm_not_supported;
    }
#endif
#ifdef XP_MACOSX
    if (!nsCocoaFeatures::OnLionOrLater()) {
      aOutMessage = NS_LITERAL_CSTRING("Minimum MacOSX version not met for Adobe EME");
      return MediaKeySystemStatus::Cdm_not_supported;
    }
#endif
    if (!EMEVoucherFileExists()) {
      // Gecko doesn't have a voucher file for the plugin-container.
      // Adobe EME isn't going to work, so don't advertise that it will.
      aOutMessage = NS_LITERAL_CSTRING("Plugin-container voucher not present");
      return MediaKeySystemStatus::Cdm_not_supported;
    }
    return EnsureMinCDMVersion(mps, aKeySystem, aMinCdmVersion, aOutMessage, aOutCdmVersion);
  }
#endif

  return MediaKeySystemStatus::Cdm_not_supported;
}
Пример #12
0
BOOL MyCreateRemoteThread(HANDLE hProcess, LPTHREAD_START_ROUTINE pThreadProc, LPVOID pRemoteBuf)
{
	HANDLE      hThread = NULL;
	FARPROC     pFunc = NULL;
	if( IsVistaOrLater() )    // Vista, 7, Server2008
	{
		pFunc = GetProcAddress(GetModuleHandle(L"ntdll.dll"), "NtCreateThreadEx");
		if( pFunc == NULL )
		{
			LogMsg("MyCreateRemoteThread() : GetProcAddress(\"NtCreateThreadEx\") 调用失败!错误代码: [%d]/n",
				GetLastError());
			return FALSE;
		}
		((PFNTCREATETHREADEX)pFunc)(&hThread,
									0x1FFFFF,
									NULL,
									hProcess,
									pThreadProc,
									pRemoteBuf,
									FALSE,
									NULL,
									NULL,
									NULL,
									NULL);
		if( hThread == NULL )
		{
			LogMsg("MyCreateRemoteThread() : NtCreateThreadEx() 调用失败!错误代码: [%d]/n", GetLastError());
			return FALSE;
		}
	}
	else                    // 2000, XP, Server2003
	{
		hThread = CreateRemoteThread(hProcess, 
										NULL, 
										0, 
										pThreadProc, 
										pRemoteBuf, 
										0, 
										NULL);
		if( hThread == NULL )
		{
			LogMsg("MyCreateRemoteThread() : CreateRemoteThread() 调用失败!错误代码: [%d]/n", GetLastError());
			return FALSE;
		}
	}
	if( WAIT_FAILED == WaitForSingleObject(hThread, INFINITE) )
	{
		LogMsg("MyCreateRemoteThread() : WaitForSingleObject() 调用失败!错误代码: [%d]/n", GetLastError());
		return FALSE;
	}
	return TRUE;
}
Пример #13
0
HRESULT D3DPresentEngine::CheckDeviceState(DeviceState *pState)
{
    HRESULT hr = S_OK;

    AutoLock lock(m_ObjectLock);

	if(IsVistaOrLater())
	{
		// Check the device state. Not every failure code is a critical failure.
		hr = ((IDirect3DDevice9Ex*)m_pDevice)->CheckDeviceState(m_hwnd);
	}
	else
	{
		/* Add support for XP!! Wait, f**k XP */
		hr = m_pDevice->TestCooperativeLevel();
	}

    *pState = DeviceOK;

    switch (hr)
    {
    case S_OK:
    case S_PRESENT_OCCLUDED:
      case S_PRESENT_MODE_CHANGED:
        // state is DeviceOK
        hr = S_OK;
        break;

    case D3DERR_DEVICELOST:
    case D3DERR_DEVICEHUNG:
        // Lost/hung device. Destroy the device and create a new one.
        CHECK_HR(hr = CreateD3DDevice());
        *pState = DeviceReset;
        hr = S_OK;
        break;

    case D3DERR_DEVICEREMOVED:
        // This is a fatal error.
        *pState = DeviceRemoved;
        break;

    case E_INVALIDARG:
        // CheckDeviceState can return E_INVALIDARG if the window is not valid
        // We'll assume that the window was destroyed; we'll recreate the device 
        // if the application sets a new window.
        hr = S_OK;
    }

done:
    return hr;
}
Пример #14
0
static bool
HavePlatformMPEGDecoders()
{
  return Preferences::GetBool("media.fragmented-mp4.use-blank-decoder") ||
#ifdef XP_WIN
         // We have H.264/AAC platform decoders on Windows Vista and up.
         IsVistaOrLater() ||
#endif
         IsAndroidAvailable() ||
         IsFFmpegAvailable() ||
         IsAppleAvailable() ||
         IsGonkMP4DecoderAvailable() ||
         // TODO: Other platforms...
         false;
}
Пример #15
0
static void
UpdateHandler(nsITimer* aTimer, void* aClosure) {
  NS_ASSERTION(!IsVistaOrLater(),
               "We shouldn't call this function for Vista or later version!");

  static hal::BatteryInformation sLastInfo;
  hal::BatteryInformation currentInfo;

  hal_impl::GetCurrentBatteryInformation(&currentInfo);
  if (sLastInfo.level() != currentInfo.level() ||
      sLastInfo.charging() != currentInfo.charging() ||
      sLastInfo.remainingTime() != currentInfo.remainingTime()) {
    hal::NotifyBatteryChange(currentInfo);
    sLastInfo = currentInfo;
  }
}
void CGitExtensionsShellEx::AddMenuItem(HMENU hMenu, LPSTR text, int resource, int firstId, int id, UINT position)
{
    MENUITEMINFO mii;
    memset(&mii, 0, sizeof(mii));
    mii.cbSize = sizeof(mii);
    mii.fMask = MIIM_STRING | MIIM_ID;
    if (resource)
    {
        mii.fMask |= MIIM_BITMAP;
        mii.hbmpItem = IsVistaOrLater() ? IconToBitmapPARGB32(resource) : HBMMENU_CALLBACK;
        myIDMap[id] = resource;
        myIDMap[firstId + id] = resource;
    }
    mii.wID	= firstId + id;
    mii.dwTypeData	= text;

    InsertMenuItem(hMenu, position, TRUE, &mii);
}
Пример #17
0
FileReader::FileReader() :
	m_hFile(INVALID_HANDLE_VALUE),
	m_pFileName(0),
  m_bUseDummyWrites(FALSE),
  m_bUseRandomAccess(FALSE),
  m_bIsStopping(FALSE),
  m_isTimeshift(FALSE),
  m_pKernel32LibHandle(NULL),
  m_pCancelSynchronousIoProcHandle(NULL)
{
  if (IsVistaOrLater())
  {
    m_pKernel32LibHandle = LoadLibraryW(L"Kernel32.dll");
    if (m_pKernel32LibHandle != NULL)
    {
      m_pCancelSynchronousIoProcHandle = (CancelSynchronousIoFn)GetProcAddress(m_pKernel32LibHandle, "CancelSynchronousIo");
    }
  }
  //LogDebug("FileReader::ctor, IsVistaOrLater: %d, got CancelSynchronousIo handle: %d", m_bIsVistaOrLater, m_pCancelSynchronousIoProcHandle != NULL);
}
STDMETHODIMP CGitExtensionsShellEx::QueryContextMenu  (
    HMENU hmenu, UINT uMenuIndex, UINT uidFirstCmd,
    UINT uidLastCmd, UINT uFlags )
{
    // If the flags include CMF_DEFAULTONLY then we shouldn't do anything.
    if ( uFlags & CMF_DEFAULTONLY )
        return MAKE_HRESULT ( SEVERITY_SUCCESS, FACILITY_NULL, 0 );

    int id = 0;

    CString szCascadeContextMenu = GetRegistryValue(HKEY_CURRENT_USER, "SOFTWARE\\GitExtensions\\GitExtensions", "ShellCascadeContextMenu");

    CascadeContextMenu = !(szCascadeContextMenu == "False");

    if (CascadeContextMenu)
    {
        // show context menu cascaded in submenu
        HMENU popupMenu = CreateMenu();

        id = PopulateMenu(popupMenu, uidFirstCmd, id, true);

        MENUITEMINFO info;

        info.cbSize = sizeof( MENUITEMINFO );
        info.fMask = MIIM_STRING | MIIM_ID | MIIM_BITMAP | MIIM_SUBMENU;
        info.wID = uidFirstCmd + 1;
        info.hbmpItem = IsVistaOrLater() ? IconToBitmapPARGB32(IDI_GITEXTENSIONS) : HBMMENU_CALLBACK;
        myIDMap[1] = IDI_GITEXTENSIONS;
        myIDMap[uidFirstCmd + 1] = IDI_GITEXTENSIONS;
        info.dwTypeData = _T("Git Extensions");
        info.hSubMenu = popupMenu;
        InsertMenuItem(hmenu, 0, true, &info);
    }
    else
    {
        // show menu items directly
        id = PopulateMenu(hmenu, uidFirstCmd, id, false);
    }

    return MAKE_HRESULT ( SEVERITY_SUCCESS, FACILITY_NULL, id );
}
Пример #19
0
BOOL IsUacSupported()
{
    HKEY hkey;
    DWORD value = 1, size = sizeof (DWORD);

    if (!IsVistaOrLater())
    {
        return FALSE;
    }

    if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
                      L"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", 0, KEY_READ, &hkey) == ERROR_SUCCESS)
    {
        if (RegQueryValueExW(hkey, L"EnableLUA", 0, 0, (LPBYTE) &value, &size) != ERROR_SUCCESS)
        {
            value = 1;
        }

        RegCloseKey (hkey);
    }

    return value != 0;
}
Пример #20
0
//=============================================================================
BOOL CXProgressWnd::Create(CWnd *pParent, 
						  LPCTSTR lpszTitle, 
// start modified code: added to allow dialog with only a message
						  BOOL bEnableCancel /* = TRUE */,
						  BOOL bEnableProgressBar /* = TRUE */,
// end modified code
						  LPCTSTR lpszAviId /*= NULL*/,
						  BOOL bSmooth /* = FALSE */)
//=============================================================================
{
	BOOL bSuccess = FALSE;

	m_pParent = pParent;
	ASSERT(m_pParent);
	if (!m_pParent)
		return FALSE;

	m_strTitle = lpszTitle;
	m_nPercentComplete = 0;

	struct OLD_NONCLIENTMETRICS
	{
		UINT    cbSize;
		int     iBorderWidth;
		int     iScrollWidth;
		int     iScrollHeight;
		int     iCaptionWidth;
		int     iCaptionHeight;
		LOGFONT lfCaptionFont;
		int     iSmCaptionWidth;
		int     iSmCaptionHeight;
		LOGFONT lfSmCaptionFont;
		int     iMenuWidth;
		int     iMenuHeight;
		LOGFONT lfMenuFont;
		LOGFONT lfStatusFont;
		LOGFONT lfMessageFont;
	};

	// Get the system window message font for use in 
	// the cancel button and messages

	// the size of the NONCLIENTMETRICS struct increased 
	// in Vista by an int (iPaddedBorderWidth)
	const UINT cbProperSize = IsVistaOrLater() ? 
		sizeof(OLD_NONCLIENTMETRICS)+sizeof(int) :
		sizeof(OLD_NONCLIENTMETRICS);

	NONCLIENTMETRICS ncm;
	ncm.cbSize = cbProperSize;

	VERIFY(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, cbProperSize, &ncm, 0));
    VERIFY(m_font.CreateFontIndirect(&(ncm.lfMessageFont)));

	// register window class
	CString csClassName = AfxRegisterWndClass(CS_OWNDC|CS_HREDRAW|CS_VREDRAW,
											  ::LoadCursor(NULL, IDC_APPSTARTING),
											  CBrush(::GetSysColor(COLOR_BTNFACE)));

	// create popup window
	bSuccess = CreateEx(WS_EX_DLGMODALFRAME/*|WS_EX_TOPMOST*/,	// Extended style
						csClassName,						// Classname
						m_strTitle,							// Title
						WS_POPUP|WS_BORDER|WS_CAPTION|WS_SYSMENU,		// style
						0,0,								// position - updated soon.
						390,130,							// Size - updated soon
						m_pParent->GetSafeHwnd(),			// handle to parent
						0,									// No menu
						NULL);	
	if (!bSuccess) 
		return FALSE;

	SetWindowPos(&wndTop, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);

	// now create the controls
	CRect TempRect(0,0,10,10);

// start modified code: added to allow dialog with only a message
	m_bEnableCancel = bEnableCancel;
	m_bEnableProgressBar = bEnableProgressBar;

	if (bEnableProgressBar)
	{
// end modified code
		DWORD dwProgressStyle = WS_CHILD|WS_VISIBLE;
#ifdef PBS_SMOOTH	
		if (bSmooth)
		   dwProgressStyle |= PBS_SMOOTH;
#endif
		bSuccess = m_wndProgress.Create(dwProgressStyle, TempRect, this, IDC_PROGRESS);
		if (!bSuccess) 
			return FALSE;
// start modified code: added to allow dialog with only a message
	}
// end modified code

	if (lpszAviId)
	{
		bSuccess = m_avi.Create(WS_CHILD|ACS_CENTER|ACS_TRANSPARENT|ACS_AUTOPLAY|WS_TABSTOP,
								TempRect, 
								this, 
								IDC_AVI);

		if (!bSuccess)
			return FALSE;

		UINT nID = (UINT) lpszAviId;

		if (HIWORD(nID))
			VERIFY(m_avi.Open(lpszAviId));		// open file
		else
			VERIFY(m_avi.Open(nID));			// open resource id
	}

// start modified code: added to allow dialog with only a message
	if (bEnableCancel)
	{
// end modified code
		bSuccess = m_CancelButton.Create(m_strCancelLabel, 
									 WS_CHILD|WS_VISIBLE|WS_TABSTOP| BS_PUSHBUTTON, 
									 TempRect, this, IDC_CANCEL);
		if (!bSuccess)
			return FALSE;

		m_CancelButton.SetFont(&m_font, TRUE);
// start modified code: added to allow dialog with only a message
	}
// end modified code

	// resize the whole thing according to the number of text lines, desired window
	// width and current font.
	SetWindowSize(m_nNumTextLines, 390);

	// center and show window
	if (m_bPersistentPosition)
		GetPreviousSettings();
	else
		CenterWindow();

	Show();

	return TRUE;
}
Пример #21
0
HRESULT D3DPresentEngine::CreateD3DDevice()
{
    HRESULT     hr = S_OK;
    HWND        hwnd = NULL;
    HMONITOR    hMonitor = NULL;
    UINT        uAdapterID = D3DADAPTER_DEFAULT;
    DWORD       vp = 0;

    D3DCAPS9    ddCaps;
    ZeroMemory(&ddCaps, sizeof(ddCaps));

    IDirect3DDevice9* pDevice = NULL;

    // Hold the lock because we might be discarding an exisiting device.
    AutoLock lock(m_ObjectLock);    

    if (!m_pD3D9 || !m_pDeviceManager)
    {
        return MF_E_NOT_INITIALIZED;
    }

    hwnd = GetDesktopWindow();

    // Note: The presenter creates additional swap chains to present the
    // video frames. Therefore, it does not use the device's implicit 
    // swap chain, so the size of the back buffer here is 1 x 1.

	D3DPRESENT_PARAMETERS pp;
	ZeroMemory(&pp, sizeof(pp));

    pp.BackBufferWidth = 1;
    pp.BackBufferHeight = 1;
    pp.Windowed = TRUE;
    pp.SwapEffect = D3DSWAPEFFECT_COPY;
    pp.BackBufferFormat = D3DFMT_UNKNOWN;
    pp.hDeviceWindow = hwnd;
    pp.Flags = D3DPRESENTFLAG_VIDEO;
    pp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;

    // Find the monitor for this window.
    if (m_hwnd)
    {
        hMonitor = MonitorFromWindow(m_hwnd, MONITOR_DEFAULTTONEAREST);

        // Find the corresponding adapter.
    	CHECK_HR(hr = FindAdapter(m_pD3D9, hMonitor, &uAdapterID));
    }

    // Get the device caps for this adapter.
    CHECK_HR(hr = m_pD3D9->GetDeviceCaps(uAdapterID, D3DDEVTYPE_HAL, &ddCaps));

    if(ddCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT)
    {
        vp = D3DCREATE_HARDWARE_VERTEXPROCESSING;
    }
    else
    {
        vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
    }

	if(IsVistaOrLater())
	{
		IDirect3DDevice9Ex * pDeviceEx;

		// Create the device.
		CHECK_HR(hr = m_pD3D9->CreateDeviceEx(uAdapterID,
											  D3DDEVTYPE_HAL,
											  pp.hDeviceWindow,
											  vp | D3DCREATE_NOWINDOWCHANGES | D3DCREATE_MULTITHREADED | D3DCREATE_FPU_PRESERVE,
										      &pp, 
										  	  NULL,
											  &pDeviceEx));
		pDevice = pDeviceEx;
	}
	else
	{
		CHECK_HR(hr = m_pD3D9->CreateDevice(uAdapterID,
											  D3DDEVTYPE_HAL,
											  pp.hDeviceWindow,
											  vp | D3DCREATE_NOWINDOWCHANGES | D3DCREATE_MULTITHREADED | D3DCREATE_FPU_PRESERVE,
										      &pp, 
											  &pDevice));
	}

    // Get the adapter display mode.
    CHECK_HR(hr = m_pD3D9->GetAdapterDisplayMode(uAdapterID, &m_DisplayMode));

    // Reset the D3DDeviceManager with the new device 
    CHECK_HR(hr = m_pDeviceManager->ResetDevice(pDevice, m_DeviceResetToken));

    SAFE_RELEASE(m_pDevice);

    m_pDevice = pDevice;
    m_pDevice->AddRef();

done:
	SAFE_RELEASE(pDevice);
	return hr;
}
Пример #22
0
STDMETHODIMP CGitExtensionsShellEx::QueryContextMenu(
    HMENU hMenu, UINT menuIndex, UINT uidFirstCmd, UINT uidLastCmd, UINT uFlags)
{
    DBG_TRACE(L"CGitExtensionsShellEx::QueryContextMenu(menuIndex=%u,uidLastCmd=%u,uFlags=%u)", menuIndex, uidLastCmd, uFlags);
    // If the flags include CMF_DEFAULTONLY then we shouldn't do anything.
    if (uFlags & CMF_DEFAULTONLY)
        return S_OK;

    //check if we already added our menu entry for a folder.
    //we check that by iterating through all menu entries and check if
    //the dwItemData member points to our global ID string. That string is set
    //by our shell extension when the folder menu is inserted.
    TCHAR menubuf[MAX_PATH];
    int count = GetMenuItemCount(hMenu);
    for (int i=0; i<count; ++i)
    {
        MENUITEMINFO miif;
        SecureZeroMemory(&miif, sizeof(MENUITEMINFO));
        miif.cbSize = sizeof(MENUITEMINFO);
        miif.fMask = MIIM_DATA;
        miif.dwTypeData = menubuf;
        miif.cch = _countof(menubuf);
        GetMenuItemInfo(hMenu, i, TRUE, &miif);
        if (miif.dwItemData == (ULONG_PTR)_Module.GetModuleInstance())
        {
            DBG_TRACE(L"Menu already added");
            return S_OK;
        }
    }

    CString szCascadeShellMenuItems = GetRegistryValue(HKEY_CURRENT_USER, L"SOFTWARE\\GitExtensions", L"CascadeShellMenuItems");
    if (szCascadeShellMenuItems.IsEmpty())
        szCascadeShellMenuItems = "110111000111111111";
    bool cascadeContextMenu = szCascadeShellMenuItems.Find('1') != -1;
    bool alwaysShowAllCommands = GetRegistryBoolValue(HKEY_CURRENT_USER, L"SOFTWARE\\GitExtensions", L"AlwaysShowAllCommands");

    HMENU popupMenu = NULL;
    if (cascadeContextMenu)
        popupMenu = CreateMenu();

    bool isValidDir = true;
    bool isFolder = true;
    if (!alwaysShowAllCommands)
    {
        isValidDir = IsValidGitDir(m_szFile);
        isFolder = !IsFileExists(m_szFile);
    }

    // preset values, if not used
    commandsId.clear();

    UINT submenuIndex = 0;
    int id = 0;
    int cmdid;
    bool isSubMenu;

    if (alwaysShowAllCommands || !isValidDir)
    {
        isSubMenu = DisplayInSubmenu(szCascadeShellMenuItems, gcClone);
        cmdid=AddMenuItem(!isSubMenu ? hMenu : popupMenu, L"Clone...", IDI_ICONCLONEREPOGIT, uidFirstCmd, ++id, !isSubMenu ? menuIndex++ : submenuIndex++, isSubMenu);
        commandsId[cmdid]=gcClone;

        isSubMenu = DisplayInSubmenu(szCascadeShellMenuItems, gcCreateRepository);
        cmdid=AddMenuItem(!isSubMenu ? hMenu : popupMenu, L"Create new repository...", IDI_ICONCREATEREPOSITORY, uidFirstCmd, ++id, !isSubMenu ? menuIndex++ : submenuIndex++, isSubMenu);
        commandsId[cmdid]=gcCreateRepository;
    }
    if (isValidDir)
    {
        isSubMenu = DisplayInSubmenu(szCascadeShellMenuItems, gcBrowse);
        cmdid = AddMenuItem(!isSubMenu ? hMenu : popupMenu, L"Browse", IDI_ICONBROWSEFILEEXPLORER, uidFirstCmd, ++id, !isSubMenu ? menuIndex++ : submenuIndex++, isSubMenu);
        commandsId[cmdid]=gcBrowse;

        if (isFolder)
        {
            isSubMenu = DisplayInSubmenu(szCascadeShellMenuItems, gcCommit);
            cmdid = AddMenuItem(!isSubMenu ? hMenu : popupMenu, L"Commit...", IDI_ICONCOMMIT, uidFirstCmd, ++id, !isSubMenu ? menuIndex++ : submenuIndex++, isSubMenu);
            commandsId[cmdid]=gcCommit;

            isSubMenu = DisplayInSubmenu(szCascadeShellMenuItems, gcPull);
            cmdid = AddMenuItem(!isSubMenu ? hMenu : popupMenu, L"Pull...", IDI_ICONPULL, uidFirstCmd, ++id, !isSubMenu ? menuIndex++ : submenuIndex++, isSubMenu);
            commandsId[cmdid]=gcPull;

            isSubMenu = DisplayInSubmenu(szCascadeShellMenuItems, gcPush);
            cmdid=AddMenuItem(!isSubMenu ? hMenu : popupMenu, L"Push...", IDI_ICONPUSH, uidFirstCmd, ++id, !isSubMenu ? menuIndex++ : submenuIndex++, isSubMenu);
            commandsId[cmdid]=gcPush;

            isSubMenu = DisplayInSubmenu(szCascadeShellMenuItems, gcStash);
            cmdid=AddMenuItem(!isSubMenu ? hMenu : popupMenu, L"View stash", IDI_ICONSTASH, uidFirstCmd, ++id, !isSubMenu ? menuIndex++ : submenuIndex++, isSubMenu);
            commandsId[cmdid]=gcStash;

            isSubMenu = DisplayInSubmenu(szCascadeShellMenuItems, gcViewDiff);
            cmdid=AddMenuItem(!isSubMenu ? hMenu : popupMenu, L"View changes", IDI_ICONVIEWCHANGES, uidFirstCmd, ++id, !isSubMenu ? menuIndex++ : submenuIndex++, isSubMenu);
            commandsId[cmdid]=gcViewDiff;

            isSubMenu = DisplayInSubmenu(szCascadeShellMenuItems, gcCheckoutBranch);
            if (isSubMenu && submenuIndex > 0) {
                InsertMenu(popupMenu, submenuIndex++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL); ++id;
            }
            cmdid=AddMenuItem(!isSubMenu ? hMenu : popupMenu, L"Checkout branch...", IDI_ICONBRANCHCHECKOUT, uidFirstCmd, ++id, !isSubMenu ? menuIndex++ : submenuIndex++, isSubMenu);
            commandsId[cmdid]=gcCheckoutBranch;

            isSubMenu = DisplayInSubmenu(szCascadeShellMenuItems, gcCheckoutRevision);
            cmdid=AddMenuItem(!isSubMenu ? hMenu : popupMenu, L"Checkout revision...", IDI_ICONREVISIONCHECKOUT, uidFirstCmd, ++id, !isSubMenu ? menuIndex++ : submenuIndex++, isSubMenu);
            commandsId[cmdid]=gcCheckoutRevision;

            isSubMenu = DisplayInSubmenu(szCascadeShellMenuItems, gcCreateBranch);
            cmdid=AddMenuItem(!isSubMenu ? hMenu : popupMenu, L"Create branch...", IDI_ICONBRANCHCREATE, uidFirstCmd, ++id, !isSubMenu ? menuIndex++ : submenuIndex++, isSubMenu);
            commandsId[cmdid]=gcCreateBranch;
        }

        isSubMenu = DisplayInSubmenu(szCascadeShellMenuItems, gcDiffTool);
        if (isSubMenu && submenuIndex > 0) {
            InsertMenu(popupMenu, submenuIndex++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL); ++id;
        }
        cmdid=AddMenuItem(!isSubMenu ? hMenu : popupMenu, L"Open with difftool", IDI_ICONVIEWCHANGES, uidFirstCmd, ++id, !isSubMenu ? menuIndex++ : submenuIndex++, isSubMenu);
        commandsId[cmdid]=gcDiffTool;

        isSubMenu = DisplayInSubmenu(szCascadeShellMenuItems, gcFileHistory);
        cmdid=AddMenuItem(!isSubMenu ? hMenu : popupMenu, L"File history", IDI_ICONFILEHISTORY, uidFirstCmd, ++id, !isSubMenu ? menuIndex++ : submenuIndex++, isSubMenu);
        commandsId[cmdid]=gcFileHistory;

        isSubMenu = DisplayInSubmenu(szCascadeShellMenuItems, gcResetFileChanges);
        cmdid=AddMenuItem(!isSubMenu ? hMenu : popupMenu, L"Reset file changes...", IDI_ICONTRESETFILETO, uidFirstCmd, ++id, !isSubMenu ? menuIndex++ : submenuIndex++, isSubMenu);
        commandsId[cmdid]=gcResetFileChanges;

        isSubMenu = DisplayInSubmenu(szCascadeShellMenuItems, gcAddFiles);
        cmdid=AddMenuItem(!isSubMenu ? hMenu : popupMenu, L"Add files...", IDI_ICONADDED, uidFirstCmd, ++id, !isSubMenu ? menuIndex++ : submenuIndex++, isSubMenu);
        commandsId[cmdid]=gcAddFiles;

        isSubMenu = DisplayInSubmenu(szCascadeShellMenuItems, gcApplyPatch);
        cmdid=AddMenuItem(!isSubMenu ? hMenu : popupMenu, L"Apply patch...", 0, uidFirstCmd, ++id, !isSubMenu ? menuIndex++ : submenuIndex++, isSubMenu);
        commandsId[cmdid]=gcApplyPatch;
    }

    isSubMenu = DisplayInSubmenu(szCascadeShellMenuItems, gcSettings);
    if (isSubMenu && submenuIndex > 0) {
        InsertMenu(popupMenu, submenuIndex++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL); ++id;
    }
    cmdid=AddMenuItem(!isSubMenu ? hMenu : popupMenu, L"Settings", IDI_ICONSETTINGS, uidFirstCmd, ++id, !isSubMenu ? menuIndex++ : submenuIndex++, isSubMenu);
    commandsId[cmdid]=gcSettings;

    ++id;

    if (cascadeContextMenu)
    {
        MENUITEMINFO info;
        info.cbSize = sizeof(MENUITEMINFO);
        info.fMask = MIIM_STRING | MIIM_ID | MIIM_BITMAP | MIIM_SUBMENU;
        info.wID = uidFirstCmd + 1;
        info.hbmpItem = IsVistaOrLater() ? IconToBitmapPARGB32(IDI_GITEXTENSIONS) : HBMMENU_CALLBACK;
        myIDMap[1] = IDI_GITEXTENSIONS;
        myIDMap[uidFirstCmd + 1] = IDI_GITEXTENSIONS;
        info.dwTypeData = _T("Git Extensions");
        info.hSubMenu = popupMenu;
        InsertMenuItem(hMenu, menuIndex, true, &info);
    }

    return MAKE_HRESULT ( SEVERITY_SUCCESS, FACILITY_NULL, id);
}
Пример #23
0
nsresult
ShutdownXPCOM(nsIServiceManager* aServMgr)
{
  // Make sure the hang monitor is enabled for shutdown.
  HangMonitor::NotifyActivity();

  if (!NS_IsMainThread()) {
    NS_RUNTIMEABORT("Shutdown on wrong thread");
  }

  nsresult rv;
  nsCOMPtr<nsISimpleEnumerator> moduleLoaders;

  // Notify observers of xpcom shutting down
  {
    // Block it so that the COMPtr will get deleted before we hit
    // servicemanager shutdown

    nsCOMPtr<nsIThread> thread = do_GetCurrentThread();
    if (NS_WARN_IF(!thread)) {
      return NS_ERROR_UNEXPECTED;
    }

    RefPtr<nsObserverService> observerService;
    CallGetService("@mozilla.org/observer-service;1",
                   (nsObserverService**)getter_AddRefs(observerService));

    if (observerService) {
      observerService->NotifyObservers(nullptr,
                                       NS_XPCOM_WILL_SHUTDOWN_OBSERVER_ID,
                                       nullptr);

      nsCOMPtr<nsIServiceManager> mgr;
      rv = NS_GetServiceManager(getter_AddRefs(mgr));
      if (NS_SUCCEEDED(rv)) {
        observerService->NotifyObservers(mgr, NS_XPCOM_SHUTDOWN_OBSERVER_ID,
                                         nullptr);
      }
    }

    // This must happen after the shutdown of media and widgets, which
    // are triggered by the NS_XPCOM_SHUTDOWN_OBSERVER_ID notification.
    NS_ProcessPendingEvents(thread);
    gfxPlatform::ShutdownLayersIPC();

    mozilla::scache::StartupCache::DeleteSingleton();
    if (observerService)
      observerService->NotifyObservers(nullptr,
                                       NS_XPCOM_SHUTDOWN_THREADS_OBSERVER_ID,
                                       nullptr);

    gXPCOMThreadsShutDown = true;
    NS_ProcessPendingEvents(thread);

    // Shutdown the timer thread and all timers that might still be alive before
    // shutting down the component manager
    nsTimerImpl::Shutdown();

    NS_ProcessPendingEvents(thread);

    // Shutdown all remaining threads.  This method does not return until
    // all threads created using the thread manager (with the exception of
    // the main thread) have exited.
    nsThreadManager::get()->Shutdown();

    NS_ProcessPendingEvents(thread);

    HangMonitor::NotifyActivity();

    // Late-write checks needs to find the profile directory, so it has to
    // be initialized before mozilla::services::Shutdown or (because of
    // xpcshell tests replacing the service) modules being unloaded.
    mozilla::InitLateWriteChecks();

    // We save the "xpcom-shutdown-loaders" observers to notify after
    // the observerservice is gone.
    if (observerService) {
      observerService->EnumerateObservers(NS_XPCOM_SHUTDOWN_LOADERS_OBSERVER_ID,
                                          getter_AddRefs(moduleLoaders));

      observerService->Shutdown();
    }
  }

  // Free ClearOnShutdown()'ed smart pointers.  This needs to happen *after*
  // we've finished notifying observers of XPCOM shutdown, because shutdown
  // observers themselves might call ClearOnShutdown().
  mozilla::KillClearOnShutdown();

  // XPCOM is officially in shutdown mode NOW
  // Set this only after the observers have been notified as this
  // will cause servicemanager to become inaccessible.
  mozilla::services::Shutdown();

#ifdef DEBUG_dougt
  fprintf(stderr, "* * * * XPCOM shutdown. Access will be denied * * * * \n");
#endif
  // We may have AddRef'd for the caller of NS_InitXPCOM, so release it
  // here again:
  NS_IF_RELEASE(aServMgr);

  // Shutdown global servicemanager
  if (nsComponentManagerImpl::gComponentManager) {
    nsComponentManagerImpl::gComponentManager->FreeServices();
  }

  // Release the directory service
  NS_IF_RELEASE(nsDirectoryService::gService);

  free(gGREBinPath);
  gGREBinPath = nullptr;

  if (moduleLoaders) {
    bool more;
    nsCOMPtr<nsISupports> el;
    while (NS_SUCCEEDED(moduleLoaders->HasMoreElements(&more)) && more) {
      moduleLoaders->GetNext(getter_AddRefs(el));

      // Don't worry about weak-reference observers here: there is
      // no reason for weak-ref observers to register for
      // xpcom-shutdown-loaders

      // FIXME: This can cause harmless writes from sqlite committing
      // log files. We have to ignore them before we can move
      // the mozilla::PoisonWrite call before this point. See bug
      // 834945 for the details.
      nsCOMPtr<nsIObserver> obs(do_QueryInterface(el));
      if (obs) {
        obs->Observe(nullptr, NS_XPCOM_SHUTDOWN_LOADERS_OBSERVER_ID, nullptr);
      }
    }

    moduleLoaders = nullptr;
  }

  nsCycleCollector_shutdown();

  layers::AsyncTransactionTrackersHolder::Finalize();

  PROFILER_MARKER("Shutdown xpcom");
  // If we are doing any shutdown checks, poison writes.
  if (gShutdownChecks != SCM_NOTHING) {
#ifdef XP_MACOSX
    mozilla::OnlyReportDirtyWrites();
#endif /* XP_MACOSX */
    mozilla::BeginLateWriteChecks();
  }

  // Shutdown nsLocalFile string conversion
  NS_ShutdownLocalFile();
#ifdef XP_UNIX
  NS_ShutdownNativeCharsetUtils();
#endif

#if defined(XP_WIN)
  // This exit(0) call is intended to be temporary, to get shutdown leak
  // checking working on Linux.
  // On Windows XP debug, there are intermittent failures in
  // dom/media/tests/mochitest/test_peerConnection_basicH264Video.html
  // if we don't exit early in a child process. See bug 1073310.
  if (XRE_IsContentProcess() && !IsVistaOrLater()) {
      NS_WARNING("Exiting child process early!");
      exit(0);
  }
#endif

  // Shutdown xpcom. This will release all loaders and cause others holding
  // a refcount to the component manager to release it.
  if (nsComponentManagerImpl::gComponentManager) {
    rv = (nsComponentManagerImpl::gComponentManager)->Shutdown();
    NS_ASSERTION(NS_SUCCEEDED(rv), "Component Manager shutdown failed.");
  } else {
    NS_WARNING("Component Manager was never created ...");
  }

#ifdef MOZ_ENABLE_PROFILER_SPS
  // In optimized builds we don't do shutdown collections by default, so
  // uncollected (garbage) objects may keep the nsXPConnect singleton alive,
  // and its XPCJSRuntime along with it. However, we still destroy various
  // bits of state in JS_ShutDown(), so we need to make sure the profiler
  // can't access them when it shuts down. This call nulls out the
  // JS pseudo-stack's internal reference to the main thread JSRuntime,
  // duplicating the call in XPCJSRuntime::~XPCJSRuntime() in case that
  // never fired.
  if (PseudoStack* stack = mozilla_get_pseudo_stack()) {
    stack->sampleRuntime(nullptr);
  }
#endif

  // Shut down the JS engine.
  JS_ShutDown();

  // Release our own singletons
  // Do this _after_ shutting down the component manager, because the
  // JS component loader will use XPConnect to call nsIModule::canUnload,
  // and that will spin up the InterfaceInfoManager again -- bad mojo
  XPTInterfaceInfoManager::FreeInterfaceInfoManager();

  // Finally, release the component manager last because it unloads the
  // libraries:
  if (nsComponentManagerImpl::gComponentManager) {
    nsrefcnt cnt;
    NS_RELEASE2(nsComponentManagerImpl::gComponentManager, cnt);
    NS_ASSERTION(cnt == 0, "Component Manager being held past XPCOM shutdown.");
  }
  nsComponentManagerImpl::gComponentManager = nullptr;
  nsCategoryManager::Destroy();

  NS_PurgeAtomTable();

  NS_IF_RELEASE(gDebug);

  delete sIOThread;
  sIOThread = nullptr;

  delete sMessageLoop;
  sMessageLoop = nullptr;

  if (sCommandLineWasInitialized) {
    CommandLine::Terminate();
    sCommandLineWasInitialized = false;
  }

  delete sExitManager;
  sExitManager = nullptr;

  Omnijar::CleanUp();

  HangMonitor::Shutdown();

  delete sMainHangMonitor;
  sMainHangMonitor = nullptr;

  BackgroundHangMonitor::Shutdown();

  profiler_shutdown();

  NS_LogTerm();

#if defined(MOZ_WIDGET_GONK)
  // This exit(0) call is intended to be temporary, to get shutdown leak
  // checking working on Linux.
  // On debug B2G, the child process crashes very late.  Instead, just
  // give up so at least we exit cleanly. See bug 1071866.
  if (XRE_IsContentProcess()) {
      NS_WARNING("Exiting child process early!");
      exit(0);
  }
#endif

  return NS_OK;
}
void
DecoderDoctorDocumentWatcher::SynthesizeAnalysis()
{
  MOZ_ASSERT(NS_IsMainThread());

  nsAutoString playableFormats;
  nsAutoString unplayableFormats;
  // Subsets of unplayableFormats that require a specific platform decoder:
#if defined(XP_WIN)
  nsAutoString formatsRequiringWMF;
#endif
#if defined(MOZ_FFMPEG)
  nsAutoString formatsRequiringFFMpeg;
#endif
  nsAutoString supportedKeySystems;
  nsAutoString unsupportedKeySystems;
  DecoderDoctorDiagnostics::KeySystemIssue lastKeySystemIssue =
    DecoderDoctorDiagnostics::eUnset;

  for (const auto& diag : mDiagnosticsSequence) {
    switch (diag.mDecoderDoctorDiagnostics.Type()) {
      case DecoderDoctorDiagnostics::eFormatSupportCheck:
        if (diag.mDecoderDoctorDiagnostics.CanPlay()) {
          AppendToFormatsList(playableFormats,
                              diag.mDecoderDoctorDiagnostics.Format());
        } else {
          AppendToFormatsList(unplayableFormats,
                              diag.mDecoderDoctorDiagnostics.Format());
#if defined(XP_WIN)
          if (diag.mDecoderDoctorDiagnostics.DidWMFFailToLoad()) {
            AppendToFormatsList(formatsRequiringWMF,
                                diag.mDecoderDoctorDiagnostics.Format());
          }
#endif
#if defined(MOZ_FFMPEG)
          if (diag.mDecoderDoctorDiagnostics.DidFFmpegFailToLoad()) {
            AppendToFormatsList(formatsRequiringFFMpeg,
                                diag.mDecoderDoctorDiagnostics.Format());
          }
#endif
        }
        break;
      case DecoderDoctorDiagnostics::eMediaKeySystemAccessRequest:
        if (diag.mDecoderDoctorDiagnostics.IsKeySystemSupported()) {
          AppendToFormatsList(supportedKeySystems,
                              diag.mDecoderDoctorDiagnostics.KeySystem());
        } else {
          AppendToFormatsList(unsupportedKeySystems,
                              diag.mDecoderDoctorDiagnostics.KeySystem());
          DecoderDoctorDiagnostics::KeySystemIssue issue =
            diag.mDecoderDoctorDiagnostics.GetKeySystemIssue();
          if (issue != DecoderDoctorDiagnostics::eUnset) {
            lastKeySystemIssue = issue;
          }
        }
        break;
      default:
        MOZ_ASSERT(diag.mDecoderDoctorDiagnostics.Type()
                     == DecoderDoctorDiagnostics::eFormatSupportCheck
                   || diag.mDecoderDoctorDiagnostics.Type()
                        == DecoderDoctorDiagnostics::eMediaKeySystemAccessRequest);
        break;
    }
  }

  // Check if issues have been solved, by finding if some now-playable
  // key systems or formats were previously recorded as having issues.
  if (!supportedKeySystems.IsEmpty() || !playableFormats.IsEmpty()) {
    DD_DEBUG("DecoderDoctorDocumentWatcher[%p, doc=%p]::SynthesizeAnalysis() - supported key systems '%s', playable formats '%s'; See if they show issues have been solved...",
             this, mDocument,
             NS_ConvertUTF16toUTF8(supportedKeySystems).Data(),
             NS_ConvertUTF16toUTF8(playableFormats).get());
    const nsAString* workingFormatsArray[] =
      { &supportedKeySystems, &playableFormats };
    // For each type of notification, retrieve the pref that contains formats/
    // key systems with issues.
    for (const NotificationAndReportStringId* id :
           sAllNotificationsAndReportStringIds) {
      nsAutoCString formatsPref("media.decoder-doctor.");
      formatsPref += id->mReportStringId;
      formatsPref += ".formats";
      nsAdoptingString formatsWithIssues =
        Preferences::GetString(formatsPref.Data());
      if (formatsWithIssues.IsEmpty()) {
        continue;
      }
      // See if that list of formats-with-issues contains any formats that are
      // now playable/supported.
      bool solved = false;
      for (const nsAString* workingFormats : workingFormatsArray) {
        for (const auto& workingFormat : MakeStringListRange(*workingFormats)) {
          if (FormatsListContains(formatsWithIssues, workingFormat)) {
            // This now-working format used not to work -> Report solved issue.
            DD_INFO("DecoderDoctorDocumentWatcher[%p, doc=%p]::SynthesizeAnalysis() - %s solved ('%s' now works, it was in pref(%s)='%s')",
                    this, mDocument, id->mReportStringId,
                    NS_ConvertUTF16toUTF8(workingFormat).get(),
                    formatsPref.Data(),
                    NS_ConvertUTF16toUTF8(formatsWithIssues).get());
            ReportAnalysis(*id, true, workingFormat);
            // This particular Notification&ReportId has been solved, no need
            // to keep looking at other keysys/formats that might solve it too.
            solved = true;
            break;
          }
        }
        if (solved) {
          break;
        }
      }
      if (!solved) {
        DD_DEBUG("DecoderDoctorDocumentWatcher[%p, doc=%p]::SynthesizeAnalysis() - %s not solved (pref(%s)='%s')",
                 this, mDocument, id->mReportStringId, formatsPref.Data(),
                 NS_ConvertUTF16toUTF8(formatsWithIssues).get());
      }
    }
  }

  // Look at Key System issues first, as they take precedence over format checks.
  if (!unsupportedKeySystems.IsEmpty() && supportedKeySystems.IsEmpty()) {
    // No supported key systems!
    switch (lastKeySystemIssue) {
      case DecoderDoctorDiagnostics::eWidevineWithNoWMF:
        if (CheckSilverlight() != eSilverlightEnabled) {
          DD_INFO("DecoderDoctorDocumentWatcher[%p, doc=%p]::SynthesizeAnalysis() - unsupported key systems: %s, widevine without WMF nor Silverlight",
                  this, mDocument, NS_ConvertUTF16toUTF8(unsupportedKeySystems).get());
          ReportAnalysis(
            sMediaWidevineNoWMFNoSilverlight, false, unsupportedKeySystems);
          return;
        }
        break;
      default:
        break;
    }
  }

  // Next, check playability of requested formats.
  if (!unplayableFormats.IsEmpty()) {
    // Some requested formats cannot be played.
    if (playableFormats.IsEmpty()) {
      // No requested formats can be played. See if we can help the user, by
      // going through expected decoders from most to least desirable.
#if defined(XP_WIN)
      if (!formatsRequiringWMF.IsEmpty()) {
        if (IsVistaOrLater()) {
          DD_INFO("DecoderDoctorDocumentWatcher[%p, doc=%p]::SynthesizeAnalysis() - unplayable formats: %s -> Cannot play media because WMF was not found",
                  this, mDocument, NS_ConvertUTF16toUTF8(formatsRequiringWMF).get());
          ReportAnalysis(sMediaWMFNeeded, false, formatsRequiringWMF);
        } else {
          DD_INFO("DecoderDoctorDocumentWatcher[%p, doc=%p]::SynthesizeAnalysis() - unplayable formats: %s -> Cannot play media before Windows Vista",
                  this, mDocument, NS_ConvertUTF16toUTF8(formatsRequiringWMF).get());
          ReportAnalysis(sMediaUnsupportedBeforeWindowsVista, false, formatsRequiringWMF);
        }
        return;
      }
#endif
#if defined(MOZ_FFMPEG)
      if (!formatsRequiringFFMpeg.IsEmpty()) {
        DD_INFO("DecoderDoctorDocumentWatcher[%p, doc=%p]::SynthesizeAnalysis() - unplayable formats: %s -> Cannot play media because platform decoder was not found",
                this, mDocument, NS_ConvertUTF16toUTF8(formatsRequiringFFMpeg).get());
        ReportAnalysis(sMediaPlatformDecoderNotFound,
                       false, formatsRequiringFFMpeg);
        return;
      }
#endif
      DD_INFO("DecoderDoctorDocumentWatcher[%p, doc=%p]::SynthesizeAnalysis() - Cannot play media, unplayable formats: %s",
              this, mDocument, NS_ConvertUTF16toUTF8(unplayableFormats).get());
      ReportAnalysis(sMediaCannotPlayNoDecoders, false, unplayableFormats);
      return;
    }

    DD_INFO("DecoderDoctorDocumentWatcher[%p, doc=%p]::SynthesizeAnalysis() - Can play media, but no decoders for some requested formats: %s",
            this, mDocument, NS_ConvertUTF16toUTF8(unplayableFormats).get());
    if (Preferences::GetBool("media.decoder-doctor.verbose", false)) {
      ReportAnalysis(sMediaNoDecoders, false, unplayableFormats);
    }
    return;
  }
  DD_DEBUG("DecoderDoctorDocumentWatcher[%p, doc=%p]::SynthesizeAnalysis() - Can play media, decoders available for all requested formats",
           this, mDocument);
}
Пример #25
0
static VOID TestTraceKernel()
{
	ULONG BufferCount;
	ULONG BufferSize;
	PROC_SET Set;
	DWORD_PTR FailedProc;
	UINT Tracepoints, Count;
	UINT EnumCount;
	JPFSV_TRACEPOINT Tracepnt;
	HRESULT Hr;
	JPFSV_HANDLE KernelCtx;
	JPFSV_TRACING_TYPE TracingType;
	ULONG TypesTested = 0;
	
	TEST_OK( CdiagCreateSession( NULL, NULL, &DiagSession ) );

	for ( TracingType = JpfsvTracingTypeDefault;
		  TracingType <= JpfsvTracingTypeMax;
		  TracingType++ )
	{
		UINT Index;
		BOOL Instrumentable;
		WCHAR LogFile[ MAX_PATH ];
		UINT PaddingSize;

		TEST_OK( StringCchPrintf( 
			LogFile, _countof( LogFile ), L"__kern%d.log",  TracingType ) );

		//
		// Start a trace.
		//
		KernelCtx = NULL;
		Hr = JpfsvLoadContext( JPFSV_KERNEL, NULL, &KernelCtx );
		if ( Hr == JPFSV_E_UNSUP_ON_WOW64 )
		{
			CFIX_INCONCLUSIVE( L"Not supported on WOW64" );
			return;
		}
		TEST_OK( Hr );
		
		TEST( JPFSV_E_NO_TRACESESSION == 
			JpfsvGetTracepointContext( KernelCtx, 0xF00, &Tracepnt ) );

		DeleteFile( LogFile );
		if ( TracingType != JpfsvTracingTypeWmk )
		{
			TEST( E_INVALIDARG == JpfsvAttachContext( KernelCtx, TracingType, NULL ) );
			Hr = JpfsvAttachContext( KernelCtx, TracingType, LogFile );
		}
		else
		{
			TEST( E_INVALIDARG == JpfsvAttachContext( KernelCtx, TracingType, LogFile ) );
			Hr = JpfsvAttachContext( KernelCtx, TracingType, NULL );
		}
		if ( Hr == JPFSV_E_UNSUPPORTED_TRACING_TYPE ||
			 Hr == HRESULT_FROM_NT( 0xC0049300L ) ) // STATUS_KFBT_KERNEL_NOT_SUPPORTED
		{
			continue;
		}

		TEST_OK( Hr );

		if ( TracingType == JpfsvTracingTypeWmk )
		{
			BufferCount = 0;
			BufferSize = 0;
		}
		else
		{
			BufferCount = 5;
			BufferSize = 1024;
		}

		//
		// Instrument some procedures.
		//
		Set.Count = 0;
		Set.ContextHandle = KernelCtx;
		Set.Process = JpfsvGetProcessHandleContext( KernelCtx );
		TEST( Set.Process );

		//
		// Not all patchable...
		//
		TEST( SymEnumSymbols(
			Set.Process,
			0,
			L"tcpip!*",
			AddProcedureSymCallback,
			&Set ) );

		TEST_OK( JpfsvStartTraceContext(
			KernelCtx,
			BufferCount,
			BufferSize,
			DiagSession ) );
		TEST( E_UNEXPECTED == JpfsvStartTraceContext(
			KernelCtx,
			BufferCount,
			BufferSize,
			DiagSession ) );

		TEST( Set.Count > 0 );

		TEST_OK( JpfsvCountTracePointsContext( KernelCtx, &Count ) );
		TEST( 0 == Count );

		TEST_STATUS( ( ULONG ) HRESULT_FROM_NT( STATUS_FBT_PROC_NOT_PATCHABLE ), 
			JpfsvSetTracePointsContext(
				KernelCtx,
				JpfsvAddTracepoint,
				Set.Count,
				Set.Procedures,
				&FailedProc ) );

		//
		// Instrumentable...
		//
		Set.Count = 0;
		Set.ContextHandle = KernelCtx;
		Set.Process = JpfsvGetProcessHandleContext( KernelCtx );
		TEST( SymEnumSymbols(
			Set.Process,
			0,
			IsVistaOrLater()
				? L"tcpip!IPReg*"
				: L"tcpip!IPRc*",
			AddProcedureSymCallback,
			&Set ) );
		TEST( Set.Count > 0 );
		for ( Index = 0; Index < Set.Count; Index++ )
		{
			TEST_OK( JpfsvCheckProcedureInstrumentability(
				KernelCtx,
				Set.Procedures[ Index ],
				&Instrumentable,
				&PaddingSize ) );
			TEST( Instrumentable );
			TEST( PaddingSize == 5 );
		}

		//
		// Not instrumentable...
		//
		Set.Count = 0;
		Set.ContextHandle = KernelCtx;
		Set.Process = JpfsvGetProcessHandleContext( KernelCtx );
		TEST( SymEnumSymbols(
			Set.Process,
			0,
			IsVistaOrLater()
				? L"tcpip!__report_gsfailure"
				: L"tcpip!_wcsicmp",
			AddProcedureSymCallback,
			&Set ) );
		TEST( Set.Count > 0 );
		TEST_OK( JpfsvCheckProcedureInstrumentability(
			KernelCtx,
			Set.Procedures[ 0 ],
			&Instrumentable,
			&PaddingSize ) );
		TEST( ! Instrumentable );
		TEST( PaddingSize == 0 );

		//
		// All patchable...
		//
		Set.Count = 0;
		Set.ContextHandle = KernelCtx;
		Set.Process = JpfsvGetProcessHandleContext( KernelCtx );
		TEST( Set.Process );

		TEST( SymEnumSymbols(
			Set.Process,
			0,
			IsVistaOrLater()
				? L"tcpip!IPReg*"
				: L"tcpip!IPRc*",
			AddProcedureSymCallback,
			&Set ) );
		TEST( Set.Count >= 3 );

		TEST_OK( JpfsvSetTracePointsContext(
			KernelCtx,
			JpfsvAddTracepoint,
			Set.Count,
			Set.Procedures,
			&FailedProc ) );

		// again - should be a noop.
		TEST_OK( JpfsvSetTracePointsContext(
			KernelCtx,
			JpfsvAddTracepoint,
			Set.Count,
			Set.Procedures,
			&FailedProc ) );
		TEST( FailedProc == 0 );


		TEST_OK( JpfsvCountTracePointsContext( KernelCtx, &Tracepoints ) );
		TEST( Tracepoints > Set.Count / 2 );	// Duplicate-cleaned!
		TEST( Tracepoints <= Set.Count );

		TEST_OK( JpfsvGetTracepointContext( KernelCtx, Set.Procedures[ 0 ], &Tracepnt ) );
		TEST( Tracepnt.Procedure == Set.Procedures[ 0 ] );
		TEST( wcslen( Tracepnt.SymbolName ) );
		TEST( wcslen( Tracepnt.ModuleName ) );

		TEST( JPFSV_E_TRACEPOINT_NOT_FOUND == JpfsvGetTracepointContext( KernelCtx, 0xBA2, &Tracepnt ) );

		//
		// Count enum callbacks.
		//
		EnumCount = 0;
		TEST_OK( JpfsvEnumTracePointsContext(
			KernelCtx,
			CountTracepointsCallback,
			&EnumCount ) );
		TEST( EnumCount == Tracepoints );

		//
		// Stop while tracing active -> implicitly revoke all tracepoints.
		//
		TEST_OK( JpfsvStopTraceContext( KernelCtx, TRUE ) );
		TEST_OK( JpfsvCountTracePointsContext( KernelCtx, &Count ) );
		TEST( 0 == Count );

		//
		// Trace again.
		//
		DeleteFile( LogFile );
		TEST_OK( JpfsvStartTraceContext(
			KernelCtx,
			BufferCount,
			BufferSize,
			DiagSession ) );
		TEST_OK( JpfsvSetTracePointsContext(
			KernelCtx,
			JpfsvAddTracepoint,
			Set.Count,
			Set.Procedures,
			&FailedProc ) );
		TEST( FailedProc == 0 );

		TEST_OK( JpfsvCountTracePointsContext( KernelCtx, &Count ) );
		TEST( Tracepoints == Count );

		//
		// Clean shutdown.
		//
		TEST_OK( JpfsvSetTracePointsContext(
			KernelCtx,
			JpfsvRemoveTracepoint,
			Set.Count,
			Set.Procedures,
			&FailedProc ) );
		TEST( FailedProc == 0 );

		TEST_OK( JpfsvCountTracePointsContext( KernelCtx, &Count ) );
		TEST( 0 == Count );

		TEST_OK( JpfsvStopTraceContext( KernelCtx, TRUE ) );
		TEST_OK( DetachContextSafe( KernelCtx ) );
		TEST_OK( JpfsvUnloadContext( KernelCtx ) );

		TypesTested++;
	}

	TEST_OK( CdiagDereferenceSession( DiagSession ) );

	if ( TypesTested == 0 )
	{
		CFIX_INCONCLUSIVE( L"No TracingTypes supported" );
	}
}
Пример #26
0
STDMETHODIMP CGitExtensionsShellEx::QueryContextMenu  (
    HMENU hMenu, UINT menuIndex, UINT uidFirstCmd,
    UINT uidLastCmd, UINT uFlags )
{
    // If the flags include CMF_DEFAULTONLY then we shouldn't do anything.
    if ( uFlags & CMF_DEFAULTONLY )
        return S_OK;

    CString szCascadeShellMenuItems = GetRegistryValue(HKEY_CURRENT_USER, L"SOFTWARE\\GitExtensions\\GitExtensions", L"CascadeShellMenuItems");
    if (szCascadeShellMenuItems.IsEmpty())
        szCascadeShellMenuItems = "110111000111111111";
    bool CascadeContextMenu = szCascadeShellMenuItems.Find('1') != -1;
    HMENU popupMenu = NULL;
    if (CascadeContextMenu)
        popupMenu = CreateMenu();

    bool isValidDir = IsValidGitDir(m_szFile);
    bool isFile = IsFileExists(m_szFile);

    // preset values, if not used
    commandsId.clear();

    UINT submenuIndex = 0;
    int id = 0;
    int cmdid;
    bool isSubMenu;

    if (isValidDir)
    {
        if (!isFile)
        {
            isSubMenu = DisplayInSubmenu(szCascadeShellMenuItems, gcBrowse);
            cmdid = AddMenuItem(!isSubMenu ? hMenu : popupMenu, L"Browse", IDI_ICONBROWSEFILEEXPLORER, uidFirstCmd, ++id, !isSubMenu ? menuIndex++ : submenuIndex++, isSubMenu);
            commandsId[cmdid]=gcBrowse;

            isSubMenu = DisplayInSubmenu(szCascadeShellMenuItems, gcCommit);
            cmdid = AddMenuItem(!isSubMenu ? hMenu : popupMenu, L"Commit", IDI_ICONCOMMIT, uidFirstCmd, ++id, !isSubMenu ? menuIndex++ : submenuIndex++, isSubMenu);
            commandsId[cmdid]=gcCommit;

            isSubMenu = DisplayInSubmenu(szCascadeShellMenuItems, gcPull);
            cmdid = AddMenuItem(!isSubMenu ? hMenu : popupMenu, L"Pull", IDI_ICONPULL, uidFirstCmd, ++id, !isSubMenu ? menuIndex++ : submenuIndex++, isSubMenu);
            commandsId[cmdid]=gcPull;

            isSubMenu = DisplayInSubmenu(szCascadeShellMenuItems, gcPush);
            cmdid=AddMenuItem(!isSubMenu ? hMenu : popupMenu, L"Push", IDI_ICONPUSH, uidFirstCmd, ++id, !isSubMenu ? menuIndex++ : submenuIndex++, isSubMenu);
            commandsId[cmdid]=gcPush;

            isSubMenu = DisplayInSubmenu(szCascadeShellMenuItems, gcStash);
            cmdid=AddMenuItem(!isSubMenu ? hMenu : popupMenu, L"View stash", IDI_ICONSTASH, uidFirstCmd, ++id, !isSubMenu ? menuIndex++ : submenuIndex++, isSubMenu);
            commandsId[cmdid]=gcStash;

            isSubMenu = DisplayInSubmenu(szCascadeShellMenuItems, gcViewDiff);
            cmdid=AddMenuItem(!isSubMenu ? hMenu : popupMenu, L"View changes", IDI_ICONVIEWCHANGES, uidFirstCmd, ++id, !isSubMenu ? menuIndex++ : submenuIndex++, isSubMenu);
            commandsId[cmdid]=gcViewDiff;

            isSubMenu = DisplayInSubmenu(szCascadeShellMenuItems, gcCheckoutBranch);
            if (isSubMenu && submenuIndex > 0) {
                InsertMenu(popupMenu, submenuIndex++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL); ++id;
            }
            cmdid=AddMenuItem(!isSubMenu ? hMenu : popupMenu, L"Checkout branch", IDI_ICONBRANCHCHECKOUT, uidFirstCmd, ++id, !isSubMenu ? menuIndex++ : submenuIndex++, isSubMenu);
            commandsId[cmdid]=gcCheckoutBranch;

            isSubMenu = DisplayInSubmenu(szCascadeShellMenuItems, gcCheckoutRevision);
            cmdid=AddMenuItem(!isSubMenu ? hMenu : popupMenu, L"Checkout revision", IDI_ICONREVISIONCHECKOUT, uidFirstCmd, ++id, !isSubMenu ? menuIndex++ : submenuIndex++, isSubMenu);
            commandsId[cmdid]=gcCheckoutRevision;

            isSubMenu = DisplayInSubmenu(szCascadeShellMenuItems, gcCreateBranch);
            cmdid=AddMenuItem(!isSubMenu ? hMenu : popupMenu, L"Create branch", IDI_ICONBRANCHCREATE, uidFirstCmd, ++id, !isSubMenu ? menuIndex++ : submenuIndex++, isSubMenu);
            commandsId[cmdid]=gcCreateBranch;
        }

        isSubMenu = DisplayInSubmenu(szCascadeShellMenuItems, gcDiffTool);
        if (isSubMenu && submenuIndex > 0) {
            InsertMenu(popupMenu, submenuIndex++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL); ++id;
        }
        cmdid=AddMenuItem(!isSubMenu ? hMenu : popupMenu, L"Open with difftool", IDI_ICONVIEWCHANGES, uidFirstCmd, ++id, !isSubMenu ? menuIndex++ : submenuIndex++, isSubMenu);
        commandsId[cmdid]=gcDiffTool;

        isSubMenu = DisplayInSubmenu(szCascadeShellMenuItems, gcFileHistory);
        cmdid=AddMenuItem(!isSubMenu ? hMenu : popupMenu, L"File history", IDI_ICONFILEHISTORY, uidFirstCmd, ++id, !isSubMenu ? menuIndex++ : submenuIndex++, isSubMenu);
        commandsId[cmdid]=gcFileHistory;

        isSubMenu = DisplayInSubmenu(szCascadeShellMenuItems, gcResetFileChanges);
        cmdid=AddMenuItem(!isSubMenu ? hMenu : popupMenu, L"Reset file changes", IDI_ICONTRESETFILETO, uidFirstCmd, ++id, !isSubMenu ? menuIndex++ : submenuIndex++, isSubMenu);
        commandsId[cmdid]=gcResetFileChanges;

        isSubMenu = DisplayInSubmenu(szCascadeShellMenuItems, gcAddFiles);
        cmdid=AddMenuItem(!isSubMenu ? hMenu : popupMenu, L"Add files", IDI_ICONADDED, uidFirstCmd, ++id, !isSubMenu ? menuIndex++ : submenuIndex++, isSubMenu);
        commandsId[cmdid]=gcAddFiles;

        isSubMenu = DisplayInSubmenu(szCascadeShellMenuItems, gcApplyPatch);
        cmdid=AddMenuItem(!isSubMenu ? hMenu : popupMenu, L"Apply patch", 0, uidFirstCmd, ++id, !isSubMenu ? menuIndex++ : submenuIndex++, isSubMenu);
        commandsId[cmdid]=gcApplyPatch;
    }
    else 
    {
        isSubMenu = DisplayInSubmenu(szCascadeShellMenuItems, gcClone);
        cmdid=AddMenuItem(!isSubMenu ? hMenu : popupMenu, L"Clone", IDI_ICONCLONEREPOGIT, uidFirstCmd, ++id, !isSubMenu ? menuIndex++ : submenuIndex++, isSubMenu);
        commandsId[cmdid]=gcClone;

        isSubMenu = DisplayInSubmenu(szCascadeShellMenuItems, gcCreateRepository);
        cmdid=AddMenuItem(!isSubMenu ? hMenu : popupMenu, L"Create new repository", IDI_ICONCREATEREPOSITORY, uidFirstCmd, ++id, !isSubMenu ? menuIndex++ : submenuIndex++, isSubMenu);
        commandsId[cmdid]=gcCreateRepository;
    }

    isSubMenu = DisplayInSubmenu(szCascadeShellMenuItems, gcSettings);
    if (isSubMenu && submenuIndex > 0) {
        InsertMenu(popupMenu, submenuIndex++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL); ++id;
    }
    cmdid=AddMenuItem(!isSubMenu ? hMenu : popupMenu, L"Settings", IDI_ICONSETTINGS, uidFirstCmd, ++id, !isSubMenu ? menuIndex++ : submenuIndex++, isSubMenu);
    commandsId[cmdid]=gcSettings;

    ++id;

    if (CascadeContextMenu)
    {
        MENUITEMINFO info;
        info.cbSize = sizeof( MENUITEMINFO );
        info.fMask = MIIM_STRING | MIIM_ID | MIIM_BITMAP | MIIM_SUBMENU;
        info.wID = uidFirstCmd + 1;
        info.hbmpItem = IsVistaOrLater() ? IconToBitmapPARGB32(IDI_GITEXTENSIONS) : HBMMENU_CALLBACK;
        myIDMap[1] = IDI_GITEXTENSIONS;
        myIDMap[uidFirstCmd + 1] = IDI_GITEXTENSIONS;
        info.dwTypeData = _T("Git Extensions");
        info.hSubMenu = popupMenu;
        InsertMenuItem(hMenu, menuIndex, true, &info);
    }

    return MAKE_HRESULT ( SEVERITY_SUCCESS, FACILITY_NULL, id);
}
Пример #27
0
void
EnableBatteryNotifications()
{
#if MOZ_WINSDK_TARGETVER >= MOZ_NTDDI_LONGHORN
  if (IsVistaOrLater()) {
    // RegisterPowerSettingNotification is from Vista or later.
    // Use this API if available.
    HMODULE hUser32 = GetModuleHandleW(L"USER32.DLL");
    if (!sRegisterPowerSettingNotification)
      sRegisterPowerSettingNotification = (REGISTERPOWERSETTINGNOTIFICATION)
        GetProcAddress(hUser32, "RegisterPowerSettingNotification");
    if (!sUnregisterPowerSettingNotification)
      sUnregisterPowerSettingNotification = (UNREGISTERPOWERSETTINGNOTIFICATION)
        GetProcAddress(hUser32, "UnregisterPowerSettingNotification");

    if (!sRegisterPowerSettingNotification ||
        !sUnregisterPowerSettingNotification) {
      NS_ASSERTION(false, "Canot find PowerSettingNotification functions.");
      return;
    }

    // Create custom window to watch battery event
    // If we can get Gecko's window handle, this is unnecessary.

    if (sHWnd == nsnull) {
      WNDCLASSW wc;
      HMODULE hSelf = GetModuleHandle(nsnull);

      if (!GetClassInfoW(hSelf, L"MozillaBatteryClass", &wc)) {
        ZeroMemory(&wc, sizeof(WNDCLASSW));
        wc.hInstance = hSelf;
        wc.lpfnWndProc = BatteryWindowProc;
        wc.lpszClassName = L"MozillaBatteryClass";
        RegisterClassW(&wc);
      }

      sHWnd = CreateWindowW(L"MozillaBatteryClass", L"Battery Watcher",
                            0, 0, 0, 0, 0,
                            nsnull, nsnull, hSelf, nsnull);
    }

    if (sHWnd == nsnull) {
      return;
    }

    sPowerHandle =
      sRegisterPowerSettingNotification(sHWnd,
                                        &GUID_ACDC_POWER_SOURCE,
                                        DEVICE_NOTIFY_WINDOW_HANDLE);
    sCapacityHandle =
      sRegisterPowerSettingNotification(sHWnd,
                                        &GUID_BATTERY_PERCENTAGE_REMAINING,
                                        DEVICE_NOTIFY_WINDOW_HANDLE);
  } else
#endif
  {
    // for Windows 2000 and Windwos XP.  If we remove Windows XP support,
    // we should remove timer-based power notification
    sUpdateTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
    if (sUpdateTimer) {
      sUpdateTimer->InitWithFuncCallback(UpdateHandler,
                                         nsnull,
                                         Preferences::GetInt("dom.battery.timer",
                                                             30000 /* 30s */),
                                         nsITimer::TYPE_REPEATING_SLACK);
    } 
  }
}
Пример #28
0
/* static */
MediaKeySystemStatus
MediaKeySystemAccess::GetKeySystemStatus(const nsAString& aKeySystem,
                                         int32_t aMinCdmVersion,
                                         nsACString& aOutMessage,
                                         nsACString& aOutCdmVersion)
{
  MOZ_ASSERT(MediaPrefs::EMEEnabled());
  nsCOMPtr<mozIGeckoMediaPluginService> mps =
    do_GetService("@mozilla.org/gecko-media-plugin-service;1");
  if (NS_WARN_IF(!mps)) {
    aOutMessage = NS_LITERAL_CSTRING("Failed to get GMP service");
    return MediaKeySystemStatus::Error;
  }

  if (aKeySystem.EqualsLiteral("org.w3.clearkey")) {
    if (!Preferences::GetBool("media.eme.clearkey.enabled", true)) {
      aOutMessage = NS_LITERAL_CSTRING("ClearKey was disabled");
      return MediaKeySystemStatus::Cdm_disabled;
    }
    return EnsureMinCDMVersion(mps, aKeySystem, aMinCdmVersion, aOutMessage, aOutCdmVersion);
  }

  if (Preferences::GetBool("media.gmp-eme-adobe.visible", false)) {
    if (aKeySystem.EqualsLiteral("com.adobe.primetime")) {
      if (!Preferences::GetBool("media.gmp-eme-adobe.enabled", false)) {
        aOutMessage = NS_LITERAL_CSTRING("Adobe EME disabled");
        return MediaKeySystemStatus::Cdm_disabled;
      }
#ifdef XP_WIN
      // Win Vista and later only.
      if (!IsVistaOrLater()) {
        aOutMessage = NS_LITERAL_CSTRING("Minimum Windows version (Vista) not met for Adobe EME");
        return MediaKeySystemStatus::Cdm_not_supported;
      }
#endif
#ifdef XP_MACOSX
      if (!nsCocoaFeatures::OnLionOrLater()) {
        aOutMessage = NS_LITERAL_CSTRING("Minimum MacOSX version (10.7) not met for Adobe EME");
        return MediaKeySystemStatus::Cdm_not_supported;
      }
#endif
      return EnsureMinCDMVersion(mps, aKeySystem, aMinCdmVersion, aOutMessage, aOutCdmVersion);
    }
  }

  if (Preferences::GetBool("media.gmp-widevinecdm.visible", false)) {
    if (aKeySystem.EqualsLiteral("com.widevine.alpha")) {
#ifdef XP_WIN
      // Win Vista and later only.
      if (!IsVistaOrLater()) {
        aOutMessage = NS_LITERAL_CSTRING("Minimum Windows version (Vista) not met for Widevine EME");
        return MediaKeySystemStatus::Cdm_not_supported;
      }
#endif
#ifdef XP_MACOSX
      if (!nsCocoaFeatures::OnLionOrLater()) {
        aOutMessage = NS_LITERAL_CSTRING("Minimum MacOSX version (10.7) not met for Widevine EME");
        return MediaKeySystemStatus::Cdm_not_supported;
      }
#endif
      if (!Preferences::GetBool("media.gmp-widevinecdm.enabled", false)) {
        aOutMessage = NS_LITERAL_CSTRING("Widevine EME disabled");
        return MediaKeySystemStatus::Cdm_disabled;
      }
      return EnsureMinCDMVersion(mps, aKeySystem, aMinCdmVersion, aOutMessage, aOutCdmVersion);
    }
  }

  return MediaKeySystemStatus::Cdm_not_supported;
}