| OLD | NEW |
| 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 Loading... |
| 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 1880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1943 !LoadSandboxedPages(error) || | 1942 !LoadSandboxedPages(error) || |
| 1944 !LoadRequirements(error) || | 1943 !LoadRequirements(error) || |
| 1945 !LoadDefaultLocale(error) || | 1944 !LoadDefaultLocale(error) || |
| 1946 !LoadOfflineEnabled(error) || | 1945 !LoadOfflineEnabled(error) || |
| 1947 !LoadOptionsPage(error) || | 1946 !LoadOptionsPage(error) || |
| 1948 // LoadBackgroundScripts() must be called before LoadBackgroundPage(). | 1947 // LoadBackgroundScripts() must be called before LoadBackgroundPage(). |
| 1949 !LoadBackgroundScripts(error) || | 1948 !LoadBackgroundScripts(error) || |
| 1950 !LoadBackgroundPage(api_permissions, error) || | 1949 !LoadBackgroundPage(api_permissions, error) || |
| 1951 !LoadBackgroundPersistent(api_permissions, error) || | 1950 !LoadBackgroundPersistent(api_permissions, error) || |
| 1952 !LoadBackgroundAllowJSAccess(api_permissions, error) || | 1951 !LoadBackgroundAllowJSAccess(api_permissions, error) || |
| 1953 !LoadWebIntentServices(error) || | |
| 1954 !LoadOAuth2Info(error)) | 1952 !LoadOAuth2Info(error)) |
| 1955 return false; | 1953 return false; |
| 1956 | 1954 |
| 1957 return true; | 1955 return true; |
| 1958 } | 1956 } |
| 1959 | 1957 |
| 1960 bool Extension::LoadDescription(string16* error) { | 1958 bool Extension::LoadDescription(string16* error) { |
| 1961 if (manifest_->HasKey(keys::kDescription) && | 1959 if (manifest_->HasKey(keys::kDescription) && |
| 1962 !manifest_->GetString(keys::kDescription, &description_)) { | 1960 !manifest_->GetString(keys::kDescription, &description_)) { |
| 1963 *error = ASCIIToUTF16(errors::kInvalidDescription); | 1961 *error = ASCIIToUTF16(errors::kInvalidDescription); |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2547 | 2545 |
| 2548 if (!allow_js_access->IsType(Value::TYPE_BOOLEAN) || | 2546 if (!allow_js_access->IsType(Value::TYPE_BOOLEAN) || |
| 2549 !allow_js_access->GetAsBoolean(&allow_background_js_access_)) { | 2547 !allow_js_access->GetAsBoolean(&allow_background_js_access_)) { |
| 2550 *error = ASCIIToUTF16(errors::kInvalidBackgroundAllowJsAccess); | 2548 *error = ASCIIToUTF16(errors::kInvalidBackgroundAllowJsAccess); |
| 2551 return false; | 2549 return false; |
| 2552 } | 2550 } |
| 2553 | 2551 |
| 2554 return true; | 2552 return true; |
| 2555 } | 2553 } |
| 2556 | 2554 |
| 2557 bool Extension::LoadWebIntentAction(const std::string& action_name, | |
| 2558 const DictionaryValue& intent_service, | |
| 2559 string16* error) { | |
| 2560 DCHECK(error); | |
| 2561 webkit_glue::WebIntentServiceData service; | |
| 2562 std::string value; | |
| 2563 | |
| 2564 service.action = UTF8ToUTF16(action_name); | |
| 2565 | |
| 2566 const ListValue* mime_types = NULL; | |
| 2567 if (!intent_service.HasKey(keys::kIntentType) || | |
| 2568 !intent_service.GetList(keys::kIntentType, &mime_types) || | |
| 2569 mime_types->GetSize() == 0) { | |
| 2570 *error = ErrorUtils::FormatErrorMessageUTF16( | |
| 2571 errors::kInvalidIntentType, action_name); | |
| 2572 return false; | |
| 2573 } | |
| 2574 | |
| 2575 std::string href; | |
| 2576 if (intent_service.HasKey(keys::kIntentPath)) { | |
| 2577 if (!intent_service.GetString(keys::kIntentPath, &href)) { | |
| 2578 *error = ASCIIToUTF16(errors::kInvalidIntentHref); | |
| 2579 return false; | |
| 2580 } | |
| 2581 } | |
| 2582 | |
| 2583 if (intent_service.HasKey(keys::kIntentHref)) { | |
| 2584 if (!href.empty()) { | |
| 2585 *error = ErrorUtils::FormatErrorMessageUTF16( | |
| 2586 errors::kInvalidIntentHrefOldAndNewKey, action_name, | |
| 2587 keys::kIntentPath, keys::kIntentHref); | |
| 2588 return false; | |
| 2589 } | |
| 2590 if (!intent_service.GetString(keys::kIntentHref, &href)) { | |
| 2591 *error = ASCIIToUTF16(errors::kInvalidIntentHref); | |
| 2592 return false; | |
| 2593 } | |
| 2594 } | |
| 2595 | |
| 2596 // For packaged/hosted apps, empty href implies the respective launch URLs. | |
| 2597 if (href.empty()) { | |
| 2598 if (is_hosted_app()) { | |
| 2599 href = launch_web_url(); | |
| 2600 } else if (is_legacy_packaged_app()) { | |
| 2601 href = launch_local_path(); | |
| 2602 } | |
| 2603 } | |
| 2604 | |
| 2605 // If there still is not an href, the manifest is malformed, unless this is a | |
| 2606 // platform app in which case the href should not be present. | |
| 2607 if (href.empty() && !is_platform_app()) { | |
| 2608 *error = ErrorUtils::FormatErrorMessageUTF16( | |
| 2609 errors::kInvalidIntentHrefEmpty, action_name); | |
| 2610 return false; | |
| 2611 } else if (!href.empty() && is_platform_app()) { | |
| 2612 *error = ErrorUtils::FormatErrorMessageUTF16( | |
| 2613 errors::kInvalidIntentHrefInPlatformApp, action_name); | |
| 2614 return false; | |
| 2615 } | |
| 2616 | |
| 2617 GURL service_url(href); | |
| 2618 if (is_hosted_app()) { | |
| 2619 // Hosted apps require an absolute URL for intents. | |
| 2620 if (!service_url.is_valid() || | |
| 2621 !(web_extent().MatchesURL(service_url))) { | |
| 2622 *error = ErrorUtils::FormatErrorMessageUTF16( | |
| 2623 errors::kInvalidIntentPageInHostedApp, action_name); | |
| 2624 return false; | |
| 2625 } | |
| 2626 service.service_url = service_url; | |
| 2627 } else if (is_platform_app()) { | |
| 2628 service.service_url = GetBackgroundURL(); | |
| 2629 } else { | |
| 2630 // We do not allow absolute intent URLs in non-hosted apps. | |
| 2631 if (service_url.is_valid()) { | |
| 2632 *error = ErrorUtils::FormatErrorMessageUTF16( | |
| 2633 errors::kCannotAccessPage, href); | |
| 2634 return false; | |
| 2635 } | |
| 2636 service.service_url = GetResourceURL(href); | |
| 2637 } | |
| 2638 | |
| 2639 if (intent_service.HasKey(keys::kIntentTitle) && | |
| 2640 !intent_service.GetString(keys::kIntentTitle, &service.title)) { | |
| 2641 *error = ASCIIToUTF16(errors::kInvalidIntentTitle); | |
| 2642 return false; | |
| 2643 } | |
| 2644 | |
| 2645 if (intent_service.HasKey(keys::kIntentDisposition)) { | |
| 2646 if (is_platform_app()) { | |
| 2647 *error = ErrorUtils::FormatErrorMessageUTF16( | |
| 2648 errors::kInvalidIntentDispositionInPlatformApp, action_name); | |
| 2649 return false; | |
| 2650 } | |
| 2651 if (!intent_service.GetString(keys::kIntentDisposition, &value) || | |
| 2652 (value != values::kIntentDispositionWindow && | |
| 2653 value != values::kIntentDispositionInline)) { | |
| 2654 *error = ASCIIToUTF16(errors::kInvalidIntentDisposition); | |
| 2655 return false; | |
| 2656 } | |
| 2657 if (value == values::kIntentDispositionInline) { | |
| 2658 service.disposition = | |
| 2659 webkit_glue::WebIntentServiceData::DISPOSITION_INLINE; | |
| 2660 } else { | |
| 2661 service.disposition = | |
| 2662 webkit_glue::WebIntentServiceData::DISPOSITION_WINDOW; | |
| 2663 } | |
| 2664 } | |
| 2665 | |
| 2666 for (size_t i = 0; i < mime_types->GetSize(); ++i) { | |
| 2667 if (!mime_types->GetString(i, &service.type)) { | |
| 2668 *error = ErrorUtils::FormatErrorMessageUTF16( | |
| 2669 errors::kInvalidIntentTypeElement, action_name, | |
| 2670 std::string(base::IntToString(i))); | |
| 2671 return false; | |
| 2672 } | |
| 2673 intents_services_.push_back(service); | |
| 2674 } | |
| 2675 return true; | |
| 2676 } | |
| 2677 | |
| 2678 bool Extension::LoadWebIntentServices(string16* error) { | |
| 2679 DCHECK(error); | |
| 2680 | |
| 2681 if (!manifest_->HasKey(keys::kIntents)) | |
| 2682 return true; | |
| 2683 | |
| 2684 DictionaryValue* all_services = NULL; | |
| 2685 if (!manifest_->GetDictionary(keys::kIntents, &all_services)) { | |
| 2686 *error = ASCIIToUTF16(errors::kInvalidIntents); | |
| 2687 return false; | |
| 2688 } | |
| 2689 | |
| 2690 for (DictionaryValue::key_iterator iter(all_services->begin_keys()); | |
| 2691 iter != all_services->end_keys(); ++iter) { | |
| 2692 // Any entry in the intents dictionary can either have a list of | |
| 2693 // dictionaries, or just a single dictionary attached to that. Try | |
| 2694 // lists first, fall back to single dictionary. | |
| 2695 ListValue* service_list = NULL; | |
| 2696 DictionaryValue* one_service = NULL; | |
| 2697 if (all_services->GetListWithoutPathExpansion(*iter, &service_list)) { | |
| 2698 for (size_t i = 0; i < service_list->GetSize(); ++i) { | |
| 2699 if (!service_list->GetDictionary(i, &one_service)) { | |
| 2700 *error = ASCIIToUTF16(errors::kInvalidIntent); | |
| 2701 return false; | |
| 2702 } | |
| 2703 if (!LoadWebIntentAction(*iter, *one_service, error)) | |
| 2704 return false; | |
| 2705 } | |
| 2706 } else { | |
| 2707 if (!all_services->GetDictionaryWithoutPathExpansion(*iter, | |
| 2708 &one_service)) { | |
| 2709 *error = ASCIIToUTF16(errors::kInvalidIntent); | |
| 2710 return false; | |
| 2711 } | |
| 2712 if (!LoadWebIntentAction(*iter, *one_service, error)) | |
| 2713 return false; | |
| 2714 } | |
| 2715 } | |
| 2716 return true; | |
| 2717 } | |
| 2718 | |
| 2719 bool Extension::LoadFileHandler(const std::string& handler_id, | 2555 bool Extension::LoadFileHandler(const std::string& handler_id, |
| 2720 const DictionaryValue& handler_info, | 2556 const DictionaryValue& handler_info, |
| 2721 string16* error) { | 2557 string16* error) { |
| 2722 DCHECK(error); | 2558 DCHECK(error); |
| 2723 DCHECK(is_platform_app()); | 2559 DCHECK(is_platform_app()); |
| 2724 FileHandlerInfo handler; | 2560 FileHandlerInfo handler; |
| 2725 | 2561 |
| 2726 handler.id = handler_id; | 2562 handler.id = handler_id; |
| 2727 | 2563 |
| 2728 const ListValue* mime_types = NULL; | 2564 const ListValue* mime_types = NULL; |
| (...skipping 1319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4048 | 3884 |
| 4049 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 3885 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
| 4050 const Extension* extension, | 3886 const Extension* extension, |
| 4051 const PermissionSet* permissions, | 3887 const PermissionSet* permissions, |
| 4052 Reason reason) | 3888 Reason reason) |
| 4053 : reason(reason), | 3889 : reason(reason), |
| 4054 extension(extension), | 3890 extension(extension), |
| 4055 permissions(permissions) {} | 3891 permissions(permissions) {} |
| 4056 | 3892 |
| 4057 } // namespace extensions | 3893 } // namespace extensions |
| OLD | NEW |