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

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

Issue 10834383: Chrome OS "open with" picker allowing Web Intents (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: enum => string Created 8 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
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/extension_special_storage_policy.h" 5 #include "chrome/browser/extensions/extension_special_storage_policy.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/content_settings/cookie_settings.h" 11 #include "chrome/browser/content_settings/cookie_settings.h"
12 #include "chrome/browser/intents/web_intents_util.h"
11 #include "chrome/common/content_settings.h" 13 #include "chrome/common/content_settings.h"
12 #include "chrome/common/content_settings_types.h" 14 #include "chrome/common/content_settings_types.h"
13 #include "chrome/common/extensions/extension.h" 15 #include "chrome/common/extensions/extension.h"
14 #include "chrome/common/url_constants.h" 16 #include "chrome/common/url_constants.h"
15 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
18 #include "webkit/glue/web_intent_service_data.h"
16 19
17 using content::BrowserThread; 20 using content::BrowserThread;
18 using extensions::APIPermission; 21 using extensions::APIPermission;
19 22
23 namespace {
24
25 // Does the specified extension support the passed Web Intent, |action|?
26 bool ExtensionSupportsIntentAction(const extensions::Extension* extension,
27 const std::string& action) {
tbarzic 2012/09/19 15:45:13 nit: args should be vertically aligned
thorogood 2012/09/20 00:48:17 Done.
28 for (std::vector<webkit_glue::WebIntentServiceData>::const_iterator i =
29 extension->intents_services().begin();
30 i != extension->intents_services().end(); ++i) {
31 if (UTF16ToUTF8(i->action) == action)
32 return true;
33 }
34 return false;
35 }
36
37 } // namespace
38
20 ExtensionSpecialStoragePolicy::ExtensionSpecialStoragePolicy( 39 ExtensionSpecialStoragePolicy::ExtensionSpecialStoragePolicy(
21 CookieSettings* cookie_settings) 40 CookieSettings* cookie_settings)
22 : cookie_settings_(cookie_settings) {} 41 : cookie_settings_(cookie_settings) {}
23 42
24 ExtensionSpecialStoragePolicy::~ExtensionSpecialStoragePolicy() {} 43 ExtensionSpecialStoragePolicy::~ExtensionSpecialStoragePolicy() {}
25 44
26 bool ExtensionSpecialStoragePolicy::IsStorageProtected(const GURL& origin) { 45 bool ExtensionSpecialStoragePolicy::IsStorageProtected(const GURL& origin) {
27 if (origin.SchemeIs(chrome::kExtensionScheme)) 46 if (origin.SchemeIs(chrome::kExtensionScheme))
28 return true; 47 return true;
29 base::AutoLock locker(lock_); 48 base::AutoLock locker(lock_);
(...skipping 26 matching lines...) Expand all
56 for (size_t i = 0; i < entries.size(); ++i) { 75 for (size_t i = 0; i < entries.size(); ++i) {
57 if (entries[i].setting == CONTENT_SETTING_SESSION_ONLY) 76 if (entries[i].setting == CONTENT_SETTING_SESSION_ONLY)
58 return true; 77 return true;
59 } 78 }
60 return false; 79 return false;
61 } 80 }
62 81
63 bool ExtensionSpecialStoragePolicy::IsFileHandler( 82 bool ExtensionSpecialStoragePolicy::IsFileHandler(
64 const std::string& extension_id) { 83 const std::string& extension_id) {
65 base::AutoLock locker(lock_); 84 base::AutoLock locker(lock_);
66 return file_handler_extensions_.ContainsExtension(extension_id); 85 return web_intent_extensions_.ContainsExtension(extension_id) ||
86 file_handler_extensions_.ContainsExtension(extension_id);
67 } 87 }
68 88
69 bool ExtensionSpecialStoragePolicy::NeedsProtection( 89 bool ExtensionSpecialStoragePolicy::NeedsProtection(
70 const extensions::Extension* extension) { 90 const extensions::Extension* extension) {
71 return extension->is_hosted_app() && !extension->from_bookmark(); 91 return extension->is_hosted_app() && !extension->from_bookmark();
72 } 92 }
73 93
74 const ExtensionSet* ExtensionSpecialStoragePolicy::ExtensionsProtectingOrigin( 94 const ExtensionSet* ExtensionSpecialStoragePolicy::ExtensionsProtectingOrigin(
75 const GURL& origin) { 95 const GURL& origin) {
76 base::AutoLock locker(lock_); 96 base::AutoLock locker(lock_);
77 return protected_apps_.ExtensionsContaining(origin); 97 return protected_apps_.ExtensionsContaining(origin);
78 } 98 }
79 99
80 void ExtensionSpecialStoragePolicy::GrantRightsForExtension( 100 void ExtensionSpecialStoragePolicy::GrantRightsForExtension(
81 const extensions::Extension* extension) { 101 const extensions::Extension* extension) {
82 DCHECK(extension); 102 DCHECK(extension);
103 const bool supports_intent_view = ExtensionSupportsIntentAction(
104 extension, web_intents::kActionView);
83 if (!NeedsProtection(extension) && 105 if (!NeedsProtection(extension) &&
84 !extension->HasAPIPermission( 106 !extension->HasAPIPermission(
85 APIPermission::kUnlimitedStorage) && 107 APIPermission::kUnlimitedStorage) &&
86 !extension->HasAPIPermission( 108 !extension->HasAPIPermission(
87 APIPermission::kFileBrowserHandler)) { 109 APIPermission::kFileBrowserHandler) &&
110 !supports_intent_view) {
88 return; 111 return;
89 } 112 }
90 { 113 {
91 base::AutoLock locker(lock_); 114 base::AutoLock locker(lock_);
92 if (NeedsProtection(extension)) 115 if (NeedsProtection(extension))
93 protected_apps_.Add(extension); 116 protected_apps_.Add(extension);
94 // FIXME: Does GrantRightsForExtension imply |extension| is installed? 117 // FIXME: Does GrantRightsForExtension imply |extension| is installed?
95 if (extension->is_app()) 118 if (extension->is_app())
96 installed_apps_.Add(extension); 119 installed_apps_.Add(extension);
97 if (extension->HasAPIPermission(APIPermission::kUnlimitedStorage)) 120 if (extension->HasAPIPermission(APIPermission::kUnlimitedStorage))
98 unlimited_extensions_.Add(extension); 121 unlimited_extensions_.Add(extension);
99 if (extension->HasAPIPermission( 122 if (extension->HasAPIPermission(
100 APIPermission::kFileBrowserHandler)) { 123 APIPermission::kFileBrowserHandler))
101 file_handler_extensions_.Add(extension); 124 file_handler_extensions_.Add(extension);
102 } 125 if (supports_intent_view)
126 web_intent_extensions_.Add(extension);
103 } 127 }
104 NotifyChanged(); 128 NotifyChanged();
105 } 129 }
106 130
107 void ExtensionSpecialStoragePolicy::RevokeRightsForExtension( 131 void ExtensionSpecialStoragePolicy::RevokeRightsForExtension(
108 const extensions::Extension* extension) { 132 const extensions::Extension* extension) {
109 DCHECK(extension); 133 DCHECK(extension);
134 const bool supports_intent_view = ExtensionSupportsIntentAction(
135 extension, web_intents::kActionView);
110 if (!NeedsProtection(extension) && 136 if (!NeedsProtection(extension) &&
111 !extension->HasAPIPermission( 137 !extension->HasAPIPermission(
112 APIPermission::kUnlimitedStorage) && 138 APIPermission::kUnlimitedStorage) &&
113 !extension->HasAPIPermission( 139 !extension->HasAPIPermission(
114 APIPermission::kFileBrowserHandler)) { 140 APIPermission::kFileBrowserHandler) &&
141 !supports_intent_view) {
115 return; 142 return;
116 } 143 }
117 { 144 {
118 base::AutoLock locker(lock_); 145 base::AutoLock locker(lock_);
119 if (NeedsProtection(extension)) 146 if (NeedsProtection(extension))
120 protected_apps_.Remove(extension); 147 protected_apps_.Remove(extension);
121 if (extension->is_app()) 148 if (extension->is_app())
122 installed_apps_.Remove(extension); 149 installed_apps_.Remove(extension);
123 if (extension->HasAPIPermission(APIPermission::kUnlimitedStorage)) 150 if (extension->HasAPIPermission(APIPermission::kUnlimitedStorage))
124 unlimited_extensions_.Remove(extension); 151 unlimited_extensions_.Remove(extension);
125 if (extension->HasAPIPermission(APIPermission::kFileBrowserHandler)) 152 if (extension->HasAPIPermission(APIPermission::kFileBrowserHandler))
126 file_handler_extensions_.Remove(extension); 153 file_handler_extensions_.Remove(extension);
154 if (supports_intent_view)
155 web_intent_extensions_.Remove(extension);
127 } 156 }
128 NotifyChanged(); 157 NotifyChanged();
129 } 158 }
130 159
131 void ExtensionSpecialStoragePolicy::RevokeRightsForAllExtensions() { 160 void ExtensionSpecialStoragePolicy::RevokeRightsForAllExtensions() {
132 { 161 {
133 base::AutoLock locker(lock_); 162 base::AutoLock locker(lock_);
134 protected_apps_.Clear(); 163 protected_apps_.Clear();
135 installed_apps_.Clear(); 164 installed_apps_.Clear();
136 unlimited_extensions_.Clear(); 165 unlimited_extensions_.Clear();
137 file_handler_extensions_.Clear(); 166 file_handler_extensions_.Clear();
167 web_intent_extensions_.Clear();
138 } 168 }
139 NotifyChanged(); 169 NotifyChanged();
140 } 170 }
141 171
142 void ExtensionSpecialStoragePolicy::NotifyChanged() { 172 void ExtensionSpecialStoragePolicy::NotifyChanged() {
143 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { 173 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
144 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 174 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
145 base::Bind(&ExtensionSpecialStoragePolicy::NotifyChanged, this)); 175 base::Bind(&ExtensionSpecialStoragePolicy::NotifyChanged, this));
146 return; 176 return;
147 } 177 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 229
200 void ExtensionSpecialStoragePolicy::SpecialCollection::Clear() { 230 void ExtensionSpecialStoragePolicy::SpecialCollection::Clear() {
201 ClearCache(); 231 ClearCache();
202 extensions_.Clear(); 232 extensions_.Clear();
203 } 233 }
204 234
205 void ExtensionSpecialStoragePolicy::SpecialCollection::ClearCache() { 235 void ExtensionSpecialStoragePolicy::SpecialCollection::ClearCache() {
206 STLDeleteValues(&cached_results_); 236 STLDeleteValues(&cached_results_);
207 cached_results_.clear(); 237 cached_results_.clear();
208 } 238 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698