From 11685faffa9c7664198cbdeb16c37fafba3a0428 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 12 Apr 2016 16:35:35 +0900 Subject: [PATCH] Hijack the Page.reload command --- brightray/browser/inspectable_web_contents_delegate.h | 1 + brightray/browser/inspectable_web_contents_impl.cc | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/brightray/browser/inspectable_web_contents_delegate.h b/brightray/browser/inspectable_web_contents_delegate.h index e9f071cb4d..7f004dd4fb 100644 --- a/brightray/browser/inspectable_web_contents_delegate.h +++ b/brightray/browser/inspectable_web_contents_delegate.h @@ -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( diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 9484593de4..6454405895 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -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); }