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

Unified Diff: chrome/browser/extensions/active_script_controller.h

Issue 270153004: Introduce ActiveScriptController; track active extension scripts (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Kalman's 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: chrome/browser/extensions/active_script_controller.h
diff --git a/chrome/browser/extensions/active_script_controller.h b/chrome/browser/extensions/active_script_controller.h
new file mode 100644
index 0000000000000000000000000000000000000000..8b938e7dc88ba0eadac198baf2436da5a09f8715
--- /dev/null
+++ b/chrome/browser/extensions/active_script_controller.h
@@ -0,0 +1,70 @@
+// 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 CHROME_BROWSER_EXTENSIONS_ACTIVE_SCRIPT_CONTROLLER_H_
+#define CHROME_BROWSER_EXTENSIONS_ACTIVE_SCRIPT_CONTROLLER_H_
+
+#include <map>
+#include <set>
+#include <string>
+
+#include "base/compiler_specific.h"
+#include "base/memory/linked_ptr.h"
+#include "chrome/browser/extensions/location_bar_controller_provider.h"
+
+namespace content {
+class WebContents;
+}
+
+class ExtensionAction;
+
+namespace extensions {
+class Extension;
+
+// The provider for ExtensionActions corresponding to scripts which are actively
+// running or need permission.
+class ActiveScriptController : public LocationBarControllerProvider {
not at google - send to devlin 2014/05/08 20:47:09 "Controller" is not an accurate term at this point
Devlin 2014/05/08 23:01:00 Added a TODO, per offline conversation.
+ public:
+ explicit ActiveScriptController(content::WebContents* web_contents);
+ virtual ~ActiveScriptController();
+
+ // Notify the ActiveScriptController that an extension is running a script.
+ // TODO(rdevlin.cronin): Soon, this should be ask the user for permission,
+ // rather than simply notifying them.
+ void NotifyScriptExecuting(const std::string& extension_id, int page_id);
not at google - send to devlin 2014/05/08 20:47:09 it would be a more convenient interface to pass th
Devlin 2014/05/08 23:01:00 Since this is forwarded via IPC, it doesn't make s
+
+ // Returns true if there is an entry for the given |extension_id|.
+ bool HasActionForExtensionId(const std::string& extension_id);
not at google - send to devlin 2014/05/08 20:47:09 ditto
Devlin 2014/05/08 23:01:00 Moot.
+
+ // LocationBarControllerProvider implementation.
+ virtual ExtensionAction* GetActionForExtension(
+ const Extension* extension) OVERRIDE;
+ virtual LocationBarController::Action OnClicked(
+ const Extension* extension) OVERRIDE;
+ virtual void OnNavigated() OVERRIDE;
+
+ private:
+ // The associated WebContents.
+ content::WebContents* web_contents_;
+
+ // Whether or not the ActiveScriptController is enabled (corresponding to the
+ // kActiveScriptEnforcement switch). If it is not, it acts as an empty shell,
+ // always allowing scripts to run and never displaying actions.
+ bool enabled_;
+
+ // The extensions that have called ExecuteScript on the current frame.
+ std::set<std::string> extensions_executing_scripts_;
+
+ // Script badges that have been generated for extensions. This is both those
+ // with actions already declared that are copied and normalised, and actions
+ // that get generated for extensions that haven't declared anything.
+ typedef std::map<std::string, linked_ptr<ExtensionAction> > ActiveScriptMap;
+ ActiveScriptMap active_script_actions_;
+
+ DISALLOW_COPY_AND_ASSIGN(ActiveScriptController);
+};
+
+} // namespace extensions
+
+#endif // CHROME_BROWSER_EXTENSIONS_ACTIVE_SCRIPT_CONTROLLER_H_

Powered by Google App Engine
This is Rietveld 408576698