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

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

Issue 1809813002: [Extensions] Show a "refresh" bubble when needed with click-to-script (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update comment Created 4 years, 9 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_EXTENSION_ACTION_RUNNER_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_RUNNER_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_RUNNER_H_ 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_RUNNER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
11 #include <set> 11 #include <set>
12 #include <string> 12 #include <string>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/callback.h" 15 #include "base/callback.h"
16 #include "base/compiler_specific.h" 16 #include "base/compiler_specific.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/memory/weak_ptr.h"
18 #include "base/scoped_observer.h" 19 #include "base/scoped_observer.h"
19 #include "chrome/browser/extensions/extension_action.h" 20 #include "chrome/browser/extensions/extension_action.h"
21 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_bubble_delegate.h"
20 #include "content/public/browser/web_contents_observer.h" 22 #include "content/public/browser/web_contents_observer.h"
21 #include "extensions/browser/blocked_action_type.h" 23 #include "extensions/browser/blocked_action_type.h"
22 #include "extensions/browser/extension_registry_observer.h" 24 #include "extensions/browser/extension_registry_observer.h"
23 #include "extensions/common/permissions/permissions_data.h" 25 #include "extensions/common/permissions/permissions_data.h"
24 #include "extensions/common/user_script.h" 26 #include "extensions/common/user_script.h"
25 27
26 namespace content { 28 namespace content {
27 class BrowserContext; 29 class BrowserContext;
28 class WebContents; 30 class WebContents;
29 } 31 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 // Called when a webRequest event for the given |extension| was blocked. 71 // Called when a webRequest event for the given |extension| was blocked.
70 void OnWebRequestBlocked(const Extension* extension); 72 void OnWebRequestBlocked(const Extension* extension);
71 73
72 // Returns a bitmask of BlockedActionType for the actions that have been 74 // Returns a bitmask of BlockedActionType for the actions that have been
73 // blocked for the given extension. 75 // blocked for the given extension.
74 int GetBlockedActions(const Extension* extension); 76 int GetBlockedActions(const Extension* extension);
75 77
76 // Returns true if the given |extension| has any blocked actions. 78 // Returns true if the given |extension| has any blocked actions.
77 bool WantsToRun(const Extension* extension); 79 bool WantsToRun(const Extension* extension);
78 80
81 // Runs any blocked actions the extension has, but does not handle any page
82 // refreshes for document_start/webRequest.
83 void RunForTesting(const Extension* extension);
84
79 int num_page_requests() const { return num_page_requests_; } 85 int num_page_requests() const { return num_page_requests_; }
80 86
87 void set_default_bubble_close_action_for_testing(
88 scoped_ptr<ToolbarActionsBarBubbleDelegate::CloseAction> action) {
89 default_bubble_close_action_for_testing_ = std::move(action);
90 }
91
81 #if defined(UNIT_TEST) 92 #if defined(UNIT_TEST)
82 // Only used in tests. 93 // Only used in tests.
83 PermissionsData::AccessType RequiresUserConsentForScriptInjectionForTesting( 94 PermissionsData::AccessType RequiresUserConsentForScriptInjectionForTesting(
84 const Extension* extension, 95 const Extension* extension,
85 UserScript::InjectionType type) { 96 UserScript::InjectionType type) {
86 return RequiresUserConsentForScriptInjection(extension, type); 97 return RequiresUserConsentForScriptInjection(extension, type);
87 } 98 }
88 void RequestScriptInjectionForTesting(const Extension* extension, 99 void RequestScriptInjectionForTesting(const Extension* extension,
89 UserScript::RunLocation run_location, 100 UserScript::RunLocation run_location,
90 const base::Closure& callback) { 101 const base::Closure& callback) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 // Grants permission for the given request to run. 145 // Grants permission for the given request to run.
135 void PermitScriptInjection(int64_t request_id); 146 void PermitScriptInjection(int64_t request_id);
136 147
137 // Notifies the ExtensionActionAPI of a change (either that an extension now 148 // Notifies the ExtensionActionAPI of a change (either that an extension now
138 // wants permission to run, or that it has been run). 149 // wants permission to run, or that it has been run).
139 void NotifyChange(const Extension* extension); 150 void NotifyChange(const Extension* extension);
140 151
141 // Log metrics. 152 // Log metrics.
142 void LogUMA() const; 153 void LogUMA() const;
143 154
155 // Shows the bubble to prompt the user to refresh the page to run the blocked
156 // actions for the given |extension|.
157 void ShowBlockedActionBubble(const Extension* extension);
158
159 // Called when the blocked actions bubble is closed.
160 void OnBlockedActionBubbleClosed(
161 const std::string& extension_id,
162 ToolbarActionsBarBubbleDelegate::CloseAction action);
163
144 // content::WebContentsObserver implementation. 164 // content::WebContentsObserver implementation.
145 bool OnMessageReceived(const IPC::Message& message, 165 bool OnMessageReceived(const IPC::Message& message,
146 content::RenderFrameHost* render_frame_host) override; 166 content::RenderFrameHost* render_frame_host) override;
147 void DidNavigateMainFrame( 167 void DidNavigateMainFrame(
148 const content::LoadCommittedDetails& details, 168 const content::LoadCommittedDetails& details,
149 const content::FrameNavigateParams& params) override; 169 const content::FrameNavigateParams& params) override;
150 170
151 // ExtensionRegistryObserver: 171 // ExtensionRegistryObserver:
152 void OnExtensionUnloaded(content::BrowserContext* browser_context, 172 void OnExtensionUnloaded(content::BrowserContext* browser_context,
153 const Extension* extension, 173 const Extension* extension,
(...skipping 16 matching lines...) Expand all
170 190
171 // A set of ids for which the webRequest API was blocked on the page. 191 // A set of ids for which the webRequest API was blocked on the page.
172 std::set<std::string> web_request_blocked_; 192 std::set<std::string> web_request_blocked_;
173 193
174 // The extensions which have been granted permission to run on the given page. 194 // The extensions which have been granted permission to run on the given page.
175 // TODO(rdevlin.cronin): Right now, this just keeps track of extensions that 195 // TODO(rdevlin.cronin): Right now, this just keeps track of extensions that
176 // have been permitted to run on the page via this interface. Instead, it 196 // have been permitted to run on the page via this interface. Instead, it
177 // should incorporate more fully with ActiveTab. 197 // should incorporate more fully with ActiveTab.
178 std::set<std::string> permitted_extensions_; 198 std::set<std::string> permitted_extensions_;
179 199
200 // If true, ignore active tab being granted rather than running pending
201 // actions.
202 bool ignore_active_tab_granted_;
203
204 // If non-null, the bubble action to simulate for testing.
205 scoped_ptr<ToolbarActionsBarBubbleDelegate::CloseAction>
206 default_bubble_close_action_for_testing_;
207
180 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> 208 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
181 extension_registry_observer_; 209 extension_registry_observer_;
182 210
211 base::WeakPtrFactory<ExtensionActionRunner> weak_factory_;
212
183 DISALLOW_COPY_AND_ASSIGN(ExtensionActionRunner); 213 DISALLOW_COPY_AND_ASSIGN(ExtensionActionRunner);
184 }; 214 };
185 215
186 } // namespace extensions 216 } // namespace extensions
187 217
188 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_RUNNER_H_ 218 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_RUNNER_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/web_request/web_request_apitest.cc ('k') | chrome/browser/extensions/extension_action_runner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698