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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 bool active) { | 177 bool active) { |
178 // If tab is new, send created event. | 178 // If tab is new, send created event. |
179 int tab_id = ExtensionTabUtil::GetTabId(contents->web_contents()); | 179 int tab_id = ExtensionTabUtil::GetTabId(contents->web_contents()); |
180 if (!GetTabEntry(contents->web_contents())) { | 180 if (!GetTabEntry(contents->web_contents())) { |
181 tab_entries_[tab_id] = TabEntry(); | 181 tab_entries_[tab_id] = TabEntry(); |
182 | 182 |
183 TabCreatedAt(contents->web_contents(), index, active); | 183 TabCreatedAt(contents->web_contents(), index, active); |
184 return; | 184 return; |
185 } | 185 } |
186 | 186 |
187 ListValue args; | 187 scoped_ptr<ListValue> args(new ListValue()); |
188 args.Append(Value::CreateIntegerValue(tab_id)); | 188 args->Append(Value::CreateIntegerValue(tab_id)); |
189 | 189 |
190 DictionaryValue* object_args = new DictionaryValue(); | 190 DictionaryValue* object_args = new DictionaryValue(); |
191 object_args->Set(tab_keys::kNewWindowIdKey, Value::CreateIntegerValue( | 191 object_args->Set(tab_keys::kNewWindowIdKey, Value::CreateIntegerValue( |
192 ExtensionTabUtil::GetWindowIdOfTab(contents->web_contents()))); | 192 ExtensionTabUtil::GetWindowIdOfTab(contents->web_contents()))); |
193 object_args->Set(tab_keys::kNewPositionKey, Value::CreateIntegerValue( | 193 object_args->Set(tab_keys::kNewPositionKey, Value::CreateIntegerValue( |
194 index)); | 194 index)); |
195 args.Append(object_args); | 195 args->Append(object_args); |
196 | 196 |
197 std::string json_args; | 197 DispatchEvent(contents->profile(), events::kOnTabAttached, args.Pass(), |
198 base::JSONWriter::Write(&args, &json_args); | |
199 | |
200 DispatchEvent(contents->profile(), events::kOnTabAttached, json_args, | |
201 EventRouter::USER_GESTURE_UNKNOWN); | 198 EventRouter::USER_GESTURE_UNKNOWN); |
202 } | 199 } |
203 | 200 |
204 void BrowserEventRouter::TabDetachedAt(TabContents* contents, int index) { | 201 void BrowserEventRouter::TabDetachedAt(TabContents* contents, int index) { |
205 if (!GetTabEntry(contents->web_contents())) { | 202 if (!GetTabEntry(contents->web_contents())) { |
206 // The tab was removed. Don't send detach event. | 203 // The tab was removed. Don't send detach event. |
207 return; | 204 return; |
208 } | 205 } |
209 | 206 |
210 ListValue args; | 207 scoped_ptr<ListValue> args(new ListValue()); |
211 args.Append(Value::CreateIntegerValue( | 208 args->Append(Value::CreateIntegerValue( |
212 ExtensionTabUtil::GetTabId(contents->web_contents()))); | 209 ExtensionTabUtil::GetTabId(contents->web_contents()))); |
213 | 210 |
214 DictionaryValue* object_args = new DictionaryValue(); | 211 DictionaryValue* object_args = new DictionaryValue(); |
215 object_args->Set(tab_keys::kOldWindowIdKey, Value::CreateIntegerValue( | 212 object_args->Set(tab_keys::kOldWindowIdKey, Value::CreateIntegerValue( |
216 ExtensionTabUtil::GetWindowIdOfTab(contents->web_contents()))); | 213 ExtensionTabUtil::GetWindowIdOfTab(contents->web_contents()))); |
217 object_args->Set(tab_keys::kOldPositionKey, Value::CreateIntegerValue( | 214 object_args->Set(tab_keys::kOldPositionKey, Value::CreateIntegerValue( |
218 index)); | 215 index)); |
219 args.Append(object_args); | 216 args->Append(object_args); |
220 | 217 |
221 std::string json_args; | 218 DispatchEvent(contents->profile(), events::kOnTabDetached, args.Pass(), |
222 base::JSONWriter::Write(&args, &json_args); | |
223 | |
224 DispatchEvent(contents->profile(), events::kOnTabDetached, json_args, | |
225 EventRouter::USER_GESTURE_UNKNOWN); | 219 EventRouter::USER_GESTURE_UNKNOWN); |
226 } | 220 } |
227 | 221 |
228 void BrowserEventRouter::TabClosingAt(TabStripModel* tab_strip_model, | 222 void BrowserEventRouter::TabClosingAt(TabStripModel* tab_strip_model, |
229 TabContents* contents, | 223 TabContents* contents, |
230 int index) { | 224 int index) { |
231 int tab_id = ExtensionTabUtil::GetTabId(contents->web_contents()); | 225 int tab_id = ExtensionTabUtil::GetTabId(contents->web_contents()); |
232 | 226 |
233 ListValue args; | 227 scoped_ptr<ListValue> args(new ListValue()); |
234 args.Append(Value::CreateIntegerValue(tab_id)); | 228 args->Append(Value::CreateIntegerValue(tab_id)); |
235 | 229 |
236 DictionaryValue* object_args = new DictionaryValue(); | 230 DictionaryValue* object_args = new DictionaryValue(); |
237 object_args->SetBoolean(tab_keys::kWindowClosing, | 231 object_args->SetBoolean(tab_keys::kWindowClosing, |
238 tab_strip_model->closing_all()); | 232 tab_strip_model->closing_all()); |
239 args.Append(object_args); | 233 args->Append(object_args); |
240 | 234 |
241 std::string json_args; | 235 DispatchEvent(contents->profile(), events::kOnTabRemoved, args.Pass(), |
242 base::JSONWriter::Write(&args, &json_args); | |
243 | |
244 DispatchEvent(contents->profile(), events::kOnTabRemoved, json_args, | |
245 EventRouter::USER_GESTURE_UNKNOWN); | 236 EventRouter::USER_GESTURE_UNKNOWN); |
246 | 237 |
247 int removed_count = tab_entries_.erase(tab_id); | 238 int removed_count = tab_entries_.erase(tab_id); |
248 DCHECK_GT(removed_count, 0); | 239 DCHECK_GT(removed_count, 0); |
249 | 240 |
250 UnregisterForTabNotifications(contents->web_contents()); | 241 UnregisterForTabNotifications(contents->web_contents()); |
251 } | 242 } |
252 | 243 |
253 void BrowserEventRouter::ActiveTabChanged(TabContents* old_contents, | 244 void BrowserEventRouter::ActiveTabChanged(TabContents* old_contents, |
254 TabContents* new_contents, | 245 TabContents* new_contents, |
255 int index, | 246 int index, |
256 bool user_gesture) { | 247 bool user_gesture) { |
257 ListValue args; | 248 scoped_ptr<ListValue> args(new ListValue()); |
258 int tab_id = ExtensionTabUtil::GetTabId(new_contents->web_contents()); | 249 int tab_id = ExtensionTabUtil::GetTabId(new_contents->web_contents()); |
259 args.Append(Value::CreateIntegerValue(tab_id)); | 250 args->Append(Value::CreateIntegerValue(tab_id)); |
260 | 251 |
261 DictionaryValue* object_args = new DictionaryValue(); | 252 DictionaryValue* object_args = new DictionaryValue(); |
262 object_args->Set(tab_keys::kWindowIdKey, Value::CreateIntegerValue( | 253 object_args->Set(tab_keys::kWindowIdKey, Value::CreateIntegerValue( |
263 ExtensionTabUtil::GetWindowIdOfTab(new_contents->web_contents()))); | 254 ExtensionTabUtil::GetWindowIdOfTab(new_contents->web_contents()))); |
264 args.Append(object_args); | 255 args->Append(object_args); |
265 | 256 |
266 // The onActivated event replaced onActiveChanged and onSelectionChanged. The | 257 // The onActivated event replaced onActiveChanged and onSelectionChanged. The |
267 // deprecated events take two arguments: tabId, {windowId}. | 258 // deprecated events take two arguments: tabId, {windowId}. |
268 std::string old_json_args; | |
269 base::JSONWriter::Write(&args, &old_json_args); | |
270 | |
271 // The onActivated event takes one argument: {windowId, tabId}. | |
272 std::string new_json_args; | |
273 args.Remove(0, NULL); | |
274 object_args->Set(tab_keys::kTabIdKey, Value::CreateIntegerValue(tab_id)); | |
275 base::JSONWriter::Write(&args, &new_json_args); | |
276 | |
277 Profile* profile = new_contents->profile(); | 259 Profile* profile = new_contents->profile(); |
278 EventRouter::UserGestureState gesture = user_gesture ? | 260 EventRouter::UserGestureState gesture = user_gesture ? |
279 EventRouter::USER_GESTURE_ENABLED : EventRouter::USER_GESTURE_NOT_ENABLED; | 261 EventRouter::USER_GESTURE_ENABLED : EventRouter::USER_GESTURE_NOT_ENABLED; |
280 DispatchEvent(profile, events::kOnTabSelectionChanged, old_json_args, | 262 DispatchEvent(profile, events::kOnTabSelectionChanged, |
281 gesture); | 263 scoped_ptr<ListValue>(args->DeepCopy()), gesture); |
282 DispatchEvent(profile, events::kOnTabActiveChanged, old_json_args, gesture); | 264 DispatchEvent(profile, events::kOnTabActiveChanged, |
283 DispatchEvent(profile, events::kOnTabActivated, new_json_args, gesture); | 265 scoped_ptr<ListValue>(args->DeepCopy()), gesture); |
| 266 |
| 267 // The onActivated event takes one argument: {windowId, tabId}. |
| 268 args->Remove(0, NULL); |
| 269 object_args->Set(tab_keys::kTabIdKey, Value::CreateIntegerValue(tab_id)); |
| 270 DispatchEvent(profile, events::kOnTabActivated, args.Pass(), gesture); |
284 } | 271 } |
285 | 272 |
286 void BrowserEventRouter::TabSelectionChanged( | 273 void BrowserEventRouter::TabSelectionChanged( |
287 TabStripModel* tab_strip_model, | 274 TabStripModel* tab_strip_model, |
288 const TabStripSelectionModel& old_model) { | 275 const TabStripSelectionModel& old_model) { |
289 TabStripSelectionModel::SelectedIndices new_selection = | 276 TabStripSelectionModel::SelectedIndices new_selection = |
290 tab_strip_model->selection_model().selected_indices(); | 277 tab_strip_model->selection_model().selected_indices(); |
291 ListValue* all = new ListValue(); | 278 ListValue* all = new ListValue(); |
292 | 279 |
293 for (size_t i = 0; i < new_selection.size(); ++i) { | 280 for (size_t i = 0; i < new_selection.size(); ++i) { |
294 int index = new_selection[i]; | 281 int index = new_selection[i]; |
295 TabContents* contents = tab_strip_model->GetTabContentsAt(index); | 282 TabContents* contents = tab_strip_model->GetTabContentsAt(index); |
296 if (!contents) | 283 if (!contents) |
297 break; | 284 break; |
298 int tab_id = ExtensionTabUtil::GetTabId(contents->web_contents()); | 285 int tab_id = ExtensionTabUtil::GetTabId(contents->web_contents()); |
299 all->Append(Value::CreateIntegerValue(tab_id)); | 286 all->Append(Value::CreateIntegerValue(tab_id)); |
300 } | 287 } |
301 | 288 |
302 ListValue args; | 289 scoped_ptr<ListValue> args(new ListValue()); |
303 DictionaryValue* select_info = new DictionaryValue(); | 290 DictionaryValue* select_info = new DictionaryValue(); |
304 | 291 |
305 select_info->Set(tab_keys::kWindowIdKey, Value::CreateIntegerValue( | 292 select_info->Set(tab_keys::kWindowIdKey, Value::CreateIntegerValue( |
306 ExtensionTabUtil::GetWindowIdOfTabStripModel(tab_strip_model))); | 293 ExtensionTabUtil::GetWindowIdOfTabStripModel(tab_strip_model))); |
307 | 294 |
308 select_info->Set(tab_keys::kTabIdsKey, all); | 295 select_info->Set(tab_keys::kTabIdsKey, all); |
309 args.Append(select_info); | 296 args->Append(select_info); |
310 | |
311 std::string json_args; | |
312 base::JSONWriter::Write(&args, &json_args); | |
313 | 297 |
314 // The onHighlighted event replaced onHighlightChanged. | 298 // The onHighlighted event replaced onHighlightChanged. |
315 Profile* profile = tab_strip_model->profile(); | 299 Profile* profile = tab_strip_model->profile(); |
316 DispatchEvent(profile, events::kOnTabHighlightChanged, json_args, | 300 DispatchEvent(profile, events::kOnTabHighlightChanged, |
| 301 scoped_ptr<ListValue>(args->DeepCopy()), |
317 EventRouter::USER_GESTURE_UNKNOWN); | 302 EventRouter::USER_GESTURE_UNKNOWN); |
318 DispatchEvent(profile, events::kOnTabHighlighted, json_args, | 303 DispatchEvent(profile, events::kOnTabHighlighted, args.Pass(), |
319 EventRouter::USER_GESTURE_UNKNOWN); | 304 EventRouter::USER_GESTURE_UNKNOWN); |
320 } | 305 } |
321 | 306 |
322 void BrowserEventRouter::TabMoved(TabContents* contents, | 307 void BrowserEventRouter::TabMoved(TabContents* contents, |
323 int from_index, | 308 int from_index, |
324 int to_index) { | 309 int to_index) { |
325 ListValue args; | 310 scoped_ptr<ListValue> args(new ListValue()); |
326 args.Append(Value::CreateIntegerValue( | 311 args->Append(Value::CreateIntegerValue( |
327 ExtensionTabUtil::GetTabId(contents->web_contents()))); | 312 ExtensionTabUtil::GetTabId(contents->web_contents()))); |
328 | 313 |
329 DictionaryValue* object_args = new DictionaryValue(); | 314 DictionaryValue* object_args = new DictionaryValue(); |
330 object_args->Set(tab_keys::kWindowIdKey, Value::CreateIntegerValue( | 315 object_args->Set(tab_keys::kWindowIdKey, Value::CreateIntegerValue( |
331 ExtensionTabUtil::GetWindowIdOfTab(contents->web_contents()))); | 316 ExtensionTabUtil::GetWindowIdOfTab(contents->web_contents()))); |
332 object_args->Set(tab_keys::kFromIndexKey, Value::CreateIntegerValue( | 317 object_args->Set(tab_keys::kFromIndexKey, Value::CreateIntegerValue( |
333 from_index)); | 318 from_index)); |
334 object_args->Set(tab_keys::kToIndexKey, Value::CreateIntegerValue( | 319 object_args->Set(tab_keys::kToIndexKey, Value::CreateIntegerValue( |
335 to_index)); | 320 to_index)); |
336 args.Append(object_args); | 321 args->Append(object_args); |
337 | 322 |
338 std::string json_args; | 323 DispatchEvent(contents->profile(), events::kOnTabMoved, args.Pass(), |
339 base::JSONWriter::Write(&args, &json_args); | |
340 | |
341 DispatchEvent(contents->profile(), events::kOnTabMoved, json_args, | |
342 EventRouter::USER_GESTURE_UNKNOWN); | 324 EventRouter::USER_GESTURE_UNKNOWN); |
343 } | 325 } |
344 | 326 |
345 void BrowserEventRouter::TabUpdated(WebContents* contents, bool did_navigate) { | 327 void BrowserEventRouter::TabUpdated(WebContents* contents, bool did_navigate) { |
346 TabEntry* entry = GetTabEntry(contents); | 328 TabEntry* entry = GetTabEntry(contents); |
347 DictionaryValue* changed_properties = NULL; | 329 DictionaryValue* changed_properties = NULL; |
348 | 330 |
349 DCHECK(entry); | 331 DCHECK(entry); |
350 | 332 |
351 if (did_navigate) | 333 if (did_navigate) |
352 changed_properties = entry->DidNavigate(contents); | 334 changed_properties = entry->DidNavigate(contents); |
353 else | 335 else |
354 changed_properties = entry->UpdateLoadState(contents); | 336 changed_properties = entry->UpdateLoadState(contents); |
355 | 337 |
356 if (changed_properties) | 338 if (changed_properties) |
357 DispatchTabUpdatedEvent(contents, changed_properties); | 339 DispatchTabUpdatedEvent(contents, changed_properties); |
358 } | 340 } |
359 | 341 |
360 void BrowserEventRouter::DispatchEvent( | 342 void BrowserEventRouter::DispatchEvent( |
361 Profile* profile, | 343 Profile* profile, |
362 const char* event_name, | 344 const char* event_name, |
363 const std::string& json_args, | 345 scoped_ptr<ListValue> args, |
364 EventRouter::UserGestureState user_gesture) { | 346 EventRouter::UserGestureState user_gesture) { |
365 if (!profile_->IsSameProfile(profile) || !profile->GetExtensionEventRouter()) | 347 if (!profile_->IsSameProfile(profile) || !profile->GetExtensionEventRouter()) |
366 return; | 348 return; |
367 | 349 |
368 profile->GetExtensionEventRouter()->DispatchEventToRenderers( | 350 profile->GetExtensionEventRouter()->DispatchEventToRenderers( |
369 event_name, json_args, profile, GURL(), user_gesture); | 351 event_name, args.Pass(), profile, GURL(), user_gesture); |
370 } | 352 } |
371 | 353 |
372 void BrowserEventRouter::DispatchEventToExtension( | 354 void BrowserEventRouter::DispatchEventToExtension( |
373 Profile* profile, | 355 Profile* profile, |
374 const std::string& extension_id, | 356 const std::string& extension_id, |
375 const char* event_name, | 357 const char* event_name, |
376 const std::string& json_args, | 358 scoped_ptr<ListValue> event_args, |
377 EventRouter::UserGestureState user_gesture) { | 359 EventRouter::UserGestureState user_gesture) { |
378 if (!profile_->IsSameProfile(profile) || !profile->GetExtensionEventRouter()) | 360 if (!profile_->IsSameProfile(profile) || !profile->GetExtensionEventRouter()) |
379 return; | 361 return; |
380 | 362 |
381 profile->GetExtensionEventRouter()->DispatchEventToExtension( | 363 profile->GetExtensionEventRouter()->DispatchEventToExtension( |
382 extension_id, event_name, json_args, profile, GURL(), user_gesture); | 364 extension_id, event_name, event_args.Pass(), profile, GURL(), |
| 365 user_gesture); |
383 } | 366 } |
384 | 367 |
385 void BrowserEventRouter::DispatchEventsAcrossIncognito( | 368 void BrowserEventRouter::DispatchEventsAcrossIncognito( |
386 Profile* profile, | 369 Profile* profile, |
387 const char* event_name, | 370 const char* event_name, |
388 const std::string& json_args, | 371 scoped_ptr<ListValue> event_args, |
389 const std::string& cross_incognito_args) { | 372 scoped_ptr<ListValue> cross_incognito_args) { |
390 if (!profile_->IsSameProfile(profile) || !profile->GetExtensionEventRouter()) | 373 if (!profile_->IsSameProfile(profile) || !profile->GetExtensionEventRouter()) |
391 return; | 374 return; |
392 | 375 |
393 profile->GetExtensionEventRouter()->DispatchEventsToRenderersAcrossIncognito( | 376 profile->GetExtensionEventRouter()->DispatchEventsToRenderersAcrossIncognito( |
394 event_name, json_args, profile, cross_incognito_args, GURL()); | 377 event_name, event_args.Pass(), profile, cross_incognito_args.Pass(), |
| 378 GURL()); |
395 } | 379 } |
396 | 380 |
397 void BrowserEventRouter::DispatchEventWithTab( | 381 void BrowserEventRouter::DispatchEventWithTab( |
398 Profile* profile, | 382 Profile* profile, |
399 const std::string& extension_id, | 383 const std::string& extension_id, |
400 const char* event_name, | 384 const char* event_name, |
401 const WebContents* web_contents, | 385 const WebContents* web_contents, |
402 bool active, | 386 bool active, |
403 EventRouter::UserGestureState user_gesture) { | 387 EventRouter::UserGestureState user_gesture) { |
404 if (!profile_->IsSameProfile(profile)) | 388 if (!profile_->IsSameProfile(profile)) |
405 return; | 389 return; |
406 | 390 |
407 ListValue args; | 391 scoped_ptr<ListValue> args(new ListValue()); |
408 args.Append(ExtensionTabUtil::CreateTabValueActive( | 392 args->Append(ExtensionTabUtil::CreateTabValueActive( |
409 web_contents, active)); | 393 web_contents, active)); |
410 std::string json_args; | |
411 base::JSONWriter::Write(&args, &json_args); | |
412 if (!extension_id.empty()) { | 394 if (!extension_id.empty()) { |
413 DispatchEventToExtension(profile, extension_id, event_name, json_args, | 395 DispatchEventToExtension(profile, extension_id, event_name, args.Pass(), |
414 user_gesture); | 396 user_gesture); |
415 } else { | 397 } else { |
416 DispatchEvent(profile, event_name, json_args, user_gesture); | 398 DispatchEvent(profile, event_name, args.Pass(), user_gesture); |
417 } | 399 } |
418 } | 400 } |
419 | 401 |
420 void BrowserEventRouter::DispatchSimpleBrowserEvent( | 402 void BrowserEventRouter::DispatchSimpleBrowserEvent( |
421 Profile* profile, const int window_id, const char* event_name) { | 403 Profile* profile, const int window_id, const char* event_name) { |
422 if (!profile_->IsSameProfile(profile)) | 404 if (!profile_->IsSameProfile(profile)) |
423 return; | 405 return; |
424 | 406 |
425 ListValue args; | 407 scoped_ptr<ListValue> args(new ListValue()); |
426 args.Append(Value::CreateIntegerValue(window_id)); | 408 args->Append(Value::CreateIntegerValue(window_id)); |
427 | 409 |
428 std::string json_args; | 410 DispatchEvent(profile, event_name, args.Pass(), |
429 base::JSONWriter::Write(&args, &json_args); | |
430 | |
431 DispatchEvent(profile, event_name, json_args, | |
432 EventRouter::USER_GESTURE_UNKNOWN); | 411 EventRouter::USER_GESTURE_UNKNOWN); |
433 } | 412 } |
434 | 413 |
435 void BrowserEventRouter::DispatchTabUpdatedEvent( | 414 void BrowserEventRouter::DispatchTabUpdatedEvent( |
436 WebContents* contents, DictionaryValue* changed_properties) { | 415 WebContents* contents, DictionaryValue* changed_properties) { |
437 DCHECK(changed_properties); | 416 DCHECK(changed_properties); |
438 DCHECK(contents); | 417 DCHECK(contents); |
439 | 418 |
440 // The state of the tab (as seen from the extension point of view) has | 419 // The state of the tab (as seen from the extension point of view) has |
441 // changed. Send a notification to the extension. | 420 // changed. Send a notification to the extension. |
442 ListValue args; | 421 scoped_ptr<ListValue> args(new ListValue()); |
443 | 422 |
444 // First arg: The id of the tab that changed. | 423 // First arg: The id of the tab that changed. |
445 args.Append(Value::CreateIntegerValue(ExtensionTabUtil::GetTabId(contents))); | 424 args->Append(Value::CreateIntegerValue(ExtensionTabUtil::GetTabId(contents))); |
446 | 425 |
447 // Second arg: An object containing the changes to the tab state. | 426 // Second arg: An object containing the changes to the tab state. |
448 args.Append(changed_properties); | 427 args->Append(changed_properties); |
449 | 428 |
450 // Third arg: An object containing the state of the tab. | 429 // Third arg: An object containing the state of the tab. |
451 args.Append(ExtensionTabUtil::CreateTabValue(contents)); | 430 args->Append(ExtensionTabUtil::CreateTabValue(contents)); |
452 | |
453 std::string json_args; | |
454 base::JSONWriter::Write(&args, &json_args); | |
455 | 431 |
456 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); | 432 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); |
457 DispatchEvent(profile, events::kOnTabUpdated, json_args, | 433 DispatchEvent(profile, events::kOnTabUpdated, args.Pass(), |
458 EventRouter::USER_GESTURE_UNKNOWN); | 434 EventRouter::USER_GESTURE_UNKNOWN); |
459 } | 435 } |
460 | 436 |
461 BrowserEventRouter::TabEntry* BrowserEventRouter::GetTabEntry( | 437 BrowserEventRouter::TabEntry* BrowserEventRouter::GetTabEntry( |
462 const WebContents* contents) { | 438 const WebContents* contents) { |
463 int tab_id = ExtensionTabUtil::GetTabId(contents); | 439 int tab_id = ExtensionTabUtil::GetTabId(contents); |
464 std::map<int, TabEntry>::iterator i = tab_entries_.find(tab_id); | 440 std::map<int, TabEntry>::iterator i = tab_entries_.find(tab_id); |
465 if (tab_entries_.end() == i) | 441 if (tab_entries_.end() == i) |
466 return NULL; | 442 return NULL; |
467 return &i->second; | 443 return &i->second; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 | 492 |
517 void BrowserEventRouter::TabStripEmpty() {} | 493 void BrowserEventRouter::TabStripEmpty() {} |
518 | 494 |
519 void BrowserEventRouter::DispatchOldPageActionEvent( | 495 void BrowserEventRouter::DispatchOldPageActionEvent( |
520 Profile* profile, | 496 Profile* profile, |
521 const std::string& extension_id, | 497 const std::string& extension_id, |
522 const std::string& page_action_id, | 498 const std::string& page_action_id, |
523 int tab_id, | 499 int tab_id, |
524 const std::string& url, | 500 const std::string& url, |
525 int button) { | 501 int button) { |
526 ListValue args; | 502 scoped_ptr<ListValue> args(new ListValue()); |
527 args.Append(Value::CreateStringValue(page_action_id)); | 503 args->Append(Value::CreateStringValue(page_action_id)); |
528 | 504 |
529 DictionaryValue* data = new DictionaryValue(); | 505 DictionaryValue* data = new DictionaryValue(); |
530 data->Set(tab_keys::kTabIdKey, Value::CreateIntegerValue(tab_id)); | 506 data->Set(tab_keys::kTabIdKey, Value::CreateIntegerValue(tab_id)); |
531 data->Set(tab_keys::kTabUrlKey, Value::CreateStringValue(url)); | 507 data->Set(tab_keys::kTabUrlKey, Value::CreateStringValue(url)); |
532 data->Set(page_action_keys::kButtonKey, Value::CreateIntegerValue(button)); | 508 data->Set(page_action_keys::kButtonKey, Value::CreateIntegerValue(button)); |
533 args.Append(data); | 509 args->Append(data); |
534 | 510 |
535 std::string json_args; | 511 DispatchEventToExtension(profile, extension_id, "pageActions", args.Pass(), |
536 base::JSONWriter::Write(&args, &json_args); | |
537 | |
538 DispatchEventToExtension(profile, extension_id, "pageActions", json_args, | |
539 EventRouter::USER_GESTURE_ENABLED); | 512 EventRouter::USER_GESTURE_ENABLED); |
540 } | 513 } |
541 | 514 |
542 void BrowserEventRouter::BrowserActionExecuted( | 515 void BrowserEventRouter::BrowserActionExecuted( |
543 const ExtensionAction& browser_action, | 516 const ExtensionAction& browser_action, |
544 Browser* browser) { | 517 Browser* browser) { |
545 Profile* profile = browser->profile(); | 518 Profile* profile = browser->profile(); |
546 TabContents* tab_contents = NULL; | 519 TabContents* tab_contents = NULL; |
547 int tab_id = 0; | 520 int tab_id = 0; |
548 if (!ExtensionTabUtil::GetDefaultTab(browser, &tab_contents, &tab_id)) | 521 if (!ExtensionTabUtil::GetDefaultTab(browser, &tab_contents, &tab_id)) |
(...skipping 24 matching lines...) Expand all Loading... |
573 if (!ExtensionTabUtil::GetTabById(tab_id, profile, profile->IsOffTheRecord(), | 546 if (!ExtensionTabUtil::GetTabById(tab_id, profile, profile->IsOffTheRecord(), |
574 NULL, NULL, &tab_contents, NULL)) { | 547 NULL, NULL, &tab_contents, NULL)) { |
575 return; | 548 return; |
576 } | 549 } |
577 ExtensionActionExecuted(profile, script_badge, tab_contents); | 550 ExtensionActionExecuted(profile, script_badge, tab_contents); |
578 } | 551 } |
579 | 552 |
580 void BrowserEventRouter::CommandExecuted(Profile* profile, | 553 void BrowserEventRouter::CommandExecuted(Profile* profile, |
581 const std::string& extension_id, | 554 const std::string& extension_id, |
582 const std::string& command) { | 555 const std::string& command) { |
583 ListValue args; | 556 scoped_ptr<ListValue> args(new ListValue()); |
584 args.Append(Value::CreateStringValue(command)); | 557 args->Append(Value::CreateStringValue(command)); |
585 std::string json_args; | |
586 base::JSONWriter::Write(&args, &json_args); | |
587 | 558 |
588 DispatchEventToExtension(profile, | 559 DispatchEventToExtension(profile, |
589 extension_id, | 560 extension_id, |
590 "experimental.commands.onCommand", | 561 "experimental.commands.onCommand", |
591 json_args, | 562 args.Pass(), |
592 EventRouter::USER_GESTURE_ENABLED); | 563 EventRouter::USER_GESTURE_ENABLED); |
593 } | 564 } |
594 | 565 |
595 void BrowserEventRouter::ExtensionActionExecuted( | 566 void BrowserEventRouter::ExtensionActionExecuted( |
596 Profile* profile, | 567 Profile* profile, |
597 const ExtensionAction& extension_action, | 568 const ExtensionAction& extension_action, |
598 TabContents* tab_contents) { | 569 TabContents* tab_contents) { |
599 const char* event_name = NULL; | 570 const char* event_name = NULL; |
600 switch (extension_action.action_type()) { | 571 switch (extension_action.action_type()) { |
601 case ExtensionAction::TYPE_BROWSER: | 572 case ExtensionAction::TYPE_BROWSER: |
(...skipping 11 matching lines...) Expand all Loading... |
613 DispatchEventWithTab(profile, | 584 DispatchEventWithTab(profile, |
614 extension_action.extension_id(), | 585 extension_action.extension_id(), |
615 event_name, | 586 event_name, |
616 tab_contents->web_contents(), | 587 tab_contents->web_contents(), |
617 true, | 588 true, |
618 EventRouter::USER_GESTURE_ENABLED); | 589 EventRouter::USER_GESTURE_ENABLED); |
619 } | 590 } |
620 } | 591 } |
621 | 592 |
622 } // namespace extensions | 593 } // namespace extensions |
OLD | NEW |