ipc/chromium/src/base/event_recorder.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ipc/chromium/src/base/event_recorder.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,102 @@
     1.4 +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
     1.5 +// Use of this source code is governed by a BSD-style license that can be
     1.6 +// found in the LICENSE file.
     1.7 +
     1.8 +#ifndef BASE_EVENT_RECORDER_H_
     1.9 +#define BASE_EVENT_RECORDER_H_
    1.10 +
    1.11 +#include <string>
    1.12 +#if defined(OS_WIN)
    1.13 +#include <windows.h>
    1.14 +#endif
    1.15 +#include "base/basictypes.h"
    1.16 +
    1.17 +class FilePath;
    1.18 +
    1.19 +namespace base {
    1.20 +
    1.21 +// A class for recording and playing back keyboard and mouse input events.
    1.22 +//
    1.23 +// Note - if you record events, and the playback with the windows in
    1.24 +//        different sizes or positions, the playback will fail.  When
    1.25 +//        recording and playing, you should move the relevant windows
    1.26 +//        to constant sizes and locations.
    1.27 +// TODO(mbelshe) For now this is a singleton.  I believe that this class
    1.28 +//        could be easily modified to:
    1.29 +//             support two simultaneous recorders
    1.30 +//             be playing back events while already recording events.
    1.31 +//        Why?  Imagine if the product had a "record a macro" feature.
    1.32 +//        You might be recording globally, while recording or playing back
    1.33 +//        a macro.  I don't think two playbacks make sense.
    1.34 +class EventRecorder {
    1.35 + public:
    1.36 +  // Get the singleton EventRecorder.
    1.37 +  // We can only handle one recorder/player at a time.
    1.38 +  static EventRecorder* current() {
    1.39 +    if (!current_)
    1.40 +      current_ = new EventRecorder();
    1.41 +    return current_;
    1.42 +  }
    1.43 +
    1.44 +  // Starts recording events.
    1.45 +  // Will clobber the file if it already exists.
    1.46 +  // Returns true on success, or false if an error occurred.
    1.47 +  bool StartRecording(const FilePath& filename);
    1.48 +
    1.49 +  // Stops recording.
    1.50 +  void StopRecording();
    1.51 +
    1.52 +  // Is the EventRecorder currently recording.
    1.53 +  bool is_recording() const { return is_recording_; }
    1.54 +
    1.55 +  // Plays events previously recorded.
    1.56 +  // Returns true on success, or false if an error occurred.
    1.57 +  bool StartPlayback(const FilePath& filename);
    1.58 +
    1.59 +  // Stops playback.
    1.60 +  void StopPlayback();
    1.61 +
    1.62 +  // Is the EventRecorder currently playing.
    1.63 +  bool is_playing() const { return is_playing_; }
    1.64 +
    1.65 +#if defined(OS_WIN)
    1.66 +  // C-style callbacks for the EventRecorder.
    1.67 +  // Used for internal purposes only.
    1.68 +  LRESULT RecordWndProc(int nCode, WPARAM wParam, LPARAM lParam);
    1.69 +  LRESULT PlaybackWndProc(int nCode, WPARAM wParam, LPARAM lParam);
    1.70 +#endif
    1.71 +
    1.72 + private:
    1.73 +  // Create a new EventRecorder.  Events are saved to the file filename.
    1.74 +  // If the file already exists, it will be deleted before recording
    1.75 +  // starts.
    1.76 +  explicit EventRecorder()
    1.77 +      : is_recording_(false),
    1.78 +        is_playing_(false),
    1.79 +#if defined(OS_WIN)
    1.80 +        journal_hook_(NULL),
    1.81 +        file_(NULL),
    1.82 +#endif
    1.83 +        playback_first_msg_time_(0),
    1.84 +        playback_start_time_(0) {
    1.85 +  }
    1.86 +  ~EventRecorder();
    1.87 +
    1.88 +  static EventRecorder* current_;  // Our singleton.
    1.89 +
    1.90 +  bool is_recording_;
    1.91 +  bool is_playing_;
    1.92 +#if defined(OS_WIN)
    1.93 +  HHOOK journal_hook_;
    1.94 +  FILE* file_;
    1.95 +  EVENTMSG playback_msg_;
    1.96 +#endif
    1.97 +  int playback_first_msg_time_;
    1.98 +  int playback_start_time_;
    1.99 +
   1.100 +  DISALLOW_EVIL_CONSTRUCTORS(EventRecorder);
   1.101 +};
   1.102 +
   1.103 +}  // namespace base
   1.104 +
   1.105 +#endif // BASE_EVENT_RECORDER_H_

mercurial