| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/browser_commands.h" | 5 #include "chrome/browser/ui/browser_commands.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 // location bar contents, since all browser-UI-triggered navigations should | 206 // location bar contents, since all browser-UI-triggered navigations should |
| 207 // revert any omnibox edits in the current tab. | 207 // revert any omnibox edits in the current tab. |
| 208 WebContents* GetTabAndRevertIfNecessary(Browser* browser, | 208 WebContents* GetTabAndRevertIfNecessary(Browser* browser, |
| 209 WindowOpenDisposition disposition) { | 209 WindowOpenDisposition disposition) { |
| 210 WebContents* current_tab = browser->tab_strip_model()->GetActiveWebContents(); | 210 WebContents* current_tab = browser->tab_strip_model()->GetActiveWebContents(); |
| 211 switch (disposition) { | 211 switch (disposition) { |
| 212 case NEW_FOREGROUND_TAB: | 212 case NEW_FOREGROUND_TAB: |
| 213 case NEW_BACKGROUND_TAB: { | 213 case NEW_BACKGROUND_TAB: { |
| 214 WebContents* new_tab = current_tab->Clone(); | 214 WebContents* new_tab = current_tab->Clone(); |
| 215 browser->tab_strip_model()->AddWebContents( | 215 browser->tab_strip_model()->AddWebContents( |
| 216 new_tab, -1, content::PAGE_TRANSITION_LINK, | 216 new_tab, -1, ui::PAGE_TRANSITION_LINK, |
| 217 (disposition == NEW_FOREGROUND_TAB) ? | 217 (disposition == NEW_FOREGROUND_TAB) ? |
| 218 TabStripModel::ADD_ACTIVE : TabStripModel::ADD_NONE); | 218 TabStripModel::ADD_ACTIVE : TabStripModel::ADD_NONE); |
| 219 return new_tab; | 219 return new_tab; |
| 220 } | 220 } |
| 221 case NEW_WINDOW: { | 221 case NEW_WINDOW: { |
| 222 WebContents* new_tab = current_tab->Clone(); | 222 WebContents* new_tab = current_tab->Clone(); |
| 223 Browser* new_browser = new Browser(Browser::CreateParams( | 223 Browser* new_browser = new Browser(Browser::CreateParams( |
| 224 browser->profile(), browser->host_desktop_type())); | 224 browser->profile(), browser->host_desktop_type())); |
| 225 new_browser->tab_strip_model()->AddWebContents( | 225 new_browser->tab_strip_model()->AddWebContents( |
| 226 new_tab, -1, content::PAGE_TRANSITION_LINK, | 226 new_tab, -1, ui::PAGE_TRANSITION_LINK, |
| 227 TabStripModel::ADD_ACTIVE); | 227 TabStripModel::ADD_ACTIVE); |
| 228 new_browser->window()->Show(); | 228 new_browser->window()->Show(); |
| 229 return new_tab; | 229 return new_tab; |
| 230 } | 230 } |
| 231 default: | 231 default: |
| 232 browser->window()->GetLocationBar()->Revert(); | 232 browser->window()->GetLocationBar()->Revert(); |
| 233 return current_tab; | 233 return current_tab; |
| 234 } | 234 } |
| 235 } | 235 } |
| 236 | 236 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 if (service) | 386 if (service) |
| 387 service->RestoreMostRecentEntry(NULL, host_desktop_type); | 387 service->RestoreMostRecentEntry(NULL, host_desktop_type); |
| 388 } | 388 } |
| 389 | 389 |
| 390 void OpenURLOffTheRecord(Profile* profile, | 390 void OpenURLOffTheRecord(Profile* profile, |
| 391 const GURL& url, | 391 const GURL& url, |
| 392 chrome::HostDesktopType desktop_type) { | 392 chrome::HostDesktopType desktop_type) { |
| 393 ScopedTabbedBrowserDisplayer displayer(profile->GetOffTheRecordProfile(), | 393 ScopedTabbedBrowserDisplayer displayer(profile->GetOffTheRecordProfile(), |
| 394 desktop_type); | 394 desktop_type); |
| 395 AddSelectedTabWithURL(displayer.browser(), url, | 395 AddSelectedTabWithURL(displayer.browser(), url, |
| 396 content::PAGE_TRANSITION_LINK); | 396 ui::PAGE_TRANSITION_LINK); |
| 397 } | 397 } |
| 398 | 398 |
| 399 bool CanGoBack(const Browser* browser) { | 399 bool CanGoBack(const Browser* browser) { |
| 400 return browser->tab_strip_model()->GetActiveWebContents()-> | 400 return browser->tab_strip_model()->GetActiveWebContents()-> |
| 401 GetController().CanGoBack(); | 401 GetController().CanGoBack(); |
| 402 } | 402 } |
| 403 | 403 |
| 404 void GoBack(Browser* browser, WindowOpenDisposition disposition) { | 404 void GoBack(Browser* browser, WindowOpenDisposition disposition) { |
| 405 content::RecordAction(UserMetricsAction("Back")); | 405 content::RecordAction(UserMetricsAction("Back")); |
| 406 | 406 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 extensions::ExtensionRegistry::EVERYTHING); | 482 extensions::ExtensionRegistry::EVERYTHING); |
| 483 if (!extension) | 483 if (!extension) |
| 484 return; | 484 return; |
| 485 | 485 |
| 486 url = extensions::AppLaunchInfo::GetLaunchWebURL(extension); | 486 url = extensions::AppLaunchInfo::GetLaunchWebURL(extension); |
| 487 } | 487 } |
| 488 #endif | 488 #endif |
| 489 | 489 |
| 490 OpenURLParams params( | 490 OpenURLParams params( |
| 491 url, Referrer(), disposition, | 491 url, Referrer(), disposition, |
| 492 content::PageTransitionFromInt( | 492 ui::PageTransitionFromInt( |
| 493 content::PAGE_TRANSITION_AUTO_BOOKMARK | | 493 ui::PAGE_TRANSITION_AUTO_BOOKMARK | |
| 494 content::PAGE_TRANSITION_HOME_PAGE), | 494 ui::PAGE_TRANSITION_HOME_PAGE), |
| 495 false); | 495 false); |
| 496 params.extra_headers = extra_headers; | 496 params.extra_headers = extra_headers; |
| 497 browser->OpenURL(params); | 497 browser->OpenURL(params); |
| 498 } | 498 } |
| 499 | 499 |
| 500 void OpenCurrentURL(Browser* browser) { | 500 void OpenCurrentURL(Browser* browser) { |
| 501 content::RecordAction(UserMetricsAction("LoadURL")); | 501 content::RecordAction(UserMetricsAction("LoadURL")); |
| 502 LocationBar* location_bar = browser->window()->GetLocationBar(); | 502 LocationBar* location_bar = browser->window()->GetLocationBar(); |
| 503 if (!location_bar) | 503 if (!location_bar) |
| 504 return; | 504 return; |
| 505 | 505 |
| 506 GURL url(location_bar->GetDestinationURL()); | 506 GURL url(location_bar->GetDestinationURL()); |
| 507 | 507 |
| 508 content::PageTransition page_transition = location_bar->GetPageTransition(); | 508 ui::PageTransition page_transition = location_bar->GetPageTransition(); |
| 509 content::PageTransition page_transition_without_qualifier( | 509 ui::PageTransition page_transition_without_qualifier( |
| 510 PageTransitionStripQualifier(page_transition)); | 510 ui::PageTransitionStripQualifier(page_transition)); |
| 511 WindowOpenDisposition open_disposition = | 511 WindowOpenDisposition open_disposition = |
| 512 location_bar->GetWindowOpenDisposition(); | 512 location_bar->GetWindowOpenDisposition(); |
| 513 // A PAGE_TRANSITION_TYPED means the user has typed a URL. We do not want to | 513 // A PAGE_TRANSITION_TYPED means the user has typed a URL. We do not want to |
| 514 // open URLs with instant_controller since in some cases it disregards it | 514 // open URLs with instant_controller since in some cases it disregards it |
| 515 // and performs a search instead. For example, when using CTRL-Enter, the | 515 // and performs a search instead. For example, when using CTRL-Enter, the |
| 516 // location_bar is aware of the URL but instant is not. | 516 // location_bar is aware of the URL but instant is not. |
| 517 // Instant should also not handle PAGE_TRANSITION_RELOAD because its knowledge | 517 // Instant should also not handle PAGE_TRANSITION_RELOAD because its knowledge |
| 518 // of the omnibox text may be stale if the user focuses in the omnibox and | 518 // of the omnibox text may be stale if the user focuses in the omnibox and |
| 519 // presses enter without typing anything. | 519 // presses enter without typing anything. |
| 520 if (page_transition_without_qualifier != content::PAGE_TRANSITION_TYPED && | 520 if (page_transition_without_qualifier != ui::PAGE_TRANSITION_TYPED && |
| 521 page_transition_without_qualifier != content::PAGE_TRANSITION_RELOAD && | 521 page_transition_without_qualifier != ui::PAGE_TRANSITION_RELOAD && |
| 522 browser->instant_controller() && | 522 browser->instant_controller() && |
| 523 browser->instant_controller()->OpenInstant(open_disposition, url)) | 523 browser->instant_controller()->OpenInstant(open_disposition, url)) |
| 524 return; | 524 return; |
| 525 | 525 |
| 526 NavigateParams params(browser, url, page_transition); | 526 NavigateParams params(browser, url, page_transition); |
| 527 params.disposition = open_disposition; | 527 params.disposition = open_disposition; |
| 528 // Use ADD_INHERIT_OPENER so that all pages opened by the omnibox at least | 528 // Use ADD_INHERIT_OPENER so that all pages opened by the omnibox at least |
| 529 // inherit the opener. In some cases the tabstrip will determine the group | 529 // inherit the opener. In some cases the tabstrip will determine the group |
| 530 // should be inherited, in which case the group is inherited instead of the | 530 // should be inherited, in which case the group is inherited instead of the |
| 531 // opener. | 531 // opener. |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(), | 702 new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(), |
| 703 browser->window()->GetRestoredBounds().size())); | 703 browser->window()->GetRestoredBounds().size())); |
| 704 | 704 |
| 705 // We need to show the browser now. Otherwise ContainerWin assumes the | 705 // We need to show the browser now. Otherwise ContainerWin assumes the |
| 706 // WebContents is invisible and won't size it. | 706 // WebContents is invisible and won't size it. |
| 707 new_browser->window()->Show(); | 707 new_browser->window()->Show(); |
| 708 | 708 |
| 709 // The page transition below is only for the purpose of inserting the tab. | 709 // The page transition below is only for the purpose of inserting the tab. |
| 710 new_browser->tab_strip_model()->AddWebContents( | 710 new_browser->tab_strip_model()->AddWebContents( |
| 711 contents_dupe, -1, | 711 contents_dupe, -1, |
| 712 content::PAGE_TRANSITION_LINK, | 712 ui::PAGE_TRANSITION_LINK, |
| 713 TabStripModel::ADD_ACTIVE); | 713 TabStripModel::ADD_ACTIVE); |
| 714 } | 714 } |
| 715 | 715 |
| 716 SessionService* session_service = | 716 SessionService* session_service = |
| 717 SessionServiceFactory::GetForProfileIfExisting(browser->profile()); | 717 SessionServiceFactory::GetForProfileIfExisting(browser->profile()); |
| 718 if (session_service) | 718 if (session_service) |
| 719 session_service->TabRestored(contents_dupe, pinned); | 719 session_service->TabRestored(contents_dupe, pinned); |
| 720 return contents_dupe; | 720 return contents_dupe; |
| 721 } | 721 } |
| 722 | 722 |
| (...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1209 BrowserWindow* new_window = b->window(); | 1209 BrowserWindow* new_window = b->window(); |
| 1210 new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(), | 1210 new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(), |
| 1211 browser->window()->GetRestoredBounds().size())); | 1211 browser->window()->GetRestoredBounds().size())); |
| 1212 | 1212 |
| 1213 // We need to show the browser now. Otherwise ContainerWin assumes the | 1213 // We need to show the browser now. Otherwise ContainerWin assumes the |
| 1214 // WebContents is invisible and won't size it. | 1214 // WebContents is invisible and won't size it. |
| 1215 b->window()->Show(); | 1215 b->window()->Show(); |
| 1216 | 1216 |
| 1217 // The page transition below is only for the purpose of inserting the tab. | 1217 // The page transition below is only for the purpose of inserting the tab. |
| 1218 b->tab_strip_model()->AddWebContents(view_source_contents, -1, | 1218 b->tab_strip_model()->AddWebContents(view_source_contents, -1, |
| 1219 content::PAGE_TRANSITION_LINK, | 1219 ui::PAGE_TRANSITION_LINK, |
| 1220 TabStripModel::ADD_ACTIVE); | 1220 TabStripModel::ADD_ACTIVE); |
| 1221 } | 1221 } |
| 1222 | 1222 |
| 1223 SessionService* session_service = | 1223 SessionService* session_service = |
| 1224 SessionServiceFactory::GetForProfileIfExisting(browser->profile()); | 1224 SessionServiceFactory::GetForProfileIfExisting(browser->profile()); |
| 1225 if (session_service) | 1225 if (session_service) |
| 1226 session_service->TabRestored(view_source_contents, false); | 1226 session_service->TabRestored(view_source_contents, false); |
| 1227 } | 1227 } |
| 1228 | 1228 |
| 1229 void ViewSelectedSource(Browser* browser) { | 1229 void ViewSelectedSource(Browser* browser) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1278 browser->profile(), | 1278 browser->profile(), |
| 1279 browser->host_desktop_type())); | 1279 browser->host_desktop_type())); |
| 1280 app_browser->tab_strip_model()->AppendWebContents(contents, true); | 1280 app_browser->tab_strip_model()->AppendWebContents(contents, true); |
| 1281 | 1281 |
| 1282 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; | 1282 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; |
| 1283 contents->GetRenderViewHost()->SyncRendererPrefs(); | 1283 contents->GetRenderViewHost()->SyncRendererPrefs(); |
| 1284 app_browser->window()->Show(); | 1284 app_browser->window()->Show(); |
| 1285 } | 1285 } |
| 1286 | 1286 |
| 1287 } // namespace chrome | 1287 } // namespace chrome |
| OLD | NEW |