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

Unified Diff: extensions/renderer/user_script_slave.h

Issue 288053002: Block content scripts from executing until user grants permission (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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/user_script_slave.h
diff --git a/extensions/renderer/user_script_slave.h b/extensions/renderer/user_script_slave.h
index fc3da79ae05a9223e52566cc1118043fb3b75119..48fcf069f44d47fd5f1bafcf324f1c927e308609 100644
--- a/extensions/renderer/user_script_slave.h
+++ b/extensions/renderer/user_script_slave.h
@@ -10,11 +10,13 @@
#include <string>
#include <vector>
+#include "base/memory/linked_ptr.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/shared_memory.h"
#include "base/stl_util.h"
#include "base/strings/string_piece.h"
#include "extensions/common/user_script.h"
+#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/web/WebScriptSource.h"
class GURL;
@@ -23,12 +25,15 @@ namespace blink {
class WebFrame;
}
+namespace content {
+class RenderView;
+}
+
using blink::WebScriptSource;
namespace extensions {
class Extension;
class ExtensionSet;
-
// Manages installed UserScripts for a render process.
class UserScriptSlave {
public:
@@ -41,11 +46,6 @@ class UserScriptSlave {
// Update the parsed scripts from shared memory.
bool UpdateScripts(base::SharedMemoryHandle shared_memory);
- // Inject the appropriate scripts into a frame based on its URL.
- // TODO(aa): Extract a UserScriptFrame interface out of this to improve
- // testability.
- void InjectScripts(blink::WebFrame* frame, UserScript::RunLocation location);
-
// 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.
@@ -59,7 +59,50 @@ class UserScriptSlave {
void RemoveIsolatedWorld(const std::string& extension_id);
+ // Inject the appropriate scripts into a frame based on its URL.
+ // TODO(aa): Extract a UserScriptFrame interface out of this to improve
+ // testability.
+ void InjectScripts(blink::WebFrame* frame, UserScript::RunLocation location);
+
+ // Allow an extension to inject scripts that were previously delayed for user
+ // approval.
+ void OnContentScriptGrantedPermission(
+ content::RenderView* render_view, int request_id);
+
private:
+ // A PendingInjection that needs user approval before it can be executed.
+ struct PendingInjection;
+ typedef std::vector<linked_ptr<PendingInjection> > PendingInjectionList;
+
+ // The information about a given set of scripts being run. Primarily for
+ // metrics.
+ struct ScriptsRunInfo;
+
+ // Adds a pending injection to |pending_injections_|. Returns the id of the
+ // pending injection.
+ int AddPendingInjection(UserScript* script,
+ UserScript::RunLocation location,
+ const blink::WebString& frame_name);
+
+ // Inject the css scripts from the given |script| into the |frame|, and record
+ // metrics into |scripts_run_info|.
+ void InjectCSSScripts(blink::WebFrame* frame,
+ UserScript* script,
+ ScriptsRunInfo* scripts_run_info);
+
+ // Inject the js scripts from the given |script| into the |frame|, and record
+ // metrics into |scripts_run_info|.
+ void InjectJSScripts(blink::WebFrame* frame,
+ UserScript* script,
+ const Extension* extension,
+ ScriptsRunInfo* scripts_run_info);
+
+ // Log the data from scripts being run, including doing UMA and notifying the
+ // browser.
+ void LogScriptsRun(blink::WebFrame* frame,
+ UserScript::RunLocation location,
+ const ScriptsRunInfo& info);
+
// Shared memory containing raw script data.
scoped_ptr<base::SharedMemory> shared_memory_;
@@ -67,6 +110,9 @@ class UserScriptSlave {
std::vector<UserScript*> scripts_;
STLElementDeleter<std::vector<UserScript*> > script_deleter_;
+ // Map of extension ids to the injections pending for those extensions.
+ PendingInjectionList pending_injections_;
+
// Greasemonkey API source that is injected with the scripts.
base::StringPiece api_js_;

Powered by Google App Engine
This is Rietveld 408576698