summaryrefslogtreecommitdiffstats
path: root/src/core/user_script_controller_host.cpp
diff options
context:
space:
mode:
authorKai Koehne <kai.koehne@theqtcompany.com>2015-09-25 15:39:12 +0200
committerKai Koehne <kai.koehne@theqtcompany.com>2015-10-08 10:31:08 +0000
commita45f6fc3e1016a223a4b235cc61b033f8665c853 (patch)
tree66ee5d1d819493a8875a6638b11bdf8e44f11f86 /src/core/user_script_controller_host.cpp
parentf681793c6895d390fe7a5f57718e25a4fcd10ed0 (diff)
Keep order of scripts added to QWebEngineScriptCollection
Use a QList instead of a QSet to store the scripts in the collection. This avoids situations where two scripts injected depend on each other, and fail or succeed depending on the semi-random order that QSet imposes. Change-Id: I44d5d89866ff2431544cc91afb1c102d93daa5da Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com>
Diffstat (limited to 'src/core/user_script_controller_host.cpp')
-rw-r--r--src/core/user_script_controller_host.cpp31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/core/user_script_controller_host.cpp b/src/core/user_script_controller_host.cpp
index d57518275..a0d3f6fed 100644
--- a/src/core/user_script_controller_host.cpp
+++ b/src/core/user_script_controller_host.cpp
@@ -116,9 +116,11 @@ void UserScriptControllerHost::addUserScript(const UserScript &script, WebConten
return;
// Global scripts should be dispatched to all our render processes.
if (!adapter) {
- m_profileWideScripts.insert(script);
- Q_FOREACH (content::RenderProcessHost *renderer, m_observedProcesses)
- renderer->Send(new UserScriptController_AddScript(script.data()));
+ if (!m_profileWideScripts.contains(script)) {
+ m_profileWideScripts.append(script);
+ Q_FOREACH (content::RenderProcessHost *renderer, m_observedProcesses)
+ renderer->Send(new UserScriptController_AddScript(script.data()));
+ }
} else {
content::WebContents *contents = adapter->webContents();
ContentsScriptsMap::iterator it = m_perContentsScripts.find(contents);
@@ -126,11 +128,13 @@ void UserScriptControllerHost::addUserScript(const UserScript &script, WebConten
// We need to keep track of RenderView/RenderViewHost changes for a given contents
// in order to make sure the scripts stay in sync
new WebContentsObserverHelper(this, contents);
- it = m_perContentsScripts.insert(contents, (QSet<UserScript>() << script));
+ it = m_perContentsScripts.insert(contents, (QList<UserScript>() << script));
} else {
- QSet<UserScript> currentScripts = it.value();
- currentScripts.insert(script);
- m_perContentsScripts.insert(contents, currentScripts);
+ QList<UserScript> currentScripts = it.value();
+ if (!currentScripts.contains(script)) {
+ currentScripts.append(script);
+ m_perContentsScripts.insert(contents, currentScripts);
+ }
}
contents->Send(new RenderViewObserverHelper_AddScript(contents->GetRoutingID(), script.data()));
}
@@ -151,7 +155,8 @@ bool UserScriptControllerHost::removeUserScript(const UserScript &script, WebCon
if (script.isNull())
return false;
if (!adapter) {
- QSet<UserScript>::iterator it = m_profileWideScripts.find(script);
+ QList<UserScript>::iterator it
+ = std::find(m_profileWideScripts.begin(), m_profileWideScripts.end(), script);
if (it == m_profileWideScripts.end())
return false;
Q_FOREACH (content::RenderProcessHost *renderer, m_observedProcesses)
@@ -161,12 +166,12 @@ bool UserScriptControllerHost::removeUserScript(const UserScript &script, WebCon
content::WebContents *contents = adapter->webContents();
if (!m_perContentsScripts.contains(contents))
return false;
- QSet<UserScript> &set(m_perContentsScripts[contents]);
- QSet<UserScript>::iterator it = set.find(script);
- if (it == set.end())
+ QList<UserScript> &list(m_perContentsScripts[contents]);
+ QList<UserScript>::iterator it = std::find(list.begin(), list.end(), script);
+ if (it == list.end())
return false;
contents->Send(new RenderViewObserverHelper_RemoveScript(contents->GetRoutingID(), (*it).data()));
- set.erase(it);
+ list.erase(it);
}
return true;
}
@@ -184,7 +189,7 @@ void UserScriptControllerHost::clearAllScripts(WebContentsAdapter *adapter)
}
}
-const QSet<UserScript> UserScriptControllerHost::registeredScripts(WebContentsAdapter *adapter) const
+const QList<UserScript> UserScriptControllerHost::registeredScripts(WebContentsAdapter *adapter) const
{
if (!adapter)
return m_profileWideScripts;