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_contents.h" | 8 #include "apps/app_window_contents.h" |
8 #include "apps/shell_window.h" | 9 #include "apps/app_window_registry.h" |
9 #include "apps/shell_window_registry.h" | |
10 #include "apps/ui/native_app_window.h" | 10 #include "apps/ui/native_app_window.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/browser/app_mode/app_mode_utils.h" | 14 #include "chrome/browser/app_mode/app_mode_utils.h" |
15 #include "chrome/browser/devtools/devtools_window.h" | 15 #include "chrome/browser/devtools/devtools_window.h" |
16 #include "chrome/browser/extensions/window_controller.h" | 16 #include "chrome/browser/extensions/window_controller.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/ui/apps/chrome_shell_window_delegate.h" | 18 #include "chrome/browser/ui/apps/chrome_shell_window_delegate.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/common/switches.h" | 28 #include "extensions/common/switches.h" |
29 #include "ui/base/ui_base_types.h" | 29 #include "ui/base/ui_base_types.h" |
30 #include "ui/gfx/rect.h" | 30 #include "ui/gfx/rect.h" |
31 #include "url/gurl.h" | 31 #include "url/gurl.h" |
32 | 32 |
33 #if defined(USE_ASH) | 33 #if defined(USE_ASH) |
34 #include "ash/shell.h" | 34 #include "ash/shell.h" |
35 #include "ui/aura/root_window.h" | 35 #include "ui/aura/root_window.h" |
36 #include "ui/aura/window.h" | 36 #include "ui/aura/window.h" |
37 #endif | 37 #endif |
38 | 38 |
39 using apps::ShellWindow; | 39 using apps::AppWindow; |
40 | 40 |
41 namespace app_window = extensions::api::app_window; | 41 namespace app_window = extensions::api::app_window; |
42 namespace Create = app_window::Create; | 42 namespace Create = app_window::Create; |
43 | 43 |
44 namespace extensions { | 44 namespace extensions { |
45 | 45 |
46 namespace app_window_constants { | 46 namespace app_window_constants { |
47 const char kInvalidWindowId[] = | 47 const char kInvalidWindowId[] = |
48 "The window id can not be more than 256 characters long."; | 48 "The window id can not be more than 256 characters long."; |
49 } | 49 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 // path. | 101 // path. |
102 if (GetExtension()->location() == extensions::Manifest::COMPONENT) { | 102 if (GetExtension()->location() == extensions::Manifest::COMPONENT) { |
103 GURL absolute = GURL(params->url); | 103 GURL absolute = GURL(params->url); |
104 if (absolute.has_scheme()) | 104 if (absolute.has_scheme()) |
105 url = absolute; | 105 url = absolute; |
106 } | 106 } |
107 | 107 |
108 bool inject_html_titlebar = false; | 108 bool inject_html_titlebar = false; |
109 | 109 |
110 // TODO(jeremya): figure out a way to pass the opening WebContents through to | 110 // TODO(jeremya): figure out a way to pass the opening WebContents through to |
111 // ShellWindow::Create so we can set the opener at create time rather than | 111 // AppWindow::Create so we can set the opener at create time rather than |
112 // with a hack in AppWindowCustomBindings::GetView(). | 112 // with a hack in AppWindowCustomBindings::GetView(). |
113 ShellWindow::CreateParams create_params; | 113 AppWindow::CreateParams create_params; |
114 app_window::CreateWindowOptions* options = params->options.get(); | 114 app_window::CreateWindowOptions* options = params->options.get(); |
115 if (options) { | 115 if (options) { |
116 if (options->id.get()) { | 116 if (options->id.get()) { |
117 // TODO(mek): use URL if no id specified? | 117 // TODO(mek): use URL if no id specified? |
118 // Limit length of id to 256 characters. | 118 // Limit length of id to 256 characters. |
119 if (options->id->length() > 256) { | 119 if (options->id->length() > 256) { |
120 error_ = app_window_constants::kInvalidWindowId; | 120 error_ = app_window_constants::kInvalidWindowId; |
121 return false; | 121 return false; |
122 } | 122 } |
123 | 123 |
124 create_params.window_key = *options->id; | 124 create_params.window_key = *options->id; |
125 | 125 |
126 if (options->singleton && *options->singleton == false) { | 126 if (options->singleton && *options->singleton == false) { |
127 WriteToConsole( | 127 WriteToConsole( |
128 content::CONSOLE_MESSAGE_LEVEL_WARNING, | 128 content::CONSOLE_MESSAGE_LEVEL_WARNING, |
129 "The 'singleton' option in chrome.apps.window.create() is deprecated!" | 129 "The 'singleton' option in chrome.apps.window.create() is deprecated!" |
130 " Change your code to no longer rely on this."); | 130 " Change your code to no longer rely on this."); |
131 } | 131 } |
132 | 132 |
133 if (!options->singleton || *options->singleton) { | 133 if (!options->singleton || *options->singleton) { |
134 ShellWindow* window = apps::ShellWindowRegistry::Get( | 134 AppWindow* window = apps::AppWindowRegistry::Get(GetProfile()) |
135 GetProfile())->GetShellWindowForAppAndKey(extension_id(), | 135 ->GetAppWindowForAppAndKey( |
136 create_params.window_key); | 136 extension_id(), create_params.window_key); |
137 if (window) { | 137 if (window) { |
138 content::RenderViewHost* created_view = | 138 content::RenderViewHost* created_view = |
139 window->web_contents()->GetRenderViewHost(); | 139 window->web_contents()->GetRenderViewHost(); |
140 int view_id = MSG_ROUTING_NONE; | 140 int view_id = MSG_ROUTING_NONE; |
141 if (render_view_host_->GetProcess()->GetID() == | 141 if (render_view_host_->GetProcess()->GetID() == |
142 created_view->GetProcess()->GetID()) { | 142 created_view->GetProcess()->GetID()) { |
143 view_id = created_view->GetRoutingID(); | 143 view_id = created_view->GetRoutingID(); |
144 } | 144 } |
145 | 145 |
146 if (options->focused.get() && !*options->focused.get()) | 146 if (options->focused.get() && !*options->focused.get()) |
147 window->Show(ShellWindow::SHOW_INACTIVE); | 147 window->Show(AppWindow::SHOW_INACTIVE); |
148 else | 148 else |
149 window->Show(ShellWindow::SHOW_ACTIVE); | 149 window->Show(AppWindow::SHOW_ACTIVE); |
150 | 150 |
151 base::DictionaryValue* result = new base::DictionaryValue; | 151 base::DictionaryValue* result = new base::DictionaryValue; |
152 result->Set("viewId", new base::FundamentalValue(view_id)); | 152 result->Set("viewId", new base::FundamentalValue(view_id)); |
153 window->GetSerializedState(result); | 153 window->GetSerializedState(result); |
154 result->SetBoolean("existingWindow", true); | 154 result->SetBoolean("existingWindow", true); |
155 result->SetBoolean("injectTitlebar", false); | 155 result->SetBoolean("injectTitlebar", false); |
156 SetResult(result); | 156 SetResult(result); |
157 SendResponse(true); | 157 SendResponse(true); |
158 return true; | 158 return true; |
159 } | 159 } |
(...skipping 28 matching lines...) Expand all Loading... |
188 create_params.bounds.set_height(*bounds->height.get()); | 188 create_params.bounds.set_height(*bounds->height.get()); |
189 if (bounds->left.get()) | 189 if (bounds->left.get()) |
190 create_params.bounds.set_x(*bounds->left.get()); | 190 create_params.bounds.set_x(*bounds->left.get()); |
191 if (bounds->top.get()) | 191 if (bounds->top.get()) |
192 create_params.bounds.set_y(*bounds->top.get()); | 192 create_params.bounds.set_y(*bounds->top.get()); |
193 } | 193 } |
194 | 194 |
195 if (GetCurrentChannel() <= chrome::VersionInfo::CHANNEL_DEV || | 195 if (GetCurrentChannel() <= chrome::VersionInfo::CHANNEL_DEV || |
196 GetExtension()->location() == extensions::Manifest::COMPONENT) { | 196 GetExtension()->location() == extensions::Manifest::COMPONENT) { |
197 if (options->type == extensions::api::app_window::WINDOW_TYPE_PANEL) { | 197 if (options->type == extensions::api::app_window::WINDOW_TYPE_PANEL) { |
198 create_params.window_type = ShellWindow::WINDOW_TYPE_PANEL; | 198 create_params.window_type = AppWindow::WINDOW_TYPE_PANEL; |
199 } | 199 } |
200 } | 200 } |
201 | 201 |
202 if (options->frame.get()) { | 202 if (options->frame.get()) { |
203 if (*options->frame == kHtmlFrameOption && | 203 if (*options->frame == kHtmlFrameOption && |
204 (GetExtension()->HasAPIPermission(APIPermission::kExperimental) || | 204 (GetExtension()->HasAPIPermission(APIPermission::kExperimental) || |
205 CommandLine::ForCurrentProcess()->HasSwitch( | 205 CommandLine::ForCurrentProcess()->HasSwitch( |
206 switches::kEnableExperimentalExtensionApis))) { | 206 switches::kEnableExperimentalExtensionApis))) { |
207 create_params.frame = ShellWindow::FRAME_NONE; | 207 create_params.frame = AppWindow::FRAME_NONE; |
208 inject_html_titlebar = true; | 208 inject_html_titlebar = true; |
209 } else if (*options->frame == kNoneFrameOption) { | 209 } else if (*options->frame == kNoneFrameOption) { |
210 create_params.frame = ShellWindow::FRAME_NONE; | 210 create_params.frame = AppWindow::FRAME_NONE; |
211 } else { | 211 } else { |
212 create_params.frame = ShellWindow::FRAME_CHROME; | 212 create_params.frame = AppWindow::FRAME_CHROME; |
213 } | 213 } |
214 } | 214 } |
215 | 215 |
216 if (options->transparent_background.get() && | 216 if (options->transparent_background.get() && |
217 (GetExtension()->HasAPIPermission(APIPermission::kExperimental) || | 217 (GetExtension()->HasAPIPermission(APIPermission::kExperimental) || |
218 CommandLine::ForCurrentProcess()->HasSwitch( | 218 CommandLine::ForCurrentProcess()->HasSwitch( |
219 switches::kEnableExperimentalExtensionApis))) { | 219 switches::kEnableExperimentalExtensionApis))) { |
220 create_params.transparent_background = *options->transparent_background; | 220 create_params.transparent_background = *options->transparent_background; |
221 } | 221 } |
222 | 222 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 case extensions::api::app_window::STATE_MINIMIZED: | 258 case extensions::api::app_window::STATE_MINIMIZED: |
259 create_params.state = ui::SHOW_STATE_MINIMIZED; | 259 create_params.state = ui::SHOW_STATE_MINIMIZED; |
260 break; | 260 break; |
261 } | 261 } |
262 } | 262 } |
263 } | 263 } |
264 | 264 |
265 create_params.creator_process_id = | 265 create_params.creator_process_id = |
266 render_view_host_->GetProcess()->GetID(); | 266 render_view_host_->GetProcess()->GetID(); |
267 | 267 |
268 ShellWindow* shell_window = new ShellWindow( | 268 AppWindow* app_window = new AppWindow( |
269 GetProfile(), new ChromeShellWindowDelegate(), GetExtension()); | 269 GetProfile(), new ChromeShellWindowDelegate(), GetExtension()); |
270 shell_window->Init(url, | 270 app_window->Init( |
271 new apps::AppWindowContents(shell_window), | 271 url, new apps::AppWindowContentsImpl(app_window), create_params); |
272 create_params); | |
273 | 272 |
274 if (chrome::IsRunningInForcedAppMode()) | 273 if (chrome::IsRunningInForcedAppMode()) |
275 shell_window->ForcedFullscreen(); | 274 app_window->ForcedFullscreen(); |
276 | 275 |
277 content::RenderViewHost* created_view = | 276 content::RenderViewHost* created_view = |
278 shell_window->web_contents()->GetRenderViewHost(); | 277 app_window->web_contents()->GetRenderViewHost(); |
279 int view_id = MSG_ROUTING_NONE; | 278 int view_id = MSG_ROUTING_NONE; |
280 if (create_params.creator_process_id == created_view->GetProcess()->GetID()) | 279 if (create_params.creator_process_id == created_view->GetProcess()->GetID()) |
281 view_id = created_view->GetRoutingID(); | 280 view_id = created_view->GetRoutingID(); |
282 | 281 |
283 base::DictionaryValue* result = new base::DictionaryValue; | 282 base::DictionaryValue* result = new base::DictionaryValue; |
284 result->Set("viewId", new base::FundamentalValue(view_id)); | 283 result->Set("viewId", new base::FundamentalValue(view_id)); |
285 result->Set("injectTitlebar", | 284 result->Set("injectTitlebar", |
286 new base::FundamentalValue(inject_html_titlebar)); | 285 new base::FundamentalValue(inject_html_titlebar)); |
287 result->Set("id", new base::StringValue(shell_window->window_key())); | 286 result->Set("id", new base::StringValue(app_window->window_key())); |
288 shell_window->GetSerializedState(result); | 287 app_window->GetSerializedState(result); |
289 SetResult(result); | 288 SetResult(result); |
290 | 289 |
291 if (apps::ShellWindowRegistry::Get(GetProfile()) | 290 if (apps::AppWindowRegistry::Get(GetProfile()) |
292 ->HadDevToolsAttached(created_view)) { | 291 ->HadDevToolsAttached(created_view)) { |
293 new DevToolsRestorer(this, created_view); | 292 new DevToolsRestorer(this, created_view); |
294 return true; | 293 return true; |
295 } | 294 } |
296 | 295 |
297 SendResponse(true); | 296 SendResponse(true); |
298 return true; | 297 return true; |
299 } | 298 } |
300 | 299 |
301 } // namespace extensions | 300 } // namespace extensions |
OLD | NEW |