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/time.h" | 7 #include "base/time.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/extensions/extension_window_controller.h" | 9 #include "chrome/browser/extensions/extension_window_controller.h" |
10 #include "chrome/browser/extensions/extension_window_list.h" | 10 #include "chrome/browser/extensions/extension_window_list.h" |
11 #include "chrome/browser/ui/extensions/shell_window.h" | 11 #include "chrome/browser/ui/extensions/shell_window.h" |
12 #include "chrome/common/extensions/api/app_window.h" | 12 #include "chrome/common/extensions/api/app_window.h" |
13 #include "content/public/common/url_constants.h" | 13 #include "content/public/common/url_constants.h" |
14 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
15 #include "content/public/browser/render_view_host.h" | 15 #include "content/public/browser/render_view_host.h" |
16 #include "chrome/common/extensions/extension_error_utils.h" | 16 #include "chrome/common/extensions/extension_error_utils.h" |
17 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
18 #include "ui/gfx/rect.h" | 18 #include "ui/gfx/rect.h" |
19 | 19 |
20 namespace Create = extensions::api::app_window::Create; | 20 namespace app_window = extensions::api::app_window; |
21 namespace Create = app_window::Create; | |
Mihai Parparita -not on Chrome
2012/05/29 06:14:42
Nit: would using app_window::Create have worked he
| |
21 | 22 |
22 namespace extensions { | 23 namespace extensions { |
23 | 24 |
24 const char kCustomFrameOption[] = "custom"; | 25 const char kCustomFrameOption[] = "custom"; |
25 | 26 |
26 bool AppWindowCreateFunction::RunImpl() { | 27 bool AppWindowCreateFunction::RunImpl() { |
27 scoped_ptr<Create::Params> params(Create::Params::Create(*args_)); | 28 scoped_ptr<Create::Params> params(Create::Params::Create(*args_)); |
28 EXTENSION_FUNCTION_VALIDATE(params.get()); | 29 EXTENSION_FUNCTION_VALIDATE(params.get()); |
29 | 30 |
30 GURL url = GetExtension()->GetResourceURL(params->url); | 31 GURL url = GetExtension()->GetResourceURL(params->url); |
31 | 32 |
32 bool use_custom_frame = params->options.frame.get() && | |
33 *params->options.frame.get() == kCustomFrameOption; | |
34 | |
35 // TODO(jeremya): figure out a way to pass the opening WebContents through to | 33 // TODO(jeremya): figure out a way to pass the opening WebContents through to |
36 // ShellWindow::Create so we can set the opener at create time rather than | 34 // ShellWindow::Create so we can set the opener at create time rather than |
37 // with a hack in AppWindowCustomBindings::GetView(). | 35 // with a hack in AppWindowCustomBindings::GetView(). |
38 ShellWindow::CreateParams create_params; | 36 ShellWindow::CreateParams create_params; |
39 if (params->options.width.get()) | 37 app_window::CreateWindowOptions* options = params->options.get(); |
40 create_params.bounds.set_width(*params->options.width.get()); | 38 if (options) { |
41 if (params->options.height.get()) | 39 if (options->width.get()) |
42 create_params.bounds.set_height(*params->options.height.get()); | 40 create_params.bounds.set_width(*options->width.get()); |
43 if (params->options.left.get()) | 41 if (options->height.get()) |
44 create_params.bounds.set_x(*params->options.left.get()); | 42 create_params.bounds.set_height(*options->height.get()); |
45 if (params->options.top.get()) | 43 if (options->left.get()) |
46 create_params.bounds.set_y(*params->options.top.get()); | 44 create_params.bounds.set_x(*options->left.get()); |
47 create_params.frame = use_custom_frame ? | 45 if (options->top.get()) |
48 ShellWindow::CreateParams::FRAME_CUSTOM : | 46 create_params.bounds.set_y(*options->top.get()); |
49 ShellWindow::CreateParams::FRAME_CHROME; | 47 |
48 if (options->frame.get()) { | |
49 create_params.frame = *options->frame == kCustomFrameOption ? | |
50 ShellWindow::CreateParams::FRAME_CUSTOM : | |
51 ShellWindow::CreateParams::FRAME_CHROME; | |
52 } | |
53 } | |
50 ShellWindow* shell_window = | 54 ShellWindow* shell_window = |
51 ShellWindow::Create(profile(), GetExtension(), url, create_params); | 55 ShellWindow::Create(profile(), GetExtension(), url, create_params); |
52 shell_window->Show(); | 56 shell_window->Show(); |
53 | 57 |
54 content::WebContents* created_contents = shell_window->web_contents(); | 58 content::WebContents* created_contents = shell_window->web_contents(); |
55 int view_id = created_contents->GetRenderViewHost()->GetRoutingID(); | 59 int view_id = created_contents->GetRenderViewHost()->GetRoutingID(); |
56 | 60 |
57 result_.reset(base::Value::CreateIntegerValue(view_id)); | 61 result_.reset(base::Value::CreateIntegerValue(view_id)); |
58 return true; | 62 return true; |
59 } | 63 } |
60 | 64 |
61 } // namespace extensions | 65 } // namespace extensions |
OLD | NEW |