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

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

Issue 5610005: Makes instant run before unload listeners. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome
Patch Set: Fix comments and reset session id appropriately 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 #include "chrome/browser/extensions/extension_disabled_infobar_delegate.h" 50 #include "chrome/browser/extensions/extension_disabled_infobar_delegate.h"
51 #include "chrome/browser/extensions/extension_host.h" 51 #include "chrome/browser/extensions/extension_host.h"
52 #include "chrome/browser/extensions/extension_prefs.h" 52 #include "chrome/browser/extensions/extension_prefs.h"
53 #include "chrome/browser/extensions/extension_tabs_module.h" 53 #include "chrome/browser/extensions/extension_tabs_module.h"
54 #include "chrome/browser/extensions/extensions_service.h" 54 #include "chrome/browser/extensions/extensions_service.h"
55 #include "chrome/browser/first_run/first_run.h" 55 #include "chrome/browser/first_run/first_run.h"
56 #include "chrome/browser/google/google_url_tracker.h" 56 #include "chrome/browser/google/google_url_tracker.h"
57 #include "chrome/browser/google/google_util.h" 57 #include "chrome/browser/google/google_util.h"
58 #include "chrome/browser/host_zoom_map.h" 58 #include "chrome/browser/host_zoom_map.h"
59 #include "chrome/browser/instant/instant_controller.h" 59 #include "chrome/browser/instant/instant_controller.h"
60 #include "chrome/browser/instant/instant_unload_handler.h"
60 #include "chrome/browser/metrics/user_metrics.h" 61 #include "chrome/browser/metrics/user_metrics.h"
61 #include "chrome/browser/net/browser_url_util.h" 62 #include "chrome/browser/net/browser_url_util.h"
62 #include "chrome/browser/net/url_fixer_upper.h" 63 #include "chrome/browser/net/url_fixer_upper.h"
63 #include "chrome/browser/platform_util.h" 64 #include "chrome/browser/platform_util.h"
64 #include "chrome/browser/prefs/pref_service.h" 65 #include "chrome/browser/prefs/pref_service.h"
65 #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h" 66 #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h"
66 #include "chrome/browser/profiles/profile.h" 67 #include "chrome/browser/profiles/profile.h"
67 #include "chrome/browser/renderer_host/render_view_host.h" 68 #include "chrome/browser/renderer_host/render_view_host.h"
68 #include "chrome/browser/renderer_host/site_instance.h" 69 #include "chrome/browser/renderer_host/site_instance.h"
69 #include "chrome/browser/sessions/session_service.h" 70 #include "chrome/browser/sessions/session_service.h"
(...skipping 106 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 629 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 if (!CanCloseWithInProgressDownloads()) 826 if (!CanCloseWithInProgressDownloads())
833 return false; 827 return false;
834 828
835 if (HasCompletedUnloadProcessing()) 829 if (HasCompletedUnloadProcessing())
836 return IsClosingPermitted(); 830 return IsClosingPermitted();
837 831
838 is_attempting_to_close_browser_ = true; 832 is_attempting_to_close_browser_ = true;
839 833
840 for (int i = 0; i < tab_count(); ++i) { 834 for (int i = 0; i < tab_count(); ++i) {
841 TabContents* contents = GetTabContentsAt(i); 835 TabContents* contents = GetTabContentsAt(i);
842 if (TabHasUnloadListener(contents)) 836 if (contents->NeedToFireBeforeUnload())
843 tabs_needing_before_unload_fired_.insert(contents); 837 tabs_needing_before_unload_fired_.insert(contents);
844 } 838 }
845 839
846 if (tabs_needing_before_unload_fired_.empty()) 840 if (tabs_needing_before_unload_fired_.empty())
847 return IsClosingPermitted(); 841 return IsClosingPermitted();
848 842
849 ProcessPendingTabs(); 843 ProcessPendingTabs();
850 return false; 844 return false;
851 } 845 }
852 846
(...skipping 1197 matching lines...) Expand 10 before | Expand all | Expand 10 after
2050 prefs->RegisterBooleanPref(prefs::kDevToolsDisabled, false); 2044 prefs->RegisterBooleanPref(prefs::kDevToolsDisabled, false);
2051 prefs->RegisterRealPref(prefs::kDefaultZoomLevel, 0.0); 2045 prefs->RegisterRealPref(prefs::kDefaultZoomLevel, 0.0);
2052 } 2046 }
2053 2047
2054 // static 2048 // static
2055 bool Browser::RunUnloadEventsHelper(TabContents* contents) { 2049 bool Browser::RunUnloadEventsHelper(TabContents* contents) {
2056 // If the TabContents is not connected yet, then there's no unload 2050 // If the TabContents is not connected yet, then there's no unload
2057 // handler we can fire even if the TabContents has an unload listener. 2051 // handler we can fire even if the TabContents has an unload listener.
2058 // One case where we hit this is in a tab that has an infinite loop 2052 // One case where we hit this is in a tab that has an infinite loop
2059 // before load. 2053 // before load.
2060 if (TabHasUnloadListener(contents)) { 2054 if (contents->NeedToFireBeforeUnload()) {
2061 // If the page has unload listeners, then we tell the renderer to fire 2055 // If the page has unload listeners, then we tell the renderer to fire
2062 // them. Once they have fired, we'll get a message back saying whether 2056 // them. Once they have fired, we'll get a message back saying whether
2063 // to proceed closing the page or not, which sends us back to this method 2057 // to proceed closing the page or not, which sends us back to this method
2064 // with the HasUnloadListener bit cleared. 2058 // with the NeedToFireBeforeUnload bit cleared.
2065 contents->render_view_host()->FirePageBeforeUnload(false); 2059 contents->render_view_host()->FirePageBeforeUnload(false);
2066 return true; 2060 return true;
2067 } 2061 }
2068 return false; 2062 return false;
2069 } 2063 }
2070 2064
2071 // static 2065 // static
2072 Browser* Browser::GetBrowserForController( 2066 Browser* Browser::GetBrowserForController(
2073 const NavigationController* controller, int* index_result) { 2067 const NavigationController* controller, int* index_result) {
2074 BrowserList::const_iterator it; 2068 BrowserList::const_iterator it;
(...skipping 1255 matching lines...) Expand 10 before | Expand all | Expand 10 after
3330 case NotificationType::PREF_CHANGED: { 3324 case NotificationType::PREF_CHANGED: {
3331 const std::string& pref_name = *Details<std::string>(details).ptr(); 3325 const std::string& pref_name = *Details<std::string>(details).ptr();
3332 if (pref_name == prefs::kUseVerticalTabs) { 3326 if (pref_name == prefs::kUseVerticalTabs) {
3333 UseVerticalTabsChanged(); 3327 UseVerticalTabsChanged();
3334 } else if (pref_name == prefs::kPrintingEnabled) { 3328 } else if (pref_name == prefs::kPrintingEnabled) {
3335 UpdatePrintingState(0); 3329 UpdatePrintingState(0);
3336 } else if (pref_name == prefs::kInstantEnabled) { 3330 } else if (pref_name == prefs::kInstantEnabled) {
3337 if (!InstantController::IsEnabled(profile())) { 3331 if (!InstantController::IsEnabled(profile())) {
3338 if (instant()) { 3332 if (instant()) {
3339 instant()->DestroyPreviewContents(); 3333 instant()->DestroyPreviewContents();
3340 instant_.reset(NULL); 3334 instant_.reset();
3335 instant_unload_handler_.reset();
3341 } 3336 }
3342 } else { 3337 } else {
3343 CreateInstantIfNecessary(); 3338 CreateInstantIfNecessary();
3344 } 3339 }
3345 } else if (pref_name == prefs::kDevToolsDisabled) { 3340 } else if (pref_name == prefs::kDevToolsDisabled) {
3346 UpdateCommandsForDevTools(); 3341 UpdateCommandsForDevTools();
3347 if (dev_tools_disabled_.GetValue()) 3342 if (dev_tools_disabled_.GetValue())
3348 g_browser_process->devtools_manager()->CloseAllClientHosts(); 3343 g_browser_process->devtools_manager()->CloseAllClientHosts();
3349 } else { 3344 } else {
3350 NOTREACHED(); 3345 NOTREACHED();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
3390 } 3385 }
3391 3386
3392 void Browser::CommitInstant(TabContentsWrapper* preview_contents) { 3387 void Browser::CommitInstant(TabContentsWrapper* preview_contents) {
3393 TabContentsWrapper* tab_contents = instant_->tab_contents(); 3388 TabContentsWrapper* tab_contents = instant_->tab_contents();
3394 int index = 3389 int index =
3395 tab_handler_->GetTabStripModel()->GetIndexOfTabContents(tab_contents); 3390 tab_handler_->GetTabStripModel()->GetIndexOfTabContents(tab_contents);
3396 DCHECK_NE(TabStripModel::kNoTab, index); 3391 DCHECK_NE(TabStripModel::kNoTab, index);
3397 preview_contents->controller().CopyStateFromAndPrune( 3392 preview_contents->controller().CopyStateFromAndPrune(
3398 &tab_contents->controller()); 3393 &tab_contents->controller());
3399 // TabStripModel takes ownership of preview_contents. 3394 // TabStripModel takes ownership of preview_contents.
3400 tab_handler_->GetTabStripModel()->ReplaceTabContentsAt( 3395 TabContentsWrapper* old_contents =
3401 index, preview_contents); 3396 tab_handler_->GetTabStripModel()->ReplaceTabContentsAt(
3397 index, preview_contents);
3398 // InstantUnloadHandler takes ownership of old_contents.
3399 instant_unload_handler_->RunUnloadListenersOrDestroy(old_contents, index);
3402 } 3400 }
3403 3401
3404 void Browser::SetSuggestedText(const string16& text) { 3402 void Browser::SetSuggestedText(const string16& text) {
3405 window()->GetLocationBar()->SetSuggestedText(text); 3403 window()->GetLocationBar()->SetSuggestedText(text);
3406 } 3404 }
3407 3405
3408 gfx::Rect Browser::GetInstantBounds() { 3406 gfx::Rect Browser::GetInstantBounds() {
3409 return window()->GetInstantBounds(); 3407 return window()->GetInstantBounds();
3410 } 3408 }
3411 3409
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after
4159 // to handle them. If you hit this NOTREACHED file a bug and I'll (sky) add 4157 // to handle them. If you hit this NOTREACHED file a bug and I'll (sky) add
4160 // support for the new disposition. 4158 // support for the new disposition.
4161 NOTREACHED(); 4159 NOTREACHED();
4162 return false; 4160 return false;
4163 } 4161 }
4164 4162
4165 void Browser::CreateInstantIfNecessary() { 4163 void Browser::CreateInstantIfNecessary() {
4166 if (type() == TYPE_NORMAL && InstantController::IsEnabled(profile()) && 4164 if (type() == TYPE_NORMAL && InstantController::IsEnabled(profile()) &&
4167 !profile()->IsOffTheRecord()) { 4165 !profile()->IsOffTheRecord()) {
4168 instant_.reset(new InstantController(profile_, this)); 4166 instant_.reset(new InstantController(profile_, this));
4167 instant_unload_handler_.reset(new InstantUnloadHandler(this));
4169 } 4168 }
4170 } 4169 }
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