| 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/ui/fast_unload_controller.h" | 5 #include "chrome/browser/ui/fast_unload_controller.h" |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| 11 #include "base/threading/thread_task_runner_handle.h" | 11 #include "base/threading/thread_task_runner_handle.h" |
| 12 #include "chrome/browser/chrome_notification_types.h" | 12 #include "chrome/browser/chrome_notification_types.h" |
| 13 #include "chrome/browser/devtools/devtools_window.h" | 13 #include "chrome/browser/devtools/devtools_window.h" |
| 14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/browser_tabstrip.h" | 15 #include "chrome/browser/ui/browser_tabstrip.h" |
| 16 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" | 16 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
| 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 18 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h" | 18 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h" |
| 19 #include "content/public/browser/notification_service.h" | 19 #include "content/public/browser/notification_service.h" |
| 20 #include "content/public/browser/notification_source.h" | 20 #include "content/public/browser/notification_source.h" |
| 21 #include "content/public/browser/notification_types.h" | 21 #include "content/public/browser/notification_types.h" |
| 22 #include "content/public/browser/render_view_host.h" | 22 #include "content/public/browser/render_view_host.h" |
| 23 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
| 24 #include "content/public/browser/web_contents_delegate.h" | 24 #include "content/public/browser/web_contents_delegate.h" |
| 25 | 25 |
| 26 #if defined (ENABLE_EXTENSIONS) |
| 27 #include "extensions/browser/extension_registry.h" |
| 28 #include "extensions/common/constants.h" |
| 29 #endif // (ENABLE_EXTENSIONS) |
| 30 |
| 26 namespace chrome { | 31 namespace chrome { |
| 27 | 32 |
| 28 | |
| 29 //////////////////////////////////////////////////////////////////////////////// | 33 //////////////////////////////////////////////////////////////////////////////// |
| 30 // DetachedWebContentsDelegate will delete web contents when they close. | 34 // DetachedWebContentsDelegate will delete web contents when they close. |
| 31 class FastUnloadController::DetachedWebContentsDelegate | 35 class FastUnloadController::DetachedWebContentsDelegate |
| 32 : public content::WebContentsDelegate { | 36 : public content::WebContentsDelegate { |
| 33 public: | 37 public: |
| 34 DetachedWebContentsDelegate() { } | 38 DetachedWebContentsDelegate() { } |
| 35 ~DetachedWebContentsDelegate() override {} | 39 ~DetachedWebContentsDelegate() override {} |
| 36 | 40 |
| 37 private: | 41 private: |
| 38 // WebContentsDelegate implementation. | 42 // WebContentsDelegate implementation. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 | 79 |
| 76 bool FastUnloadController::ShouldRunUnloadEventsHelper( | 80 bool FastUnloadController::ShouldRunUnloadEventsHelper( |
| 77 content::WebContents* contents) { | 81 content::WebContents* contents) { |
| 78 // If |contents| is being inspected, devtools needs to intercept beforeunload | 82 // If |contents| is being inspected, devtools needs to intercept beforeunload |
| 79 // events. | 83 // events. |
| 80 return DevToolsWindow::GetInstanceForInspectedWebContents(contents) != NULL; | 84 return DevToolsWindow::GetInstanceForInspectedWebContents(contents) != NULL; |
| 81 } | 85 } |
| 82 | 86 |
| 83 bool FastUnloadController::RunUnloadEventsHelper( | 87 bool FastUnloadController::RunUnloadEventsHelper( |
| 84 content::WebContents* contents) { | 88 content::WebContents* contents) { |
| 89 #if defined (ENABLE_EXTENSIONS) |
| 90 // Don't run for extensions that are disabled or uninstalled; the tabs will |
| 91 // be killed if they make any network requests, and the extension shouldn't |
| 92 // be doing any work if it's removed. |
| 93 GURL url = contents->GetLastCommittedURL(); |
| 94 if (url.SchemeIs(extensions::kExtensionScheme) && |
| 95 !extensions::ExtensionRegistry::Get(browser_->profile()) |
| 96 ->enabled_extensions() |
| 97 .GetExtensionOrAppByURL(url)) { |
| 98 return false; |
| 99 } |
| 100 #endif // (ENABLE_EXTENSIONS) |
| 101 |
| 85 // Special case for when we quit an application. The Devtools window can | 102 // Special case for when we quit an application. The Devtools window can |
| 86 // close if it's beforeunload event has already fired which will happen due | 103 // close if it's beforeunload event has already fired which will happen due |
| 87 // to the interception of it's content's beforeunload. | 104 // to the interception of it's content's beforeunload. |
| 88 if (browser_->is_devtools() && | 105 if (browser_->is_devtools() && |
| 89 DevToolsWindow::HasFiredBeforeUnloadEventForDevToolsBrowser(browser_)) | 106 DevToolsWindow::HasFiredBeforeUnloadEventForDevToolsBrowser(browser_)) |
| 90 return false; | 107 return false; |
| 91 | 108 |
| 92 // If there's a devtools window attached to |contents|, | 109 // If there's a devtools window attached to |contents|, |
| 93 // we would like devtools to call its own beforeunload handlers first, | 110 // we would like devtools to call its own beforeunload handlers first, |
| 94 // and then call beforeunload handlers for |contents|. | 111 // and then call beforeunload handlers for |contents|. |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 } | 490 } |
| 474 } | 491 } |
| 475 | 492 |
| 476 void FastUnloadController::PostTaskForProcessPendingTabs() { | 493 void FastUnloadController::PostTaskForProcessPendingTabs() { |
| 477 base::ThreadTaskRunnerHandle::Get()->PostTask( | 494 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 478 FROM_HERE, base::Bind(&FastUnloadController::ProcessPendingTabs, | 495 FROM_HERE, base::Bind(&FastUnloadController::ProcessPendingTabs, |
| 479 weak_factory_.GetWeakPtr())); | 496 weak_factory_.GetWeakPtr())); |
| 480 } | 497 } |
| 481 | 498 |
| 482 } // namespace chrome | 499 } // namespace chrome |
| OLD | NEW |