diff --git a/brightray/browser/devtools_embedder_message_dispatcher.cc b/brightray/browser/devtools_embedder_message_dispatcher.cc index cb44ec16d86..2a4b3817659 100644 --- a/brightray/browser/devtools_embedder_message_dispatcher.cc +++ b/brightray/browser/devtools_embedder_message_dispatcher.cc @@ -195,6 +195,11 @@ DevToolsEmbedderMessageDispatcher::CreateForDevToolsFrontend( d->RegisterHandler("recordActionUMA", &Delegate::RecordActionUMA, delegate); d->RegisterHandlerWithCallback("sendJsonRequest", &Delegate::SendJsonRequest, delegate); + d->RegisterHandlerWithCallback("getPreferences", + &Delegate::GetPreferences, delegate); + d->RegisterHandler("setPreference", &Delegate::SetPreference, delegate); + d->RegisterHandler("removePreference", &Delegate::RemovePreference, delegate); + d->RegisterHandler("clearPreferences", &Delegate::ClearPreferences, delegate); return d; } diff --git a/brightray/browser/devtools_embedder_message_dispatcher.h b/brightray/browser/devtools_embedder_message_dispatcher.h index 851a2f49058..46f54dfbf2c 100644 --- a/brightray/browser/devtools_embedder_message_dispatcher.h +++ b/brightray/browser/devtools_embedder_message_dispatcher.h @@ -73,6 +73,11 @@ class DevToolsEmbedderMessageDispatcher { virtual void SendJsonRequest(const DispatchCallback& callback, const std::string& browser_id, const std::string& url) = 0; + virtual void GetPreferences(const DispatchCallback& callback) = 0; + virtual void SetPreference(const std::string& name, + const std::string& value) = 0; + virtual void RemovePreference(const std::string& name) = 0; + virtual void ClearPreferences() = 0; }; using DispatchCallback = Delegate::DispatchCallback; diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 80b142c4ad6..6d2f24fae4c 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -17,6 +17,7 @@ #include "base/metrics/histogram.h" #include "base/prefs/pref_registry_simple.h" #include "base/prefs/pref_service.h" +#include "base/prefs/scoped_user_pref_update.h" #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" #include "base/values.h" @@ -44,6 +45,7 @@ const char kChromeUIDevToolsURL[] = "chrome-devtools://devtools/devtools.html?" "experiments=true"; const char kDevToolsBoundsPref[] = "brightray.devtools.bounds"; const char kDevToolsZoomPref[] = "brightray.devtools.zoom"; +const char kDevToolsPreferences[] = "brightray.devtools.preferences"; const char kFrontendHostId[] = "id"; const char kFrontendHostMethod[] = "method"; @@ -160,6 +162,7 @@ void InspectableWebContentsImpl::RegisterPrefs(PrefRegistrySimple* registry) { RectToDictionary(gfx::Rect(0, 0, 800, 600), bounds_dict.get()); registry->RegisterDictionaryPref(kDevToolsBoundsPref, bounds_dict.release()); registry->RegisterDoublePref(kDevToolsZoomPref, 0.); + registry->RegisterDictionaryPref(kDevToolsPreferences); } InspectableWebContentsImpl::InspectableWebContentsImpl( @@ -469,6 +472,29 @@ void InspectableWebContentsImpl::SendJsonRequest(const DispatchCallback& callbac callback.Run(nullptr); } +void InspectableWebContentsImpl::GetPreferences( + const DispatchCallback& callback) { + const base::DictionaryValue* prefs = pref_service_->GetDictionary( + kDevToolsPreferences); + callback.Run(prefs); +} + +void InspectableWebContentsImpl::SetPreference(const std::string& name, + const std::string& value) { + DictionaryPrefUpdate update(pref_service_, kDevToolsPreferences); + update.Get()->SetStringWithoutPathExpansion(name, value); +} + +void InspectableWebContentsImpl::RemovePreference(const std::string& name) { + DictionaryPrefUpdate update(pref_service_, kDevToolsPreferences); + update.Get()->RemoveWithoutPathExpansion(name, nullptr); +} + +void InspectableWebContentsImpl::ClearPreferences() { + DictionaryPrefUpdate update(pref_service_, kDevToolsPreferences); + update.Get()->Clear(); +} + void InspectableWebContentsImpl::HandleMessageFromDevToolsFrontend(const std::string& message) { std::string method; base::ListValue empty_params; diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 0c185df79ea..62cfffec4f6 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -110,6 +110,11 @@ class InspectableWebContentsImpl : void SendJsonRequest(const DispatchCallback& callback, const std::string& browser_id, const std::string& url) override; + void GetPreferences(const DispatchCallback& callback) override; + void SetPreference(const std::string& name, + const std::string& value) override; + void RemovePreference(const std::string& name) override; + void ClearPreferences() override; // content::DevToolsFrontendHostDelegate: void HandleMessageFromDevToolsFrontend(const std::string& message) override;