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

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

Issue 10382216: Remove browser-actions-for-all flag and replace funcionality with action-box. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: whitespace Created 8 years, 7 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
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/base64.h" 7 #include "base/base64.h"
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
(...skipping 12 matching lines...) Expand all
23 #include "base/values.h" 23 #include "base/values.h"
24 #include "base/version.h" 24 #include "base/version.h"
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/csp_validator.h" 28 #include "chrome/common/extensions/csp_validator.h"
29 #include "chrome/common/extensions/extension_action.h" 29 #include "chrome/common/extensions/extension_action.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_manifest_constants.h" 31 #include "chrome/common/extensions/extension_manifest_constants.h"
32 #include "chrome/common/extensions/extension_resource.h" 32 #include "chrome/common/extensions/extension_resource.h"
33 #include "chrome/common/extensions/extension_switch_utils.h"
33 #include "chrome/common/extensions/feature.h" 34 #include "chrome/common/extensions/feature.h"
34 #include "chrome/common/extensions/file_browser_handler.h" 35 #include "chrome/common/extensions/file_browser_handler.h"
35 #include "chrome/common/extensions/manifest.h" 36 #include "chrome/common/extensions/manifest.h"
36 #include "chrome/common/extensions/simple_feature_provider.h" 37 #include "chrome/common/extensions/simple_feature_provider.h"
37 #include "chrome/common/extensions/user_script.h" 38 #include "chrome/common/extensions/user_script.h"
38 #include "chrome/common/url_constants.h" 39 #include "chrome/common/url_constants.h"
39 #include "crypto/sha2.h" 40 #include "crypto/sha2.h"
40 #include "googleurl/src/url_util.h" 41 #include "googleurl/src/url_util.h"
41 #include "grit/chromium_strings.h" 42 #include "grit/chromium_strings.h"
42 #include "grit/generated_resources.h" 43 #include "grit/generated_resources.h"
43 #include "grit/theme_resources.h" 44 #include "grit/theme_resources.h"
44 #include "net/base/registry_controlled_domain.h" 45 #include "net/base/registry_controlled_domain.h"
45 #include "third_party/skia/include/core/SkBitmap.h" 46 #include "third_party/skia/include/core/SkBitmap.h"
46 #include "ui/base/keycodes/keyboard_codes.h" 47 #include "ui/base/keycodes/keyboard_codes.h"
47 #include "ui/base/l10n/l10n_util.h" 48 #include "ui/base/l10n/l10n_util.h"
48 #include "ui/base/resource/resource_bundle.h" 49 #include "ui/base/resource/resource_bundle.h"
49 #include "webkit/glue/image_decoder.h" 50 #include "webkit/glue/image_decoder.h"
50 #include "webkit/glue/web_intent_service_data.h" 51 #include "webkit/glue/web_intent_service_data.h"
51 52
52 namespace keys = extension_manifest_keys; 53 namespace keys = extension_manifest_keys;
53 namespace values = extension_manifest_values; 54 namespace values = extension_manifest_values;
54 namespace errors = extension_manifest_errors; 55 namespace errors = extension_manifest_errors;
55 namespace info_keys = extension_info_keys; 56 namespace info_keys = extension_info_keys;
57 namespace switch_utils = extensions::switch_utils;
56 58
57 using extensions::csp_validator::ContentSecurityPolicyIsLegal; 59 using extensions::csp_validator::ContentSecurityPolicyIsLegal;
58 using extensions::csp_validator::ContentSecurityPolicyIsSecure; 60 using extensions::csp_validator::ContentSecurityPolicyIsSecure;
59 61
60 namespace { 62 namespace {
61 63
62 const int kModernManifestVersion = 1; 64 const int kModernManifestVersion = 1;
63 const int kPEMOutputColumns = 65; 65 const int kPEMOutputColumns = 65;
64 66
65 const char kOverrideExtentUrlPatternFormat[] = "chrome://%s/*"; 67 const char kOverrideExtentUrlPatternFormat[] = "chrome://%s/*";
(...skipping 2039 matching lines...) Expand 10 before | Expand all | Expand 10 after
2105 } 2107 }
2106 } 2108 }
2107 2109
2108 // If page_action_value is not NULL, then there was a valid page action. 2110 // If page_action_value is not NULL, then there was a valid page action.
2109 if (page_action_value) { 2111 if (page_action_value) {
2110 page_action_ = LoadExtensionActionHelper(page_action_value, error); 2112 page_action_ = LoadExtensionActionHelper(page_action_value, error);
2111 if (!page_action_.get()) 2113 if (!page_action_.get())
2112 return false; // Failed to parse page action definition. 2114 return false; // Failed to parse page action definition.
2113 declared_action_type_ = ExtensionAction::TYPE_PAGE; 2115 declared_action_type_ = ExtensionAction::TYPE_PAGE;
2114 2116
2115 if (CommandLine::ForCurrentProcess()->HasSwitch( 2117 // The action box changes the meaning of the page action area, so we need
2116 switches::kEnableBrowserActionsForAll)) { 2118 // to convert page actions into browser actions.
2119 if (switch_utils::IsActionBoxEnabled()) {
2117 browser_action_ = page_action_.Pass(); 2120 browser_action_ = page_action_.Pass();
2118 // declared_action_type_ stays the same; that's the point. 2121 // declared_action_type_ stays the same; that's the point.
2119 } 2122 }
2120 } 2123 }
2121 2124
2122 return true; 2125 return true;
2123 } 2126 }
2124 2127
2125 bool Extension::LoadBrowserAction(string16* error) { 2128 bool Extension::LoadBrowserAction(string16* error) {
2126 if (!manifest_->HasKey(keys::kBrowserAction)) 2129 if (!manifest_->HasKey(keys::kBrowserAction))
2127 return true; 2130 return true;
2128 DictionaryValue* browser_action_value = NULL; 2131 DictionaryValue* browser_action_value = NULL;
2129 if (!manifest_->GetDictionary(keys::kBrowserAction, &browser_action_value)) { 2132 if (!manifest_->GetDictionary(keys::kBrowserAction, &browser_action_value)) {
2130 *error = ASCIIToUTF16(errors::kInvalidBrowserAction); 2133 *error = ASCIIToUTF16(errors::kInvalidBrowserAction);
2131 return false; 2134 return false;
2132 } 2135 }
2133 2136
2134 browser_action_ = LoadExtensionActionHelper(browser_action_value, error); 2137 browser_action_ = LoadExtensionActionHelper(browser_action_value, error);
2135 if (!browser_action_.get()) 2138 if (!browser_action_.get())
2136 return false; // Failed to parse browser action definition. 2139 return false; // Failed to parse browser action definition.
2137 declared_action_type_ = ExtensionAction::TYPE_BROWSER; 2140 declared_action_type_ = ExtensionAction::TYPE_BROWSER;
2138 return true; 2141 return true;
2139 } 2142 }
2140 2143
2141 void Extension::GenerateBrowserActionIfPossible() {
2142 // It only makes sense to generate brower actions for extensions that are
2143 // shown in chrome://extensions.
2144 if (!ShouldDisplayInExtensionSettings())
2145 return;
2146
2147 // Hosted and platform apps are shown in extension settings, but we don't
2148 // want to generate browser actions for those either, since they can't define
2149 // browser actions.
2150 if (is_app())
2151 return;
2152
2153 browser_action_.reset(new ExtensionAction(id()));
2154 browser_action_->SetTitle(ExtensionAction::kDefaultTabId, name());
2155 }
2156
2157 bool Extension::LoadFileBrowserHandlers(string16* error) { 2144 bool Extension::LoadFileBrowserHandlers(string16* error) {
2158 if (!manifest_->HasKey(keys::kFileBrowserHandlers)) 2145 if (!manifest_->HasKey(keys::kFileBrowserHandlers))
2159 return true; 2146 return true;
2160 ListValue* file_browser_handlers_value = NULL; 2147 ListValue* file_browser_handlers_value = NULL;
2161 if (!manifest_->GetList(keys::kFileBrowserHandlers, 2148 if (!manifest_->GetList(keys::kFileBrowserHandlers,
2162 &file_browser_handlers_value)) { 2149 &file_browser_handlers_value)) {
2163 *error = ASCIIToUTF16(errors::kInvalidFileBrowserHandler); 2150 *error = ASCIIToUTF16(errors::kInvalidFileBrowserHandler);
2164 return false; 2151 return false;
2165 } 2152 }
2166 file_browser_handlers_.reset( 2153 file_browser_handlers_.reset(
(...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after
2907 2894
2908 if (!LoadSharedFeatures(api_permissions, error)) 2895 if (!LoadSharedFeatures(api_permissions, error))
2909 return false; 2896 return false;
2910 2897
2911 if (!LoadExtensionFeatures(api_permissions, error)) 2898 if (!LoadExtensionFeatures(api_permissions, error))
2912 return false; 2899 return false;
2913 2900
2914 if (!LoadThemeFeatures(error)) 2901 if (!LoadThemeFeatures(error))
2915 return false; 2902 return false;
2916 2903
2917 if (CommandLine::ForCurrentProcess()->HasSwitch(
2918 switches::kEnableBrowserActionsForAll) &&
2919 !browser_action()) {
2920 GenerateBrowserActionIfPossible();
2921 }
2922
2923 if (HasMultipleUISurfaces()) { 2904 if (HasMultipleUISurfaces()) {
2924 *error = ASCIIToUTF16(errors::kOneUISurfaceOnly); 2905 *error = ASCIIToUTF16(errors::kOneUISurfaceOnly);
2925 return false; 2906 return false;
2926 } 2907 }
2927 2908
2928 runtime_data_.SetActivePermissions(new ExtensionPermissionSet( 2909 runtime_data_.SetActivePermissions(new ExtensionPermissionSet(
2929 this, api_permissions, host_permissions, oauth2_info_.GetScopesAsSet())); 2910 this, api_permissions, host_permissions, oauth2_info_.GetScopesAsSet()));
2930 required_permission_set_ = new ExtensionPermissionSet( 2911 required_permission_set_ = new ExtensionPermissionSet(
2931 this, api_permissions, host_permissions, oauth2_info_.GetScopesAsSet()); 2912 this, api_permissions, host_permissions, oauth2_info_.GetScopesAsSet());
2932 optional_permission_set_ = new ExtensionPermissionSet( 2913 optional_permission_set_ = new ExtensionPermissionSet(
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
3563 already_disabled(false), 3544 already_disabled(false),
3564 extension(extension) {} 3545 extension(extension) {}
3565 3546
3566 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( 3547 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo(
3567 const Extension* extension, 3548 const Extension* extension,
3568 const ExtensionPermissionSet* permissions, 3549 const ExtensionPermissionSet* permissions,
3569 Reason reason) 3550 Reason reason)
3570 : reason(reason), 3551 : reason(reason),
3571 extension(extension), 3552 extension(extension),
3572 permissions(permissions) {} 3553 permissions(permissions) {}
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698