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

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

Issue 1871713002: Convert //chrome/browser/extensions from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and fix header 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 // 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 #include "chrome/browser/extensions/api/tabs/tabs_event_router.h" 5 #include "chrome/browser/extensions/api/tabs/tabs_event_router.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8
8 #include <utility> 9 #include <utility>
9 10
11 #include "base/memory/ptr_util.h"
10 #include "base/values.h" 12 #include "base/values.h"
11 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" 13 #include "chrome/browser/extensions/api/tabs/tabs_constants.h"
12 #include "chrome/browser/extensions/api/tabs/tabs_windows_api.h" 14 #include "chrome/browser/extensions/api/tabs/tabs_windows_api.h"
13 #include "chrome/browser/extensions/api/tabs/windows_event_router.h" 15 #include "chrome/browser/extensions/api/tabs/windows_event_router.h"
14 #include "chrome/browser/extensions/extension_tab_util.h" 16 #include "chrome/browser/extensions/extension_tab_util.h"
15 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/ui/browser.h" 18 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_list.h" 19 #include "chrome/browser/ui/browser_list.h"
18 #include "chrome/browser/ui/tabs/tab_strip_model.h" 20 #include "chrome/browser/ui/tabs/tab_strip_model.h"
19 #include "chrome/common/extensions/extension_constants.h" 21 #include "chrome/common/extensions/extension_constants.h"
(...skipping 14 matching lines...) Expand all
34 36
35 namespace tabs = api::tabs; 37 namespace tabs = api::tabs;
36 38
37 bool WillDispatchTabUpdatedEvent( 39 bool WillDispatchTabUpdatedEvent(
38 WebContents* contents, 40 WebContents* contents,
39 const std::set<std::string> changed_property_names, 41 const std::set<std::string> changed_property_names,
40 content::BrowserContext* context, 42 content::BrowserContext* context,
41 const Extension* extension, 43 const Extension* extension,
42 Event* event, 44 Event* event,
43 const base::DictionaryValue* listener_filter) { 45 const base::DictionaryValue* listener_filter) {
44 scoped_ptr<api::tabs::Tab> tab_object = 46 std::unique_ptr<api::tabs::Tab> tab_object =
45 ExtensionTabUtil::CreateTabObject(contents, extension); 47 ExtensionTabUtil::CreateTabObject(contents, extension);
46 48
47 base::DictionaryValue* tab_value = tab_object->ToValue().release(); 49 base::DictionaryValue* tab_value = tab_object->ToValue().release();
48 50
49 scoped_ptr<base::DictionaryValue> changed_properties( 51 std::unique_ptr<base::DictionaryValue> changed_properties(
50 new base::DictionaryValue); 52 new base::DictionaryValue);
51 const base::Value* value = nullptr; 53 const base::Value* value = nullptr;
52 for (const auto& property : changed_property_names) { 54 for (const auto& property : changed_property_names) {
53 if (tab_value->Get(property, &value)) 55 if (tab_value->Get(property, &value))
54 changed_properties->Set(property, make_scoped_ptr(value->DeepCopy())); 56 changed_properties->Set(property, base::WrapUnique(value->DeepCopy()));
55 } 57 }
56 58
57 event->event_args->Set(1, changed_properties.release()); 59 event->event_args->Set(1, changed_properties.release());
58 event->event_args->Set(2, tab_value); 60 event->event_args->Set(2, tab_value);
59 return true; 61 return true;
60 } 62 }
61 63
62 } // namespace 64 } // namespace
63 65
64 TabsEventRouter::TabEntry::TabEntry(TabsEventRouter* router, 66 TabsEventRouter::TabEntry::TabEntry(TabsEventRouter* router,
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 } 150 }
149 151
150 void TabsEventRouter::RegisterForTabNotifications(WebContents* contents) { 152 void TabsEventRouter::RegisterForTabNotifications(WebContents* contents) {
151 favicon_scoped_observer_.Add( 153 favicon_scoped_observer_.Add(
152 favicon::ContentFaviconDriver::FromWebContents(contents)); 154 favicon::ContentFaviconDriver::FromWebContents(contents));
153 155
154 ZoomController::FromWebContents(contents)->AddObserver(this); 156 ZoomController::FromWebContents(contents)->AddObserver(this);
155 157
156 int tab_id = ExtensionTabUtil::GetTabId(contents); 158 int tab_id = ExtensionTabUtil::GetTabId(contents);
157 DCHECK(tab_entries_.find(tab_id) == tab_entries_.end()); 159 DCHECK(tab_entries_.find(tab_id) == tab_entries_.end());
158 tab_entries_[tab_id] = make_scoped_ptr(new TabEntry(this, contents)); 160 tab_entries_[tab_id] = base::WrapUnique(new TabEntry(this, contents));
159 } 161 }
160 162
161 void TabsEventRouter::UnregisterForTabNotifications(WebContents* contents) { 163 void TabsEventRouter::UnregisterForTabNotifications(WebContents* contents) {
162 favicon_scoped_observer_.Remove( 164 favicon_scoped_observer_.Remove(
163 favicon::ContentFaviconDriver::FromWebContents(contents)); 165 favicon::ContentFaviconDriver::FromWebContents(contents));
164 166
165 ZoomController::FromWebContents(contents)->RemoveObserver(this); 167 ZoomController::FromWebContents(contents)->RemoveObserver(this);
166 168
167 int tab_id = ExtensionTabUtil::GetTabId(contents); 169 int tab_id = ExtensionTabUtil::GetTabId(contents);
168 int removed_count = tab_entries_.erase(tab_id); 170 int removed_count = tab_entries_.erase(tab_id);
(...skipping 23 matching lines...) Expand all
192 event->event_args->Append(tab_value); 194 event->event_args->Append(tab_value);
193 tab_value->SetBoolean(tabs_constants::kSelectedKey, active); 195 tab_value->SetBoolean(tabs_constants::kSelectedKey, active);
194 tab_value->SetBoolean(tabs_constants::kActiveKey, active); 196 tab_value->SetBoolean(tabs_constants::kActiveKey, active);
195 return true; 197 return true;
196 } 198 }
197 199
198 void TabsEventRouter::TabCreatedAt(WebContents* contents, 200 void TabsEventRouter::TabCreatedAt(WebContents* contents,
199 int index, 201 int index,
200 bool active) { 202 bool active) {
201 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); 203 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
202 scoped_ptr<base::ListValue> args(new base::ListValue); 204 std::unique_ptr<base::ListValue> args(new base::ListValue);
203 scoped_ptr<Event> event(new Event( 205 std::unique_ptr<Event> event(new Event(
204 events::TABS_ON_CREATED, tabs::OnCreated::kEventName, std::move(args))); 206 events::TABS_ON_CREATED, tabs::OnCreated::kEventName, std::move(args)));
205 event->restrict_to_browser_context = profile; 207 event->restrict_to_browser_context = profile;
206 event->user_gesture = EventRouter::USER_GESTURE_NOT_ENABLED; 208 event->user_gesture = EventRouter::USER_GESTURE_NOT_ENABLED;
207 event->will_dispatch_callback = 209 event->will_dispatch_callback =
208 base::Bind(&WillDispatchTabCreatedEvent, contents, active); 210 base::Bind(&WillDispatchTabCreatedEvent, contents, active);
209 EventRouter::Get(profile)->BroadcastEvent(std::move(event)); 211 EventRouter::Get(profile)->BroadcastEvent(std::move(event));
210 212
211 RegisterForTabNotifications(contents); 213 RegisterForTabNotifications(contents);
212 } 214 }
213 215
214 void TabsEventRouter::TabInsertedAt(WebContents* contents, 216 void TabsEventRouter::TabInsertedAt(WebContents* contents,
215 int index, 217 int index,
216 bool active) { 218 bool active) {
217 if (!GetTabEntry(contents)) { 219 if (!GetTabEntry(contents)) {
218 // We've never seen this tab, send create event as long as we're not in the 220 // We've never seen this tab, send create event as long as we're not in the
219 // constructor. 221 // constructor.
220 if (browser_tab_strip_tracker_.is_processing_initial_browsers()) 222 if (browser_tab_strip_tracker_.is_processing_initial_browsers())
221 RegisterForTabNotifications(contents); 223 RegisterForTabNotifications(contents);
222 else 224 else
223 TabCreatedAt(contents, index, active); 225 TabCreatedAt(contents, index, active);
224 return; 226 return;
225 } 227 }
226 228
227 int tab_id = ExtensionTabUtil::GetTabId(contents); 229 int tab_id = ExtensionTabUtil::GetTabId(contents);
228 scoped_ptr<base::ListValue> args(new base::ListValue); 230 std::unique_ptr<base::ListValue> args(new base::ListValue);
229 args->Append(new FundamentalValue(tab_id)); 231 args->Append(new FundamentalValue(tab_id));
230 232
231 base::DictionaryValue* object_args = new base::DictionaryValue(); 233 base::DictionaryValue* object_args = new base::DictionaryValue();
232 object_args->Set(tabs_constants::kNewWindowIdKey, 234 object_args->Set(tabs_constants::kNewWindowIdKey,
233 new FundamentalValue( 235 new FundamentalValue(
234 ExtensionTabUtil::GetWindowIdOfTab(contents))); 236 ExtensionTabUtil::GetWindowIdOfTab(contents)));
235 object_args->Set(tabs_constants::kNewPositionKey, 237 object_args->Set(tabs_constants::kNewPositionKey,
236 new FundamentalValue(index)); 238 new FundamentalValue(index));
237 args->Append(object_args); 239 args->Append(object_args);
238 240
239 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); 241 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
240 DispatchEvent(profile, events::TABS_ON_ATTACHED, tabs::OnAttached::kEventName, 242 DispatchEvent(profile, events::TABS_ON_ATTACHED, tabs::OnAttached::kEventName,
241 std::move(args), EventRouter::USER_GESTURE_UNKNOWN); 243 std::move(args), EventRouter::USER_GESTURE_UNKNOWN);
242 } 244 }
243 245
244 void TabsEventRouter::TabDetachedAt(WebContents* contents, int index) { 246 void TabsEventRouter::TabDetachedAt(WebContents* contents, int index) {
245 if (!GetTabEntry(contents)) { 247 if (!GetTabEntry(contents)) {
246 // The tab was removed. Don't send detach event. 248 // The tab was removed. Don't send detach event.
247 return; 249 return;
248 } 250 }
249 251
250 scoped_ptr<base::ListValue> args(new base::ListValue); 252 std::unique_ptr<base::ListValue> args(new base::ListValue);
251 args->Append( 253 args->Append(
252 new FundamentalValue(ExtensionTabUtil::GetTabId(contents))); 254 new FundamentalValue(ExtensionTabUtil::GetTabId(contents)));
253 255
254 base::DictionaryValue* object_args = new base::DictionaryValue(); 256 base::DictionaryValue* object_args = new base::DictionaryValue();
255 object_args->Set(tabs_constants::kOldWindowIdKey, 257 object_args->Set(tabs_constants::kOldWindowIdKey,
256 new FundamentalValue( 258 new FundamentalValue(
257 ExtensionTabUtil::GetWindowIdOfTab(contents))); 259 ExtensionTabUtil::GetWindowIdOfTab(contents)));
258 object_args->Set(tabs_constants::kOldPositionKey, 260 object_args->Set(tabs_constants::kOldPositionKey,
259 new FundamentalValue(index)); 261 new FundamentalValue(index));
260 args->Append(object_args); 262 args->Append(object_args);
261 263
262 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); 264 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
263 DispatchEvent(profile, events::TABS_ON_DETACHED, tabs::OnDetached::kEventName, 265 DispatchEvent(profile, events::TABS_ON_DETACHED, tabs::OnDetached::kEventName,
264 std::move(args), EventRouter::USER_GESTURE_UNKNOWN); 266 std::move(args), EventRouter::USER_GESTURE_UNKNOWN);
265 } 267 }
266 268
267 void TabsEventRouter::TabClosingAt(TabStripModel* tab_strip_model, 269 void TabsEventRouter::TabClosingAt(TabStripModel* tab_strip_model,
268 WebContents* contents, 270 WebContents* contents,
269 int index) { 271 int index) {
270 int tab_id = ExtensionTabUtil::GetTabId(contents); 272 int tab_id = ExtensionTabUtil::GetTabId(contents);
271 273
272 scoped_ptr<base::ListValue> args(new base::ListValue); 274 std::unique_ptr<base::ListValue> args(new base::ListValue);
273 args->Append(new FundamentalValue(tab_id)); 275 args->Append(new FundamentalValue(tab_id));
274 276
275 base::DictionaryValue* object_args = new base::DictionaryValue(); 277 base::DictionaryValue* object_args = new base::DictionaryValue();
276 object_args->SetInteger(tabs_constants::kWindowIdKey, 278 object_args->SetInteger(tabs_constants::kWindowIdKey,
277 ExtensionTabUtil::GetWindowIdOfTab(contents)); 279 ExtensionTabUtil::GetWindowIdOfTab(contents));
278 object_args->SetBoolean(tabs_constants::kWindowClosing, 280 object_args->SetBoolean(tabs_constants::kWindowClosing,
279 tab_strip_model->closing_all()); 281 tab_strip_model->closing_all());
280 args->Append(object_args); 282 args->Append(object_args);
281 283
282 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); 284 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
283 DispatchEvent(profile, events::TABS_ON_REMOVED, tabs::OnRemoved::kEventName, 285 DispatchEvent(profile, events::TABS_ON_REMOVED, tabs::OnRemoved::kEventName,
284 std::move(args), EventRouter::USER_GESTURE_UNKNOWN); 286 std::move(args), EventRouter::USER_GESTURE_UNKNOWN);
285 287
286 UnregisterForTabNotifications(contents); 288 UnregisterForTabNotifications(contents);
287 } 289 }
288 290
289 void TabsEventRouter::ActiveTabChanged(WebContents* old_contents, 291 void TabsEventRouter::ActiveTabChanged(WebContents* old_contents,
290 WebContents* new_contents, 292 WebContents* new_contents,
291 int index, 293 int index,
292 int reason) { 294 int reason) {
293 scoped_ptr<base::ListValue> args(new base::ListValue); 295 std::unique_ptr<base::ListValue> args(new base::ListValue);
294 int tab_id = ExtensionTabUtil::GetTabId(new_contents); 296 int tab_id = ExtensionTabUtil::GetTabId(new_contents);
295 args->Append(new FundamentalValue(tab_id)); 297 args->Append(new FundamentalValue(tab_id));
296 298
297 base::DictionaryValue* object_args = new base::DictionaryValue(); 299 base::DictionaryValue* object_args = new base::DictionaryValue();
298 object_args->Set(tabs_constants::kWindowIdKey, 300 object_args->Set(tabs_constants::kWindowIdKey,
299 new FundamentalValue( 301 new FundamentalValue(
300 ExtensionTabUtil::GetWindowIdOfTab(new_contents))); 302 ExtensionTabUtil::GetWindowIdOfTab(new_contents)));
301 args->Append(object_args); 303 args->Append(object_args);
302 304
303 // The onActivated event replaced onActiveChanged and onSelectionChanged. The 305 // The onActivated event replaced onActiveChanged and onSelectionChanged. The
304 // deprecated events take two arguments: tabId, {windowId}. 306 // deprecated events take two arguments: tabId, {windowId}.
305 Profile* profile = 307 Profile* profile =
306 Profile::FromBrowserContext(new_contents->GetBrowserContext()); 308 Profile::FromBrowserContext(new_contents->GetBrowserContext());
307 EventRouter::UserGestureState gesture = 309 EventRouter::UserGestureState gesture =
308 reason & CHANGE_REASON_USER_GESTURE 310 reason & CHANGE_REASON_USER_GESTURE
309 ? EventRouter::USER_GESTURE_ENABLED 311 ? EventRouter::USER_GESTURE_ENABLED
310 : EventRouter::USER_GESTURE_NOT_ENABLED; 312 : EventRouter::USER_GESTURE_NOT_ENABLED;
311 DispatchEvent(profile, events::TABS_ON_SELECTION_CHANGED, 313 DispatchEvent(profile, events::TABS_ON_SELECTION_CHANGED,
312 tabs::OnSelectionChanged::kEventName, 314 tabs::OnSelectionChanged::kEventName,
313 scoped_ptr<base::ListValue>(args->DeepCopy()), gesture); 315 std::unique_ptr<base::ListValue>(args->DeepCopy()), gesture);
314 DispatchEvent(profile, events::TABS_ON_ACTIVE_CHANGED, 316 DispatchEvent(profile, events::TABS_ON_ACTIVE_CHANGED,
315 tabs::OnActiveChanged::kEventName, 317 tabs::OnActiveChanged::kEventName,
316 scoped_ptr<base::ListValue>(args->DeepCopy()), gesture); 318 std::unique_ptr<base::ListValue>(args->DeepCopy()), gesture);
317 319
318 // The onActivated event takes one argument: {windowId, tabId}. 320 // The onActivated event takes one argument: {windowId, tabId}.
319 args->Remove(0, NULL); 321 args->Remove(0, NULL);
320 object_args->Set(tabs_constants::kTabIdKey, 322 object_args->Set(tabs_constants::kTabIdKey,
321 new FundamentalValue(tab_id)); 323 new FundamentalValue(tab_id));
322 DispatchEvent(profile, events::TABS_ON_ACTIVATED, 324 DispatchEvent(profile, events::TABS_ON_ACTIVATED,
323 tabs::OnActivated::kEventName, std::move(args), gesture); 325 tabs::OnActivated::kEventName, std::move(args), gesture);
324 } 326 }
325 327
326 void TabsEventRouter::TabSelectionChanged( 328 void TabsEventRouter::TabSelectionChanged(
327 TabStripModel* tab_strip_model, 329 TabStripModel* tab_strip_model,
328 const ui::ListSelectionModel& old_model) { 330 const ui::ListSelectionModel& old_model) {
329 ui::ListSelectionModel::SelectedIndices new_selection = 331 ui::ListSelectionModel::SelectedIndices new_selection =
330 tab_strip_model->selection_model().selected_indices(); 332 tab_strip_model->selection_model().selected_indices();
331 scoped_ptr<base::ListValue> all_tabs(new base::ListValue); 333 std::unique_ptr<base::ListValue> all_tabs(new base::ListValue);
332 334
333 for (size_t i = 0; i < new_selection.size(); ++i) { 335 for (size_t i = 0; i < new_selection.size(); ++i) {
334 int index = new_selection[i]; 336 int index = new_selection[i];
335 WebContents* contents = tab_strip_model->GetWebContentsAt(index); 337 WebContents* contents = tab_strip_model->GetWebContentsAt(index);
336 if (!contents) 338 if (!contents)
337 break; 339 break;
338 int tab_id = ExtensionTabUtil::GetTabId(contents); 340 int tab_id = ExtensionTabUtil::GetTabId(contents);
339 all_tabs->Append(new FundamentalValue(tab_id)); 341 all_tabs->Append(new FundamentalValue(tab_id));
340 } 342 }
341 343
342 scoped_ptr<base::ListValue> args(new base::ListValue); 344 std::unique_ptr<base::ListValue> args(new base::ListValue);
343 scoped_ptr<base::DictionaryValue> select_info(new base::DictionaryValue); 345 std::unique_ptr<base::DictionaryValue> select_info(new base::DictionaryValue);
344 346
345 select_info->Set( 347 select_info->Set(
346 tabs_constants::kWindowIdKey, 348 tabs_constants::kWindowIdKey,
347 new FundamentalValue( 349 new FundamentalValue(
348 ExtensionTabUtil::GetWindowIdOfTabStripModel(tab_strip_model))); 350 ExtensionTabUtil::GetWindowIdOfTabStripModel(tab_strip_model)));
349 351
350 select_info->Set(tabs_constants::kTabIdsKey, all_tabs.release()); 352 select_info->Set(tabs_constants::kTabIdsKey, all_tabs.release());
351 args->Append(select_info.release()); 353 args->Append(select_info.release());
352 354
353 // The onHighlighted event replaced onHighlightChanged. 355 // The onHighlighted event replaced onHighlightChanged.
354 Profile* profile = tab_strip_model->profile(); 356 Profile* profile = tab_strip_model->profile();
355 DispatchEvent(profile, events::TABS_ON_HIGHLIGHT_CHANGED, 357 DispatchEvent(profile, events::TABS_ON_HIGHLIGHT_CHANGED,
356 tabs::OnHighlightChanged::kEventName, 358 tabs::OnHighlightChanged::kEventName,
357 scoped_ptr<base::ListValue>(args->DeepCopy()), 359 std::unique_ptr<base::ListValue>(args->DeepCopy()),
358 EventRouter::USER_GESTURE_UNKNOWN); 360 EventRouter::USER_GESTURE_UNKNOWN);
359 DispatchEvent(profile, events::TABS_ON_HIGHLIGHTED, 361 DispatchEvent(profile, events::TABS_ON_HIGHLIGHTED,
360 tabs::OnHighlighted::kEventName, std::move(args), 362 tabs::OnHighlighted::kEventName, std::move(args),
361 EventRouter::USER_GESTURE_UNKNOWN); 363 EventRouter::USER_GESTURE_UNKNOWN);
362 } 364 }
363 365
364 void TabsEventRouter::TabMoved(WebContents* contents, 366 void TabsEventRouter::TabMoved(WebContents* contents,
365 int from_index, 367 int from_index,
366 int to_index) { 368 int to_index) {
367 scoped_ptr<base::ListValue> args(new base::ListValue); 369 std::unique_ptr<base::ListValue> args(new base::ListValue);
368 args->Append( 370 args->Append(
369 new FundamentalValue(ExtensionTabUtil::GetTabId(contents))); 371 new FundamentalValue(ExtensionTabUtil::GetTabId(contents)));
370 372
371 base::DictionaryValue* object_args = new base::DictionaryValue(); 373 base::DictionaryValue* object_args = new base::DictionaryValue();
372 object_args->Set(tabs_constants::kWindowIdKey, 374 object_args->Set(tabs_constants::kWindowIdKey,
373 new FundamentalValue( 375 new FundamentalValue(
374 ExtensionTabUtil::GetWindowIdOfTab(contents))); 376 ExtensionTabUtil::GetWindowIdOfTab(contents)));
375 object_args->Set(tabs_constants::kFromIndexKey, 377 object_args->Set(tabs_constants::kFromIndexKey,
376 new FundamentalValue(from_index)); 378 new FundamentalValue(from_index));
377 object_args->Set(tabs_constants::kToIndexKey, 379 object_args->Set(tabs_constants::kToIndexKey,
(...skipping 29 matching lines...) Expand all
407 return; 409 return;
408 std::set<std::string> changed_property_names; 410 std::set<std::string> changed_property_names;
409 changed_property_names.insert(tabs_constants::kFaviconUrlKey); 411 changed_property_names.insert(tabs_constants::kFaviconUrlKey);
410 DispatchTabUpdatedEvent(contents, std::move(changed_property_names)); 412 DispatchTabUpdatedEvent(contents, std::move(changed_property_names));
411 } 413 }
412 414
413 void TabsEventRouter::DispatchEvent( 415 void TabsEventRouter::DispatchEvent(
414 Profile* profile, 416 Profile* profile,
415 events::HistogramValue histogram_value, 417 events::HistogramValue histogram_value,
416 const std::string& event_name, 418 const std::string& event_name,
417 scoped_ptr<base::ListValue> args, 419 std::unique_ptr<base::ListValue> args,
418 EventRouter::UserGestureState user_gesture) { 420 EventRouter::UserGestureState user_gesture) {
419 EventRouter* event_router = EventRouter::Get(profile); 421 EventRouter* event_router = EventRouter::Get(profile);
420 if (!profile_->IsSameProfile(profile) || !event_router) 422 if (!profile_->IsSameProfile(profile) || !event_router)
421 return; 423 return;
422 424
423 scoped_ptr<Event> event( 425 std::unique_ptr<Event> event(
424 new Event(histogram_value, event_name, std::move(args))); 426 new Event(histogram_value, event_name, std::move(args)));
425 event->restrict_to_browser_context = profile; 427 event->restrict_to_browser_context = profile;
426 event->user_gesture = user_gesture; 428 event->user_gesture = user_gesture;
427 event_router->BroadcastEvent(std::move(event)); 429 event_router->BroadcastEvent(std::move(event));
428 } 430 }
429 431
430 void TabsEventRouter::DispatchTabUpdatedEvent( 432 void TabsEventRouter::DispatchTabUpdatedEvent(
431 WebContents* contents, 433 WebContents* contents,
432 const std::set<std::string> changed_property_names) { 434 const std::set<std::string> changed_property_names) {
433 DCHECK(!changed_property_names.empty()); 435 DCHECK(!changed_property_names.empty());
434 DCHECK(contents); 436 DCHECK(contents);
435 437
436 // The state of the tab (as seen from the extension point of view) has 438 // The state of the tab (as seen from the extension point of view) has
437 // changed. Send a notification to the extension. 439 // changed. Send a notification to the extension.
438 scoped_ptr<base::ListValue> args_base(new base::ListValue); 440 std::unique_ptr<base::ListValue> args_base(new base::ListValue);
439 441
440 // First arg: The id of the tab that changed. 442 // First arg: The id of the tab that changed.
441 args_base->AppendInteger(ExtensionTabUtil::GetTabId(contents)); 443 args_base->AppendInteger(ExtensionTabUtil::GetTabId(contents));
442 444
443 // Second arg: An object containing the changes to the tab state. Filled in 445 // Second arg: An object containing the changes to the tab state. Filled in
444 // by WillDispatchTabUpdatedEvent as a copy of changed_properties, if the 446 // by WillDispatchTabUpdatedEvent as a copy of changed_properties, if the
445 // extension has the tabs permission. 447 // extension has the tabs permission.
446 448
447 // Third arg: An object containing the state of the tab. Filled in by 449 // Third arg: An object containing the state of the tab. Filled in by
448 // WillDispatchTabUpdatedEvent. 450 // WillDispatchTabUpdatedEvent.
449 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); 451 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
450 452
451 scoped_ptr<Event> event(new Event(events::TABS_ON_UPDATED, 453 std::unique_ptr<Event> event(new Event(events::TABS_ON_UPDATED,
452 tabs::OnUpdated::kEventName, 454 tabs::OnUpdated::kEventName,
453 std::move(args_base))); 455 std::move(args_base)));
454 event->restrict_to_browser_context = profile; 456 event->restrict_to_browser_context = profile;
455 event->user_gesture = EventRouter::USER_GESTURE_NOT_ENABLED; 457 event->user_gesture = EventRouter::USER_GESTURE_NOT_ENABLED;
456 event->will_dispatch_callback = 458 event->will_dispatch_callback =
457 base::Bind(&WillDispatchTabUpdatedEvent, contents, 459 base::Bind(&WillDispatchTabUpdatedEvent, contents,
458 std::move(changed_property_names)); 460 std::move(changed_property_names));
459 EventRouter::Get(profile)->BroadcastEvent(std::move(event)); 461 EventRouter::Get(profile)->BroadcastEvent(std::move(event));
460 } 462 }
461 463
462 TabsEventRouter::TabEntry* TabsEventRouter::GetTabEntry(WebContents* contents) { 464 TabsEventRouter::TabEntry* TabsEventRouter::GetTabEntry(WebContents* contents) {
463 const auto it = tab_entries_.find(ExtensionTabUtil::GetTabId(contents)); 465 const auto it = tab_entries_.find(ExtensionTabUtil::GetTabId(contents));
(...skipping 10 matching lines...) Expand all
474 } 476 }
475 477
476 void TabsEventRouter::TabReplacedAt(TabStripModel* tab_strip_model, 478 void TabsEventRouter::TabReplacedAt(TabStripModel* tab_strip_model,
477 WebContents* old_contents, 479 WebContents* old_contents,
478 WebContents* new_contents, 480 WebContents* new_contents,
479 int index) { 481 int index) {
480 // Notify listeners that the next tabs closing or being added are due to 482 // Notify listeners that the next tabs closing or being added are due to
481 // WebContents being swapped. 483 // WebContents being swapped.
482 const int new_tab_id = ExtensionTabUtil::GetTabId(new_contents); 484 const int new_tab_id = ExtensionTabUtil::GetTabId(new_contents);
483 const int old_tab_id = ExtensionTabUtil::GetTabId(old_contents); 485 const int old_tab_id = ExtensionTabUtil::GetTabId(old_contents);
484 scoped_ptr<base::ListValue> args(new base::ListValue); 486 std::unique_ptr<base::ListValue> args(new base::ListValue);
485 args->Append(new FundamentalValue(new_tab_id)); 487 args->Append(new FundamentalValue(new_tab_id));
486 args->Append(new FundamentalValue(old_tab_id)); 488 args->Append(new FundamentalValue(old_tab_id));
487 489
488 DispatchEvent(Profile::FromBrowserContext(new_contents->GetBrowserContext()), 490 DispatchEvent(Profile::FromBrowserContext(new_contents->GetBrowserContext()),
489 events::TABS_ON_REPLACED, tabs::OnReplaced::kEventName, 491 events::TABS_ON_REPLACED, tabs::OnReplaced::kEventName,
490 std::move(args), EventRouter::USER_GESTURE_UNKNOWN); 492 std::move(args), EventRouter::USER_GESTURE_UNKNOWN);
491 493
492 UnregisterForTabNotifications(old_contents); 494 UnregisterForTabNotifications(old_contents);
493 495
494 if (!GetTabEntry(new_contents)) 496 if (!GetTabEntry(new_contents))
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 bool icon_url_changed, 541 bool icon_url_changed,
540 const gfx::Image& image) { 542 const gfx::Image& image) {
541 if (notification_icon_type == NON_TOUCH_16_DIP && icon_url_changed) { 543 if (notification_icon_type == NON_TOUCH_16_DIP && icon_url_changed) {
542 favicon::ContentFaviconDriver* content_favicon_driver = 544 favicon::ContentFaviconDriver* content_favicon_driver =
543 static_cast<favicon::ContentFaviconDriver*>(favicon_driver); 545 static_cast<favicon::ContentFaviconDriver*>(favicon_driver);
544 FaviconUrlUpdated(content_favicon_driver->web_contents()); 546 FaviconUrlUpdated(content_favicon_driver->web_contents());
545 } 547 }
546 } 548 }
547 549
548 } // namespace extensions 550 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/tabs/tabs_event_router.h ('k') | chrome/browser/extensions/api/tabs/tabs_interactive_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698