diff options
author | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-19 10:51:16 +0000 |
---|---|---|
committer | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-19 10:51:16 +0000 |
commit | 1ccb3568d81cf47adf6f062067c186fdf43dd56d (patch) | |
tree | b8200bd953cbc88db64a09cc8fb6f7eca7237088 | |
parent | 0f0acb414b3e4ad3febc85bc3e6364a8b206ab76 (diff) | |
download | chromium_src-1ccb3568d81cf47adf6f062067c186fdf43dd56d.zip chromium_src-1ccb3568d81cf47adf6f062067c186fdf43dd56d.tar.gz chromium_src-1ccb3568d81cf47adf6f062067c186fdf43dd56d.tar.bz2 |
linux: plumb shift-reload down into new shift-reload API
Currently Linux-only, but the Mac/Win bits should now be trivial.
While I was add it, I tweaked a NavigationController function
that took a bare boolean into an enum to make the call sites more
explicit about what they're doing.
(In most places I added new functions that call into a shared
backing function; this is so I don't need to change every single
caller of e.g. Reload() to pass through an extra flag that will
be the same for almost every caller.)
BUG=1906
TEST=visit astronomy picture of the day; hit reload, picture pops
up quickly; hit shift-reload, picture loads slowly
Review URL: http://codereview.chromium.org/594063
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39430 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/app/chrome_dll_resource.h | 3 | ||||
-rw-r--r-- | chrome/browser/browser.cc | 17 | ||||
-rw-r--r-- | chrome/browser/browser.h | 4 | ||||
-rw-r--r-- | chrome/browser/gtk/accelerators_gtk.cc | 5 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_toolbar_gtk.cc | 8 | ||||
-rw-r--r-- | chrome/browser/tab_contents/navigation_controller.cc | 26 | ||||
-rw-r--r-- | chrome/browser/tab_contents/navigation_controller.h | 13 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.cc | 26 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.h | 3 |
9 files changed, 82 insertions, 23 deletions
diff --git a/chrome/app/chrome_dll_resource.h b/chrome/app/chrome_dll_resource.h index c73243c..1d5caff 100644 --- a/chrome/app/chrome_dll_resource.h +++ b/chrome/app/chrome_dll_resource.h @@ -73,6 +73,9 @@ #define IDC_OPEN_CURRENT_URL 33004 #define IDC_GO 33005 #define IDC_STOP 33006 +// TODO: put this alongside RELOAD, next time someone wants to fix all +// the Mac ids. +#define IDC_RELOAD_IGNORING_CACHE 33007 // Window management commands #define IDC_NEW_WINDOW 34000 diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index ac41f0b..c5608a8 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -824,7 +824,15 @@ void Browser::GoForward(WindowOpenDisposition disp) { void Browser::Reload() { UserMetrics::RecordAction("Reload", profile_); + ReloadInternal(false); +} + +void Browser::ReloadIgnoringCache() { + UserMetrics::RecordAction("ReloadIgnoringCache", profile_); + ReloadInternal(true); +} +void Browser::ReloadInternal(bool ignore_cache) { // If we are showing an interstitial, treat this as an OpenURL. TabContents* current_tab = GetSelectedTabContents(); if (current_tab) { @@ -838,7 +846,10 @@ void Browser::Reload() { // As this is caused by a user action, give the focus to the page. if (!current_tab->FocusLocationBarByDefault()) current_tab->Focus(); - current_tab->controller().Reload(true); + if (ignore_cache) + current_tab->controller().ReloadIgnoringCache(true); + else + current_tab->controller().Reload(true); } } @@ -1469,6 +1480,7 @@ void Browser::ExecuteCommandWithDisposition( case IDC_BACK: GoBack(disposition); break; case IDC_FORWARD: GoForward(disposition); break; case IDC_RELOAD: Reload(); break; + case IDC_RELOAD_IGNORING_CACHE: ReloadIgnoringCache(); break; case IDC_HOME: Home(disposition); break; case IDC_OPEN_CURRENT_URL: OpenCurrentURL(); break; case IDC_GO: Go(disposition); break; @@ -2509,6 +2521,7 @@ void Browser::InitCommandState() { // Navigation commands command_updater_.UpdateCommandEnabled(IDC_RELOAD, true); + command_updater_.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE, true); // Window management commands command_updater_.UpdateCommandEnabled(IDC_NEW_WINDOW, true); @@ -2700,6 +2713,8 @@ void Browser::UpdateCommandsForTabState() { // Disable certain items if running DevTools command_updater_.UpdateCommandEnabled(IDC_RELOAD, CanReloadContents(current_tab)); + command_updater_.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE, + CanReloadContents(current_tab)); bool enabled_for_non_devtools = type() != TYPE_DEVTOOLS; command_updater_.UpdateCommandEnabled(IDC_FIND, enabled_for_non_devtools); command_updater_.UpdateCommandEnabled(IDC_FIND_NEXT, diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h index 1dbf26e..ed5c28a 100644 --- a/chrome/browser/browser.h +++ b/chrome/browser/browser.h @@ -350,6 +350,7 @@ class Browser : public TabStripModelDelegate, void GoBack(WindowOpenDisposition disposition); void GoForward(WindowOpenDisposition disposition); void Reload(); + void ReloadIgnoringCache(); // AKA shift-reload. void Home(WindowOpenDisposition disposition); void OpenCurrentURL(); void Go(WindowOpenDisposition disposition); @@ -773,6 +774,9 @@ class Browser : public TabStripModelDelegate, void SetAppExtensionById(TabContents* contents, const std::string& app_extension_id); + // Shared code between Reload() and ReloadAll(). + void ReloadInternal(bool ignore_cache); + // Data members ///////////////////////////////////////////////////////////// NotificationRegistrar registrar_; diff --git a/chrome/browser/gtk/accelerators_gtk.cc b/chrome/browser/gtk/accelerators_gtk.cc index fa043d1..c815598 100644 --- a/chrome/browser/gtk/accelerators_gtk.cc +++ b/chrome/browser/gtk/accelerators_gtk.cc @@ -120,9 +120,10 @@ const struct AcceleratorMapping { { GDK_Right, IDC_FORWARD, GDK_MOD1_MASK }, { XF86XK_Forward, IDC_FORWARD, GdkModifierType(0) }, { GDK_r, IDC_RELOAD, GDK_CONTROL_MASK }, + { GDK_r, IDC_RELOAD_IGNORING_CACHE, + GdkModifierType(GDK_CONTROL_MASK|GDK_SHIFT_MASK) }, { GDK_F5, IDC_RELOAD, GdkModifierType(0) }, - { GDK_F5, IDC_RELOAD, GDK_CONTROL_MASK }, - { GDK_F5, IDC_RELOAD, GDK_SHIFT_MASK }, + { GDK_F5, IDC_RELOAD_IGNORING_CACHE, GDK_SHIFT_MASK }, { XF86XK_Reload, IDC_RELOAD, GdkModifierType(0) }, { XF86XK_Refresh, IDC_RELOAD, GdkModifierType(0) }, diff --git a/chrome/browser/gtk/browser_toolbar_gtk.cc b/chrome/browser/gtk/browser_toolbar_gtk.cc index af78212..05d10e1 100644 --- a/chrome/browser/gtk/browser_toolbar_gtk.cc +++ b/chrome/browser/gtk/browser_toolbar_gtk.cc @@ -626,7 +626,13 @@ void BrowserToolbarGtk::OnButtonClick(GtkWidget* button, int tag = -1; if (button == toolbar->reload_->widget()) { - tag = IDC_RELOAD; + GdkModifierType modifier_state; + if (gtk_get_current_event_state(&modifier_state) && + modifier_state & GDK_SHIFT_MASK) { + tag = IDC_RELOAD_IGNORING_CACHE; + } else { + tag = IDC_RELOAD; + } toolbar->location_bar_->Revert(); } else if (toolbar->home_.get() && button == toolbar->home_->widget()) { tag = IDC_HOME; diff --git a/chrome/browser/tab_contents/navigation_controller.cc b/chrome/browser/tab_contents/navigation_controller.cc index 58d4123..3edb1ce 100644 --- a/chrome/browser/tab_contents/navigation_controller.cc +++ b/chrome/browser/tab_contents/navigation_controller.cc @@ -173,6 +173,14 @@ void NavigationController::RestoreFromState( } void NavigationController::Reload(bool check_for_repost) { + ReloadInternal(check_for_repost, RELOAD); +} +void NavigationController::ReloadIgnoringCache(bool check_for_repost) { + ReloadInternal(check_for_repost, RELOAD_IGNORING_CACHE); +} + +void NavigationController::ReloadInternal(bool check_for_repost, + ReloadType reload_type) { // Reloading a transient entry does nothing. if (transient_entry_index_ != -1) return; @@ -199,7 +207,7 @@ void NavigationController::Reload(bool check_for_repost) { pending_entry_index_ = current_index; entries_[pending_entry_index_]->set_transition_type(PageTransition::RELOAD); - NavigateToPendingEntry(true); + NavigateToPendingEntry(reload_type); } } @@ -224,7 +232,7 @@ void NavigationController::LoadEntry(NavigationEntry* entry) { NotificationType::NAV_ENTRY_PENDING, Source<NavigationController>(this), NotificationService::NoDetails()); - NavigateToPendingEntry(false); + NavigateToPendingEntry(NO_RELOAD); } NavigationEntry* NavigationController::GetActiveEntry() const { @@ -288,7 +296,7 @@ void NavigationController::GoBack() { DiscardNonCommittedEntries(); pending_entry_index_ = current_index - 1; - NavigateToPendingEntry(false); + NavigateToPendingEntry(NO_RELOAD); } void NavigationController::GoForward() { @@ -310,7 +318,7 @@ void NavigationController::GoForward() { if (!transient) pending_entry_index_++; - NavigateToPendingEntry(false); + NavigateToPendingEntry(NO_RELOAD); } void NavigationController::GoToIndex(int index) { @@ -333,7 +341,7 @@ void NavigationController::GoToIndex(int index) { DiscardNonCommittedEntries(); pending_entry_index_ = index; - NavigateToPendingEntry(false); + NavigateToPendingEntry(NO_RELOAD); } void NavigationController::GoToOffset(int offset) { @@ -360,7 +368,7 @@ void NavigationController::RemoveEntryAtIndex(int index, // We removed the currently shown entry, so we have to load something else. if (last_committed_entry_index_ != -1) { pending_entry_index_ = last_committed_entry_index_; - NavigateToPendingEntry(false); + NavigateToPendingEntry(NO_RELOAD); } else { // If there is nothing to show, show a default page. LoadURL(default_url.is_empty() ? GURL("about:blank") : default_url, @@ -940,7 +948,7 @@ void NavigationController::SetWindowID(const SessionID& id) { NotificationService::NoDetails()); } -void NavigationController::NavigateToPendingEntry(bool reload) { +void NavigationController::NavigateToPendingEntry(ReloadType reload_type) { needs_reload_ = false; // For session history navigations only the pending_entry_index_ is set. @@ -949,7 +957,7 @@ void NavigationController::NavigateToPendingEntry(bool reload) { pending_entry_ = entries_[pending_entry_index_].get(); } - if (!tab_contents_->NavigateToPendingEntry(reload)) + if (!tab_contents_->NavigateToPendingEntry(reload_type)) DiscardNonCommittedEntries(); } @@ -995,7 +1003,7 @@ void NavigationController::LoadIfNecessary() { // Explicitly use NavigateToPendingEntry so that the renderer uses the // cached state. pending_entry_index_ = last_committed_entry_index_; - NavigateToPendingEntry(false); + NavigateToPendingEntry(NO_RELOAD); } void NavigationController::NotifyEntryChanged(const NavigationEntry* entry, diff --git a/chrome/browser/tab_contents/navigation_controller.h b/chrome/browser/tab_contents/navigation_controller.h index 2aba4fe..810f8b9 100644 --- a/chrome/browser/tab_contents/navigation_controller.h +++ b/chrome/browser/tab_contents/navigation_controller.h @@ -133,6 +133,12 @@ class NavigationController { int count; }; + enum ReloadType { + NO_RELOAD, // Normal load. + RELOAD, // Normal (cache-validating) reload. + RELOAD_IGNORING_CACHE // Reload bypassing the cache, aka shift-reload. + }; + // --------------------------------------------------------------------------- NavigationController(TabContents* tab_contents, Profile* profile); @@ -286,6 +292,8 @@ class NavigationController { // entry has POST data the user is prompted to see if they really want to // reload the page. In nearly all cases pass in true. void Reload(bool check_for_repost); + // Like Reload(), but don't use caches (aka "shift-reload"). + void ReloadIgnoringCache(bool check_for_repost); // Removing of entries ------------------------------------------------------- @@ -431,8 +439,11 @@ class NavigationController { bool RendererDidNavigateAutoSubframe( const ViewHostMsg_FrameNavigate_Params& params); + // Helper function for code shared between Reload() and ReloadAll(). + void ReloadInternal(bool check_for_repost, ReloadType reload_type); + // Actually issues the navigation held in pending_entry. - void NavigateToPendingEntry(bool reload); + void NavigateToPendingEntry(ReloadType reload_type); // Allows the derived class to issue notifications that a load has been // committed. This will fill in the active entry to the details structure. diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index f050c93..82ec6f0 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -186,9 +186,16 @@ BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) { #endif ViewMsg_Navigate_Params::NavigationType GetNavigationType( - Profile* profile, const NavigationEntry& entry, bool reload) { - if (reload) - return ViewMsg_Navigate_Params::RELOAD; + Profile* profile, const NavigationEntry& entry, + NavigationController::ReloadType reload_type) { + switch (reload_type) { + case NavigationController::RELOAD: + return ViewMsg_Navigate_Params::RELOAD; + case NavigationController::RELOAD_IGNORING_CACHE: + return ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE; + case NavigationController::NO_RELOAD: + break; // Fall through to rest of function. + } if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION && profile->DidLastSessionExitCleanly()) @@ -198,13 +205,14 @@ ViewMsg_Navigate_Params::NavigationType GetNavigationType( } void MakeNavigateParams(Profile* profile, const NavigationEntry& entry, - bool reload, ViewMsg_Navigate_Params* params) { + NavigationController::ReloadType reload_type, + ViewMsg_Navigate_Params* params) { params->page_id = entry.page_id(); params->url = entry.url(); params->referrer = entry.referrer(); params->transition = entry.transition_type(); params->state = entry.content_state(); - params->navigation_type = GetNavigationType(profile, entry, reload); + params->navigation_type = GetNavigationType(profile, entry, reload_type); params->request_time = base::Time::Now(); } @@ -703,7 +711,8 @@ void TabContents::OpenURL(const GURL& url, const GURL& referrer, delegate_->OpenURLFromTab(this, url, referrer, disposition, transition); } -bool TabContents::NavigateToPendingEntry(bool reload) { +bool TabContents::NavigateToPendingEntry( + NavigationController::ReloadType reload_type) { const NavigationEntry& entry = *controller_.pending_entry(); RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry); @@ -724,7 +733,7 @@ bool TabContents::NavigateToPendingEntry(bool reload) { // Navigate in the desired RenderViewHost. ViewMsg_Navigate_Params navigate_params; - MakeNavigateParams(profile(), entry, reload, &navigate_params); + MakeNavigateParams(profile(), entry, reload_type, &navigate_params); dest_render_view_host->Navigate(navigate_params); if (entry.page_id() == -1) { @@ -742,7 +751,8 @@ bool TabContents::NavigateToPendingEntry(bool reload) { // loading. GetPasswordManager()->ClearProvisionalSave(); - if (reload && !profile()->IsOffTheRecord()) { + if (reload_type != NavigationController::NO_RELOAD && + !profile()->IsOffTheRecord()) { FaviconService* favicon_service = profile()->GetFaviconService(Profile::IMPLICIT_ACCESS); if (favicon_service) diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h index 4d11745..1553032 100644 --- a/chrome/browser/tab_contents/tab_contents.h +++ b/chrome/browser/tab_contents/tab_contents.h @@ -321,7 +321,8 @@ class TabContents : public PageNavigator, // // If this method returns false, then the navigation is discarded (equivalent // to calling DiscardPendingEntry on the NavigationController). - virtual bool NavigateToPendingEntry(bool reload); + virtual bool NavigateToPendingEntry( + NavigationController::ReloadType reload_type); // Stop any pending navigation. virtual void Stop(); |