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

Side by Side Diff: chrome/common/extensions/extension.cc

Issue 11741014: Move 'intents' parsing out of Extension (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed special_storage_policy unittest Created 7 years, 11 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/common/extensions/extension.h" 5 #include "chrome/common/extensions/extension.h"
6 6
7 #include <ostream> 7 #include <ostream>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "extensions/common/constants.h" 42 #include "extensions/common/constants.h"
43 #include "extensions/common/error_utils.h" 43 #include "extensions/common/error_utils.h"
44 #include "extensions/common/url_pattern_set.h" 44 #include "extensions/common/url_pattern_set.h"
45 #include "googleurl/src/url_util.h" 45 #include "googleurl/src/url_util.h"
46 #include "grit/chromium_strings.h" 46 #include "grit/chromium_strings.h"
47 #include "grit/theme_resources.h" 47 #include "grit/theme_resources.h"
48 #include "third_party/skia/include/core/SkBitmap.h" 48 #include "third_party/skia/include/core/SkBitmap.h"
49 #include "ui/base/l10n/l10n_util.h" 49 #include "ui/base/l10n/l10n_util.h"
50 #include "ui/base/resource/resource_bundle.h" 50 #include "ui/base/resource/resource_bundle.h"
51 #include "webkit/glue/image_decoder.h" 51 #include "webkit/glue/image_decoder.h"
52 #include "webkit/glue/web_intent_service_data.h"
53 52
54 #if defined(OS_WIN) 53 #if defined(OS_WIN)
55 #include "base/win/metro.h" 54 #include "base/win/metro.h"
56 #include "grit/generated_resources.h" 55 #include "grit/generated_resources.h"
57 #endif 56 #endif
58 57
59 namespace keys = extension_manifest_keys; 58 namespace keys = extension_manifest_keys;
60 namespace values = extension_manifest_values; 59 namespace values = extension_manifest_values;
61 namespace errors = extension_manifest_errors; 60 namespace errors = extension_manifest_errors;
62 namespace info_keys = extension_info_keys; 61 namespace info_keys = extension_info_keys;
(...skipping 1919 matching lines...) Expand 10 before | Expand all | Expand 10 after
1982 !LoadSandboxedPages(error) || 1981 !LoadSandboxedPages(error) ||
1983 !LoadRequirements(error) || 1982 !LoadRequirements(error) ||
1984 !LoadDefaultLocale(error) || 1983 !LoadDefaultLocale(error) ||
1985 !LoadOfflineEnabled(error) || 1984 !LoadOfflineEnabled(error) ||
1986 !LoadOptionsPage(error) || 1985 !LoadOptionsPage(error) ||
1987 // LoadBackgroundScripts() must be called before LoadBackgroundPage(). 1986 // LoadBackgroundScripts() must be called before LoadBackgroundPage().
1988 !LoadBackgroundScripts(error) || 1987 !LoadBackgroundScripts(error) ||
1989 !LoadBackgroundPage(api_permissions, error) || 1988 !LoadBackgroundPage(api_permissions, error) ||
1990 !LoadBackgroundPersistent(api_permissions, error) || 1989 !LoadBackgroundPersistent(api_permissions, error) ||
1991 !LoadBackgroundAllowJSAccess(api_permissions, error) || 1990 !LoadBackgroundAllowJSAccess(api_permissions, error) ||
1992 !LoadWebIntentServices(error) ||
1993 !LoadOAuth2Info(error)) 1991 !LoadOAuth2Info(error))
1994 return false; 1992 return false;
1995 1993
1996 return true; 1994 return true;
1997 } 1995 }
1998 1996
1999 bool Extension::LoadDescription(string16* error) { 1997 bool Extension::LoadDescription(string16* error) {
2000 if (manifest_->HasKey(keys::kDescription) && 1998 if (manifest_->HasKey(keys::kDescription) &&
2001 !manifest_->GetString(keys::kDescription, &description_)) { 1999 !manifest_->GetString(keys::kDescription, &description_)) {
2002 *error = ASCIIToUTF16(errors::kInvalidDescription); 2000 *error = ASCIIToUTF16(errors::kInvalidDescription);
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after
2586 2584
2587 if (!allow_js_access->IsType(Value::TYPE_BOOLEAN) || 2585 if (!allow_js_access->IsType(Value::TYPE_BOOLEAN) ||
2588 !allow_js_access->GetAsBoolean(&allow_background_js_access_)) { 2586 !allow_js_access->GetAsBoolean(&allow_background_js_access_)) {
2589 *error = ASCIIToUTF16(errors::kInvalidBackgroundAllowJsAccess); 2587 *error = ASCIIToUTF16(errors::kInvalidBackgroundAllowJsAccess);
2590 return false; 2588 return false;
2591 } 2589 }
2592 2590
2593 return true; 2591 return true;
2594 } 2592 }
2595 2593
2596 bool Extension::LoadWebIntentAction(const std::string& action_name,
2597 const DictionaryValue& intent_service,
2598 string16* error) {
2599 DCHECK(error);
2600 webkit_glue::WebIntentServiceData service;
2601 std::string value;
2602
2603 service.action = UTF8ToUTF16(action_name);
2604
2605 const ListValue* mime_types = NULL;
2606 if (!intent_service.HasKey(keys::kIntentType) ||
2607 !intent_service.GetList(keys::kIntentType, &mime_types) ||
2608 mime_types->GetSize() == 0) {
2609 *error = ErrorUtils::FormatErrorMessageUTF16(
2610 errors::kInvalidIntentType, action_name);
2611 return false;
2612 }
2613
2614 std::string href;
2615 if (intent_service.HasKey(keys::kIntentPath)) {
2616 if (!intent_service.GetString(keys::kIntentPath, &href)) {
2617 *error = ASCIIToUTF16(errors::kInvalidIntentHref);
2618 return false;
2619 }
2620 }
2621
2622 if (intent_service.HasKey(keys::kIntentHref)) {
2623 if (!href.empty()) {
2624 *error = ErrorUtils::FormatErrorMessageUTF16(
2625 errors::kInvalidIntentHrefOldAndNewKey, action_name,
2626 keys::kIntentPath, keys::kIntentHref);
2627 return false;
2628 }
2629 if (!intent_service.GetString(keys::kIntentHref, &href)) {
2630 *error = ASCIIToUTF16(errors::kInvalidIntentHref);
2631 return false;
2632 }
2633 }
2634
2635 // For packaged/hosted apps, empty href implies the respective launch URLs.
2636 if (href.empty()) {
2637 if (is_hosted_app()) {
2638 href = launch_web_url();
2639 } else if (is_legacy_packaged_app()) {
2640 href = launch_local_path();
2641 }
2642 }
2643
2644 // If there still is not an href, the manifest is malformed, unless this is a
2645 // platform app in which case the href should not be present.
2646 if (href.empty() && !is_platform_app()) {
2647 *error = ErrorUtils::FormatErrorMessageUTF16(
2648 errors::kInvalidIntentHrefEmpty, action_name);
2649 return false;
2650 } else if (!href.empty() && is_platform_app()) {
2651 *error = ErrorUtils::FormatErrorMessageUTF16(
2652 errors::kInvalidIntentHrefInPlatformApp, action_name);
2653 return false;
2654 }
2655
2656 GURL service_url(href);
2657 if (is_hosted_app()) {
2658 // Hosted apps require an absolute URL for intents.
2659 if (!service_url.is_valid() ||
2660 !(web_extent().MatchesURL(service_url))) {
2661 *error = ErrorUtils::FormatErrorMessageUTF16(
2662 errors::kInvalidIntentPageInHostedApp, action_name);
2663 return false;
2664 }
2665 service.service_url = service_url;
2666 } else if (is_platform_app()) {
2667 service.service_url = GetBackgroundURL();
2668 } else {
2669 // We do not allow absolute intent URLs in non-hosted apps.
2670 if (service_url.is_valid()) {
2671 *error = ErrorUtils::FormatErrorMessageUTF16(
2672 errors::kCannotAccessPage, href);
2673 return false;
2674 }
2675 service.service_url = GetResourceURL(href);
2676 }
2677
2678 if (intent_service.HasKey(keys::kIntentTitle) &&
2679 !intent_service.GetString(keys::kIntentTitle, &service.title)) {
2680 *error = ASCIIToUTF16(errors::kInvalidIntentTitle);
2681 return false;
2682 }
2683
2684 if (intent_service.HasKey(keys::kIntentDisposition)) {
2685 if (is_platform_app()) {
2686 *error = ErrorUtils::FormatErrorMessageUTF16(
2687 errors::kInvalidIntentDispositionInPlatformApp, action_name);
2688 return false;
2689 }
2690 if (!intent_service.GetString(keys::kIntentDisposition, &value) ||
2691 (value != values::kIntentDispositionWindow &&
2692 value != values::kIntentDispositionInline)) {
2693 *error = ASCIIToUTF16(errors::kInvalidIntentDisposition);
2694 return false;
2695 }
2696 if (value == values::kIntentDispositionInline) {
2697 service.disposition =
2698 webkit_glue::WebIntentServiceData::DISPOSITION_INLINE;
2699 } else {
2700 service.disposition =
2701 webkit_glue::WebIntentServiceData::DISPOSITION_WINDOW;
2702 }
2703 }
2704
2705 for (size_t i = 0; i < mime_types->GetSize(); ++i) {
2706 if (!mime_types->GetString(i, &service.type)) {
2707 *error = ErrorUtils::FormatErrorMessageUTF16(
2708 errors::kInvalidIntentTypeElement, action_name,
2709 std::string(base::IntToString(i)));
2710 return false;
2711 }
2712 intents_services_.push_back(service);
2713 }
2714 return true;
2715 }
2716
2717 bool Extension::LoadWebIntentServices(string16* error) {
2718 DCHECK(error);
2719
2720 if (!manifest_->HasKey(keys::kIntents))
2721 return true;
2722
2723 DictionaryValue* all_services = NULL;
2724 if (!manifest_->GetDictionary(keys::kIntents, &all_services)) {
2725 *error = ASCIIToUTF16(errors::kInvalidIntents);
2726 return false;
2727 }
2728
2729 for (DictionaryValue::key_iterator iter(all_services->begin_keys());
2730 iter != all_services->end_keys(); ++iter) {
2731 // Any entry in the intents dictionary can either have a list of
2732 // dictionaries, or just a single dictionary attached to that. Try
2733 // lists first, fall back to single dictionary.
2734 ListValue* service_list = NULL;
2735 DictionaryValue* one_service = NULL;
2736 if (all_services->GetListWithoutPathExpansion(*iter, &service_list)) {
2737 for (size_t i = 0; i < service_list->GetSize(); ++i) {
2738 if (!service_list->GetDictionary(i, &one_service)) {
2739 *error = ASCIIToUTF16(errors::kInvalidIntent);
2740 return false;
2741 }
2742 if (!LoadWebIntentAction(*iter, *one_service, error))
2743 return false;
2744 }
2745 } else {
2746 if (!all_services->GetDictionaryWithoutPathExpansion(*iter,
2747 &one_service)) {
2748 *error = ASCIIToUTF16(errors::kInvalidIntent);
2749 return false;
2750 }
2751 if (!LoadWebIntentAction(*iter, *one_service, error))
2752 return false;
2753 }
2754 }
2755 return true;
2756 }
2757
2758 bool Extension::LoadFileHandler(const std::string& handler_id, 2594 bool Extension::LoadFileHandler(const std::string& handler_id,
2759 const DictionaryValue& handler_info, 2595 const DictionaryValue& handler_info,
2760 string16* error) { 2596 string16* error) {
2761 DCHECK(error); 2597 DCHECK(error);
2762 DCHECK(is_platform_app()); 2598 DCHECK(is_platform_app());
2763 FileHandlerInfo handler; 2599 FileHandlerInfo handler;
2764 2600
2765 handler.id = handler_id; 2601 handler.id = handler_id;
2766 2602
2767 const ListValue* mime_types = NULL; 2603 const ListValue* mime_types = NULL;
(...skipping 1099 matching lines...) Expand 10 before | Expand all | Expand 10 after
3867 3703
3868 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( 3704 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo(
3869 const Extension* extension, 3705 const Extension* extension,
3870 const PermissionSet* permissions, 3706 const PermissionSet* permissions,
3871 Reason reason) 3707 Reason reason)
3872 : reason(reason), 3708 : reason(reason),
3873 extension(extension), 3709 extension(extension),
3874 permissions(permissions) {} 3710 permissions(permissions) {}
3875 3711
3876 } // namespace extensions 3712 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698