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

Side by Side Diff: chrome/browser/extensions/api/tabs/tabs_event_router.h

Issue 987583004: Add audible, muted to Tab, c.t.query, c.t.update, and c.t.onUpdated where relevant (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@patch1
Patch Set: Followup for review of patch #7 Created 5 years, 6 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 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_EXTENSIONS_API_TABS_TABS_EVENT_ROUTER_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_TABS_TABS_EVENT_ROUTER_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_TABS_TABS_EVENT_ROUTER_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_TABS_TABS_EVENT_ROUTER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 // ZoomObserver. 75 // ZoomObserver.
76 void OnZoomChanged( 76 void OnZoomChanged(
77 const ui_zoom::ZoomController::ZoomChangedEventData& data) override; 77 const ui_zoom::ZoomController::ZoomChangedEventData& data) override;
78 78
79 private: 79 private:
80 // "Synthetic" event. Called from TabInsertedAt if new tab is detected. 80 // "Synthetic" event. Called from TabInsertedAt if new tab is detected.
81 void TabCreatedAt(content::WebContents* contents, int index, bool active); 81 void TabCreatedAt(content::WebContents* contents, int index, bool active);
82 82
83 // Internal processing of tab updated events. Is called by both TabChangedAt 83 // Internal processing of tab updated events. Is called by both TabChangedAt
84 // and Observe/NAV_ENTRY_COMMITTED. 84 // and Observe/NAV_ENTRY_COMMITTED.
85 void TabUpdated(content::WebContents* contents, bool did_navigate); 85 class TabEntry;
86 void TabUpdated(TabEntry* entry,
87 scoped_ptr<base::DictionaryValue> changed_properties);
86 88
87 // Triggers a tab updated event if the favicon URL changes. 89 // Triggers a tab updated event if the favicon URL changes.
88 void FaviconUrlUpdated(content::WebContents* contents); 90 void FaviconUrlUpdated(content::WebContents* contents);
89 91
90 // The DispatchEvent methods forward events to the |profile|'s event router. 92 // The DispatchEvent methods forward events to the |profile|'s event router.
91 // The TabsEventRouter listens to events for all profiles, 93 // The TabsEventRouter listens to events for all profiles,
92 // so we avoid duplication by dropping events destined for other profiles. 94 // so we avoid duplication by dropping events destined for other profiles.
93 void DispatchEvent(Profile* profile, 95 void DispatchEvent(Profile* profile,
94 const std::string& event_name, 96 const std::string& event_name,
95 scoped_ptr<base::ListValue> args, 97 scoped_ptr<base::ListValue> args,
(...skipping 26 matching lines...) Expand all
122 // Removes notifications added in RegisterForTabNotifications. 124 // Removes notifications added in RegisterForTabNotifications.
123 void UnregisterForTabNotifications(content::WebContents* contents); 125 void UnregisterForTabNotifications(content::WebContents* contents);
124 126
125 content::NotificationRegistrar registrar_; 127 content::NotificationRegistrar registrar_;
126 128
127 // Maintain some information about known tabs, so we can: 129 // Maintain some information about known tabs, so we can:
128 // 130 //
129 // - distinguish between tab creation and tab insertion 131 // - distinguish between tab creation and tab insertion
130 // - not send tab-detached after tab-removed 132 // - not send tab-detached after tab-removed
131 // - reduce the "noise" of TabChangedAt() when sending events to extensions 133 // - reduce the "noise" of TabChangedAt() when sending events to extensions
134 // - remember last muted and audible states to know if there was a change
132 class TabEntry { 135 class TabEntry {
133 public: 136 public:
134 // Create a new tab entry whose initial state is TAB_COMPLETE. This 137 // Create a TabEntry associated with, and tracking state changes to,
135 // constructor is required because TabEntry objects placed inside an 138 // |contents|.
136 // std::map<> by value. 139 explicit TabEntry(content::WebContents* contents);
137 TabEntry();
138 140
139 // Update the load state of the tab based on its WebContents. Returns true 141 // Indicate via a list of key/value pairs if a tab is loading based on its
140 // if the state changed, false otherwise. Whether the state has changed or 142 // WebContents. Whether the state has changed or not is used to determine
141 // not is used to determine if events needs to be sent to extensions during 143 // if events needs to be sent to extensions during processing of
142 // processing of TabChangedAt(). This method will "hold" a state-change 144 // TabChangedAt(). If this method indicates that a tab should "hold" a
143 // to "loading", until the DidNavigate() method which should always follow 145 // state-change to "loading", the DidNavigate() method should eventually
144 // it. Returns NULL if no updates should be sent. 146 // send a similar message to undo it. If false, the returned key/value
145 base::DictionaryValue* UpdateLoadState( 147 // pairs list is empty.
146 const content::WebContents* contents); 148 scoped_ptr<base::DictionaryValue> UpdateLoadState();
147 149
148 // Indicates that a tab load has resulted in a navigation and the 150 // Indicate via a list of key/value pairs that a tab load has resulted in a
149 // destination url is available for inspection. Returns NULL if no updates 151 // navigation and the destination url is available for inspection. The list
150 // should be sent. 152 // is empty if no updates should be sent.
151 base::DictionaryValue* DidNavigate(const content::WebContents* contents); 153 scoped_ptr<base::DictionaryValue> DidNavigate();
154
155 // Update the audible and muted states and return whether they were changed
156 bool SetAudible(bool new_val);
157 bool SetMuted(bool new_val);
158
159 content::WebContents* web_contents() { return contents_; }
152 160
153 private: 161 private:
162 content::WebContents* contents_;
163
154 // Whether we are waiting to fire the 'complete' status change. This will 164 // Whether we are waiting to fire the 'complete' status change. This will
155 // occur the first time the WebContents stops loading after the 165 // occur the first time the WebContents stops loading after the
156 // NAV_ENTRY_COMMITTED was fired. The tab may go back into and out of the 166 // NAV_ENTRY_COMMITTED was fired. The tab may go back into and out of the
157 // loading state subsequently, but we will ignore those changes. 167 // loading state subsequently, but we will ignore those changes.
158 bool complete_waiting_on_load_; 168 bool complete_waiting_on_load_;
159 169
170 // Previous audible and muted states
171 bool was_audible_;
172 bool was_muted_;
173
160 GURL url_; 174 GURL url_;
175
176 // Create a new tab entry whose initial state is TAB_COMPLETE. This
177 // constructor is required because TabEntry objects placed inside an
178 // std::map<> by value.
179 TabEntry();
180
181 friend class std::map<int, TabEntry>;
miu 2015/05/27 20:10:14 Thanks for doing this. The style guide requires s
miu 2015/05/28 21:36:23 Done.
161 }; 182 };
162 183
163 // Gets the TabEntry for the given |contents|. Returns TabEntry* if 184 // Gets the TabEntry for the given |contents|. Returns TabEntry* if
164 // found, NULL if not. 185 // found, NULL if not.
165 TabEntry* GetTabEntry(content::WebContents* contents); 186 TabEntry* GetTabEntry(content::WebContents* contents);
166 187
167 std::map<int, TabEntry> tab_entries_; 188 std::map<int, TabEntry> tab_entries_;
168 189
169 // The main profile that owns this event router. 190 // The main profile that owns this event router.
170 Profile* profile_; 191 Profile* profile_;
171 192
172 DISALLOW_COPY_AND_ASSIGN(TabsEventRouter); 193 DISALLOW_COPY_AND_ASSIGN(TabsEventRouter);
173 }; 194 };
174 195
175 } // namespace extensions 196 } // namespace extensions
176 197
177 #endif // CHROME_BROWSER_EXTENSIONS_API_TABS_TABS_EVENT_ROUTER_H_ 198 #endif // CHROME_BROWSER_EXTENSIONS_API_TABS_TABS_EVENT_ROUTER_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/tabs/tabs_constants.cc ('k') | chrome/browser/extensions/api/tabs/tabs_event_router.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698