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

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

Issue 309533007: Refactor PermissionsData pt1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 APIPermissionSet new_apis; 43 APIPermissionSet new_apis;
44 URLPatternSet new_hosts; 44 URLPatternSet new_hosts;
45 45
46 // If the extension requires action for script execution, we grant it 46 // If the extension requires action for script execution, we grant it
47 // active tab-style permissions, even if it doesn't have the activeTab 47 // active tab-style permissions, even if it doesn't have the activeTab
48 // permission in the manifest. 48 // permission in the manifest.
49 // We don't take tab id into account, because we want to know if the extension 49 // We don't take tab id into account, because we want to know if the extension
50 // should require active tab in general (not for the current tab). 50 // should require active tab in general (not for the current tab).
51 bool requires_action_for_script_execution = 51 bool requires_action_for_script_execution =
52 PermissionsData::RequiresActionForScriptExecution( 52 PermissionsData::ForExtension(extension)
53 extension, 53 ->RequiresActionForScriptExecution(extension,
54 -1, // No tab id. 54 -1, // No tab id.
55 GURL::EmptyGURL()); 55 GURL());
56 56
57 if (extension->HasAPIPermission(APIPermission::kActiveTab) || 57 if (extension->HasAPIPermission(APIPermission::kActiveTab) ||
58 requires_action_for_script_execution) { 58 requires_action_for_script_execution) {
59 URLPattern pattern(UserScript::ValidUserScriptSchemes()); 59 URLPattern pattern(UserScript::ValidUserScriptSchemes());
60 // Pattern parsing could fail if this is an unsupported URL e.g. chrome://. 60 // Pattern parsing could fail if this is an unsupported URL e.g. chrome://.
61 if (pattern.Parse(web_contents()->GetURL().spec()) == 61 if (pattern.Parse(web_contents()->GetURL().spec()) ==
62 URLPattern::PARSE_SUCCESS) { 62 URLPattern::PARSE_SUCCESS) {
63 new_hosts.AddPattern(pattern); 63 new_hosts.AddPattern(pattern);
64 } 64 }
65 new_apis.insert(APIPermission::kTab); 65 new_apis.insert(APIPermission::kTab);
66 } 66 }
67 67
68 if (extension->HasAPIPermission(APIPermission::kTabCapture)) 68 if (extension->HasAPIPermission(APIPermission::kTabCapture))
69 new_apis.insert(APIPermission::kTabCaptureForTab); 69 new_apis.insert(APIPermission::kTabCaptureForTab);
70 70
71 if (!new_apis.empty() || !new_hosts.is_empty()) { 71 if (!new_apis.empty() || !new_hosts.is_empty()) {
72 granted_extensions_.Insert(extension); 72 granted_extensions_.Insert(extension);
73 scoped_refptr<const PermissionSet> new_permissions = 73 scoped_refptr<const PermissionSet> new_permissions =
74 new PermissionSet(new_apis, ManifestPermissionSet(), 74 new PermissionSet(new_apis, ManifestPermissionSet(),
75 new_hosts, URLPatternSet()); 75 new_hosts, URLPatternSet());
76 PermissionsData::UpdateTabSpecificPermissions(extension, 76 PermissionsData::ForExtension(extension)
not at google - send to devlin 2014/06/02 23:20:06 and here
Devlin 2014/06/03 15:28:21 Done.
77 tab_id_, 77 ->UpdateTabSpecificPermissions(tab_id_, new_permissions);
78 new_permissions);
79 const content::NavigationEntry* navigation_entry = 78 const content::NavigationEntry* navigation_entry =
80 web_contents()->GetController().GetVisibleEntry(); 79 web_contents()->GetController().GetVisibleEntry();
81 if (navigation_entry) { 80 if (navigation_entry) {
82 Send(new ExtensionMsg_UpdateTabSpecificPermissions( 81 Send(new ExtensionMsg_UpdateTabSpecificPermissions(
83 navigation_entry->GetPageID(), 82 navigation_entry->GetPageID(),
84 tab_id_, 83 tab_id_,
85 extension->id(), 84 extension->id(),
86 new_hosts)); 85 new_hosts));
87 // If more things ever need to know about this, we should consider making 86 // If more things ever need to know about this, we should consider making
88 // an observer class. 87 // an observer class.
(...skipping 29 matching lines...) Expand all
118 } 117 }
119 118
120 void ActiveTabPermissionGranter::ClearActiveExtensionsAndNotify() { 119 void ActiveTabPermissionGranter::ClearActiveExtensionsAndNotify() {
121 if (granted_extensions_.is_empty()) 120 if (granted_extensions_.is_empty())
122 return; 121 return;
123 122
124 std::vector<std::string> extension_ids; 123 std::vector<std::string> extension_ids;
125 124
126 for (ExtensionSet::const_iterator it = granted_extensions_.begin(); 125 for (ExtensionSet::const_iterator it = granted_extensions_.begin();
127 it != granted_extensions_.end(); ++it) { 126 it != granted_extensions_.end(); ++it) {
128 PermissionsData::ClearTabSpecificPermissions(it->get(), tab_id_); 127 PermissionsData::ForExtension(it->get())
128 ->ClearTabSpecificPermissions(tab_id_);
129 extension_ids.push_back((*it)->id()); 129 extension_ids.push_back((*it)->id());
130 } 130 }
131 131
132 Send(new ExtensionMsg_ClearTabSpecificPermissions(tab_id_, extension_ids)); 132 Send(new ExtensionMsg_ClearTabSpecificPermissions(tab_id_, extension_ids));
133 granted_extensions_.Clear(); 133 granted_extensions_.Clear();
134 } 134 }
135 135
136 } // namespace extensions 136 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698