instInternal->PushPopupsEnabledState();
instInternal->PushPopupsEnabledState(PR_TRUE);
static LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){  nsPluginNativeWindowWin * win = (nsPluginNativeWindowWin *)::GetProp(hWnd, NS_PLUGIN_WINDOW_PROPERTY_ASSOCIATION);  if (!win)    return TRUE;  // check plugin myme type and cache whether it is Flash or not  // Flash will need special treatment later  if (win->mPluginType == nsPluginType_Unknown) {    nsCOMPtr<nsIPluginInstance> inst;    win->GetPluginInstance(inst);    if (inst) {      nsCOMPtr<nsIPluginInstancePeer> pip;      inst->GetPeer(getter_AddRefs(pip));      if (pip) {        nsMIMEType mimetype = nsnull;        pip->GetMIMEType(&mimetype);        if (mimetype) {           if (!strcmp(mimetype, "application/x-shockwave-flash"))            win->mPluginType = nsPluginType_Flash;          else if (!strcmp(mimetype, "audio/x-pn-realaudio-plugin"))            win->mPluginType = nsPluginType_Real;          else            win->mPluginType = nsPluginType_Other;        }      }    }  }  // Real may go into a state where it recursivly dispatches the same event  // when subclassed. If this is Real, lets examine the event and drop it  // on the floor if we get into this recursive situation. See bug 192914.  if (win->mPluginType == nsPluginType_Real) {        if (sInMessageDispatch && (msg == sLastMsg)) {#ifdef DEBUG      printf("Dropping event %d for Real on the floor\n", msg);#endif      return PR_TRUE;  // prevents event dispatch    } else {      sLastMsg = msg;  // no need to prevent dispatch    }  }  PRBool enablePopups = PR_FALSE;  // Activate/deactivate mouse capture on the plugin widget  // here, before we pass the Windows event to the plugin  // because its possible our widget won't get paired events  // (see bug 131007) and we'll look frozen. Note that this  // is also done in ChildWindow::DispatchMouseEvent.  switch (msg) {    case WM_LBUTTONDOWN:    case WM_MBUTTONDOWN:    case WM_RBUTTONDOWN: {      nsCOMPtr<nsIWidget> widget;      win->GetPluginWidget(getter_AddRefs(widget));      if (widget)        widget->CaptureMouse(PR_TRUE);      break;    }    case WM_LBUTTONUP:      enablePopups = PR_TRUE;      // fall through    case WM_MBUTTONUP:    case WM_RBUTTONUP: {      nsCOMPtr<nsIWidget> widget;      win->GetPluginWidget(getter_AddRefs(widget));      if (widget)        widget->CaptureMouse(PR_FALSE);      break;    }    case WM_KEYDOWN:      // Ignore repeating keydown messages...      if ((lParam & 0x40000000) != 0) {        break;      }      // fall through    case WM_KEYUP:      enablePopups = PR_TRUE;      break;  }  // Macromedia Flash plugin may flood the message queue with some special messages  // (WM_USER+1) causing 100% CPU consumption and GUI freeze, see mozilla bug 132759;  // we can prevent this from happening by delaying the processing such messages;  if (win->mPluginType == nsPluginType_Flash) {    if (ProcessFlashMessageDelayed(win, hWnd, msg, wParam, lParam))      return TRUE;  }  LRESULT res = TRUE;  nsCOMPtr<nsIPluginInstanceInternal> instInternal;  nsCOMPtr<nsIPluginInstance> inst;  win->GetPluginInstance(inst);  if (enablePopups) {    nsCOMPtr<nsIPluginInstanceInternal> tmp = do_QueryInterface(inst);    if (tmp && !nsVersionOK(tmp->GetPluginAPIVersion(),                            NP_POPUP_API_VERSION)) {      tmp.swap(instInternal);      instInternal->PushPopupsEnabledState();    }  }  sInMessageDispatch = PR_TRUE;  NS_TRY_SAFE_CALL_RETURN(res,                           ::CallWindowProc((WNDPROC)win->GetWindowProc(), hWnd, msg, wParam, lParam),                          nsnull, inst);  sInMessageDispatch = PR_FALSE;  if (instInternal) {    // Popups are enabled (were enabled before the call to    // CallWindowProc()). Some plugins (at least the flash player)    // post messages from their key handlers etc that delay the actual    // processing, so we need to delay the disabling of popups so that    // popups remain enabled when the flash player ends up processing    // the actual key handlers. We do this by posting an event that    // does the disabling, this way our disabling will happen after    // the handlers in the plugin are done.    // Note that it's not fatal if any of this fails (which won't    // happen unless we're out of memory anyways) since the plugin    // code will pop any popup state pushed by this plugin on    // destruction.    nsIEventQueueService *eventService = win->GetEventService();    if (eventService) {      nsCOMPtr<nsIEventQueue> eventQueue;        eventService->GetThreadEventQueue(PR_GetCurrentThread(),                                        getter_AddRefs(eventQueue));      if (eventQueue) {        PLEvent *event = new PLEvent;        if (event) {          nsIPluginInstanceInternal *eventInst = instInternal;          // Make the event own the plugin instance.          NS_ADDREF(eventInst);          PL_InitEvent(event, eventInst, DelayedPopupsEnabledEvent_Handle,                       DelayedPopupsEnabledEvent_Destroy);          eventQueue->PostEvent(event);        }      }    }  }  return res;}