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

Side by Side Diff: chrome/browser/extensions/extension_browser_event_router.cc

Issue 100164: extensions api: windows.removeWindow(), events: onWindowCreated, onWindowRemoved (Closed)
Patch Set: touch grd to avoid clobber build Created 11 years, 7 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 (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/extension_browser_event_router.h" 5 #include "chrome/browser/extensions/extension_browser_event_router.h"
6 6
7 #include "base/json_writer.h" 7 #include "base/json_writer.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/browser.h" 9 #include "chrome/browser/browser.h"
10 #include "chrome/browser/profile.h" 10 #include "chrome/browser/profile.h"
11 #include "chrome/browser/extensions/extension.h" 11 #include "chrome/browser/extensions/extension.h"
12 #include "chrome/browser/extensions/extension_message_service.h" 12 #include "chrome/browser/extensions/extension_message_service.h"
13 #include "chrome/browser/extensions/extension_tabs_module.h" 13 #include "chrome/browser/extensions/extension_tabs_module.h"
14 #include "chrome/common/notification_service.h" 14 #include "chrome/common/notification_service.h"
15 15
16 const char* kOnWindowCreated = "window-created";
17 const char* kOnWindowRemoved = "window-removed";
16 const char* kOnTabCreated = "tab-created"; 18 const char* kOnTabCreated = "tab-created";
17 const char* kOnTabMoved = "tab-moved"; 19 const char* kOnTabMoved = "tab-moved";
18 const char* kOnTabSelectionChanged = "tab-selection-changed"; 20 const char* kOnTabSelectionChanged = "tab-selection-changed";
19 const char* kOnTabAttached = "tab-attached"; 21 const char* kOnTabAttached = "tab-attached";
20 const char* kOnTabDetached = "tab-detached"; 22 const char* kOnTabDetached = "tab-detached";
21 const char* kOnTabRemoved = "tab-removed"; 23 const char* kOnTabRemoved = "tab-removed";
22 24
23 ExtensionBrowserEventRouter* ExtensionBrowserEventRouter::GetInstance() { 25 ExtensionBrowserEventRouter* ExtensionBrowserEventRouter::GetInstance() {
24 return Singleton<ExtensionBrowserEventRouter>::get(); 26 return Singleton<ExtensionBrowserEventRouter>::get();
25 } 27 }
(...skipping 22 matching lines...) Expand all
48 50
49 // NotificationObserver 51 // NotificationObserver
50 void ExtensionBrowserEventRouter::Observe(NotificationType type, 52 void ExtensionBrowserEventRouter::Observe(NotificationType type,
51 const NotificationSource& source, const NotificationDetails& details) { 53 const NotificationSource& source, const NotificationDetails& details) {
52 Browser* browser; 54 Browser* browser;
53 55
54 switch (type.value) { 56 switch (type.value) {
55 case(NotificationType::BROWSER_OPENED) : 57 case(NotificationType::BROWSER_OPENED) :
56 browser = Source<Browser>(source).ptr(); 58 browser = Source<Browser>(source).ptr();
57 browser->tabstrip_model()->AddObserver(this); 59 browser->tabstrip_model()->AddObserver(this);
60 BrowserOpened(browser);
58 break; 61 break;
59 case(NotificationType::BROWSER_CLOSED) : 62 case(NotificationType::BROWSER_CLOSED) :
60 browser = Source<Browser>(source).ptr(); 63 browser = Source<Browser>(source).ptr();
61 browser->tabstrip_model()->RemoveObserver(this); 64 browser->tabstrip_model()->RemoveObserver(this);
65 BrowserClosed(browser);
62 break; 66 break;
63 default: 67 default:
64 NOTREACHED(); 68 NOTREACHED();
65 break; 69 break;
66 } 70 }
67 } 71 }
68 72
73 void ExtensionBrowserEventRouter::BrowserOpened(Browser* browser) {
74 int window_id = ExtensionTabUtil::GetWindowId(browser);
75
76 ListValue args;
77 args.Append(Value::CreateIntegerValue(window_id));
78
79 std::string json_args;
80 JSONWriter::Write(&args, false, &json_args);
81
82 DispatchEvent(browser->profile(), kOnWindowCreated, json_args);
83 }
84
85 void ExtensionBrowserEventRouter::BrowserClosed(Browser* browser) {
86 int window_id = ExtensionTabUtil::GetWindowId(browser);
87
88 ListValue args;
89 args.Append(Value::CreateIntegerValue(window_id));
90
91 std::string json_args;
92 JSONWriter::Write(&args, false, &json_args);
93
94 DispatchEvent(browser->profile(), kOnWindowRemoved, json_args);
95 }
96
69 void ExtensionBrowserEventRouter::TabInsertedAt(TabContents* contents, 97 void ExtensionBrowserEventRouter::TabInsertedAt(TabContents* contents,
70 int index, 98 int index,
71 bool foreground) { 99 bool foreground) {
72 const char* event_name = kOnTabAttached; 100 const char* event_name = kOnTabAttached;
73 // If tab is new, send tab-created event. 101 // If tab is new, send tab-created event.
74 int tab_id = ExtensionTabUtil::GetTabId(contents); 102 int tab_id = ExtensionTabUtil::GetTabId(contents);
75 if (tab_ids_.find(tab_id) == tab_ids_.end()) { 103 if (tab_ids_.find(tab_id) == tab_ids_.end()) {
76 tab_ids_.insert(tab_id); 104 tab_ids_.insert(tab_id);
77 event_name = kOnTabCreated; 105 event_name = kOnTabCreated;
78 } 106 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 JSONWriter::Write(&args, false, &json_args); 193 JSONWriter::Write(&args, false, &json_args);
166 194
167 DispatchEvent(contents->profile(), kOnTabMoved, json_args); 195 DispatchEvent(contents->profile(), kOnTabMoved, json_args);
168 } 196 }
169 197
170 void ExtensionBrowserEventRouter::TabChangedAt(TabContents* contents, 198 void ExtensionBrowserEventRouter::TabChangedAt(TabContents* contents,
171 int index, 199 int index,
172 bool loading_only) { } 200 bool loading_only) { }
173 201
174 void ExtensionBrowserEventRouter::TabStripEmpty() { } 202 void ExtensionBrowserEventRouter::TabStripEmpty() { }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_browser_event_router.h ('k') | chrome/browser/extensions/extension_function_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698