| OLD | NEW | 
|---|
| 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  Loading... | 
| 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  Loading... | 
| 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  Loading... | 
| 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 1197 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2031   prefs->RegisterBooleanPref(prefs::kDevToolsDisabled, false); | 2025   prefs->RegisterBooleanPref(prefs::kDevToolsDisabled, false); | 
| 2032   prefs->RegisterRealPref(prefs::kDefaultZoomLevel, 0.0); | 2026   prefs->RegisterRealPref(prefs::kDefaultZoomLevel, 0.0); | 
| 2033 } | 2027 } | 
| 2034 | 2028 | 
| 2035 // static | 2029 // static | 
| 2036 bool Browser::RunUnloadEventsHelper(TabContents* contents) { | 2030 bool Browser::RunUnloadEventsHelper(TabContents* contents) { | 
| 2037   // If the TabContents is not connected yet, then there's no unload | 2031   // If the TabContents is not connected yet, then there's no unload | 
| 2038   // handler we can fire even if the TabContents has an unload listener. | 2032   // handler we can fire even if the TabContents has an unload listener. | 
| 2039   // One case where we hit this is in a tab that has an infinite loop | 2033   // One case where we hit this is in a tab that has an infinite loop | 
| 2040   // before load. | 2034   // before load. | 
| 2041   if (TabHasUnloadListener(contents)) { | 2035   if (contents->NeedToFireBeforeUnload()) { | 
| 2042     // If the page has unload listeners, then we tell the renderer to fire | 2036     // If the page has unload listeners, then we tell the renderer to fire | 
| 2043     // them. Once they have fired, we'll get a message back saying whether | 2037     // them. Once they have fired, we'll get a message back saying whether | 
| 2044     // to proceed closing the page or not, which sends us back to this method | 2038     // to proceed closing the page or not, which sends us back to this method | 
| 2045     // with the HasUnloadListener bit cleared. | 2039     // with the NeedToFireBeforeUnload bit cleared. | 
| 2046     contents->render_view_host()->FirePageBeforeUnload(false); | 2040     contents->render_view_host()->FirePageBeforeUnload(false); | 
| 2047     return true; | 2041     return true; | 
| 2048   } | 2042   } | 
| 2049   return false; | 2043   return false; | 
| 2050 } | 2044 } | 
| 2051 | 2045 | 
| 2052 // static | 2046 // static | 
| 2053 Browser* Browser::GetBrowserForController( | 2047 Browser* Browser::GetBrowserForController( | 
| 2054     const NavigationController* controller, int* index_result) { | 2048     const NavigationController* controller, int* index_result) { | 
| 2055   BrowserList::const_iterator it; | 2049   BrowserList::const_iterator it; | 
| (...skipping 1255 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 3311     case NotificationType::PREF_CHANGED: { | 3305     case NotificationType::PREF_CHANGED: { | 
| 3312       const std::string& pref_name = *Details<std::string>(details).ptr(); | 3306       const std::string& pref_name = *Details<std::string>(details).ptr(); | 
| 3313       if (pref_name == prefs::kUseVerticalTabs) { | 3307       if (pref_name == prefs::kUseVerticalTabs) { | 
| 3314         UseVerticalTabsChanged(); | 3308         UseVerticalTabsChanged(); | 
| 3315       } else if (pref_name == prefs::kPrintingEnabled) { | 3309       } else if (pref_name == prefs::kPrintingEnabled) { | 
| 3316         UpdatePrintingState(0); | 3310         UpdatePrintingState(0); | 
| 3317       } else if (pref_name == prefs::kInstantEnabled) { | 3311       } else if (pref_name == prefs::kInstantEnabled) { | 
| 3318         if (!InstantController::IsEnabled(profile())) { | 3312         if (!InstantController::IsEnabled(profile())) { | 
| 3319           if (instant()) { | 3313           if (instant()) { | 
| 3320             instant()->DestroyPreviewContents(); | 3314             instant()->DestroyPreviewContents(); | 
| 3321             instant_.reset(NULL); | 3315             instant_.reset(); | 
|  | 3316             instant_unload_handler_.reset(); | 
| 3322           } | 3317           } | 
| 3323         } else { | 3318         } else { | 
| 3324           CreateInstantIfNecessary(); | 3319           CreateInstantIfNecessary(); | 
| 3325         } | 3320         } | 
| 3326       } else if (pref_name == prefs::kDevToolsDisabled) { | 3321       } else if (pref_name == prefs::kDevToolsDisabled) { | 
| 3327         UpdateCommandsForDevTools(); | 3322         UpdateCommandsForDevTools(); | 
| 3328         if (dev_tools_disabled_.GetValue()) | 3323         if (dev_tools_disabled_.GetValue()) | 
| 3329           g_browser_process->devtools_manager()->CloseAllClientHosts(); | 3324           g_browser_process->devtools_manager()->CloseAllClientHosts(); | 
| 3330       } else { | 3325       } else { | 
| 3331         NOTREACHED(); | 3326         NOTREACHED(); | 
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 3371 } | 3366 } | 
| 3372 | 3367 | 
| 3373 void Browser::CommitInstant(TabContentsWrapper* preview_contents) { | 3368 void Browser::CommitInstant(TabContentsWrapper* preview_contents) { | 
| 3374   TabContentsWrapper* tab_contents = instant_->tab_contents(); | 3369   TabContentsWrapper* tab_contents = instant_->tab_contents(); | 
| 3375   int index = | 3370   int index = | 
| 3376       tab_handler_->GetTabStripModel()->GetIndexOfTabContents(tab_contents); | 3371       tab_handler_->GetTabStripModel()->GetIndexOfTabContents(tab_contents); | 
| 3377   DCHECK_NE(TabStripModel::kNoTab, index); | 3372   DCHECK_NE(TabStripModel::kNoTab, index); | 
| 3378   preview_contents->controller().CopyStateFromAndPrune( | 3373   preview_contents->controller().CopyStateFromAndPrune( | 
| 3379       &tab_contents->controller()); | 3374       &tab_contents->controller()); | 
| 3380   // TabStripModel takes ownership of preview_contents. | 3375   // TabStripModel takes ownership of preview_contents. | 
| 3381   tab_handler_->GetTabStripModel()->ReplaceTabContentsAt( | 3376   TabContentsWrapper* old_contents = | 
| 3382       index, preview_contents); | 3377       tab_handler_->GetTabStripModel()->ReplaceTabContentsAt( | 
|  | 3378           index, preview_contents); | 
|  | 3379   // InstantUnloadHandler takes ownership of old_contents. | 
|  | 3380   instant_unload_handler_->Own(old_contents, index); | 
| 3383 } | 3381 } | 
| 3384 | 3382 | 
| 3385 void Browser::SetSuggestedText(const string16& text) { | 3383 void Browser::SetSuggestedText(const string16& text) { | 
| 3386   window()->GetLocationBar()->SetSuggestedText(text); | 3384   window()->GetLocationBar()->SetSuggestedText(text); | 
| 3387 } | 3385 } | 
| 3388 | 3386 | 
| 3389 gfx::Rect Browser::GetInstantBounds() { | 3387 gfx::Rect Browser::GetInstantBounds() { | 
| 3390   return window()->GetInstantBounds(); | 3388   return window()->GetInstantBounds(); | 
| 3391 } | 3389 } | 
| 3392 | 3390 | 
| (...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 4140   // to handle them. If you hit this NOTREACHED file a bug and I'll (sky) add | 4138   // to handle them. If you hit this NOTREACHED file a bug and I'll (sky) add | 
| 4141   // support for the new disposition. | 4139   // support for the new disposition. | 
| 4142   NOTREACHED(); | 4140   NOTREACHED(); | 
| 4143   return false; | 4141   return false; | 
| 4144 } | 4142 } | 
| 4145 | 4143 | 
| 4146 void Browser::CreateInstantIfNecessary() { | 4144 void Browser::CreateInstantIfNecessary() { | 
| 4147   if (type() == TYPE_NORMAL && InstantController::IsEnabled(profile()) && | 4145   if (type() == TYPE_NORMAL && InstantController::IsEnabled(profile()) && | 
| 4148       !profile()->IsOffTheRecord()) { | 4146       !profile()->IsOffTheRecord()) { | 
| 4149     instant_.reset(new InstantController(profile_, this)); | 4147     instant_.reset(new InstantController(profile_, this)); | 
|  | 4148     instant_unload_handler_.reset(new InstantUnloadHandler(this)); | 
| 4150   } | 4149   } | 
| 4151 } | 4150 } | 
| OLD | NEW | 
|---|