OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/renderer_startup_helper.h" | 5 #include "extensions/browser/renderer_startup_helper.h" |
6 | 6 |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 8 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
9 #include "content/public/browser/notification_service.h" | 9 #include "content/public/browser/notification_service.h" |
10 #include "content/public/browser/notification_types.h" | 10 #include "content/public/browser/notification_types.h" |
(...skipping 10 matching lines...) Expand all Loading... | |
21 | 21 |
22 using content::BrowserContext; | 22 using content::BrowserContext; |
23 | 23 |
24 namespace extensions { | 24 namespace extensions { |
25 | 25 |
26 RendererStartupHelper::RendererStartupHelper(BrowserContext* browser_context) | 26 RendererStartupHelper::RendererStartupHelper(BrowserContext* browser_context) |
27 : browser_context_(browser_context) { | 27 : browser_context_(browser_context) { |
28 DCHECK(browser_context); | 28 DCHECK(browser_context); |
29 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED, | 29 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED, |
30 content::NotificationService::AllBrowserContextsAndSources()); | 30 content::NotificationService::AllBrowserContextsAndSources()); |
31 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | |
32 content::NotificationService::AllBrowserContextsAndSources()); | |
31 } | 33 } |
32 | 34 |
33 RendererStartupHelper::~RendererStartupHelper() {} | 35 RendererStartupHelper::~RendererStartupHelper() {} |
34 | 36 |
35 void RendererStartupHelper::Observe( | 37 void RendererStartupHelper::Observe( |
36 int type, | 38 int type, |
37 const content::NotificationSource& source, | 39 const content::NotificationSource& source, |
38 const content::NotificationDetails& details) { | 40 const content::NotificationDetails& details) { |
39 DCHECK_EQ(content::NOTIFICATION_RENDERER_PROCESS_CREATED, type); | 41 switch (type) { |
40 content::RenderProcessHost* process = | 42 case content::NOTIFICATION_RENDERER_PROCESS_CREATED: |
41 content::Source<content::RenderProcessHost>(source).ptr(); | 43 InitializeProcess( |
44 content::Source<content::RenderProcessHost>(source).ptr()); | |
45 break; | |
46 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: | |
47 UntrackProcess(content::Source<content::RenderProcessHost>(source).ptr()); | |
48 break; | |
49 default: | |
50 NOTREACHED() << "Unexpected notification: " << type; | |
51 } | |
52 } | |
53 | |
54 void RendererStartupHelper::InitializeProcess( | |
55 content::RenderProcessHost* process) { | |
42 ExtensionsBrowserClient* client = ExtensionsBrowserClient::Get(); | 56 ExtensionsBrowserClient* client = ExtensionsBrowserClient::Get(); |
43 if (!client->IsSameContext(browser_context_, process->GetBrowserContext())) | 57 if (!client->IsSameContext(browser_context_, process->GetBrowserContext())) |
44 return; | 58 return; |
45 | 59 |
46 bool activity_logging_enabled = | 60 bool activity_logging_enabled = |
47 client->IsActivityLoggingEnabled(process->GetBrowserContext()); | 61 client->IsActivityLoggingEnabled(process->GetBrowserContext()); |
48 // We only send the ActivityLoggingEnabled message if it is enabled; otherwise | 62 // We only send the ActivityLoggingEnabled message if it is enabled; otherwise |
49 // the default (not enabled) is correct. | 63 // the default (not enabled) is correct. |
50 if (activity_logging_enabled) { | 64 if (activity_logging_enabled) { |
51 process->Send( | 65 process->Send( |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 // TODO(kalman): Only include tab specific permissions for extension | 98 // TODO(kalman): Only include tab specific permissions for extension |
85 // processes, no other process needs it, so it's mildly wasteful. | 99 // processes, no other process needs it, so it's mildly wasteful. |
86 // I am not sure this is possible to know this here, at such a low | 100 // I am not sure this is possible to know this here, at such a low |
87 // level of the stack. Perhaps site isolation can help. | 101 // level of the stack. Perhaps site isolation can help. |
88 bool include_tab_permissions = true; | 102 bool include_tab_permissions = true; |
89 loaded_extensions.push_back( | 103 loaded_extensions.push_back( |
90 ExtensionMsg_Loaded_Params(ext.get(), include_tab_permissions)); | 104 ExtensionMsg_Loaded_Params(ext.get(), include_tab_permissions)); |
91 } | 105 } |
92 } | 106 } |
93 process->Send(new ExtensionMsg_Loaded(loaded_extensions)); | 107 process->Send(new ExtensionMsg_Loaded(loaded_extensions)); |
108 auto iter = pending_active_extensions_.find(process); | |
109 if (iter != pending_active_extensions_.end()) { | |
110 for (const ExtensionId& id : iter->second) | |
111 process->Send(new ExtensionMsg_ActivateExtension(id)); | |
lazyboy
2016/07/22 00:29:31
DCHECK(extensions.Contains(id)) or does that make
Devlin
2016/07/26 03:45:09
Sure, done.
| |
112 } | |
113 | |
114 initialized_processes_.insert(process); | |
115 } | |
116 | |
117 void RendererStartupHelper::UntrackProcess( | |
118 content::RenderProcessHost* process) { | |
119 initialized_processes_.erase(process); | |
lazyboy
2016/07/22 00:29:31
Though not necessary, I think bailing out of this
Devlin
2016/07/26 03:45:09
Done.
| |
120 pending_active_extensions_.erase(process); | |
121 } | |
122 | |
123 void RendererStartupHelper::ActivateExtensionInProcess( | |
124 const ExtensionId& id, | |
125 content::RenderProcessHost* process) { | |
126 if (initialized_processes_.count(process)) | |
127 process->Send(new ExtensionMsg_ActivateExtension(id)); | |
128 else | |
129 pending_active_extensions_[process].insert(id); | |
130 } | |
131 | |
132 void RendererStartupHelper::OnExtensionLoaded(const Extension& extension) { | |
133 if (extension.is_theme()) | |
lazyboy
2016/07/22 00:29:31
Retain the old comment:
// Renderers don't need to
Devlin
2016/07/26 03:45:09
Done.
| |
134 return; | |
135 | |
136 // We don't need to include tab permisisons here, since the extension | |
137 // was just loaded. | |
138 // Uninitialized renderers will be informed of the extension load during the | |
139 // first batch of messages. | |
140 std::vector<ExtensionMsg_Loaded_Params> params( | |
141 1, | |
142 ExtensionMsg_Loaded_Params(&extension, false /* no tab permissions */)); | |
143 for (content::RenderProcessHost* process : initialized_processes_) | |
144 process->Send(new ExtensionMsg_Loaded(params)); | |
145 } | |
146 | |
147 void RendererStartupHelper::OnExtensionUnloaded(const ExtensionId& id) { | |
148 for (content::RenderProcessHost* process : initialized_processes_) | |
149 process->Send(new ExtensionMsg_Unloaded(id)); | |
150 for (auto& kv : pending_active_extensions_) | |
lazyboy
2016/07/22 00:29:31
s/kv/extensions_in_process or sth.
Devlin
2016/07/26 03:45:09
replaced with process_extensions_pair (it's not ex
| |
151 kv.second.erase(id); | |
94 } | 152 } |
95 | 153 |
96 ////////////////////////////////////////////////////////////////////////////// | 154 ////////////////////////////////////////////////////////////////////////////// |
97 | 155 |
98 // static | 156 // static |
99 RendererStartupHelper* RendererStartupHelperFactory::GetForBrowserContext( | 157 RendererStartupHelper* RendererStartupHelperFactory::GetForBrowserContext( |
100 BrowserContext* context) { | 158 BrowserContext* context) { |
101 return static_cast<RendererStartupHelper*>( | 159 return static_cast<RendererStartupHelper*>( |
102 GetInstance()->GetServiceForBrowserContext(context, true)); | 160 GetInstance()->GetServiceForBrowserContext(context, true)); |
103 } | 161 } |
(...skipping 21 matching lines...) Expand all Loading... | |
125 BrowserContext* context) const { | 183 BrowserContext* context) const { |
126 // Redirected in incognito. | 184 // Redirected in incognito. |
127 return ExtensionsBrowserClient::Get()->GetOriginalContext(context); | 185 return ExtensionsBrowserClient::Get()->GetOriginalContext(context); |
128 } | 186 } |
129 | 187 |
130 bool RendererStartupHelperFactory::ServiceIsCreatedWithBrowserContext() const { | 188 bool RendererStartupHelperFactory::ServiceIsCreatedWithBrowserContext() const { |
131 return true; | 189 return true; |
132 } | 190 } |
133 | 191 |
134 } // namespace extensions | 192 } // namespace extensions |
OLD | NEW |