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

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

Issue 2858013002: PS - Showing permission prompt for activeTab (Closed)
Patch Set: Rebase 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
83 void ActiveTabPermissionGranter::GrantIfRequested(const Extension* extension) { 93 void ActiveTabPermissionGranter::GrantIfRequested(const Extension* extension) {
84 if (granted_extensions_.Contains(extension->id())) 94 if (granted_extensions_.Contains(extension->id()))
85 return; 95 return;
86 96
87 APIPermissionSet new_apis; 97 APIPermissionSet new_apis;
88 URLPatternSet new_hosts; 98 URLPatternSet new_hosts;
89 99
90 const PermissionsData* permissions_data = extension->permissions_data(); 100 const PermissionsData* permissions_data = extension->permissions_data();
91 101
102 bool active_tab_granted = !g_delegate ||
103 g_delegate->ActiveTabPermissionGranted(extension, web_contents());
92 // If the extension requested all-hosts but has had it withheld, we grant it 104 // 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 105 // active tab-style permissions, even if it doesn't have the activeTab
94 // permission in the manifest. 106 // permission in the manifest.
95 if (permissions_data->HasAPIPermission(APIPermission::kActiveTab) || 107 if (active_tab_granted &&
96 permissions_data->HasWithheldImpliedAllHosts()) { 108 (permissions_data->HasWithheldImpliedAllHosts() ||
109 permissions_data->HasAPIPermission(APIPermission::kActiveTab))) {
97 new_hosts.AddOrigin(UserScript::ValidUserScriptSchemes(), 110 new_hosts.AddOrigin(UserScript::ValidUserScriptSchemes(),
98 web_contents()->GetVisibleURL().GetOrigin()); 111 web_contents()->GetVisibleURL().GetOrigin());
99 new_apis.insert(APIPermission::kTab); 112 new_apis.insert(APIPermission::kTab);
100 } 113 }
101 114
102 if (permissions_data->HasAPIPermission(APIPermission::kTabCapture)) 115 if (permissions_data->HasAPIPermission(APIPermission::kTabCapture))
Devlin 2017/05/12 14:56:45 do we want to gate this on whether or not we grant
Ivan Šandrk 2017/05/12 18:27:44 kTabCapture is already dealt with[1], so I'd keep
103 new_apis.insert(APIPermission::kTabCaptureForTab); 116 new_apis.insert(APIPermission::kTabCaptureForTab);
104 117
105 if (!new_apis.empty() || !new_hosts.is_empty()) { 118 if (!new_apis.empty() || !new_hosts.is_empty()) {
106 granted_extensions_.Insert(extension); 119 granted_extensions_.Insert(extension);
107 PermissionSet new_permissions(new_apis, ManifestPermissionSet(), new_hosts, 120 PermissionSet new_permissions(new_apis, ManifestPermissionSet(), new_hosts,
108 URLPatternSet()); 121 URLPatternSet());
109 permissions_data->UpdateTabSpecificPermissions(tab_id_, new_permissions); 122 permissions_data->UpdateTabSpecificPermissions(tab_id_, new_permissions);
110 const content::NavigationEntry* navigation_entry = 123 const content::NavigationEntry* navigation_entry =
111 web_contents()->GetController().GetVisibleEntry(); 124 web_contents()->GetController().GetVisibleEntry();
112 if (navigation_entry) { 125 if (navigation_entry) {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 CreateMessageFunction clear_message = 215 CreateMessageFunction clear_message =
203 base::Bind(&CreateClearMessage, extension_ids, tab_id_); 216 base::Bind(&CreateClearMessage, extension_ids, tab_id_);
204 SendMessageToProcesses(frame_hosts, 217 SendMessageToProcesses(frame_hosts,
205 web_contents()->GetRenderProcessHost(), 218 web_contents()->GetRenderProcessHost(),
206 clear_message); 219 clear_message);
207 220
208 granted_extensions_.Clear(); 221 granted_extensions_.Clear();
209 } 222 }
210 223
211 } // namespace extensions 224 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698