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

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

Issue 348313003: Create withheld permissions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Kalman's Created 6 years, 5 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 | Annotate | Revision Log
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/active_script_controller.h" 7 #include "chrome/browser/extensions/active_script_controller.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "content/public/browser/navigation_details.h" 9 #include "content/public/browser/navigation_details.h"
10 #include "content/public/browser/navigation_entry.h" 10 #include "content/public/browser/navigation_entry.h"
(...skipping 27 matching lines...) Expand all
38 web_contents()->UserGestureDone(); 38 web_contents()->UserGestureDone();
39 39
40 if (granted_extensions_.Contains(extension->id())) 40 if (granted_extensions_.Contains(extension->id()))
41 return; 41 return;
42 42
43 APIPermissionSet new_apis; 43 APIPermissionSet new_apis;
44 URLPatternSet new_hosts; 44 URLPatternSet new_hosts;
45 45
46 const PermissionsData* permissions_data = extension->permissions_data(); 46 const PermissionsData* permissions_data = extension->permissions_data();
47 47
48 // If the extension requires action for script execution, we grant it 48 // If the extension requested all-hosts but has had it withheld, we grant it
49 // active tab-style permissions, even if it doesn't have the activeTab 49 // active tab-style permissions, even if it doesn't have the activeTab
50 // permission in the manifest. 50 // permission in the manifest.
51 // We don't take tab id into account, because we want to know if the extension 51 if (permissions_data->HasAPIPermission(APIPermission::kActiveTab) ||
52 // should require active tab in general (not for the current tab). 52 permissions_data->HasWithheldImpliedAllHosts()) {
53 bool requires_action_for_script_execution =
54 permissions_data->RequiresActionForScriptExecution(extension,
55 -1, // No tab id.
56 GURL());
57
58 if (extension->permissions_data()->HasAPIPermission(
59 APIPermission::kActiveTab) ||
60 requires_action_for_script_execution) {
61 URLPattern pattern(UserScript::ValidUserScriptSchemes()); 53 URLPattern pattern(UserScript::ValidUserScriptSchemes());
62 // Pattern parsing could fail if this is an unsupported URL e.g. chrome://. 54 // Pattern parsing could fail if this is an unsupported URL e.g. chrome://.
63 if (pattern.Parse(web_contents()->GetURL().spec()) == 55 if (pattern.Parse(web_contents()->GetURL().spec()) ==
64 URLPattern::PARSE_SUCCESS) { 56 URLPattern::PARSE_SUCCESS) {
65 new_hosts.AddPattern(pattern); 57 new_hosts.AddPattern(pattern);
66 } 58 }
67 new_apis.insert(APIPermission::kTab); 59 new_apis.insert(APIPermission::kTab);
68 } 60 }
69 61
70 if (extension->permissions_data()->HasAPIPermission( 62 if (permissions_data->HasAPIPermission(APIPermission::kTabCapture))
71 APIPermission::kTabCapture))
72 new_apis.insert(APIPermission::kTabCaptureForTab); 63 new_apis.insert(APIPermission::kTabCaptureForTab);
73 64
74 if (!new_apis.empty() || !new_hosts.is_empty()) { 65 if (!new_apis.empty() || !new_hosts.is_empty()) {
75 granted_extensions_.Insert(extension); 66 granted_extensions_.Insert(extension);
76 scoped_refptr<const PermissionSet> new_permissions = 67 scoped_refptr<const PermissionSet> new_permissions =
77 new PermissionSet(new_apis, ManifestPermissionSet(), 68 new PermissionSet(new_apis, ManifestPermissionSet(),
78 new_hosts, URLPatternSet()); 69 new_hosts, URLPatternSet());
79 permissions_data->UpdateTabSpecificPermissions(tab_id_, new_permissions); 70 permissions_data->UpdateTabSpecificPermissions(tab_id_, new_permissions);
80 const content::NavigationEntry* navigation_entry = 71 const content::NavigationEntry* navigation_entry =
81 web_contents()->GetController().GetVisibleEntry(); 72 web_contents()->GetController().GetVisibleEntry();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 it != granted_extensions_.end(); ++it) { 119 it != granted_extensions_.end(); ++it) {
129 it->get()->permissions_data()->ClearTabSpecificPermissions(tab_id_); 120 it->get()->permissions_data()->ClearTabSpecificPermissions(tab_id_);
130 extension_ids.push_back((*it)->id()); 121 extension_ids.push_back((*it)->id());
131 } 122 }
132 123
133 Send(new ExtensionMsg_ClearTabSpecificPermissions(tab_id_, extension_ids)); 124 Send(new ExtensionMsg_ClearTabSpecificPermissions(tab_id_, extension_ids));
134 granted_extensions_.Clear(); 125 granted_extensions_.Clear();
135 } 126 }
136 127
137 } // namespace extensions 128 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698