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/extension_host.h" | 5 #include "extensions/browser/extension_host.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "content/public/browser/browser_context.h" | 12 #include "content/public/browser/browser_context.h" |
13 #include "content/public/browser/content_browser_client.h" | 13 #include "content/public/browser/content_browser_client.h" |
14 #include "content/public/browser/native_web_keyboard_event.h" | 14 #include "content/public/browser/native_web_keyboard_event.h" |
15 #include "content/public/browser/notification_service.h" | 15 #include "content/public/browser/notification_service.h" |
16 #include "content/public/browser/notification_source.h" | |
17 #include "content/public/browser/notification_types.h" | |
18 #include "content/public/browser/render_process_host.h" | 16 #include "content/public/browser/render_process_host.h" |
19 #include "content/public/browser/render_view_host.h" | 17 #include "content/public/browser/render_view_host.h" |
20 #include "content/public/browser/render_widget_host_view.h" | 18 #include "content/public/browser/render_widget_host_view.h" |
21 #include "content/public/browser/site_instance.h" | 19 #include "content/public/browser/site_instance.h" |
22 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
23 #include "extensions/browser/event_router.h" | 21 #include "extensions/browser/event_router.h" |
24 #include "extensions/browser/extension_error.h" | 22 #include "extensions/browser/extension_error.h" |
25 #include "extensions/browser/extension_host_delegate.h" | 23 #include "extensions/browser/extension_host_delegate.h" |
26 #include "extensions/browser/extension_host_observer.h" | 24 #include "extensions/browser/extension_host_observer.h" |
27 #include "extensions/browser/extension_host_queue.h" | 25 #include "extensions/browser/extension_host_queue.h" |
| 26 #include "extensions/browser/extension_registry.h" |
28 #include "extensions/browser/extension_system.h" | 27 #include "extensions/browser/extension_system.h" |
29 #include "extensions/browser/extensions_browser_client.h" | 28 #include "extensions/browser/extensions_browser_client.h" |
30 #include "extensions/browser/load_monitoring_extension_host_queue.h" | 29 #include "extensions/browser/load_monitoring_extension_host_queue.h" |
31 #include "extensions/browser/notification_types.h" | 30 #include "extensions/browser/notification_types.h" |
32 #include "extensions/browser/process_manager.h" | 31 #include "extensions/browser/process_manager.h" |
33 #include "extensions/browser/runtime_data.h" | 32 #include "extensions/browser/runtime_data.h" |
34 #include "extensions/browser/view_type_utils.h" | 33 #include "extensions/browser/view_type_utils.h" |
35 #include "extensions/common/extension.h" | 34 #include "extensions/common/extension.h" |
36 #include "extensions/common/extension_messages.h" | 35 #include "extensions/common/extension_messages.h" |
37 #include "extensions/common/extension_urls.h" | 36 #include "extensions/common/extension_urls.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 host_contents_.reset(WebContents::Create( | 69 host_contents_.reset(WebContents::Create( |
71 WebContents::CreateParams(browser_context_, site_instance))), | 70 WebContents::CreateParams(browser_context_, site_instance))), |
72 content::WebContentsObserver::Observe(host_contents_.get()); | 71 content::WebContentsObserver::Observe(host_contents_.get()); |
73 host_contents_->SetDelegate(this); | 72 host_contents_->SetDelegate(this); |
74 SetViewType(host_contents_.get(), host_type); | 73 SetViewType(host_contents_.get(), host_type); |
75 | 74 |
76 render_view_host_ = host_contents_->GetRenderViewHost(); | 75 render_view_host_ = host_contents_->GetRenderViewHost(); |
77 | 76 |
78 // Listen for when an extension is unloaded from the same profile, as it may | 77 // Listen for when an extension is unloaded from the same profile, as it may |
79 // be the same extension that this points to. | 78 // be the same extension that this points to. |
80 registrar_.Add(this, | 79 ExtensionRegistry::Get(browser_context_)->AddObserver(this); |
81 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, | |
82 content::Source<BrowserContext>(browser_context_)); | |
83 | 80 |
84 // Set up web contents observers and pref observers. | 81 // Set up web contents observers and pref observers. |
85 delegate_->OnExtensionHostCreated(host_contents()); | 82 delegate_->OnExtensionHostCreated(host_contents()); |
86 } | 83 } |
87 | 84 |
88 ExtensionHost::~ExtensionHost() { | 85 ExtensionHost::~ExtensionHost() { |
| 86 ExtensionRegistry::Get(browser_context_)->RemoveObserver(this); |
| 87 |
89 if (extension_host_type_ == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE && | 88 if (extension_host_type_ == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE && |
90 extension_ && BackgroundInfo::HasLazyBackgroundPage(extension_) && | 89 extension_ && BackgroundInfo::HasLazyBackgroundPage(extension_) && |
91 load_start_.get()) { | 90 load_start_.get()) { |
92 UMA_HISTOGRAM_LONG_TIMES("Extensions.EventPageActiveTime2", | 91 UMA_HISTOGRAM_LONG_TIMES("Extensions.EventPageActiveTime2", |
93 load_start_->Elapsed()); | 92 load_start_->Elapsed()); |
94 } | 93 } |
95 content::NotificationService::current()->Notify( | 94 content::NotificationService::current()->Notify( |
96 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 95 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
97 content::Source<BrowserContext>(browser_context_), | 96 content::Source<BrowserContext>(browser_context_), |
98 content::Details<ExtensionHost>(this)); | 97 content::Details<ExtensionHost>(this)); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 host_contents_->GetController().LoadURL( | 202 host_contents_->GetController().LoadURL( |
204 initial_url_, content::Referrer(), ui::PAGE_TRANSITION_LINK, | 203 initial_url_, content::Referrer(), ui::PAGE_TRANSITION_LINK, |
205 std::string()); | 204 std::string()); |
206 } | 205 } |
207 | 206 |
208 bool ExtensionHost::IsBackgroundPage() const { | 207 bool ExtensionHost::IsBackgroundPage() const { |
209 DCHECK(extension_host_type_ == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); | 208 DCHECK(extension_host_type_ == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); |
210 return true; | 209 return true; |
211 } | 210 } |
212 | 211 |
213 void ExtensionHost::Observe(int type, | 212 void ExtensionHost::OnExtensionUnloaded( |
214 const content::NotificationSource& source, | 213 content::BrowserContext* browser_context, |
215 const content::NotificationDetails& details) { | 214 const Extension* extension, |
216 switch (type) { | 215 UnloadedExtensionInfo::Reason reason) { |
217 case extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: | 216 // The extension object will be deleted after this notification has been sent. |
218 // The extension object will be deleted after this notification has been | 217 // Null it out so that dirty pointer issues don't arise in cases when multiple |
219 // sent. Null it out so that dirty pointer issues don't arise in cases | 218 // ExtensionHost objects pointing to the same Extension are present. |
220 // when multiple ExtensionHost objects pointing to the same Extension are | 219 if (extension_ == extension) { |
221 // present. | 220 extension_ = nullptr; |
222 if (extension_ == content::Details<UnloadedExtensionInfo>(details)-> | |
223 extension) { | |
224 extension_ = nullptr; | |
225 } | |
226 break; | |
227 default: | |
228 NOTREACHED() << "Unexpected notification sent."; | |
229 break; | |
230 } | 221 } |
231 } | 222 } |
232 | 223 |
233 void ExtensionHost::RenderProcessGone(base::TerminationStatus status) { | 224 void ExtensionHost::RenderProcessGone(base::TerminationStatus status) { |
234 // During browser shutdown, we may use sudden termination on an extension | 225 // During browser shutdown, we may use sudden termination on an extension |
235 // process, so it is expected to lose our connection to the render view. | 226 // process, so it is expected to lose our connection to the render view. |
236 // Do nothing. | 227 // Do nothing. |
237 RenderProcessHost* process_host = host_contents_->GetRenderProcessHost(); | 228 RenderProcessHost* process_host = host_contents_->GetRenderProcessHost(); |
238 if (process_host && process_host->FastShutdownStarted()) | 229 if (process_host && process_host->FastShutdownStarted()) |
239 return; | 230 return; |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 return delegate_->CheckMediaAccessPermission( | 431 return delegate_->CheckMediaAccessPermission( |
441 web_contents, security_origin, type, extension()); | 432 web_contents, security_origin, type, extension()); |
442 } | 433 } |
443 | 434 |
444 bool ExtensionHost::IsNeverVisible(content::WebContents* web_contents) { | 435 bool ExtensionHost::IsNeverVisible(content::WebContents* web_contents) { |
445 ViewType view_type = extensions::GetViewType(web_contents); | 436 ViewType view_type = extensions::GetViewType(web_contents); |
446 return view_type == extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE; | 437 return view_type == extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE; |
447 } | 438 } |
448 | 439 |
449 } // namespace extensions | 440 } // namespace extensions |
OLD | NEW |