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" | |
8 #include "apps/app_window_contents.h" | 7 #include "apps/app_window_contents.h" |
9 #include "apps/app_window_registry.h" | |
10 #include "apps/ui/apps_client.h" | |
11 #include "base/command_line.h" | 8 #include "base/command_line.h" |
12 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
14 #include "base/time/time.h" | 11 #include "base/time/time.h" |
15 #include "base/values.h" | 12 #include "base/values.h" |
16 #include "chrome/common/extensions/api/app_window.h" | 13 #include "chrome/common/extensions/api/app_window.h" |
17 #include "content/public/browser/notification_registrar.h" | 14 #include "content/public/browser/notification_registrar.h" |
18 #include "content/public/browser/notification_types.h" | 15 #include "content/public/browser/notification_types.h" |
19 #include "content/public/browser/render_process_host.h" | 16 #include "content/public/browser/render_process_host.h" |
20 #include "content/public/browser/render_view_host.h" | 17 #include "content/public/browser/render_view_host.h" |
21 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
22 #include "content/public/common/url_constants.h" | 19 #include "content/public/common/url_constants.h" |
| 20 #include "extensions/browser/app_window/app_window.h" |
| 21 #include "extensions/browser/app_window/app_window_registry.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/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 using apps::AppWindow; | |
35 | |
36 namespace app_window = extensions::api::app_window; | 34 namespace app_window = extensions::api::app_window; |
37 namespace Create = app_window::Create; | 35 namespace Create = app_window::Create; |
38 | 36 |
39 namespace extensions { | 37 namespace extensions { |
40 | 38 |
41 namespace app_window_constants { | 39 namespace app_window_constants { |
42 const char kInvalidWindowId[] = | 40 const char kInvalidWindowId[] = |
43 "The window id can not be more than 256 characters long."; | 41 "The window id can not be more than 256 characters long."; |
44 const char kInvalidColorSpecification[] = | 42 const char kInvalidColorSpecification[] = |
45 "The color specification could not be parsed."; | 43 "The color specification could not be parsed."; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 return false; | 78 return false; |
81 } | 79 } |
82 | 80 |
83 return true; | 81 return true; |
84 } | 82 } |
85 | 83 |
86 // Copy over the bounds specification properties from the API to the | 84 // Copy over the bounds specification properties from the API to the |
87 // AppWindow::CreateParams. | 85 // AppWindow::CreateParams. |
88 void CopyBoundsSpec( | 86 void CopyBoundsSpec( |
89 const extensions::api::app_window::BoundsSpecification* input_spec, | 87 const extensions::api::app_window::BoundsSpecification* input_spec, |
90 apps::AppWindow::BoundsSpecification* create_spec) { | 88 AppWindow::BoundsSpecification* create_spec) { |
91 if (!input_spec) | 89 if (!input_spec) |
92 return; | 90 return; |
93 | 91 |
94 if (input_spec->left.get()) | 92 if (input_spec->left.get()) |
95 create_spec->bounds.set_x(*input_spec->left); | 93 create_spec->bounds.set_x(*input_spec->left); |
96 if (input_spec->top.get()) | 94 if (input_spec->top.get()) |
97 create_spec->bounds.set_y(*input_spec->top); | 95 create_spec->bounds.set_y(*input_spec->top); |
98 if (input_spec->width.get()) | 96 if (input_spec->width.get()) |
99 create_spec->bounds.set_width(*input_spec->width); | 97 create_spec->bounds.set_width(*input_spec->width); |
100 if (input_spec->height.get()) | 98 if (input_spec->height.get()) |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 create_params.window_key = *options->id; | 151 create_params.window_key = *options->id; |
154 | 152 |
155 if (options->singleton && *options->singleton == false) { | 153 if (options->singleton && *options->singleton == false) { |
156 WriteToConsole( | 154 WriteToConsole( |
157 content::CONSOLE_MESSAGE_LEVEL_WARNING, | 155 content::CONSOLE_MESSAGE_LEVEL_WARNING, |
158 "The 'singleton' option in chrome.apps.window.create() is deprecated!" | 156 "The 'singleton' option in chrome.apps.window.create() is deprecated!" |
159 " Change your code to no longer rely on this."); | 157 " Change your code to no longer rely on this."); |
160 } | 158 } |
161 | 159 |
162 if (!options->singleton || *options->singleton) { | 160 if (!options->singleton || *options->singleton) { |
163 AppWindow* window = apps::AppWindowRegistry::Get(browser_context()) | 161 AppWindow* window = AppWindowRegistry::Get(browser_context()) |
164 ->GetAppWindowForAppAndKey( | 162 ->GetAppWindowForAppAndKey( |
165 extension_id(), create_params.window_key); | 163 extension_id(), create_params.window_key); |
166 if (window) { | 164 if (window) { |
167 content::RenderViewHost* created_view = | 165 content::RenderViewHost* created_view = |
168 window->web_contents()->GetRenderViewHost(); | 166 window->web_contents()->GetRenderViewHost(); |
169 int view_id = MSG_ROUTING_NONE; | 167 int view_id = MSG_ROUTING_NONE; |
170 if (render_view_host_->GetProcess()->GetID() == | 168 if (render_view_host_->GetProcess()->GetID() == |
171 created_view->GetProcess()->GetID()) { | 169 created_view->GetProcess()->GetID()) { |
172 view_id = created_view->GetRoutingID(); | 170 view_id = created_view->GetRoutingID(); |
173 } | 171 } |
(...skipping 14 matching lines...) Expand all Loading... |
188 SetResult(result); | 186 SetResult(result); |
189 SendResponse(true); | 187 SendResponse(true); |
190 return true; | 188 return true; |
191 } | 189 } |
192 } | 190 } |
193 } | 191 } |
194 | 192 |
195 if (!GetBoundsSpec(*options, &create_params, &error_)) | 193 if (!GetBoundsSpec(*options, &create_params, &error_)) |
196 return false; | 194 return false; |
197 | 195 |
198 if (!apps::AppsClient::Get()->IsCurrentChannelOlderThanDev() || | 196 if (!AppsClient::Get()->IsCurrentChannelOlderThanDev() || |
199 extension()->location() == extensions::Manifest::COMPONENT) { | 197 extension()->location() == extensions::Manifest::COMPONENT) { |
200 if (options->type == extensions::api::app_window::WINDOW_TYPE_PANEL) { | 198 if (options->type == extensions::api::app_window::WINDOW_TYPE_PANEL) { |
201 create_params.window_type = AppWindow::WINDOW_TYPE_PANEL; | 199 create_params.window_type = AppWindow::WINDOW_TYPE_PANEL; |
202 } | 200 } |
203 } | 201 } |
204 | 202 |
205 if (!GetFrameOptions(*options, &create_params)) | 203 if (!GetFrameOptions(*options, &create_params)) |
206 return false; | 204 return false; |
207 | 205 |
208 if (options->alpha_enabled.get()) { | 206 if (options->alpha_enabled.get()) { |
209 const char* whitelist[] = { | 207 const char* whitelist[] = { |
210 "0F42756099D914A026DADFA182871C015735DD95", // http://crbug.com/323773 | 208 "0F42756099D914A026DADFA182871C015735DD95", // http://crbug.com/323773 |
211 "2D22CDB6583FD0A13758AEBE8B15E45208B4E9A7", | 209 "2D22CDB6583FD0A13758AEBE8B15E45208B4E9A7", |
212 "E7E2461CE072DF036CF9592740196159E2D7C089", // http://crbug.com/356200 | 210 "E7E2461CE072DF036CF9592740196159E2D7C089", // http://crbug.com/356200 |
213 "A74A4D44C7CFCD8844830E6140C8D763E12DD8F3", | 211 "A74A4D44C7CFCD8844830E6140C8D763E12DD8F3", |
214 "312745D9BF916161191143F6490085EEA0434997", | 212 "312745D9BF916161191143F6490085EEA0434997", |
215 "53041A2FA309EECED01FFC751E7399186E860B2C" | 213 "53041A2FA309EECED01FFC751E7399186E860B2C" |
216 }; | 214 }; |
217 if (apps::AppsClient::Get()->IsCurrentChannelOlderThanDev() && | 215 if (AppsClient::Get()->IsCurrentChannelOlderThanDev() && |
218 !extensions::SimpleFeature::IsIdInList( | 216 !extensions::SimpleFeature::IsIdInList( |
219 extension_id(), | 217 extension_id(), |
220 std::set<std::string>(whitelist, | 218 std::set<std::string>(whitelist, |
221 whitelist + arraysize(whitelist)))) { | 219 whitelist + arraysize(whitelist)))) { |
222 error_ = app_window_constants::kAlphaEnabledWrongChannel; | 220 error_ = app_window_constants::kAlphaEnabledWrongChannel; |
223 return false; | 221 return false; |
224 } | 222 } |
225 if (!extension()->permissions_data()->HasAPIPermission( | 223 if (!extension()->permissions_data()->HasAPIPermission( |
226 APIPermission::kAlphaEnabled)) { | 224 APIPermission::kAlphaEnabled)) { |
227 error_ = app_window_constants::kAlphaEnabledMissingPermission; | 225 error_ = app_window_constants::kAlphaEnabledMissingPermission; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 create_params.state = ui::SHOW_STATE_MINIMIZED; | 272 create_params.state = ui::SHOW_STATE_MINIMIZED; |
275 break; | 273 break; |
276 } | 274 } |
277 } | 275 } |
278 } | 276 } |
279 | 277 |
280 create_params.creator_process_id = | 278 create_params.creator_process_id = |
281 render_view_host_->GetProcess()->GetID(); | 279 render_view_host_->GetProcess()->GetID(); |
282 | 280 |
283 AppWindow* app_window = | 281 AppWindow* app_window = |
284 apps::AppsClient::Get()->CreateAppWindow(browser_context(), extension()); | 282 AppsClient::Get()->CreateAppWindow(browser_context(), extension()); |
285 app_window->Init( | 283 app_window->Init( |
286 url, new apps::AppWindowContentsImpl(app_window), create_params); | 284 url, new apps::AppWindowContentsImpl(app_window), create_params); |
287 | 285 |
288 if (ExtensionsBrowserClient::Get()->IsRunningInForcedAppMode()) | 286 if (ExtensionsBrowserClient::Get()->IsRunningInForcedAppMode()) |
289 app_window->ForcedFullscreen(); | 287 app_window->ForcedFullscreen(); |
290 | 288 |
291 content::RenderViewHost* created_view = | 289 content::RenderViewHost* created_view = |
292 app_window->web_contents()->GetRenderViewHost(); | 290 app_window->web_contents()->GetRenderViewHost(); |
293 int view_id = MSG_ROUTING_NONE; | 291 int view_id = MSG_ROUTING_NONE; |
294 if (create_params.creator_process_id == created_view->GetProcess()->GetID()) | 292 if (create_params.creator_process_id == created_view->GetProcess()->GetID()) |
295 view_id = created_view->GetRoutingID(); | 293 view_id = created_view->GetRoutingID(); |
296 | 294 |
297 base::DictionaryValue* result = new base::DictionaryValue; | 295 base::DictionaryValue* result = new base::DictionaryValue; |
298 result->Set("viewId", new base::FundamentalValue(view_id)); | 296 result->Set("viewId", new base::FundamentalValue(view_id)); |
299 result->Set("injectTitlebar", | 297 result->Set("injectTitlebar", |
300 new base::FundamentalValue(inject_html_titlebar_)); | 298 new base::FundamentalValue(inject_html_titlebar_)); |
301 result->Set("id", new base::StringValue(app_window->window_key())); | 299 result->Set("id", new base::StringValue(app_window->window_key())); |
302 app_window->GetSerializedState(result); | 300 app_window->GetSerializedState(result); |
303 SetResult(result); | 301 SetResult(result); |
304 | 302 |
305 if (apps::AppWindowRegistry::Get(browser_context()) | 303 if (AppWindowRegistry::Get(browser_context()) |
306 ->HadDevToolsAttached(created_view)) { | 304 ->HadDevToolsAttached(created_view)) { |
307 apps::AppsClient::Get()->OpenDevToolsWindow( | 305 AppsClient::Get()->OpenDevToolsWindow( |
308 app_window->web_contents(), | 306 app_window->web_contents(), |
309 base::Bind(&AppWindowCreateFunction::SendResponse, this, true)); | 307 base::Bind(&AppWindowCreateFunction::SendResponse, this, true)); |
310 return true; | 308 return true; |
311 } | 309 } |
312 | 310 |
313 SendResponse(true); | 311 SendResponse(true); |
314 app_window->WindowEventsReady(); | 312 app_window->WindowEventsReady(); |
315 | 313 |
316 return true; | 314 return true; |
317 } | 315 } |
318 | 316 |
319 bool AppWindowCreateFunction::GetBoundsSpec( | 317 bool AppWindowCreateFunction::GetBoundsSpec( |
320 const extensions::api::app_window::CreateWindowOptions& options, | 318 const extensions::api::app_window::CreateWindowOptions& options, |
321 apps::AppWindow::CreateParams* params, | 319 AppWindow::CreateParams* params, |
322 std::string* error) { | 320 std::string* error) { |
323 DCHECK(params); | 321 DCHECK(params); |
324 DCHECK(error); | 322 DCHECK(error); |
325 | 323 |
326 if (options.inner_bounds.get() || options.outer_bounds.get()) { | 324 if (options.inner_bounds.get() || options.outer_bounds.get()) { |
327 // Parse the inner and outer bounds specifications. If developers use the | 325 // Parse the inner and outer bounds specifications. If developers use the |
328 // new API, the deprecated fields will be ignored - do not attempt to merge | 326 // new API, the deprecated fields will be ignored - do not attempt to merge |
329 // them. | 327 // them. |
330 | 328 |
331 const extensions::api::app_window::BoundsSpecification* inner_bounds = | 329 const extensions::api::app_window::BoundsSpecification* inner_bounds = |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 | 489 |
492 if (options.frame->as_frame_options->inactive_color.get()) { | 490 if (options.frame->as_frame_options->inactive_color.get()) { |
493 error_ = app_window_constants::kInactiveColorWithoutColor; | 491 error_ = app_window_constants::kInactiveColorWithoutColor; |
494 return false; | 492 return false; |
495 } | 493 } |
496 | 494 |
497 return true; | 495 return true; |
498 } | 496 } |
499 | 497 |
500 } // namespace extensions | 498 } // namespace extensions |
OLD | NEW |