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 "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 "chrome/common/extensions/api/app_window.h" | 12 #include "chrome/common/extensions/api/app_window.h" |
13 #include "content/public/browser/notification_registrar.h" | 13 #include "content/public/browser/notification_registrar.h" |
14 #include "content/public/browser/notification_types.h" | 14 #include "content/public/browser/notification_types.h" |
15 #include "content/public/browser/render_process_host.h" | 15 #include "content/public/browser/render_process_host.h" |
16 #include "content/public/browser/render_view_host.h" | 16 #include "content/public/browser/render_view_host.h" |
17 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
18 #include "content/public/common/url_constants.h" | 18 #include "content/public/common/url_constants.h" |
19 #include "extensions/browser/app_window/app_window.h" | 19 #include "extensions/browser/app_window/app_window.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/apps_client.h" | 22 #include "extensions/browser/app_window/apps_client.h" |
23 #include "extensions/browser/app_window/native_app_window.h" | 23 #include "extensions/browser/app_window/native_app_window.h" |
24 #include "extensions/browser/extensions_browser_client.h" | 24 #include "extensions/browser/extensions_browser_client.h" |
25 #include "extensions/browser/image_util.h" | 25 #include "extensions/browser/image_util.h" |
26 #include "extensions/common/features/simple_feature.h" | 26 #include "extensions/common/features/simple_feature.h" |
27 #include "extensions/common/manifest.h" | |
27 #include "extensions/common/permissions/permissions_data.h" | 28 #include "extensions/common/permissions/permissions_data.h" |
28 #include "extensions/common/switches.h" | 29 #include "extensions/common/switches.h" |
29 #include "third_party/skia/include/core/SkColor.h" | 30 #include "third_party/skia/include/core/SkColor.h" |
30 #include "ui/base/ui_base_types.h" | 31 #include "ui/base/ui_base_types.h" |
31 #include "ui/gfx/rect.h" | 32 #include "ui/gfx/rect.h" |
32 #include "url/gurl.h" | 33 #include "url/gurl.h" |
33 | 34 |
34 namespace app_window = extensions::api::app_window; | 35 namespace app_window = extensions::api::app_window; |
35 namespace Create = app_window::Create; | 36 namespace Create = app_window::Create; |
36 | 37 |
(...skipping 12 matching lines...) Expand all Loading... | |
49 const char kAlwaysOnTopPermission[] = | 50 const char kAlwaysOnTopPermission[] = |
50 "The \"app.window.alwaysOnTop\" permission is required."; | 51 "The \"app.window.alwaysOnTop\" permission is required."; |
51 const char kInvalidUrlParameter[] = | 52 const char kInvalidUrlParameter[] = |
52 "The URL used for window creation must be local for security reasons."; | 53 "The URL used for window creation must be local for security reasons."; |
53 const char kAlphaEnabledWrongChannel[] = | 54 const char kAlphaEnabledWrongChannel[] = |
54 "The alphaEnabled option requires dev channel or newer."; | 55 "The alphaEnabled option requires dev channel or newer."; |
55 const char kAlphaEnabledMissingPermission[] = | 56 const char kAlphaEnabledMissingPermission[] = |
56 "The alphaEnabled option requires app.window.alpha permission."; | 57 "The alphaEnabled option requires app.window.alpha permission."; |
57 const char kAlphaEnabledNeedsFrameNone[] = | 58 const char kAlphaEnabledNeedsFrameNone[] = |
58 "The alphaEnabled option can only be used with \"frame: 'none'\"."; | 59 "The alphaEnabled option can only be used with \"frame: 'none'\"."; |
60 const char kImeOptionMustTrueAndNeedsFrameNone[] = | |
jackhou1
2014/09/15 03:49:33
Nit: s/MustTrue/MustBeTrue/
bshe
2014/09/16 12:44:56
Done.
| |
61 "IME extensions must create window with \"ime: true\" and " \ | |
62 "\"frame: 'none'\"."; | |
63 const char kImeWindowMissingPermission[] = | |
64 "The \"ime\" option requires \"app.window.ime\" permission."; | |
jackhou1
2014/09/15 03:49:33
"Extensions require the \"app.window.ime\" permiss
bshe
2014/09/16 12:44:56
Done.
| |
65 const char kImeOptionIsNotSupported[] = | |
66 "The \"ime\" option is not supported for platform app."; | |
67 #if !defined(OS_CHROMEOS) | |
68 const char kImeWindowUnsupportedPlatform[] = | |
69 "The \"ime\" option can only be used on ChromeOS."; | |
70 #endif | |
59 } // namespace app_window_constants | 71 } // namespace app_window_constants |
60 | 72 |
61 const char kNoneFrameOption[] = "none"; | 73 const char kNoneFrameOption[] = "none"; |
62 // TODO(benwells): Remove HTML titlebar injection. | 74 // TODO(benwells): Remove HTML titlebar injection. |
63 const char kHtmlFrameOption[] = "experimental-html"; | 75 const char kHtmlFrameOption[] = "experimental-html"; |
64 | 76 |
65 namespace { | 77 namespace { |
66 | 78 |
67 // If the same property is specified for the inner and outer bounds, raise an | 79 // If the same property is specified for the inner and outer bounds, raise an |
68 // error. | 80 // error. |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 if (!AppsClient::Get()->IsCurrentChannelOlderThanDev() || | 208 if (!AppsClient::Get()->IsCurrentChannelOlderThanDev() || |
197 extension()->location() == extensions::Manifest::COMPONENT) { | 209 extension()->location() == extensions::Manifest::COMPONENT) { |
198 if (options->type == extensions::api::app_window::WINDOW_TYPE_PANEL) { | 210 if (options->type == extensions::api::app_window::WINDOW_TYPE_PANEL) { |
199 create_params.window_type = AppWindow::WINDOW_TYPE_PANEL; | 211 create_params.window_type = AppWindow::WINDOW_TYPE_PANEL; |
200 } | 212 } |
201 } | 213 } |
202 | 214 |
203 if (!GetFrameOptions(*options, &create_params)) | 215 if (!GetFrameOptions(*options, &create_params)) |
204 return false; | 216 return false; |
205 | 217 |
218 if (extension()->GetType() == extensions::Manifest::TYPE_EXTENSION) { | |
219 // Whitelisted IME extensions are allowed to use this API to create IME | |
220 // specific windows to show accented characters or suggestions. | |
221 if (!extension()->permissions_data()->HasAPIPermission( | |
222 APIPermission::kImeWindowEnabled)) { | |
223 error_ = app_window_constants::kImeWindowMissingPermission; | |
224 return false; | |
225 } | |
226 | |
227 #if !defined(OS_CHROMEOS) | |
228 // IME window is only supported on ChromeOS. | |
229 error_ = app_window_constants::kImeWindowUnsupportedPlatform; | |
230 return false; | |
231 #endif | |
232 | |
233 // IME extensions must create window with "ime: true" and "frame: none". | |
234 if (!options->ime.get() || !*options->ime.get() || | |
235 create_params.frame != AppWindow::FRAME_NONE) { | |
236 error_ = app_window_constants::kImeOptionMustTrueAndNeedsFrameNone; | |
237 return false; | |
238 } | |
239 create_params.is_ime_window = true; | |
240 } else { | |
241 if (options->ime.get()) { | |
242 error_ = app_window_constants::kImeOptionIsNotSupported; | |
243 return false; | |
244 } | |
245 } | |
246 | |
206 if (options->alpha_enabled.get()) { | 247 if (options->alpha_enabled.get()) { |
207 const char* whitelist[] = { | 248 const char* whitelist[] = { |
208 "0F42756099D914A026DADFA182871C015735DD95", // http://crbug.com/323773 | 249 "0F42756099D914A026DADFA182871C015735DD95", // http://crbug.com/323773 |
209 "2D22CDB6583FD0A13758AEBE8B15E45208B4E9A7", | 250 "2D22CDB6583FD0A13758AEBE8B15E45208B4E9A7", |
210 "E7E2461CE072DF036CF9592740196159E2D7C089", // http://crbug.com/356200 | 251 "E7E2461CE072DF036CF9592740196159E2D7C089", // http://crbug.com/356200 |
211 "A74A4D44C7CFCD8844830E6140C8D763E12DD8F3", | 252 "A74A4D44C7CFCD8844830E6140C8D763E12DD8F3", |
212 "312745D9BF916161191143F6490085EEA0434997", | 253 "312745D9BF916161191143F6490085EEA0434997", |
213 "53041A2FA309EECED01FFC751E7399186E860B2C" | 254 "53041A2FA309EECED01FFC751E7399186E860B2C" |
214 }; | 255 }; |
215 if (AppsClient::Get()->IsCurrentChannelOlderThanDev() && | 256 if (AppsClient::Get()->IsCurrentChannelOlderThanDev() && |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
488 | 529 |
489 if (options.frame->as_frame_options->inactive_color.get()) { | 530 if (options.frame->as_frame_options->inactive_color.get()) { |
490 error_ = app_window_constants::kInactiveColorWithoutColor; | 531 error_ = app_window_constants::kInactiveColorWithoutColor; |
491 return false; | 532 return false; |
492 } | 533 } |
493 | 534 |
494 return true; | 535 return true; |
495 } | 536 } |
496 | 537 |
497 } // namespace extensions | 538 } // namespace extensions |
OLD | NEW |