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

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

Issue 17298002: Allow tabCapture API to be granted for chrome:// pages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: use new permission instead Created 7 years, 3 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/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
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 }
not at google - send to devlin 2013/09/13 03:22:44 this check here isn't worth much anymore
justinlin 2013/09/13 19:27:32 Still need this, otherwise there will be some un-n
not at google - send to devlin 2013/09/13 22:09:45 why? you check new_apis.empty.
justinlin 2013/09/13 22:47:15 Done. Well, now I do :)
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 if (extension->HasAPIPermission(APIPermission::kActiveTab)) {
49 if (pattern.Parse(web_contents()->GetURL().spec()) != 49 URLPattern pattern(UserScript::ValidUserScriptSchemes());
50 URLPattern::PARSE_SUCCESS) { 50 if (pattern.Parse(web_contents()->GetURL().spec()) !=
51 // Pattern parsing could fail if this is an unsupported URL e.g. chrome://. 51 URLPattern::PARSE_SUCCESS) {
52 return; 52 // Pattern parsing could fail if this is an unsupported URL e.g.
53 // chrome://.
54 return;
55 }
56
57 APIPermissionSet new_apis;
58 new_apis.insert(APIPermission::kTab);
59 URLPatternSet new_hosts;
60 new_hosts.AddPattern(pattern);
61 scoped_refptr<const PermissionSet> new_permissions =
62 new PermissionSet(new_apis, new_hosts, URLPatternSet());
63
64 PermissionsData::UpdateTabSpecificPermissions(extension,
65 tab_id_,
66 new_permissions);
67 Send(new ExtensionMsg_UpdateTabSpecificPermissions(GetPageID(),
68 tab_id_,
69 extension->id(),
70 new_hosts));
53 } 71 }
54 72
55 APIPermissionSet new_apis; 73 if (extension->HasAPIPermission(APIPermission::kTabCapture)) {
56 new_apis.insert(APIPermission::kTab); 74 APIPermissionSet new_apis;
57 URLPatternSet new_hosts; 75 new_apis.insert(APIPermission::kTabCaptureForTab);
58 new_hosts.AddPattern(pattern); 76 scoped_refptr<const PermissionSet> new_permissions =
59 scoped_refptr<const PermissionSet> new_permissions = 77 new PermissionSet(new_apis, URLPatternSet(), URLPatternSet());
60 new PermissionSet(new_apis, new_hosts, URLPatternSet()); 78 PermissionsData::UpdateTabSpecificPermissions(extension,
79 tab_id_,
80 new_permissions);
not at google - send to devlin 2013/09/13 03:22:44 could you factor this so that each case shares mor
justinlin 2013/09/13 19:27:32 Done. Fixed a kind of subtle bug too with this sec
81 }
61 82
62 PermissionsData::UpdateTabSpecificPermissions(extension,
63 tab_id_,
64 new_permissions);
65 granted_extensions_.Insert(extension); 83 granted_extensions_.Insert(extension);
66 Send(new ExtensionMsg_UpdateTabSpecificPermissions(GetPageID(),
67 tab_id_,
68 extension->id(),
69 new_hosts));
70 }
71
72 bool ActiveTabPermissionGranter::IsGranted(const Extension* extension) {
73 return granted_extensions_.Contains(extension->id());
74 } 84 }
75 85
76 void ActiveTabPermissionGranter::DidNavigateMainFrame( 86 void ActiveTabPermissionGranter::DidNavigateMainFrame(
77 const content::LoadCommittedDetails& details, 87 const content::LoadCommittedDetails& details,
78 const content::FrameNavigateParams& params) { 88 const content::FrameNavigateParams& params) {
79 if (details.is_in_page) 89 if (details.is_in_page)
80 return; 90 return;
81 DCHECK(details.is_main_frame); // important: sub-frames don't get granted! 91 DCHECK(details.is_main_frame); // important: sub-frames don't get granted!
82 ClearActiveExtensionsAndNotify(); 92 ClearActiveExtensionsAndNotify();
83 } 93 }
(...skipping 29 matching lines...) Expand all
113 123
114 Send(new ExtensionMsg_ClearTabSpecificPermissions(tab_id_, extension_ids)); 124 Send(new ExtensionMsg_ClearTabSpecificPermissions(tab_id_, extension_ids));
115 granted_extensions_.Clear(); 125 granted_extensions_.Clear();
116 } 126 }
117 127
118 int32 ActiveTabPermissionGranter::GetPageID() { 128 int32 ActiveTabPermissionGranter::GetPageID() {
119 return web_contents()->GetController().GetVisibleEntry()->GetPageID(); 129 return web_contents()->GetController().GetVisibleEntry()->GetPageID();
120 } 130 }
121 131
122 } // namespace extensions 132 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698