dom/plugins/ipc/PluginHangUIParent.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/plugins/ipc/PluginHangUIParent.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,159 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim: set ts=2 et sw=2 tw=80: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef mozilla_plugins_PluginHangUIParent_h
    1.11 +#define mozilla_plugins_PluginHangUIParent_h
    1.12 +
    1.13 +#include "nsString.h"
    1.14 +
    1.15 +#include "base/process.h"
    1.16 +#include "base/process_util.h"
    1.17 +
    1.18 +#include "mozilla/Mutex.h"
    1.19 +#include "mozilla/plugins/PluginMessageUtils.h"
    1.20 +
    1.21 +#include "MiniShmParent.h"
    1.22 +
    1.23 +namespace mozilla {
    1.24 +namespace plugins {
    1.25 +
    1.26 +class PluginModuleParent;
    1.27 +
    1.28 +/**
    1.29 + * This class is responsible for launching and communicating with the 
    1.30 + * plugin-hang-ui process.
    1.31 + *
    1.32 + * NOTE: PluginHangUIParent is *not* an IPDL actor! In this case, "Parent" 
    1.33 + *       is describing the fact that firefox is the parent process to the 
    1.34 + *       plugin-hang-ui process, which is the PluginHangUIChild.
    1.35 + *       PluginHangUIParent and PluginHangUIChild are a matched pair.
    1.36 + * @see PluginHangUIChild
    1.37 + */
    1.38 +class PluginHangUIParent : public MiniShmObserver
    1.39 +{
    1.40 +public:
    1.41 +  PluginHangUIParent(PluginModuleParent* aModule,
    1.42 +                     const int32_t aHangUITimeoutPref,
    1.43 +                     const int32_t aChildTimeoutPref);
    1.44 +  virtual ~PluginHangUIParent();
    1.45 +
    1.46 +  /**
    1.47 +   * Spawn the plugin-hang-ui.exe child process and terminate the given 
    1.48 +   * plugin container process if the user elects to stop the hung plugin.
    1.49 +   *
    1.50 +   * @param aPluginName Human-readable name of the affected plugin.
    1.51 +   * @return true if the plugin hang ui process was successfully launched,
    1.52 +   *         otherwise false.
    1.53 +   */
    1.54 +  bool
    1.55 +  Init(const nsString& aPluginName);
    1.56 +
    1.57 +  /**
    1.58 +   * If the Plugin Hang UI is being shown, send a cancel notification to the 
    1.59 +   * Plugin Hang UI child process.
    1.60 +   *
    1.61 +   * @return true if the UI was shown and the cancel command was successfully
    1.62 +   *              sent to the child process, otherwise false.
    1.63 +   */
    1.64 +  bool
    1.65 +  Cancel();
    1.66 +
    1.67 +  /**
    1.68 +   * Returns whether the Plugin Hang UI is currently being displayed.
    1.69 +   *
    1.70 +   * @return true if the Plugin Hang UI is showing, otherwise false.
    1.71 +   */
    1.72 +  bool
    1.73 +  IsShowing() const { return mIsShowing; }
    1.74 +
    1.75 +  /**
    1.76 +   * Returns whether this Plugin Hang UI instance has been shown. Note 
    1.77 +   * that this does not necessarily mean that the UI is showing right now.
    1.78 +   *
    1.79 +   * @return true if the Plugin Hang UI has shown, otherwise false.
    1.80 +   */
    1.81 +  bool
    1.82 +  WasShown() const { return mIsShowing || mLastUserResponse != 0; }
    1.83 +
    1.84 +  /**
    1.85 +   * Returns whether the user checked the "Don't ask me again" checkbox.
    1.86 +   *
    1.87 +   * @return true if the user does not want to see the Hang UI again.
    1.88 +   */
    1.89 +  bool
    1.90 +  DontShowAgain() const;
    1.91 +
    1.92 +  /**
    1.93 +   * Returns whether the user clicked stop during the last time that the 
    1.94 +   * Plugin Hang UI was displayed, if applicable.
    1.95 +   *
    1.96 +   * @return true if the UI was shown and the user chose to stop the 
    1.97 +   *         plugin, otherwise false
    1.98 +   */
    1.99 +  bool
   1.100 +  WasLastHangStopped() const;
   1.101 +
   1.102 +  /**
   1.103 +   * @return unsigned int containing the response bits from the last 
   1.104 +   * time the Plugin Hang UI ran.
   1.105 +   */
   1.106 +  unsigned int
   1.107 +  LastUserResponse() const { return mLastUserResponse; }
   1.108 +
   1.109 +  /**
   1.110 +   * @return unsigned int containing the number of milliseconds that 
   1.111 +   * the Plugin Hang UI was displayed before the user responded.
   1.112 +   * Returns 0 if the Plugin Hang UI has not been shown or was cancelled.
   1.113 +   */
   1.114 +  unsigned int
   1.115 +  LastShowDurationMs() const;
   1.116 +
   1.117 +  virtual void
   1.118 +  OnMiniShmEvent(MiniShmBase* aMiniShmObj) MOZ_OVERRIDE;
   1.119 +
   1.120 +  virtual void
   1.121 +  OnMiniShmConnect(MiniShmBase* aMiniShmObj) MOZ_OVERRIDE;
   1.122 +
   1.123 +private:
   1.124 +  nsresult
   1.125 +  GetHangUIOwnerWindowHandle(NativeWindowHandle& windowHandle);
   1.126 +
   1.127 +  bool
   1.128 +  SendCancel();
   1.129 +
   1.130 +  bool
   1.131 +  RecvUserResponse(const unsigned int& aResponse);
   1.132 +
   1.133 +  bool
   1.134 +  UnwatchHangUIChildProcess(bool aWait);
   1.135 +
   1.136 +  static
   1.137 +  VOID CALLBACK SOnHangUIProcessExit(PVOID aContext, BOOLEAN aIsTimer);
   1.138 +
   1.139 +private:
   1.140 +  Mutex mMutex;
   1.141 +  PluginModuleParent* mModule;
   1.142 +  const uint32_t mTimeoutPrefMs;
   1.143 +  const uint32_t mIPCTimeoutMs;
   1.144 +  MessageLoop* mMainThreadMessageLoop;
   1.145 +  bool mIsShowing;
   1.146 +  unsigned int mLastUserResponse;
   1.147 +  base::ProcessHandle mHangUIProcessHandle;
   1.148 +  NativeWindowHandle mMainWindowHandle;
   1.149 +  HANDLE mRegWait;
   1.150 +  HANDLE mShowEvent;
   1.151 +  DWORD mShowTicks;
   1.152 +  DWORD mResponseTicks;
   1.153 +  MiniShmParent mMiniShm;
   1.154 +
   1.155 +  DISALLOW_COPY_AND_ASSIGN(PluginHangUIParent);
   1.156 +};
   1.157 +
   1.158 +} // namespace plugins
   1.159 +} // namespace mozilla
   1.160 +
   1.161 +#endif // mozilla_plugins_PluginHangUIParent_h
   1.162 +

mercurial