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

Unified Diff: extensions/renderer/user_script_injection.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/user_script_injection.h
diff --git a/extensions/renderer/user_script_injection.h b/extensions/renderer/user_script_injection.h
new file mode 100644
index 0000000000000000000000000000000000000000..d55e15650d0c004be1abd8b29dc61412aadae75c
--- /dev/null
+++ b/extensions/renderer/user_script_injection.h
@@ -0,0 +1,75 @@
+// 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_USER_SCRIPT_INJECTION_H_
+#define EXTENSIONS_RENDERER_USER_SCRIPT_INJECTION_H_
+
+#include "extensions/renderer/script_injection.h"
+
+#include <string>
+
+#include "base/memory/scoped_ptr.h"
+#include "base/scoped_observer.h"
+#include "extensions/common/user_script.h"
+#include "extensions/renderer/user_script_injection_list.h"
+
+namespace blink {
+class WebFrame;
+}
+
+namespace extensions {
+class Extension;
+
+// A ScriptInjection for UserScripts.
+class UserScriptInjection : public ScriptInjection,
+ public UserScriptInjectionList::Observer {
+ public:
+ UserScriptInjection(blink::WebFrame* web_frame,
+ const std::string& extension_id,
+ UserScript::RunLocation run_location,
+ int tab_id,
+ UserScriptInjectionList* script_list,
+ const UserScript* script,
+ bool inject_js,
+ bool inject_css);
+ virtual ~UserScriptInjection();
+
+ int64 script_id() const { return script_id_; }
+ void set_script(const UserScript* script) { script_ = script; }
+
+ private:
+ // Inject the JS/CSS specified in |script_|.
+ void InjectJS(const Extension* extension, ScriptsRunInfo* scripts_run_info);
+ void InjectCSS(ScriptsRunInfo* scripts_run_info);
+
+ // ScriptInjection implementation.
+ virtual bool Allowed(const Extension* extension) OVERRIDE;
+ virtual void Inject(ScriptsRunInfo* scripts_run_info,
+ const Extension* extension) OVERRIDE;
+
+ // UserScriptInjectionList::Observer implementation.
+ virtual void OnUserScriptsUpdated(
+ const std::set<std::string>& changed_extensions,
+ const std::vector<UserScript*>& scripts) OVERRIDE;
+
+ // The associated user script. Owned by the UserScriptInjection that created
+ // this object.
+ const UserScript* script_;
+
+ // The id of the associated user script.
+ int64 script_id_;
+
+ // Whether or not this should inject JS.
+ bool inject_js_;
+
+ // Whether or not this should inject CSS.
+ bool inject_css_;
+
+ ScopedObserver<UserScriptInjectionList, UserScriptInjectionList::Observer>
+ user_script_injection_list_observer_;
+};
+
+} // namespace extensions
+
+#endif // EXTENSIONS_RENDERER_USER_SCRIPT_INJECTION_H_

Powered by Google App Engine
This is Rietveld 408576698