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 "chrome/browser/extensions/api/app_window/app_window_api.h" | 5 #include "chrome/browser/extensions/api/app_window/app_window_api.h" |
6 | 6 |
7 #include "apps/app_window.h" | 7 #include "apps/app_window.h" |
8 #include "apps/app_window_contents.h" | 8 #include "apps/app_window_contents.h" |
9 #include "apps/app_window_registry.h" | 9 #include "apps/app_window_registry.h" |
10 #include "apps/ui/apps_client.h" | 10 #include "apps/ui/apps_client.h" |
11 #include "apps/ui/native_app_window.h" | 11 #include "apps/ui/native_app_window.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "base/values.h" | 16 #include "base/values.h" |
17 #include "chrome/browser/devtools/devtools_window.h" | 17 #include "chrome/browser/devtools/devtools_window.h" |
18 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
19 #include "chrome/common/extensions/api/app_window.h" | 19 #include "chrome/common/extensions/api/app_window.h" |
20 #include "chrome/common/extensions/features/feature_channel.h" | 20 #include "chrome/common/extensions/features/feature_channel.h" |
21 #include "content/public/browser/notification_registrar.h" | 21 #include "content/public/browser/notification_registrar.h" |
22 #include "content/public/browser/notification_types.h" | 22 #include "content/public/browser/notification_types.h" |
23 #include "content/public/browser/render_process_host.h" | 23 #include "content/public/browser/render_process_host.h" |
24 #include "content/public/browser/render_view_host.h" | 24 #include "content/public/browser/render_view_host.h" |
25 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
26 #include "content/public/common/url_constants.h" | 26 #include "content/public/common/url_constants.h" |
27 #include "extensions/browser/extensions_browser_client.h" | 27 #include "extensions/browser/extensions_browser_client.h" |
28 #include "extensions/browser/image_util.h" | 28 #include "extensions/browser/image_util.h" |
| 29 #include "extensions/common/features/simple_feature.h" |
29 #include "extensions/common/permissions/permissions_data.h" | 30 #include "extensions/common/permissions/permissions_data.h" |
30 #include "extensions/common/switches.h" | 31 #include "extensions/common/switches.h" |
31 #include "third_party/skia/include/core/SkColor.h" | 32 #include "third_party/skia/include/core/SkColor.h" |
32 #include "ui/base/ui_base_types.h" | 33 #include "ui/base/ui_base_types.h" |
33 #include "ui/gfx/rect.h" | 34 #include "ui/gfx/rect.h" |
34 #include "url/gurl.h" | 35 #include "url/gurl.h" |
35 | 36 |
36 using apps::AppWindow; | 37 using apps::AppWindow; |
37 | 38 |
38 namespace app_window = extensions::api::app_window; | 39 namespace app_window = extensions::api::app_window; |
39 namespace Create = app_window::Create; | 40 namespace Create = app_window::Create; |
40 | 41 |
41 namespace extensions { | 42 namespace extensions { |
42 | 43 |
43 namespace app_window_constants { | 44 namespace app_window_constants { |
44 const char kInvalidWindowId[] = | 45 const char kInvalidWindowId[] = |
45 "The window id can not be more than 256 characters long."; | 46 "The window id can not be more than 256 characters long."; |
46 const char kInvalidColorSpecification[] = | 47 const char kInvalidColorSpecification[] = |
47 "The color specification could not be parsed."; | 48 "The color specification could not be parsed."; |
48 const char kColorWithFrameNone[] = "Windows with no frame cannot have a color."; | 49 const char kColorWithFrameNone[] = "Windows with no frame cannot have a color."; |
49 const char kInactiveColorWithoutColor[] = | 50 const char kInactiveColorWithoutColor[] = |
50 "frame.inactiveColor must be used with frame.color."; | 51 "frame.inactiveColor must be used with frame.color."; |
51 const char kConflictingBoundsOptions[] = | 52 const char kConflictingBoundsOptions[] = |
52 "The $1 property cannot be specified for both inner and outer bounds."; | 53 "The $1 property cannot be specified for both inner and outer bounds."; |
53 const char kAlwaysOnTopPermission[] = | 54 const char kAlwaysOnTopPermission[] = |
54 "The \"app.window.alwaysOnTop\" permission is required."; | 55 "The \"app.window.alwaysOnTop\" permission is required."; |
55 const char kInvalidUrlParameter[] = | 56 const char kInvalidUrlParameter[] = |
56 "The URL used for window creation must be local for security reasons."; | 57 "The URL used for window creation must be local for security reasons."; |
| 58 const char kAlphaEnabledWrongChannel[] = |
| 59 "The alphaEnabled option requires dev channel or newer."; |
| 60 const char kAlphaEnabledMissingPermission[] = |
| 61 "The alphaEnabled option requires app.window.alpha permission."; |
57 } // namespace app_window_constants | 62 } // namespace app_window_constants |
58 | 63 |
59 const char kNoneFrameOption[] = "none"; | 64 const char kNoneFrameOption[] = "none"; |
60 // TODO(benwells): Remove HTML titlebar injection. | 65 // TODO(benwells): Remove HTML titlebar injection. |
61 const char kHtmlFrameOption[] = "experimental-html"; | 66 const char kHtmlFrameOption[] = "experimental-html"; |
62 | 67 |
63 namespace { | 68 namespace { |
64 | 69 |
65 // Opens an inspector window and delays the response to the | 70 // Opens an inspector window and delays the response to the |
66 // AppWindowCreateFunction until the DevToolsWindow has finished loading, and is | 71 // AppWindowCreateFunction until the DevToolsWindow has finished loading, and is |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 if (GetCurrentChannel() <= chrome::VersionInfo::CHANNEL_DEV || | 232 if (GetCurrentChannel() <= chrome::VersionInfo::CHANNEL_DEV || |
228 extension()->location() == extensions::Manifest::COMPONENT) { | 233 extension()->location() == extensions::Manifest::COMPONENT) { |
229 if (options->type == extensions::api::app_window::WINDOW_TYPE_PANEL) { | 234 if (options->type == extensions::api::app_window::WINDOW_TYPE_PANEL) { |
230 create_params.window_type = AppWindow::WINDOW_TYPE_PANEL; | 235 create_params.window_type = AppWindow::WINDOW_TYPE_PANEL; |
231 } | 236 } |
232 } | 237 } |
233 | 238 |
234 if (!GetFrameOptions(*options, &create_params)) | 239 if (!GetFrameOptions(*options, &create_params)) |
235 return false; | 240 return false; |
236 | 241 |
237 if (options->transparent_background.get() && | 242 if (options->alpha_enabled.get()) { |
238 (extension()->permissions_data()->HasAPIPermission( | 243 const char* whitelist[] = { |
239 APIPermission::kExperimental) || | 244 "0F42756099D914A026DADFA182871C015735DD95", // http://crbug.com/323773 |
240 CommandLine::ForCurrentProcess()->HasSwitch( | 245 "2D22CDB6583FD0A13758AEBE8B15E45208B4E9A7", |
241 switches::kEnableExperimentalExtensionApis))) { | 246 "E7E2461CE072DF036CF9592740196159E2D7C089", // http://crbug.com/356200 |
242 create_params.transparent_background = *options->transparent_background; | 247 "A74A4D44C7CFCD8844830E6140C8D763E12DD8F3", |
| 248 "312745D9BF916161191143F6490085EEA0434997", |
| 249 "53041A2FA309EECED01FFC751E7399186E860B2C" |
| 250 }; |
| 251 if (GetCurrentChannel() > chrome::VersionInfo::CHANNEL_DEV && |
| 252 !extensions::SimpleFeature::IsIdInList( |
| 253 extension_id(), |
| 254 std::set<std::string>(whitelist, |
| 255 whitelist + arraysize(whitelist)))) { |
| 256 error_ = app_window_constants::kAlphaEnabledWrongChannel; |
| 257 return false; |
| 258 } |
| 259 if (!extension()->permissions_data()->HasAPIPermission( |
| 260 APIPermission::kAlphaEnabled)) { |
| 261 error_ = app_window_constants::kAlphaEnabledMissingPermission; |
| 262 return false; |
| 263 } |
| 264 #if defined(USE_AURA) |
| 265 create_params.alpha_enabled = *options->alpha_enabled; |
| 266 #else |
| 267 // Transparency is only supported on Aura. |
| 268 // Fallback to creating an opaque window (by ignoring alphaEnabled). |
| 269 #endif |
243 } | 270 } |
244 | 271 |
245 if (options->hidden.get()) | 272 if (options->hidden.get()) |
246 create_params.hidden = *options->hidden.get(); | 273 create_params.hidden = *options->hidden.get(); |
247 | 274 |
248 if (options->resizable.get()) | 275 if (options->resizable.get()) |
249 create_params.resizable = *options->resizable.get(); | 276 create_params.resizable = *options->resizable.get(); |
250 | 277 |
251 if (options->always_on_top.get()) { | 278 if (options->always_on_top.get()) { |
252 create_params.always_on_top = *options->always_on_top.get(); | 279 create_params.always_on_top = *options->always_on_top.get(); |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 | 519 |
493 if (options.frame->as_frame_options->inactive_color.get()) { | 520 if (options.frame->as_frame_options->inactive_color.get()) { |
494 error_ = app_window_constants::kInactiveColorWithoutColor; | 521 error_ = app_window_constants::kInactiveColorWithoutColor; |
495 return false; | 522 return false; |
496 } | 523 } |
497 | 524 |
498 return true; | 525 return true; |
499 } | 526 } |
500 | 527 |
501 } // namespace extensions | 528 } // namespace extensions |
OLD | NEW |