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

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: tbarzic comments 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(
27 const extensions::Extension* extension,
28 const std::string& action) {
29 for (std::vector<webkit_glue::WebIntentServiceData>::const_iterator i =
30 extension->intents_services().begin();
31 i != extension->intents_services().end(); ++i) {
32 if (UTF16ToUTF8(i->action) == action)
33 return true;
34 }
35 return false;
36 }
37
38 } // namespace
39
20 ExtensionSpecialStoragePolicy::ExtensionSpecialStoragePolicy( 40 ExtensionSpecialStoragePolicy::ExtensionSpecialStoragePolicy(
21 CookieSettings* cookie_settings) 41 CookieSettings* cookie_settings)
22 : cookie_settings_(cookie_settings) {} 42 : cookie_settings_(cookie_settings) {}
23 43
24 ExtensionSpecialStoragePolicy::~ExtensionSpecialStoragePolicy() {} 44 ExtensionSpecialStoragePolicy::~ExtensionSpecialStoragePolicy() {}
25 45
26 bool ExtensionSpecialStoragePolicy::IsStorageProtected(const GURL& origin) { 46 bool ExtensionSpecialStoragePolicy::IsStorageProtected(const GURL& origin) {
27 if (origin.SchemeIs(chrome::kExtensionScheme)) 47 if (origin.SchemeIs(chrome::kExtensionScheme))
28 return true; 48 return true;
29 base::AutoLock locker(lock_); 49 base::AutoLock locker(lock_);
(...skipping 26 matching lines...) Expand all
56 for (size_t i = 0; i < entries.size(); ++i) { 76 for (size_t i = 0; i < entries.size(); ++i) {
57 if (entries[i].setting == CONTENT_SETTING_SESSION_ONLY) 77 if (entries[i].setting == CONTENT_SETTING_SESSION_ONLY)
58 return true; 78 return true;
59 } 79 }
60 return false; 80 return false;
61 } 81 }
62 82
63 bool ExtensionSpecialStoragePolicy::IsFileHandler( 83 bool ExtensionSpecialStoragePolicy::IsFileHandler(
64 const std::string& extension_id) { 84 const std::string& extension_id) {
65 base::AutoLock locker(lock_); 85 base::AutoLock locker(lock_);
66 return file_handler_extensions_.ContainsExtension(extension_id); 86 return web_intent_extensions_.ContainsExtension(extension_id) ||
87 file_handler_extensions_.ContainsExtension(extension_id);
67 } 88 }
68 89
69 bool ExtensionSpecialStoragePolicy::NeedsProtection( 90 bool ExtensionSpecialStoragePolicy::NeedsProtection(
70 const extensions::Extension* extension) { 91 const extensions::Extension* extension) {
71 return extension->is_hosted_app() && !extension->from_bookmark(); 92 return extension->is_hosted_app() && !extension->from_bookmark();
72 } 93 }
73 94
74 const ExtensionSet* ExtensionSpecialStoragePolicy::ExtensionsProtectingOrigin( 95 const ExtensionSet* ExtensionSpecialStoragePolicy::ExtensionsProtectingOrigin(
75 const GURL& origin) { 96 const GURL& origin) {
76 base::AutoLock locker(lock_); 97 base::AutoLock locker(lock_);
77 return protected_apps_.ExtensionsContaining(origin); 98 return protected_apps_.ExtensionsContaining(origin);
78 } 99 }
79 100
80 void ExtensionSpecialStoragePolicy::GrantRightsForExtension( 101 void ExtensionSpecialStoragePolicy::GrantRightsForExtension(
81 const extensions::Extension* extension) { 102 const extensions::Extension* extension) {
82 DCHECK(extension); 103 DCHECK(extension);
104 const bool supports_intent_view = ExtensionSupportsIntentAction(
105 extension, web_intents::kActionView);
83 if (!NeedsProtection(extension) && 106 if (!NeedsProtection(extension) &&
84 !extension->HasAPIPermission( 107 !extension->HasAPIPermission(
85 APIPermission::kUnlimitedStorage) && 108 APIPermission::kUnlimitedStorage) &&
86 !extension->HasAPIPermission( 109 !extension->HasAPIPermission(
87 APIPermission::kFileBrowserHandler)) { 110 APIPermission::kFileBrowserHandler) &&
111 !supports_intent_view) {
88 return; 112 return;
89 } 113 }
90 { 114 {
91 base::AutoLock locker(lock_); 115 base::AutoLock locker(lock_);
92 if (NeedsProtection(extension)) 116 if (NeedsProtection(extension))
93 protected_apps_.Add(extension); 117 protected_apps_.Add(extension);
94 // FIXME: Does GrantRightsForExtension imply |extension| is installed? 118 // FIXME: Does GrantRightsForExtension imply |extension| is installed?
95 if (extension->is_app()) 119 if (extension->is_app())
96 installed_apps_.Add(extension); 120 installed_apps_.Add(extension);
97 if (extension->HasAPIPermission(APIPermission::kUnlimitedStorage)) 121 if (extension->HasAPIPermission(APIPermission::kUnlimitedStorage))
98 unlimited_extensions_.Add(extension); 122 unlimited_extensions_.Add(extension);
99 if (extension->HasAPIPermission( 123 if (extension->HasAPIPermission(
100 APIPermission::kFileBrowserHandler)) { 124 APIPermission::kFileBrowserHandler))
101 file_handler_extensions_.Add(extension); 125 file_handler_extensions_.Add(extension);
102 } 126 if (supports_intent_view)
127 web_intent_extensions_.Add(extension);
103 } 128 }
104 NotifyChanged(); 129 NotifyChanged();
105 } 130 }
106 131
107 void ExtensionSpecialStoragePolicy::RevokeRightsForExtension( 132 void ExtensionSpecialStoragePolicy::RevokeRightsForExtension(
108 const extensions::Extension* extension) { 133 const extensions::Extension* extension) {
109 DCHECK(extension); 134 DCHECK(extension);
135 const bool supports_intent_view = ExtensionSupportsIntentAction(
136 extension, web_intents::kActionView);
110 if (!NeedsProtection(extension) && 137 if (!NeedsProtection(extension) &&
111 !extension->HasAPIPermission( 138 !extension->HasAPIPermission(
112 APIPermission::kUnlimitedStorage) && 139 APIPermission::kUnlimitedStorage) &&
113 !extension->HasAPIPermission( 140 !extension->HasAPIPermission(
114 APIPermission::kFileBrowserHandler)) { 141 APIPermission::kFileBrowserHandler) &&
142 !supports_intent_view) {
115 return; 143 return;
116 } 144 }
117 { 145 {
118 base::AutoLock locker(lock_); 146 base::AutoLock locker(lock_);
119 if (NeedsProtection(extension)) 147 if (NeedsProtection(extension))
120 protected_apps_.Remove(extension); 148 protected_apps_.Remove(extension);
121 if (extension->is_app()) 149 if (extension->is_app())
122 installed_apps_.Remove(extension); 150 installed_apps_.Remove(extension);
123 if (extension->HasAPIPermission(APIPermission::kUnlimitedStorage)) 151 if (extension->HasAPIPermission(APIPermission::kUnlimitedStorage))
124 unlimited_extensions_.Remove(extension); 152 unlimited_extensions_.Remove(extension);
125 if (extension->HasAPIPermission(APIPermission::kFileBrowserHandler)) 153 if (extension->HasAPIPermission(APIPermission::kFileBrowserHandler))
126 file_handler_extensions_.Remove(extension); 154 file_handler_extensions_.Remove(extension);
155 if (supports_intent_view)
156 web_intent_extensions_.Remove(extension);
127 } 157 }
128 NotifyChanged(); 158 NotifyChanged();
129 } 159 }
130 160
131 void ExtensionSpecialStoragePolicy::RevokeRightsForAllExtensions() { 161 void ExtensionSpecialStoragePolicy::RevokeRightsForAllExtensions() {
132 { 162 {
133 base::AutoLock locker(lock_); 163 base::AutoLock locker(lock_);
134 protected_apps_.Clear(); 164 protected_apps_.Clear();
135 installed_apps_.Clear(); 165 installed_apps_.Clear();
136 unlimited_extensions_.Clear(); 166 unlimited_extensions_.Clear();
137 file_handler_extensions_.Clear(); 167 file_handler_extensions_.Clear();
168 web_intent_extensions_.Clear();
138 } 169 }
139 NotifyChanged(); 170 NotifyChanged();
140 } 171 }
141 172
142 void ExtensionSpecialStoragePolicy::NotifyChanged() { 173 void ExtensionSpecialStoragePolicy::NotifyChanged() {
143 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { 174 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
144 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 175 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
145 base::Bind(&ExtensionSpecialStoragePolicy::NotifyChanged, this)); 176 base::Bind(&ExtensionSpecialStoragePolicy::NotifyChanged, this));
146 return; 177 return;
147 } 178 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 230
200 void ExtensionSpecialStoragePolicy::SpecialCollection::Clear() { 231 void ExtensionSpecialStoragePolicy::SpecialCollection::Clear() {
201 ClearCache(); 232 ClearCache();
202 extensions_.Clear(); 233 extensions_.Clear();
203 } 234 }
204 235
205 void ExtensionSpecialStoragePolicy::SpecialCollection::ClearCache() { 236 void ExtensionSpecialStoragePolicy::SpecialCollection::ClearCache() {
206 STLDeleteValues(&cached_results_); 237 STLDeleteValues(&cached_results_);
207 cached_results_.clear(); 238 cached_results_.clear();
208 } 239 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698