Commit d5e6098d authored by dgozman's avatar dgozman Committed by Commit bot

[DevTools] Do not use "settings" query param.

Implemented the same functionality on embedder side.
Also, sanitizing "settings" query param for remote frontends.

BUG=618037

Review-Url: https://codereview.chromium.org/2177983004
Cr-Commit-Position: refs/heads/master@{#407666}
parent 9e24b26d
......@@ -90,6 +90,20 @@ bool FindInspectedBrowserAndTabIndex(
return false;
}
void SetPreferencesFromJson(Profile* profile, const std::string& json) {
base::DictionaryValue* dict = nullptr;
std::unique_ptr<base::Value> parsed = base::JSONReader::Read(json);
if (!parsed || !parsed->GetAsDictionary(&dict))
return;
DictionaryPrefUpdate update(profile->GetPrefs(), prefs::kDevToolsPreferences);
for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) {
if (!it.value().IsType(base::Value::TYPE_STRING))
continue;
update.Get()->SetWithoutPathExpansion(
it.key(), it.value().CreateDeepCopy());
}
}
// DevToolsToolboxDelegate ----------------------------------------------------
class DevToolsToolboxDelegate
......@@ -791,7 +805,7 @@ DevToolsWindow* DevToolsWindow::Create(
GURL url(GetDevToolsURL(profile, frontend_url,
shared_worker_frontend,
remote_frontend,
can_dock, settings));
can_dock));
std::unique_ptr<WebContents> main_web_contents(
WebContents::Create(WebContents::CreateParams(profile)));
main_web_contents->GetController().LoadURL(
......@@ -801,7 +815,8 @@ DevToolsWindow* DevToolsWindow::Create(
DevToolsUIBindings::ForWebContents(main_web_contents.get());
if (!bindings)
return nullptr;
if (!settings.empty())
SetPreferencesFromJson(profile, settings);
return new DevToolsWindow(profile, main_web_contents.release(), bindings,
inspected_web_contents, can_dock);
}
......@@ -811,8 +826,7 @@ GURL DevToolsWindow::GetDevToolsURL(Profile* profile,
const GURL& base_url,
bool shared_worker_frontend,
const std::string& remote_frontend,
bool can_dock,
const std::string& settings) {
bool can_dock) {
// Compatibility errors are encoded with data urls, pass them
// through with no decoration.
if (base_url.SchemeIs("data"))
......@@ -834,8 +848,6 @@ GURL DevToolsWindow::GetDevToolsURL(Profile* profile,
}
if (can_dock)
url_string += "&can_dock=true";
if (settings.size())
url_string += "&settings=" + settings;
return GURL(url_string);
}
......
......@@ -254,8 +254,7 @@ class DevToolsWindow : public DevToolsUIBindings::Delegate,
const GURL& base_url,
bool shared_worker_frontend,
const std::string& remote_frontend,
bool can_dock,
const std::string& settings);
bool can_dock);
static DevToolsWindow* CreateDevToolsWindowForWorker(Profile* profile);
static void ToggleDevToolsWindow(
......
......@@ -774,7 +774,7 @@ void BlinkTestController::OnClearDevToolsLocalStorage() {
StoragePartition* storage_partition =
BrowserContext::GetStoragePartition(browser_context, NULL);
storage_partition->GetDOMStorageContext()->DeleteLocalStorage(
content::LayoutTestDevToolsFrontend::GetDevToolsPathAsURL("", "")
content::LayoutTestDevToolsFrontend::GetDevToolsPathAsURL("")
.GetOrigin());
}
......
......@@ -30,15 +30,13 @@ LayoutTestDevToolsFrontend* LayoutTestDevToolsFrontend::Show(
gfx::Size());
LayoutTestDevToolsFrontend* devtools_frontend =
new LayoutTestDevToolsFrontend(shell, inspected_contents);
shell->LoadURL(GetDevToolsPathAsURL(settings, frontend_url));
devtools_frontend->SetPreferences(settings);
shell->LoadURL(GetDevToolsPathAsURL(frontend_url));
return devtools_frontend;
}
// static.
GURL LayoutTestDevToolsFrontend::GetDevToolsPathAsURL(
const std::string& settings,
const std::string& frontend_url) {
if (!frontend_url.empty())
return GURL(frontend_url);
......@@ -62,18 +60,16 @@ GURL LayoutTestDevToolsFrontend::GetDevToolsPathAsURL(
#if defined(DEBUG_DEVTOOLS)
url_string += "&debugFrontend=true";
#endif // defined(DEBUG_DEVTOOLS)
if (!settings.empty())
url_string += "&settings=" + settings;
return GURL(url_string);
}
void LayoutTestDevToolsFrontend::ReuseFrontend(const std::string& settings,
const std::string frontend_url) {
DisconnectFromTarget();
preferences()->Clear();
SetPreferences(settings);
ready_for_test_ = false;
pending_evaluations_.clear();
frontend_shell()->LoadURL(GetDevToolsPathAsURL(settings, frontend_url));
frontend_shell()->LoadURL(GetDevToolsPathAsURL(frontend_url));
}
void LayoutTestDevToolsFrontend::EvaluateInFrontend(
......
......@@ -21,8 +21,7 @@ class LayoutTestDevToolsFrontend : public ShellDevToolsFrontend {
const std::string& settings,
const std::string& frontend_url);
static GURL GetDevToolsPathAsURL(const std::string& settings,
const std::string& frontend_url);
static GURL GetDevToolsPathAsURL(const std::string& frontend_url);
void ReuseFrontend(const std::string& settings,
const std::string frontend_url);
......
......@@ -193,6 +193,21 @@ void ShellDevToolsFrontend::WebContentsDestroyed() {
delete this;
}
void ShellDevToolsFrontend::SetPreferences(const std::string& json) {
preferences_.Clear();
if (json.empty())
return;
base::DictionaryValue* dict = nullptr;
std::unique_ptr<base::Value> parsed = base::JSONReader::Read(json);
if (!parsed || !parsed->GetAsDictionary(&dict))
return;
for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) {
if (!it.value().IsType(base::Value::TYPE_STRING))
continue;
preferences_.SetWithoutPathExpansion(it.key(), it.value().CreateDeepCopy());
}
}
void ShellDevToolsFrontend::HandleMessageFromDevToolsFrontend(
const std::string& message) {
if (!agent_host_)
......
......@@ -55,7 +55,7 @@ class ShellDevToolsFrontend : public WebContentsObserver,
void AgentHostClosed(DevToolsAgentHost* agent_host, bool replaced) override;
void DispatchProtocolMessage(DevToolsAgentHost* agent_host,
const std::string& message) override;
base::DictionaryValue* preferences() { return &preferences_; }
void SetPreferences(const std::string& json);
virtual void HandleMessageFromDevToolsFrontend(const std::string& message);
private:
......
......@@ -1000,6 +1000,8 @@ function sanitizeRemoteFrontendUrl()
location.search = "";
if (name === "remoteBase" && !remoteBaseRegexp.test(value))
location.search = "";
if (name === "settings")
location.search = "";
}
}
......
......@@ -77,18 +77,6 @@ WebInspector.Main.prototype = {
*/
_createSettings: function(prefs)
{
// Patch settings from the URL param (for tests).
var settingsParam = Runtime.queryParam("settings");
if (settingsParam) {
try {
var settings = JSON.parse(window.decodeURI(settingsParam));
for (var key in settings)
prefs[key] = settings[key];
} catch (e) {
// Ignore malformed settings.
}
}
this._initializeExperiments(prefs);
WebInspector.settings = new WebInspector.Settings(new WebInspector.SettingsStorage(prefs,
InspectorFrontendHost.setPreference, InspectorFrontendHost.removePreference, InspectorFrontendHost.clearPreferences));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment