Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Unified Diff: extensions/renderer/script_injection_manager.h

Issue 321993003: Refactor renderer-side script injection (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Missing files Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: extensions/renderer/script_injection_manager.h
diff --git a/extensions/renderer/script_injection_manager.h b/extensions/renderer/script_injection_manager.h
new file mode 100644
index 0000000000000000000000000000000000000000..055b31b18caa27e2b16627dcd6d25fc79b6dd362
--- /dev/null
+++ b/extensions/renderer/script_injection_manager.h
@@ -0,0 +1,124 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef EXTENSIONS_RENDERER_SCRIPT_INJECTION_MANAGER_H_
+#define EXTENSIONS_RENDERER_SCRIPT_INJECTION_MANAGER_H_
+
+#include <map>
+#include <set>
+#include <string>
+
+#include "base/callback.h"
+#include "base/memory/scoped_vector.h"
+#include "base/memory/shared_memory.h"
+#include "base/scoped_observer.h"
+#include "extensions/common/user_script.h"
+#include "extensions/renderer/script_injection.h"
+#include "extensions/renderer/user_script_injection_list.h"
+
+struct ExtensionMsg_ExecuteCode_Params;
+
+namespace blink {
+class WebFrame;
+class WebLocalFrame;
+}
+
+namespace content {
+class RenderView;
+}
+
+namespace extensions {
+class Extension;
+class ExtensionSet;
+
+// The ScriptInjectionManager manages extensions injecting scripts into frames
+// via both content/user scripts and tabs.executeScript(). It is responsible for
+// maintaining any pending injections awaiting permission or the appropriate
+// load point, and injecting them when ready.
+class ScriptInjectionManager : public UserScriptInjectionList::Observer {
+ public:
+ explicit ScriptInjectionManager(const ExtensionSet* extensions);
+ virtual ~ScriptInjectionManager();
+
+ // Notifies that a new render view has been created.
+ void OnRenderViewCreated(content::RenderView* render_view);
+
+ UserScriptInjectionList* user_script_injection_list() {
not at google - send to devlin 2014/06/15 23:53:38 it would make more sense to me for Dispatcher to o
Devlin 2014/06/16 18:11:16 Done.
+ return user_script_injection_list_.get();
+ }
+
+ private:
+ // A RenderViewObserver implementation which watches the various render views
+ // in order to notify the ScriptInjectionManager of different document load
+ // states.
+ class RVOHelper;
+
+ // A struct to hold the current RunLocation for each frame, and whether or
+ // not scripts set to document_idle have been run.
+ struct FrameStatus {
+ FrameStatus();
+
+ UserScript::RunLocation current_location;
+ bool has_run_idle;
+ };
+ typedef std::map<blink::WebFrame*, FrameStatus> FrameStatusMap;
+
+ // UserScriptInjectionList::Observer implementation.
+ virtual void OnUserScriptsUpdated(
+ const std::set<std::string>& changed_extensions,
+ const std::vector<UserScript*>& scripts) OVERRIDE;
+
+ // Notifies that an RVOHelper should be removed.
+ void RemoveObserver(RVOHelper* helper);
+
+ // Invalidate any pending tasks associated with |frame|.
+ void InvalidateForFrame(blink::WebFrame* frame);
+
+ // Inject appropriate scripts into |frame|.
+ void InjectScripts(blink::WebFrame* frame,
+ UserScript::RunLocation run_location);
+
+ // Requests permission for the given |injection| or immediately injects,
+ // depending on whether or not the feature is enabled.
+ void RequestPermissionOrInject(scoped_ptr<ScriptInjection> injection,
+ ScriptInjection::ScriptsRunInfo*,
+ const Extension* extension);
+
+ // Handle the ExecuteCode extension message.
+ void HandleExecuteCode(const ExtensionMsg_ExecuteCode_Params& params,
+ content::RenderView* render_view);
+
+ // Handle the GrantInjectionPermission extension message.
+ void HandlePermitScriptInjection(int request_id);
+
+ // Extensions metadata, owned by Dispatcher (which owns this object).
+ const ExtensionSet* extensions_;
+
+ // The map of active web frames to their corresponding statuses.
+ FrameStatusMap frame_statuses_;
+
+ // The collection of RVOHelpers.
+ ScopedVector<RVOHelper> rvo_helpers_;
+
+ // The UserScriptInjectionList, to create the ScriptInjections for extensions'
+ // UserScripts.
+ scoped_ptr<UserScriptInjectionList> user_script_injection_list_;
+
+ // Pending injections which are waiting for the proper RunLocation.
+ ScopedVector<ScriptInjection> injections_awaiting_location_;
+
+ // Pending injections which are waiting for user consent.
+ ScopedVector<ScriptInjection> injections_awaiting_permission_;
+
+ // Note: This must be declared after UserScriptInjectionList so that the
+ // observer is removed before UserScriptInjectionList is destroyed.
+ ScopedObserver<UserScriptInjectionList, UserScriptInjectionList::Observer>
+ user_script_injection_list_observer_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScriptInjectionManager);
+};
+
+} // namespace extensions
+
+#endif // EXTENSIONS_RENDERER_SCRIPT_INJECTION_MANAGER_H_

Powered by Google App Engine
This is Rietveld 408576698