| 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 #include <vector> |
| 12 | 12 |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/memory/linked_ptr.h" | 15 #include "base/scoped_observer.h" |
| 16 #include "chrome/browser/extensions/location_bar_controller.h" | |
| 17 #include "content/public/browser/web_contents_observer.h" | 16 #include "content/public/browser/web_contents_observer.h" |
| 18 #include "extensions/browser/extension_registry_observer.h" | 17 #include "extensions/browser/extension_registry_observer.h" |
| 19 #include "extensions/common/permissions/permissions_data.h" | 18 #include "extensions/common/permissions/permissions_data.h" |
| 20 #include "extensions/common/user_script.h" | 19 #include "extensions/common/user_script.h" |
| 21 | 20 |
| 22 namespace content { | 21 namespace content { |
| 23 class WebContents; | 22 class WebContents; |
| 24 } | 23 } |
| 25 | 24 |
| 26 namespace IPC { | 25 namespace IPC { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 57 void OnAdInjectionDetected(const std::set<std::string>& ad_injectors); | 56 void OnAdInjectionDetected(const std::set<std::string>& ad_injectors); |
| 58 | 57 |
| 59 // Adds the visible origin to |extension|'s active permissions, granting | 58 // Adds the visible origin to |extension|'s active permissions, granting |
| 60 // |extension| permission to always run script injections on the origin. | 59 // |extension| permission to always run script injections on the origin. |
| 61 void AlwaysRunOnVisibleOrigin(const Extension* extension); | 60 void AlwaysRunOnVisibleOrigin(const Extension* extension); |
| 62 | 61 |
| 63 // Notifies the ActiveScriptController that the action for |extension| has | 62 // Notifies the ActiveScriptController that the action for |extension| has |
| 64 // been clicked, running any pending tasks that were previously shelved. | 63 // been clicked, running any pending tasks that were previously shelved. |
| 65 void OnClicked(const Extension* extension); | 64 void OnClicked(const Extension* extension); |
| 66 | 65 |
| 67 // Returns true if there is an active script injection action for |extension|. | 66 // Returns true if the given |extension| has a pending script that wants to |
| 68 bool HasActiveScriptAction(const Extension* extension); | 67 // run. |
| 69 | 68 bool WantsToRun(const Extension* extension); |
| 70 // Returns the action to display for the given |extension|, or NULL if no | |
| 71 // action should be displayed. | |
| 72 ExtensionAction* GetActionForExtension(const Extension* extension); | |
| 73 | 69 |
| 74 #if defined(UNIT_TEST) | 70 #if defined(UNIT_TEST) |
| 75 // Only used in tests. | 71 // Only used in tests. |
| 76 PermissionsData::AccessType RequiresUserConsentForScriptInjectionForTesting( | 72 PermissionsData::AccessType RequiresUserConsentForScriptInjectionForTesting( |
| 77 const Extension* extension, | 73 const Extension* extension, |
| 78 UserScript::InjectionType type) { | 74 UserScript::InjectionType type) { |
| 79 return RequiresUserConsentForScriptInjection(extension, type); | 75 return RequiresUserConsentForScriptInjection(extension, type); |
| 80 } | 76 } |
| 81 void RequestScriptInjectionForTesting(const Extension* extension, | 77 void RequestScriptInjectionForTesting(const Extension* extension, |
| 82 const base::Closure& callback) { | 78 const base::Closure& callback) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 130 |
| 135 // The map of extension_id:pending_request of all pending requests. | 131 // The map of extension_id:pending_request of all pending requests. |
| 136 PendingRequestMap pending_requests_; | 132 PendingRequestMap pending_requests_; |
| 137 | 133 |
| 138 // The extensions which have been granted permission to run on the given page. | 134 // The extensions which have been granted permission to run on the given page. |
| 139 // TODO(rdevlin.cronin): Right now, this just keeps track of extensions that | 135 // TODO(rdevlin.cronin): Right now, this just keeps track of extensions that |
| 140 // have been permitted to run on the page via this interface. Instead, it | 136 // have been permitted to run on the page via this interface. Instead, it |
| 141 // should incorporate more fully with ActiveTab. | 137 // should incorporate more fully with ActiveTab. |
| 142 std::set<std::string> permitted_extensions_; | 138 std::set<std::string> permitted_extensions_; |
| 143 | 139 |
| 144 // Script badges that have been generated for extensions. This is both those | |
| 145 // with actions already declared that are copied and normalised, and actions | |
| 146 // that get generated for extensions that haven't declared anything. | |
| 147 typedef std::map<std::string, linked_ptr<ExtensionAction> > ActiveScriptMap; | |
| 148 ActiveScriptMap active_script_actions_; | |
| 149 | |
| 150 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> | 140 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
| 151 extension_registry_observer_; | 141 extension_registry_observer_; |
| 152 | 142 |
| 153 DISALLOW_COPY_AND_ASSIGN(ActiveScriptController); | 143 DISALLOW_COPY_AND_ASSIGN(ActiveScriptController); |
| 154 }; | 144 }; |
| 155 | 145 |
| 156 } // namespace extensions | 146 } // namespace extensions |
| 157 | 147 |
| 158 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVE_SCRIPT_CONTROLLER_H_ | 148 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVE_SCRIPT_CONTROLLER_H_ |
| OLD | NEW |