OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_host.h" | 5 #include "chrome/browser/extensions/extension_host.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
16 #include "chrome/browser/browser_shutdown.h" | 16 #include "chrome/browser/browser_shutdown.h" |
17 #include "chrome/browser/extensions/event_router.h" | 17 #include "chrome/browser/extensions/event_router.h" |
18 #include "chrome/browser/extensions/extension_process_manager.h" | 18 #include "chrome/browser/extensions/extension_process_manager.h" |
19 #include "chrome/browser/extensions/extension_service.h" | 19 #include "chrome/browser/extensions/extension_service.h" |
20 #include "chrome/browser/extensions/extension_system.h" | 20 #include "chrome/browser/extensions/extension_system.h" |
21 #include "chrome/browser/extensions/extension_tab_util.h" | 21 #include "chrome/browser/extensions/extension_tab_util.h" |
22 #include "chrome/browser/extensions/window_controller.h" | 22 #include "chrome/browser/extensions/window_controller.h" |
23 #include "chrome/browser/file_select_helper.h" | 23 #include "chrome/browser/file_select_helper.h" |
24 #include "chrome/browser/lifetime/application_lifetime.h" | |
24 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
25 #include "chrome/browser/ui/app_modal_dialogs/javascript_dialog_creator.h" | 26 #include "chrome/browser/ui/app_modal_dialogs/javascript_dialog_creator.h" |
26 #include "chrome/browser/ui/browser.h" | 27 #include "chrome/browser/ui/browser.h" |
27 #include "chrome/browser/ui/browser_finder.h" | 28 #include "chrome/browser/ui/browser_finder.h" |
28 #include "chrome/browser/ui/browser_list.h" | 29 #include "chrome/browser/ui/browser_list.h" |
29 #include "chrome/browser/ui/browser_window.h" | 30 #include "chrome/browser/ui/browser_window.h" |
30 #include "chrome/browser/ui/prefs/prefs_tab_helper.h" | 31 #include "chrome/browser/ui/prefs/prefs_tab_helper.h" |
31 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 32 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
32 #include "chrome/browser/view_type_utils.h" | 33 #include "chrome/browser/view_type_utils.h" |
33 #include "chrome/common/chrome_constants.h" | 34 #include "chrome/common/chrome_constants.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
147 chrome::SetViewType(host_contents_.get(), host_type); | 148 chrome::SetViewType(host_contents_.get(), host_type); |
148 | 149 |
149 PrefsTabHelper::CreateForWebContents(host_contents()); | 150 PrefsTabHelper::CreateForWebContents(host_contents()); |
150 | 151 |
151 render_view_host_ = host_contents_->GetRenderViewHost(); | 152 render_view_host_ = host_contents_->GetRenderViewHost(); |
152 | 153 |
153 // Listen for when an extension is unloaded from the same profile, as it may | 154 // Listen for when an extension is unloaded from the same profile, as it may |
154 // be the same extension that this points to. | 155 // be the same extension that this points to. |
155 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 156 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
156 content::Source<Profile>(profile_)); | 157 content::Source<Profile>(profile_)); |
158 | |
159 // Keep the browser process alive while platform apps have active background | |
160 // pages. | |
161 if (extension_->is_platform_app() && | |
162 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { | |
benwells
2012/10/12 05:33:38
I don't like putting the is_platform_app check her
Aaron Boodman
2012/10/12 17:58:30
What about if ExtensionHost supported this feature
| |
163 browser::StartKeepAlive(); | |
164 } | |
157 } | 165 } |
158 | 166 |
159 ExtensionHost::~ExtensionHost() { | 167 ExtensionHost::~ExtensionHost() { |
160 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE && | 168 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE && |
161 extension_ && extension_->has_lazy_background_page()) { | 169 extension_ && extension_->has_lazy_background_page()) { |
162 UMA_HISTOGRAM_LONG_TIMES("Extensions.EventPageActiveTime", | 170 UMA_HISTOGRAM_LONG_TIMES("Extensions.EventPageActiveTime", |
163 since_created_.Elapsed()); | 171 since_created_.Elapsed()); |
164 } | 172 } |
165 content::NotificationService::current()->Notify( | 173 content::NotificationService::current()->Notify( |
166 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 174 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
167 content::Source<Profile>(profile_), | 175 content::Source<Profile>(profile_), |
168 content::Details<ExtensionHost>(this)); | 176 content::Details<ExtensionHost>(this)); |
169 ProcessCreationQueue::GetInstance()->Remove(this); | 177 ProcessCreationQueue::GetInstance()->Remove(this); |
178 | |
179 if (extension_->is_platform_app() && | |
180 extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { | |
181 browser::EndKeepAlive(); | |
182 } | |
170 } | 183 } |
171 | 184 |
172 void ExtensionHost::CreateView(Browser* browser) { | 185 void ExtensionHost::CreateView(Browser* browser) { |
173 #if defined(TOOLKIT_VIEWS) | 186 #if defined(TOOLKIT_VIEWS) |
174 view_.reset(new ExtensionViewViews(this, browser)); | 187 view_.reset(new ExtensionViewViews(this, browser)); |
175 // We own |view_|, so don't auto delete when it's removed from the view | 188 // We own |view_|, so don't auto delete when it's removed from the view |
176 // hierarchy. | 189 // hierarchy. |
177 view_->set_owned_by_client(); | 190 view_->set_owned_by_client(); |
178 #elif defined(OS_MACOSX) | 191 #elif defined(OS_MACOSX) |
179 view_.reset(new ExtensionViewMac(this, browser)); | 192 view_.reset(new ExtensionViewMac(this, browser)); |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
634 } | 647 } |
635 | 648 |
636 void ExtensionHost::RenderViewReady() { | 649 void ExtensionHost::RenderViewReady() { |
637 content::NotificationService::current()->Notify( | 650 content::NotificationService::current()->Notify( |
638 chrome::NOTIFICATION_EXTENSION_HOST_CREATED, | 651 chrome::NOTIFICATION_EXTENSION_HOST_CREATED, |
639 content::Source<Profile>(profile_), | 652 content::Source<Profile>(profile_), |
640 content::Details<ExtensionHost>(this)); | 653 content::Details<ExtensionHost>(this)); |
641 } | 654 } |
642 | 655 |
643 } // namespace extensions | 656 } // namespace extensions |
OLD | NEW |