Implement devtools preference interfaces.

This commit is contained in:
Haojian Wu 2015-08-06 13:39:23 +08:00 committed by Cheng Zhao
parent 6171ab8f6b
commit f82ab5f193
4 changed files with 41 additions and 0 deletions

View file

@ -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;
}

View file

@ -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;

View file

@ -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;

View file

@ -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;