diff --git a/include/internal/cef_types.h b/include/internal/cef_types.h index 5fc046c9d..98e1e2509 100644 --- a/include/internal/cef_types.h +++ b/include/internal/cef_types.h @@ -190,6 +190,11 @@ typedef struct _cef_browser_settings_t /// bool load_drops_disabled; + /// + // Disable history back/forward navigation. + /// + bool history_disabled; + // The below values map to WebPreferences settings. /// diff --git a/include/internal/cef_types_wrappers.h b/include/internal/cef_types_wrappers.h index b2bc07b90..89eb2cefb 100644 --- a/include/internal/cef_types_wrappers.h +++ b/include/internal/cef_types_wrappers.h @@ -324,6 +324,7 @@ struct CefBrowserSettingsTraits { { target->drag_drop_disabled = src->drag_drop_disabled; target->load_drops_disabled = src->load_drops_disabled; + target->history_disabled = src->history_disabled; cef_string_set(src->standard_font_family.str, src->standard_font_family.length, &target->standard_font_family, copy); diff --git a/libcef/browser_navigation_controller.cc b/libcef/browser_navigation_controller.cc index a7cd84ec2..6ad9138d4 100644 --- a/libcef/browser_navigation_controller.cc +++ b/libcef/browser_navigation_controller.cc @@ -43,11 +43,12 @@ void BrowserNavigationEntry::SetContentState(const std::string& state) { // ---------------------------------------------------------------------------- // BrowserNavigationController -BrowserNavigationController::BrowserNavigationController(CefBrowserImpl* shell) +BrowserNavigationController::BrowserNavigationController( + CefBrowserImpl* browser) : pending_entry_(NULL), last_committed_entry_index_(-1), pending_entry_index_(-1), - browser_(shell), + browser_(browser), max_page_id_(-1) { } @@ -60,6 +61,7 @@ void BrowserNavigationController::Reset() { DiscardPendingEntry(); last_committed_entry_index_ = -1; + UpdateMaxPageID(); } void BrowserNavigationController::Reload(bool ignoreCache) { @@ -198,12 +200,19 @@ void BrowserNavigationController::DiscardPendingEntry() { void BrowserNavigationController::InsertEntry(BrowserNavigationEntry* entry) { DiscardPendingEntry(); - // Prune any entry which are in front of the current entry - int current_size = static_cast(entries_.size()); - if (current_size > 0) { - while (last_committed_entry_index_ < (current_size - 1)) { - entries_.pop_back(); - current_size--; + const CefBrowserSettings& settings = browser_->settings(); + if (settings.history_disabled) { + // History is disabled. Remove any existing entries. + if (entries_.size() > 0) + entries_.clear(); + } else { + // Prune any entry which are in front of the current entry. + int current_size = static_cast(entries_.size()); + if (current_size > 0) { + while (last_committed_entry_index_ < (current_size - 1)) { + entries_.pop_back(); + current_size--; + } } } diff --git a/libcef/browser_navigation_controller.h b/libcef/browser_navigation_controller.h index 42a057804..e0148bc96 100644 --- a/libcef/browser_navigation_controller.h +++ b/libcef/browser_navigation_controller.h @@ -97,7 +97,7 @@ private: // version as possible. class BrowserNavigationController { public: - BrowserNavigationController(CefBrowserImpl* shell); + BrowserNavigationController(CefBrowserImpl* browser); ~BrowserNavigationController(); void Reset(); diff --git a/tests/cefclient/cefclient.cpp b/tests/cefclient/cefclient.cpp index c1e908724..34c9d706a 100644 --- a/tests/cefclient/cefclient.cpp +++ b/tests/cefclient/cefclient.cpp @@ -197,6 +197,8 @@ void AppGetBrowserSettings(CefBrowserSettings& settings) g_command_line->HasSwitch(cefclient::kDragDropDisabled); settings.load_drops_disabled = g_command_line->HasSwitch(cefclient::kLoadDropsDisabled); + settings.history_disabled = + g_command_line->HasSwitch(cefclient::kHistoryDisabled); settings.remote_fonts_disabled = g_command_line->HasSwitch(cefclient::kRemoteFontsDisabled); diff --git a/tests/cefclient/cefclient_switches.cpp b/tests/cefclient/cefclient_switches.cpp index 060493886..1f9f74418 100644 --- a/tests/cefclient/cefclient_switches.cpp +++ b/tests/cefclient/cefclient_switches.cpp @@ -32,6 +32,7 @@ const char kJavascriptFlags[] = "javascript-flags"; // CefBrowserSettings attributes. const char kDragDropDisabled[] = "drag-drop-disabled"; const char kLoadDropsDisabled[] = "load-drops-disabled"; +const char kHistoryDisabled[] = "history-disabled"; const char kRemoteFontsDisabled[] = "remote-fonts-disabled"; const char kDefaultEncoding[] = "default-encoding"; const char kEncodingDetectorEnabled[] = "encoding-detector-enabled"; diff --git a/tests/cefclient/cefclient_switches.h b/tests/cefclient/cefclient_switches.h index 40594abf8..9080c88fc 100644 --- a/tests/cefclient/cefclient_switches.h +++ b/tests/cefclient/cefclient_switches.h @@ -35,6 +35,7 @@ extern const char kJavascriptFlags[]; // CefBrowserSettings attributes. extern const char kDragDropDisabled[]; extern const char kLoadDropsDisabled[]; +extern const char kHistoryDisabled[]; extern const char kRemoteFontsDisabled[]; extern const char kDefaultEncoding[]; extern const char kEncodingDetectorEnabled[];