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

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

Issue 516633002: Stop showing page actions in the location bar with redesign enabled (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Latest CQ for Master 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
« no previous file with comments | « no previous file | chrome/browser/extensions/active_script_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
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/memory/linked_ptr.h"
16 #include "chrome/browser/extensions/location_bar_controller.h" 16 #include "chrome/browser/extensions/location_bar_controller.h"
17 #include "content/public/browser/web_contents_observer.h" 17 #include "content/public/browser/web_contents_observer.h"
18 #include "extensions/browser/extension_registry_observer.h"
18 #include "extensions/common/permissions/permissions_data.h" 19 #include "extensions/common/permissions/permissions_data.h"
19 #include "extensions/common/user_script.h" 20 #include "extensions/common/user_script.h"
20 21
21 namespace content { 22 namespace content {
22 class WebContents; 23 class WebContents;
23 } 24 }
24 25
25 namespace IPC { 26 namespace IPC {
26 class Message; 27 class Message;
27 } 28 }
28 29
29 class ExtensionAction; 30 class ExtensionAction;
30 31
31 namespace extensions { 32 namespace extensions {
32 class Extension; 33 class Extension;
34 class ExtensionRegistry;
33 35
34 // The provider for ExtensionActions corresponding to scripts which are actively 36 // The provider for ExtensionActions corresponding to scripts which are actively
35 // running or need permission. 37 // running or need permission.
36 // 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
37 // with LocationBar"Controller". 39 // with LocationBar"Controller".
38 class ActiveScriptController : public content::WebContentsObserver { 40 class ActiveScriptController : public content::WebContentsObserver,
41 public ExtensionRegistryObserver {
39 public: 42 public:
40 explicit ActiveScriptController(content::WebContents* web_contents); 43 explicit ActiveScriptController(content::WebContents* web_contents);
41 virtual ~ActiveScriptController(); 44 virtual ~ActiveScriptController();
42 45
43 // Returns the ActiveScriptController for the given |web_contents|, or NULL 46 // Returns the ActiveScriptController for the given |web_contents|, or NULL
44 // if one does not exist. 47 // if one does not exist.
45 static ActiveScriptController* GetForWebContents( 48 static ActiveScriptController* GetForWebContents(
46 content::WebContents* web_contents); 49 content::WebContents* web_contents);
47 50
48 // Notifies the ActiveScriptController that an extension has been granted 51 // Notifies the ActiveScriptController that an extension has been granted
(...skipping 12 matching lines...) Expand all
61 // been clicked, running any pending tasks that were previously shelved. 64 // been clicked, running any pending tasks that were previously shelved.
62 void OnClicked(const Extension* extension); 65 void OnClicked(const Extension* extension);
63 66
64 // Returns true if there is an active script injection action for |extension|. 67 // Returns true if there is an active script injection action for |extension|.
65 bool HasActiveScriptAction(const Extension* extension); 68 bool HasActiveScriptAction(const Extension* extension);
66 69
67 // Returns the action to display for the given |extension|, or NULL if no 70 // Returns the action to display for the given |extension|, or NULL if no
68 // action should be displayed. 71 // action should be displayed.
69 ExtensionAction* GetActionForExtension(const Extension* extension); 72 ExtensionAction* GetActionForExtension(const Extension* extension);
70 73
71 // Notifies that the given |extension| has been unloaded; forwarded from the
72 // ExtensionRegistryObserver method.
73 void OnExtensionUnloaded(const Extension* extension);
74
75 #if defined(UNIT_TEST) 74 #if defined(UNIT_TEST)
76 // Only used in tests. 75 // Only used in tests.
77 PermissionsData::AccessType RequiresUserConsentForScriptInjectionForTesting( 76 PermissionsData::AccessType RequiresUserConsentForScriptInjectionForTesting(
78 const Extension* extension, 77 const Extension* extension,
79 UserScript::InjectionType type) { 78 UserScript::InjectionType type) {
80 return RequiresUserConsentForScriptInjection(extension, type); 79 return RequiresUserConsentForScriptInjection(extension, type);
81 } 80 }
82 void RequestScriptInjectionForTesting(const Extension* extension, 81 void RequestScriptInjectionForTesting(const Extension* extension,
83 const base::Closure& callback) { 82 const base::Closure& callback) {
84 return RequestScriptInjection(extension, callback); 83 return RequestScriptInjection(extension, callback);
(...skipping 21 matching lines...) Expand all
106 105
107 // Handle the RequestScriptInjectionPermission message. 106 // Handle the RequestScriptInjectionPermission message.
108 void OnRequestScriptInjectionPermission( 107 void OnRequestScriptInjectionPermission(
109 const std::string& extension_id, 108 const std::string& extension_id,
110 UserScript::InjectionType script_type, 109 UserScript::InjectionType script_type,
111 int64 request_id); 110 int64 request_id);
112 111
113 // Grants permission for the given request to run. 112 // Grants permission for the given request to run.
114 void PermitScriptInjection(int64 request_id); 113 void PermitScriptInjection(int64 request_id);
115 114
115 // Log metrics.
116 void LogUMA() const;
117
116 // content::WebContentsObserver implementation. 118 // content::WebContentsObserver implementation.
117 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 119 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
118 virtual void DidNavigateMainFrame( 120 virtual void DidNavigateMainFrame(
119 const content::LoadCommittedDetails& details, 121 const content::LoadCommittedDetails& details,
120 const content::FrameNavigateParams& params) OVERRIDE; 122 const content::FrameNavigateParams& params) OVERRIDE;
121 123
122 // Log metrics. 124 // ExtensionRegistryObserver:
123 void LogUMA() const; 125 virtual void OnExtensionUnloaded(
126 content::BrowserContext* browser_context,
127 const Extension* extension,
128 UnloadedExtensionInfo::Reason reason) OVERRIDE;
124 129
125 // Whether or not the ActiveScriptController is enabled (corresponding to the 130 // Whether or not the ActiveScriptController is enabled (corresponding to the
126 // kActiveScriptEnforcement switch). If it is not, it acts as an empty shell, 131 // kActiveScriptEnforcement switch). If it is not, it acts as an empty shell,
127 // always allowing scripts to run and never displaying actions. 132 // always allowing scripts to run and never displaying actions.
128 bool enabled_; 133 bool enabled_;
129 134
130 // The map of extension_id:pending_request of all pending requests. 135 // The map of extension_id:pending_request of all pending requests.
131 PendingRequestMap pending_requests_; 136 PendingRequestMap pending_requests_;
132 137
133 // The extensions which have been granted permission to run on the given page. 138 // The extensions which have been granted permission to run on the given page.
134 // TODO(rdevlin.cronin): Right now, this just keeps track of extensions that 139 // TODO(rdevlin.cronin): Right now, this just keeps track of extensions that
135 // have been permitted to run on the page via this interface. Instead, it 140 // have been permitted to run on the page via this interface. Instead, it
136 // should incorporate more fully with ActiveTab. 141 // should incorporate more fully with ActiveTab.
137 std::set<std::string> permitted_extensions_; 142 std::set<std::string> permitted_extensions_;
138 143
139 // Script badges that have been generated for extensions. This is both those 144 // Script badges that have been generated for extensions. This is both those
140 // with actions already declared that are copied and normalised, and actions 145 // with actions already declared that are copied and normalised, and actions
141 // that get generated for extensions that haven't declared anything. 146 // that get generated for extensions that haven't declared anything.
142 typedef std::map<std::string, linked_ptr<ExtensionAction> > ActiveScriptMap; 147 typedef std::map<std::string, linked_ptr<ExtensionAction> > ActiveScriptMap;
143 ActiveScriptMap active_script_actions_; 148 ActiveScriptMap active_script_actions_;
144 149
150 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
151 extension_registry_observer_;
152
145 DISALLOW_COPY_AND_ASSIGN(ActiveScriptController); 153 DISALLOW_COPY_AND_ASSIGN(ActiveScriptController);
146 }; 154 };
147 155
148 } // namespace extensions 156 } // namespace extensions
149 157
150 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVE_SCRIPT_CONTROLLER_H_ 158 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVE_SCRIPT_CONTROLLER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/active_script_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698