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 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
390 return; | 390 return; |
391 | 391 |
392 scoped_ptr<ListValue> args(new ListValue()); | 392 scoped_ptr<ListValue> args(new ListValue()); |
393 args->Append(Value::CreateIntegerValue(window_id)); | 393 args->Append(Value::CreateIntegerValue(window_id)); |
394 | 394 |
395 DispatchEvent(profile, event_name, args.Pass(), | 395 DispatchEvent(profile, event_name, args.Pass(), |
396 EventRouter::USER_GESTURE_UNKNOWN); | 396 EventRouter::USER_GESTURE_UNKNOWN); |
397 } | 397 } |
398 | 398 |
399 static void WillDispatchTabUpdatedEvent(WebContents* contents, | 399 static void WillDispatchTabUpdatedEvent(WebContents* contents, |
400 DictionaryValue* changed_properties, | |
400 Profile* profile, | 401 Profile* profile, |
401 const Extension* extension, | 402 const Extension* extension, |
402 ListValue* event_args) { | 403 ListValue* event_args) { |
404 // Overwrite the second argument with the appropriate properties dictionary, | |
405 // depending on extension permissions. | |
406 DictionaryValue* properties_value = | |
407 ExtensionTabUtil::ScrubTabValue(contents, extension, changed_properties); | |
not at google - send to devlin
2013/01/08 21:25:09
since DispatchTabUpdatedEvent is taking ownership
mvrable
2013/01/09 01:46:59
I believe the way this callback works is that it r
| |
408 event_args->Set(1, properties_value); | |
409 | |
410 // Overwrite the third arg with our tab value as seen by this extension. | |
403 DictionaryValue* tab_value = ExtensionTabUtil::CreateTabValue( | 411 DictionaryValue* tab_value = ExtensionTabUtil::CreateTabValue( |
404 contents, extension); | 412 contents, extension); |
405 // Overwrite the third arg with our tab value as seen by this extension. | |
406 event_args->Set(2, tab_value); | 413 event_args->Set(2, tab_value); |
407 } | 414 } |
408 | 415 |
409 void BrowserEventRouter::DispatchTabUpdatedEvent( | 416 void BrowserEventRouter::DispatchTabUpdatedEvent( |
410 WebContents* contents, DictionaryValue* changed_properties) { | 417 WebContents* contents, DictionaryValue* changed_properties) { |
not at google - send to devlin
2013/01/08 21:25:09
cleanup: make this take a scoped_ptr<DictionaryVal
mvrable
2013/01/09 01:46:59
Done.
| |
411 DCHECK(changed_properties); | 418 DCHECK(changed_properties); |
412 DCHECK(contents); | 419 DCHECK(contents); |
413 | 420 |
414 // The state of the tab (as seen from the extension point of view) has | 421 // The state of the tab (as seen from the extension point of view) has |
415 // changed. Send a notification to the extension. | 422 // changed. Send a notification to the extension. |
416 scoped_ptr<ListValue> args_base(new ListValue()); | 423 scoped_ptr<ListValue> args_base(new ListValue()); |
417 | 424 |
425 // Ownership of changed_properties has been passed to us; ensure it is | |
426 // cleaned up when we return. | |
427 scoped_ptr<DictionaryValue> changed_properties_deleter(changed_properties); | |
428 | |
418 // First arg: The id of the tab that changed. | 429 // First arg: The id of the tab that changed. |
419 args_base->AppendInteger(ExtensionTabUtil::GetTabId(contents)); | 430 args_base->AppendInteger(ExtensionTabUtil::GetTabId(contents)); |
420 | 431 |
421 // Second arg: An object containing the changes to the tab state. | 432 // Second arg: An object containing the changes to the tab state. Filled in |
422 args_base->Append(changed_properties); | 433 // by WillDispatchTabUpdatedEvent as a copy of changed_properties, if the |
434 // extension has the tabs permission. | |
423 | 435 |
424 // Third arg: An object containing the state of the tab. Filled in by | 436 // Third arg: An object containing the state of the tab. Filled in by |
425 // WillDispatchTabUpdatedEvent. | 437 // WillDispatchTabUpdatedEvent. |
426 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); | 438 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); |
427 | 439 |
428 scoped_ptr<Event> event(new Event(events::kOnTabUpdated, args_base.Pass())); | 440 scoped_ptr<Event> event(new Event(events::kOnTabUpdated, args_base.Pass())); |
429 event->restrict_to_profile = profile; | 441 event->restrict_to_profile = profile; |
430 event->user_gesture = EventRouter::USER_GESTURE_NOT_ENABLED; | 442 event->user_gesture = EventRouter::USER_GESTURE_NOT_ENABLED; |
431 event->will_dispatch_callback = | 443 event->will_dispatch_callback = |
432 base::Bind(&WillDispatchTabUpdatedEvent, contents); | 444 base::Bind(&WillDispatchTabUpdatedEvent, contents, changed_properties); |
not at google - send to devlin
2013/01/08 21:25:09
changed_properties will have been deleted by the t
mvrable
2013/01/09 01:46:59
I believe that the callback is run from within Bro
| |
433 ExtensionSystem::Get(profile)->event_router()->BroadcastEvent(event.Pass()); | 445 ExtensionSystem::Get(profile)->event_router()->BroadcastEvent(event.Pass()); |
434 } | 446 } |
435 | 447 |
436 BrowserEventRouter::TabEntry* BrowserEventRouter::GetTabEntry( | 448 BrowserEventRouter::TabEntry* BrowserEventRouter::GetTabEntry( |
437 const WebContents* contents) { | 449 const WebContents* contents) { |
438 int tab_id = ExtensionTabUtil::GetTabId(contents); | 450 int tab_id = ExtensionTabUtil::GetTabId(contents); |
439 std::map<int, TabEntry>::iterator i = tab_entries_.find(tab_id); | 451 std::map<int, TabEntry>::iterator i = tab_entries_.find(tab_id); |
440 if (tab_entries_.end() == i) | 452 if (tab_entries_.end() == i) |
441 return NULL; | 453 return NULL; |
442 return &i->second; | 454 return &i->second; |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
577 | 589 |
578 DispatchEventToExtension(profile, | 590 DispatchEventToExtension(profile, |
579 extension_action.extension_id(), | 591 extension_action.extension_id(), |
580 event_name, | 592 event_name, |
581 args.Pass(), | 593 args.Pass(), |
582 EventRouter::USER_GESTURE_ENABLED); | 594 EventRouter::USER_GESTURE_ENABLED); |
583 } | 595 } |
584 } | 596 } |
585 | 597 |
586 } // namespace extensions | 598 } // namespace extensions |
OLD | NEW |