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

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

mercurial