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

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: ready Created 4 years, 3 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
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 #include "extensions/browser/extension_registry.h"
21 #include "extensions/common/constants.h"
20 22
21 namespace chrome { 23 namespace chrome {
22 24
23 //////////////////////////////////////////////////////////////////////////////// 25 ////////////////////////////////////////////////////////////////////////////////
24 // UnloadController, public: 26 // UnloadController, public:
25 27
26 UnloadController::UnloadController(Browser* browser) 28 UnloadController::UnloadController(Browser* browser)
27 : browser_(browser), 29 : browser_(browser),
28 is_attempting_to_close_browser_(false), 30 is_attempting_to_close_browser_(false),
29 weak_factory_(this) { 31 weak_factory_(this) {
(...skipping 14 matching lines...) Expand all
44 } 46 }
45 47
46 bool UnloadController::ShouldRunUnloadEventsHelper( 48 bool UnloadController::ShouldRunUnloadEventsHelper(
47 content::WebContents* contents) { 49 content::WebContents* contents) {
48 // If |contents| is being inspected, devtools needs to intercept beforeunload 50 // If |contents| is being inspected, devtools needs to intercept beforeunload
49 // events. 51 // events.
50 return DevToolsWindow::GetInstanceForInspectedWebContents(contents) != NULL; 52 return DevToolsWindow::GetInstanceForInspectedWebContents(contents) != NULL;
51 } 53 }
52 54
53 bool UnloadController::RunUnloadEventsHelper(content::WebContents* contents) { 55 bool UnloadController::RunUnloadEventsHelper(content::WebContents* contents) {
56 GURL url = contents->GetLastCommittedURL();
Charlie Reis 2016/09/21 18:29:33 Same.
Devlin 2016/09/22 00:35:21 Done.
57 if (url.SchemeIs(extensions::kExtensionScheme) &&
58 !extensions::ExtensionRegistry::Get(browser_->profile())
59 ->enabled_extensions()
60 .GetExtensionOrAppByURL(url)) {
61 return false;
62 }
63
54 // Special case for when we quit an application. The devtools window can 64 // 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 65 // close if it's beforeunload event has already fired which will happen due
56 // to the interception of it's content's beforeunload. 66 // to the interception of it's content's beforeunload.
57 if (browser_->is_devtools() && 67 if (browser_->is_devtools() &&
58 DevToolsWindow::HasFiredBeforeUnloadEventForDevToolsBrowser(browser_)) 68 DevToolsWindow::HasFiredBeforeUnloadEventForDevToolsBrowser(browser_))
59 return false; 69 return false;
60 70
61 // If there's a devtools window attached to |contents|, 71 // If there's a devtools window attached to |contents|,
62 // we would like devtools to call its own beforeunload handlers first, 72 // we would like devtools to call its own beforeunload handlers first,
63 // and then call beforeunload handlers for |contents|. 73 // and then call beforeunload handlers for |contents|.
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 ProcessPendingTabs(); 370 ProcessPendingTabs();
361 } else { 371 } else {
362 base::ThreadTaskRunnerHandle::Get()->PostTask( 372 base::ThreadTaskRunnerHandle::Get()->PostTask(
363 FROM_HERE, base::Bind(&UnloadController::ProcessPendingTabs, 373 FROM_HERE, base::Bind(&UnloadController::ProcessPendingTabs,
364 weak_factory_.GetWeakPtr())); 374 weak_factory_.GetWeakPtr()));
365 } 375 }
366 } 376 }
367 } 377 }
368 378
369 } // namespace chrome 379 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698