Chromium Code Reviews| 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 #include "extensions/browser/extension_registry.h" | |
| 26 #include "extensions/common/constants.h" | |
| 25 | 27 |
| 26 namespace chrome { | 28 namespace chrome { |
| 27 | 29 |
| 28 | |
| 29 //////////////////////////////////////////////////////////////////////////////// | 30 //////////////////////////////////////////////////////////////////////////////// |
| 30 // DetachedWebContentsDelegate will delete web contents when they close. | 31 // DetachedWebContentsDelegate will delete web contents when they close. |
| 31 class FastUnloadController::DetachedWebContentsDelegate | 32 class FastUnloadController::DetachedWebContentsDelegate |
| 32 : public content::WebContentsDelegate { | 33 : public content::WebContentsDelegate { |
| 33 public: | 34 public: |
| 34 DetachedWebContentsDelegate() { } | 35 DetachedWebContentsDelegate() { } |
| 35 ~DetachedWebContentsDelegate() override {} | 36 ~DetachedWebContentsDelegate() override {} |
| 36 | 37 |
| 37 private: | 38 private: |
| 38 // WebContentsDelegate implementation. | 39 // WebContentsDelegate implementation. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 | 76 |
| 76 bool FastUnloadController::ShouldRunUnloadEventsHelper( | 77 bool FastUnloadController::ShouldRunUnloadEventsHelper( |
| 77 content::WebContents* contents) { | 78 content::WebContents* contents) { |
| 78 // If |contents| is being inspected, devtools needs to intercept beforeunload | 79 // If |contents| is being inspected, devtools needs to intercept beforeunload |
| 79 // events. | 80 // events. |
| 80 return DevToolsWindow::GetInstanceForInspectedWebContents(contents) != NULL; | 81 return DevToolsWindow::GetInstanceForInspectedWebContents(contents) != NULL; |
| 81 } | 82 } |
| 82 | 83 |
| 83 bool FastUnloadController::RunUnloadEventsHelper( | 84 bool FastUnloadController::RunUnloadEventsHelper( |
| 84 content::WebContents* contents) { | 85 content::WebContents* contents) { |
| 86 GURL url = contents->GetLastCommittedURL(); | |
|
Charlie Reis
2016/09/21 18:29:33
Let's add a comment, like: Don't run unload for ex
Devlin
2016/09/22 00:35:21
Done.
| |
| 87 if (url.SchemeIs(extensions::kExtensionScheme) && | |
| 88 !extensions::ExtensionRegistry::Get(browser_->profile()) | |
|
Charlie Reis
2016/09/21 18:29:33
You would know better than I do, but does this nee
Devlin
2016/09/22 00:35:21
Probably should, yes. Added. An OWNER here can d
| |
| 89 ->enabled_extensions() | |
| 90 .GetExtensionOrAppByURL(url)) { | |
| 91 return false; | |
| 92 } | |
| 93 | |
| 85 // Special case for when we quit an application. The Devtools window can | 94 // 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 | 95 // close if it's beforeunload event has already fired which will happen due |
| 87 // to the interception of it's content's beforeunload. | 96 // to the interception of it's content's beforeunload. |
| 88 if (browser_->is_devtools() && | 97 if (browser_->is_devtools() && |
| 89 DevToolsWindow::HasFiredBeforeUnloadEventForDevToolsBrowser(browser_)) | 98 DevToolsWindow::HasFiredBeforeUnloadEventForDevToolsBrowser(browser_)) |
| 90 return false; | 99 return false; |
| 91 | 100 |
| 92 // If there's a devtools window attached to |contents|, | 101 // If there's a devtools window attached to |contents|, |
| 93 // we would like devtools to call its own beforeunload handlers first, | 102 // we would like devtools to call its own beforeunload handlers first, |
| 94 // and then call beforeunload handlers for |contents|. | 103 // and then call beforeunload handlers for |contents|. |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 472 } | 481 } |
| 473 } | 482 } |
| 474 | 483 |
| 475 void FastUnloadController::PostTaskForProcessPendingTabs() { | 484 void FastUnloadController::PostTaskForProcessPendingTabs() { |
| 476 base::ThreadTaskRunnerHandle::Get()->PostTask( | 485 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 477 FROM_HERE, base::Bind(&FastUnloadController::ProcessPendingTabs, | 486 FROM_HERE, base::Bind(&FastUnloadController::ProcessPendingTabs, |
| 478 weak_factory_.GetWeakPtr())); | 487 weak_factory_.GetWeakPtr())); |
| 479 } | 488 } |
| 480 | 489 |
| 481 } // namespace chrome | 490 } // namespace chrome |
| OLD | NEW |