| Index: extensions/renderer/script_injection.h
|
| diff --git a/extensions/renderer/script_injection.h b/extensions/renderer/script_injection.h
|
| index a8835457d95312b220ded68cba089261eb05e745..eccc1461bfe1106c480e1b5e4e3c39109b252363 100644
|
| --- a/extensions/renderer/script_injection.h
|
| +++ b/extensions/renderer/script_injection.h
|
| @@ -7,6 +7,7 @@
|
|
|
| #include "base/basictypes.h"
|
| #include "base/macros.h"
|
| +#include "base/memory/scoped_ptr.h"
|
| #include "extensions/common/user_script.h"
|
| #include "extensions/renderer/script_injector.h"
|
|
|
| @@ -15,15 +16,28 @@ struct HostID;
|
|
|
| namespace blink {
|
| class WebLocalFrame;
|
| +template<typename T> class WebVector;
|
| +}
|
| +
|
| +namespace v8 {
|
| +class Value;
|
| +template <class T> class Local;
|
| }
|
|
|
| namespace extensions {
|
| +class ScriptInjectionManager;
|
| struct ScriptsRunInfo;
|
|
|
| // 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:
|
| + enum InjectionResult {
|
| + INJECTION_FINISHED,
|
| + INJECTION_BLOCKED,
|
| + INJECTION_WAITING
|
| + };
|
| +
|
| // Return the id of the injection host associated with the given world.
|
| static std::string GetHostIdForIsolatedWorld(int world_id);
|
|
|
| @@ -37,19 +51,27 @@ class ScriptInjection {
|
| int tab_id);
|
| ~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
|
| - // is done), and false if injection is delayed (either for permission purposes
|
| - // or because |current_location| is not the designated |run_location_|).
|
| + // Try to inject the script at the |current_location|. This returns
|
| + // INJECTION_FINISHED if injection has injected or will never inject, returns
|
| + // INJECTION_BLOCKED if injection is running asynchronously and has not
|
| + // finished yet, returns INJECTION_WAITING if injections is delayed (either
|
| + // for permission purposes or because |current_location| is not the designated
|
| + // |run_location_|).
|
| // NOTE: |injection_host| may be NULL, if the injection_host is removed!
|
| - bool TryToInject(UserScript::RunLocation current_location,
|
| - const InjectionHost* injection_host,
|
| - ScriptsRunInfo* scripts_run_info);
|
| + InjectionResult TryToInject(UserScript::RunLocation current_location,
|
| + const InjectionHost* injection_host,
|
| + ScriptsRunInfo* scripts_run_info,
|
| + ScriptInjectionManager* manager);
|
|
|
| // Called when permission for the given injection has been granted.
|
| - // Returns true if the injection ran.
|
| - bool OnPermissionGranted(const InjectionHost* injection_host,
|
| - ScriptsRunInfo* scripts_run_info);
|
| + // Returns INJECTION_FINISHED if injection has injected or will never inject,
|
| + // returns INJECTION_BLOCKED if injection is runned asynchronously.
|
| + InjectionResult OnPermissionGranted(const InjectionHost* injection_host,
|
| + ScriptsRunInfo* scripts_run_info);
|
| +
|
| + // Called when JS injection for the given frame has been completed.
|
| + void OnJsInjectionCompleted(blink::WebLocalFrame* frame,
|
| + const blink::WebVector<v8::Local<v8::Value> >&);
|
|
|
| // Accessors.
|
| blink::WebLocalFrame* web_frame() const { return web_frame_; }
|
| @@ -61,15 +83,18 @@ class ScriptInjection {
|
| // like to inject, or to notify the browser that it is currently injecting.
|
| void SendInjectionMessage(bool request_permission);
|
|
|
| - // Injects the script, optionally populating |scripts_run_info|.
|
| - void Inject(const InjectionHost* injection_host,
|
| - ScriptsRunInfo* scripts_run_info);
|
| + // Injects the script. Returns INJECTION_FINISHED if injection has finished,
|
| + // otherwise INJECTION_BLOCKED.
|
| + InjectionResult Inject(const InjectionHost* injection_host,
|
| + ScriptsRunInfo* scripts_run_info);
|
|
|
| // Inject any JS scripts into the |frame|, optionally populating
|
| // |execution_results|.
|
| void InjectJs(const InjectionHost* injection_host,
|
| - blink::WebLocalFrame* frame,
|
| - base::ListValue* execution_results);
|
| + blink::WebLocalFrame* frame);
|
| +
|
| + // Checks if all scripts have been injected and finished.
|
| + void TryToFinish();
|
|
|
| // Inject any CSS source into the |frame|.
|
| void InjectCss(blink::WebLocalFrame* frame);
|
| @@ -100,6 +125,19 @@ class ScriptInjection {
|
| // or because it will never complete.
|
| bool complete_;
|
|
|
| + // Number of frames in which the injection is running.
|
| + int running_frames_;
|
| +
|
| + // Results storage.
|
| + scoped_ptr<base::ListValue> execution_results_;
|
| +
|
| + // Flag is true when injections for each frame started.
|
| + bool all_injections_started_;
|
| +
|
| + // ScriptInjectionManager::OnInjectionFinished will be called after injection
|
| + // finished.
|
| + ScriptInjectionManager* script_injection_manager_;
|
| +
|
| DISALLOW_COPY_AND_ASSIGN(ScriptInjection);
|
| };
|
|
|
|
|