OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_ACTIVE_SCRIPT_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_ACTIVE_SCRIPT_CONTROLLER_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <set> |
| 10 #include <string> |
| 11 |
| 12 #include "base/compiler_specific.h" |
| 13 #include "base/memory/linked_ptr.h" |
| 14 #include "chrome/browser/extensions/location_bar_controller_provider.h" |
| 15 |
| 16 namespace content { |
| 17 class WebContents; |
| 18 } |
| 19 |
| 20 class ExtensionAction; |
| 21 |
| 22 namespace extensions { |
| 23 class Extension; |
| 24 |
| 25 // The provider for ExtensionActions corresponding to scripts which are actively |
| 26 // running or need permission. |
| 27 class ActiveScriptController : public LocationBarControllerProvider { |
| 28 public: |
| 29 explicit ActiveScriptController(content::WebContents* web_contents); |
| 30 virtual ~ActiveScriptController(); |
| 31 |
| 32 // Notify the ActiveScriptController that an extension is running a script. |
| 33 // TODO(rdevlin.cronin): Soon, this should be ask the user for permission, |
| 34 // rather than simply notifying them. |
| 35 void NotifyScriptExecuting(const std::string& extension_id); |
| 36 |
| 37 // Returns true if there is an entry for the given |extension_id|. |
| 38 bool HasActionForExtensionId(const std::string& extension_id); |
| 39 |
| 40 // LocationBarControllerProvider implementation. |
| 41 virtual std::vector<ExtensionAction*> GetCurrentActions() OVERRIDE; |
| 42 virtual LocationBarController::Action OnClicked( |
| 43 const Extension* extension, |
| 44 LocationBarController::MouseButton button) OVERRIDE; |
| 45 virtual void NavigatedMainFrame( |
| 46 const content::LoadCommittedDetails& details, |
| 47 const content::FrameNavigateParams& params) OVERRIDE; |
| 48 |
| 49 private: |
| 50 // Returns an extension action for the given |extension|, creating one if |
| 51 // necessary. |
| 52 ExtensionAction* GetActionForExtension(const Extension* extension); |
| 53 |
| 54 // Whether or not the ActiveScriptController is enabled (corresponding to the |
| 55 // kActiveScriptEnforcement switch). If it is not, it acts as an empty shell, |
| 56 // always allowing scripts to run and never displaying actions. |
| 57 bool enabled_; |
| 58 |
| 59 // The extensions that have called ExecuteScript on the current frame. |
| 60 std::set<std::string> extensions_executing_scripts_; |
| 61 |
| 62 // Script badges that have been generated for extensions. This is both those |
| 63 // with actions already declared that are copied and normalised, and actions |
| 64 // that get generated for extensions that haven't declared anything. |
| 65 typedef std::map<std::string, linked_ptr<ExtensionAction> > ActiveScriptMap; |
| 66 ActiveScriptMap script_badges_; |
| 67 |
| 68 DISALLOW_COPY_AND_ASSIGN(ActiveScriptController); |
| 69 }; |
| 70 |
| 71 } // namespace extensions |
| 72 |
| 73 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVE_SCRIPT_CONTROLLER_H_ |
OLD | NEW |