| 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/time.h" | 8 #include "base/time.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/extensions/window_controller.h" | 10 #include "chrome/browser/extensions/window_controller.h" |
| 11 #include "chrome/browser/ui/extensions/shell_window.h" | 11 #include "chrome/browser/ui/extensions/shell_window.h" |
| 12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
| 13 #include "chrome/common/extensions/api/app_window.h" | 13 #include "chrome/common/extensions/api/app_window.h" |
| 14 #include "content/public/browser/render_process_host.h" |
| 14 #include "content/public/browser/render_view_host.h" | 15 #include "content/public/browser/render_view_host.h" |
| 15 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 16 #include "content/public/common/url_constants.h" | 17 #include "content/public/common/url_constants.h" |
| 17 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
| 18 #include "ui/gfx/rect.h" | 19 #include "ui/gfx/rect.h" |
| 19 | 20 |
| 20 namespace app_window = extensions::api::app_window; | 21 namespace app_window = extensions::api::app_window; |
| 21 namespace Create = app_window::Create; | 22 namespace Create = app_window::Create; |
| 22 | 23 |
| 23 namespace extensions { | 24 namespace extensions { |
| 24 | 25 |
| 25 namespace app_window_constants { | 26 namespace app_window_constants { |
| 26 const char kInvalidWindowId[] = | 27 const char kInvalidWindowId[] = |
| 27 "The window id can not be more than 256 characters long."; | 28 "The window id can not be more than 256 characters long."; |
| 28 }; | 29 }; |
| 29 | 30 |
| 30 const char kNoneFrameOption[] = "none"; | 31 const char kNoneFrameOption[] = "none"; |
| 31 const char kHtmlFrameOption[] = "experimental-html"; | 32 const char kHtmlFrameOption[] = "experimental-html"; |
| 32 | 33 |
| 33 bool AppWindowCreateFunction::RunImpl() { | 34 bool AppWindowCreateFunction::RunImpl() { |
| 34 scoped_ptr<Create::Params> params(Create::Params::Create(*args_)); | 35 scoped_ptr<Create::Params> params(Create::Params::Create(*args_)); |
| 35 EXTENSION_FUNCTION_VALIDATE(params.get()); | 36 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 36 | 37 |
| 37 GURL url = GetExtension()->GetResourceURL(params->url); | 38 GURL url = GetExtension()->GetResourceURL(params->url); |
| 39 // Allow absolute URLs for component apps, otherwise prepend the extension |
| 40 // path. |
| 41 if (GetExtension()->location() == extensions::Extension::COMPONENT) { |
| 42 GURL absolute = GURL(params->url); |
| 43 if (absolute.has_scheme()) |
| 44 url = absolute; |
| 45 } |
| 38 | 46 |
| 39 bool inject_html_titlebar = false; | 47 bool inject_html_titlebar = false; |
| 40 | 48 |
| 41 // TODO(jeremya): figure out a way to pass the opening WebContents through to | 49 // TODO(jeremya): figure out a way to pass the opening WebContents through to |
| 42 // ShellWindow::Create so we can set the opener at create time rather than | 50 // ShellWindow::Create so we can set the opener at create time rather than |
| 43 // with a hack in AppWindowCustomBindings::GetView(). | 51 // with a hack in AppWindowCustomBindings::GetView(). |
| 44 ShellWindow::CreateParams create_params; | 52 ShellWindow::CreateParams create_params; |
| 45 app_window::CreateWindowOptions* options = params->options.get(); | 53 app_window::CreateWindowOptions* options = params->options.get(); |
| 46 if (options) { | 54 if (options) { |
| 47 if (options->id.get()) { | 55 if (options->id.get()) { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 create_params.bounds.set_width(maximum_size.width()); | 124 create_params.bounds.set_width(maximum_size.width()); |
| 117 if (create_params.bounds.width() < minimum_size.width()) | 125 if (create_params.bounds.width() < minimum_size.width()) |
| 118 create_params.bounds.set_width(minimum_size.width()); | 126 create_params.bounds.set_width(minimum_size.width()); |
| 119 | 127 |
| 120 if (maximum_size.height() && | 128 if (maximum_size.height() && |
| 121 create_params.bounds.height() > maximum_size.height()) | 129 create_params.bounds.height() > maximum_size.height()) |
| 122 create_params.bounds.set_height(maximum_size.height()); | 130 create_params.bounds.set_height(maximum_size.height()); |
| 123 if (create_params.bounds.height() < minimum_size.height()) | 131 if (create_params.bounds.height() < minimum_size.height()) |
| 124 create_params.bounds.set_height(minimum_size.height()); | 132 create_params.bounds.set_height(minimum_size.height()); |
| 125 } | 133 } |
| 134 |
| 135 create_params.creator_process_id = |
| 136 render_view_host_->GetProcess()->GetID(); |
| 137 |
| 126 ShellWindow* shell_window = | 138 ShellWindow* shell_window = |
| 127 ShellWindow::Create(profile(), GetExtension(), url, create_params); | 139 ShellWindow::Create(profile(), GetExtension(), url, create_params); |
| 128 shell_window->GetBaseWindow()->Show(); | 140 shell_window->GetBaseWindow()->Show(); |
| 129 | 141 |
| 130 content::WebContents* created_contents = shell_window->web_contents(); | 142 content::RenderViewHost* created_view = |
| 131 int view_id = created_contents->GetRenderViewHost()->GetRoutingID(); | 143 shell_window->web_contents()->GetRenderViewHost(); |
| 144 int view_id = MSG_ROUTING_NONE; |
| 145 if (create_params.creator_process_id == created_view->GetProcess()->GetID()) |
| 146 view_id = created_view->GetRoutingID(); |
| 132 | 147 |
| 133 base::DictionaryValue* result = new base::DictionaryValue; | 148 base::DictionaryValue* result = new base::DictionaryValue; |
| 134 result->Set("viewId", base::Value::CreateIntegerValue(view_id)); | 149 result->Set("viewId", base::Value::CreateIntegerValue(view_id)); |
| 135 result->Set("injectTitlebar", | 150 result->Set("injectTitlebar", |
| 136 base::Value::CreateBooleanValue(inject_html_titlebar)); | 151 base::Value::CreateBooleanValue(inject_html_titlebar)); |
| 137 result->Set("id", base::Value::CreateStringValue(shell_window->window_key())); | 152 result->Set("id", base::Value::CreateStringValue(shell_window->window_key())); |
| 138 SetResult(result); | 153 SetResult(result); |
| 139 return true; | 154 return true; |
| 140 } | 155 } |
| 141 | 156 |
| 142 } // namespace extensions | 157 } // namespace extensions |
| OLD | NEW |