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( ...@@ -90,6 +90,20 @@ bool FindInspectedBrowserAndTabIndex(
return false; 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 ---------------------------------------------------- // DevToolsToolboxDelegate ----------------------------------------------------
class DevToolsToolboxDelegate class DevToolsToolboxDelegate
...@@ -791,7 +805,7 @@ DevToolsWindow* DevToolsWindow::Create( ...@@ -791,7 +805,7 @@ DevToolsWindow* DevToolsWindow::Create(
GURL url(GetDevToolsURL(profile, frontend_url, GURL url(GetDevToolsURL(profile, frontend_url,
shared_worker_frontend, shared_worker_frontend,
remote_frontend, remote_frontend,
can_dock, settings)); can_dock));
std::unique_ptr<WebContents> main_web_contents( std::unique_ptr<WebContents> main_web_contents(
WebContents::Create(WebContents::CreateParams(profile))); WebContents::Create(WebContents::CreateParams(profile)));
main_web_contents->GetController().LoadURL( main_web_contents->GetController().LoadURL(
...@@ -801,7 +815,8 @@ DevToolsWindow* DevToolsWindow::Create( ...@@ -801,7 +815,8 @@ DevToolsWindow* DevToolsWindow::Create(
DevToolsUIBindings::ForWebContents(main_web_contents.get()); DevToolsUIBindings::ForWebContents(main_web_contents.get());
if (!bindings) if (!bindings)
return nullptr; return nullptr;
if (!settings.empty())
SetPreferencesFromJson(profile, settings);
return new DevToolsWindow(profile, main_web_contents.release(), bindings, return new DevToolsWindow(profile, main_web_contents.release(), bindings,
inspected_web_contents, can_dock); inspected_web_contents, can_dock);
} }
...@@ -811,8 +826,7 @@ GURL DevToolsWindow::GetDevToolsURL(Profile* profile, ...@@ -811,8 +826,7 @@ GURL DevToolsWindow::GetDevToolsURL(Profile* profile,
const GURL& base_url, const GURL& base_url,
bool shared_worker_frontend, bool shared_worker_frontend,
const std::string& remote_frontend, const std::string& remote_frontend,
bool can_dock, bool can_dock) {
const std::string& settings) {
// Compatibility errors are encoded with data urls, pass them // Compatibility errors are encoded with data urls, pass them
// through with no decoration. // through with no decoration.
if (base_url.SchemeIs("data")) if (base_url.SchemeIs("data"))
...@@ -834,8 +848,6 @@ GURL DevToolsWindow::GetDevToolsURL(Profile* profile, ...@@ -834,8 +848,6 @@ GURL DevToolsWindow::GetDevToolsURL(Profile* profile,
} }
if (can_dock) if (can_dock)
url_string += "&can_dock=true"; url_string += "&can_dock=true";
if (settings.size())
url_string += "&settings=" + settings;
return GURL(url_string); return GURL(url_string);
} }
......
...@@ -254,8 +254,7 @@ class DevToolsWindow : public DevToolsUIBindings::Delegate, ...@@ -254,8 +254,7 @@ class DevToolsWindow : public DevToolsUIBindings::Delegate,
const GURL& base_url, const GURL& base_url,
bool shared_worker_frontend, bool shared_worker_frontend,
const std::string& remote_frontend, const std::string& remote_frontend,
bool can_dock, bool can_dock);
const std::string& settings);
static DevToolsWindow* CreateDevToolsWindowForWorker(Profile* profile); static DevToolsWindow* CreateDevToolsWindowForWorker(Profile* profile);
static void ToggleDevToolsWindow( static void ToggleDevToolsWindow(
......
...@@ -774,7 +774,7 @@ void BlinkTestController::OnClearDevToolsLocalStorage() { ...@@ -774,7 +774,7 @@ void BlinkTestController::OnClearDevToolsLocalStorage() {
StoragePartition* storage_partition = StoragePartition* storage_partition =
BrowserContext::GetStoragePartition(browser_context, NULL); BrowserContext::GetStoragePartition(browser_context, NULL);
storage_partition->GetDOMStorageContext()->DeleteLocalStorage( storage_partition->GetDOMStorageContext()->DeleteLocalStorage(
content::LayoutTestDevToolsFrontend::GetDevToolsPathAsURL("", "") content::LayoutTestDevToolsFrontend::GetDevToolsPathAsURL("")
.GetOrigin()); .GetOrigin());
} }
......
...@@ -30,15 +30,13 @@ LayoutTestDevToolsFrontend* LayoutTestDevToolsFrontend::Show( ...@@ -30,15 +30,13 @@ LayoutTestDevToolsFrontend* LayoutTestDevToolsFrontend::Show(
gfx::Size()); gfx::Size());
LayoutTestDevToolsFrontend* devtools_frontend = LayoutTestDevToolsFrontend* devtools_frontend =
new LayoutTestDevToolsFrontend(shell, inspected_contents); new LayoutTestDevToolsFrontend(shell, inspected_contents);
devtools_frontend->SetPreferences(settings);
shell->LoadURL(GetDevToolsPathAsURL(settings, frontend_url)); shell->LoadURL(GetDevToolsPathAsURL(frontend_url));
return devtools_frontend; return devtools_frontend;
} }
// static. // static.
GURL LayoutTestDevToolsFrontend::GetDevToolsPathAsURL( GURL LayoutTestDevToolsFrontend::GetDevToolsPathAsURL(
const std::string& settings,
const std::string& frontend_url) { const std::string& frontend_url) {
if (!frontend_url.empty()) if (!frontend_url.empty())
return GURL(frontend_url); return GURL(frontend_url);
...@@ -62,18 +60,16 @@ GURL LayoutTestDevToolsFrontend::GetDevToolsPathAsURL( ...@@ -62,18 +60,16 @@ GURL LayoutTestDevToolsFrontend::GetDevToolsPathAsURL(
#if defined(DEBUG_DEVTOOLS) #if defined(DEBUG_DEVTOOLS)
url_string += "&debugFrontend=true"; url_string += "&debugFrontend=true";
#endif // defined(DEBUG_DEVTOOLS) #endif // defined(DEBUG_DEVTOOLS)
if (!settings.empty())
url_string += "&settings=" + settings;
return GURL(url_string); return GURL(url_string);
} }
void LayoutTestDevToolsFrontend::ReuseFrontend(const std::string& settings, void LayoutTestDevToolsFrontend::ReuseFrontend(const std::string& settings,
const std::string frontend_url) { const std::string frontend_url) {
DisconnectFromTarget(); DisconnectFromTarget();
preferences()->Clear(); SetPreferences(settings);
ready_for_test_ = false; ready_for_test_ = false;
pending_evaluations_.clear(); pending_evaluations_.clear();
frontend_shell()->LoadURL(GetDevToolsPathAsURL(settings, frontend_url)); frontend_shell()->LoadURL(GetDevToolsPathAsURL(frontend_url));
} }
void LayoutTestDevToolsFrontend::EvaluateInFrontend( void LayoutTestDevToolsFrontend::EvaluateInFrontend(
......
...@@ -21,8 +21,7 @@ class LayoutTestDevToolsFrontend : public ShellDevToolsFrontend { ...@@ -21,8 +21,7 @@ class LayoutTestDevToolsFrontend : public ShellDevToolsFrontend {
const std::string& settings, const std::string& settings,
const std::string& frontend_url); const std::string& frontend_url);
static GURL GetDevToolsPathAsURL(const std::string& settings, static GURL GetDevToolsPathAsURL(const std::string& frontend_url);
const std::string& frontend_url);
void ReuseFrontend(const std::string& settings, void ReuseFrontend(const std::string& settings,
const std::string frontend_url); const std::string frontend_url);
......
...@@ -193,6 +193,21 @@ void ShellDevToolsFrontend::WebContentsDestroyed() { ...@@ -193,6 +193,21 @@ void ShellDevToolsFrontend::WebContentsDestroyed() {
delete this; 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( void ShellDevToolsFrontend::HandleMessageFromDevToolsFrontend(
const std::string& message) { const std::string& message) {
if (!agent_host_) if (!agent_host_)
......
...@@ -55,7 +55,7 @@ class ShellDevToolsFrontend : public WebContentsObserver, ...@@ -55,7 +55,7 @@ class ShellDevToolsFrontend : public WebContentsObserver,
void AgentHostClosed(DevToolsAgentHost* agent_host, bool replaced) override; void AgentHostClosed(DevToolsAgentHost* agent_host, bool replaced) override;
void DispatchProtocolMessage(DevToolsAgentHost* agent_host, void DispatchProtocolMessage(DevToolsAgentHost* agent_host,
const std::string& message) override; const std::string& message) override;
base::DictionaryValue* preferences() { return &preferences_; } void SetPreferences(const std::string& json);
virtual void HandleMessageFromDevToolsFrontend(const std::string& message); virtual void HandleMessageFromDevToolsFrontend(const std::string& message);
private: private:
......
...@@ -1000,6 +1000,8 @@ function sanitizeRemoteFrontendUrl() ...@@ -1000,6 +1000,8 @@ function sanitizeRemoteFrontendUrl()
location.search = ""; location.search = "";
if (name === "remoteBase" && !remoteBaseRegexp.test(value)) if (name === "remoteBase" && !remoteBaseRegexp.test(value))
location.search = ""; location.search = "";
if (name === "settings")
location.search = "";
} }
} }
......
...@@ -77,18 +77,6 @@ WebInspector.Main.prototype = { ...@@ -77,18 +77,6 @@ WebInspector.Main.prototype = {
*/ */
_createSettings: function(prefs) _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); this._initializeExperiments(prefs);
WebInspector.settings = new WebInspector.Settings(new WebInspector.SettingsStorage(prefs, WebInspector.settings = new WebInspector.Settings(new WebInspector.SettingsStorage(prefs,
InspectorFrontendHost.setPreference, InspectorFrontendHost.removePreference, InspectorFrontendHost.clearPreferences)); 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