Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/idle_timer.h" | 8 #include "base/idle_timer.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 1639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1650 controller->LoadURL(url, referrer, transition); | 1650 controller->LoadURL(url, referrer, transition); |
| 1651 // If the TabContents type has been swapped, we need to point to the current | 1651 // If the TabContents type has been swapped, we need to point to the current |
| 1652 // active type otherwise there will be weirdness. | 1652 // active type otherwise there will be weirdness. |
| 1653 new_contents = controller->active_contents(); | 1653 new_contents = controller->active_contents(); |
| 1654 if (GetStatusBubble()) | 1654 if (GetStatusBubble()) |
| 1655 GetStatusBubble()->Hide(); | 1655 GetStatusBubble()->Hide(); |
| 1656 | 1656 |
| 1657 // Synchronously update the location bar. This allows us to immediately | 1657 // Synchronously update the location bar. This allows us to immediately |
| 1658 // have the URL bar update when the user types something, rather than | 1658 // have the URL bar update when the user types something, rather than |
| 1659 // going through the normal system of ScheduleUIUpdate which has a delay. | 1659 // going through the normal system of ScheduleUIUpdate which has a delay. |
| 1660 ScheduleUIUpdate(source, TabContents::INVALIDATE_URL | | |
|
Ben Goodger (Google)
2009/04/04 17:27:59
You might move this above the comment above since
| |
| 1661 TabContents::INVALIDATE_LOAD); | |
| 1660 UpdateToolbar(false); | 1662 UpdateToolbar(false); |
| 1661 } else if (disposition == OFF_THE_RECORD) { | 1663 } else if (disposition == OFF_THE_RECORD) { |
| 1662 OpenURLOffTheRecord(profile_, url); | 1664 OpenURLOffTheRecord(profile_, url); |
| 1663 return; | 1665 return; |
| 1664 } else if (disposition != SUPPRESS_OPEN) { | 1666 } else if (disposition != SUPPRESS_OPEN) { |
| 1665 new_contents = AddTabWithURL(url, referrer, transition, | 1667 new_contents = AddTabWithURL(url, referrer, transition, |
| 1666 disposition != NEW_BACKGROUND_TAB, instance); | 1668 disposition != NEW_BACKGROUND_TAB, instance); |
| 1667 } | 1669 } |
| 1668 | 1670 |
| 1669 if (disposition != NEW_BACKGROUND_TAB && source_tab_was_frontmost) { | 1671 if (disposition != NEW_BACKGROUND_TAB && source_tab_was_frontmost) { |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1858 | 1860 |
| 1859 tabstrip_model_.DetachTabContentsAt(index); | 1861 tabstrip_model_.DetachTabContentsAt(index); |
| 1860 Browser* browser = Browser::CreateForApp(app_name, profile_, false); | 1862 Browser* browser = Browser::CreateForApp(app_name, profile_, false); |
| 1861 browser->tabstrip_model()->AppendTabContents(contents, true); | 1863 browser->tabstrip_model()->AppendTabContents(contents, true); |
| 1862 browser->window()->Show(); | 1864 browser->window()->Show(); |
| 1863 } | 1865 } |
| 1864 | 1866 |
| 1865 void Browser::ContentsStateChanged(TabContents* source) { | 1867 void Browser::ContentsStateChanged(TabContents* source) { |
| 1866 int index = tabstrip_model_.GetIndexOfTabContents(source); | 1868 int index = tabstrip_model_.GetIndexOfTabContents(source); |
| 1867 if (index != TabStripModel::kNoTab) | 1869 if (index != TabStripModel::kNoTab) |
| 1868 tabstrip_model_.UpdateTabContentsStateAt(index); | 1870 tabstrip_model_.UpdateTabContentsStateAt(index, true); |
| 1869 } | 1871 } |
| 1870 | 1872 |
| 1871 bool Browser::ShouldDisplayURLField() { | 1873 bool Browser::ShouldDisplayURLField() { |
| 1872 return !IsApplication(); | 1874 return !IsApplication(); |
| 1873 } | 1875 } |
| 1874 | 1876 |
| 1875 void Browser::BeforeUnloadFired(TabContents* tab, | 1877 void Browser::BeforeUnloadFired(TabContents* tab, |
| 1876 bool proceed, | 1878 bool proceed, |
| 1877 bool* proceed_to_fire_unload) { | 1879 bool* proceed_to_fire_unload) { |
| 1878 if (!is_attempting_to_close_browser_) { | 1880 if (!is_attempting_to_close_browser_) { |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2189 | 2191 |
| 2190 /////////////////////////////////////////////////////////////////////////////// | 2192 /////////////////////////////////////////////////////////////////////////////// |
| 2191 // Browser, UI update coalescing and handling (private): | 2193 // Browser, UI update coalescing and handling (private): |
| 2192 | 2194 |
| 2193 void Browser::UpdateToolbar(bool should_restore_state) { | 2195 void Browser::UpdateToolbar(bool should_restore_state) { |
| 2194 window_->UpdateToolbar(GetSelectedTabContents(), should_restore_state); | 2196 window_->UpdateToolbar(GetSelectedTabContents(), should_restore_state); |
| 2195 } | 2197 } |
| 2196 | 2198 |
| 2197 void Browser::ScheduleUIUpdate(const TabContents* source, | 2199 void Browser::ScheduleUIUpdate(const TabContents* source, |
| 2198 unsigned changed_flags) { | 2200 unsigned changed_flags) { |
| 2199 // Synchronously update the URL. | 2201 // Do some synchronous updates. |
| 2200 if (changed_flags & TabContents::INVALIDATE_URL && | 2202 if (changed_flags & TabContents::INVALIDATE_URL && |
| 2201 source == GetSelectedTabContents()) { | 2203 source == GetSelectedTabContents()) { |
| 2202 // Only update the URL for the current tab. Note that we do not update | 2204 // Only update the URL for the current tab. Note that we do not update |
| 2203 // the navigation commands since those would have already been updated | 2205 // the navigation commands since those would have already been updated |
| 2204 // synchronously by NavigationStateChanged. | 2206 // synchronously by NavigationStateChanged. |
| 2205 UpdateToolbar(false); | 2207 UpdateToolbar(false); |
| 2208 } | |
| 2209 if (changed_flags & TabContents::INVALIDATE_LOAD && source) { | |
| 2210 // Update the loading state synchronously. This is so the throbber will | |
| 2211 // immediately start/stop, which gives a more snappy feel. We want to do | |
| 2212 // this for any tab so they start & stop quickly, but the source can be | |
| 2213 // NULL, so we have to check for that. | |
| 2214 tabstrip_model_.UpdateTabContentsStateAt( | |
| 2215 tabstrip_model_.GetIndexOfController(source->controller()), true); | |
| 2216 } | |
| 2206 | 2217 |
| 2207 if (changed_flags == TabContents::INVALIDATE_URL) | 2218 // If the only updates were synchronously handled above, we're done. |
| 2208 return; // Just had an update URL and nothing else. | 2219 if (changed_flags == |
| 2209 } | 2220 (TabContents::INVALIDATE_URL | TabContents::INVALIDATE_LOAD)) |
| 2221 return; | |
| 2210 | 2222 |
| 2211 // Save the dirty bits. | 2223 // Save the dirty bits. |
| 2212 scheduled_updates_.push_back(UIUpdate(source, changed_flags)); | 2224 scheduled_updates_.push_back(UIUpdate(source, changed_flags)); |
| 2213 | 2225 |
| 2214 if (chrome_updater_factory_.empty()) { | 2226 if (chrome_updater_factory_.empty()) { |
| 2215 // No task currently scheduled, start another. | 2227 // No task currently scheduled, start another. |
| 2216 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 2228 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 2217 chrome_updater_factory_.NewRunnableMethod( | 2229 chrome_updater_factory_.NewRunnableMethod( |
| 2218 &Browser::ProcessPendingUIUpdates), | 2230 &Browser::ProcessPendingUIUpdates), |
| 2219 kUIUpdateCoalescingTimeMS); | 2231 kUIUpdateCoalescingTimeMS); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2279 if (flags & TabContents::INVALIDATE_FEEDLIST) | 2291 if (flags & TabContents::INVALIDATE_FEEDLIST) |
| 2280 window()->GetLocationBar()->UpdateFeedIcon(); | 2292 window()->GetLocationBar()->UpdateFeedIcon(); |
| 2281 | 2293 |
| 2282 // Updating the URL happens synchronously in ScheduleUIUpdate. | 2294 // Updating the URL happens synchronously in ScheduleUIUpdate. |
| 2283 | 2295 |
| 2284 if (flags & TabContents::INVALIDATE_LOAD && GetStatusBubble()) | 2296 if (flags & TabContents::INVALIDATE_LOAD && GetStatusBubble()) |
| 2285 GetStatusBubble()->SetStatus(GetSelectedTabContents()->GetStatusText()); | 2297 GetStatusBubble()->SetStatus(GetSelectedTabContents()->GetStatusText()); |
| 2286 | 2298 |
| 2287 if (invalidate_tab) { // INVALIDATE_TITLE or INVALIDATE_FAVICON. | 2299 if (invalidate_tab) { // INVALIDATE_TITLE or INVALIDATE_FAVICON. |
| 2288 tabstrip_model_.UpdateTabContentsStateAt( | 2300 tabstrip_model_.UpdateTabContentsStateAt( |
| 2289 tabstrip_model_.GetIndexOfController(contents->controller())); | 2301 tabstrip_model_.GetIndexOfController(contents->controller()), false); |
| 2290 window_->UpdateTitleBar(); | 2302 window_->UpdateTitleBar(); |
| 2291 | 2303 |
| 2292 if (contents == GetSelectedTabContents()) { | 2304 if (contents == GetSelectedTabContents()) { |
| 2293 TabContents* current_tab = GetSelectedTabContents(); | 2305 TabContents* current_tab = GetSelectedTabContents(); |
| 2294 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, | 2306 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, |
| 2295 current_tab->type() == TAB_CONTENTS_WEB && | 2307 current_tab->type() == TAB_CONTENTS_WEB && |
| 2296 !current_tab->GetFavIcon().isNull()); | 2308 !current_tab->GetFavIcon().isNull()); |
| 2297 } | 2309 } |
| 2298 } | 2310 } |
| 2299 | 2311 |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2509 | 2521 |
| 2510 // We need to register the window position pref. | 2522 // We need to register the window position pref. |
| 2511 std::wstring window_pref(prefs::kBrowserWindowPlacement); | 2523 std::wstring window_pref(prefs::kBrowserWindowPlacement); |
| 2512 window_pref.append(L"_"); | 2524 window_pref.append(L"_"); |
| 2513 window_pref.append(app_name); | 2525 window_pref.append(app_name); |
| 2514 PrefService* prefs = g_browser_process->local_state(); | 2526 PrefService* prefs = g_browser_process->local_state(); |
| 2515 DCHECK(prefs); | 2527 DCHECK(prefs); |
| 2516 | 2528 |
| 2517 prefs->RegisterDictionaryPref(window_pref.c_str()); | 2529 prefs->RegisterDictionaryPref(window_pref.c_str()); |
| 2518 } | 2530 } |
| OLD | NEW |