| 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/browser.h" | 5 #include "chrome/browser/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 2254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2265 last_blocked_command_disposition_ = CURRENT_TAB; | 2265 last_blocked_command_disposition_ = CURRENT_TAB; |
| 2266 } | 2266 } |
| 2267 } | 2267 } |
| 2268 | 2268 |
| 2269 int Browser::GetLastBlockedCommand(WindowOpenDisposition* disposition) { | 2269 int Browser::GetLastBlockedCommand(WindowOpenDisposition* disposition) { |
| 2270 if (disposition) | 2270 if (disposition) |
| 2271 *disposition = last_blocked_command_disposition_; | 2271 *disposition = last_blocked_command_disposition_; |
| 2272 return last_blocked_command_id_; | 2272 return last_blocked_command_id_; |
| 2273 } | 2273 } |
| 2274 | 2274 |
| 2275 void Browser::UpdateUIForNavigationInTab(TabContents* contents, |
| 2276 PageTransition::Type transition, |
| 2277 bool user_initiated) { |
| 2278 tabstrip_model()->TabNavigating(contents, transition); |
| 2279 |
| 2280 bool contents_is_selected = contents == GetSelectedTabContents(); |
| 2281 if (user_initiated && contents_is_selected && window()->GetLocationBar()) { |
| 2282 // Forcibly reset the location bar if the url is going to change in the |
| 2283 // current tab, since otherwise it won't discard any ongoing user edits, |
| 2284 // since it doesn't realize this is a user-initiated action. |
| 2285 window()->GetLocationBar()->Revert(); |
| 2286 } |
| 2287 |
| 2288 if (GetStatusBubble()) |
| 2289 GetStatusBubble()->Hide(); |
| 2290 |
| 2291 // Update the location bar. This is synchronous. We specifically don't |
| 2292 // update the load state since the load hasn't started yet and updating it |
| 2293 // will put it out of sync with the actual state like whether we're |
| 2294 // displaying a favicon, which controls the throbber. If we updated it here, |
| 2295 // the throbber will show the default favicon for a split second when |
| 2296 // navigating away from the new tab page. |
| 2297 ScheduleUIUpdate(contents, TabContents::INVALIDATE_URL); |
| 2298 |
| 2299 if (contents_is_selected) |
| 2300 contents->Focus(); |
| 2301 } |
| 2302 |
| 2303 GURL Browser::GetHomePage() const { |
| 2304 // --homepage overrides any preferences. |
| 2305 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 2306 if (command_line.HasSwitch(switches::kHomePage)) { |
| 2307 FilePath browser_directory; |
| 2308 PathService::Get(base::DIR_CURRENT, &browser_directory); |
| 2309 GURL home_page(URLFixerUpper::FixupRelativeFile(browser_directory, |
| 2310 command_line.GetSwitchValuePath(switches::kHomePage))); |
| 2311 if (home_page.is_valid()) |
| 2312 return home_page; |
| 2313 } |
| 2314 |
| 2315 if (profile_->GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage)) |
| 2316 return GURL(chrome::kChromeUINewTabURL); |
| 2317 GURL home_page(URLFixerUpper::FixupURL( |
| 2318 profile_->GetPrefs()->GetString(prefs::kHomePage), |
| 2319 std::string())); |
| 2320 if (!home_page.is_valid()) |
| 2321 return GURL(chrome::kChromeUINewTabURL); |
| 2322 return home_page; |
| 2323 } |
| 2324 |
| 2275 /////////////////////////////////////////////////////////////////////////////// | 2325 /////////////////////////////////////////////////////////////////////////////// |
| 2276 // Browser, PageNavigator implementation: | 2326 // Browser, PageNavigator implementation: |
| 2327 |
| 2277 void Browser::OpenURL(const GURL& url, const GURL& referrer, | 2328 void Browser::OpenURL(const GURL& url, const GURL& referrer, |
| 2278 WindowOpenDisposition disposition, | 2329 WindowOpenDisposition disposition, |
| 2279 PageTransition::Type transition) { | 2330 PageTransition::Type transition) { |
| 2280 OpenURLFromTab(NULL, url, referrer, disposition, transition); | 2331 OpenURLFromTab(NULL, url, referrer, disposition, transition); |
| 2281 } | 2332 } |
| 2282 | 2333 |
| 2283 /////////////////////////////////////////////////////////////////////////////// | 2334 /////////////////////////////////////////////////////////////////////////////// |
| 2284 // Browser, CommandUpdater::CommandUpdaterDelegate implementation: | 2335 // Browser, CommandUpdater::CommandUpdaterDelegate implementation: |
| 2285 | 2336 |
| 2286 void Browser::ExecuteCommand(int id) { | 2337 void Browser::ExecuteCommand(int id) { |
| (...skipping 1738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4025 } | 4076 } |
| 4026 | 4077 |
| 4027 if (disposition != NEW_BACKGROUND_TAB && source_tab_was_frontmost && | 4078 if (disposition != NEW_BACKGROUND_TAB && source_tab_was_frontmost && |
| 4028 new_contents) { | 4079 new_contents) { |
| 4029 // Give the focus to the newly navigated tab, if the source tab was | 4080 // Give the focus to the newly navigated tab, if the source tab was |
| 4030 // front-most. | 4081 // front-most. |
| 4031 new_contents->Focus(); | 4082 new_contents->Focus(); |
| 4032 } | 4083 } |
| 4033 } | 4084 } |
| 4034 | 4085 |
| 4035 GURL Browser::GetHomePage() const { | |
| 4036 // --homepage overrides any preferences. | |
| 4037 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
| 4038 if (command_line.HasSwitch(switches::kHomePage)) { | |
| 4039 FilePath browser_directory; | |
| 4040 PathService::Get(base::DIR_CURRENT, &browser_directory); | |
| 4041 GURL home_page(URLFixerUpper::FixupRelativeFile(browser_directory, | |
| 4042 command_line.GetSwitchValuePath(switches::kHomePage))); | |
| 4043 if (home_page.is_valid()) | |
| 4044 return home_page; | |
| 4045 } | |
| 4046 | |
| 4047 if (profile_->GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage)) | |
| 4048 return GURL(chrome::kChromeUINewTabURL); | |
| 4049 GURL home_page(URLFixerUpper::FixupURL( | |
| 4050 profile_->GetPrefs()->GetString(prefs::kHomePage), | |
| 4051 std::string())); | |
| 4052 if (!home_page.is_valid()) | |
| 4053 return GURL(chrome::kChromeUINewTabURL); | |
| 4054 return home_page; | |
| 4055 } | |
| 4056 | |
| 4057 void Browser::FindInPage(bool find_next, bool forward_direction) { | 4086 void Browser::FindInPage(bool find_next, bool forward_direction) { |
| 4058 ShowFindBar(); | 4087 ShowFindBar(); |
| 4059 if (find_next) { | 4088 if (find_next) { |
| 4060 string16 find_text; | 4089 string16 find_text; |
| 4061 #if defined(OS_MACOSX) | 4090 #if defined(OS_MACOSX) |
| 4062 // We always want to search for the contents of the find pasteboard on OS X. | 4091 // We always want to search for the contents of the find pasteboard on OS X. |
| 4063 find_text = GetFindPboardText(); | 4092 find_text = GetFindPboardText(); |
| 4064 #endif | 4093 #endif |
| 4065 GetSelectedTabContents()->StartFinding(find_text, | 4094 GetSelectedTabContents()->StartFinding(find_text, |
| 4066 forward_direction, | 4095 forward_direction, |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4151 disposition == NEW_FOREGROUND_TAB ? TabStripModel::ADD_SELECTED : | 4180 disposition == NEW_FOREGROUND_TAB ? TabStripModel::ADD_SELECTED : |
| 4152 TabStripModel::ADD_NONE); | 4181 TabStripModel::ADD_NONE); |
| 4153 return true; | 4182 return true; |
| 4154 } | 4183 } |
| 4155 // The omnibox currently doesn't use other dispositions, so we don't attempt | 4184 // The omnibox currently doesn't use other dispositions, so we don't attempt |
| 4156 // to handle them. If you hit this NOTREACHED file a bug and I'll (sky) add | 4185 // to handle them. If you hit this NOTREACHED file a bug and I'll (sky) add |
| 4157 // support for the new disposition. | 4186 // support for the new disposition. |
| 4158 NOTREACHED(); | 4187 NOTREACHED(); |
| 4159 return false; | 4188 return false; |
| 4160 } | 4189 } |
| OLD | NEW |