summaryrefslogtreecommitdiffstats
path: root/content/browser/devtools/renderer_overrides_handler.cc
diff options
context:
space:
mode:
authorkaznacheev@chromium.org <kaznacheev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-06 20:11:43 +0000
committerkaznacheev@chromium.org <kaznacheev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-06 20:11:43 +0000
commit990222767c6407f91804875827cdb7bb08929e9c (patch)
tree416757c419577aa30e7877f947460e74e36d68eb /content/browser/devtools/renderer_overrides_handler.cc
parentdb4fc1e2a877bb9d6871274af4e75180856f7560 (diff)
downloadchromium_src-990222767c6407f91804875827cdb7bb08929e9c.zip
chromium_src-990222767c6407f91804875827cdb7bb08929e9c.tar.gz
chromium_src-990222767c6407f91804875827cdb7bb08929e9c.tar.bz2
Support Page.getNavigationHistory and Page.navigateToHistoryEntry in RendererOverridesHandler
BUG=285169 Review URL: https://chromiumcodereview.appspot.com/23943004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221763 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/devtools/renderer_overrides_handler.cc')
-rw-r--r--content/browser/devtools/renderer_overrides_handler.cc75
1 files changed, 75 insertions, 0 deletions
diff --git a/content/browser/devtools/renderer_overrides_handler.cc b/content/browser/devtools/renderer_overrides_handler.cc
index f397038..c0574d8 100644
--- a/content/browser/devtools/renderer_overrides_handler.cc
+++ b/content/browser/devtools/renderer_overrides_handler.cc
@@ -24,6 +24,7 @@
#include "content/public/browser/devtools_agent_host.h"
#include "content/public/browser/javascript_dialog_manager.h"
#include "content/public/browser/navigation_controller.h"
+#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host_view.h"
@@ -96,6 +97,16 @@ RendererOverridesHandler::RendererOverridesHandler(DevToolsAgentHost* agent)
&RendererOverridesHandler::PageNavigate,
base::Unretained(this)));
RegisterCommandHandler(
+ devtools::Page::getNavigationHistory::kName,
+ base::Bind(
+ &RendererOverridesHandler::PageGetNavigationHistory,
+ base::Unretained(this)));
+ RegisterCommandHandler(
+ devtools::Page::navigateToHistoryEntry::kName,
+ base::Bind(
+ &RendererOverridesHandler::PageNavigateToHistoryEntry,
+ base::Unretained(this)));
+ RegisterCommandHandler(
devtools::Page::captureScreenshot::kName,
base::Bind(
&RendererOverridesHandler::PageCaptureScreenshot,
@@ -300,6 +311,70 @@ RendererOverridesHandler::PageNavigate(
}
scoped_refptr<DevToolsProtocol::Response>
+RendererOverridesHandler::PageGetNavigationHistory(
+ scoped_refptr<DevToolsProtocol::Command> command) {
+ RenderViewHost* host = agent_->GetRenderViewHost();
+ if (host) {
+ WebContents* web_contents = host->GetDelegate()->GetAsWebContents();
+ if (web_contents) {
+ base::DictionaryValue* result = new base::DictionaryValue();
+ NavigationController& controller = web_contents->GetController();
+ result->SetInteger(
+ devtools::Page::getNavigationHistory::kResponseCurrentIndex,
+ controller.GetCurrentEntryIndex());
+ ListValue* entries = new ListValue();
+ for (int i = 0; i != controller.GetEntryCount(); ++i) {
+ const NavigationEntry* entry = controller.GetEntryAtIndex(i);
+ base::DictionaryValue* entry_value = new base::DictionaryValue();
+ entry_value->SetInteger(
+ devtools::Page::getNavigationHistory::kResponseEntryId,
+ entry->GetUniqueID());
+ entry_value->SetString(
+ devtools::Page::getNavigationHistory::kResponseEntryURL,
+ entry->GetURL().spec());
+ entry_value->SetString(
+ devtools::Page::getNavigationHistory::kResponseEntryTitle,
+ entry->GetTitle());
+ entries->Append(entry_value);
+ }
+ result->Set(
+ devtools::Page::getNavigationHistory::kResponseEntries,
+ entries);
+ return command->SuccessResponse(result);
+ }
+ }
+ return command->InternalErrorResponse("No WebContents to navigate");
+}
+
+scoped_refptr<DevToolsProtocol::Response>
+RendererOverridesHandler::PageNavigateToHistoryEntry(
+ scoped_refptr<DevToolsProtocol::Command> command) {
+ int entry_id;
+
+ base::DictionaryValue* params = command->params();
+ const char* param = devtools::Page::navigateToHistoryEntry::kParamEntryId;
+ if (!params || !params->GetInteger(param, &entry_id)) {
+ return command->InvalidParamResponse(param);
+ }
+
+ RenderViewHost* host = agent_->GetRenderViewHost();
+ if (host) {
+ WebContents* web_contents = host->GetDelegate()->GetAsWebContents();
+ if (web_contents) {
+ NavigationController& controller = web_contents->GetController();
+ for (int i = 0; i != controller.GetEntryCount(); ++i) {
+ if (controller.GetEntryAtIndex(i)->GetUniqueID() == entry_id) {
+ controller.GoToIndex(i);
+ return command->SuccessResponse(new base::DictionaryValue());
+ }
+ }
+ return command->InvalidParamResponse(param);
+ }
+ }
+ return command->InternalErrorResponse("No WebContents to navigate");
+}
+
+scoped_refptr<DevToolsProtocol::Response>
RendererOverridesHandler::PageCaptureScreenshot(
scoped_refptr<DevToolsProtocol::Command> command) {
std::string format;