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

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

Issue 5581010: Merge 68646 - Makes instant run before unload listeners.... (Closed) Base URL: svn://svn.chromium.org/chrome/branches/597/src/
Patch Set: Created 10 years 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/browser.h ('k') | chrome/chrome_browser.gypi » ('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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/browser.h" 5 #include "chrome/browser/ui/browser.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <shellapi.h> 8 #include <shellapi.h>
9 #include <windows.h> 9 #include <windows.h>
10 #endif // OS_WIN 10 #endif // OS_WIN
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 #include "chrome/browser/extensions/extension_prefs.h" 53 #include "chrome/browser/extensions/extension_prefs.h"
54 #include "chrome/browser/extensions/extension_tabs_module.h" 54 #include "chrome/browser/extensions/extension_tabs_module.h"
55 #include "chrome/browser/extensions/extensions_service.h" 55 #include "chrome/browser/extensions/extensions_service.h"
56 #include "chrome/browser/find_bar.h" 56 #include "chrome/browser/find_bar.h"
57 #include "chrome/browser/find_bar_controller.h" 57 #include "chrome/browser/find_bar_controller.h"
58 #include "chrome/browser/first_run/first_run.h" 58 #include "chrome/browser/first_run/first_run.h"
59 #include "chrome/browser/google/google_url_tracker.h" 59 #include "chrome/browser/google/google_url_tracker.h"
60 #include "chrome/browser/google/google_util.h" 60 #include "chrome/browser/google/google_util.h"
61 #include "chrome/browser/host_zoom_map.h" 61 #include "chrome/browser/host_zoom_map.h"
62 #include "chrome/browser/instant/instant_controller.h" 62 #include "chrome/browser/instant/instant_controller.h"
63 #include "chrome/browser/instant/instant_unload_handler.h"
63 #include "chrome/browser/location_bar.h" 64 #include "chrome/browser/location_bar.h"
64 #include "chrome/browser/metrics/user_metrics.h" 65 #include "chrome/browser/metrics/user_metrics.h"
65 #include "chrome/browser/net/browser_url_util.h" 66 #include "chrome/browser/net/browser_url_util.h"
66 #include "chrome/browser/net/url_fixer_upper.h" 67 #include "chrome/browser/net/url_fixer_upper.h"
67 #include "chrome/browser/options_window.h" 68 #include "chrome/browser/options_window.h"
68 #include "chrome/browser/platform_util.h" 69 #include "chrome/browser/platform_util.h"
69 #include "chrome/browser/prefs/pref_service.h" 70 #include "chrome/browser/prefs/pref_service.h"
70 #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h" 71 #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h"
71 #include "chrome/browser/profile.h" 72 #include "chrome/browser/profile.h"
72 #include "chrome/browser/renderer_host/render_view_host.h" 73 #include "chrome/browser/renderer_host/render_view_host.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 177
177 const char kHashMark[] = "#"; 178 const char kHashMark[] = "#";
178 179
179 #if defined(OS_CHROMEOS) 180 #if defined(OS_CHROMEOS)
180 // If a popup window is bigger than this fraction of the screen on chrome os, 181 // If a popup window is bigger than this fraction of the screen on chrome os,
181 // turn it into a tab 182 // turn it into a tab
182 const float kPopupMaxWidthFactor = 0.5; 183 const float kPopupMaxWidthFactor = 0.5;
183 const float kPopupMaxHeightFactor = 0.6; 184 const float kPopupMaxHeightFactor = 0.6;
184 #endif 185 #endif
185 186
186 // Returns true if the specified TabContents has unload listeners registered.
187 bool TabHasUnloadListener(TabContents* contents) {
188 return contents->notify_disconnection() &&
189 !contents->showing_interstitial_page() &&
190 !contents->render_view_host()->SuddenTerminationAllowed();
191 }
192
193 } // namespace 187 } // namespace
194 188
195 extern bool g_log_bug53991; 189 extern bool g_log_bug53991;
196 190
197 /////////////////////////////////////////////////////////////////////////////// 191 ///////////////////////////////////////////////////////////////////////////////
198 // Browser, Constructors, Creation, Showing: 192 // Browser, Constructors, Creation, Showing:
199 193
200 Browser::Browser(Type type, Profile* profile) 194 Browser::Browser(Type type, Profile* profile)
201 : type_(type), 195 : type_(type),
202 profile_(profile), 196 profile_(profile),
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 if (!CanCloseWithInProgressDownloads()) 807 if (!CanCloseWithInProgressDownloads())
814 return false; 808 return false;
815 809
816 if (HasCompletedUnloadProcessing()) 810 if (HasCompletedUnloadProcessing())
817 return IsClosingPermitted(); 811 return IsClosingPermitted();
818 812
819 is_attempting_to_close_browser_ = true; 813 is_attempting_to_close_browser_ = true;
820 814
821 for (int i = 0; i < tab_count(); ++i) { 815 for (int i = 0; i < tab_count(); ++i) {
822 TabContents* contents = GetTabContentsAt(i); 816 TabContents* contents = GetTabContentsAt(i);
823 if (TabHasUnloadListener(contents)) 817 if (contents->NeedToFireBeforeUnload())
824 tabs_needing_before_unload_fired_.insert(contents); 818 tabs_needing_before_unload_fired_.insert(contents);
825 } 819 }
826 820
827 if (tabs_needing_before_unload_fired_.empty()) 821 if (tabs_needing_before_unload_fired_.empty())
828 return IsClosingPermitted(); 822 return IsClosingPermitted();
829 823
830 ProcessPendingTabs(); 824 ProcessPendingTabs();
831 return false; 825 return false;
832 } 826 }
833 827
(...skipping 1193 matching lines...) Expand 10 before | Expand all | Expand 10 after
2027 prefs->RegisterBooleanPref(prefs::kDevToolsDisabled, false); 2021 prefs->RegisterBooleanPref(prefs::kDevToolsDisabled, false);
2028 prefs->RegisterRealPref(prefs::kDefaultZoomLevel, 0.0); 2022 prefs->RegisterRealPref(prefs::kDefaultZoomLevel, 0.0);
2029 } 2023 }
2030 2024
2031 // static 2025 // static
2032 bool Browser::RunUnloadEventsHelper(TabContents* contents) { 2026 bool Browser::RunUnloadEventsHelper(TabContents* contents) {
2033 // If the TabContents is not connected yet, then there's no unload 2027 // If the TabContents is not connected yet, then there's no unload
2034 // handler we can fire even if the TabContents has an unload listener. 2028 // handler we can fire even if the TabContents has an unload listener.
2035 // One case where we hit this is in a tab that has an infinite loop 2029 // One case where we hit this is in a tab that has an infinite loop
2036 // before load. 2030 // before load.
2037 if (TabHasUnloadListener(contents)) { 2031 if (contents->NeedToFireBeforeUnload()) {
2038 // If the page has unload listeners, then we tell the renderer to fire 2032 // If the page has unload listeners, then we tell the renderer to fire
2039 // them. Once they have fired, we'll get a message back saying whether 2033 // them. Once they have fired, we'll get a message back saying whether
2040 // to proceed closing the page or not, which sends us back to this method 2034 // to proceed closing the page or not, which sends us back to this method
2041 // with the HasUnloadListener bit cleared. 2035 // with the NeedToFireBeforeUnload bit cleared.
2042 contents->render_view_host()->FirePageBeforeUnload(false); 2036 contents->render_view_host()->FirePageBeforeUnload(false);
2043 return true; 2037 return true;
2044 } 2038 }
2045 return false; 2039 return false;
2046 } 2040 }
2047 2041
2048 // static 2042 // static
2049 Browser* Browser::GetBrowserForController( 2043 Browser* Browser::GetBrowserForController(
2050 const NavigationController* controller, int* index_result) { 2044 const NavigationController* controller, int* index_result) {
2051 BrowserList::const_iterator it; 2045 BrowserList::const_iterator it;
(...skipping 1254 matching lines...) Expand 10 before | Expand all | Expand 10 after
3306 case NotificationType::PREF_CHANGED: { 3300 case NotificationType::PREF_CHANGED: {
3307 const std::string& pref_name = *Details<std::string>(details).ptr(); 3301 const std::string& pref_name = *Details<std::string>(details).ptr();
3308 if (pref_name == prefs::kUseVerticalTabs) { 3302 if (pref_name == prefs::kUseVerticalTabs) {
3309 UseVerticalTabsChanged(); 3303 UseVerticalTabsChanged();
3310 } else if (pref_name == prefs::kPrintingEnabled) { 3304 } else if (pref_name == prefs::kPrintingEnabled) {
3311 UpdatePrintingState(0); 3305 UpdatePrintingState(0);
3312 } else if (pref_name == prefs::kInstantEnabled) { 3306 } else if (pref_name == prefs::kInstantEnabled) {
3313 if (!InstantController::IsEnabled(profile())) { 3307 if (!InstantController::IsEnabled(profile())) {
3314 if (instant()) { 3308 if (instant()) {
3315 instant()->DestroyPreviewContents(); 3309 instant()->DestroyPreviewContents();
3316 instant_.reset(NULL); 3310 instant_.reset();
3311 instant_unload_handler_.reset();
3317 } 3312 }
3318 } else { 3313 } else {
3319 CreateInstantIfNecessary(); 3314 CreateInstantIfNecessary();
3320 } 3315 }
3321 } else if (pref_name == prefs::kDevToolsDisabled) { 3316 } else if (pref_name == prefs::kDevToolsDisabled) {
3322 UpdateCommandsForDevTools(); 3317 UpdateCommandsForDevTools();
3323 if (dev_tools_disabled_.GetValue()) 3318 if (dev_tools_disabled_.GetValue())
3324 g_browser_process->devtools_manager()->CloseAllClientHosts(); 3319 g_browser_process->devtools_manager()->CloseAllClientHosts();
3325 } else { 3320 } else {
3326 NOTREACHED(); 3321 NOTREACHED();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
3366 } 3361 }
3367 3362
3368 void Browser::CommitInstant(TabContentsWrapper* preview_contents) { 3363 void Browser::CommitInstant(TabContentsWrapper* preview_contents) {
3369 TabContentsWrapper* tab_contents = instant_->tab_contents(); 3364 TabContentsWrapper* tab_contents = instant_->tab_contents();
3370 int index = 3365 int index =
3371 tab_handler_->GetTabStripModel()->GetIndexOfTabContents(tab_contents); 3366 tab_handler_->GetTabStripModel()->GetIndexOfTabContents(tab_contents);
3372 DCHECK_NE(TabStripModel::kNoTab, index); 3367 DCHECK_NE(TabStripModel::kNoTab, index);
3373 preview_contents->controller().CopyStateFromAndPrune( 3368 preview_contents->controller().CopyStateFromAndPrune(
3374 &tab_contents->controller()); 3369 &tab_contents->controller());
3375 // TabStripModel takes ownership of preview_contents. 3370 // TabStripModel takes ownership of preview_contents.
3376 tab_handler_->GetTabStripModel()->ReplaceTabContentsAt( 3371 TabContentsWrapper* old_contents =
3377 index, preview_contents); 3372 tab_handler_->GetTabStripModel()->ReplaceTabContentsAt(
3373 index, preview_contents);
3374 // InstantUnloadHandler takes ownership of old_contents.
3375 instant_unload_handler_->RunUnloadListenersOrDestroy(old_contents, index);
3378 } 3376 }
3379 3377
3380 void Browser::SetSuggestedText(const string16& text) { 3378 void Browser::SetSuggestedText(const string16& text) {
3381 window()->GetLocationBar()->SetSuggestedText(text); 3379 window()->GetLocationBar()->SetSuggestedText(text);
3382 } 3380 }
3383 3381
3384 gfx::Rect Browser::GetInstantBounds() { 3382 gfx::Rect Browser::GetInstantBounds() {
3385 return window()->GetInstantBounds(); 3383 return window()->GetInstantBounds();
3386 } 3384 }
3387 3385
(...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after
4134 // to handle them. If you hit this NOTREACHED file a bug and I'll (sky) add 4132 // to handle them. If you hit this NOTREACHED file a bug and I'll (sky) add
4135 // support for the new disposition. 4133 // support for the new disposition.
4136 NOTREACHED(); 4134 NOTREACHED();
4137 return false; 4135 return false;
4138 } 4136 }
4139 4137
4140 void Browser::CreateInstantIfNecessary() { 4138 void Browser::CreateInstantIfNecessary() {
4141 if (type() == TYPE_NORMAL && InstantController::IsEnabled(profile()) && 4139 if (type() == TYPE_NORMAL && InstantController::IsEnabled(profile()) &&
4142 !profile()->IsOffTheRecord()) { 4140 !profile()->IsOffTheRecord()) {
4143 instant_.reset(new InstantController(profile_, this)); 4141 instant_.reset(new InstantController(profile_, this));
4142 instant_unload_handler_.reset(new InstantUnloadHandler(this));
4144 } 4143 }
4145 } 4144 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698