summaryrefslogtreecommitdiffstats
path: root/extensions/renderer/script_injection.h
diff options
context:
space:
mode:
authorrdevlin.cronin@chromium.org <rdevlin.cronin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-03 22:41:02 +0000
committerrdevlin.cronin@chromium.org <rdevlin.cronin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-03 22:41:02 +0000
commit0d8d69767a1ff6becad7e25442ccdf94cac7290e (patch)
treebf080b49953ed8bf895e5bc9de306b64fb3dba37 /extensions/renderer/script_injection.h
parente8daf71e4ad7e36b52267316c7f33b754356a01c (diff)
downloadchromium_src-0d8d69767a1ff6becad7e25442ccdf94cac7290e.zip
chromium_src-0d8d69767a1ff6becad7e25442ccdf94cac7290e.tar.gz
chromium_src-0d8d69767a1ff6becad7e25442ccdf94cac7290e.tar.bz2
Resubmit: Block content scripts from executing until user grants permission
Original CL: https://codereview.chromium.org/288053002/ Original Description: Prevent extensions with <all_urls> from running content scripts without user consent if the scripts-require-action switch is on. ----------------------------------------------- This had a problem in that when user scripts are updated, the old versions are invalidated (as they rely on StringPieces, which do not actually own content). Fix is to update all user scripts, even if they didn't actually change. Also add in ActiveScriptController removing actions for unloaded extensions. TBR=jschuh@chromium.org (for extension_messages.h, no change from original patch) BUG=362353 Review URL: https://codereview.chromium.org/313453002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274659 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'extensions/renderer/script_injection.h')
-rw-r--r--extensions/renderer/script_injection.h59
1 files changed, 48 insertions, 11 deletions
diff --git a/extensions/renderer/script_injection.h b/extensions/renderer/script_injection.h
index 813fbb4..17c18de 100644
--- a/extensions/renderer/script_injection.h
+++ b/extensions/renderer/script_injection.h
@@ -9,8 +9,10 @@
#include <set>
#include <string>
+#include "base/basictypes.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/scoped_vector.h"
#include "base/timer/elapsed_timer.h"
#include "extensions/common/user_script.h"
@@ -20,6 +22,10 @@ namespace blink {
class WebFrame;
}
+namespace content {
+class RenderView;
+}
+
namespace extensions {
class UserScriptSlave;
@@ -56,6 +62,39 @@ class ScriptInjection {
UserScriptSlave* user_script_slave);
~ScriptInjection();
+ // Inject the script into the given |frame| if the script should run on the
+ // frame and has permission to do so. If the script requires user consent,
+ // this will register a pending request to inject at a later time.
+ // If the script is run immediately, |scripts_run_info| is updated with
+ // information about the run.
+ void InjectIfAllowed(blink::WebFrame* frame,
+ UserScript::RunLocation location,
+ const GURL& document_url,
+ ScriptsRunInfo* scripts_run_info);
+
+ // If a request with the given |request_id| exists, runs that request and
+ // modifies |scripts_run_info| with information about the run. Otherwise, does
+ // nothing.
+ // If |frame_out| is non-NULL and a script was run, |frame_out| will be
+ // populated with the frame in which the script was run.
+ // Returns true if the request was found *and* the script was run.
+ bool NotifyScriptPermitted(int64 request_id,
+ content::RenderView* render_view,
+ ScriptsRunInfo* scripts_run_info,
+ blink::WebFrame** frame_out);
+
+ // Notififies the Injection that the frame has been detached (i.e. is about
+ // to be destroyed).
+ void FrameDetached(blink::WebFrame* frame);
+
+ void SetScript(scoped_ptr<UserScript> script);
+
+ const std::string& extension_id() { return extension_id_; }
+ const UserScript* script() { return script_.get(); }
+
+ private:
+ struct PendingInjection;
+
// Returns true if this ScriptInjection wants to run on the given |frame| at
// the given |run_location| (i.e., if this script would inject either JS or
// CSS).
@@ -63,20 +102,17 @@ class ScriptInjection {
UserScript::RunLocation run_location,
const GURL& document_url) const;
+ // Returns true if the script will inject [css|js] at the given
+ // |run_location|.
+ bool ShouldInjectJS(UserScript::RunLocation run_location) const;
+ bool ShouldInjectCSS(UserScript::RunLocation run_location) const;
+
// Injects the script into the given |frame|, and updates |scripts_run_info|
// information about the run.
void Inject(blink::WebFrame* frame,
UserScript::RunLocation run_location,
ScriptsRunInfo* scripts_run_info) const;
- const std::string& extension_id() { return extension_id_; }
-
- private:
- // Returns true if the script will inject [css|js] at the given
- // |run_location|.
- bool ShouldInjectJS(UserScript::RunLocation run_location) const;
- bool ShouldInjectCSS(UserScript::RunLocation run_location) const;
-
// Injects the [css|js] scripts into the frame, and stores the results of
// the run in |scripts_run_info|.
void InjectJS(blink::WebFrame* frame, ScriptsRunInfo* scripts_run_info) const;
@@ -86,9 +122,8 @@ class ScriptInjection {
// The UserScript this is injecting.
scoped_ptr<UserScript> script_;
- // The associated extension's id. This is a safe const&, since it is owned by
- // the |user_script_|.
- const std::string& extension_id_;
+ // The associated extension's id.
+ std::string extension_id_;
// The associated UserScriptSlave.
// It's unfortunate that this is needed, but we use it to get the isolated
@@ -99,6 +134,8 @@ class ScriptInjection {
// True if the script is a standalone script or emulates greasemonkey.
bool is_standalone_or_emulate_greasemonkey_;
+ ScopedVector<PendingInjection> pending_injections_;
+
DISALLOW_COPY_AND_ASSIGN(ScriptInjection);
};