Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1240)

Side by Side Diff: chrome/browser/extensions/active_script_controller.h

Issue 508563003: Remove PageActionsController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 16 matching lines...) Expand all
27 } 27 }
28 28
29 class ExtensionAction; 29 class ExtensionAction;
30 30
31 namespace extensions { 31 namespace extensions {
32 class Extension; 32 class Extension;
33 33
34 // The provider for ExtensionActions corresponding to scripts which are actively 34 // The provider for ExtensionActions corresponding to scripts which are actively
35 // running or need permission. 35 // running or need permission.
36 // TODO(rdevlin.cronin): This isn't really a controller, but it has good parity 36 // TODO(rdevlin.cronin): This isn't really a controller, but it has good parity
37 // with PageAction"Controller". 37 // with LocationBar"Controller".
38 class ActiveScriptController : public LocationBarController::ActionProvider, 38 class ActiveScriptController : public content::WebContentsObserver {
39 public content::WebContentsObserver {
40 public: 39 public:
41 explicit ActiveScriptController(content::WebContents* web_contents); 40 explicit ActiveScriptController(content::WebContents* web_contents);
42 virtual ~ActiveScriptController(); 41 virtual ~ActiveScriptController();
43 42
44 // Returns the ActiveScriptController for the given |web_contents|, or NULL 43 // Returns the ActiveScriptController for the given |web_contents|, or NULL
45 // if one does not exist. 44 // if one does not exist.
46 static ActiveScriptController* GetForWebContents( 45 static ActiveScriptController* GetForWebContents(
47 content::WebContents* web_contents); 46 content::WebContents* web_contents);
48 47
49 // Notifies the ActiveScriptController that an extension has been granted 48 // Notifies the ActiveScriptController that an extension has been granted
50 // active tab permissions. This will run any pending injections for that 49 // active tab permissions. This will run any pending injections for that
51 // extension. 50 // extension.
52 void OnActiveTabPermissionGranted(const Extension* extension); 51 void OnActiveTabPermissionGranted(const Extension* extension);
53 52
54 // Notifies the ActiveScriptController of detected ad injection. 53 // Notifies the ActiveScriptController of detected ad injection.
55 void OnAdInjectionDetected(const std::set<std::string>& ad_injectors); 54 void OnAdInjectionDetected(const std::set<std::string>& ad_injectors);
56 55
57 // Adds the visible origin to |extension|'s active permissions, granting 56 // Adds the visible origin to |extension|'s active permissions, granting
58 // |extension| permission to always run script injections on the origin. 57 // |extension| permission to always run script injections on the origin.
59 void AlwaysRunOnVisibleOrigin(const Extension* extension); 58 void AlwaysRunOnVisibleOrigin(const Extension* extension);
60 59
61 // Notifies the ActiveScriptController that the action for |extension| has 60 // Notifies the ActiveScriptController that the action for |extension| has
62 // been clicked, running any pending tasks that were previously shelved. 61 // been clicked, running any pending tasks that were previously shelved.
63 void OnClicked(const Extension* extension); 62 void OnClicked(const Extension* extension);
64 63
65 // Returns true if there is an active script injection action for |extension|. 64 // Returns true if there is an active script injection action for |extension|.
66 bool HasActiveScriptAction(const Extension* extension); 65 bool HasActiveScriptAction(const Extension* extension);
67 66
68 // LocationBarControllerProvider implementation. 67 // Returns the action to display for the given |extension|, or NULL if no
69 virtual ExtensionAction* GetActionForExtension( 68 // action should be displayed.
70 const Extension* extension) OVERRIDE; 69 ExtensionAction* GetActionForExtension(const Extension* extension);
71 virtual void OnNavigated() OVERRIDE; 70
72 virtual void OnExtensionUnloaded(const Extension* extension) OVERRIDE; 71 // Notifies that the given |extension| has been unloaded; forwarded from the
72 // ExtensionRegistryObserver method.
73 void OnExtensionUnloaded(const Extension* extension);
73 74
74 #if defined(UNIT_TEST) 75 #if defined(UNIT_TEST)
75 // Only used in tests. 76 // Only used in tests.
76 PermissionsData::AccessType RequiresUserConsentForScriptInjectionForTesting( 77 PermissionsData::AccessType RequiresUserConsentForScriptInjectionForTesting(
77 const Extension* extension, 78 const Extension* extension,
78 UserScript::InjectionType type) { 79 UserScript::InjectionType type) {
79 return RequiresUserConsentForScriptInjection(extension, type); 80 return RequiresUserConsentForScriptInjection(extension, type);
80 } 81 }
81 void RequestScriptInjectionForTesting(const Extension* extension, 82 void RequestScriptInjectionForTesting(const Extension* extension,
82 const base::Closure& callback) { 83 const base::Closure& callback) {
(...skipping 24 matching lines...) Expand all
107 void OnRequestScriptInjectionPermission( 108 void OnRequestScriptInjectionPermission(
108 const std::string& extension_id, 109 const std::string& extension_id,
109 UserScript::InjectionType script_type, 110 UserScript::InjectionType script_type,
110 int64 request_id); 111 int64 request_id);
111 112
112 // Grants permission for the given request to run. 113 // Grants permission for the given request to run.
113 void PermitScriptInjection(int64 request_id); 114 void PermitScriptInjection(int64 request_id);
114 115
115 // content::WebContentsObserver implementation. 116 // content::WebContentsObserver implementation.
116 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 117 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
118 virtual void DidNavigateMainFrame(
119 const content::LoadCommittedDetails& details,
120 const content::FrameNavigateParams& params) OVERRIDE;
117 121
118 // Log metrics. 122 // Log metrics.
119 void LogUMA() const; 123 void LogUMA() const;
120 124
121 // Whether or not the ActiveScriptController is enabled (corresponding to the 125 // Whether or not the ActiveScriptController is enabled (corresponding to the
122 // kActiveScriptEnforcement switch). If it is not, it acts as an empty shell, 126 // kActiveScriptEnforcement switch). If it is not, it acts as an empty shell,
123 // always allowing scripts to run and never displaying actions. 127 // always allowing scripts to run and never displaying actions.
124 bool enabled_; 128 bool enabled_;
125 129
126 // The map of extension_id:pending_request of all pending requests. 130 // The map of extension_id:pending_request of all pending requests.
(...skipping 10 matching lines...) Expand all
137 // that get generated for extensions that haven't declared anything. 141 // that get generated for extensions that haven't declared anything.
138 typedef std::map<std::string, linked_ptr<ExtensionAction> > ActiveScriptMap; 142 typedef std::map<std::string, linked_ptr<ExtensionAction> > ActiveScriptMap;
139 ActiveScriptMap active_script_actions_; 143 ActiveScriptMap active_script_actions_;
140 144
141 DISALLOW_COPY_AND_ASSIGN(ActiveScriptController); 145 DISALLOW_COPY_AND_ASSIGN(ActiveScriptController);
142 }; 146 };
143 147
144 } // namespace extensions 148 } // namespace extensions
145 149
146 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVE_SCRIPT_CONTROLLER_H_ 150 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVE_SCRIPT_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698