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

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

Powered by Google App Engine
This is Rietveld 408576698