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 "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" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "content/public/browser/notification_registrar.h" | 12 #include "content/public/browser/notification_registrar.h" |
13 #include "content/public/browser/notification_types.h" | 13 #include "content/public/browser/notification_types.h" |
14 #include "content/public/browser/render_process_host.h" | 14 #include "content/public/browser/render_process_host.h" |
15 #include "content/public/browser/render_view_host.h" | 15 #include "content/public/browser/render_view_host.h" |
16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
17 #include "content/public/common/url_constants.h" | 17 #include "content/public/common/url_constants.h" |
18 #include "extensions/browser/app_window/app_window.h" | 18 #include "extensions/browser/app_window/app_window.h" |
19 #include "extensions/browser/app_window/app_window_client.h" | 19 #include "extensions/browser/app_window/app_window_client.h" |
20 #include "extensions/browser/app_window/app_window_contents.h" | 20 #include "extensions/browser/app_window/app_window_contents.h" |
21 #include "extensions/browser/app_window/app_window_registry.h" | 21 #include "extensions/browser/app_window/app_window_registry.h" |
22 #include "extensions/browser/app_window/native_app_window.h" | |
23 #include "extensions/browser/extensions_browser_client.h" | 22 #include "extensions/browser/extensions_browser_client.h" |
24 #include "extensions/browser/image_util.h" | 23 #include "extensions/browser/image_util.h" |
25 #include "extensions/common/api/app_window.h" | 24 #include "extensions/common/api/app_window.h" |
26 #include "extensions/common/features/simple_feature.h" | 25 #include "extensions/common/features/simple_feature.h" |
27 #include "extensions/common/manifest.h" | 26 #include "extensions/common/manifest.h" |
28 #include "extensions/common/permissions/permissions_data.h" | 27 #include "extensions/common/permissions/permissions_data.h" |
29 #include "extensions/common/switches.h" | 28 #include "extensions/common/switches.h" |
30 #include "third_party/skia/include/core/SkColor.h" | 29 #include "third_party/skia/include/core/SkColor.h" |
31 #include "ui/base/ui_base_types.h" | 30 #include "ui/base/ui_base_types.h" |
32 #include "ui/gfx/rect.h" | 31 #include "ui/gfx/rect.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 subst.push_back(property_name); | 89 subst.push_back(property_name); |
91 *error = ReplaceStringPlaceholders( | 90 *error = ReplaceStringPlaceholders( |
92 app_window_constants::kConflictingBoundsOptions, subst, NULL); | 91 app_window_constants::kConflictingBoundsOptions, subst, NULL); |
93 return false; | 92 return false; |
94 } | 93 } |
95 | 94 |
96 return true; | 95 return true; |
97 } | 96 } |
98 | 97 |
99 // Copy over the bounds specification properties from the API to the | 98 // Copy over the bounds specification properties from the API to the |
100 // AppWindow::CreateParams. | 99 // native_app_window::CreateParams. |
101 void CopyBoundsSpec(const app_window::BoundsSpecification* input_spec, | 100 void CopyBoundsSpec(const app_window::BoundsSpecification* input_spec, |
102 AppWindow::BoundsSpecification* create_spec) { | 101 native_app_window::BoundsSpecification* create_spec) { |
103 if (!input_spec) | 102 if (!input_spec) |
104 return; | 103 return; |
105 | 104 |
106 if (input_spec->left.get()) | 105 if (input_spec->left.get()) |
107 create_spec->bounds.set_x(*input_spec->left); | 106 create_spec->bounds.set_x(*input_spec->left); |
108 if (input_spec->top.get()) | 107 if (input_spec->top.get()) |
109 create_spec->bounds.set_y(*input_spec->top); | 108 create_spec->bounds.set_y(*input_spec->top); |
110 if (input_spec->width.get()) | 109 if (input_spec->width.get()) |
111 create_spec->bounds.set_width(*input_spec->width); | 110 create_spec->bounds.set_width(*input_spec->width); |
112 if (input_spec->height.get()) | 111 if (input_spec->height.get()) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 } else { | 143 } else { |
145 // Show error when url passed isn't local. | 144 // Show error when url passed isn't local. |
146 error_ = app_window_constants::kInvalidUrlParameter; | 145 error_ = app_window_constants::kInvalidUrlParameter; |
147 return false; | 146 return false; |
148 } | 147 } |
149 } | 148 } |
150 | 149 |
151 // TODO(jeremya): figure out a way to pass the opening WebContents through to | 150 // 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 | 151 // AppWindow::Create so we can set the opener at create time rather than |
153 // with a hack in AppWindowCustomBindings::GetView(). | 152 // with a hack in AppWindowCustomBindings::GetView(). |
154 AppWindow::CreateParams create_params; | 153 native_app_window::AppWindowCreateParams create_params; |
155 app_window::CreateWindowOptions* options = params->options.get(); | 154 app_window::CreateWindowOptions* options = params->options.get(); |
156 if (options) { | 155 if (options) { |
157 if (options->id.get()) { | 156 if (options->id.get()) { |
158 // TODO(mek): use URL if no id specified? | 157 // TODO(mek): use URL if no id specified? |
159 // Limit length of id to 256 characters. | 158 // Limit length of id to 256 characters. |
160 if (options->id->length() > 256) { | 159 if (options->id->length() > 256) { |
161 error_ = app_window_constants::kInvalidWindowId; | 160 error_ = app_window_constants::kInvalidWindowId; |
162 return false; | 161 return false; |
163 } | 162 } |
164 | 163 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 } | 202 } |
204 } | 203 } |
205 } | 204 } |
206 | 205 |
207 if (!GetBoundsSpec(*options, &create_params, &error_)) | 206 if (!GetBoundsSpec(*options, &create_params, &error_)) |
208 return false; | 207 return false; |
209 | 208 |
210 if (!AppWindowClient::Get()->IsCurrentChannelOlderThanDev() || | 209 if (!AppWindowClient::Get()->IsCurrentChannelOlderThanDev() || |
211 extension()->location() == extensions::Manifest::COMPONENT) { | 210 extension()->location() == extensions::Manifest::COMPONENT) { |
212 if (options->type == app_window::WINDOW_TYPE_PANEL) { | 211 if (options->type == app_window::WINDOW_TYPE_PANEL) { |
213 create_params.window_type = AppWindow::WINDOW_TYPE_PANEL; | 212 create_params.window_type = native_app_window::WINDOW_TYPE_PANEL; |
214 } | 213 } |
215 } | 214 } |
216 | 215 |
217 if (!GetFrameOptions(*options, &create_params)) | 216 if (!GetFrameOptions(*options, &create_params)) |
218 return false; | 217 return false; |
219 | 218 |
220 if (extension()->GetType() == extensions::Manifest::TYPE_EXTENSION) { | 219 if (extension()->GetType() == extensions::Manifest::TYPE_EXTENSION) { |
221 // Whitelisted IME extensions are allowed to use this API to create IME | 220 // Whitelisted IME extensions are allowed to use this API to create IME |
222 // specific windows to show accented characters or suggestions. | 221 // specific windows to show accented characters or suggestions. |
223 if (!extension()->permissions_data()->HasAPIPermission( | 222 if (!extension()->permissions_data()->HasAPIPermission( |
224 APIPermission::kImeWindowEnabled)) { | 223 APIPermission::kImeWindowEnabled)) { |
225 error_ = app_window_constants::kImeWindowMissingPermission; | 224 error_ = app_window_constants::kImeWindowMissingPermission; |
226 return false; | 225 return false; |
227 } | 226 } |
228 | 227 |
229 #if !defined(OS_CHROMEOS) | 228 #if !defined(OS_CHROMEOS) |
230 // IME window is only supported on ChromeOS. | 229 // IME window is only supported on ChromeOS. |
231 error_ = app_window_constants::kImeWindowUnsupportedPlatform; | 230 error_ = app_window_constants::kImeWindowUnsupportedPlatform; |
232 return false; | 231 return false; |
233 #else | 232 #else |
234 // IME extensions must create window with "ime: true" and "frame: none". | 233 // IME extensions must create window with "ime: true" and "frame: none". |
235 if (!options->ime.get() || !*options->ime.get() || | 234 if (!options->ime.get() || !*options->ime.get() || |
236 create_params.frame != AppWindow::FRAME_NONE) { | 235 create_params.frame != native_app_window::FRAME_NONE) { |
237 error_ = app_window_constants::kImeOptionMustBeTrueAndNeedsFrameNone; | 236 error_ = app_window_constants::kImeOptionMustBeTrueAndNeedsFrameNone; |
238 return false; | 237 return false; |
239 } | 238 } |
240 create_params.is_ime_window = true; | 239 create_params.is_ime_window = true; |
241 #endif // OS_CHROMEOS | 240 #endif // OS_CHROMEOS |
242 } else { | 241 } else { |
243 if (options->ime.get()) { | 242 if (options->ime.get()) { |
244 error_ = app_window_constants::kImeOptionIsNotSupported; | 243 error_ = app_window_constants::kImeOptionIsNotSupported; |
245 return false; | 244 return false; |
246 } | 245 } |
(...skipping 20 matching lines...) Expand all Loading... |
267 std::set<std::string>(whitelist, | 266 std::set<std::string>(whitelist, |
268 whitelist + arraysize(whitelist)))) { | 267 whitelist + arraysize(whitelist)))) { |
269 error_ = app_window_constants::kAlphaEnabledWrongChannel; | 268 error_ = app_window_constants::kAlphaEnabledWrongChannel; |
270 return false; | 269 return false; |
271 } | 270 } |
272 if (!extension()->permissions_data()->HasAPIPermission( | 271 if (!extension()->permissions_data()->HasAPIPermission( |
273 APIPermission::kAlphaEnabled)) { | 272 APIPermission::kAlphaEnabled)) { |
274 error_ = app_window_constants::kAlphaEnabledMissingPermission; | 273 error_ = app_window_constants::kAlphaEnabledMissingPermission; |
275 return false; | 274 return false; |
276 } | 275 } |
277 if (create_params.frame != AppWindow::FRAME_NONE) { | 276 if (create_params.frame != native_app_window::FRAME_NONE) { |
278 error_ = app_window_constants::kAlphaEnabledNeedsFrameNone; | 277 error_ = app_window_constants::kAlphaEnabledNeedsFrameNone; |
279 return false; | 278 return false; |
280 } | 279 } |
281 #if defined(USE_AURA) | 280 #if defined(USE_AURA) |
282 create_params.alpha_enabled = *options->alpha_enabled; | 281 create_params.alpha_enabled = *options->alpha_enabled; |
283 #else | 282 #else |
284 // Transparency is only supported on Aura. | 283 // Transparency is only supported on Aura. |
285 // Fallback to creating an opaque window (by ignoring alphaEnabled). | 284 // Fallback to creating an opaque window (by ignoring alphaEnabled). |
286 #endif | 285 #endif |
287 } | 286 } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 } | 365 } |
367 | 366 |
368 SendResponse(true); | 367 SendResponse(true); |
369 app_window->WindowEventsReady(); | 368 app_window->WindowEventsReady(); |
370 | 369 |
371 return true; | 370 return true; |
372 } | 371 } |
373 | 372 |
374 bool AppWindowCreateFunction::GetBoundsSpec( | 373 bool AppWindowCreateFunction::GetBoundsSpec( |
375 const app_window::CreateWindowOptions& options, | 374 const app_window::CreateWindowOptions& options, |
376 AppWindow::CreateParams* params, | 375 native_app_window::AppWindowCreateParams* params, |
377 std::string* error) { | 376 std::string* error) { |
378 DCHECK(params); | 377 DCHECK(params); |
379 DCHECK(error); | 378 DCHECK(error); |
380 | 379 |
381 if (options.inner_bounds.get() || options.outer_bounds.get()) { | 380 if (options.inner_bounds.get() || options.outer_bounds.get()) { |
382 // Parse the inner and outer bounds specifications. If developers use the | 381 // Parse the inner and outer bounds specifications. If developers use the |
383 // new API, the deprecated fields will be ignored - do not attempt to merge | 382 // new API, the deprecated fields will be ignored - do not attempt to merge |
384 // them. | 383 // them. |
385 | 384 |
386 const app_window::BoundsSpecification* inner_bounds = | 385 const app_window::BoundsSpecification* inner_bounds = |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 "maxHeight", | 426 "maxHeight", |
428 error)) { | 427 error)) { |
429 return false; | 428 return false; |
430 } | 429 } |
431 } | 430 } |
432 | 431 |
433 CopyBoundsSpec(inner_bounds, &(params->content_spec)); | 432 CopyBoundsSpec(inner_bounds, &(params->content_spec)); |
434 CopyBoundsSpec(outer_bounds, &(params->window_spec)); | 433 CopyBoundsSpec(outer_bounds, &(params->window_spec)); |
435 } else { | 434 } else { |
436 // Parse deprecated fields. | 435 // Parse deprecated fields. |
437 // Due to a bug in NativeAppWindow::GetFrameInsets() on Windows and ChromeOS | 436 // Due to a bug in Nativenative_app_window::GetFrameInsets() on Windows and |
| 437 // ChromeOS |
438 // the bounds set the position of the window and the size of the content. | 438 // the bounds set the position of the window and the size of the content. |
439 // This will be preserved as apps may be relying on this behavior. | 439 // This will be preserved as apps may be relying on this behavior. |
440 | 440 |
441 if (options.default_width.get()) | 441 if (options.default_width.get()) |
442 params->content_spec.bounds.set_width(*options.default_width.get()); | 442 params->content_spec.bounds.set_width(*options.default_width.get()); |
443 if (options.default_height.get()) | 443 if (options.default_height.get()) |
444 params->content_spec.bounds.set_height(*options.default_height.get()); | 444 params->content_spec.bounds.set_height(*options.default_height.get()); |
445 if (options.default_left.get()) | 445 if (options.default_left.get()) |
446 params->window_spec.bounds.set_x(*options.default_left.get()); | 446 params->window_spec.bounds.set_x(*options.default_left.get()); |
447 if (options.default_top.get()) | 447 if (options.default_top.get()) |
(...skipping 28 matching lines...) Expand all Loading... |
476 gfx::Size& maximum_size = params->content_spec.maximum_size; | 476 gfx::Size& maximum_size = params->content_spec.maximum_size; |
477 if (options.max_width.get()) | 477 if (options.max_width.get()) |
478 maximum_size.set_width(*options.max_width); | 478 maximum_size.set_width(*options.max_width); |
479 if (options.max_height.get()) | 479 if (options.max_height.get()) |
480 maximum_size.set_height(*options.max_height); | 480 maximum_size.set_height(*options.max_height); |
481 } | 481 } |
482 | 482 |
483 return true; | 483 return true; |
484 } | 484 } |
485 | 485 |
486 AppWindow::Frame AppWindowCreateFunction::GetFrameFromString( | 486 native_app_window::Frame AppWindowCreateFunction::GetFrameFromString( |
487 const std::string& frame_string) { | 487 const std::string& frame_string) { |
488 if (frame_string == kHtmlFrameOption && | 488 if (frame_string == kHtmlFrameOption && |
489 (extension()->permissions_data()->HasAPIPermission( | 489 (extension()->permissions_data()->HasAPIPermission( |
490 APIPermission::kExperimental) || | 490 APIPermission::kExperimental) || |
491 CommandLine::ForCurrentProcess()->HasSwitch( | 491 CommandLine::ForCurrentProcess()->HasSwitch( |
492 switches::kEnableExperimentalExtensionApis))) { | 492 switches::kEnableExperimentalExtensionApis))) { |
493 inject_html_titlebar_ = true; | 493 inject_html_titlebar_ = true; |
494 return AppWindow::FRAME_NONE; | 494 return native_app_window::FRAME_NONE; |
495 } | 495 } |
496 | 496 |
497 if (frame_string == kNoneFrameOption) | 497 if (frame_string == kNoneFrameOption) |
498 return AppWindow::FRAME_NONE; | 498 return native_app_window::FRAME_NONE; |
499 | 499 |
500 return AppWindow::FRAME_CHROME; | 500 return native_app_window::FRAME_CHROME; |
501 } | 501 } |
502 | 502 |
503 bool AppWindowCreateFunction::GetFrameOptions( | 503 bool AppWindowCreateFunction::GetFrameOptions( |
504 const app_window::CreateWindowOptions& options, | 504 const app_window::CreateWindowOptions& options, |
505 AppWindow::CreateParams* create_params) { | 505 native_app_window::AppWindowCreateParams* create_params) { |
506 if (!options.frame) | 506 if (!options.frame) |
507 return true; | 507 return true; |
508 | 508 |
509 DCHECK(options.frame->as_string || options.frame->as_frame_options); | 509 DCHECK(options.frame->as_string || options.frame->as_frame_options); |
510 if (options.frame->as_string) { | 510 if (options.frame->as_string) { |
511 create_params->frame = GetFrameFromString(*options.frame->as_string); | 511 create_params->frame = GetFrameFromString(*options.frame->as_string); |
512 return true; | 512 return true; |
513 } | 513 } |
514 | 514 |
515 if (options.frame->as_frame_options->type) | 515 if (options.frame->as_frame_options->type) |
516 create_params->frame = | 516 create_params->frame = |
517 GetFrameFromString(*options.frame->as_frame_options->type); | 517 GetFrameFromString(*options.frame->as_frame_options->type); |
518 | 518 |
519 if (options.frame->as_frame_options->color.get()) { | 519 if (options.frame->as_frame_options->color.get()) { |
520 if (create_params->frame != AppWindow::FRAME_CHROME) { | 520 if (create_params->frame != native_app_window::FRAME_CHROME) { |
521 error_ = app_window_constants::kColorWithFrameNone; | 521 error_ = app_window_constants::kColorWithFrameNone; |
522 return false; | 522 return false; |
523 } | 523 } |
524 | 524 |
525 if (!image_util::ParseCSSColorString( | 525 if (!image_util::ParseCSSColorString( |
526 *options.frame->as_frame_options->color, | 526 *options.frame->as_frame_options->color, |
527 &create_params->active_frame_color)) { | 527 &create_params->active_frame_color)) { |
528 error_ = app_window_constants::kInvalidColorSpecification; | 528 error_ = app_window_constants::kInvalidColorSpecification; |
529 return false; | 529 return false; |
530 } | 530 } |
(...skipping 15 matching lines...) Expand all Loading... |
546 | 546 |
547 if (options.frame->as_frame_options->inactive_color.get()) { | 547 if (options.frame->as_frame_options->inactive_color.get()) { |
548 error_ = app_window_constants::kInactiveColorWithoutColor; | 548 error_ = app_window_constants::kInactiveColorWithoutColor; |
549 return false; | 549 return false; |
550 } | 550 } |
551 | 551 |
552 return true; | 552 return true; |
553 } | 553 } |
554 | 554 |
555 } // namespace extensions | 555 } // namespace extensions |
OLD | NEW |