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

Side by Side Diff: chrome/browser/ui/views/accessibility/accessibility_event_router_views.h

Issue 13584005: Fix use-after-free of Profile after it's been destroyed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_UI_VIEWS_ACCESSIBILITY_ACCESSIBILITY_EVENT_ROUTER_VIEWS_H _ 5 #ifndef CHROME_BROWSER_UI_VIEWS_ACCESSIBILITY_ACCESSIBILITY_EVENT_ROUTER_VIEWS_H _
6 #define CHROME_BROWSER_UI_VIEWS_ACCESSIBILITY_ACCESSIBILITY_EVENT_ROUTER_VIEWS_H _ 6 #define CHROME_BROWSER_UI_VIEWS_ACCESSIBILITY_ACCESSIBILITY_EVENT_ROUTER_VIEWS_H _
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/gtest_prod_util.h" 11 #include "base/gtest_prod_util.h"
12 #include "base/memory/scoped_ptr.h"
12 #include "base/string16.h" 13 #include "base/string16.h"
13 #include "chrome/browser/accessibility/accessibility_events.h" 14 #include "chrome/browser/accessibility/accessibility_events.h"
15 #include "content/public/browser/notification_observer.h"
14 #include "ui/base/accessibility/accessibility_types.h" 16 #include "ui/base/accessibility/accessibility_types.h"
15 17
16 class Profile; 18 class Profile;
17 19
18 template <typename T> struct DefaultSingletonTraits; 20 template <typename T> struct DefaultSingletonTraits;
19 21
22 namespace content {
23 class NotificationRegistrar;
24 }
25
20 namespace views { 26 namespace views {
21 class View; 27 class View;
22 } 28 }
23 29
24 // NOTE: This class is part of the Accessibility Extension API, which lets 30 // NOTE: This class is part of the Accessibility Extension API, which lets
25 // extensions receive accessibility events. It's distinct from code that 31 // extensions receive accessibility events. It's distinct from code that
26 // implements platform accessibility APIs like MSAA or ATK. 32 // implements platform accessibility APIs like MSAA or ATK.
27 // 33 //
28 // Singleton class that adds listeners to many views, then sends an 34 // Singleton class that adds listeners to many views, then sends an
29 // accessibility notification whenever a relevant event occurs in an 35 // accessibility notification whenever a relevant event occurs in an
30 // accessible view. 36 // accessible view.
31 // 37 //
32 // Views are not accessible by default. When you register a root widget, 38 // Views are not accessible by default. When you register a root widget,
33 // that widget and all of its descendants will start sending accessibility 39 // that widget and all of its descendants will start sending accessibility
34 // event notifications. You can then override the default behavior for 40 // event notifications. You can then override the default behavior for
35 // specific descendants using other methods. 41 // specific descendants using other methods.
36 // 42 //
37 // You can use Profile::PauseAccessibilityEvents to prevent a flurry 43 // You can use Profile::PauseAccessibilityEvents to prevent a flurry
38 // of accessibility events when a window is being created or initialized. 44 // of accessibility events when a window is being created or initialized.
39 class AccessibilityEventRouterViews { 45 class AccessibilityEventRouterViews : public content::NotificationObserver {
40 public: 46 public:
41 // Internal information about a particular view to override the 47 // Internal information about a particular view to override the
42 // information we get directly from the view. 48 // information we get directly from the view.
43 struct ViewInfo { 49 struct ViewInfo {
44 ViewInfo() : ignore(false) {} 50 ViewInfo() : ignore(false) {}
45 51
46 // If nonempty, will use this name instead of the view's label. 52 // If nonempty, will use this name instead of the view's label.
47 std::string name; 53 std::string name;
48 54
49 // If true, will ignore this widget and not send accessibility events. 55 // If true, will ignore this widget and not send accessibility events.
50 bool ignore; 56 bool ignore;
51 }; 57 };
52 58
53 // Get the single instance of this class. 59 // Get the single instance of this class.
54 static AccessibilityEventRouterViews* GetInstance(); 60 static AccessibilityEventRouterViews* GetInstance();
55 61
56 // Handle an accessibility event generated by a view. 62 // Handle an accessibility event generated by a view.
57 void HandleAccessibilityEvent( 63 void HandleAccessibilityEvent(
58 views::View* view, ui::AccessibilityTypes::Event event_type); 64 views::View* view, ui::AccessibilityTypes::Event event_type);
59 65
60 // Handle a menu item being focused (separate because a menu item is 66 // Handle a menu item being focused (separate because a menu item is
61 // not necessarily its own view). 67 // not necessarily its own view).
62 void HandleMenuItemFocused(const string16& menu_name, 68 void HandleMenuItemFocused(const string16& menu_name,
63 const string16& menu_item_name, 69 const string16& menu_item_name,
64 int item_index, 70 int item_index,
65 int item_count, 71 int item_count,
66 bool has_submenu); 72 bool has_submenu);
67 73
74 // NotificationObserver implementation.
75 virtual void Observe(int type,
76 const content::NotificationSource& source,
77 const content::NotificationDetails& details) OVERRIDE;
78
68 private: 79 private:
69 friend struct DefaultSingletonTraits<AccessibilityEventRouterViews>; 80 friend struct DefaultSingletonTraits<AccessibilityEventRouterViews>;
70 81
71 FRIEND_TEST_ALL_PREFIXES(AccessibilityEventRouterViewsTest, 82 FRIEND_TEST_ALL_PREFIXES(AccessibilityEventRouterViewsTest,
72 TestFocusNotification); 83 TestFocusNotification);
73 84
74 AccessibilityEventRouterViews(); 85 AccessibilityEventRouterViews();
75 virtual ~AccessibilityEventRouterViews(); 86 virtual ~AccessibilityEventRouterViews();
76 87
77 // Checks the type of the view and calls one of the more specific 88 // Checks the type of the view and calls one of the more specific
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 int* count); 156 int* count);
146 157
147 // Recursively explore the subviews and return the text from the first 158 // Recursively explore the subviews and return the text from the first
148 // subview with a role of STATIC_TEXT. 159 // subview with a role of STATIC_TEXT.
149 static std::string RecursiveGetStaticText(views::View* view); 160 static std::string RecursiveGetStaticText(views::View* view);
150 161
151 // The profile associated with the most recent window event - used to 162 // The profile associated with the most recent window event - used to
152 // figure out where to route a few events that can't be directly traced 163 // figure out where to route a few events that can't be directly traced
153 // to a window with a profile (like menu events). 164 // to a window with a profile (like menu events).
154 Profile* most_recent_profile_; 165 Profile* most_recent_profile_;
166
167 // Notification registrar so we can clear most_recent_profile_ when a
168 // profile is destroyed.
169 scoped_ptr<content::NotificationRegistrar> registrar_;
Lei Zhang 2013/04/03 21:56:49 Any particular reason for making it a scoper? Most
dmazzoni 2013/04/03 22:02:29 One less include in a header file? I have no stro
155 }; 170 };
156 171
157 #endif // CHROME_BROWSER_UI_VIEWS_ACCESSIBILITY_ACCESSIBILITY_EVENT_ROUTER_VIEW S_H_ 172 #endif // CHROME_BROWSER_UI_VIEWS_ACCESSIBILITY_ACCESSIBILITY_EVENT_ROUTER_VIEW S_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698