| 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/intents/web_intents_util.h" | 24 #include "chrome/browser/intents/web_intents_util.h" |
| 25 #include "chrome/browser/lifetime/application_lifetime.h" | |
| 26 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
| 27 #include "chrome/browser/ui/app_modal_dialogs/javascript_dialog_creator.h" | 26 #include "chrome/browser/ui/app_modal_dialogs/javascript_dialog_creator.h" |
| 28 #include "chrome/browser/ui/browser.h" | 27 #include "chrome/browser/ui/browser.h" |
| 29 #include "chrome/browser/ui/browser_finder.h" | 28 #include "chrome/browser/ui/browser_finder.h" |
| 30 #include "chrome/browser/ui/browser_list.h" | 29 #include "chrome/browser/ui/browser_list.h" |
| 31 #include "chrome/browser/ui/browser_window.h" | 30 #include "chrome/browser/ui/browser_window.h" |
| 32 #include "chrome/browser/ui/prefs/prefs_tab_helper.h" | 31 #include "chrome/browser/ui/prefs/prefs_tab_helper.h" |
| 33 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 32 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 34 #include "chrome/browser/view_type_utils.h" | 33 #include "chrome/browser/view_type_utils.h" |
| 35 #include "chrome/common/chrome_constants.h" | 34 #include "chrome/common/chrome_constants.h" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 SiteInstance* site_instance, | 130 SiteInstance* site_instance, |
| 132 const GURL& url, | 131 const GURL& url, |
| 133 chrome::ViewType host_type) | 132 chrome::ViewType host_type) |
| 134 : extension_(extension), | 133 : extension_(extension), |
| 135 extension_id_(extension->id()), | 134 extension_id_(extension->id()), |
| 136 profile_(Profile::FromBrowserContext( | 135 profile_(Profile::FromBrowserContext( |
| 137 site_instance->GetBrowserContext())), | 136 site_instance->GetBrowserContext())), |
| 138 render_view_host_(NULL), | 137 render_view_host_(NULL), |
| 139 did_stop_loading_(false), | 138 did_stop_loading_(false), |
| 140 document_element_available_(false), | 139 document_element_available_(false), |
| 141 keeping_browser_process_alive_(false), | |
| 142 initial_url_(url), | 140 initial_url_(url), |
| 143 ALLOW_THIS_IN_INITIALIZER_LIST( | 141 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 144 extension_function_dispatcher_(profile_, this)), | 142 extension_function_dispatcher_(profile_, this)), |
| 145 extension_host_type_(host_type), | 143 extension_host_type_(host_type), |
| 146 associated_web_contents_(NULL) { | 144 associated_web_contents_(NULL) { |
| 147 host_contents_.reset(WebContents::Create( | 145 host_contents_.reset(WebContents::Create( |
| 148 profile_, site_instance, MSG_ROUTING_NONE, NULL)); | 146 profile_, site_instance, MSG_ROUTING_NONE, NULL)); |
| 149 content::WebContentsObserver::Observe(host_contents_.get()); | 147 content::WebContentsObserver::Observe(host_contents_.get()); |
| 150 host_contents_->SetDelegate(this); | 148 host_contents_->SetDelegate(this); |
| 151 chrome::SetViewType(host_contents_.get(), host_type); | 149 chrome::SetViewType(host_contents_.get(), host_type); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 164 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE && | 162 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE && |
| 165 extension_ && extension_->has_lazy_background_page()) { | 163 extension_ && extension_->has_lazy_background_page()) { |
| 166 UMA_HISTOGRAM_LONG_TIMES("Extensions.EventPageActiveTime", | 164 UMA_HISTOGRAM_LONG_TIMES("Extensions.EventPageActiveTime", |
| 167 since_created_.Elapsed()); | 165 since_created_.Elapsed()); |
| 168 } | 166 } |
| 169 content::NotificationService::current()->Notify( | 167 content::NotificationService::current()->Notify( |
| 170 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 168 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
| 171 content::Source<Profile>(profile_), | 169 content::Source<Profile>(profile_), |
| 172 content::Details<ExtensionHost>(this)); | 170 content::Details<ExtensionHost>(this)); |
| 173 ProcessCreationQueue::GetInstance()->Remove(this); | 171 ProcessCreationQueue::GetInstance()->Remove(this); |
| 174 | |
| 175 #if !defined(OS_ANDROID) | |
| 176 if (keeping_browser_process_alive_) | |
| 177 browser::EndKeepAlive(); | |
| 178 #endif | |
| 179 } | 172 } |
| 180 | 173 |
| 181 void ExtensionHost::CreateView(Browser* browser) { | 174 void ExtensionHost::CreateView(Browser* browser) { |
| 182 #if defined(TOOLKIT_VIEWS) | 175 #if defined(TOOLKIT_VIEWS) |
| 183 view_.reset(new ExtensionViewViews(this, browser)); | 176 view_.reset(new ExtensionViewViews(this, browser)); |
| 184 // We own |view_|, so don't auto delete when it's removed from the view | 177 // We own |view_|, so don't auto delete when it's removed from the view |
| 185 // hierarchy. | 178 // hierarchy. |
| 186 view_->set_owned_by_client(); | 179 view_->set_owned_by_client(); |
| 187 #elif defined(OS_MACOSX) | 180 #elif defined(OS_MACOSX) |
| 188 view_.reset(new ExtensionViewMac(this, browser)); | 181 view_.reset(new ExtensionViewMac(this, browser)); |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 pm->IncrementLazyKeepaliveCount(extension()); | 453 pm->IncrementLazyKeepaliveCount(extension()); |
| 461 } | 454 } |
| 462 | 455 |
| 463 void ExtensionHost::DidCloseJavaScriptDialog() { | 456 void ExtensionHost::DidCloseJavaScriptDialog() { |
| 464 ExtensionProcessManager* pm = | 457 ExtensionProcessManager* pm = |
| 465 ExtensionSystem::Get(profile_)->process_manager(); | 458 ExtensionSystem::Get(profile_)->process_manager(); |
| 466 if (pm) | 459 if (pm) |
| 467 pm->DecrementLazyKeepaliveCount(extension()); | 460 pm->DecrementLazyKeepaliveCount(extension()); |
| 468 } | 461 } |
| 469 | 462 |
| 470 void ExtensionHost::SetKeepsBrowserProcessAlive() { | |
| 471 if (keeping_browser_process_alive_) | |
| 472 return; | |
| 473 | |
| 474 #if !defined(OS_ANDROID) | |
| 475 keeping_browser_process_alive_ = true; | |
| 476 browser::StartKeepAlive(); | |
| 477 #endif | |
| 478 } | |
| 479 | |
| 480 WebContents* ExtensionHost::OpenURLFromTab(WebContents* source, | 463 WebContents* ExtensionHost::OpenURLFromTab(WebContents* source, |
| 481 const OpenURLParams& params) { | 464 const OpenURLParams& params) { |
| 482 // Whitelist the dispositions we will allow to be opened. | 465 // Whitelist the dispositions we will allow to be opened. |
| 483 switch (params.disposition) { | 466 switch (params.disposition) { |
| 484 case SINGLETON_TAB: | 467 case SINGLETON_TAB: |
| 485 case NEW_FOREGROUND_TAB: | 468 case NEW_FOREGROUND_TAB: |
| 486 case NEW_BACKGROUND_TAB: | 469 case NEW_BACKGROUND_TAB: |
| 487 case NEW_POPUP: | 470 case NEW_POPUP: |
| 488 case NEW_WINDOW: | 471 case NEW_WINDOW: |
| 489 case SAVE_TO_DISK: | 472 case SAVE_TO_DISK: |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 void ExtensionHost::RequestMediaAccessPermission( | 649 void ExtensionHost::RequestMediaAccessPermission( |
| 667 content::WebContents* web_contents, | 650 content::WebContents* web_contents, |
| 668 const content::MediaStreamRequest* request, | 651 const content::MediaStreamRequest* request, |
| 669 const content::MediaResponseCallback& callback) { | 652 const content::MediaResponseCallback& callback) { |
| 670 // For tab capture device, we require the tabCapture permission. | 653 // For tab capture device, we require the tabCapture permission. |
| 671 RequestMediaAccessPermissionHelper::AuthorizeRequest( | 654 RequestMediaAccessPermissionHelper::AuthorizeRequest( |
| 672 request, callback, extension(), false); | 655 request, callback, extension(), false); |
| 673 } | 656 } |
| 674 | 657 |
| 675 } // namespace extensions | 658 } // namespace extensions |
| OLD | NEW |