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 "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 "chrome/common/extensions/api/app_window.h" | |
13 #include "content/public/browser/notification_registrar.h" | 12 #include "content/public/browser/notification_registrar.h" |
14 #include "content/public/browser/notification_types.h" | 13 #include "content/public/browser/notification_types.h" |
15 #include "content/public/browser/render_process_host.h" | 14 #include "content/public/browser/render_process_host.h" |
16 #include "content/public/browser/render_view_host.h" | 15 #include "content/public/browser/render_view_host.h" |
17 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
18 #include "content/public/common/url_constants.h" | 17 #include "content/public/common/url_constants.h" |
19 #include "extensions/browser/app_window/app_window.h" | 18 #include "extensions/browser/app_window/app_window.h" |
20 #include "extensions/browser/app_window/app_window_contents.h" | 19 #include "extensions/browser/app_window/app_window_contents.h" |
21 #include "extensions/browser/app_window/app_window_registry.h" | 20 #include "extensions/browser/app_window/app_window_registry.h" |
22 #include "extensions/browser/app_window/apps_client.h" | 21 #include "extensions/browser/app_window/apps_client.h" |
23 #include "extensions/browser/app_window/native_app_window.h" | 22 #include "extensions/browser/app_window/native_app_window.h" |
24 #include "extensions/browser/extensions_browser_client.h" | 23 #include "extensions/browser/extensions_browser_client.h" |
25 #include "extensions/browser/image_util.h" | 24 #include "extensions/browser/image_util.h" |
| 25 #include "extensions/common/api/app_window.h" |
26 #include "extensions/common/features/simple_feature.h" | 26 #include "extensions/common/features/simple_feature.h" |
27 #include "extensions/common/permissions/permissions_data.h" | 27 #include "extensions/common/permissions/permissions_data.h" |
28 #include "extensions/common/switches.h" | 28 #include "extensions/common/switches.h" |
29 #include "third_party/skia/include/core/SkColor.h" | 29 #include "third_party/skia/include/core/SkColor.h" |
30 #include "ui/base/ui_base_types.h" | 30 #include "ui/base/ui_base_types.h" |
31 #include "ui/gfx/rect.h" | 31 #include "ui/gfx/rect.h" |
32 #include "url/gurl.h" | 32 #include "url/gurl.h" |
33 | 33 |
34 namespace app_window = extensions::api::app_window; | 34 namespace app_window = extensions::core_api::app_window; |
35 namespace Create = app_window::Create; | 35 namespace Create = app_window::Create; |
36 | 36 |
37 namespace extensions { | 37 namespace extensions { |
38 | 38 |
39 namespace app_window_constants { | 39 namespace app_window_constants { |
40 const char kInvalidWindowId[] = | 40 const char kInvalidWindowId[] = |
41 "The window id can not be more than 256 characters long."; | 41 "The window id can not be more than 256 characters long."; |
42 const char kInvalidColorSpecification[] = | 42 const char kInvalidColorSpecification[] = |
43 "The color specification could not be parsed."; | 43 "The color specification could not be parsed."; |
44 const char kColorWithFrameNone[] = "Windows with no frame cannot have a color."; | 44 const char kColorWithFrameNone[] = "Windows with no frame cannot have a color."; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 *error = ReplaceStringPlaceholders( | 76 *error = ReplaceStringPlaceholders( |
77 app_window_constants::kConflictingBoundsOptions, subst, NULL); | 77 app_window_constants::kConflictingBoundsOptions, subst, NULL); |
78 return false; | 78 return false; |
79 } | 79 } |
80 | 80 |
81 return true; | 81 return true; |
82 } | 82 } |
83 | 83 |
84 // Copy over the bounds specification properties from the API to the | 84 // Copy over the bounds specification properties from the API to the |
85 // AppWindow::CreateParams. | 85 // AppWindow::CreateParams. |
86 void CopyBoundsSpec( | 86 void CopyBoundsSpec(const app_window::BoundsSpecification* input_spec, |
87 const extensions::api::app_window::BoundsSpecification* input_spec, | 87 AppWindow::BoundsSpecification* create_spec) { |
88 AppWindow::BoundsSpecification* create_spec) { | |
89 if (!input_spec) | 88 if (!input_spec) |
90 return; | 89 return; |
91 | 90 |
92 if (input_spec->left.get()) | 91 if (input_spec->left.get()) |
93 create_spec->bounds.set_x(*input_spec->left); | 92 create_spec->bounds.set_x(*input_spec->left); |
94 if (input_spec->top.get()) | 93 if (input_spec->top.get()) |
95 create_spec->bounds.set_y(*input_spec->top); | 94 create_spec->bounds.set_y(*input_spec->top); |
96 if (input_spec->width.get()) | 95 if (input_spec->width.get()) |
97 create_spec->bounds.set_width(*input_spec->width); | 96 create_spec->bounds.set_width(*input_spec->width); |
98 if (input_spec->height.get()) | 97 if (input_spec->height.get()) |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 return true; | 187 return true; |
189 } | 188 } |
190 } | 189 } |
191 } | 190 } |
192 | 191 |
193 if (!GetBoundsSpec(*options, &create_params, &error_)) | 192 if (!GetBoundsSpec(*options, &create_params, &error_)) |
194 return false; | 193 return false; |
195 | 194 |
196 if (!AppsClient::Get()->IsCurrentChannelOlderThanDev() || | 195 if (!AppsClient::Get()->IsCurrentChannelOlderThanDev() || |
197 extension()->location() == extensions::Manifest::COMPONENT) { | 196 extension()->location() == extensions::Manifest::COMPONENT) { |
198 if (options->type == extensions::api::app_window::WINDOW_TYPE_PANEL) { | 197 if (options->type == app_window::WINDOW_TYPE_PANEL) { |
199 create_params.window_type = AppWindow::WINDOW_TYPE_PANEL; | 198 create_params.window_type = AppWindow::WINDOW_TYPE_PANEL; |
200 } | 199 } |
201 } | 200 } |
202 | 201 |
203 if (!GetFrameOptions(*options, &create_params)) | 202 if (!GetFrameOptions(*options, &create_params)) |
204 return false; | 203 return false; |
205 | 204 |
206 if (options->alpha_enabled.get()) { | 205 if (options->alpha_enabled.get()) { |
207 const char* whitelist[] = { | 206 const char* whitelist[] = { |
208 "0F42756099D914A026DADFA182871C015735DD95", // http://crbug.com/323773 | 207 "0F42756099D914A026DADFA182871C015735DD95", // http://crbug.com/323773 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 !extension()->permissions_data()->HasAPIPermission( | 249 !extension()->permissions_data()->HasAPIPermission( |
251 APIPermission::kAlwaysOnTopWindows)) { | 250 APIPermission::kAlwaysOnTopWindows)) { |
252 error_ = app_window_constants::kAlwaysOnTopPermission; | 251 error_ = app_window_constants::kAlwaysOnTopPermission; |
253 return false; | 252 return false; |
254 } | 253 } |
255 } | 254 } |
256 | 255 |
257 if (options->focused.get()) | 256 if (options->focused.get()) |
258 create_params.focused = *options->focused.get(); | 257 create_params.focused = *options->focused.get(); |
259 | 258 |
260 if (options->type != extensions::api::app_window::WINDOW_TYPE_PANEL) { | 259 if (options->type != app_window::WINDOW_TYPE_PANEL) { |
261 switch (options->state) { | 260 switch (options->state) { |
262 case extensions::api::app_window::STATE_NONE: | 261 case app_window::STATE_NONE: |
263 case extensions::api::app_window::STATE_NORMAL: | 262 case app_window::STATE_NORMAL: |
264 break; | 263 break; |
265 case extensions::api::app_window::STATE_FULLSCREEN: | 264 case app_window::STATE_FULLSCREEN: |
266 create_params.state = ui::SHOW_STATE_FULLSCREEN; | 265 create_params.state = ui::SHOW_STATE_FULLSCREEN; |
267 break; | 266 break; |
268 case extensions::api::app_window::STATE_MAXIMIZED: | 267 case app_window::STATE_MAXIMIZED: |
269 create_params.state = ui::SHOW_STATE_MAXIMIZED; | 268 create_params.state = ui::SHOW_STATE_MAXIMIZED; |
270 break; | 269 break; |
271 case extensions::api::app_window::STATE_MINIMIZED: | 270 case app_window::STATE_MINIMIZED: |
272 create_params.state = ui::SHOW_STATE_MINIMIZED; | 271 create_params.state = ui::SHOW_STATE_MINIMIZED; |
273 break; | 272 break; |
274 } | 273 } |
275 } | 274 } |
276 } | 275 } |
277 | 276 |
278 create_params.creator_process_id = | 277 create_params.creator_process_id = |
279 render_view_host_->GetProcess()->GetID(); | 278 render_view_host_->GetProcess()->GetID(); |
280 | 279 |
281 AppWindow* app_window = | 280 AppWindow* app_window = |
(...skipping 25 matching lines...) Expand all Loading... |
307 return true; | 306 return true; |
308 } | 307 } |
309 | 308 |
310 SendResponse(true); | 309 SendResponse(true); |
311 app_window->WindowEventsReady(); | 310 app_window->WindowEventsReady(); |
312 | 311 |
313 return true; | 312 return true; |
314 } | 313 } |
315 | 314 |
316 bool AppWindowCreateFunction::GetBoundsSpec( | 315 bool AppWindowCreateFunction::GetBoundsSpec( |
317 const extensions::api::app_window::CreateWindowOptions& options, | 316 const app_window::CreateWindowOptions& options, |
318 AppWindow::CreateParams* params, | 317 AppWindow::CreateParams* params, |
319 std::string* error) { | 318 std::string* error) { |
320 DCHECK(params); | 319 DCHECK(params); |
321 DCHECK(error); | 320 DCHECK(error); |
322 | 321 |
323 if (options.inner_bounds.get() || options.outer_bounds.get()) { | 322 if (options.inner_bounds.get() || options.outer_bounds.get()) { |
324 // Parse the inner and outer bounds specifications. If developers use the | 323 // Parse the inner and outer bounds specifications. If developers use the |
325 // new API, the deprecated fields will be ignored - do not attempt to merge | 324 // new API, the deprecated fields will be ignored - do not attempt to merge |
326 // them. | 325 // them. |
327 | 326 |
328 const extensions::api::app_window::BoundsSpecification* inner_bounds = | 327 const app_window::BoundsSpecification* inner_bounds = |
329 options.inner_bounds.get(); | 328 options.inner_bounds.get(); |
330 const extensions::api::app_window::BoundsSpecification* outer_bounds = | 329 const app_window::BoundsSpecification* outer_bounds = |
331 options.outer_bounds.get(); | 330 options.outer_bounds.get(); |
332 if (inner_bounds && outer_bounds) { | 331 if (inner_bounds && outer_bounds) { |
333 if (!CheckBoundsConflict( | 332 if (!CheckBoundsConflict( |
334 inner_bounds->left, outer_bounds->left, "left", error)) { | 333 inner_bounds->left, outer_bounds->left, "left", error)) { |
335 return false; | 334 return false; |
336 } | 335 } |
337 if (!CheckBoundsConflict( | 336 if (!CheckBoundsConflict( |
338 inner_bounds->top, outer_bounds->top, "top", error)) { | 337 inner_bounds->top, outer_bounds->top, "top", error)) { |
339 return false; | 338 return false; |
340 } | 339 } |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 | 487 |
489 if (options.frame->as_frame_options->inactive_color.get()) { | 488 if (options.frame->as_frame_options->inactive_color.get()) { |
490 error_ = app_window_constants::kInactiveColorWithoutColor; | 489 error_ = app_window_constants::kInactiveColorWithoutColor; |
491 return false; | 490 return false; |
492 } | 491 } |
493 | 492 |
494 return true; | 493 return true; |
495 } | 494 } |
496 | 495 |
497 } // namespace extensions | 496 } // namespace extensions |
OLD | NEW |