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-27 17:07:34 +0000
committerrdevlin.cronin@chromium.org <rdevlin.cronin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-27 17:07:34 +0000
commitc11e6591d1ed62fd84eb0ac7ec46f087c9bb8e0f (patch)
treefb34b019538cd03ca0fbe6644620ccebff3d655a /extensions/renderer/script_injection.h
parent3a8ae8eb779b286c098e263d952ec38a4078605d (diff)
downloadchromium_src-c11e6591d1ed62fd84eb0ac7ec46f087c9bb8e0f.zip
chromium_src-c11e6591d1ed62fd84eb0ac7ec46f087c9bb8e0f.tar.gz
chromium_src-c11e6591d1ed62fd84eb0ac7ec46f087c9bb8e0f.tar.bz2
Make a Delegate class for extension script injections.
Create a delegate for programmatic script injections and user script injections. Place logic for injecting within ScriptInjection. Make ScriptInjection non-abstract. TBR=jochen@chromium.org (Comment update to c/renderer/isolated_world_ids.h) BUG=382945 Review URL: https://codereview.chromium.org/352823006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@280349 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'extensions/renderer/script_injection.h')
-rw-r--r--extensions/renderer/script_injection.h100
1 files changed, 25 insertions, 75 deletions
diff --git a/extensions/renderer/script_injection.h b/extensions/renderer/script_injection.h
index 821ef38..42ecdbd 100644
--- a/extensions/renderer/script_injection.h
+++ b/extensions/renderer/script_injection.h
@@ -5,13 +5,10 @@
#ifndef EXTENSIONS_RENDERER_SCRIPT_INJECTION_H_
#define EXTENSIONS_RENDERER_SCRIPT_INJECTION_H_
-#include <map>
-#include <vector>
-
#include "base/basictypes.h"
#include "base/macros.h"
-#include "base/timer/elapsed_timer.h"
#include "extensions/common/user_script.h"
+#include "extensions/renderer/script_injector.h"
namespace blink {
class WebFrame;
@@ -19,49 +16,24 @@ class WebFrame;
namespace extensions {
class Extension;
+struct ScriptsRunInfo;
-// An abstract script wrapper which is aware of whether or not it is allowed
-// to execute, and contains the implementation to do so.
+// A script wrapper which is aware of whether or not it is allowed to execute,
+// and contains the implementation to do so.
class ScriptInjection {
public:
- // Map of extensions IDs to the executing script paths.
- typedef std::map<std::string, std::set<std::string> > ExecutingScriptsMap;
-
- // A struct containing information about a script run.
- struct ScriptsRunInfo {
- ScriptsRunInfo();
- ~ScriptsRunInfo();
-
- // The number of CSS scripts injected.
- size_t num_css;
- // The number of JS scripts injected.
- size_t num_js;
- // A map of extension ids to executing script paths.
- ExecutingScriptsMap executing_scripts;
- // The elapsed time since the ScriptsRunInfo was constructed.
- base::ElapsedTimer timer;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(ScriptsRunInfo);
- };
-
- // Gets the isolated world ID to use for the given |extension| in the given
- // |frame|. If no isolated world has been created for that extension,
- // one will be created and initialized.
- static int GetIsolatedWorldIdForExtension(const Extension* extension,
- blink::WebFrame* web_frame);
-
// Return the id of the extension associated with the given world.
static std::string GetExtensionIdForIsolatedWorld(int world_id);
// Remove the isolated world associated with the given extension.
static void RemoveIsolatedWorld(const std::string& extension_id);
- ScriptInjection(blink::WebFrame* web_frame,
+ ScriptInjection(scoped_ptr<ScriptInjector> injector,
+ blink::WebFrame* web_frame,
const std::string& extension_id,
UserScript::RunLocation run_location,
int tab_id);
- virtual ~ScriptInjection();
+ ~ScriptInjection();
// Try to inject the script at the |current_location|. This returns true if
// the script has either injected or will never inject (i.e., if the object
@@ -74,57 +46,35 @@ class ScriptInjection {
// Called when permission for the given injection has been granted.
// Returns true if the injection ran.
- virtual bool OnPermissionGranted(const Extension* extension,
- ScriptsRunInfo* scripts_run_info);
+ bool OnPermissionGranted(const Extension* extension,
+ ScriptsRunInfo* scripts_run_info);
// Accessors.
- const blink::WebFrame* web_frame() const { return web_frame_; }
- blink::WebFrame* web_frame() { return web_frame_; }
- UserScript::RunLocation run_location() const { return run_location_; }
+ blink::WebFrame* web_frame() const { return web_frame_; }
const std::string& extension_id() const { return extension_id_; }
- int tab_id() const { return tab_id_; }
int64 request_id() const { return request_id_; }
- void set_request_id(int64 request_id) { request_id_ = request_id; }
-
- protected:
- // The possible reasons for not injecting the script.
- enum InjectFailureReason {
- EXTENSION_REMOVED, // The extension was removed before injection.
- NOT_ALLOWED, // The script is not allowed to inject.
- WONT_INJECT // The injection won't inject because the user rejected
- // (or just did not accept) the injection.
- };
-
- // The possible types of access for a given frame.
- enum AccessType {
- DENY_ACCESS, // The script cannot access the given frame.
- ALLOW_ACCESS, // The script can access the given frame.
- REQUEST_ACCESS // The browser must determine if the script can access the
- // given frame.
- };
-
- // Returns whether or not the script is allowed to run.
- virtual AccessType Allowed(const Extension* extension) const = 0;
-
- // Injects the script, optionally populating |scripts_run_info|.
- virtual void Inject(const Extension* extension,
- ScriptsRunInfo* scripts_run_info) = 0;
-
- // Handles the case that the script will never inject (e.g., notifying
- // listeners that the injection is "complete"). |reason| contains the reason
- // injection will not occur.
- virtual void OnWillNotInject(InjectFailureReason reason) {};
private:
// Send a message to the browser requesting permission to execute.
void RequestPermission();
+ // Injects the script, optionally populating |scripts_run_info|.
+ void Inject(const Extension* extension, ScriptsRunInfo* scripts_run_info);
+
+ // Inject any JS scripts into the |frame|, optionally populating
+ // |execution_results|.
+ void InjectJs(const Extension* extension,
+ blink::WebFrame* frame,
+ base::ListValue* execution_results);
+
+ // Inject any CSS source into the |frame|.
+ void InjectCss(blink::WebFrame* frame);
+
// Notify that we will not inject, and mark it as acknowledged.
- void NotifyWillNotInject(InjectFailureReason reason);
+ void NotifyWillNotInject(ScriptInjector::InjectFailureReason reason);
- // Inject the script and mark this injection as |complete_|.
- void InjectAndMarkComplete(const Extension* extension,
- ScriptsRunInfo* scripts_run_info);
+ // The injector for this injection.
+ scoped_ptr<ScriptInjector> injector_;
// The (main) WebFrame into which this should inject the script.
blink::WebFrame* web_frame_;