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.h" |
| 15 #include "content/public/browser/web_contents_observer.h" |
| 16 |
| 17 namespace content { |
| 18 class WebContents; |
| 19 } |
| 20 |
| 21 namespace IPC { |
| 22 class Message; |
| 23 } |
| 24 |
| 25 class ExtensionAction; |
| 26 |
| 27 namespace extensions { |
| 28 class Extension; |
| 29 |
| 30 // The provider for ExtensionActions corresponding to scripts which are actively |
| 31 // running or need permission. |
| 32 // TODO(rdevlin.cronin): This isn't really a controller, but it has good parity |
| 33 // with PageAction"Controller". |
| 34 class ActiveScriptController : public LocationBarController::ActionProvider, |
| 35 public content::WebContentsObserver { |
| 36 public: |
| 37 explicit ActiveScriptController(content::WebContents* web_contents); |
| 38 virtual ~ActiveScriptController(); |
| 39 |
| 40 // Notify the ActiveScriptController that an extension is running a script. |
| 41 // TODO(rdevlin.cronin): Soon, this should be ask the user for permission, |
| 42 // rather than simply notifying them. |
| 43 void NotifyScriptExecuting(const std::string& extension_id, int page_id); |
| 44 |
| 45 // Notifies the ActiveScriptController of detected ad injection. |
| 46 void OnAdInjectionDetected(const std::vector<std::string> ad_injectors); |
| 47 |
| 48 // LocationBarControllerProvider implementation. |
| 49 virtual ExtensionAction* GetActionForExtension( |
| 50 const Extension* extension) OVERRIDE; |
| 51 virtual LocationBarController::Action OnClicked( |
| 52 const Extension* extension) OVERRIDE; |
| 53 virtual void OnNavigated() OVERRIDE; |
| 54 |
| 55 private: |
| 56 // content::WebContentsObserver implementation. |
| 57 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 58 |
| 59 // Handle the NotifyExtensionScriptExecution message. |
| 60 void OnNotifyExtensionScriptExecution(const std::string& extension_id, |
| 61 int page_id); |
| 62 |
| 63 // Log metrics. |
| 64 void LogUMA() const; |
| 65 |
| 66 // Whether or not the ActiveScriptController is enabled (corresponding to the |
| 67 // kActiveScriptEnforcement switch). If it is not, it acts as an empty shell, |
| 68 // always allowing scripts to run and never displaying actions. |
| 69 bool enabled_; |
| 70 |
| 71 // The extensions that have called ExecuteScript on the current frame. |
| 72 std::set<std::string> extensions_executing_scripts_; |
| 73 |
| 74 // The extensions which have injected ads. |
| 75 std::set<std::string> ad_injectors_; |
| 76 |
| 77 // Script badges that have been generated for extensions. This is both those |
| 78 // with actions already declared that are copied and normalised, and actions |
| 79 // that get generated for extensions that haven't declared anything. |
| 80 typedef std::map<std::string, linked_ptr<ExtensionAction> > ActiveScriptMap; |
| 81 ActiveScriptMap active_script_actions_; |
| 82 |
| 83 DISALLOW_COPY_AND_ASSIGN(ActiveScriptController); |
| 84 }; |
| 85 |
| 86 } // namespace extensions |
| 87 |
| 88 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVE_SCRIPT_CONTROLLER_H_ |
OLD | NEW |