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> |
(...skipping 23 matching lines...) Expand all Loading... |
34 class ExtensionRegistry; | 34 class ExtensionRegistry; |
35 | 35 |
36 // The provider for ExtensionActions corresponding to scripts which are actively | 36 // The provider for ExtensionActions corresponding to scripts which are actively |
37 // running or need permission. | 37 // running or need permission. |
38 // TODO(rdevlin.cronin): This isn't really a controller, but it has good parity | 38 // TODO(rdevlin.cronin): This isn't really a controller, but it has good parity |
39 // with LocationBar"Controller". | 39 // with LocationBar"Controller". |
40 class ActiveScriptController : public content::WebContentsObserver, | 40 class ActiveScriptController : public content::WebContentsObserver, |
41 public ExtensionRegistryObserver { | 41 public ExtensionRegistryObserver { |
42 public: | 42 public: |
43 explicit ActiveScriptController(content::WebContents* web_contents); | 43 explicit ActiveScriptController(content::WebContents* web_contents); |
44 virtual ~ActiveScriptController(); | 44 ~ActiveScriptController() override; |
45 | 45 |
46 // Returns the ActiveScriptController for the given |web_contents|, or NULL | 46 // Returns the ActiveScriptController for the given |web_contents|, or NULL |
47 // if one does not exist. | 47 // if one does not exist. |
48 static ActiveScriptController* GetForWebContents( | 48 static ActiveScriptController* GetForWebContents( |
49 content::WebContents* web_contents); | 49 content::WebContents* web_contents); |
50 | 50 |
51 // Notifies the ActiveScriptController that an extension has been granted | 51 // Notifies the ActiveScriptController that an extension has been granted |
52 // active tab permissions. This will run any pending injections for that | 52 // active tab permissions. This will run any pending injections for that |
53 // extension. | 53 // extension. |
54 void OnActiveTabPermissionGranted(const Extension* extension); | 54 void OnActiveTabPermissionGranted(const Extension* extension); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 void PermitScriptInjection(int64 request_id); | 110 void PermitScriptInjection(int64 request_id); |
111 | 111 |
112 // Notifies the ExtensionActionAPI of a change (either that an extension now | 112 // Notifies the ExtensionActionAPI of a change (either that an extension now |
113 // wants permission to run, or that it has been run). | 113 // wants permission to run, or that it has been run). |
114 void NotifyChange(const Extension* extension); | 114 void NotifyChange(const Extension* extension); |
115 | 115 |
116 // Log metrics. | 116 // Log metrics. |
117 void LogUMA() const; | 117 void LogUMA() const; |
118 | 118 |
119 // content::WebContentsObserver implementation. | 119 // content::WebContentsObserver implementation. |
120 virtual bool OnMessageReceived(const IPC::Message& message) override; | 120 bool OnMessageReceived(const IPC::Message& message) override; |
121 virtual void DidNavigateMainFrame( | 121 void DidNavigateMainFrame( |
122 const content::LoadCommittedDetails& details, | 122 const content::LoadCommittedDetails& details, |
123 const content::FrameNavigateParams& params) override; | 123 const content::FrameNavigateParams& params) override; |
124 | 124 |
125 // ExtensionRegistryObserver: | 125 // ExtensionRegistryObserver: |
126 virtual void OnExtensionUnloaded( | 126 void OnExtensionUnloaded(content::BrowserContext* browser_context, |
127 content::BrowserContext* browser_context, | 127 const Extension* extension, |
128 const Extension* extension, | 128 UnloadedExtensionInfo::Reason reason) override; |
129 UnloadedExtensionInfo::Reason reason) override; | |
130 | 129 |
131 // The associated browser context. | 130 // The associated browser context. |
132 content::BrowserContext* browser_context_; | 131 content::BrowserContext* browser_context_; |
133 | 132 |
134 // Whether or not the ActiveScriptController is enabled (corresponding to the | 133 // Whether or not the ActiveScriptController is enabled (corresponding to the |
135 // kActiveScriptEnforcement switch). If it is not, it acts as an empty shell, | 134 // kActiveScriptEnforcement switch). If it is not, it acts as an empty shell, |
136 // always allowing scripts to run and never displaying actions. | 135 // always allowing scripts to run and never displaying actions. |
137 bool enabled_; | 136 bool enabled_; |
138 | 137 |
139 // The map of extension_id:pending_request of all pending requests. | 138 // The map of extension_id:pending_request of all pending requests. |
140 PendingRequestMap pending_requests_; | 139 PendingRequestMap pending_requests_; |
141 | 140 |
142 // The extensions which have been granted permission to run on the given page. | 141 // The extensions which have been granted permission to run on the given page. |
143 // TODO(rdevlin.cronin): Right now, this just keeps track of extensions that | 142 // TODO(rdevlin.cronin): Right now, this just keeps track of extensions that |
144 // have been permitted to run on the page via this interface. Instead, it | 143 // have been permitted to run on the page via this interface. Instead, it |
145 // should incorporate more fully with ActiveTab. | 144 // should incorporate more fully with ActiveTab. |
146 std::set<std::string> permitted_extensions_; | 145 std::set<std::string> permitted_extensions_; |
147 | 146 |
148 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> | 147 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
149 extension_registry_observer_; | 148 extension_registry_observer_; |
150 | 149 |
151 DISALLOW_COPY_AND_ASSIGN(ActiveScriptController); | 150 DISALLOW_COPY_AND_ASSIGN(ActiveScriptController); |
152 }; | 151 }; |
153 | 152 |
154 } // namespace extensions | 153 } // namespace extensions |
155 | 154 |
156 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVE_SCRIPT_CONTROLLER_H_ | 155 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVE_SCRIPT_CONTROLLER_H_ |
OLD | NEW |