Hijack the Page.reload command

This commit is contained in:
Cheng Zhao 2016-04-12 16:35:35 +09:00
parent 3d3cc8c226
commit 11685faffa
2 changed files with 12 additions and 0 deletions

View file

@ -10,6 +10,7 @@ class InspectableWebContentsDelegate {
virtual ~InspectableWebContentsDelegate() {}
// Requested by WebContents of devtools.
virtual void DevToolsReloadPage() {}
virtual void DevToolsSaveToFile(
const std::string& url, const std::string& content, bool save_as) {}
virtual void DevToolsAppendToFile(

View file

@ -18,6 +18,7 @@
#include "base/prefs/pref_registry_simple.h"
#include "base/prefs/pref_service.h"
#include "base/prefs/scoped_user_pref_update.h"
#include "base/strings/pattern.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
@ -480,6 +481,16 @@ void InspectableWebContentsImpl::SetDevicesUpdatesEnabled(bool enabled) {
void InspectableWebContentsImpl::DispatchProtocolMessageFromDevToolsFrontend(
const std::string& message) {
// If the devtools wants to reload the page, hijack the message and handle it
// to the delegate.
if (base::MatchPattern(message, "{\"id\":*,"
"\"method\":\"Page.reload\","
"\"params\":*}")) {
if (delegate_)
delegate_->DevToolsReloadPage();
return;
}
if (agent_host_.get())
agent_host_->DispatchProtocolMessage(message);
}