Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(254)

Side by Side Diff: third_party/WebKit/Source/platform/UserGestureIndicator.h

Issue 1799253002: Stricter user gestures for touch - measure and warn (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tweaks Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2010 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 WTF_MAKE_NONCOPYABLE(UserGestureToken); 44 WTF_MAKE_NONCOPYABLE(UserGestureToken);
45 public: 45 public:
46 UserGestureToken() { } 46 UserGestureToken() { }
47 virtual ~UserGestureToken() { } 47 virtual ~UserGestureToken() { }
48 virtual bool hasGestures() const = 0; 48 virtual bool hasGestures() const = 0;
49 virtual void setOutOfProcess() = 0; 49 virtual void setOutOfProcess() = 0;
50 virtual void setJavascriptPrompt() = 0; 50 virtual void setJavascriptPrompt() = 0;
51 virtual void setPauseInDebugger() = 0; 51 virtual void setPauseInDebugger() = 0;
52 }; 52 };
53 53
54 // Callback to be invoked when the state of a UserGestureIndicator is
55 // used (only during the scope of a UserGestureIndicator, does
56 // not flow with the UserGestureToken). It's the responsibility of the
57 // caller to ensure the UserGestureUtilizedCallback is kept alive as long
58 // as the UserGestureIndicator it's used in.
59 // Note that this doesn't currently track EVERY way in which the
60 // state of a UserGesture can be read (sometimes it's just propagated
61 // elsewhere, or otherwise read in a way that's hard to know if it will
62 // actually be used), but should include the primary use cases. Therefore
63 // this is suitable mainly for diagnostics and measurement purposes.
64 class PLATFORM_EXPORT UserGestureUtilizedCallback {
65 public:
66 virtual ~UserGestureUtilizedCallback() = default;
67 virtual void userGestureUtilized() = 0;
68 };
69
54 class PLATFORM_EXPORT UserGestureIndicator final { 70 class PLATFORM_EXPORT UserGestureIndicator final {
55 USING_FAST_MALLOC(UserGestureIndicator); 71 USING_FAST_MALLOC(UserGestureIndicator);
56 WTF_MAKE_NONCOPYABLE(UserGestureIndicator); 72 WTF_MAKE_NONCOPYABLE(UserGestureIndicator);
57 public: 73 public:
74 // Returns whether a user gesture is currently in progress.
75 // Does not invoke the UserGestureUtilizedCallback. Consider calling
76 // utilizeUserGesture instead if you know for sure that the return value
77 // will have an effect.
58 static bool processingUserGesture(); 78 static bool processingUserGesture();
79
80 // Indicates that a user gesture (if any) is being used, without preventing it
81 // from being used again. Returns whether a user gesture is currently in pr ogress.
82 // If true, invokes (and then clears) any UserGestureUtilizedCallback.
83 static bool utilizeUserGesture();
84
85 // Mark the current user gesture (if any) as having been used, such that
86 // it cannot be used again. This is done only for very security-sensitive
87 // operations like creating a new process.
88 // Like utilizeUserGesture, may invoke/clear any UserGestureUtilizedCallback .
59 static bool consumeUserGesture(); 89 static bool consumeUserGesture();
90
60 static UserGestureToken* currentToken(); 91 static UserGestureToken* currentToken();
92
93 // Reset the notion of "since load".
61 static void clearProcessedUserGestureSinceLoad(); 94 static void clearProcessedUserGestureSinceLoad();
95
96 // Returns whether a user gesture has occurred since page load.
62 static bool processedUserGestureSinceLoad(); 97 static bool processedUserGestureSinceLoad();
63 98
64 explicit UserGestureIndicator(ProcessingUserGestureState); 99 explicit UserGestureIndicator(ProcessingUserGestureState, UserGestureUtilize dCallback* = 0);
65 explicit UserGestureIndicator(PassRefPtr<UserGestureToken>); 100 explicit UserGestureIndicator(PassRefPtr<UserGestureToken>, UserGestureUtili zedCallback* = 0);
66 ~UserGestureIndicator(); 101 ~UserGestureIndicator();
67 102
68 private: 103 private:
69 static ProcessingUserGestureState s_state; 104 static ProcessingUserGestureState s_state;
70 static UserGestureIndicator* s_topmostIndicator; 105 static UserGestureIndicator* s_topmostIndicator;
71 static bool s_processedUserGestureSinceLoad; 106 static bool s_processedUserGestureSinceLoad;
72 ProcessingUserGestureState m_previousState; 107 ProcessingUserGestureState m_previousState;
73 RefPtr<UserGestureToken> m_token; 108 RefPtr<UserGestureToken> m_token;
109 UserGestureUtilizedCallback* m_usageCallback;
74 }; 110 };
75 111
76 } // namespace blink 112 } // namespace blink
77 113
78 #endif 114 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698