OLD | NEW |
---|---|
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/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
9 #include "chrome/browser/extensions/extension_system.h" | 9 #include "chrome/browser/extensions/extension_system.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
(...skipping 19 matching lines...) Expand all Loading... | |
30 content::WebContents* web_contents, int tab_id, Profile* profile) | 30 content::WebContents* web_contents, int tab_id, Profile* profile) |
31 : WebContentsObserver(web_contents), tab_id_(tab_id) { | 31 : WebContentsObserver(web_contents), tab_id_(tab_id) { |
32 registrar_.Add(this, | 32 registrar_.Add(this, |
33 chrome::NOTIFICATION_EXTENSION_UNLOADED, | 33 chrome::NOTIFICATION_EXTENSION_UNLOADED, |
34 content::Source<Profile>(profile)); | 34 content::Source<Profile>(profile)); |
35 } | 35 } |
36 | 36 |
37 ActiveTabPermissionGranter::~ActiveTabPermissionGranter() {} | 37 ActiveTabPermissionGranter::~ActiveTabPermissionGranter() {} |
38 | 38 |
39 void ActiveTabPermissionGranter::GrantIfRequested(const Extension* extension) { | 39 void ActiveTabPermissionGranter::GrantIfRequested(const Extension* extension) { |
40 if (!extension->HasAPIPermission(extensions::APIPermission::kActiveTab) && | 40 if (!extension->HasAPIPermission(APIPermission::kActiveTab) && |
41 !extension->HasAPIPermission(extensions::APIPermission::kTabCapture)) { | 41 !extension->HasAPIPermission(APIPermission::kTabCapture)) { |
42 return; | 42 return; |
43 } | 43 } |
44 | 44 |
45 if (IsGranted(extension)) | 45 if (granted_extensions_.Contains(extension->id())) |
46 return; | 46 return; |
47 | 47 |
48 URLPattern pattern(UserScript::ValidUserScriptSchemes()); | 48 APIPermissionSet new_apis; |
49 if (pattern.Parse(web_contents()->GetURL().spec()) != | 49 URLPatternSet new_hosts; |
50 URLPattern::PARSE_SUCCESS) { | 50 |
51 if (extension->HasAPIPermission(APIPermission::kActiveTab)) { | |
52 URLPattern pattern(UserScript::ValidUserScriptSchemes()); | |
51 // Pattern parsing could fail if this is an unsupported URL e.g. chrome://. | 53 // Pattern parsing could fail if this is an unsupported URL e.g. chrome://. |
52 return; | 54 if (pattern.Parse(web_contents()->GetURL().spec()) == |
55 URLPattern::PARSE_SUCCESS) { | |
56 new_hosts.AddPattern(pattern); | |
57 new_apis.insert(APIPermission::kTab); | |
not at google - send to devlin
2013/09/13 22:09:45
for consistency with tabCapture I think add this p
justinlin
2013/09/13 22:47:15
OK, I'll do this separately. I'm not really sure w
not at google - send to devlin
2013/09/13 22:48:52
It would mean that extensions could read the title
| |
58 granted_extensions_.Insert(extension); | |
59 } | |
53 } | 60 } |
54 | 61 |
55 APIPermissionSet new_apis; | 62 if (extension->HasAPIPermission(APIPermission::kTabCapture)) |
56 new_apis.insert(APIPermission::kTab); | 63 new_apis.insert(APIPermission::kTabCaptureForTab); |
57 URLPatternSet new_hosts; | |
58 new_hosts.AddPattern(pattern); | |
59 scoped_refptr<const PermissionSet> new_permissions = | |
60 new PermissionSet(new_apis, new_hosts, URLPatternSet()); | |
61 | 64 |
62 PermissionsData::UpdateTabSpecificPermissions(extension, | 65 if (!new_apis.empty()) { |
63 tab_id_, | 66 scoped_refptr<const PermissionSet> new_permissions = |
64 new_permissions); | 67 new PermissionSet(new_apis, new_hosts, URLPatternSet()); |
65 granted_extensions_.Insert(extension); | 68 PermissionsData::UpdateTabSpecificPermissions(extension, |
66 Send(new ExtensionMsg_UpdateTabSpecificPermissions(GetPageID(), | 69 tab_id_, |
67 tab_id_, | 70 new_permissions); |
68 extension->id(), | 71 Send(new ExtensionMsg_UpdateTabSpecificPermissions(GetPageID(), |
69 new_hosts)); | 72 tab_id_, |
70 } | 73 extension->id(), |
71 | 74 new_hosts)); |
72 bool ActiveTabPermissionGranter::IsGranted(const Extension* extension) { | 75 } |
73 return granted_extensions_.Contains(extension->id()); | |
74 } | 76 } |
75 | 77 |
76 void ActiveTabPermissionGranter::DidNavigateMainFrame( | 78 void ActiveTabPermissionGranter::DidNavigateMainFrame( |
77 const content::LoadCommittedDetails& details, | 79 const content::LoadCommittedDetails& details, |
78 const content::FrameNavigateParams& params) { | 80 const content::FrameNavigateParams& params) { |
79 if (details.is_in_page) | 81 if (details.is_in_page) |
80 return; | 82 return; |
81 DCHECK(details.is_main_frame); // important: sub-frames don't get granted! | 83 DCHECK(details.is_main_frame); // important: sub-frames don't get granted! |
82 ClearActiveExtensionsAndNotify(); | 84 ClearActiveExtensionsAndNotify(); |
83 } | 85 } |
(...skipping 28 matching lines...) Expand all Loading... | |
112 } | 114 } |
113 | 115 |
114 Send(new ExtensionMsg_ClearTabSpecificPermissions(tab_id_, extension_ids)); | 116 Send(new ExtensionMsg_ClearTabSpecificPermissions(tab_id_, extension_ids)); |
115 granted_extensions_.Clear(); | 117 granted_extensions_.Clear(); |
116 } | 118 } |
117 | 119 |
118 int32 ActiveTabPermissionGranter::GetPageID() { | 120 int32 ActiveTabPermissionGranter::GetPageID() { |
119 return web_contents()->GetController().GetVisibleEntry()->GetPageID(); | 121 return web_contents()->GetController().GetVisibleEntry()->GetPageID(); |
120 } | 122 } |
121 | 123 |
124 // static | |
125 bool ActiveTabPermissionGranter::IsGrantedForTab( | |
126 const Extension* extension, | |
127 const content::WebContents* web_contents) { | |
128 return PermissionsData::HasAPIPermissionForTab( | |
129 extension, | |
130 SessionID::IdForTab(web_contents), | |
131 APIPermission::kTab); | |
not at google - send to devlin
2013/09/13 22:09:45
can you just write this check specifically whereve
justinlin
2013/09/13 22:47:15
Done.
| |
132 } | |
133 | |
122 } // namespace extensions | 134 } // namespace extensions |
OLD | NEW |