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 Extension* extension); |
51 | |
52 // Register a request for a script injection, to be executed by running | |
53 // |callback|. The only assumption that can be made about when (or if) | |
54 // |callback| is run is that, if it is run, it will run on the current page. | |
55 void RequestScriptInjection(const Extension* extension, | |
56 int page_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 // A single pending request. This could be a pair, but we'd have way too many | |
71 // stl typedefs, and "request.closure" is nicer than "request.first". | |
72 struct PendingRequest { | |
73 PendingRequest(); // For STL. | |
74 PendingRequest(const base::Closure closure, int page_id); | |
not at google - send to devlin
2014/05/16 17:32:12
const base::Closure&
Devlin
2014/05/19 16:17:46
Done.
| |
75 ~PendingRequest(); | |
76 | |
77 base::Closure closure; | |
78 int page_id; | |
79 }; | |
80 typedef std::vector<PendingRequest> PendingRequestList; | |
81 typedef std::map<std::string, PendingRequestList> PendingRequestMap; | |
82 | |
83 // Handles the NotifyExtensionScriptExecution message. | |
84 void OnNotifyExtensionScriptExecution(const std::string& extension_id, | |
85 int page_id); | |
86 | |
61 // content::WebContentsObserver implementation. | 87 // content::WebContentsObserver implementation. |
62 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 88 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
63 | 89 |
64 // Handle the NotifyExtensionScriptExecution message. | |
65 void OnNotifyExtensionScriptExecution(const std::string& extension_id, | |
66 int page_id); | |
67 | |
68 // Log metrics. | 90 // Log metrics. |
69 void LogUMA() const; | 91 void LogUMA() const; |
70 | 92 |
71 // Whether or not the ActiveScriptController is enabled (corresponding to the | 93 // Whether or not the ActiveScriptController is enabled (corresponding to the |
72 // kActiveScriptEnforcement switch). If it is not, it acts as an empty shell, | 94 // kActiveScriptEnforcement switch). If it is not, it acts as an empty shell, |
73 // always allowing scripts to run and never displaying actions. | 95 // always allowing scripts to run and never displaying actions. |
74 bool enabled_; | 96 bool enabled_; |
75 | 97 |
76 // The extensions that have called ExecuteScript on the current frame. | 98 // The map of extension_id:pending_request of all pending requests. |
77 std::set<std::string> extensions_executing_scripts_; | 99 PendingRequestMap pending_requests_; |
78 | 100 |
79 // The extensions which have injected ads. | 101 // The extensions which have been granted permission to run on the given page. |
80 std::set<std::string> ad_injectors_; | 102 // TODO(rdevlin.cronin): Right now, this just keeps track of extensions that |
103 // have been permitted to run on the page via this interface. Instead, it | |
104 // should incorporate more fully with ActiveTab. | |
105 std::set<std::string> permitted_extensions_; | |
81 | 106 |
82 // Script badges that have been generated for extensions. This is both those | 107 // Script badges that have been generated for extensions. This is both those |
83 // with actions already declared that are copied and normalised, and actions | 108 // with actions already declared that are copied and normalised, and actions |
84 // that get generated for extensions that haven't declared anything. | 109 // that get generated for extensions that haven't declared anything. |
85 typedef std::map<std::string, linked_ptr<ExtensionAction> > ActiveScriptMap; | 110 typedef std::map<std::string, linked_ptr<ExtensionAction> > ActiveScriptMap; |
86 ActiveScriptMap active_script_actions_; | 111 ActiveScriptMap active_script_actions_; |
87 | 112 |
88 DISALLOW_COPY_AND_ASSIGN(ActiveScriptController); | 113 DISALLOW_COPY_AND_ASSIGN(ActiveScriptController); |
89 }; | 114 }; |
90 | 115 |
91 } // namespace extensions | 116 } // namespace extensions |
92 | 117 |
93 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVE_SCRIPT_CONTROLLER_H_ | 118 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVE_SCRIPT_CONTROLLER_H_ |
OLD | NEW |