OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/chrome_notification_observer.h" | 5 #include "chrome/browser/extensions/chrome_notification_observer.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/common/extensions/features/feature_channel.h" |
11 #include "content/public/browser/notification_service.h" | 12 #include "content/public/browser/notification_service.h" |
| 13 #include "content/public/browser/notification_types.h" |
| 14 #include "content/public/browser/render_process_host.h" |
12 #include "extensions/browser/extension_system.h" | 15 #include "extensions/browser/extension_system.h" |
13 #include "extensions/browser/process_manager.h" | 16 #include "extensions/browser/process_manager.h" |
| 17 #include "extensions/common/extension_messages.h" |
14 | 18 |
15 namespace extensions { | 19 namespace extensions { |
16 | 20 |
17 ChromeNotificationObserver::ChromeNotificationObserver() { | 21 ChromeNotificationObserver::ChromeNotificationObserver() { |
18 // Notifications for extensions::ProcessManager | 22 registrar_.Add(this, |
19 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY, | 23 chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
20 content::NotificationService::AllSources()); | 24 content::NotificationService::AllSources()); |
| 25 registrar_.Add(this, |
| 26 content::NOTIFICATION_RENDERER_PROCESS_CREATED, |
| 27 content::NotificationService::AllBrowserContextsAndSources()); |
21 } | 28 } |
22 | 29 |
23 ChromeNotificationObserver::~ChromeNotificationObserver() {} | 30 ChromeNotificationObserver::~ChromeNotificationObserver() {} |
24 | 31 |
25 void ChromeNotificationObserver::OnBrowserWindowReady(Browser* browser) { | 32 void ChromeNotificationObserver::OnBrowserWindowReady(Browser* browser) { |
26 Profile* profile = browser->profile(); | 33 Profile* profile = browser->profile(); |
27 DCHECK(profile); | 34 DCHECK(profile); |
28 | 35 |
29 // Inform the process manager for this profile that the window is ready. | 36 // Inform the process manager for this profile that the window is ready. |
30 // We continue to observe the notification in case browser windows open for | 37 // We continue to observe the notification in case browser windows open for |
(...skipping 12 matching lines...) Expand all Loading... |
43 if (profile->IsOffTheRecord()) { | 50 if (profile->IsOffTheRecord()) { |
44 Profile* original_profile = profile->GetOriginalProfile(); | 51 Profile* original_profile = profile->GetOriginalProfile(); |
45 extensions::ProcessManager* original_manager = | 52 extensions::ProcessManager* original_manager = |
46 ExtensionSystem::Get(original_profile)->process_manager(); | 53 ExtensionSystem::Get(original_profile)->process_manager(); |
47 DCHECK(original_manager); | 54 DCHECK(original_manager); |
48 DCHECK_EQ(original_profile, original_manager->GetBrowserContext()); | 55 DCHECK_EQ(original_profile, original_manager->GetBrowserContext()); |
49 original_manager->OnBrowserWindowReady(); | 56 original_manager->OnBrowserWindowReady(); |
50 } | 57 } |
51 } | 58 } |
52 | 59 |
| 60 void ChromeNotificationObserver::OnRendererProcessCreated( |
| 61 content::RenderProcessHost* process) { |
| 62 // Extensions need to know the channel for API restrictions. Send the channel |
| 63 // to all renderers, as the non-extension renderers may have content scripts. |
| 64 process->Send(new ExtensionMsg_SetChannel(GetCurrentChannel())); |
| 65 } |
| 66 |
53 void ChromeNotificationObserver::Observe(int type, | 67 void ChromeNotificationObserver::Observe(int type, |
54 const content::NotificationSource& source, | 68 const content::NotificationSource& source, |
55 const content::NotificationDetails& details) { | 69 const content::NotificationDetails& details) { |
56 switch (type) { | 70 switch (type) { |
57 case chrome::NOTIFICATION_BROWSER_WINDOW_READY: { | 71 case chrome::NOTIFICATION_BROWSER_WINDOW_READY: { |
58 Browser* browser = content::Source<Browser>(source).ptr(); | 72 Browser* browser = content::Source<Browser>(source).ptr(); |
59 OnBrowserWindowReady(browser); | 73 OnBrowserWindowReady(browser); |
60 break; | 74 break; |
61 } | 75 } |
62 | 76 |
| 77 case content::NOTIFICATION_RENDERER_PROCESS_CREATED: { |
| 78 content::RenderProcessHost* process = |
| 79 content::Source<content::RenderProcessHost>(source).ptr(); |
| 80 OnRendererProcessCreated(process); |
| 81 break; |
| 82 } |
| 83 |
63 default: | 84 default: |
64 NOTREACHED(); | 85 NOTREACHED(); |
65 } | 86 } |
66 } | 87 } |
67 | 88 |
68 } // namespace extensions | 89 } // namespace extensions |
OLD | NEW |