Exemple #1
0
NPBool CPlugin::init(NPWindow* pNPWindow)
{
  AfxEnableControlContainer();

  if(pNPWindow == NULL)
    return FALSE;

  m_hWnd = (HWND)pNPWindow->window;
  if (!IsWindow(m_hWnd))
    return FALSE;

  DWORD navId = 0;
  CString url;
  CString post;
  CString headers;

  if (m_strId == _T("coba-object"))
  {
    // 获取Plugin所在页面的URL, URL的格式是chrome://coba/content/container.xhtml?url=XXX,
    // 其中XXX是实际要访问的URL
    CString strHostUrl = GetHostURL();
    static const CString PREFIX(_T("chrome://coba/content/container.xhtml?url="));

    // 安全检查, 检查Plugin所在页面的URL,不允许其他插件或页面调用这个Plugin
    if (!strHostUrl.Mid(0, PREFIX.GetLength()) == PREFIX)
      return FALSE;

    // 从URL参数中获取实际要访问的URL地址
    url = strHostUrl.Mid(PREFIX.GetLength());

    // 获取从Firefox传入的其他参数
    navId = GetNavigateWindowId();
    post = GetNavigatePostData();
    headers = GetNavigateHeaders();
    RemoveNavigateParams();
  }

  m_pIEHostWindow = CreateIEHostWindow(m_hWnd, navId);
  if (m_pIEHostWindow == NULL)
  {
    return FALSE;
  }

  if (m_strId == _T("coba-cookie-object"))
  {
    CIEHostWindow::AddCookieIEWindow(m_pIEHostWindow);
  }

  // navId为0时,IEHostWindow是新创建的,需要指定浏览器的地址
  if (navId == 0)
  {
    m_pIEHostWindow->Navigate(url, post, headers);
  }


  // 有了这两句, Firefox 窗口变化的时候才会通知 IE 窗口刷新显示
  SetWindowLong(m_hWnd, GWL_STYLE, GetWindowLong(m_hWnd, GWL_STYLE)|WS_CLIPCHILDREN);
  SetWindowLong(m_hWnd, GWL_EXSTYLE, GetWindowLong(m_hWnd, GWL_EXSTYLE)|WS_EX_CONTROLPARENT);

  m_bInitialized = TRUE;
  return TRUE;
}
Exemple #2
0
	NPBool CPlugin::init(NPWindow* pNPWindow)
	{
		if(pNPWindow == NULL)
			return FALSE;

		m_hWnd = (HWND)pNPWindow->window;
		if (!IsWindow(m_hWnd))
			return FALSE;

		ULONG_PTR ulId = 0;
		CString url;
		CString post;
		CString headers;

		bool bIsContentPlugin = m_strId == RES_OBJECTNAME_T;
		m_bIsUtilsPlugin = m_strId == RES_UTILS_OBJECT_T;

		if (bIsContentPlugin)
		{
			// Fetch the hosting page's URL. The format is chrome://fireie/content/container.xhtml?url=XXX
			// where XXX is the actual URL to visit
			CString strHostUrl = GetHostURL();
			static const CString PREFIX(RES_CHROME_PREFIX_T);

			// Secrity check. Do not allow other pages to load this plugin.
			if (strHostUrl.Mid(0, PREFIX.GetLength()) != PREFIX)
				return FALSE;

			// Fetch the URL to visit from host URL
			url = GetNavigateURL();

			// Fetch other parameters from Firefox
			ulId = GetNavigateWindowId();
			post = GetNavigatePostData();
			headers = GetNavigateHeaders();
			RemoveNavigateParams();
		}
		else if (m_bIsUtilsPlugin)
		{
			CString strHostUrl = GetHostURL();

			// Secrity check. Do not allow pages other than the hidden window to load the utils plugin.
			if (strHostUrl != RES_UTILS_URL_T)
				return FALSE;
		}
		else return FALSE;

		bool bIsNewlyCreated = true;
		m_pIEHostWindow = CreateIEHostWindow(m_hWnd, ulId, m_bIsUtilsPlugin, &bIsNewlyCreated);
		if (m_pIEHostWindow == NULL)
		{
			return FALSE;
		}

		if (m_bIsUtilsPlugin)
		{
			CIEHostWindow::AddUtilsIEWindow(m_pIEHostWindow);
		}

		// if the IEHostWindow is newly created, we should specify its URL
		if (bIsNewlyCreated)
		{
			m_pIEHostWindow->Navigate(url, post, headers);
		}

		// Let IE redraw when Firefox window size changes
		SetWindowLong(m_hWnd, GWL_STYLE, GetWindowLong(m_hWnd, GWL_STYLE)|WS_CLIPCHILDREN);
		SetWindowLong(m_hWnd, GWL_EXSTYLE, GetWindowLong(m_hWnd, GWL_EXSTYLE)|WS_EX_CONTROLPARENT);

		m_bInitialized = TRUE;

		// Init event is fired when the scriptable plugin object is created

		return TRUE;
	}