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

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

Issue 6749021: Added new fileBrowserPrivate and fileHandler extension APIs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 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 | Annotate | Revision Log
OLDNEW
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 14 matching lines...) Expand all
25 #include "chrome/common/chrome_constants.h" 25 #include "chrome/common/chrome_constants.h"
26 #include "chrome/common/chrome_switches.h" 26 #include "chrome/common/chrome_switches.h"
27 #include "chrome/common/chrome_version_info.h" 27 #include "chrome/common/chrome_version_info.h"
28 #include "chrome/common/extensions/extension_action.h" 28 #include "chrome/common/extensions/extension_action.h"
29 #include "chrome/common/extensions/extension_constants.h" 29 #include "chrome/common/extensions/extension_constants.h"
30 #include "chrome/common/extensions/extension_error_utils.h" 30 #include "chrome/common/extensions/extension_error_utils.h"
31 #include "chrome/common/extensions/extension_l10n_util.h" 31 #include "chrome/common/extensions/extension_l10n_util.h"
32 #include "chrome/common/extensions/extension_resource.h" 32 #include "chrome/common/extensions/extension_resource.h"
33 #include "chrome/common/extensions/extension_sidebar_defaults.h" 33 #include "chrome/common/extensions/extension_sidebar_defaults.h"
34 #include "chrome/common/extensions/extension_sidebar_utils.h" 34 #include "chrome/common/extensions/extension_sidebar_utils.h"
35 #include "chrome/common/extensions/file_browser_action.h"
35 #include "chrome/common/extensions/user_script.h" 36 #include "chrome/common/extensions/user_script.h"
36 #include "chrome/common/url_constants.h" 37 #include "chrome/common/url_constants.h"
37 #include "googleurl/src/url_util.h" 38 #include "googleurl/src/url_util.h"
38 #include "grit/chromium_strings.h" 39 #include "grit/chromium_strings.h"
39 #include "grit/generated_resources.h" 40 #include "grit/generated_resources.h"
40 #include "grit/theme_resources.h" 41 #include "grit/theme_resources.h"
41 #include "net/base/registry_controlled_domain.h" 42 #include "net/base/registry_controlled_domain.h"
42 #include "third_party/skia/include/core/SkBitmap.h" 43 #include "third_party/skia/include/core/SkBitmap.h"
43 #include "ui/base/l10n/l10n_util.h" 44 #include "ui/base/l10n/l10n_util.h"
44 #include "ui/base/resource/resource_bundle.h" 45 #include "ui/base/resource/resource_bundle.h"
(...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 result->SetPopupUrl(ExtensionAction::kDefaultTabId, url); 873 result->SetPopupUrl(ExtensionAction::kDefaultTabId, url);
873 } else { 874 } else {
874 DCHECK(!result->HasPopup(ExtensionAction::kDefaultTabId)) 875 DCHECK(!result->HasPopup(ExtensionAction::kDefaultTabId))
875 << "Shouldn't be posible for the popup to be set."; 876 << "Shouldn't be posible for the popup to be set.";
876 } 877 }
877 } 878 }
878 879
879 return result.release(); 880 return result.release();
880 } 881 }
881 882
883 Extension::FileBrowserActionList* Extension::LoadFileBrowserActions(
884 const ListValue* extension_actions, std::string* error) {
885 scoped_ptr<FileBrowserActionList> result(
886 new FileBrowserActionList());
887 for (ListValue::const_iterator iter = extension_actions->begin();
888 iter != extension_actions->end();
889 ++iter) {
890 if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) {
891 *error = errors::kInvalidFileBrowserAction;
892 return false;
893 }
894 scoped_ptr<FileBrowserAction> action(
895 LoadFileBrowserAction(
896 reinterpret_cast<DictionaryValue*>(*iter), error));
897 if (!action.get())
898 return NULL; // Failed to parse file browser action definition.
899 result->push_back(linked_ptr<FileBrowserAction>(action.release()));
900 }
901 return result.release();
902 }
903
904 FileBrowserAction* Extension::LoadFileBrowserAction(
905 const DictionaryValue* file_browser_actions, std::string* error) {
Aaron Boodman 2011/04/12 22:47:21 s/file_browser_actions/file_browser_action/
zel 2011/04/13 17:49:55 Done.
906 scoped_ptr<FileBrowserAction> result(
907 new FileBrowserAction());
908 result->set_extension_id(id());
909
910 std::string id;
911 // Read the file action |id| (mandatory).
912 if (!file_browser_actions->HasKey(keys::kPageActionId) ||
Aaron Boodman 2011/04/12 22:47:21 Can you name this property "name" instead? (We don
Aaron Boodman 2011/04/12 22:48:20 Whoops, I didn't mean to include this comment. I t
913 !file_browser_actions->GetString(keys::kPageActionId, &id)) {
914 *error = errors::kInvalidPageActionId;
Aaron Boodman 2011/04/12 22:47:21 Incorrect error message.
zel 2011/04/13 17:49:55 This message is used for generic "id is missing" e
915 return NULL;
916 }
917 result->set_id(id);
918
919 // Read the page action title from |default_title| (mandatory).
920 std::string title;
921 if (!file_browser_actions->HasKey(keys::kPageActionDefaultTitle) ||
Aaron Boodman 2011/04/12 22:47:21 It's a bit weird to reuse these constants (pageAct
zel 2011/04/13 17:49:55 Done.
922 !file_browser_actions->GetString(keys::kPageActionDefaultTitle, &title)) {
923 *error = errors::kInvalidPageActionDefaultTitle;
924 return NULL;
925 }
926 result->set_default_title(title);
927
928 // Initialize file filters (mandatory).
929 ListValue* list_value;
Aaron Boodman 2011/04/12 22:47:21 = NULL
zel 2011/04/13 17:49:55 Done.
930 if (!file_browser_actions->HasKey(keys::kFileFilters) ||
931 !file_browser_actions->GetList(keys::kFileFilters, &list_value) ||
932 list_value->empty()) {
933 *error = errors::kInvalidFileFiltersList;
934 return false;
935 }
936 for (size_t i = 0; i < list_value->GetSize(); ++i) {
937 std::string filter;
938 if (!list_value->GetString(i, &filter)) {
939 *error = ExtensionErrorUtils::FormatErrorMessage(
940 errors::kInvalidFileFilterValue, base::IntToString(i));
941 return false;
942 }
943 URLPattern pattern(URLPattern::SCHEME_FILESYSTEM);
944 // TODO(skerner): Consider enabling strict pattern parsing
945 // if this extension's location indicates that it is under development.
946 if (URLPattern::PARSE_SUCCESS != pattern.Parse(filter,
947 URLPattern::PARSE_LENIENT)) {
Aaron Boodman 2011/04/12 22:47:21 Use PARSE_STRICT and remove the TODO(skerner). The
zel 2011/04/13 17:49:55 Done.
948 *error = ExtensionErrorUtils::FormatErrorMessage(
949 errors::kInvalidURLPatternError, filter);
950 return false;
951 }
952 result->AddPattern(pattern);
953 }
954
955 std::string default_icon;
956 // Read the page action |default_icon| (optional).
Aaron Boodman 2011/04/12 22:47:21 paste-o ('page action')
zel 2011/04/13 17:49:55 Done.
957 if (file_browser_actions->HasKey(keys::kPageActionDefaultIcon)) {
958 if (!file_browser_actions->GetString(keys::kPageActionDefaultIcon,
959 &default_icon) ||
Aaron Boodman 2011/04/12 22:47:21 intent+=4
zel 2011/04/13 17:49:55 Done.
960 default_icon.empty()) {
961 *error = errors::kInvalidPageActionIconPath;
962 return NULL;
963 }
964 result->set_default_icon_path(default_icon);
965 }
966
967 return result.release();
968 }
969
882 ExtensionSidebarDefaults* Extension::LoadExtensionSidebarDefaults( 970 ExtensionSidebarDefaults* Extension::LoadExtensionSidebarDefaults(
883 const DictionaryValue* extension_sidebar, std::string* error) { 971 const DictionaryValue* extension_sidebar, std::string* error) {
884 scoped_ptr<ExtensionSidebarDefaults> result(new ExtensionSidebarDefaults()); 972 scoped_ptr<ExtensionSidebarDefaults> result(new ExtensionSidebarDefaults());
885 973
886 std::string default_icon; 974 std::string default_icon;
887 // Read sidebar's |default_icon| (optional). 975 // Read sidebar's |default_icon| (optional).
888 if (extension_sidebar->HasKey(keys::kSidebarDefaultIcon)) { 976 if (extension_sidebar->HasKey(keys::kSidebarDefaultIcon)) {
889 if (!extension_sidebar->GetString(keys::kSidebarDefaultIcon, 977 if (!extension_sidebar->GetString(keys::kSidebarDefaultIcon,
890 &default_icon) || 978 &default_icon) ||
891 default_icon.empty()) { 979 default_icon.empty()) {
(...skipping 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after
1903 *error = errors::kInvalidBrowserAction; 1991 *error = errors::kInvalidBrowserAction;
1904 return false; 1992 return false;
1905 } 1993 }
1906 1994
1907 browser_action_.reset( 1995 browser_action_.reset(
1908 LoadExtensionActionHelper(browser_action_value, error)); 1996 LoadExtensionActionHelper(browser_action_value, error));
1909 if (!browser_action_.get()) 1997 if (!browser_action_.get())
1910 return false; // Failed to parse browser action definition. 1998 return false; // Failed to parse browser action definition.
1911 } 1999 }
1912 2000
2001 // Initialize browser action (optional).
asargent_no_longer_on_chrome 2011/04/12 21:09:38 nit: comment should be "Initialize file browser ac
zel 2011/04/13 17:49:55 Done.
2002 if (source.HasKey(keys::kFileBrowserActions)) {
2003 ListValue* file_browser_actions_value = NULL;
2004 if (!source.GetList(keys::kFileBrowserActions,
2005 &file_browser_actions_value)) {
2006 *error = errors::kInvalidFileBrowserAction;
2007 return false;
2008 }
2009
2010 file_browser_actions_.reset(
2011 LoadFileBrowserActions(file_browser_actions_value, error));
2012 if (!file_browser_actions_.get())
2013 return false; // Failed to parse browser action definition.
asargent_no_longer_on_chrome 2011/04/12 21:09:38 same naming nit on comment here
zel 2011/04/13 17:49:55 Done.
2014 }
2015
1913 // Load App settings. 2016 // Load App settings.
1914 if (!LoadIsApp(manifest_value_.get(), error) || 2017 if (!LoadIsApp(manifest_value_.get(), error) ||
1915 !LoadExtent(manifest_value_.get(), keys::kWebURLs, 2018 !LoadExtent(manifest_value_.get(), keys::kWebURLs,
1916 &extent_, 2019 &extent_,
1917 errors::kInvalidWebURLs, errors::kInvalidWebURL, 2020 errors::kInvalidWebURLs, errors::kInvalidWebURL,
1918 parse_strictness, error) || 2021 parse_strictness, error) ||
1919 !EnsureNotHybridApp(manifest_value_.get(), error) || 2022 !EnsureNotHybridApp(manifest_value_.get(), error) ||
1920 !LoadLaunchURL(manifest_value_.get(), error) || 2023 !LoadLaunchURL(manifest_value_.get(), error) ||
1921 !LoadLaunchContainer(manifest_value_.get(), error) || 2024 !LoadLaunchContainer(manifest_value_.get(), error) ||
1922 !LoadAppIsolation(manifest_value_.get(), error)) { 2025 !LoadAppIsolation(manifest_value_.get(), error)) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1969 std::string permission_str; 2072 std::string permission_str;
1970 if (!permissions->GetString(i, &permission_str)) { 2073 if (!permissions->GetString(i, &permission_str)) {
1971 *error = ExtensionErrorUtils::FormatErrorMessage( 2074 *error = ExtensionErrorUtils::FormatErrorMessage(
1972 errors::kInvalidPermission, base::IntToString(i)); 2075 errors::kInvalidPermission, base::IntToString(i));
1973 return false; 2076 return false;
1974 } 2077 }
1975 2078
1976 // Only COMPONENT extensions can use private APIs. 2079 // Only COMPONENT extensions can use private APIs.
1977 // TODO(asargent) - We want a more general purpose mechanism for this, 2080 // TODO(asargent) - We want a more general purpose mechanism for this,
1978 // and better error messages. (http://crbug.com/54013) 2081 // and better error messages. (http://crbug.com/54013)
1979 if (!IsComponentOnlyPermission(permission_str)) { 2082 if (!IsComponentOnlyPermission(permission_str)
2083 #ifndef NDEBUG
2084 && !CommandLine::ForCurrentProcess()->HasSwitch(
Aaron Boodman 2011/04/12 22:47:21 Is this testing code? Can we remove it?
zel 2011/04/13 17:49:55 This is super useful for us while debugging compon
2085 switches::kExposePrivateExtensionApi)
2086 #endif
2087 ) {
1980 continue; 2088 continue;
1981 } 2089 }
1982 2090
1983 // Remap the old unlimited storage permission name. 2091 // Remap the old unlimited storage permission name.
1984 if (permission_str == kOldUnlimitedStoragePermission) 2092 if (permission_str == kOldUnlimitedStoragePermission)
1985 permission_str = kUnlimitedStoragePermission; 2093 permission_str = kUnlimitedStoragePermission;
1986 2094
1987 if (web_extent().is_empty() || location() == Extension::COMPONENT) { 2095 if (web_extent().is_empty() || location() == Extension::COMPONENT) {
1988 // Check if it's a module permission. If so, enable that permission. 2096 // Check if it's a module permission. If so, enable that permission.
1989 if (IsAPIPermission(permission_str)) { 2097 if (IsAPIPermission(permission_str)) {
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
2566 bool Extension::IsAPIPermission(const std::string& str) const { 2674 bool Extension::IsAPIPermission(const std::string& str) const {
2567 for (size_t i = 0; i < Extension::kNumPermissions; ++i) { 2675 for (size_t i = 0; i < Extension::kNumPermissions; ++i) {
2568 if (str == Extension::kPermissions[i].name) { 2676 if (str == Extension::kPermissions[i].name) {
2569 return true; 2677 return true;
2570 } 2678 }
2571 } 2679 }
2572 return false; 2680 return false;
2573 } 2681 }
2574 2682
2575 bool Extension::CanExecuteScriptEverywhere() const { 2683 bool Extension::CanExecuteScriptEverywhere() const {
2576 if (location() == Extension::COMPONENT) 2684 if (location() == Extension::COMPONENT
2685 #ifndef NDEBUG
2686 || CommandLine::ForCurrentProcess()->HasSwitch(
Aaron Boodman 2011/04/12 22:47:21 Is this testing code? Can we remove it?
zel 2011/04/13 17:49:55 see comments above
2687 switches::kExposePrivateExtensionApi)
2688 #endif
2689 )
2577 return true; 2690 return true;
2578 2691
2579 ScriptingWhitelist* whitelist = 2692 ScriptingWhitelist* whitelist =
2580 ExtensionConfig::GetInstance()->whitelist(); 2693 ExtensionConfig::GetInstance()->whitelist();
2581 2694
2582 for (ScriptingWhitelist::const_iterator it = whitelist->begin(); 2695 for (ScriptingWhitelist::const_iterator it = whitelist->begin();
2583 it != whitelist->end(); ++it) { 2696 it != whitelist->end(); ++it) {
2584 if (id() == *it) { 2697 if (id() == *it) {
2585 return true; 2698 return true;
2586 } 2699 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
2648 2761
2649 UninstalledExtensionInfo::~UninstalledExtensionInfo() {} 2762 UninstalledExtensionInfo::~UninstalledExtensionInfo() {}
2650 2763
2651 2764
2652 UnloadedExtensionInfo::UnloadedExtensionInfo( 2765 UnloadedExtensionInfo::UnloadedExtensionInfo(
2653 const Extension* extension, 2766 const Extension* extension,
2654 Reason reason) 2767 Reason reason)
2655 : reason(reason), 2768 : reason(reason),
2656 already_disabled(false), 2769 already_disabled(false),
2657 extension(extension) {} 2770 extension(extension) {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698