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 "extensions/browser/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 "content/public/browser/notification_registrar.h" | 12 #include "content/public/browser/notification_registrar.h" |
13 #include "content/public/browser/notification_types.h" | 13 #include "content/public/browser/notification_types.h" |
14 #include "content/public/browser/render_frame_host.h" | 14 #include "content/public/browser/render_frame_host.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" | |
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_client.h" | 19 #include "extensions/browser/app_window/app_window_client.h" |
21 #include "extensions/browser/app_window/app_window_contents.h" | 20 #include "extensions/browser/app_window/app_window_contents.h" |
22 #include "extensions/browser/app_window/app_window_registry.h" | 21 #include "extensions/browser/app_window/app_window_registry.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/common/api/app_window.h" | 24 #include "extensions/common/api/app_window.h" |
26 #include "extensions/common/features/simple_feature.h" | 25 #include "extensions/common/features/simple_feature.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 // Don't create app window if the system is shutting down. | 128 // Don't create app window if the system is shutting down. |
130 if (ExtensionsBrowserClient::Get()->IsShuttingDown()) | 129 if (ExtensionsBrowserClient::Get()->IsShuttingDown()) |
131 return false; | 130 return false; |
132 | 131 |
133 scoped_ptr<Create::Params> params(Create::Params::Create(*args_)); | 132 scoped_ptr<Create::Params> params(Create::Params::Create(*args_)); |
134 EXTENSION_FUNCTION_VALIDATE(params.get()); | 133 EXTENSION_FUNCTION_VALIDATE(params.get()); |
135 | 134 |
136 GURL url = extension()->GetResourceURL(params->url); | 135 GURL url = extension()->GetResourceURL(params->url); |
137 // Allow absolute URLs for component apps, otherwise prepend the extension | 136 // Allow absolute URLs for component apps, otherwise prepend the extension |
138 // path. | 137 // path. |
| 138 // TODO(devlin): Investigate if this is still used. If not, kill it dead! |
139 GURL absolute = GURL(params->url); | 139 GURL absolute = GURL(params->url); |
140 if (absolute.has_scheme()) { | 140 if (absolute.has_scheme()) { |
141 if (extension()->location() == Manifest::COMPONENT) { | 141 if (extension()->location() == Manifest::COMPONENT) { |
142 url = absolute; | 142 url = absolute; |
143 } else { | 143 } else { |
144 // Show error when url passed isn't local. | 144 // Show error when url passed isn't local. |
145 error_ = app_window_constants::kInvalidUrlParameter; | 145 error_ = app_window_constants::kInvalidUrlParameter; |
146 return false; | 146 return false; |
147 } | 147 } |
148 } | 148 } |
(...skipping 15 matching lines...) Expand all Loading... |
164 create_params.window_key = *options->id; | 164 create_params.window_key = *options->id; |
165 | 165 |
166 if (options->singleton && *options->singleton == false) { | 166 if (options->singleton && *options->singleton == false) { |
167 WriteToConsole( | 167 WriteToConsole( |
168 content::CONSOLE_MESSAGE_LEVEL_WARNING, | 168 content::CONSOLE_MESSAGE_LEVEL_WARNING, |
169 "The 'singleton' option in chrome.apps.window.create() is deprecated!" | 169 "The 'singleton' option in chrome.apps.window.create() is deprecated!" |
170 " Change your code to no longer rely on this."); | 170 " Change your code to no longer rely on this."); |
171 } | 171 } |
172 | 172 |
173 if (!options->singleton || *options->singleton) { | 173 if (!options->singleton || *options->singleton) { |
174 AppWindow* window = AppWindowRegistry::Get(browser_context()) | 174 AppWindow* existing_window = |
175 ->GetAppWindowForAppAndKey( | 175 AppWindowRegistry::Get(browser_context()) |
176 extension_id(), create_params.window_key); | 176 ->GetAppWindowForAppAndKey(extension_id(), |
177 if (window) { | 177 create_params.window_key); |
178 content::RenderViewHost* created_view = | 178 if (existing_window) { |
179 window->web_contents()->GetRenderViewHost(); | 179 content::RenderFrameHost* existing_frame = |
180 int view_id = MSG_ROUTING_NONE; | 180 existing_window->web_contents()->GetMainFrame(); |
| 181 int frame_id = MSG_ROUTING_NONE; |
181 if (render_frame_host()->GetProcess()->GetID() == | 182 if (render_frame_host()->GetProcess()->GetID() == |
182 created_view->GetProcess()->GetID()) { | 183 existing_frame->GetProcess()->GetID()) { |
183 view_id = created_view->GetRoutingID(); | 184 frame_id = existing_frame->GetRoutingID(); |
184 } | 185 } |
185 | 186 |
186 if (!options->hidden.get() || !*options->hidden.get()) { | 187 if (!options->hidden.get() || !*options->hidden.get()) { |
187 if (options->focused.get() && !*options->focused.get()) | 188 if (options->focused.get() && !*options->focused.get()) |
188 window->Show(AppWindow::SHOW_INACTIVE); | 189 existing_window->Show(AppWindow::SHOW_INACTIVE); |
189 else | 190 else |
190 window->Show(AppWindow::SHOW_ACTIVE); | 191 existing_window->Show(AppWindow::SHOW_ACTIVE); |
191 } | 192 } |
192 | 193 |
193 base::DictionaryValue* result = new base::DictionaryValue; | 194 base::DictionaryValue* result = new base::DictionaryValue; |
194 result->Set("viewId", new base::FundamentalValue(view_id)); | 195 result->Set("frameId", new base::FundamentalValue(frame_id)); |
195 window->GetSerializedState(result); | 196 existing_window->GetSerializedState(result); |
196 result->SetBoolean("existingWindow", true); | 197 result->SetBoolean("existingWindow", true); |
197 // TODO(benwells): Remove HTML titlebar injection. | 198 // TODO(benwells): Remove HTML titlebar injection. |
198 result->SetBoolean("injectTitlebar", false); | 199 result->SetBoolean("injectTitlebar", false); |
199 SetResult(result); | 200 SetResult(result); |
200 SendResponse(true); | 201 SendResponse(true); |
201 return true; | 202 return true; |
202 } | 203 } |
203 } | 204 } |
204 } | 205 } |
205 | 206 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 | 338 |
338 AppWindow* app_window = | 339 AppWindow* app_window = |
339 AppWindowClient::Get()->CreateAppWindow(browser_context(), extension()); | 340 AppWindowClient::Get()->CreateAppWindow(browser_context(), extension()); |
340 app_window->Init(url, new AppWindowContentsImpl(app_window), create_params); | 341 app_window->Init(url, new AppWindowContentsImpl(app_window), create_params); |
341 | 342 |
342 if (ExtensionsBrowserClient::Get()->IsRunningInForcedAppMode() && | 343 if (ExtensionsBrowserClient::Get()->IsRunningInForcedAppMode() && |
343 !app_window->is_ime_window()) { | 344 !app_window->is_ime_window()) { |
344 app_window->ForcedFullscreen(); | 345 app_window->ForcedFullscreen(); |
345 } | 346 } |
346 | 347 |
347 content::RenderViewHost* created_view = | 348 content::RenderFrameHost* created_frame = |
348 app_window->web_contents()->GetRenderViewHost(); | 349 app_window->web_contents()->GetMainFrame(); |
349 int view_id = MSG_ROUTING_NONE; | 350 int frame_id = MSG_ROUTING_NONE; |
350 if (create_params.creator_process_id == created_view->GetProcess()->GetID()) | 351 if (create_params.creator_process_id == created_frame->GetProcess()->GetID()) |
351 view_id = created_view->GetRoutingID(); | 352 frame_id = created_frame->GetRoutingID(); |
352 | 353 |
353 base::DictionaryValue* result = new base::DictionaryValue; | 354 base::DictionaryValue* result = new base::DictionaryValue; |
354 result->Set("viewId", new base::FundamentalValue(view_id)); | 355 result->Set("frameId", new base::FundamentalValue(frame_id)); |
355 result->Set("injectTitlebar", | 356 result->Set("injectTitlebar", |
356 new base::FundamentalValue(inject_html_titlebar_)); | 357 new base::FundamentalValue(inject_html_titlebar_)); |
357 result->Set("id", new base::StringValue(app_window->window_key())); | 358 result->Set("id", new base::StringValue(app_window->window_key())); |
358 app_window->GetSerializedState(result); | 359 app_window->GetSerializedState(result); |
359 SetResult(result); | 360 SetResult(result); |
360 | 361 |
361 if (AppWindowRegistry::Get(browser_context()) | 362 if (AppWindowRegistry::Get(browser_context()) |
362 ->HadDevToolsAttached(created_view)) { | 363 ->HadDevToolsAttached(app_window->web_contents())) { |
363 AppWindowClient::Get()->OpenDevToolsWindow( | 364 AppWindowClient::Get()->OpenDevToolsWindow( |
364 app_window->web_contents(), | 365 app_window->web_contents(), |
365 base::Bind(&AppWindowCreateFunction::SendResponse, this, true)); | 366 base::Bind(&AppWindowCreateFunction::SendResponse, this, true)); |
366 return true; | 367 return true; |
367 } | 368 } |
368 | 369 |
369 SendResponse(true); | 370 SendResponse(true); |
370 app_window->WindowEventsReady(); | 371 app_window->WindowEventsReady(); |
371 | 372 |
372 return true; | 373 return true; |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 | 548 |
548 if (options.frame->as_frame_options->inactive_color.get()) { | 549 if (options.frame->as_frame_options->inactive_color.get()) { |
549 error_ = app_window_constants::kInactiveColorWithoutColor; | 550 error_ = app_window_constants::kInactiveColorWithoutColor; |
550 return false; | 551 return false; |
551 } | 552 } |
552 | 553 |
553 return true; | 554 return true; |
554 } | 555 } |
555 | 556 |
556 } // namespace extensions | 557 } // namespace extensions |
OLD | NEW |