| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 int flags, | 246 int flags, |
| 247 const std::string& explicit_id, | 247 const std::string& explicit_id, |
| 248 std::string* error) { | 248 std::string* error) { |
| 249 scoped_refptr<Extension> extension = Create( | 249 scoped_refptr<Extension> extension = Create( |
| 250 path, location, value, flags, error); | 250 path, location, value, flags, error); |
| 251 if (extension.get()) | 251 if (extension.get()) |
| 252 extension->id_ = explicit_id; | 252 extension->id_ = explicit_id; |
| 253 return extension; | 253 return extension; |
| 254 } | 254 } |
| 255 | 255 |
| 256 namespace { | |
| 257 const char* kGalleryUpdateHttpUrl = | |
| 258 "http://clients2.google.com/service/update2/crx"; | |
| 259 const char* kGalleryUpdateHttpsUrl = | |
| 260 "https://clients2.google.com/service/update2/crx"; | |
| 261 } // namespace | |
| 262 | |
| 263 // static | |
| 264 GURL Extension::GalleryUpdateUrl(bool secure) { | |
| 265 CommandLine* cmdline = CommandLine::ForCurrentProcess(); | |
| 266 if (cmdline->HasSwitch(switches::kAppsGalleryUpdateURL)) | |
| 267 return GURL(cmdline->GetSwitchValueASCII(switches::kAppsGalleryUpdateURL)); | |
| 268 else | |
| 269 return GURL(secure ? kGalleryUpdateHttpsUrl : kGalleryUpdateHttpUrl); | |
| 270 } | |
| 271 | |
| 272 // static | 256 // static |
| 273 Extension::Location Extension::GetHigherPriorityLocation( | 257 Extension::Location Extension::GetHigherPriorityLocation( |
| 274 Extension::Location loc1, Extension::Location loc2) { | 258 Extension::Location loc1, Extension::Location loc2) { |
| 275 if (loc1 == loc2) | 259 if (loc1 == loc2) |
| 276 return loc1; | 260 return loc1; |
| 277 | 261 |
| 278 int loc1_rank = GetLocationRank(loc1); | 262 int loc1_rank = GetLocationRank(loc1); |
| 279 int loc2_rank = GetLocationRank(loc2); | 263 int loc2_rank = GetLocationRank(loc2); |
| 280 | 264 |
| 281 // If two different locations have the same rank, then we can not | 265 // If two different locations have the same rank, then we can not |
| (...skipping 2055 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2337 return true; | 2321 return true; |
| 2338 } | 2322 } |
| 2339 | 2323 |
| 2340 GURL Extension::GetHomepageURL() const { | 2324 GURL Extension::GetHomepageURL() const { |
| 2341 if (homepage_url_.is_valid()) | 2325 if (homepage_url_.is_valid()) |
| 2342 return homepage_url_; | 2326 return homepage_url_; |
| 2343 | 2327 |
| 2344 if (!UpdatesFromGallery()) | 2328 if (!UpdatesFromGallery()) |
| 2345 return GURL(); | 2329 return GURL(); |
| 2346 | 2330 |
| 2347 GURL url(extension_misc::GetWebstoreItemDetailURLPrefix() + id()); | 2331 GURL url(extension_urls::GetWebstoreItemDetailURLPrefix() + id()); |
| 2348 return url; | 2332 return url; |
| 2349 } | 2333 } |
| 2350 | 2334 |
| 2351 std::set<FilePath> Extension::GetBrowserImages() const { | 2335 std::set<FilePath> Extension::GetBrowserImages() const { |
| 2352 std::set<FilePath> image_paths; | 2336 std::set<FilePath> image_paths; |
| 2353 // TODO(viettrungluu): These |FilePath::FromWStringHack(UTF8ToWide())| | 2337 // TODO(viettrungluu): These |FilePath::FromWStringHack(UTF8ToWide())| |
| 2354 // indicate that we're doing something wrong. | 2338 // indicate that we're doing something wrong. |
| 2355 | 2339 |
| 2356 // Extension icons. | 2340 // Extension icons. |
| 2357 for (ExtensionIconSet::IconMap::const_iterator iter = icons().map().begin(); | 2341 for (ExtensionIconSet::IconMap::const_iterator iter = icons().map().begin(); |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2708 | 2692 |
| 2709 bool Extension::CanExecuteScriptOnPage(const GURL& page_url, | 2693 bool Extension::CanExecuteScriptOnPage(const GURL& page_url, |
| 2710 const UserScript* script, | 2694 const UserScript* script, |
| 2711 std::string* error) const { | 2695 std::string* error) const { |
| 2712 base::AutoLock auto_lock(runtime_data_lock_); | 2696 base::AutoLock auto_lock(runtime_data_lock_); |
| 2713 // The gallery is special-cased as a restricted URL for scripting to prevent | 2697 // The gallery is special-cased as a restricted URL for scripting to prevent |
| 2714 // access to special JS bindings we expose to the gallery (and avoid things | 2698 // access to special JS bindings we expose to the gallery (and avoid things |
| 2715 // like extensions removing the "report abuse" link). | 2699 // like extensions removing the "report abuse" link). |
| 2716 // TODO(erikkay): This seems like the wrong test. Shouldn't we we testing | 2700 // TODO(erikkay): This seems like the wrong test. Shouldn't we we testing |
| 2717 // against the store app extent? | 2701 // against the store app extent? |
| 2718 GURL store_url(extension_misc::GetWebstoreLaunchURL()); | 2702 GURL store_url(extension_urls::GetWebstoreLaunchURL()); |
| 2719 if ((page_url.host() == store_url.host()) && | 2703 if ((page_url.host() == store_url.host()) && |
| 2720 !CanExecuteScriptEverywhere() && | 2704 !CanExecuteScriptEverywhere() && |
| 2721 !CommandLine::ForCurrentProcess()->HasSwitch( | 2705 !CommandLine::ForCurrentProcess()->HasSwitch( |
| 2722 switches::kAllowScriptingGallery)) { | 2706 switches::kAllowScriptingGallery)) { |
| 2723 if (error) | 2707 if (error) |
| 2724 *error = errors::kCannotScriptGallery; | 2708 *error = errors::kCannotScriptGallery; |
| 2725 return false; | 2709 return false; |
| 2726 } | 2710 } |
| 2727 | 2711 |
| 2728 if (page_url.SchemeIs(chrome::kChromeUIScheme) && | 2712 if (page_url.SchemeIs(chrome::kChromeUIScheme) && |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2790 return true; | 2774 return true; |
| 2791 | 2775 |
| 2792 if (error) { | 2776 if (error) { |
| 2793 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kCannotAccessPage, | 2777 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kCannotAccessPage, |
| 2794 page_url.spec()); | 2778 page_url.spec()); |
| 2795 } | 2779 } |
| 2796 return false; | 2780 return false; |
| 2797 } | 2781 } |
| 2798 | 2782 |
| 2799 bool Extension::UpdatesFromGallery() const { | 2783 bool Extension::UpdatesFromGallery() const { |
| 2800 return update_url() == GalleryUpdateUrl(false) || | 2784 return update_url() == extension_urls::GetWebstoreUpdateUrl(false) || |
| 2801 update_url() == GalleryUpdateUrl(true); | 2785 update_url() == extension_urls::GetWebstoreUpdateUrl(true); |
| 2802 } | 2786 } |
| 2803 | 2787 |
| 2804 bool Extension::OverlapsWithOrigin(const GURL& origin) const { | 2788 bool Extension::OverlapsWithOrigin(const GURL& origin) const { |
| 2805 if (url() == origin) | 2789 if (url() == origin) |
| 2806 return true; | 2790 return true; |
| 2807 | 2791 |
| 2808 if (web_extent().is_empty()) | 2792 if (web_extent().is_empty()) |
| 2809 return false; | 2793 return false; |
| 2810 | 2794 |
| 2811 // Note: patterns and extents ignore port numbers. | 2795 // Note: patterns and extents ignore port numbers. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2826 if (location() != Extension::INTERNAL) { | 2810 if (location() != Extension::INTERNAL) { |
| 2827 // We have a non-standard location. | 2811 // We have a non-standard location. |
| 2828 return SYNC_TYPE_NONE; | 2812 return SYNC_TYPE_NONE; |
| 2829 } | 2813 } |
| 2830 | 2814 |
| 2831 // Disallow extensions with non-gallery auto-update URLs for now. | 2815 // Disallow extensions with non-gallery auto-update URLs for now. |
| 2832 // | 2816 // |
| 2833 // TODO(akalin): Relax this restriction once we've put in UI to | 2817 // TODO(akalin): Relax this restriction once we've put in UI to |
| 2834 // approve synced extensions. | 2818 // approve synced extensions. |
| 2835 if (!update_url().is_empty() && | 2819 if (!update_url().is_empty() && |
| 2836 (update_url() != GalleryUpdateUrl(false)) && | 2820 (update_url() != extension_urls::GetWebstoreUpdateUrl(false)) && |
| 2837 (update_url() != GalleryUpdateUrl(true))) { | 2821 (update_url() != extension_urls::GetWebstoreUpdateUrl(true))) { |
| 2838 return SYNC_TYPE_NONE; | 2822 return SYNC_TYPE_NONE; |
| 2839 } | 2823 } |
| 2840 | 2824 |
| 2841 // Disallow extensions with native code plugins. | 2825 // Disallow extensions with native code plugins. |
| 2842 // | 2826 // |
| 2843 // TODO(akalin): Relax this restriction once we've put in UI to | 2827 // TODO(akalin): Relax this restriction once we've put in UI to |
| 2844 // approve synced extensions. | 2828 // approve synced extensions. |
| 2845 if (!plugins().empty()) { | 2829 if (!plugins().empty()) { |
| 2846 return SYNC_TYPE_NONE; | 2830 return SYNC_TYPE_NONE; |
| 2847 } | 2831 } |
| 2848 | 2832 |
| 2849 switch (GetType()) { | 2833 switch (GetType()) { |
| 2850 case Extension::TYPE_EXTENSION: | 2834 case Extension::TYPE_EXTENSION: |
| 2851 return SYNC_TYPE_EXTENSION; | 2835 return SYNC_TYPE_EXTENSION; |
| 2852 | 2836 |
| 2853 case Extension::TYPE_USER_SCRIPT: | 2837 case Extension::TYPE_USER_SCRIPT: |
| 2854 // We only want to sync user scripts with gallery update URLs. | 2838 // We only want to sync user scripts with gallery update URLs. |
| 2855 if (update_url() == GalleryUpdateUrl(true) || | 2839 if (update_url() == extension_urls::GetWebstoreUpdateUrl(true) || |
| 2856 update_url() == GalleryUpdateUrl(false)) | 2840 update_url() == extension_urls::GetWebstoreUpdateUrl(false)) |
| 2857 return SYNC_TYPE_EXTENSION; | 2841 return SYNC_TYPE_EXTENSION; |
| 2858 else | 2842 else |
| 2859 return SYNC_TYPE_NONE; | 2843 return SYNC_TYPE_NONE; |
| 2860 | 2844 |
| 2861 case Extension::TYPE_HOSTED_APP: | 2845 case Extension::TYPE_HOSTED_APP: |
| 2862 case Extension::TYPE_PACKAGED_APP: | 2846 case Extension::TYPE_PACKAGED_APP: |
| 2863 return SYNC_TYPE_APP; | 2847 return SYNC_TYPE_APP; |
| 2864 | 2848 |
| 2865 default: | 2849 default: |
| 2866 return SYNC_TYPE_NONE; | 2850 return SYNC_TYPE_NONE; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2913 already_disabled(false), | 2897 already_disabled(false), |
| 2914 extension(extension) {} | 2898 extension(extension) {} |
| 2915 | 2899 |
| 2916 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 2900 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
| 2917 const Extension* extension, | 2901 const Extension* extension, |
| 2918 const ExtensionPermissionSet* permissions, | 2902 const ExtensionPermissionSet* permissions, |
| 2919 Reason reason) | 2903 Reason reason) |
| 2920 : reason(reason), | 2904 : reason(reason), |
| 2921 extension(extension), | 2905 extension(extension), |
| 2922 permissions(permissions) {} | 2906 permissions(permissions) {} |
| OLD | NEW |