Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(545)

Side by Side Diff: chrome/browser/ui/unload_controller.cc

Issue 2355183002: [Extensions] Don't run unload listeners when an extension is removed (Closed)
Patch Set: Remove terminated extensions reference Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/fast_unload_controller.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/ui/unload_controller.h" 5 #include "chrome/browser/ui/unload_controller.h"
6 6
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "base/single_thread_task_runner.h" 8 #include "base/single_thread_task_runner.h"
9 #include "base/threading/thread_task_runner_handle.h" 9 #include "base/threading/thread_task_runner_handle.h"
10 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/browser/devtools/devtools_window.h" 11 #include "chrome/browser/devtools/devtools_window.h"
12 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_tabstrip.h" 13 #include "chrome/browser/ui/browser_tabstrip.h"
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" 14 #include "chrome/browser/ui/tabs/tab_strip_model.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" 16 #include "content/public/browser/notification_source.h"
17 #include "content/public/browser/notification_types.h" 17 #include "content/public/browser/notification_types.h"
18 #include "content/public/browser/render_view_host.h" 18 #include "content/public/browser/render_view_host.h"
19 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
20 20
21 #if defined (ENABLE_EXTENSIONS)
22 #include "extensions/browser/extension_registry.h"
23 #include "extensions/common/constants.h"
24 #endif // (ENABLE_EXTENSIONS)
25
21 namespace chrome { 26 namespace chrome {
22 27
23 //////////////////////////////////////////////////////////////////////////////// 28 ////////////////////////////////////////////////////////////////////////////////
24 // UnloadController, public: 29 // UnloadController, public:
25 30
26 UnloadController::UnloadController(Browser* browser) 31 UnloadController::UnloadController(Browser* browser)
27 : browser_(browser), 32 : browser_(browser),
28 is_attempting_to_close_browser_(false), 33 is_attempting_to_close_browser_(false),
29 weak_factory_(this) { 34 weak_factory_(this) {
30 browser_->tab_strip_model()->AddObserver(this); 35 browser_->tab_strip_model()->AddObserver(this);
(...skipping 13 matching lines...) Expand all
44 } 49 }
45 50
46 bool UnloadController::ShouldRunUnloadEventsHelper( 51 bool UnloadController::ShouldRunUnloadEventsHelper(
47 content::WebContents* contents) { 52 content::WebContents* contents) {
48 // If |contents| is being inspected, devtools needs to intercept beforeunload 53 // If |contents| is being inspected, devtools needs to intercept beforeunload
49 // events. 54 // events.
50 return DevToolsWindow::GetInstanceForInspectedWebContents(contents) != NULL; 55 return DevToolsWindow::GetInstanceForInspectedWebContents(contents) != NULL;
51 } 56 }
52 57
53 bool UnloadController::RunUnloadEventsHelper(content::WebContents* contents) { 58 bool UnloadController::RunUnloadEventsHelper(content::WebContents* contents) {
59 #if defined (ENABLE_EXTENSIONS)
60 // Don't run for extensions that are disabled or uninstalled; the tabs will
61 // be killed if they make any network requests, and the extension shouldn't
62 // be doing any work if it's removed.
63 GURL url = contents->GetLastCommittedURL();
64 if (url.SchemeIs(extensions::kExtensionScheme) &&
65 !extensions::ExtensionRegistry::Get(browser_->profile())
66 ->enabled_extensions()
67 .GetExtensionOrAppByURL(url)) {
68 return false;
69 }
70 #endif // (ENABLE_EXTENSIONS)
71
54 // Special case for when we quit an application. The devtools window can 72 // Special case for when we quit an application. The devtools window can
55 // close if it's beforeunload event has already fired which will happen due 73 // close if it's beforeunload event has already fired which will happen due
56 // to the interception of it's content's beforeunload. 74 // to the interception of it's content's beforeunload.
57 if (browser_->is_devtools() && 75 if (browser_->is_devtools() &&
58 DevToolsWindow::HasFiredBeforeUnloadEventForDevToolsBrowser(browser_)) 76 DevToolsWindow::HasFiredBeforeUnloadEventForDevToolsBrowser(browser_))
59 return false; 77 return false;
60 78
61 // If there's a devtools window attached to |contents|, 79 // If there's a devtools window attached to |contents|,
62 // we would like devtools to call its own beforeunload handlers first, 80 // we would like devtools to call its own beforeunload handlers first,
63 // and then call beforeunload handlers for |contents|. 81 // and then call beforeunload handlers for |contents|.
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 ProcessPendingTabs(); 379 ProcessPendingTabs();
362 } else { 380 } else {
363 base::ThreadTaskRunnerHandle::Get()->PostTask( 381 base::ThreadTaskRunnerHandle::Get()->PostTask(
364 FROM_HERE, base::Bind(&UnloadController::ProcessPendingTabs, 382 FROM_HERE, base::Bind(&UnloadController::ProcessPendingTabs,
365 weak_factory_.GetWeakPtr())); 383 weak_factory_.GetWeakPtr()));
366 } 384 }
367 } 385 }
368 } 386 }
369 387
370 } // namespace chrome 388 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/ui/fast_unload_controller.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698