dom/plugins/ipc/PluginHangUIParent.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim: set ts=2 et sw=2 tw=80: */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 #ifndef mozilla_plugins_PluginHangUIParent_h
     8 #define mozilla_plugins_PluginHangUIParent_h
    10 #include "nsString.h"
    12 #include "base/process.h"
    13 #include "base/process_util.h"
    15 #include "mozilla/Mutex.h"
    16 #include "mozilla/plugins/PluginMessageUtils.h"
    18 #include "MiniShmParent.h"
    20 namespace mozilla {
    21 namespace plugins {
    23 class PluginModuleParent;
    25 /**
    26  * This class is responsible for launching and communicating with the 
    27  * plugin-hang-ui process.
    28  *
    29  * NOTE: PluginHangUIParent is *not* an IPDL actor! In this case, "Parent" 
    30  *       is describing the fact that firefox is the parent process to the 
    31  *       plugin-hang-ui process, which is the PluginHangUIChild.
    32  *       PluginHangUIParent and PluginHangUIChild are a matched pair.
    33  * @see PluginHangUIChild
    34  */
    35 class PluginHangUIParent : public MiniShmObserver
    36 {
    37 public:
    38   PluginHangUIParent(PluginModuleParent* aModule,
    39                      const int32_t aHangUITimeoutPref,
    40                      const int32_t aChildTimeoutPref);
    41   virtual ~PluginHangUIParent();
    43   /**
    44    * Spawn the plugin-hang-ui.exe child process and terminate the given 
    45    * plugin container process if the user elects to stop the hung plugin.
    46    *
    47    * @param aPluginName Human-readable name of the affected plugin.
    48    * @return true if the plugin hang ui process was successfully launched,
    49    *         otherwise false.
    50    */
    51   bool
    52   Init(const nsString& aPluginName);
    54   /**
    55    * If the Plugin Hang UI is being shown, send a cancel notification to the 
    56    * Plugin Hang UI child process.
    57    *
    58    * @return true if the UI was shown and the cancel command was successfully
    59    *              sent to the child process, otherwise false.
    60    */
    61   bool
    62   Cancel();
    64   /**
    65    * Returns whether the Plugin Hang UI is currently being displayed.
    66    *
    67    * @return true if the Plugin Hang UI is showing, otherwise false.
    68    */
    69   bool
    70   IsShowing() const { return mIsShowing; }
    72   /**
    73    * Returns whether this Plugin Hang UI instance has been shown. Note 
    74    * that this does not necessarily mean that the UI is showing right now.
    75    *
    76    * @return true if the Plugin Hang UI has shown, otherwise false.
    77    */
    78   bool
    79   WasShown() const { return mIsShowing || mLastUserResponse != 0; }
    81   /**
    82    * Returns whether the user checked the "Don't ask me again" checkbox.
    83    *
    84    * @return true if the user does not want to see the Hang UI again.
    85    */
    86   bool
    87   DontShowAgain() const;
    89   /**
    90    * Returns whether the user clicked stop during the last time that the 
    91    * Plugin Hang UI was displayed, if applicable.
    92    *
    93    * @return true if the UI was shown and the user chose to stop the 
    94    *         plugin, otherwise false
    95    */
    96   bool
    97   WasLastHangStopped() const;
    99   /**
   100    * @return unsigned int containing the response bits from the last 
   101    * time the Plugin Hang UI ran.
   102    */
   103   unsigned int
   104   LastUserResponse() const { return mLastUserResponse; }
   106   /**
   107    * @return unsigned int containing the number of milliseconds that 
   108    * the Plugin Hang UI was displayed before the user responded.
   109    * Returns 0 if the Plugin Hang UI has not been shown or was cancelled.
   110    */
   111   unsigned int
   112   LastShowDurationMs() const;
   114   virtual void
   115   OnMiniShmEvent(MiniShmBase* aMiniShmObj) MOZ_OVERRIDE;
   117   virtual void
   118   OnMiniShmConnect(MiniShmBase* aMiniShmObj) MOZ_OVERRIDE;
   120 private:
   121   nsresult
   122   GetHangUIOwnerWindowHandle(NativeWindowHandle& windowHandle);
   124   bool
   125   SendCancel();
   127   bool
   128   RecvUserResponse(const unsigned int& aResponse);
   130   bool
   131   UnwatchHangUIChildProcess(bool aWait);
   133   static
   134   VOID CALLBACK SOnHangUIProcessExit(PVOID aContext, BOOLEAN aIsTimer);
   136 private:
   137   Mutex mMutex;
   138   PluginModuleParent* mModule;
   139   const uint32_t mTimeoutPrefMs;
   140   const uint32_t mIPCTimeoutMs;
   141   MessageLoop* mMainThreadMessageLoop;
   142   bool mIsShowing;
   143   unsigned int mLastUserResponse;
   144   base::ProcessHandle mHangUIProcessHandle;
   145   NativeWindowHandle mMainWindowHandle;
   146   HANDLE mRegWait;
   147   HANDLE mShowEvent;
   148   DWORD mShowTicks;
   149   DWORD mResponseTicks;
   150   MiniShmParent mMiniShm;
   152   DISALLOW_COPY_AND_ASSIGN(PluginHangUIParent);
   153 };
   155 } // namespace plugins
   156 } // namespace mozilla
   158 #endif // mozilla_plugins_PluginHangUIParent_h

mercurial