| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_ACTIVE_SCRIPT_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_ACTIVE_SCRIPT_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_ACTIVE_SCRIPT_CONTROLLER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_ACTIVE_SCRIPT_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> |
| 11 | 12 |
| 13 #include "base/callback.h" |
| 12 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 13 #include "base/memory/linked_ptr.h" | 15 #include "base/memory/linked_ptr.h" |
| 14 #include "chrome/browser/extensions/location_bar_controller.h" | 16 #include "chrome/browser/extensions/location_bar_controller.h" |
| 15 #include "content/public/browser/web_contents_observer.h" | 17 #include "content/public/browser/web_contents_observer.h" |
| 16 | 18 |
| 17 namespace content { | 19 namespace content { |
| 18 class WebContents; | 20 class WebContents; |
| 19 } | 21 } |
| 20 | 22 |
| 21 namespace IPC { | 23 namespace IPC { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 35 public content::WebContentsObserver { | 37 public content::WebContentsObserver { |
| 36 public: | 38 public: |
| 37 explicit ActiveScriptController(content::WebContents* web_contents); | 39 explicit ActiveScriptController(content::WebContents* web_contents); |
| 38 virtual ~ActiveScriptController(); | 40 virtual ~ActiveScriptController(); |
| 39 | 41 |
| 40 // Returns the ActiveScriptController for the given |web_contents|, or NULL | 42 // Returns the ActiveScriptController for the given |web_contents|, or NULL |
| 41 // if one does not exist. | 43 // if one does not exist. |
| 42 static ActiveScriptController* GetForWebContents( | 44 static ActiveScriptController* GetForWebContents( |
| 43 content::WebContents* web_contents); | 45 content::WebContents* web_contents); |
| 44 | 46 |
| 45 // Notify the ActiveScriptController that an extension is running a script. | 47 // Returns true if the extension requesting script injection requires |
| 46 // TODO(rdevlin.cronin): Soon, this should be ask the user for permission, | 48 // user consent. If this is true, the caller should then register a request |
| 47 // rather than simply notifying them. | 49 // via RequestScriptInjection(). |
| 48 void NotifyScriptExecuting(const std::string& extension_id, int page_id); | 50 bool RequiresUserConsentForScriptInjection(const std::string& extension_id, |
| 51 int page_id); |
| 52 |
| 53 // Register a request for a script injection, to be executed by running |
| 54 // |callback|. The only assumption that can be made about when (or if) |
| 55 // |callback| is run is that, if it is run, it will run on the current page. |
| 56 void RequestScriptInjection(const std::string& extension_id, |
| 57 const base::Closure& callback); |
| 49 | 58 |
| 50 // Notifies the ActiveScriptController of detected ad injection. | 59 // Notifies the ActiveScriptController of detected ad injection. |
| 51 void OnAdInjectionDetected(const std::vector<std::string> ad_injectors); | 60 void OnAdInjectionDetected(const std::vector<std::string> ad_injectors); |
| 52 | 61 |
| 53 // LocationBarControllerProvider implementation. | 62 // LocationBarControllerProvider implementation. |
| 54 virtual ExtensionAction* GetActionForExtension( | 63 virtual ExtensionAction* GetActionForExtension( |
| 55 const Extension* extension) OVERRIDE; | 64 const Extension* extension) OVERRIDE; |
| 56 virtual LocationBarController::Action OnClicked( | 65 virtual LocationBarController::Action OnClicked( |
| 57 const Extension* extension) OVERRIDE; | 66 const Extension* extension) OVERRIDE; |
| 58 virtual void OnNavigated() OVERRIDE; | 67 virtual void OnNavigated() OVERRIDE; |
| 59 | 68 |
| 60 private: | 69 private: |
| 70 typedef std::vector<base::Closure> PendingRequestList; |
| 71 typedef std::map<std::string, PendingRequestList> PendingRequestMap; |
| 72 |
| 73 // Handles the NotifyExtensionScriptExecution message. |
| 74 void OnNotifyExtensionScriptExecution(const std::string& extension_id, |
| 75 int page_id); |
| 76 |
| 61 // content::WebContentsObserver implementation. | 77 // content::WebContentsObserver implementation. |
| 62 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 78 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 63 | 79 |
| 64 // Handle the NotifyExtensionScriptExecution message. | |
| 65 void OnNotifyExtensionScriptExecution(const std::string& extension_id, | |
| 66 int page_id); | |
| 67 | |
| 68 // Log metrics. | 80 // Log metrics. |
| 69 void LogUMA() const; | 81 void LogUMA() const; |
| 70 | 82 |
| 71 // Whether or not the ActiveScriptController is enabled (corresponding to the | 83 // Whether or not the ActiveScriptController is enabled (corresponding to the |
| 72 // kActiveScriptEnforcement switch). If it is not, it acts as an empty shell, | 84 // kActiveScriptEnforcement switch). If it is not, it acts as an empty shell, |
| 73 // always allowing scripts to run and never displaying actions. | 85 // always allowing scripts to run and never displaying actions. |
| 74 bool enabled_; | 86 bool enabled_; |
| 75 | 87 |
| 76 // The extensions that have called ExecuteScript on the current frame. | 88 // The map of extension_id:pending_request of all pending requests. |
| 77 std::set<std::string> extensions_executing_scripts_; | 89 PendingRequestMap pending_requests_; |
| 78 | 90 |
| 79 // The extensions which have injected ads. | 91 // The extensions which have been granted permission to run on the given page. |
| 80 std::set<std::string> ad_injectors_; | 92 // TODO(rdevlin.cronin): Right now, this just keeps track of extensions that |
| 93 // have been permitted to run on the page via this interface. Instead, it |
| 94 // should incorporate more fully with ActiveTab. |
| 95 std::set<std::string> permitted_extensions_; |
| 81 | 96 |
| 82 // Script badges that have been generated for extensions. This is both those | 97 // Script badges that have been generated for extensions. This is both those |
| 83 // with actions already declared that are copied and normalised, and actions | 98 // with actions already declared that are copied and normalised, and actions |
| 84 // that get generated for extensions that haven't declared anything. | 99 // that get generated for extensions that haven't declared anything. |
| 85 typedef std::map<std::string, linked_ptr<ExtensionAction> > ActiveScriptMap; | 100 typedef std::map<std::string, linked_ptr<ExtensionAction> > ActiveScriptMap; |
| 86 ActiveScriptMap active_script_actions_; | 101 ActiveScriptMap active_script_actions_; |
| 87 | 102 |
| 88 DISALLOW_COPY_AND_ASSIGN(ActiveScriptController); | 103 DISALLOW_COPY_AND_ASSIGN(ActiveScriptController); |
| 89 }; | 104 }; |
| 90 | 105 |
| 91 } // namespace extensions | 106 } // namespace extensions |
| 92 | 107 |
| 93 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVE_SCRIPT_CONTROLLER_H_ | 108 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVE_SCRIPT_CONTROLLER_H_ |
| OLD | NEW |