OLD | NEW |
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 #include "chrome/browser/extensions/browser_event_router.h" | 5 #include "chrome/browser/extensions/browser_event_router.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/extensions/api/extension_action/extension_page_actions_
api_constants.h" | 9 #include "chrome/browser/extensions/api/extension_action/extension_page_actions_
api_constants.h" |
10 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 10 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 if (tabs_window_api) { | 158 if (tabs_window_api) { |
159 tabs_window_api->windows_event_router()->OnActiveWindowChanged( | 159 tabs_window_api->windows_event_router()->OnActiveWindowChanged( |
160 browser ? browser->extension_window_controller() : NULL); | 160 browser ? browser->extension_window_controller() : NULL); |
161 } | 161 } |
162 } | 162 } |
163 | 163 |
164 static void WillDispatchTabCreatedEvent(WebContents* contents, | 164 static void WillDispatchTabCreatedEvent(WebContents* contents, |
165 bool active, | 165 bool active, |
166 Profile* profile, | 166 Profile* profile, |
167 const Extension* extension, | 167 const Extension* extension, |
168 ListValue* event_args) { | 168 base::ListValue* event_args) { |
169 DictionaryValue* tab_value = ExtensionTabUtil::CreateTabValue( | 169 DictionaryValue* tab_value = ExtensionTabUtil::CreateTabValue( |
170 contents, extension); | 170 contents, extension); |
171 event_args->Clear(); | 171 event_args->Clear(); |
172 event_args->Append(tab_value); | 172 event_args->Append(tab_value); |
173 tab_value->SetBoolean(tab_keys::kSelectedKey, active); | 173 tab_value->SetBoolean(tab_keys::kSelectedKey, active); |
174 } | 174 } |
175 | 175 |
176 void BrowserEventRouter::TabCreatedAt(WebContents* contents, | 176 void BrowserEventRouter::TabCreatedAt(WebContents* contents, |
177 int index, | 177 int index, |
178 bool active) { | 178 bool active) { |
179 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); | 179 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); |
180 scoped_ptr<ListValue> args(new ListValue()); | 180 scoped_ptr<base::ListValue> args(new base::ListValue()); |
181 scoped_ptr<Event> event(new Event(events::kOnTabCreated, args.Pass())); | 181 scoped_ptr<Event> event(new Event(events::kOnTabCreated, args.Pass())); |
182 event->restrict_to_profile = profile; | 182 event->restrict_to_profile = profile; |
183 event->user_gesture = EventRouter::USER_GESTURE_NOT_ENABLED; | 183 event->user_gesture = EventRouter::USER_GESTURE_NOT_ENABLED; |
184 event->will_dispatch_callback = | 184 event->will_dispatch_callback = |
185 base::Bind(&WillDispatchTabCreatedEvent, contents, active); | 185 base::Bind(&WillDispatchTabCreatedEvent, contents, active); |
186 ExtensionSystem::Get(profile)->event_router()->BroadcastEvent(event.Pass()); | 186 ExtensionSystem::Get(profile)->event_router()->BroadcastEvent(event.Pass()); |
187 | 187 |
188 RegisterForTabNotifications(contents); | 188 RegisterForTabNotifications(contents); |
189 } | 189 } |
190 | 190 |
191 void BrowserEventRouter::TabInsertedAt(WebContents* contents, | 191 void BrowserEventRouter::TabInsertedAt(WebContents* contents, |
192 int index, | 192 int index, |
193 bool active) { | 193 bool active) { |
194 // If tab is new, send created event. | 194 // If tab is new, send created event. |
195 int tab_id = ExtensionTabUtil::GetTabId(contents); | 195 int tab_id = ExtensionTabUtil::GetTabId(contents); |
196 if (!GetTabEntry(contents)) { | 196 if (!GetTabEntry(contents)) { |
197 tab_entries_[tab_id] = TabEntry(); | 197 tab_entries_[tab_id] = TabEntry(); |
198 | 198 |
199 TabCreatedAt(contents, index, active); | 199 TabCreatedAt(contents, index, active); |
200 return; | 200 return; |
201 } | 201 } |
202 | 202 |
203 scoped_ptr<ListValue> args(new ListValue()); | 203 scoped_ptr<base::ListValue> args(new base::ListValue()); |
204 args->Append(Value::CreateIntegerValue(tab_id)); | 204 args->Append(Value::CreateIntegerValue(tab_id)); |
205 | 205 |
206 DictionaryValue* object_args = new DictionaryValue(); | 206 DictionaryValue* object_args = new DictionaryValue(); |
207 object_args->Set(tab_keys::kNewWindowIdKey, Value::CreateIntegerValue( | 207 object_args->Set(tab_keys::kNewWindowIdKey, Value::CreateIntegerValue( |
208 ExtensionTabUtil::GetWindowIdOfTab(contents))); | 208 ExtensionTabUtil::GetWindowIdOfTab(contents))); |
209 object_args->Set(tab_keys::kNewPositionKey, Value::CreateIntegerValue( | 209 object_args->Set(tab_keys::kNewPositionKey, Value::CreateIntegerValue( |
210 index)); | 210 index)); |
211 args->Append(object_args); | 211 args->Append(object_args); |
212 | 212 |
213 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); | 213 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); |
214 DispatchEvent(profile, events::kOnTabAttached, args.Pass(), | 214 DispatchEvent(profile, events::kOnTabAttached, args.Pass(), |
215 EventRouter::USER_GESTURE_UNKNOWN); | 215 EventRouter::USER_GESTURE_UNKNOWN); |
216 } | 216 } |
217 | 217 |
218 void BrowserEventRouter::TabDetachedAt(WebContents* contents, int index) { | 218 void BrowserEventRouter::TabDetachedAt(WebContents* contents, int index) { |
219 if (!GetTabEntry(contents)) { | 219 if (!GetTabEntry(contents)) { |
220 // The tab was removed. Don't send detach event. | 220 // The tab was removed. Don't send detach event. |
221 return; | 221 return; |
222 } | 222 } |
223 | 223 |
224 scoped_ptr<ListValue> args(new ListValue()); | 224 scoped_ptr<base::ListValue> args(new base::ListValue()); |
225 args->Append(Value::CreateIntegerValue(ExtensionTabUtil::GetTabId(contents))); | 225 args->Append(Value::CreateIntegerValue(ExtensionTabUtil::GetTabId(contents))); |
226 | 226 |
227 DictionaryValue* object_args = new DictionaryValue(); | 227 DictionaryValue* object_args = new DictionaryValue(); |
228 object_args->Set(tab_keys::kOldWindowIdKey, Value::CreateIntegerValue( | 228 object_args->Set(tab_keys::kOldWindowIdKey, Value::CreateIntegerValue( |
229 ExtensionTabUtil::GetWindowIdOfTab(contents))); | 229 ExtensionTabUtil::GetWindowIdOfTab(contents))); |
230 object_args->Set(tab_keys::kOldPositionKey, Value::CreateIntegerValue( | 230 object_args->Set(tab_keys::kOldPositionKey, Value::CreateIntegerValue( |
231 index)); | 231 index)); |
232 args->Append(object_args); | 232 args->Append(object_args); |
233 | 233 |
234 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); | 234 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); |
235 DispatchEvent(profile, events::kOnTabDetached, args.Pass(), | 235 DispatchEvent(profile, events::kOnTabDetached, args.Pass(), |
236 EventRouter::USER_GESTURE_UNKNOWN); | 236 EventRouter::USER_GESTURE_UNKNOWN); |
237 } | 237 } |
238 | 238 |
239 void BrowserEventRouter::TabClosingAt(TabStripModel* tab_strip_model, | 239 void BrowserEventRouter::TabClosingAt(TabStripModel* tab_strip_model, |
240 WebContents* contents, | 240 WebContents* contents, |
241 int index) { | 241 int index) { |
242 int tab_id = ExtensionTabUtil::GetTabId(contents); | 242 int tab_id = ExtensionTabUtil::GetTabId(contents); |
243 | 243 |
244 scoped_ptr<ListValue> args(new ListValue()); | 244 scoped_ptr<base::ListValue> args(new base::ListValue()); |
245 args->Append(Value::CreateIntegerValue(tab_id)); | 245 args->Append(Value::CreateIntegerValue(tab_id)); |
246 | 246 |
247 DictionaryValue* object_args = new DictionaryValue(); | 247 DictionaryValue* object_args = new DictionaryValue(); |
248 object_args->SetInteger(tab_keys::kWindowIdKey, | 248 object_args->SetInteger(tab_keys::kWindowIdKey, |
249 ExtensionTabUtil::GetWindowIdOfTab(contents)); | 249 ExtensionTabUtil::GetWindowIdOfTab(contents)); |
250 object_args->SetBoolean(tab_keys::kWindowClosing, | 250 object_args->SetBoolean(tab_keys::kWindowClosing, |
251 tab_strip_model->closing_all()); | 251 tab_strip_model->closing_all()); |
252 args->Append(object_args); | 252 args->Append(object_args); |
253 | 253 |
254 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); | 254 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); |
255 DispatchEvent(profile, events::kOnTabRemoved, args.Pass(), | 255 DispatchEvent(profile, events::kOnTabRemoved, args.Pass(), |
256 EventRouter::USER_GESTURE_UNKNOWN); | 256 EventRouter::USER_GESTURE_UNKNOWN); |
257 | 257 |
258 int removed_count = tab_entries_.erase(tab_id); | 258 int removed_count = tab_entries_.erase(tab_id); |
259 DCHECK_GT(removed_count, 0); | 259 DCHECK_GT(removed_count, 0); |
260 | 260 |
261 UnregisterForTabNotifications(contents); | 261 UnregisterForTabNotifications(contents); |
262 } | 262 } |
263 | 263 |
264 void BrowserEventRouter::ActiveTabChanged(WebContents* old_contents, | 264 void BrowserEventRouter::ActiveTabChanged(WebContents* old_contents, |
265 WebContents* new_contents, | 265 WebContents* new_contents, |
266 int index, | 266 int index, |
267 int reason) { | 267 int reason) { |
268 scoped_ptr<ListValue> args(new ListValue()); | 268 scoped_ptr<base::ListValue> args(new base::ListValue()); |
269 int tab_id = ExtensionTabUtil::GetTabId(new_contents); | 269 int tab_id = ExtensionTabUtil::GetTabId(new_contents); |
270 args->Append(Value::CreateIntegerValue(tab_id)); | 270 args->Append(Value::CreateIntegerValue(tab_id)); |
271 | 271 |
272 DictionaryValue* object_args = new DictionaryValue(); | 272 DictionaryValue* object_args = new DictionaryValue(); |
273 object_args->Set(tab_keys::kWindowIdKey, Value::CreateIntegerValue( | 273 object_args->Set(tab_keys::kWindowIdKey, Value::CreateIntegerValue( |
274 ExtensionTabUtil::GetWindowIdOfTab(new_contents))); | 274 ExtensionTabUtil::GetWindowIdOfTab(new_contents))); |
275 args->Append(object_args); | 275 args->Append(object_args); |
276 | 276 |
277 // The onActivated event replaced onActiveChanged and onSelectionChanged. The | 277 // The onActivated event replaced onActiveChanged and onSelectionChanged. The |
278 // deprecated events take two arguments: tabId, {windowId}. | 278 // deprecated events take two arguments: tabId, {windowId}. |
279 Profile* profile = | 279 Profile* profile = |
280 Profile::FromBrowserContext(new_contents->GetBrowserContext()); | 280 Profile::FromBrowserContext(new_contents->GetBrowserContext()); |
281 EventRouter::UserGestureState gesture = | 281 EventRouter::UserGestureState gesture = |
282 reason & CHANGE_REASON_USER_GESTURE | 282 reason & CHANGE_REASON_USER_GESTURE |
283 ? EventRouter::USER_GESTURE_ENABLED | 283 ? EventRouter::USER_GESTURE_ENABLED |
284 : EventRouter::USER_GESTURE_NOT_ENABLED; | 284 : EventRouter::USER_GESTURE_NOT_ENABLED; |
285 DispatchEvent(profile, events::kOnTabSelectionChanged, | 285 DispatchEvent(profile, events::kOnTabSelectionChanged, |
286 scoped_ptr<ListValue>(args->DeepCopy()), gesture); | 286 scoped_ptr<base::ListValue>(args->DeepCopy()), gesture); |
287 DispatchEvent(profile, events::kOnTabActiveChanged, | 287 DispatchEvent(profile, events::kOnTabActiveChanged, |
288 scoped_ptr<ListValue>(args->DeepCopy()), gesture); | 288 scoped_ptr<base::ListValue>(args->DeepCopy()), gesture); |
289 | 289 |
290 // The onActivated event takes one argument: {windowId, tabId}. | 290 // The onActivated event takes one argument: {windowId, tabId}. |
291 args->Remove(0, NULL); | 291 args->Remove(0, NULL); |
292 object_args->Set(tab_keys::kTabIdKey, Value::CreateIntegerValue(tab_id)); | 292 object_args->Set(tab_keys::kTabIdKey, Value::CreateIntegerValue(tab_id)); |
293 DispatchEvent(profile, events::kOnTabActivated, args.Pass(), gesture); | 293 DispatchEvent(profile, events::kOnTabActivated, args.Pass(), gesture); |
294 } | 294 } |
295 | 295 |
296 void BrowserEventRouter::TabSelectionChanged( | 296 void BrowserEventRouter::TabSelectionChanged( |
297 TabStripModel* tab_strip_model, | 297 TabStripModel* tab_strip_model, |
298 const ui::ListSelectionModel& old_model) { | 298 const ui::ListSelectionModel& old_model) { |
299 ui::ListSelectionModel::SelectedIndices new_selection = | 299 ui::ListSelectionModel::SelectedIndices new_selection = |
300 tab_strip_model->selection_model().selected_indices(); | 300 tab_strip_model->selection_model().selected_indices(); |
301 ListValue* all = new ListValue(); | 301 base::ListValue* all = new base::ListValue(); |
302 | 302 |
303 for (size_t i = 0; i < new_selection.size(); ++i) { | 303 for (size_t i = 0; i < new_selection.size(); ++i) { |
304 int index = new_selection[i]; | 304 int index = new_selection[i]; |
305 WebContents* contents = tab_strip_model->GetWebContentsAt(index); | 305 WebContents* contents = tab_strip_model->GetWebContentsAt(index); |
306 if (!contents) | 306 if (!contents) |
307 break; | 307 break; |
308 int tab_id = ExtensionTabUtil::GetTabId(contents); | 308 int tab_id = ExtensionTabUtil::GetTabId(contents); |
309 all->Append(Value::CreateIntegerValue(tab_id)); | 309 all->Append(Value::CreateIntegerValue(tab_id)); |
310 } | 310 } |
311 | 311 |
312 scoped_ptr<ListValue> args(new ListValue()); | 312 scoped_ptr<base::ListValue> args(new base::ListValue()); |
313 DictionaryValue* select_info = new DictionaryValue(); | 313 DictionaryValue* select_info = new DictionaryValue(); |
314 | 314 |
315 select_info->Set(tab_keys::kWindowIdKey, Value::CreateIntegerValue( | 315 select_info->Set(tab_keys::kWindowIdKey, Value::CreateIntegerValue( |
316 ExtensionTabUtil::GetWindowIdOfTabStripModel(tab_strip_model))); | 316 ExtensionTabUtil::GetWindowIdOfTabStripModel(tab_strip_model))); |
317 | 317 |
318 select_info->Set(tab_keys::kTabIdsKey, all); | 318 select_info->Set(tab_keys::kTabIdsKey, all); |
319 args->Append(select_info); | 319 args->Append(select_info); |
320 | 320 |
321 // The onHighlighted event replaced onHighlightChanged. | 321 // The onHighlighted event replaced onHighlightChanged. |
322 Profile* profile = tab_strip_model->profile(); | 322 Profile* profile = tab_strip_model->profile(); |
323 DispatchEvent(profile, events::kOnTabHighlightChanged, | 323 DispatchEvent(profile, events::kOnTabHighlightChanged, |
324 scoped_ptr<ListValue>(args->DeepCopy()), | 324 scoped_ptr<base::ListValue>(args->DeepCopy()), |
325 EventRouter::USER_GESTURE_UNKNOWN); | 325 EventRouter::USER_GESTURE_UNKNOWN); |
326 DispatchEvent(profile, events::kOnTabHighlighted, args.Pass(), | 326 DispatchEvent(profile, events::kOnTabHighlighted, args.Pass(), |
327 EventRouter::USER_GESTURE_UNKNOWN); | 327 EventRouter::USER_GESTURE_UNKNOWN); |
328 } | 328 } |
329 | 329 |
330 void BrowserEventRouter::TabMoved(WebContents* contents, | 330 void BrowserEventRouter::TabMoved(WebContents* contents, |
331 int from_index, | 331 int from_index, |
332 int to_index) { | 332 int to_index) { |
333 scoped_ptr<ListValue> args(new ListValue()); | 333 scoped_ptr<base::ListValue> args(new base::ListValue()); |
334 args->Append(Value::CreateIntegerValue(ExtensionTabUtil::GetTabId(contents))); | 334 args->Append(Value::CreateIntegerValue(ExtensionTabUtil::GetTabId(contents))); |
335 | 335 |
336 DictionaryValue* object_args = new DictionaryValue(); | 336 DictionaryValue* object_args = new DictionaryValue(); |
337 object_args->Set(tab_keys::kWindowIdKey, Value::CreateIntegerValue( | 337 object_args->Set(tab_keys::kWindowIdKey, Value::CreateIntegerValue( |
338 ExtensionTabUtil::GetWindowIdOfTab(contents))); | 338 ExtensionTabUtil::GetWindowIdOfTab(contents))); |
339 object_args->Set(tab_keys::kFromIndexKey, Value::CreateIntegerValue( | 339 object_args->Set(tab_keys::kFromIndexKey, Value::CreateIntegerValue( |
340 from_index)); | 340 from_index)); |
341 object_args->Set(tab_keys::kToIndexKey, Value::CreateIntegerValue( | 341 object_args->Set(tab_keys::kToIndexKey, Value::CreateIntegerValue( |
342 to_index)); | 342 to_index)); |
343 args->Append(object_args); | 343 args->Append(object_args); |
(...skipping 29 matching lines...) Expand all Loading... |
373 scoped_ptr<DictionaryValue> changed_properties(new DictionaryValue()); | 373 scoped_ptr<DictionaryValue> changed_properties(new DictionaryValue()); |
374 changed_properties->SetString( | 374 changed_properties->SetString( |
375 tab_keys::kFaviconUrlKey, | 375 tab_keys::kFaviconUrlKey, |
376 entry->GetFavicon().url.possibly_invalid_spec()); | 376 entry->GetFavicon().url.possibly_invalid_spec()); |
377 DispatchTabUpdatedEvent(contents, changed_properties.Pass()); | 377 DispatchTabUpdatedEvent(contents, changed_properties.Pass()); |
378 } | 378 } |
379 | 379 |
380 void BrowserEventRouter::DispatchEvent( | 380 void BrowserEventRouter::DispatchEvent( |
381 Profile* profile, | 381 Profile* profile, |
382 const char* event_name, | 382 const char* event_name, |
383 scoped_ptr<ListValue> args, | 383 scoped_ptr<base::ListValue> args, |
384 EventRouter::UserGestureState user_gesture) { | 384 EventRouter::UserGestureState user_gesture) { |
385 if (!profile_->IsSameProfile(profile) || | 385 if (!profile_->IsSameProfile(profile) || |
386 !extensions::ExtensionSystem::Get(profile)->event_router()) | 386 !extensions::ExtensionSystem::Get(profile)->event_router()) |
387 return; | 387 return; |
388 | 388 |
389 scoped_ptr<Event> event(new Event(event_name, args.Pass())); | 389 scoped_ptr<Event> event(new Event(event_name, args.Pass())); |
390 event->restrict_to_profile = profile; | 390 event->restrict_to_profile = profile; |
391 event->user_gesture = user_gesture; | 391 event->user_gesture = user_gesture; |
392 ExtensionSystem::Get(profile)->event_router()->BroadcastEvent(event.Pass()); | 392 ExtensionSystem::Get(profile)->event_router()->BroadcastEvent(event.Pass()); |
393 } | 393 } |
394 | 394 |
395 void BrowserEventRouter::DispatchEventToExtension( | 395 void BrowserEventRouter::DispatchEventToExtension( |
396 Profile* profile, | 396 Profile* profile, |
397 const std::string& extension_id, | 397 const std::string& extension_id, |
398 const char* event_name, | 398 const char* event_name, |
399 scoped_ptr<ListValue> event_args, | 399 scoped_ptr<base::ListValue> event_args, |
400 EventRouter::UserGestureState user_gesture) { | 400 EventRouter::UserGestureState user_gesture) { |
401 if (!profile_->IsSameProfile(profile) || | 401 if (!profile_->IsSameProfile(profile) || |
402 !extensions::ExtensionSystem::Get(profile)->event_router()) | 402 !extensions::ExtensionSystem::Get(profile)->event_router()) |
403 return; | 403 return; |
404 | 404 |
405 scoped_ptr<Event> event(new Event(event_name, event_args.Pass())); | 405 scoped_ptr<Event> event(new Event(event_name, event_args.Pass())); |
406 event->restrict_to_profile = profile; | 406 event->restrict_to_profile = profile; |
407 event->user_gesture = user_gesture; | 407 event->user_gesture = user_gesture; |
408 ExtensionSystem::Get(profile)->event_router()-> | 408 ExtensionSystem::Get(profile)->event_router()-> |
409 DispatchEventToExtension(extension_id, event.Pass()); | 409 DispatchEventToExtension(extension_id, event.Pass()); |
410 } | 410 } |
411 | 411 |
412 void BrowserEventRouter::DispatchSimpleBrowserEvent( | 412 void BrowserEventRouter::DispatchSimpleBrowserEvent( |
413 Profile* profile, const int window_id, const char* event_name) { | 413 Profile* profile, const int window_id, const char* event_name) { |
414 if (!profile_->IsSameProfile(profile)) | 414 if (!profile_->IsSameProfile(profile)) |
415 return; | 415 return; |
416 | 416 |
417 scoped_ptr<ListValue> args(new ListValue()); | 417 scoped_ptr<base::ListValue> args(new base::ListValue()); |
418 args->Append(Value::CreateIntegerValue(window_id)); | 418 args->Append(Value::CreateIntegerValue(window_id)); |
419 | 419 |
420 DispatchEvent(profile, event_name, args.Pass(), | 420 DispatchEvent(profile, event_name, args.Pass(), |
421 EventRouter::USER_GESTURE_UNKNOWN); | 421 EventRouter::USER_GESTURE_UNKNOWN); |
422 } | 422 } |
423 | 423 |
424 static void WillDispatchTabUpdatedEvent( | 424 static void WillDispatchTabUpdatedEvent( |
425 WebContents* contents, | 425 WebContents* contents, |
426 const DictionaryValue* changed_properties, | 426 const DictionaryValue* changed_properties, |
427 Profile* profile, | 427 Profile* profile, |
428 const Extension* extension, | 428 const Extension* extension, |
429 ListValue* event_args) { | 429 base::ListValue* event_args) { |
430 // Overwrite the second argument with the appropriate properties dictionary, | 430 // Overwrite the second argument with the appropriate properties dictionary, |
431 // depending on extension permissions. | 431 // depending on extension permissions. |
432 DictionaryValue* properties_value = changed_properties->DeepCopy(); | 432 DictionaryValue* properties_value = changed_properties->DeepCopy(); |
433 ExtensionTabUtil::ScrubTabValueForExtension(contents, extension, | 433 ExtensionTabUtil::ScrubTabValueForExtension(contents, extension, |
434 properties_value); | 434 properties_value); |
435 event_args->Set(1, properties_value); | 435 event_args->Set(1, properties_value); |
436 | 436 |
437 // Overwrite the third arg with our tab value as seen by this extension. | 437 // Overwrite the third arg with our tab value as seen by this extension. |
438 DictionaryValue* tab_value = ExtensionTabUtil::CreateTabValue( | 438 DictionaryValue* tab_value = ExtensionTabUtil::CreateTabValue( |
439 contents, extension); | 439 contents, extension); |
440 event_args->Set(2, tab_value); | 440 event_args->Set(2, tab_value); |
441 } | 441 } |
442 | 442 |
443 void BrowserEventRouter::DispatchTabUpdatedEvent( | 443 void BrowserEventRouter::DispatchTabUpdatedEvent( |
444 WebContents* contents, scoped_ptr<DictionaryValue> changed_properties) { | 444 WebContents* contents, scoped_ptr<DictionaryValue> changed_properties) { |
445 DCHECK(changed_properties); | 445 DCHECK(changed_properties); |
446 DCHECK(contents); | 446 DCHECK(contents); |
447 | 447 |
448 // The state of the tab (as seen from the extension point of view) has | 448 // The state of the tab (as seen from the extension point of view) has |
449 // changed. Send a notification to the extension. | 449 // changed. Send a notification to the extension. |
450 scoped_ptr<ListValue> args_base(new ListValue()); | 450 scoped_ptr<base::ListValue> args_base(new base::ListValue()); |
451 | 451 |
452 // First arg: The id of the tab that changed. | 452 // First arg: The id of the tab that changed. |
453 args_base->AppendInteger(ExtensionTabUtil::GetTabId(contents)); | 453 args_base->AppendInteger(ExtensionTabUtil::GetTabId(contents)); |
454 | 454 |
455 // Second arg: An object containing the changes to the tab state. Filled in | 455 // Second arg: An object containing the changes to the tab state. Filled in |
456 // by WillDispatchTabUpdatedEvent as a copy of changed_properties, if the | 456 // by WillDispatchTabUpdatedEvent as a copy of changed_properties, if the |
457 // extension has the tabs permission. | 457 // extension has the tabs permission. |
458 | 458 |
459 // Third arg: An object containing the state of the tab. Filled in by | 459 // Third arg: An object containing the state of the tab. Filled in by |
460 // WillDispatchTabUpdatedEvent. | 460 // WillDispatchTabUpdatedEvent. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 } | 510 } |
511 | 511 |
512 void BrowserEventRouter::TabReplacedAt(TabStripModel* tab_strip_model, | 512 void BrowserEventRouter::TabReplacedAt(TabStripModel* tab_strip_model, |
513 WebContents* old_contents, | 513 WebContents* old_contents, |
514 WebContents* new_contents, | 514 WebContents* new_contents, |
515 int index) { | 515 int index) { |
516 // Notify listeners that the next tabs closing or being added are due to | 516 // Notify listeners that the next tabs closing or being added are due to |
517 // WebContents being swapped. | 517 // WebContents being swapped. |
518 const int new_tab_id = ExtensionTabUtil::GetTabId(new_contents); | 518 const int new_tab_id = ExtensionTabUtil::GetTabId(new_contents); |
519 const int old_tab_id = ExtensionTabUtil::GetTabId(old_contents); | 519 const int old_tab_id = ExtensionTabUtil::GetTabId(old_contents); |
520 scoped_ptr<ListValue> args(new ListValue()); | 520 scoped_ptr<base::ListValue> args(new base::ListValue()); |
521 args->Append(Value::CreateIntegerValue(new_tab_id)); | 521 args->Append(Value::CreateIntegerValue(new_tab_id)); |
522 args->Append(Value::CreateIntegerValue(old_tab_id)); | 522 args->Append(Value::CreateIntegerValue(old_tab_id)); |
523 | 523 |
524 DispatchEvent(Profile::FromBrowserContext(new_contents->GetBrowserContext()), | 524 DispatchEvent(Profile::FromBrowserContext(new_contents->GetBrowserContext()), |
525 events::kOnTabReplaced, | 525 events::kOnTabReplaced, |
526 args.Pass(), | 526 args.Pass(), |
527 EventRouter::USER_GESTURE_UNKNOWN); | 527 EventRouter::USER_GESTURE_UNKNOWN); |
528 | 528 |
529 // Update tab_entries_. | 529 // Update tab_entries_. |
530 const int removed_count = tab_entries_.erase(old_tab_id); | 530 const int removed_count = tab_entries_.erase(old_tab_id); |
(...skipping 21 matching lines...) Expand all Loading... |
552 | 552 |
553 void BrowserEventRouter::TabStripEmpty() {} | 553 void BrowserEventRouter::TabStripEmpty() {} |
554 | 554 |
555 void BrowserEventRouter::DispatchOldPageActionEvent( | 555 void BrowserEventRouter::DispatchOldPageActionEvent( |
556 Profile* profile, | 556 Profile* profile, |
557 const std::string& extension_id, | 557 const std::string& extension_id, |
558 const std::string& page_action_id, | 558 const std::string& page_action_id, |
559 int tab_id, | 559 int tab_id, |
560 const std::string& url, | 560 const std::string& url, |
561 int button) { | 561 int button) { |
562 scoped_ptr<ListValue> args(new ListValue()); | 562 scoped_ptr<base::ListValue> args(new base::ListValue()); |
563 args->Append(Value::CreateStringValue(page_action_id)); | 563 args->Append(Value::CreateStringValue(page_action_id)); |
564 | 564 |
565 DictionaryValue* data = new DictionaryValue(); | 565 DictionaryValue* data = new DictionaryValue(); |
566 data->Set(tab_keys::kTabIdKey, Value::CreateIntegerValue(tab_id)); | 566 data->Set(tab_keys::kTabIdKey, Value::CreateIntegerValue(tab_id)); |
567 data->Set(tab_keys::kTabUrlKey, Value::CreateStringValue(url)); | 567 data->Set(tab_keys::kTabUrlKey, Value::CreateStringValue(url)); |
568 data->Set(page_actions_keys::kButtonKey, | 568 data->Set(page_actions_keys::kButtonKey, |
569 Value::CreateIntegerValue(button)); | 569 Value::CreateIntegerValue(button)); |
570 args->Append(data); | 570 args->Append(data); |
571 | 571 |
572 DispatchEventToExtension(profile, extension_id, "pageActions", args.Pass(), | 572 DispatchEventToExtension(profile, extension_id, "pageActions", args.Pass(), |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 break; | 625 break; |
626 case ActionInfo::TYPE_SCRIPT_BADGE: | 626 case ActionInfo::TYPE_SCRIPT_BADGE: |
627 event_name = "scriptBadge.onClicked"; | 627 event_name = "scriptBadge.onClicked"; |
628 break; | 628 break; |
629 case ActionInfo::TYPE_SYSTEM_INDICATOR: | 629 case ActionInfo::TYPE_SYSTEM_INDICATOR: |
630 // The System Indicator handles its own clicks. | 630 // The System Indicator handles its own clicks. |
631 break; | 631 break; |
632 } | 632 } |
633 | 633 |
634 if (event_name) { | 634 if (event_name) { |
635 scoped_ptr<ListValue> args(new ListValue()); | 635 scoped_ptr<base::ListValue> args(new base::ListValue()); |
636 DictionaryValue* tab_value = ExtensionTabUtil::CreateTabValue( | 636 DictionaryValue* tab_value = ExtensionTabUtil::CreateTabValue( |
637 web_contents); | 637 web_contents); |
638 args->Append(tab_value); | 638 args->Append(tab_value); |
639 | 639 |
640 DispatchEventToExtension(profile, | 640 DispatchEventToExtension(profile, |
641 extension_action.extension_id(), | 641 extension_action.extension_id(), |
642 event_name, | 642 event_name, |
643 args.Pass(), | 643 args.Pass(), |
644 EventRouter::USER_GESTURE_ENABLED); | 644 EventRouter::USER_GESTURE_ENABLED); |
645 } | 645 } |
646 } | 646 } |
647 | 647 |
648 } // namespace extensions | 648 } // namespace extensions |
OLD | NEW |