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

Side by Side Diff: extensions/common/manifest_handlers/options_page_info.cc

Issue 1908953003: Convert //extensions/{common,shell} from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase? Created 4 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/common/manifest_handlers/options_page_info.h" 5 #include "extensions/common/manifest_handlers/options_page_info.h"
6 6
7 #include <memory>
8
7 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
8 #include "base/macros.h" 10 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/ptr_util.h"
10 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
11 #include "extensions/common/api/extensions_manifest_types.h" 13 #include "extensions/common/api/extensions_manifest_types.h"
12 #include "extensions/common/error_utils.h" 14 #include "extensions/common/error_utils.h"
13 #include "extensions/common/feature_switch.h" 15 #include "extensions/common/feature_switch.h"
14 #include "extensions/common/file_util.h" 16 #include "extensions/common/file_util.h"
15 #include "extensions/common/manifest_constants.h" 17 #include "extensions/common/manifest_constants.h"
16 #include "extensions/strings/grit/extensions_strings.h" 18 #include "extensions/strings/grit/extensions_strings.h"
17 #include "ui/base/l10n/l10n_util.h" 19 #include "ui/base/l10n/l10n_util.h"
18 20
19 using base::ASCIIToUTF16; 21 using base::ASCIIToUTF16;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 OptionsPageInfo* info = GetOptionsPageInfo(extension); 100 OptionsPageInfo* info = GetOptionsPageInfo(extension);
99 return info && info->chrome_styles_; 101 return info && info->chrome_styles_;
100 } 102 }
101 103
102 // static 104 // static
103 bool OptionsPageInfo::ShouldOpenInTab(const Extension* extension) { 105 bool OptionsPageInfo::ShouldOpenInTab(const Extension* extension) {
104 OptionsPageInfo* info = GetOptionsPageInfo(extension); 106 OptionsPageInfo* info = GetOptionsPageInfo(extension);
105 return info && info->open_in_tab_; 107 return info && info->open_in_tab_;
106 } 108 }
107 109
108 scoped_ptr<OptionsPageInfo> OptionsPageInfo::Create( 110 std::unique_ptr<OptionsPageInfo> OptionsPageInfo::Create(
109 Extension* extension, 111 Extension* extension,
110 const base::Value* options_ui_value, 112 const base::Value* options_ui_value,
111 const std::string& options_page_string, 113 const std::string& options_page_string,
112 std::vector<InstallWarning>* install_warnings, 114 std::vector<InstallWarning>* install_warnings,
113 base::string16* error) { 115 base::string16* error) {
114 GURL options_page; 116 GURL options_page;
115 // Chrome styling is always opt-in. 117 // Chrome styling is always opt-in.
116 bool chrome_style = false; 118 bool chrome_style = false;
117 // Extensions can opt in or out to opening in a tab, and users can choose via 119 // Extensions can opt in or out to opening in a tab, and users can choose via
118 // the --embedded-extension-options flag which should be the default. 120 // the --embedded-extension-options flag which should be the default.
119 bool open_in_tab = !FeatureSwitch::embedded_extension_options()->IsEnabled(); 121 bool open_in_tab = !FeatureSwitch::embedded_extension_options()->IsEnabled();
120 122
121 // Parse the options_ui object. 123 // Parse the options_ui object.
122 if (options_ui_value) { 124 if (options_ui_value) {
123 base::string16 options_ui_error; 125 base::string16 options_ui_error;
124 126
125 scoped_ptr<OptionsUI> options_ui = 127 std::unique_ptr<OptionsUI> options_ui =
126 OptionsUI::FromValue(*options_ui_value, &options_ui_error); 128 OptionsUI::FromValue(*options_ui_value, &options_ui_error);
127 if (!options_ui_error.empty()) { 129 if (!options_ui_error.empty()) {
128 // OptionsUI::FromValue populates |error| both when there are 130 // OptionsUI::FromValue populates |error| both when there are
129 // errors (in which case |options_ui| will be NULL) and warnings 131 // errors (in which case |options_ui| will be NULL) and warnings
130 // (in which case |options_ui| will be valid). Either way, show it 132 // (in which case |options_ui| will be valid). Either way, show it
131 // as an install warning. 133 // as an install warning.
132 install_warnings->push_back( 134 install_warnings->push_back(
133 InstallWarning(base::UTF16ToASCII(options_ui_error))); 135 InstallWarning(base::UTF16ToASCII(options_ui_error)));
134 } 136 }
135 137
(...skipping 16 matching lines...) Expand all
152 } 154 }
153 155
154 // Parse the legacy options_page entry if there was no entry for 156 // Parse the legacy options_page entry if there was no entry for
155 // options_ui.page. 157 // options_ui.page.
156 if (!options_page_string.empty() && !options_page.is_valid()) { 158 if (!options_page_string.empty() && !options_page.is_valid()) {
157 if (!ParseOptionsUrl(extension, 159 if (!ParseOptionsUrl(extension,
158 options_page_string, 160 options_page_string,
159 keys::kOptionsPage, 161 keys::kOptionsPage,
160 error, 162 error,
161 &options_page)) { 163 &options_page)) {
162 return scoped_ptr<OptionsPageInfo>(); 164 return std::unique_ptr<OptionsPageInfo>();
163 } 165 }
164 } 166 }
165 167
166 return make_scoped_ptr( 168 return base::WrapUnique(
167 new OptionsPageInfo(options_page, chrome_style, open_in_tab)); 169 new OptionsPageInfo(options_page, chrome_style, open_in_tab));
168 } 170 }
169 171
170 OptionsPageManifestHandler::OptionsPageManifestHandler() { 172 OptionsPageManifestHandler::OptionsPageManifestHandler() {
171 } 173 }
172 174
173 OptionsPageManifestHandler::~OptionsPageManifestHandler() { 175 OptionsPageManifestHandler::~OptionsPageManifestHandler() {
174 } 176 }
175 177
176 bool OptionsPageManifestHandler::Parse(Extension* extension, 178 bool OptionsPageManifestHandler::Parse(Extension* extension,
177 base::string16* error) { 179 base::string16* error) {
178 std::vector<InstallWarning> install_warnings; 180 std::vector<InstallWarning> install_warnings;
179 const Manifest* manifest = extension->manifest(); 181 const Manifest* manifest = extension->manifest();
180 182
181 std::string options_page_string; 183 std::string options_page_string;
182 if (manifest->HasPath(keys::kOptionsPage) && 184 if (manifest->HasPath(keys::kOptionsPage) &&
183 !manifest->GetString(keys::kOptionsPage, &options_page_string)) { 185 !manifest->GetString(keys::kOptionsPage, &options_page_string)) {
184 *error = ErrorUtils::FormatErrorMessageUTF16(errors::kInvalidOptionsPage, 186 *error = ErrorUtils::FormatErrorMessageUTF16(errors::kInvalidOptionsPage,
185 keys::kOptionsPage); 187 keys::kOptionsPage);
186 return false; 188 return false;
187 } 189 }
188 190
189 const base::Value* options_ui_value = NULL; 191 const base::Value* options_ui_value = NULL;
190 ignore_result(manifest->Get(keys::kOptionsUI, &options_ui_value)); 192 ignore_result(manifest->Get(keys::kOptionsUI, &options_ui_value));
191 193
192 scoped_ptr<OptionsPageInfo> info = 194 std::unique_ptr<OptionsPageInfo> info =
193 OptionsPageInfo::Create(extension, 195 OptionsPageInfo::Create(extension, options_ui_value, options_page_string,
194 options_ui_value, 196 &install_warnings, error);
195 options_page_string,
196 &install_warnings,
197 error);
198 if (!info) 197 if (!info)
199 return false; 198 return false;
200 199
201 extension->AddInstallWarnings(install_warnings); 200 extension->AddInstallWarnings(install_warnings);
202 extension->SetManifestData(keys::kOptionsUI, info.release()); 201 extension->SetManifestData(keys::kOptionsUI, info.release());
203 return true; 202 return true;
204 } 203 }
205 204
206 bool OptionsPageManifestHandler::Validate( 205 bool OptionsPageManifestHandler::Validate(
207 const Extension* extension, 206 const Extension* extension,
(...skipping 14 matching lines...) Expand all
222 } 221 }
223 return true; 222 return true;
224 } 223 }
225 224
226 const std::vector<std::string> OptionsPageManifestHandler::Keys() const { 225 const std::vector<std::string> OptionsPageManifestHandler::Keys() const {
227 static const char* keys[] = {keys::kOptionsPage, keys::kOptionsUI}; 226 static const char* keys[] = {keys::kOptionsPage, keys::kOptionsUI};
228 return std::vector<std::string>(keys, keys + arraysize(keys)); 227 return std::vector<std::string>(keys, keys + arraysize(keys));
229 } 228 }
230 229
231 } // namespace extensions 230 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/manifest_handlers/options_page_info.h ('k') | extensions/common/manifest_handlers/permissions_parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698