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

Side by Side Diff: chrome/browser/extensions/active_tab_permission_granter.cc

Issue 2858013002: PS - Showing permission prompt for activeTab (Closed)
Patch Set: Test - delegate is set and works Created 3 years, 7 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "chrome/browser/extensions/active_tab_permission_granter.h" 5 #include "chrome/browser/extensions/active_tab_permission_granter.h"
6 6
7 #include "chrome/browser/extensions/extension_action_runner.h" 7 #include "chrome/browser/extensions/extension_action_runner.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "content/public/browser/navigation_entry.h" 9 #include "content/public/browser/navigation_entry.h"
10 #include "content/public/browser/navigation_handle.h" 10 #include "content/public/browser/navigation_handle.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 process_host->Send(create_message.Run(true)); 59 process_host->Send(create_message.Run(true));
60 sent_to_hosts.insert(frame_host->GetProcess()); 60 sent_to_hosts.insert(frame_host->GetProcess());
61 } 61 }
62 } 62 }
63 // If the tab wasn't one of those processes already updated (it likely 63 // If the tab wasn't one of those processes already updated (it likely
64 // wasn't), update it. Tabs don't need to update the origin whitelist. 64 // wasn't), update it. Tabs don't need to update the origin whitelist.
65 if (sent_to_hosts.count(tab_process) == 0) 65 if (sent_to_hosts.count(tab_process) == 0)
66 tab_process->Send(create_message.Run(false)); 66 tab_process->Send(create_message.Run(false));
67 } 67 }
68 68
69 ActiveTabPermissionGranter::Delegate* g_delegate = nullptr;
70
69 } // namespace 71 } // namespace
70 72
71 ActiveTabPermissionGranter::ActiveTabPermissionGranter( 73 ActiveTabPermissionGranter::ActiveTabPermissionGranter(
72 content::WebContents* web_contents, 74 content::WebContents* web_contents,
73 int tab_id, 75 int tab_id,
74 Profile* profile) 76 Profile* profile)
75 : content::WebContentsObserver(web_contents), 77 : content::WebContentsObserver(web_contents),
76 tab_id_(tab_id), 78 tab_id_(tab_id),
77 extension_registry_observer_(this) { 79 extension_registry_observer_(this) {
78 extension_registry_observer_.Add(ExtensionRegistry::Get(profile)); 80 extension_registry_observer_.Add(ExtensionRegistry::Get(profile));
79 } 81 }
80 82
81 ActiveTabPermissionGranter::~ActiveTabPermissionGranter() {} 83 ActiveTabPermissionGranter::~ActiveTabPermissionGranter() {}
82 84
85 // static
86 void ActiveTabPermissionGranter::SetPlatformDelegate(Delegate* delegate) {
87 // Disallow setting it twice (but allow resetting - don't forget to free in
88 // that case).
89 CHECK(!g_delegate || !delegate);
90 g_delegate = delegate;
91 }
92
93 // static
94 void ActiveTabPermissionGranter::FreePlatformDelegateForTesting() {
95 free(g_delegate);
Devlin 2017/05/23 19:28:03 Why do we need this? Just for ASAN?
Ivan Šandrk 2017/05/24 09:29:01 Yes
96 g_delegate = nullptr;
97 }
98
83 void ActiveTabPermissionGranter::GrantIfRequested(const Extension* extension) { 99 void ActiveTabPermissionGranter::GrantIfRequested(const Extension* extension) {
84 if (granted_extensions_.Contains(extension->id())) 100 if (granted_extensions_.Contains(extension->id()))
85 return; 101 return;
86 102
87 APIPermissionSet new_apis; 103 APIPermissionSet new_apis;
88 URLPatternSet new_hosts; 104 URLPatternSet new_hosts;
89 105
90 const PermissionsData* permissions_data = extension->permissions_data(); 106 const PermissionsData* permissions_data = extension->permissions_data();
91 107
108 bool should_grant_active_tab = !g_delegate ||
109 g_delegate->ShouldGrantActiveTab(extension, web_contents());
Devlin 2017/05/23 19:28:04 Is this git cl format'd?
Ivan Šandrk 2017/05/24 09:29:01 Nope, now it is :)
92 // If the extension requested all-hosts but has had it withheld, we grant it 110 // If the extension requested all-hosts but has had it withheld, we grant it
93 // active tab-style permissions, even if it doesn't have the activeTab 111 // active tab-style permissions, even if it doesn't have the activeTab
94 // permission in the manifest. 112 // permission in the manifest.
95 if (permissions_data->HasAPIPermission(APIPermission::kActiveTab) || 113 if (should_grant_active_tab &&
96 permissions_data->HasWithheldImpliedAllHosts()) { 114 (permissions_data->HasWithheldImpliedAllHosts() ||
115 permissions_data->HasAPIPermission(APIPermission::kActiveTab))) {
97 new_hosts.AddOrigin(UserScript::ValidUserScriptSchemes(), 116 new_hosts.AddOrigin(UserScript::ValidUserScriptSchemes(),
98 web_contents()->GetVisibleURL().GetOrigin()); 117 web_contents()->GetVisibleURL().GetOrigin());
99 new_apis.insert(APIPermission::kTab); 118 new_apis.insert(APIPermission::kTab);
100 } 119 }
101 120
102 if (permissions_data->HasAPIPermission(APIPermission::kTabCapture)) 121 if (permissions_data->HasAPIPermission(APIPermission::kTabCapture))
103 new_apis.insert(APIPermission::kTabCaptureForTab); 122 new_apis.insert(APIPermission::kTabCaptureForTab);
104 123
105 if (!new_apis.empty() || !new_hosts.is_empty()) { 124 if (!new_apis.empty() || !new_hosts.is_empty()) {
106 granted_extensions_.Insert(extension); 125 granted_extensions_.Insert(extension);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 CreateMessageFunction clear_message = 221 CreateMessageFunction clear_message =
203 base::Bind(&CreateClearMessage, extension_ids, tab_id_); 222 base::Bind(&CreateClearMessage, extension_ids, tab_id_);
204 SendMessageToProcesses(frame_hosts, 223 SendMessageToProcesses(frame_hosts,
205 web_contents()->GetRenderProcessHost(), 224 web_contents()->GetRenderProcessHost(),
206 clear_message); 225 clear_message);
207 226
208 granted_extensions_.Clear(); 227 granted_extensions_.Clear();
209 } 228 }
210 229
211 } // namespace extensions 230 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698