Index: chrome/test/chromedriver/chrome/web_view_impl.cc |
diff --git a/chrome/test/chromedriver/chrome/web_view_impl.cc b/chrome/test/chromedriver/chrome/web_view_impl.cc |
index 9a366c5d2819a238764c64207f3b12017d84233a..806a82c7145d6f26c7679ced3c221bfb44e3384c 100644 |
--- a/chrome/test/chromedriver/chrome/web_view_impl.cc |
+++ b/chrome/test/chromedriver/chrome/web_view_impl.cc |
@@ -172,8 +172,20 @@ Status WebViewImpl::TraverseHistory(int delta) { |
scoped_ptr<base::DictionaryValue> result; |
Status status = client_->SendCommandAndGetResult( |
"Page.getNavigationHistory", params, &result); |
- if (status.IsError()) |
- return status; |
+ if (status.IsError()) { |
+ // TODO(samuong): remove this once we stop supporting WebView on KitKat. |
+ // Older versions of WebView on Android (on KitKat and earlier) do not have |
+ // the Page.getNavigationHistory DevTools command handler, so fall back to |
+ // using JavaScript to navigate back and forward. WebView reports its build |
+ // number as 0, so use the error message to detect if we can't use the |
+ // DevTools command. |
+ std::string message; |
+ result->GetString("message", &message); |
+ if (message == "'Page.getNavigationHistory' wasn't found") |
+ return TraverseHistoryWithJavaScript(delta); |
+ else |
+ return status; |
+ } |
int current_index; |
if (!result->GetInteger("currentIndex", ¤t_index)) |
@@ -199,6 +211,16 @@ Status WebViewImpl::TraverseHistory(int delta) { |
return client_->SendCommand("Page.navigateToHistoryEntry", params); |
} |
+Status WebViewImpl::TraverseHistoryWithJavaScript(int delta) { |
+ scoped_ptr<base::Value> value; |
+ if (delta == -1) |
+ return EvaluateScript(std::string(), "window.history.back();", &value); |
+ else if (delta == 1) |
+ return EvaluateScript(std::string(), "window.history.forward();", &value); |
+ else |
+ return Status(kUnknownError, "expected delta to be 1 or -1"); |
+} |
+ |
Status WebViewImpl::EvaluateScript(const std::string& frame, |
const std::string& expression, |
scoped_ptr<base::Value>* result) { |