Implement devtools preference interfaces.
This commit is contained in:
parent
6171ab8f6b
commit
f82ab5f193
4 changed files with 41 additions and 0 deletions
|
@ -195,6 +195,11 @@ DevToolsEmbedderMessageDispatcher::CreateForDevToolsFrontend(
|
||||||
d->RegisterHandler("recordActionUMA", &Delegate::RecordActionUMA, delegate);
|
d->RegisterHandler("recordActionUMA", &Delegate::RecordActionUMA, delegate);
|
||||||
d->RegisterHandlerWithCallback("sendJsonRequest",
|
d->RegisterHandlerWithCallback("sendJsonRequest",
|
||||||
&Delegate::SendJsonRequest, delegate);
|
&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;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,6 +73,11 @@ class DevToolsEmbedderMessageDispatcher {
|
||||||
virtual void SendJsonRequest(const DispatchCallback& callback,
|
virtual void SendJsonRequest(const DispatchCallback& callback,
|
||||||
const std::string& browser_id,
|
const std::string& browser_id,
|
||||||
const std::string& url) = 0;
|
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;
|
using DispatchCallback = Delegate::DispatchCallback;
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include "base/metrics/histogram.h"
|
#include "base/metrics/histogram.h"
|
||||||
#include "base/prefs/pref_registry_simple.h"
|
#include "base/prefs/pref_registry_simple.h"
|
||||||
#include "base/prefs/pref_service.h"
|
#include "base/prefs/pref_service.h"
|
||||||
|
#include "base/prefs/scoped_user_pref_update.h"
|
||||||
#include "base/strings/stringprintf.h"
|
#include "base/strings/stringprintf.h"
|
||||||
#include "base/strings/utf_string_conversions.h"
|
#include "base/strings/utf_string_conversions.h"
|
||||||
#include "base/values.h"
|
#include "base/values.h"
|
||||||
|
@ -44,6 +45,7 @@ const char kChromeUIDevToolsURL[] = "chrome-devtools://devtools/devtools.html?"
|
||||||
"experiments=true";
|
"experiments=true";
|
||||||
const char kDevToolsBoundsPref[] = "brightray.devtools.bounds";
|
const char kDevToolsBoundsPref[] = "brightray.devtools.bounds";
|
||||||
const char kDevToolsZoomPref[] = "brightray.devtools.zoom";
|
const char kDevToolsZoomPref[] = "brightray.devtools.zoom";
|
||||||
|
const char kDevToolsPreferences[] = "brightray.devtools.preferences";
|
||||||
|
|
||||||
const char kFrontendHostId[] = "id";
|
const char kFrontendHostId[] = "id";
|
||||||
const char kFrontendHostMethod[] = "method";
|
const char kFrontendHostMethod[] = "method";
|
||||||
|
@ -160,6 +162,7 @@ void InspectableWebContentsImpl::RegisterPrefs(PrefRegistrySimple* registry) {
|
||||||
RectToDictionary(gfx::Rect(0, 0, 800, 600), bounds_dict.get());
|
RectToDictionary(gfx::Rect(0, 0, 800, 600), bounds_dict.get());
|
||||||
registry->RegisterDictionaryPref(kDevToolsBoundsPref, bounds_dict.release());
|
registry->RegisterDictionaryPref(kDevToolsBoundsPref, bounds_dict.release());
|
||||||
registry->RegisterDoublePref(kDevToolsZoomPref, 0.);
|
registry->RegisterDoublePref(kDevToolsZoomPref, 0.);
|
||||||
|
registry->RegisterDictionaryPref(kDevToolsPreferences);
|
||||||
}
|
}
|
||||||
|
|
||||||
InspectableWebContentsImpl::InspectableWebContentsImpl(
|
InspectableWebContentsImpl::InspectableWebContentsImpl(
|
||||||
|
@ -469,6 +472,29 @@ void InspectableWebContentsImpl::SendJsonRequest(const DispatchCallback& callbac
|
||||||
callback.Run(nullptr);
|
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) {
|
void InspectableWebContentsImpl::HandleMessageFromDevToolsFrontend(const std::string& message) {
|
||||||
std::string method;
|
std::string method;
|
||||||
base::ListValue empty_params;
|
base::ListValue empty_params;
|
||||||
|
|
|
@ -110,6 +110,11 @@ class InspectableWebContentsImpl :
|
||||||
void SendJsonRequest(const DispatchCallback& callback,
|
void SendJsonRequest(const DispatchCallback& callback,
|
||||||
const std::string& browser_id,
|
const std::string& browser_id,
|
||||||
const std::string& url) override;
|
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:
|
// content::DevToolsFrontendHostDelegate:
|
||||||
void HandleMessageFromDevToolsFrontend(const std::string& message) override;
|
void HandleMessageFromDevToolsFrontend(const std::string& message) override;
|
||||||
|
|
Loading…
Reference in a new issue