OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <windows.h> | 8 #include <windows.h> |
9 #include <shellapi.h> | 9 #include <shellapi.h> |
10 #endif // OS_WIN | 10 #endif // OS_WIN |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 | 200 |
201 #if !defined(OS_CHROMEOS) || defined(USE_AURA) | 201 #if !defined(OS_CHROMEOS) || defined(USE_AURA) |
202 #include "chrome/browser/download/download_shelf.h" | 202 #include "chrome/browser/download/download_shelf.h" |
203 #endif | 203 #endif |
204 | 204 |
205 #if defined(FILE_MANAGER_EXTENSION) | 205 #if defined(FILE_MANAGER_EXTENSION) |
206 #include "chrome/browser/extensions/file_manager_util.h" | 206 #include "chrome/browser/extensions/file_manager_util.h" |
207 #endif | 207 #endif |
208 | 208 |
209 using base::TimeDelta; | 209 using base::TimeDelta; |
| 210 using content::NavigationController; |
210 using content::NavigationEntry; | 211 using content::NavigationEntry; |
211 using content::OpenURLParams; | 212 using content::OpenURLParams; |
212 using content::PluginService; | 213 using content::PluginService; |
213 using content::Referrer; | 214 using content::Referrer; |
214 using content::SSLStatus; | 215 using content::SSLStatus; |
215 using content::UserMetricsAction; | 216 using content::UserMetricsAction; |
216 using content::WebContents; | 217 using content::WebContents; |
217 | 218 |
218 /////////////////////////////////////////////////////////////////////////////// | 219 /////////////////////////////////////////////////////////////////////////////// |
219 | 220 |
(...skipping 952 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1172 | 1173 |
1173 int Browser::tab_count() const { | 1174 int Browser::tab_count() const { |
1174 return tab_handler_->GetTabStripModel()->count(); | 1175 return tab_handler_->GetTabStripModel()->count(); |
1175 } | 1176 } |
1176 | 1177 |
1177 int Browser::active_index() const { | 1178 int Browser::active_index() const { |
1178 return tab_handler_->GetTabStripModel()->active_index(); | 1179 return tab_handler_->GetTabStripModel()->active_index(); |
1179 } | 1180 } |
1180 | 1181 |
1181 int Browser::GetIndexOfController( | 1182 int Browser::GetIndexOfController( |
1182 const content::NavigationController* controller) const { | 1183 const NavigationController* controller) const { |
1183 return tab_handler_->GetTabStripModel()->GetIndexOfController(controller); | 1184 return tab_handler_->GetTabStripModel()->GetIndexOfController(controller); |
1184 } | 1185 } |
1185 | 1186 |
1186 TabContentsWrapper* Browser::GetSelectedTabContentsWrapper() const { | 1187 TabContentsWrapper* Browser::GetSelectedTabContentsWrapper() const { |
1187 return tabstrip_model()->GetActiveTabContents(); | 1188 return tabstrip_model()->GetActiveTabContents(); |
1188 } | 1189 } |
1189 | 1190 |
1190 WebContents* Browser::GetSelectedWebContents() const { | 1191 WebContents* Browser::GetSelectedWebContents() const { |
1191 TabContentsWrapper* wrapper = GetSelectedTabContentsWrapper(); | 1192 TabContentsWrapper* wrapper = GetSelectedTabContentsWrapper(); |
1192 return wrapper ? wrapper->web_contents() : NULL; | 1193 return wrapper ? wrapper->web_contents() : NULL; |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1366 tab_handler_->GetTabStripModel()->active_index(), | 1367 tab_handler_->GetTabStripModel()->active_index(), |
1367 wrapper); | 1368 wrapper); |
1368 } | 1369 } |
1369 | 1370 |
1370 bool Browser::CanRestoreTab() { | 1371 bool Browser::CanRestoreTab() { |
1371 return command_updater_.IsCommandEnabled(IDC_RESTORE_TAB); | 1372 return command_updater_.IsCommandEnabled(IDC_RESTORE_TAB); |
1372 } | 1373 } |
1373 | 1374 |
1374 bool Browser::NavigateToIndexWithDisposition(int index, | 1375 bool Browser::NavigateToIndexWithDisposition(int index, |
1375 WindowOpenDisposition disp) { | 1376 WindowOpenDisposition disp) { |
1376 content::NavigationController& controller = | 1377 NavigationController& controller = |
1377 GetOrCloneTabForDisposition(disp)->GetController(); | 1378 GetOrCloneTabForDisposition(disp)->GetController(); |
1378 if (index < 0 || index >= controller.GetEntryCount()) | 1379 if (index < 0 || index >= controller.GetEntryCount()) |
1379 return false; | 1380 return false; |
1380 controller.GoToIndex(index); | 1381 controller.GoToIndex(index); |
1381 return true; | 1382 return true; |
1382 } | 1383 } |
1383 | 1384 |
1384 browser::NavigateParams Browser::GetSingletonTabNavigateParams( | 1385 browser::NavigateParams Browser::GetSingletonTabNavigateParams( |
1385 const GURL& url) { | 1386 const GURL& url) { |
1386 browser::NavigateParams params( | 1387 browser::NavigateParams params( |
(...skipping 1127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2514 // to proceed closing the page or not, which sends us back to this method | 2515 // to proceed closing the page or not, which sends us back to this method |
2515 // with the NeedToFireBeforeUnload bit cleared. | 2516 // with the NeedToFireBeforeUnload bit cleared. |
2516 contents->GetRenderViewHost()->FirePageBeforeUnload(false); | 2517 contents->GetRenderViewHost()->FirePageBeforeUnload(false); |
2517 return true; | 2518 return true; |
2518 } | 2519 } |
2519 return false; | 2520 return false; |
2520 } | 2521 } |
2521 | 2522 |
2522 // static | 2523 // static |
2523 Browser* Browser::GetBrowserForController( | 2524 Browser* Browser::GetBrowserForController( |
2524 const content::NavigationController* controller, int* index_result) { | 2525 const NavigationController* controller, int* index_result) { |
2525 BrowserList::const_iterator it; | 2526 BrowserList::const_iterator it; |
2526 for (it = BrowserList::begin(); it != BrowserList::end(); ++it) { | 2527 for (it = BrowserList::begin(); it != BrowserList::end(); ++it) { |
2527 int index = (*it)->tab_handler_->GetTabStripModel()->GetIndexOfController( | 2528 int index = (*it)->tab_handler_->GetTabStripModel()->GetIndexOfController( |
2528 controller); | 2529 controller); |
2529 if (index != TabStripModel::kNoTab) { | 2530 if (index != TabStripModel::kNoTab) { |
2530 if (index_result) | 2531 if (index_result) |
2531 *index_result = index; | 2532 *index_result = index; |
2532 return *it; | 2533 return *it; |
2533 } | 2534 } |
2534 } | 2535 } |
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3096 // Load the initial URL before adding the new tab contents to the tab strip | 3097 // Load the initial URL before adding the new tab contents to the tab strip |
3097 // so that the tab contents has navigation state. | 3098 // so that the tab contents has navigation state. |
3098 contents->tab_contents()->GetController().LoadURL( | 3099 contents->tab_contents()->GetController().LoadURL( |
3099 url, referrer, transition, std::string()); | 3100 url, referrer, transition, std::string()); |
3100 } | 3101 } |
3101 | 3102 |
3102 return contents; | 3103 return contents; |
3103 } | 3104 } |
3104 | 3105 |
3105 bool Browser::CanDuplicateContentsAt(int index) { | 3106 bool Browser::CanDuplicateContentsAt(int index) { |
3106 content::NavigationController& nc = GetTabContentsAt(index)->GetController(); | 3107 NavigationController& nc = GetTabContentsAt(index)->GetController(); |
3107 return nc.GetWebContents() && nc.GetLastCommittedEntry(); | 3108 return nc.GetWebContents() && nc.GetLastCommittedEntry(); |
3108 } | 3109 } |
3109 | 3110 |
3110 void Browser::DuplicateContentsAt(int index) { | 3111 void Browser::DuplicateContentsAt(int index) { |
3111 TabContentsWrapper* contents = GetTabContentsWrapperAt(index); | 3112 TabContentsWrapper* contents = GetTabContentsWrapperAt(index); |
3112 CHECK(contents); | 3113 CHECK(contents); |
3113 TabContentsWrapper* contents_dupe = contents->Clone(); | 3114 TabContentsWrapper* contents_dupe = contents->Clone(); |
3114 | 3115 |
3115 bool pinned = false; | 3116 bool pinned = false; |
3116 if (CanSupportWindowFeature(FEATURE_TABSTRIP)) { | 3117 if (CanSupportWindowFeature(FEATURE_TABSTRIP)) { |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3266 registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_DETACHED, | 3267 registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_DETACHED, |
3267 content::Source<WebContents>(contents->web_contents())); | 3268 content::Source<WebContents>(contents->web_contents())); |
3268 } | 3269 } |
3269 | 3270 |
3270 void Browser::TabClosingAt(TabStripModel* tab_strip_model, | 3271 void Browser::TabClosingAt(TabStripModel* tab_strip_model, |
3271 TabContentsWrapper* contents, | 3272 TabContentsWrapper* contents, |
3272 int index) { | 3273 int index) { |
3273 fullscreen_controller_->OnTabClosing(contents->tab_contents()); | 3274 fullscreen_controller_->OnTabClosing(contents->tab_contents()); |
3274 content::NotificationService::current()->Notify( | 3275 content::NotificationService::current()->Notify( |
3275 content::NOTIFICATION_TAB_CLOSING, | 3276 content::NOTIFICATION_TAB_CLOSING, |
3276 content::Source<content::NavigationController>( | 3277 content::Source<NavigationController>( |
3277 &contents->web_contents()->GetController()), | 3278 &contents->web_contents()->GetController()), |
3278 content::NotificationService::NoDetails()); | 3279 content::NotificationService::NoDetails()); |
3279 | 3280 |
3280 // Sever the TabContents' connection back to us. | 3281 // Sever the TabContents' connection back to us. |
3281 SetAsDelegate(contents, NULL); | 3282 SetAsDelegate(contents, NULL); |
3282 } | 3283 } |
3283 | 3284 |
3284 void Browser::TabDetachedAt(TabContentsWrapper* contents, int index) { | 3285 void Browser::TabDetachedAt(TabContentsWrapper* contents, int index) { |
3285 TabDetachedAtImpl(contents, index, DETACH_TYPE_DETACH); | 3286 TabDetachedAtImpl(contents, index, DETACH_TYPE_DETACH); |
3286 } | 3287 } |
(...skipping 815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4102 | 4103 |
4103 case content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED: | 4104 case content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED: |
4104 // When the current tab's SSL state changes, we need to update the URL | 4105 // When the current tab's SSL state changes, we need to update the URL |
4105 // bar to reflect the new state. Note that it's possible for the selected | 4106 // bar to reflect the new state. Note that it's possible for the selected |
4106 // tab contents to be NULL. This is because we listen for all sources | 4107 // tab contents to be NULL. This is because we listen for all sources |
4107 // (NavigationControllers) for convenience, so the notification could | 4108 // (NavigationControllers) for convenience, so the notification could |
4108 // actually be for a different window while we're doing asynchronous | 4109 // actually be for a different window while we're doing asynchronous |
4109 // closing of this one. | 4110 // closing of this one. |
4110 if (GetSelectedWebContents() && | 4111 if (GetSelectedWebContents() && |
4111 &GetSelectedWebContents()->GetController() == | 4112 &GetSelectedWebContents()->GetController() == |
4112 content::Source<content::NavigationController>(source).ptr()) | 4113 content::Source<NavigationController>(source).ptr()) |
4113 UpdateToolbar(false); | 4114 UpdateToolbar(false); |
4114 break; | 4115 break; |
4115 | 4116 |
4116 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: { | 4117 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: { |
4117 // Show the UI if the extension was disabled for escalated permissions. | 4118 // Show the UI if the extension was disabled for escalated permissions. |
4118 Profile* profile = content::Source<Profile>(source).ptr(); | 4119 Profile* profile = content::Source<Profile>(source).ptr(); |
4119 if (profile_->IsSameProfile(profile)) { | 4120 if (profile_->IsSameProfile(profile)) { |
4120 ExtensionService* service = profile->GetExtensionService(); | 4121 ExtensionService* service = profile->GetExtensionService(); |
4121 DCHECK(service); | 4122 DCHECK(service); |
4122 const Extension* extension = | 4123 const Extension* extension = |
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4589 UpdateCommandsForBookmarkBar(); | 4590 UpdateCommandsForBookmarkBar(); |
4590 } | 4591 } |
4591 | 4592 |
4592 void Browser::UpdateCommandsForTabState() { | 4593 void Browser::UpdateCommandsForTabState() { |
4593 WebContents* current_tab = GetSelectedWebContents(); | 4594 WebContents* current_tab = GetSelectedWebContents(); |
4594 TabContentsWrapper* current_tab_wrapper = GetSelectedTabContentsWrapper(); | 4595 TabContentsWrapper* current_tab_wrapper = GetSelectedTabContentsWrapper(); |
4595 if (!current_tab || !current_tab_wrapper) // May be NULL during tab restore. | 4596 if (!current_tab || !current_tab_wrapper) // May be NULL during tab restore. |
4596 return; | 4597 return; |
4597 | 4598 |
4598 // Navigation commands | 4599 // Navigation commands |
4599 content::NavigationController& nc = current_tab->GetController(); | 4600 NavigationController& nc = current_tab->GetController(); |
4600 command_updater_.UpdateCommandEnabled(IDC_BACK, nc.CanGoBack()); | 4601 command_updater_.UpdateCommandEnabled(IDC_BACK, nc.CanGoBack()); |
4601 command_updater_.UpdateCommandEnabled(IDC_FORWARD, nc.CanGoForward()); | 4602 command_updater_.UpdateCommandEnabled(IDC_FORWARD, nc.CanGoForward()); |
4602 command_updater_.UpdateCommandEnabled(IDC_RELOAD, | 4603 command_updater_.UpdateCommandEnabled(IDC_RELOAD, |
4603 CanReloadContents(current_tab)); | 4604 CanReloadContents(current_tab)); |
4604 command_updater_.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE, | 4605 command_updater_.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE, |
4605 CanReloadContents(current_tab)); | 4606 CanReloadContents(current_tab)); |
4606 | 4607 |
4607 // Window management commands | 4608 // Window management commands |
4608 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, | 4609 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, |
4609 !is_app() && CanDuplicateContentsAt(active_index())); | 4610 !is_app() && CanDuplicateContentsAt(active_index())); |
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5390 window_->GetLocationBar()->ShowFirstRunBubble(bubble_type); | 5391 window_->GetLocationBar()->ShowFirstRunBubble(bubble_type); |
5391 } else { | 5392 } else { |
5392 GlobalErrorService* service = | 5393 GlobalErrorService* service = |
5393 GlobalErrorServiceFactory::GetForProfile(profile()); | 5394 GlobalErrorServiceFactory::GetForProfile(profile()); |
5394 GlobalError* error = service->GetFirstGlobalErrorWithBubbleView(); | 5395 GlobalError* error = service->GetFirstGlobalErrorWithBubbleView(); |
5395 if (error) { | 5396 if (error) { |
5396 error->ShowBubbleView(this); | 5397 error->ShowBubbleView(this); |
5397 } | 5398 } |
5398 } | 5399 } |
5399 } | 5400 } |
OLD | NEW |