| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/common/extensions/extension.h" | 5 #include "chrome/common/extensions/extension.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 2232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2243 | 2243 |
| 2244 if (browser_action()) | 2244 if (browser_action()) |
| 2245 ++num_surfaces; | 2245 ++num_surfaces; |
| 2246 | 2246 |
| 2247 if (is_app()) | 2247 if (is_app()) |
| 2248 ++num_surfaces; | 2248 ++num_surfaces; |
| 2249 | 2249 |
| 2250 return num_surfaces > 1; | 2250 return num_surfaces > 1; |
| 2251 } | 2251 } |
| 2252 | 2252 |
| 2253 // static | 2253 bool Extension::CanExecuteScriptOnPage(const GURL& page_url, |
| 2254 bool Extension::CanExecuteScriptOnPage( | 2254 UserScript* script, |
| 2255 const GURL& page_url, bool can_execute_script_everywhere, | 2255 std::string* error) const { |
| 2256 const std::vector<URLPattern>* host_permissions, | |
| 2257 UserScript* script, | |
| 2258 std::string* error) { | |
| 2259 DCHECK(!(host_permissions && script)) << "Shouldn't specify both"; | |
| 2260 | |
| 2261 // The gallery is special-cased as a restricted URL for scripting to prevent | 2256 // The gallery is special-cased as a restricted URL for scripting to prevent |
| 2262 // access to special JS bindings we expose to the gallery (and avoid things | 2257 // access to special JS bindings we expose to the gallery (and avoid things |
| 2263 // like extensions removing the "report abuse" link). | 2258 // like extensions removing the "report abuse" link). |
| 2264 // TODO(erikkay): This seems like the wrong test. Shouldn't we we testing | 2259 // TODO(erikkay): This seems like the wrong test. Shouldn't we we testing |
| 2265 // against the store app extent? | 2260 // against the store app extent? |
| 2266 if ((page_url.host() == GURL(Extension::ChromeStoreLaunchURL()).host()) && | 2261 if ((page_url.host() == GURL(Extension::ChromeStoreLaunchURL()).host()) && |
| 2267 !can_execute_script_everywhere && | 2262 !CanExecuteScriptEverywhere() && |
| 2268 !CommandLine::ForCurrentProcess()->HasSwitch( | 2263 !CommandLine::ForCurrentProcess()->HasSwitch( |
| 2269 switches::kAllowScriptingGallery)) { | 2264 switches::kAllowScriptingGallery)) { |
| 2270 if (error) | 2265 if (error) |
| 2271 *error = errors::kCannotScriptGallery; | 2266 *error = errors::kCannotScriptGallery; |
| 2272 return false; | 2267 return false; |
| 2273 } | 2268 } |
| 2274 | 2269 |
| 2275 if (host_permissions) { | 2270 // If a script is specified, use its matches. |
| 2276 for (size_t i = 0; i < host_permissions->size(); ++i) { | |
| 2277 if ((*host_permissions)[i].MatchesUrl(page_url)) | |
| 2278 return true; | |
| 2279 } | |
| 2280 } | |
| 2281 if (script) { | 2271 if (script) { |
| 2282 if (script->MatchesUrl(page_url)) | 2272 if (script->MatchesUrl(page_url)) |
| 2283 return true; | 2273 return true; |
| 2284 } | 2274 } |
| 2285 | 2275 |
| 2276 // Otherwise, see if this extension has permission to execute script |
| 2277 // programmatically on pages. |
| 2278 for (size_t i = 0; i < host_permissions_.size(); ++i) { |
| 2279 if (host_permissions_[i].MatchesUrl(page_url)) |
| 2280 return true; |
| 2281 } |
| 2282 |
| 2286 if (error) { | 2283 if (error) { |
| 2287 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kCannotAccessPage, | 2284 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kCannotAccessPage, |
| 2288 page_url.spec()); | 2285 page_url.spec()); |
| 2289 } | 2286 } |
| 2290 | 2287 |
| 2291 return false; | 2288 return false; |
| 2292 } | 2289 } |
| 2293 | 2290 |
| 2294 // static | 2291 // static |
| 2295 bool Extension::HasEffectiveAccessToAllHosts( | 2292 bool Extension::HasEffectiveAccessToAllHosts( |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2372 | 2369 |
| 2373 UninstalledExtensionInfo::~UninstalledExtensionInfo() {} | 2370 UninstalledExtensionInfo::~UninstalledExtensionInfo() {} |
| 2374 | 2371 |
| 2375 | 2372 |
| 2376 UnloadedExtensionInfo::UnloadedExtensionInfo( | 2373 UnloadedExtensionInfo::UnloadedExtensionInfo( |
| 2377 const Extension* extension, | 2374 const Extension* extension, |
| 2378 Reason reason) | 2375 Reason reason) |
| 2379 : reason(reason), | 2376 : reason(reason), |
| 2380 already_disabled(false), | 2377 already_disabled(false), |
| 2381 extension(extension) {} | 2378 extension(extension) {} |
| OLD | NEW |