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

Side by Side Diff: extensions/browser/api/app_window/app_window_api.cc

Issue 850853002: Extensions: Consolidate extension id hashing / searching. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 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
« no previous file with comments | « components/crx_file/id_util.cc ('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 "extensions/browser/api/app_window/app_window_api.h" 5 #include "extensions/browser/api/app_window/app_window_api.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 create_spec->maximum_size.set_height(*input_spec->max_height); 121 create_spec->maximum_size.set_height(*input_spec->max_height);
122 } 122 }
123 123
124 } // namespace 124 } // namespace
125 125
126 AppWindowCreateFunction::AppWindowCreateFunction() 126 AppWindowCreateFunction::AppWindowCreateFunction()
127 : inject_html_titlebar_(false) {} 127 : inject_html_titlebar_(false) {}
128 128
129 bool AppWindowCreateFunction::RunAsync() { 129 bool AppWindowCreateFunction::RunAsync() {
130 // Don't create app window if the system is shutting down. 130 // Don't create app window if the system is shutting down.
131 if (extensions::ExtensionsBrowserClient::Get()->IsShuttingDown()) 131 if (ExtensionsBrowserClient::Get()->IsShuttingDown())
132 return false; 132 return false;
133 133
134 scoped_ptr<Create::Params> params(Create::Params::Create(*args_)); 134 scoped_ptr<Create::Params> params(Create::Params::Create(*args_));
135 EXTENSION_FUNCTION_VALIDATE(params.get()); 135 EXTENSION_FUNCTION_VALIDATE(params.get());
136 136
137 GURL url = extension()->GetResourceURL(params->url); 137 GURL url = extension()->GetResourceURL(params->url);
138 // Allow absolute URLs for component apps, otherwise prepend the extension 138 // Allow absolute URLs for component apps, otherwise prepend the extension
139 // path. 139 // path.
140 GURL absolute = GURL(params->url); 140 GURL absolute = GURL(params->url);
141 if (absolute.has_scheme()) { 141 if (absolute.has_scheme()) {
142 if (extension()->location() == extensions::Manifest::COMPONENT) { 142 if (extension()->location() == Manifest::COMPONENT) {
143 url = absolute; 143 url = absolute;
144 } else { 144 } else {
145 // Show error when url passed isn't local. 145 // Show error when url passed isn't local.
146 error_ = app_window_constants::kInvalidUrlParameter; 146 error_ = app_window_constants::kInvalidUrlParameter;
147 return false; 147 return false;
148 } 148 }
149 } 149 }
150 150
151 // TODO(jeremya): figure out a way to pass the opening WebContents through to 151 // TODO(jeremya): figure out a way to pass the opening WebContents through to
152 // AppWindow::Create so we can set the opener at create time rather than 152 // AppWindow::Create so we can set the opener at create time rather than
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 SendResponse(true); 201 SendResponse(true);
202 return true; 202 return true;
203 } 203 }
204 } 204 }
205 } 205 }
206 206
207 if (!GetBoundsSpec(*options, &create_params, &error_)) 207 if (!GetBoundsSpec(*options, &create_params, &error_))
208 return false; 208 return false;
209 209
210 if (!AppWindowClient::Get()->IsCurrentChannelOlderThanDev() || 210 if (!AppWindowClient::Get()->IsCurrentChannelOlderThanDev() ||
211 extension()->location() == extensions::Manifest::COMPONENT) { 211 extension()->location() == Manifest::COMPONENT) {
212 if (options->type == app_window::WINDOW_TYPE_PANEL) { 212 if (options->type == app_window::WINDOW_TYPE_PANEL) {
213 create_params.window_type = AppWindow::WINDOW_TYPE_PANEL; 213 create_params.window_type = AppWindow::WINDOW_TYPE_PANEL;
214 } 214 }
215 } 215 }
216 216
217 if (!GetFrameOptions(*options, &create_params)) 217 if (!GetFrameOptions(*options, &create_params))
218 return false; 218 return false;
219 219
220 if (extension()->GetType() == extensions::Manifest::TYPE_EXTENSION) { 220 if (extension()->GetType() == Manifest::TYPE_EXTENSION) {
221 // Whitelisted IME extensions are allowed to use this API to create IME 221 // Whitelisted IME extensions are allowed to use this API to create IME
222 // specific windows to show accented characters or suggestions. 222 // specific windows to show accented characters or suggestions.
223 if (!extension()->permissions_data()->HasAPIPermission( 223 if (!extension()->permissions_data()->HasAPIPermission(
224 APIPermission::kImeWindowEnabled)) { 224 APIPermission::kImeWindowEnabled)) {
225 error_ = app_window_constants::kImeWindowMissingPermission; 225 error_ = app_window_constants::kImeWindowMissingPermission;
226 return false; 226 return false;
227 } 227 }
228 228
229 #if !defined(OS_CHROMEOS) 229 #if !defined(OS_CHROMEOS)
230 // IME window is only supported on ChromeOS. 230 // IME window is only supported on ChromeOS.
231 error_ = app_window_constants::kImeWindowUnsupportedPlatform; 231 error_ = app_window_constants::kImeWindowUnsupportedPlatform;
232 return false; 232 return false;
233 #else 233 #else
234 // IME extensions must create window with "ime: true" and "frame: none". 234 // IME extensions must create window with "ime: true" and "frame: none".
235 if (!options->ime.get() || !*options->ime.get() || 235 if (!options->ime.get() || !*options->ime.get() ||
236 create_params.frame != AppWindow::FRAME_NONE) { 236 create_params.frame != AppWindow::FRAME_NONE) {
237 error_ = app_window_constants::kImeOptionMustBeTrueAndNeedsFrameNone; 237 error_ = app_window_constants::kImeOptionMustBeTrueAndNeedsFrameNone;
238 return false; 238 return false;
239 } 239 }
240 create_params.is_ime_window = true; 240 create_params.is_ime_window = true;
241 #endif // OS_CHROMEOS 241 #endif // OS_CHROMEOS
242 } else { 242 } else {
243 if (options->ime.get()) { 243 if (options->ime.get()) {
244 error_ = app_window_constants::kImeOptionIsNotSupported; 244 error_ = app_window_constants::kImeOptionIsNotSupported;
245 return false; 245 return false;
246 } 246 }
247 } 247 }
248 248
249 if (options->alpha_enabled.get()) { 249 if (options->alpha_enabled.get()) {
250 const char* whitelist[] = { 250 const char* const kWhitelist[] = {
251 #if defined(OS_CHROMEOS) 251 #if defined(OS_CHROMEOS)
252 "B58B99751225318C7EB8CF4688B5434661083E07", // http://crbug.com/410550 252 "B58B99751225318C7EB8CF4688B5434661083E07", // http://crbug.com/410550
253 "06BE211D5F014BAB34BC22D9DDA09C63A81D828E", // http://crbug.com/425539 253 "06BE211D5F014BAB34BC22D9DDA09C63A81D828E", // http://crbug.com/425539
254 "F94EE6AB36D6C6588670B2B01EB65212D9C64E33", 254 "F94EE6AB36D6C6588670B2B01EB65212D9C64E33",
255 "B9EF10DDFEA11EF77873CC5009809E5037FC4C7A", // http://crbug.com/435380 255 "B9EF10DDFEA11EF77873CC5009809E5037FC4C7A", // http://crbug.com/435380
256 #endif 256 #endif
257 "0F42756099D914A026DADFA182871C015735DD95", // http://crbug.com/323773 257 "0F42756099D914A026DADFA182871C015735DD95", // http://crbug.com/323773
258 "2D22CDB6583FD0A13758AEBE8B15E45208B4E9A7", 258 "2D22CDB6583FD0A13758AEBE8B15E45208B4E9A7",
259 "E7E2461CE072DF036CF9592740196159E2D7C089", // http://crbug.com/356200 259 "E7E2461CE072DF036CF9592740196159E2D7C089", // http://crbug.com/356200
260 "A74A4D44C7CFCD8844830E6140C8D763E12DD8F3", 260 "A74A4D44C7CFCD8844830E6140C8D763E12DD8F3",
261 "312745D9BF916161191143F6490085EEA0434997", 261 "312745D9BF916161191143F6490085EEA0434997",
262 "53041A2FA309EECED01FFC751E7399186E860B2C", 262 "53041A2FA309EECED01FFC751E7399186E860B2C",
263 "A07A5B743CD82A1C2579DB77D353C98A23201EEF", // http://crbug.com/413748 263 "A07A5B743CD82A1C2579DB77D353C98A23201EEF", // http://crbug.com/413748
264 "F16F23C83C5F6DAD9B65A120448B34056DD80691", 264 "F16F23C83C5F6DAD9B65A120448B34056DD80691",
265 "0F585FB1D0FDFBEBCE1FEB5E9DFFB6DA476B8C9B" 265 "0F585FB1D0FDFBEBCE1FEB5E9DFFB6DA476B8C9B"
266 }; 266 };
267 if (AppWindowClient::Get()->IsCurrentChannelOlderThanDev() && 267 if (AppWindowClient::Get()->IsCurrentChannelOlderThanDev() &&
268 !extensions::SimpleFeature::IsIdInList( 268 !SimpleFeature::IsIdInList(
269 extension_id(), 269 extension_id(),
270 std::set<std::string>(whitelist, 270 std::set<std::string>(kWhitelist,
271 whitelist + arraysize(whitelist)))) { 271 kWhitelist + arraysize(kWhitelist)))) {
272 error_ = app_window_constants::kAlphaEnabledWrongChannel; 272 error_ = app_window_constants::kAlphaEnabledWrongChannel;
273 return false; 273 return false;
274 } 274 }
275 if (!extension()->permissions_data()->HasAPIPermission( 275 if (!extension()->permissions_data()->HasAPIPermission(
276 APIPermission::kAlphaEnabled)) { 276 APIPermission::kAlphaEnabled)) {
277 error_ = app_window_constants::kAlphaEnabledMissingPermission; 277 error_ = app_window_constants::kAlphaEnabledMissingPermission;
278 return false; 278 return false;
279 } 279 }
280 if (create_params.frame != AppWindow::FRAME_NONE) { 280 if (create_params.frame != AppWindow::FRAME_NONE) {
281 error_ = app_window_constants::kAlphaEnabledNeedsFrameNone; 281 error_ = app_window_constants::kAlphaEnabledNeedsFrameNone;
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 488
489 AppWindow::Frame AppWindowCreateFunction::GetFrameFromString( 489 AppWindow::Frame AppWindowCreateFunction::GetFrameFromString(
490 const std::string& frame_string) { 490 const std::string& frame_string) {
491 if (frame_string == kHtmlFrameOption && 491 if (frame_string == kHtmlFrameOption &&
492 (extension()->permissions_data()->HasAPIPermission( 492 (extension()->permissions_data()->HasAPIPermission(
493 APIPermission::kExperimental) || 493 APIPermission::kExperimental) ||
494 base::CommandLine::ForCurrentProcess()->HasSwitch( 494 base::CommandLine::ForCurrentProcess()->HasSwitch(
495 switches::kEnableExperimentalExtensionApis))) { 495 switches::kEnableExperimentalExtensionApis))) {
496 inject_html_titlebar_ = true; 496 inject_html_titlebar_ = true;
497 return AppWindow::FRAME_NONE; 497 return AppWindow::FRAME_NONE;
498 } 498 }
499 499
500 if (frame_string == kNoneFrameOption) 500 if (frame_string == kNoneFrameOption)
501 return AppWindow::FRAME_NONE; 501 return AppWindow::FRAME_NONE;
502 502
503 return AppWindow::FRAME_CHROME; 503 return AppWindow::FRAME_CHROME;
504 } 504 }
505 505
506 bool AppWindowCreateFunction::GetFrameOptions( 506 bool AppWindowCreateFunction::GetFrameOptions(
507 const app_window::CreateWindowOptions& options, 507 const app_window::CreateWindowOptions& options,
508 AppWindow::CreateParams* create_params) { 508 AppWindow::CreateParams* create_params) {
509 if (!options.frame) 509 if (!options.frame)
510 return true; 510 return true;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 549
550 if (options.frame->as_frame_options->inactive_color.get()) { 550 if (options.frame->as_frame_options->inactive_color.get()) {
551 error_ = app_window_constants::kInactiveColorWithoutColor; 551 error_ = app_window_constants::kInactiveColorWithoutColor;
552 return false; 552 return false;
553 } 553 }
554 554
555 return true; 555 return true;
556 } 556 }
557 557
558 } // namespace extensions 558 } // namespace extensions
OLDNEW
« no previous file with comments | « components/crx_file/id_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698