From 4fd793f802f5661357db22f09547cb97d7df05c2 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Thu, 23 Sep 2010 16:05:10 +0000 Subject: [PATCH] Add CefBrowser::ReloadIgnoreCache() method and MENU_ID_NAV_RELOAD_NOCACHE menu support. (issue #118). git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@107 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- include/cef.h | 3 +++ include/cef_capi.h | 3 +++ include/cef_types.h | 3 ++- libcef/browser_impl.cc | 20 +++++++++++++++----- libcef/browser_impl.h | 7 +++++-- libcef/browser_navigation_controller.cc | 12 ++++++------ libcef/browser_navigation_controller.h | 4 ++-- libcef_dll/cpptoc/browser_cpptoc.cc | 10 ++++++++++ libcef_dll/ctocpp/browser_ctocpp.cc | 8 ++++++++ libcef_dll/ctocpp/browser_ctocpp.h | 1 + 10 files changed, 55 insertions(+), 16 deletions(-) diff --git a/include/cef.h b/include/cef.h index 488f0f6da..4d82663fa 100644 --- a/include/cef.h +++ b/include/cef.h @@ -361,6 +361,9 @@ public: // Reload the current page. /*--cef()--*/ virtual void Reload() =0; + // Reload the current page ignoring any cached data. + /*--cef()--*/ + virtual void ReloadIgnoreCache() =0; // Stop loading the page. /*--cef()--*/ virtual void StopLoad() =0; diff --git a/include/cef_capi.h b/include/cef_capi.h index 18ffc9695..00f0d9809 100644 --- a/include/cef_capi.h +++ b/include/cef_capi.h @@ -210,6 +210,9 @@ typedef struct _cef_browser_t // Reload the current page. void (CEF_CALLBACK *reload)(struct _cef_browser_t* self); + // Reload the current page ignoring any cached data. + void (CEF_CALLBACK *reload_ignore_cache)(struct _cef_browser_t* self); + // Stop loading the page. void (CEF_CALLBACK *stop_load)(struct _cef_browser_t* self); diff --git a/include/cef_types.h b/include/cef_types.h index eb736d5ff..f09890dad 100644 --- a/include/cef_types.h +++ b/include/cef_types.h @@ -185,7 +185,8 @@ enum cef_handler_menuid_t MENU_ID_NAV_BACK = 10, MENU_ID_NAV_FORWARD = 11, MENU_ID_NAV_RELOAD = 12, - MENU_ID_NAV_STOP = 13, + MENU_ID_NAV_RELOAD_NOCACHE = 13, + MENU_ID_NAV_STOP = 14, MENU_ID_UNDO = 20, MENU_ID_REDO = 21, MENU_ID_CUT = 22, diff --git a/libcef/browser_impl.cc b/libcef/browser_impl.cc index c6f3699e7..0ce51a1ff 100644 --- a/libcef/browser_impl.cc +++ b/libcef/browser_impl.cc @@ -136,6 +136,12 @@ void CefBrowserImpl::Reload() &CefBrowserImpl::UIT_HandleActionView, MENU_ID_NAV_RELOAD)); } +void CefBrowserImpl::ReloadIgnoreCache() +{ + CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableMethod(this, + &CefBrowserImpl::UIT_HandleActionView, MENU_ID_NAV_RELOAD_NOCACHE)); +} + void CefBrowserImpl::StopLoad() { CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableMethod(this, @@ -669,14 +675,15 @@ void CefBrowserImpl::UIT_GoBackOrForward(int offset) nav_controller_->GoToOffset(offset); } -void CefBrowserImpl::UIT_Reload() +void CefBrowserImpl::UIT_Reload(bool ignoreCache) { REQUIRE_UIT(); - nav_controller_->Reload(); + nav_controller_->Reload(ignoreCache); } bool CefBrowserImpl::UIT_Navigate(const BrowserNavigationEntry& entry, - bool reload) + bool reload, + bool ignoreCache) { REQUIRE_UIT(); @@ -704,7 +711,7 @@ bool CefBrowserImpl::UIT_Navigate(const BrowserNavigationEntry& entry, // If we are reloading, then WebKit will use the state of the current page. // Otherwise, we give it the state to navigate to. if (reload) { - frame->reload(); + frame->reload(ignoreCache); } else if (!entry.GetContentState().empty()) { DCHECK(entry.GetPageID() != -1); frame->loadHistoryItem( @@ -813,7 +820,10 @@ void CefBrowserImpl::UIT_HandleAction(CefHandler::MenuId menuId, UIT_GoBackOrForward(1); break; case MENU_ID_NAV_RELOAD: - UIT_Reload(); + UIT_Reload(false); + break; + case MENU_ID_NAV_RELOAD_NOCACHE: + UIT_Reload(true); break; case MENU_ID_NAV_STOP: if (GetWebView()) diff --git a/libcef/browser_impl.h b/libcef/browser_impl.h index ba9f9999f..16ed926f0 100644 --- a/libcef/browser_impl.h +++ b/libcef/browser_impl.h @@ -49,6 +49,7 @@ public: virtual bool CanGoForward(); virtual void GoForward(); virtual void Reload(); + virtual void ReloadIgnoreCache(); virtual void StopLoad(); virtual void SetFocus(bool enable); virtual CefWindowHandle GetWindowHandle(); @@ -183,8 +184,10 @@ public: const std::wstring& script_url, int start_line); void UIT_GoBackOrForward(int offset); - void UIT_Reload(); - bool UIT_Navigate(const BrowserNavigationEntry& entry, bool reload); + void UIT_Reload(bool ignoreCache); + bool UIT_Navigate(const BrowserNavigationEntry& entry, + bool reload, + bool ignoreCahce); void UIT_SetFocus(WebWidgetHost* host, bool enable); CefRefPtr UIT_CreatePopupWindow(const std::wstring& url); diff --git a/libcef/browser_navigation_controller.cc b/libcef/browser_navigation_controller.cc index 28342be01..89c73ea24 100644 --- a/libcef/browser_navigation_controller.cc +++ b/libcef/browser_navigation_controller.cc @@ -62,7 +62,7 @@ void BrowserNavigationController::Reset() { last_committed_entry_index_ = -1; } -void BrowserNavigationController::Reload() { +void BrowserNavigationController::Reload(bool ignoreCache) { // Base the navigation on where we are now... int current_index = GetCurrentEntryIndex(); @@ -74,7 +74,7 @@ void BrowserNavigationController::Reload() { DiscardPendingEntry(); pending_entry_index_ = current_index; - NavigateToPendingEntry(true); + NavigateToPendingEntry(true, ignoreCache); } void BrowserNavigationController::GoToOffset(int offset) { @@ -92,7 +92,7 @@ void BrowserNavigationController::GoToIndex(int index) { DiscardPendingEntry(); pending_entry_index_ = index; - NavigateToPendingEntry(false); + NavigateToPendingEntry(false, false); } void BrowserNavigationController::LoadEntry(BrowserNavigationEntry* entry) { @@ -101,7 +101,7 @@ void BrowserNavigationController::LoadEntry(BrowserNavigationEntry* entry) { // result in a download or a 'no content' response (e.g., a mailto: URL). DiscardPendingEntry(); pending_entry_ = entry; - NavigateToPendingEntry(false); + NavigateToPendingEntry(false, false); } @@ -218,14 +218,14 @@ int BrowserNavigationController::GetEntryIndexWithPageID(int32 page_id) const { return -1; } -void BrowserNavigationController::NavigateToPendingEntry(bool reload) { +void BrowserNavigationController::NavigateToPendingEntry(bool reload, bool ignoreCache) { // For session history navigations only the pending_entry_index_ is set. if (!pending_entry_) { DCHECK(pending_entry_index_ != -1); pending_entry_ = entries_[pending_entry_index_].get(); } - if (browser_->UIT_Navigate(*pending_entry_, reload)) { + if (browser_->UIT_Navigate(*pending_entry_, reload, ignoreCache)) { // Note: this is redundant if navigation completed synchronously because // DidNavigateToEntry call this as well. UpdateMaxPageID(); diff --git a/libcef/browser_navigation_controller.h b/libcef/browser_navigation_controller.h index 337b98952..edbf79a3e 100644 --- a/libcef/browser_navigation_controller.h +++ b/libcef/browser_navigation_controller.h @@ -103,7 +103,7 @@ class BrowserNavigationController { void Reset(); // Causes the controller to reload the current (or pending) entry. - void Reload(); + void Reload(bool ignoreCache); // Causes the controller to go to the specified offset from current. Does // nothing if out of bounds. @@ -176,7 +176,7 @@ class BrowserNavigationController { void InsertEntry(BrowserNavigationEntry* entry); int GetMaxPageID() const { return max_page_id_; } - void NavigateToPendingEntry(bool reload); + void NavigateToPendingEntry(bool reload, bool ignoreCache); // Return the index of the entry with the corresponding type and page_id, // or -1 if not found. diff --git a/libcef_dll/cpptoc/browser_cpptoc.cc b/libcef_dll/cpptoc/browser_cpptoc.cc index cac74e239..a2a85d400 100644 --- a/libcef_dll/cpptoc/browser_cpptoc.cc +++ b/libcef_dll/cpptoc/browser_cpptoc.cc @@ -103,6 +103,15 @@ void CEF_CALLBACK browser_reload(struct _cef_browser_t* self) CefBrowserCppToC::Get(self)->Reload(); } +void CEF_CALLBACK browser_reload_ignore_cache(struct _cef_browser_t* self) +{ + DCHECK(self); + if(!self) + return; + + CefBrowserCppToC::Get(self)->ReloadIgnoreCache(); +} + void CEF_CALLBACK browser_stop_load(struct _cef_browser_t* self) { DCHECK(self); @@ -255,6 +264,7 @@ CefBrowserCppToC::CefBrowserCppToC(CefBrowser* cls) struct_.struct_.can_go_forward = browser_can_go_forward; struct_.struct_.go_forward = browser_go_forward; struct_.struct_.reload = browser_reload; + struct_.struct_.reload_ignore_cache = browser_reload_ignore_cache; struct_.struct_.stop_load = browser_stop_load; struct_.struct_.set_focus = browser_set_focus; struct_.struct_.get_window_handle = browser_get_window_handle; diff --git a/libcef_dll/ctocpp/browser_ctocpp.cc b/libcef_dll/ctocpp/browser_ctocpp.cc index f2effb815..8ee07e2bf 100644 --- a/libcef_dll/ctocpp/browser_ctocpp.cc +++ b/libcef_dll/ctocpp/browser_ctocpp.cc @@ -77,6 +77,14 @@ void CefBrowserCToCpp::Reload() struct_->reload(struct_); } +void CefBrowserCToCpp::ReloadIgnoreCache() +{ + if(CEF_MEMBER_MISSING(struct_, reload)) + return; + + struct_->reload_ignore_cache(struct_); +} + void CefBrowserCToCpp::StopLoad() { if(CEF_MEMBER_MISSING(struct_, stop_load)) diff --git a/libcef_dll/ctocpp/browser_ctocpp.h b/libcef_dll/ctocpp/browser_ctocpp.h index 74398f6db..f0c324a46 100644 --- a/libcef_dll/ctocpp/browser_ctocpp.h +++ b/libcef_dll/ctocpp/browser_ctocpp.h @@ -36,6 +36,7 @@ public: virtual bool CanGoForward(); virtual void GoForward(); virtual void Reload(); + virtual void ReloadIgnoreCache(); virtual void StopLoad(); virtual void SetFocus(bool enable); virtual CefWindowHandle GetWindowHandle();