diff options
Diffstat (limited to 'chrome/browser/extensions/extension_browser_event_router.cc')
-rw-r--r-- | chrome/browser/extensions/extension_browser_event_router.cc | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/chrome/browser/extensions/extension_browser_event_router.cc b/chrome/browser/extensions/extension_browser_event_router.cc index cefef15..c05e793 100644 --- a/chrome/browser/extensions/extension_browser_event_router.cc +++ b/chrome/browser/extensions/extension_browser_event_router.cc @@ -13,6 +13,8 @@ #include "chrome/browser/extensions/extension_tabs_module.h" #include "chrome/common/notification_service.h" +const char* kOnWindowCreated = "window-created"; +const char* kOnWindowRemoved = "window-removed"; const char* kOnTabCreated = "tab-created"; const char* kOnTabMoved = "tab-moved"; const char* kOnTabSelectionChanged = "tab-selection-changed"; @@ -55,10 +57,12 @@ void ExtensionBrowserEventRouter::Observe(NotificationType type, case(NotificationType::BROWSER_OPENED) : browser = Source<Browser>(source).ptr(); browser->tabstrip_model()->AddObserver(this); + BrowserOpened(browser); break; case(NotificationType::BROWSER_CLOSED) : browser = Source<Browser>(source).ptr(); browser->tabstrip_model()->RemoveObserver(this); + BrowserClosed(browser); break; default: NOTREACHED(); @@ -66,6 +70,30 @@ void ExtensionBrowserEventRouter::Observe(NotificationType type, } } +void ExtensionBrowserEventRouter::BrowserOpened(Browser* browser) { + int window_id = ExtensionTabUtil::GetWindowId(browser); + + ListValue args; + args.Append(Value::CreateIntegerValue(window_id)); + + std::string json_args; + JSONWriter::Write(&args, false, &json_args); + + DispatchEvent(browser->profile(), kOnWindowCreated, json_args); +} + +void ExtensionBrowserEventRouter::BrowserClosed(Browser* browser) { + int window_id = ExtensionTabUtil::GetWindowId(browser); + + ListValue args; + args.Append(Value::CreateIntegerValue(window_id)); + + std::string json_args; + JSONWriter::Write(&args, false, &json_args); + + DispatchEvent(browser->profile(), kOnWindowRemoved, json_args); +} + void ExtensionBrowserEventRouter::TabInsertedAt(TabContents* contents, int index, bool foreground) { |