Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
michael@0 | 2 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 3 | // found in the LICENSE file. |
michael@0 | 4 | |
michael@0 | 5 | #ifndef BASE_EVENT_RECORDER_H_ |
michael@0 | 6 | #define BASE_EVENT_RECORDER_H_ |
michael@0 | 7 | |
michael@0 | 8 | #include <string> |
michael@0 | 9 | #if defined(OS_WIN) |
michael@0 | 10 | #include <windows.h> |
michael@0 | 11 | #endif |
michael@0 | 12 | #include "base/basictypes.h" |
michael@0 | 13 | |
michael@0 | 14 | class FilePath; |
michael@0 | 15 | |
michael@0 | 16 | namespace base { |
michael@0 | 17 | |
michael@0 | 18 | // A class for recording and playing back keyboard and mouse input events. |
michael@0 | 19 | // |
michael@0 | 20 | // Note - if you record events, and the playback with the windows in |
michael@0 | 21 | // different sizes or positions, the playback will fail. When |
michael@0 | 22 | // recording and playing, you should move the relevant windows |
michael@0 | 23 | // to constant sizes and locations. |
michael@0 | 24 | // TODO(mbelshe) For now this is a singleton. I believe that this class |
michael@0 | 25 | // could be easily modified to: |
michael@0 | 26 | // support two simultaneous recorders |
michael@0 | 27 | // be playing back events while already recording events. |
michael@0 | 28 | // Why? Imagine if the product had a "record a macro" feature. |
michael@0 | 29 | // You might be recording globally, while recording or playing back |
michael@0 | 30 | // a macro. I don't think two playbacks make sense. |
michael@0 | 31 | class EventRecorder { |
michael@0 | 32 | public: |
michael@0 | 33 | // Get the singleton EventRecorder. |
michael@0 | 34 | // We can only handle one recorder/player at a time. |
michael@0 | 35 | static EventRecorder* current() { |
michael@0 | 36 | if (!current_) |
michael@0 | 37 | current_ = new EventRecorder(); |
michael@0 | 38 | return current_; |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | // Starts recording events. |
michael@0 | 42 | // Will clobber the file if it already exists. |
michael@0 | 43 | // Returns true on success, or false if an error occurred. |
michael@0 | 44 | bool StartRecording(const FilePath& filename); |
michael@0 | 45 | |
michael@0 | 46 | // Stops recording. |
michael@0 | 47 | void StopRecording(); |
michael@0 | 48 | |
michael@0 | 49 | // Is the EventRecorder currently recording. |
michael@0 | 50 | bool is_recording() const { return is_recording_; } |
michael@0 | 51 | |
michael@0 | 52 | // Plays events previously recorded. |
michael@0 | 53 | // Returns true on success, or false if an error occurred. |
michael@0 | 54 | bool StartPlayback(const FilePath& filename); |
michael@0 | 55 | |
michael@0 | 56 | // Stops playback. |
michael@0 | 57 | void StopPlayback(); |
michael@0 | 58 | |
michael@0 | 59 | // Is the EventRecorder currently playing. |
michael@0 | 60 | bool is_playing() const { return is_playing_; } |
michael@0 | 61 | |
michael@0 | 62 | #if defined(OS_WIN) |
michael@0 | 63 | // C-style callbacks for the EventRecorder. |
michael@0 | 64 | // Used for internal purposes only. |
michael@0 | 65 | LRESULT RecordWndProc(int nCode, WPARAM wParam, LPARAM lParam); |
michael@0 | 66 | LRESULT PlaybackWndProc(int nCode, WPARAM wParam, LPARAM lParam); |
michael@0 | 67 | #endif |
michael@0 | 68 | |
michael@0 | 69 | private: |
michael@0 | 70 | // Create a new EventRecorder. Events are saved to the file filename. |
michael@0 | 71 | // If the file already exists, it will be deleted before recording |
michael@0 | 72 | // starts. |
michael@0 | 73 | explicit EventRecorder() |
michael@0 | 74 | : is_recording_(false), |
michael@0 | 75 | is_playing_(false), |
michael@0 | 76 | #if defined(OS_WIN) |
michael@0 | 77 | journal_hook_(NULL), |
michael@0 | 78 | file_(NULL), |
michael@0 | 79 | #endif |
michael@0 | 80 | playback_first_msg_time_(0), |
michael@0 | 81 | playback_start_time_(0) { |
michael@0 | 82 | } |
michael@0 | 83 | ~EventRecorder(); |
michael@0 | 84 | |
michael@0 | 85 | static EventRecorder* current_; // Our singleton. |
michael@0 | 86 | |
michael@0 | 87 | bool is_recording_; |
michael@0 | 88 | bool is_playing_; |
michael@0 | 89 | #if defined(OS_WIN) |
michael@0 | 90 | HHOOK journal_hook_; |
michael@0 | 91 | FILE* file_; |
michael@0 | 92 | EVENTMSG playback_msg_; |
michael@0 | 93 | #endif |
michael@0 | 94 | int playback_first_msg_time_; |
michael@0 | 95 | int playback_start_time_; |
michael@0 | 96 | |
michael@0 | 97 | DISALLOW_EVIL_CONSTRUCTORS(EventRecorder); |
michael@0 | 98 | }; |
michael@0 | 99 | |
michael@0 | 100 | } // namespace base |
michael@0 | 101 | |
michael@0 | 102 | #endif // BASE_EVENT_RECORDER_H_ |