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

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

Issue 7327007: Moving notification types which are chrome specific to a new header file chrome_notification_type... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/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/extension_event_names.h" 9 #include "chrome/browser/extensions/extension_event_names.h"
10 #include "chrome/browser/extensions/extension_event_router.h" 10 #include "chrome/browser/extensions/extension_event_router.h"
11 #include "chrome/browser/extensions/extension_page_actions_module_constants.h" 11 #include "chrome/browser/extensions/extension_page_actions_module_constants.h"
12 #include "chrome/browser/extensions/extension_tabs_module_constants.h" 12 #include "chrome/browser/extensions/extension_tabs_module_constants.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/tabs/tab_strip_model.h" 14 #include "chrome/browser/tabs/tab_strip_model.h"
15 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 16 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
17 #include "chrome/common/chrome_notification_types.h"
17 #include "chrome/common/extensions/extension.h" 18 #include "chrome/common/extensions/extension.h"
18 #include "chrome/common/extensions/extension_constants.h" 19 #include "chrome/common/extensions/extension_constants.h"
19 #include "content/browser/tab_contents/navigation_entry.h" 20 #include "content/browser/tab_contents/navigation_entry.h"
20 #include "content/browser/tab_contents/tab_contents.h" 21 #include "content/browser/tab_contents/tab_contents.h"
21 #include "content/common/notification_service.h" 22 #include "content/common/notification_service.h"
22 23
23 namespace events = extension_event_names; 24 namespace events = extension_event_names;
24 namespace tab_keys = extension_tabs_module_constants; 25 namespace tab_keys = extension_tabs_module_constants;
25 namespace page_action_keys = extension_page_actions_module_constants; 26 namespace page_action_keys = extension_page_actions_module_constants;
26 27
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 } 121 }
121 122
122 void ExtensionBrowserEventRouter::RegisterForBrowserNotifications( 123 void ExtensionBrowserEventRouter::RegisterForBrowserNotifications(
123 const Browser* browser) { 124 const Browser* browser) {
124 // Start listening to TabStripModel events for this browser. 125 // Start listening to TabStripModel events for this browser.
125 browser->tabstrip_model()->AddObserver(this); 126 browser->tabstrip_model()->AddObserver(this);
126 127
127 // If this is a new window, it isn't ready at this point, so we register to be 128 // If this is a new window, it isn't ready at this point, so we register to be
128 // notified when it is. If this is an existing window, this is a no-op that we 129 // notified when it is. If this is an existing window, this is a no-op that we
129 // just do to reduce code complexity. 130 // just do to reduce code complexity.
130 registrar_.Add(this, NotificationType::BROWSER_WINDOW_READY, 131 registrar_.Add(this, chrome::BROWSER_WINDOW_READY,
131 Source<const Browser>(browser)); 132 Source<const Browser>(browser));
132 133
133 for (int i = 0; i < browser->tabstrip_model()->count(); ++i) 134 for (int i = 0; i < browser->tabstrip_model()->count(); ++i)
134 RegisterForTabNotifications(browser->GetTabContentsAt(i)); 135 RegisterForTabNotifications(browser->GetTabContentsAt(i));
135 } 136 }
136 137
137 void ExtensionBrowserEventRouter::RegisterForTabNotifications( 138 void ExtensionBrowserEventRouter::RegisterForTabNotifications(
138 TabContents* contents) { 139 TabContents* contents) {
139 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, 140 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
140 Source<NavigationController>(&contents->controller())); 141 Source<NavigationController>(&contents->controller()));
(...skipping 27 matching lines...) Expand all
168 DispatchEvent(browser->profile(), events::kOnWindowCreated, json_args); 169 DispatchEvent(browser->profile(), events::kOnWindowCreated, json_args);
169 } 170 }
170 171
171 void ExtensionBrowserEventRouter::OnBrowserRemoved(const Browser* browser) { 172 void ExtensionBrowserEventRouter::OnBrowserRemoved(const Browser* browser) {
172 if (!profile_->IsSameProfile(browser->profile())) 173 if (!profile_->IsSameProfile(browser->profile()))
173 return; 174 return;
174 175
175 // Stop listening to TabStripModel events for this browser. 176 // Stop listening to TabStripModel events for this browser.
176 browser->tabstrip_model()->RemoveObserver(this); 177 browser->tabstrip_model()->RemoveObserver(this);
177 178
178 registrar_.Remove(this, NotificationType::BROWSER_WINDOW_READY, 179 registrar_.Remove(this, chrome::BROWSER_WINDOW_READY,
179 Source<const Browser>(browser)); 180 Source<const Browser>(browser));
180 181
181 DispatchSimpleBrowserEvent(browser->profile(), 182 DispatchSimpleBrowserEvent(browser->profile(),
182 ExtensionTabUtil::GetWindowId(browser), 183 ExtensionTabUtil::GetWindowId(browser),
183 events::kOnWindowRemoved); 184 events::kOnWindowRemoved);
184 } 185 }
185 186
186 #if defined(TOOLKIT_VIEWS) 187 #if defined(TOOLKIT_VIEWS)
187 void ExtensionBrowserEventRouter::NativeFocusWillChange( 188 void ExtensionBrowserEventRouter::NativeFocusWillChange(
188 gfx::NativeView focused_before, 189 gfx::NativeView focused_before,
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 NavigationController* source_controller = 495 NavigationController* source_controller =
495 Source<NavigationController>(source).ptr(); 496 Source<NavigationController>(source).ptr();
496 TabUpdated(source_controller->tab_contents(), true); 497 TabUpdated(source_controller->tab_contents(), true);
497 } else if (type == NotificationType::TAB_CONTENTS_DESTROYED) { 498 } else if (type == NotificationType::TAB_CONTENTS_DESTROYED) {
498 // Tab was destroyed after being detached (without being re-attached). 499 // Tab was destroyed after being detached (without being re-attached).
499 TabContents* contents = Source<TabContents>(source).ptr(); 500 TabContents* contents = Source<TabContents>(source).ptr();
500 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED, 501 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
501 Source<NavigationController>(&contents->controller())); 502 Source<NavigationController>(&contents->controller()));
502 registrar_.Remove(this, NotificationType::TAB_CONTENTS_DESTROYED, 503 registrar_.Remove(this, NotificationType::TAB_CONTENTS_DESTROYED,
503 Source<TabContents>(contents)); 504 Source<TabContents>(contents));
504 } else if (type == NotificationType::BROWSER_WINDOW_READY) { 505 } else if (type == chrome::BROWSER_WINDOW_READY) {
505 const Browser* browser = Source<const Browser>(source).ptr(); 506 const Browser* browser = Source<const Browser>(source).ptr();
506 OnBrowserWindowReady(browser); 507 OnBrowserWindowReady(browser);
507 #if defined(OS_MACOSX) 508 #if defined(OS_MACOSX)
508 } else if (type == NotificationType::NO_KEY_WINDOW) { 509 } else if (type == NotificationType::NO_KEY_WINDOW) {
509 OnBrowserSetLastActive(NULL); 510 OnBrowserSetLastActive(NULL);
510 #endif 511 #endif
511 } else { 512 } else {
512 NOTREACHED(); 513 NOTREACHED();
513 } 514 }
514 } 515 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 588
588 void ExtensionBrowserEventRouter::BrowserActionExecuted( 589 void ExtensionBrowserEventRouter::BrowserActionExecuted(
589 Profile* profile, const std::string& extension_id, Browser* browser) { 590 Profile* profile, const std::string& extension_id, Browser* browser) {
590 TabContentsWrapper* tab_contents = NULL; 591 TabContentsWrapper* tab_contents = NULL;
591 int tab_id = 0; 592 int tab_id = 0;
592 if (!ExtensionTabUtil::GetDefaultTab(browser, &tab_contents, &tab_id)) 593 if (!ExtensionTabUtil::GetDefaultTab(browser, &tab_contents, &tab_id))
593 return; 594 return;
594 DispatchEventWithTab(profile, extension_id, "browserAction.onClicked", 595 DispatchEventWithTab(profile, extension_id, "browserAction.onClicked",
595 tab_contents->tab_contents(), true); 596 tab_contents->tab_contents(), true);
596 } 597 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698