| 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.h" |
| 8 #include "apps/app_window_contents.h" | 8 #include "apps/app_window_contents.h" |
| 9 #include "apps/app_window_registry.h" | 9 #include "apps/app_window_registry.h" |
| 10 #include "apps/ui/apps_client.h" | 10 #include "apps/ui/apps_client.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/browser/devtools/devtools_window.h" | |
| 17 #include "chrome/common/chrome_switches.h" | |
| 18 #include "chrome/common/extensions/api/app_window.h" | 16 #include "chrome/common/extensions/api/app_window.h" |
| 19 #include "chrome/common/extensions/features/feature_channel.h" | |
| 20 #include "content/public/browser/notification_registrar.h" | 17 #include "content/public/browser/notification_registrar.h" |
| 21 #include "content/public/browser/notification_types.h" | 18 #include "content/public/browser/notification_types.h" |
| 22 #include "content/public/browser/render_process_host.h" | 19 #include "content/public/browser/render_process_host.h" |
| 23 #include "content/public/browser/render_view_host.h" | 20 #include "content/public/browser/render_view_host.h" |
| 24 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 25 #include "content/public/common/url_constants.h" | 22 #include "content/public/common/url_constants.h" |
| 26 #include "extensions/browser/app_window/native_app_window.h" | 23 #include "extensions/browser/app_window/native_app_window.h" |
| 27 #include "extensions/browser/extensions_browser_client.h" | 24 #include "extensions/browser/extensions_browser_client.h" |
| 28 #include "extensions/browser/image_util.h" | 25 #include "extensions/browser/image_util.h" |
| 29 #include "extensions/common/features/simple_feature.h" | 26 #include "extensions/common/features/simple_feature.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 const char kAlphaEnabledNeedsFrameNone[] = | 59 const char kAlphaEnabledNeedsFrameNone[] = |
| 63 "The alphaEnabled option can only be used with \"frame: 'none'\"."; | 60 "The alphaEnabled option can only be used with \"frame: 'none'\"."; |
| 64 } // namespace app_window_constants | 61 } // namespace app_window_constants |
| 65 | 62 |
| 66 const char kNoneFrameOption[] = "none"; | 63 const char kNoneFrameOption[] = "none"; |
| 67 // TODO(benwells): Remove HTML titlebar injection. | 64 // TODO(benwells): Remove HTML titlebar injection. |
| 68 const char kHtmlFrameOption[] = "experimental-html"; | 65 const char kHtmlFrameOption[] = "experimental-html"; |
| 69 | 66 |
| 70 namespace { | 67 namespace { |
| 71 | 68 |
| 72 // Opens an inspector window and delays the response to the | |
| 73 // AppWindowCreateFunction until the DevToolsWindow has finished loading, and is | |
| 74 // ready to stop on breakpoints in the callback. | |
| 75 class DevToolsRestorer : public base::RefCounted<DevToolsRestorer> { | |
| 76 public: | |
| 77 DevToolsRestorer(AppWindowCreateFunction* delayed_create_function, | |
| 78 content::WebContents* web_contents) | |
| 79 : delayed_create_function_(delayed_create_function) { | |
| 80 AddRef(); // Balanced in LoadCompleted. | |
| 81 DevToolsWindow* devtools_window = DevToolsWindow::OpenDevToolsWindow( | |
| 82 web_contents, | |
| 83 DevToolsToggleAction::ShowConsole()); | |
| 84 devtools_window->SetLoadCompletedCallback( | |
| 85 base::Bind(&DevToolsRestorer::LoadCompleted, this)); | |
| 86 } | |
| 87 | |
| 88 private: | |
| 89 friend class base::RefCounted<DevToolsRestorer>; | |
| 90 ~DevToolsRestorer() {} | |
| 91 | |
| 92 void LoadCompleted() { | |
| 93 delayed_create_function_->SendDelayedResponse(); | |
| 94 Release(); | |
| 95 } | |
| 96 | |
| 97 scoped_refptr<AppWindowCreateFunction> delayed_create_function_; | |
| 98 }; | |
| 99 | |
| 100 // If the same property is specified for the inner and outer bounds, raise an | 69 // If the same property is specified for the inner and outer bounds, raise an |
| 101 // error. | 70 // error. |
| 102 bool CheckBoundsConflict(const scoped_ptr<int>& inner_property, | 71 bool CheckBoundsConflict(const scoped_ptr<int>& inner_property, |
| 103 const scoped_ptr<int>& outer_property, | 72 const scoped_ptr<int>& outer_property, |
| 104 const std::string& property_name, | 73 const std::string& property_name, |
| 105 std::string* error) { | 74 std::string* error) { |
| 106 if (inner_property.get() && outer_property.get()) { | 75 if (inner_property.get() && outer_property.get()) { |
| 107 std::vector<std::string> subst; | 76 std::vector<std::string> subst; |
| 108 subst.push_back(property_name); | 77 subst.push_back(property_name); |
| 109 *error = ReplaceStringPlaceholders( | 78 *error = ReplaceStringPlaceholders( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 138 create_spec->maximum_size.set_width(*input_spec->max_width); | 107 create_spec->maximum_size.set_width(*input_spec->max_width); |
| 139 if (input_spec->max_height.get()) | 108 if (input_spec->max_height.get()) |
| 140 create_spec->maximum_size.set_height(*input_spec->max_height); | 109 create_spec->maximum_size.set_height(*input_spec->max_height); |
| 141 } | 110 } |
| 142 | 111 |
| 143 } // namespace | 112 } // namespace |
| 144 | 113 |
| 145 AppWindowCreateFunction::AppWindowCreateFunction() | 114 AppWindowCreateFunction::AppWindowCreateFunction() |
| 146 : inject_html_titlebar_(false) {} | 115 : inject_html_titlebar_(false) {} |
| 147 | 116 |
| 148 void AppWindowCreateFunction::SendDelayedResponse() { | |
| 149 SendResponse(true); | |
| 150 } | |
| 151 | |
| 152 bool AppWindowCreateFunction::RunAsync() { | 117 bool AppWindowCreateFunction::RunAsync() { |
| 153 // Don't create app window if the system is shutting down. | 118 // Don't create app window if the system is shutting down. |
| 154 if (extensions::ExtensionsBrowserClient::Get()->IsShuttingDown()) | 119 if (extensions::ExtensionsBrowserClient::Get()->IsShuttingDown()) |
| 155 return false; | 120 return false; |
| 156 | 121 |
| 157 scoped_ptr<Create::Params> params(Create::Params::Create(*args_)); | 122 scoped_ptr<Create::Params> params(Create::Params::Create(*args_)); |
| 158 EXTENSION_FUNCTION_VALIDATE(params.get()); | 123 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 159 | 124 |
| 160 GURL url = extension()->GetResourceURL(params->url); | 125 GURL url = extension()->GetResourceURL(params->url); |
| 161 // Allow absolute URLs for component apps, otherwise prepend the extension | 126 // Allow absolute URLs for component apps, otherwise prepend the extension |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 SetResult(result); | 188 SetResult(result); |
| 224 SendResponse(true); | 189 SendResponse(true); |
| 225 return true; | 190 return true; |
| 226 } | 191 } |
| 227 } | 192 } |
| 228 } | 193 } |
| 229 | 194 |
| 230 if (!GetBoundsSpec(*options, &create_params, &error_)) | 195 if (!GetBoundsSpec(*options, &create_params, &error_)) |
| 231 return false; | 196 return false; |
| 232 | 197 |
| 233 if (GetCurrentChannel() <= chrome::VersionInfo::CHANNEL_DEV || | 198 if (!apps::AppsClient::Get()->IsCurrentChannelOlderThanDev() || |
| 234 extension()->location() == extensions::Manifest::COMPONENT) { | 199 extension()->location() == extensions::Manifest::COMPONENT) { |
| 235 if (options->type == extensions::api::app_window::WINDOW_TYPE_PANEL) { | 200 if (options->type == extensions::api::app_window::WINDOW_TYPE_PANEL) { |
| 236 create_params.window_type = AppWindow::WINDOW_TYPE_PANEL; | 201 create_params.window_type = AppWindow::WINDOW_TYPE_PANEL; |
| 237 } | 202 } |
| 238 } | 203 } |
| 239 | 204 |
| 240 if (!GetFrameOptions(*options, &create_params)) | 205 if (!GetFrameOptions(*options, &create_params)) |
| 241 return false; | 206 return false; |
| 242 | 207 |
| 243 if (options->alpha_enabled.get()) { | 208 if (options->alpha_enabled.get()) { |
| 244 const char* whitelist[] = { | 209 const char* whitelist[] = { |
| 245 "0F42756099D914A026DADFA182871C015735DD95", // http://crbug.com/323773 | 210 "0F42756099D914A026DADFA182871C015735DD95", // http://crbug.com/323773 |
| 246 "2D22CDB6583FD0A13758AEBE8B15E45208B4E9A7", | 211 "2D22CDB6583FD0A13758AEBE8B15E45208B4E9A7", |
| 247 "E7E2461CE072DF036CF9592740196159E2D7C089", // http://crbug.com/356200 | 212 "E7E2461CE072DF036CF9592740196159E2D7C089", // http://crbug.com/356200 |
| 248 "A74A4D44C7CFCD8844830E6140C8D763E12DD8F3", | 213 "A74A4D44C7CFCD8844830E6140C8D763E12DD8F3", |
| 249 "312745D9BF916161191143F6490085EEA0434997", | 214 "312745D9BF916161191143F6490085EEA0434997", |
| 250 "53041A2FA309EECED01FFC751E7399186E860B2C" | 215 "53041A2FA309EECED01FFC751E7399186E860B2C" |
| 251 }; | 216 }; |
| 252 if (GetCurrentChannel() > chrome::VersionInfo::CHANNEL_DEV && | 217 if (apps::AppsClient::Get()->IsCurrentChannelOlderThanDev() && |
| 253 !extensions::SimpleFeature::IsIdInList( | 218 !extensions::SimpleFeature::IsIdInList( |
| 254 extension_id(), | 219 extension_id(), |
| 255 std::set<std::string>(whitelist, | 220 std::set<std::string>(whitelist, |
| 256 whitelist + arraysize(whitelist)))) { | 221 whitelist + arraysize(whitelist)))) { |
| 257 error_ = app_window_constants::kAlphaEnabledWrongChannel; | 222 error_ = app_window_constants::kAlphaEnabledWrongChannel; |
| 258 return false; | 223 return false; |
| 259 } | 224 } |
| 260 if (!extension()->permissions_data()->HasAPIPermission( | 225 if (!extension()->permissions_data()->HasAPIPermission( |
| 261 APIPermission::kAlphaEnabled)) { | 226 APIPermission::kAlphaEnabled)) { |
| 262 error_ = app_window_constants::kAlphaEnabledMissingPermission; | 227 error_ = app_window_constants::kAlphaEnabledMissingPermission; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 base::DictionaryValue* result = new base::DictionaryValue; | 297 base::DictionaryValue* result = new base::DictionaryValue; |
| 333 result->Set("viewId", new base::FundamentalValue(view_id)); | 298 result->Set("viewId", new base::FundamentalValue(view_id)); |
| 334 result->Set("injectTitlebar", | 299 result->Set("injectTitlebar", |
| 335 new base::FundamentalValue(inject_html_titlebar_)); | 300 new base::FundamentalValue(inject_html_titlebar_)); |
| 336 result->Set("id", new base::StringValue(app_window->window_key())); | 301 result->Set("id", new base::StringValue(app_window->window_key())); |
| 337 app_window->GetSerializedState(result); | 302 app_window->GetSerializedState(result); |
| 338 SetResult(result); | 303 SetResult(result); |
| 339 | 304 |
| 340 if (apps::AppWindowRegistry::Get(browser_context()) | 305 if (apps::AppWindowRegistry::Get(browser_context()) |
| 341 ->HadDevToolsAttached(created_view)) { | 306 ->HadDevToolsAttached(created_view)) { |
| 342 new DevToolsRestorer(this, app_window->web_contents()); | 307 apps::AppsClient::Get()->OpenDevToolsWindow( |
| 308 app_window->web_contents(), |
| 309 base::Bind(&AppWindowCreateFunction::SendResponse, this, true)); |
| 343 return true; | 310 return true; |
| 344 } | 311 } |
| 345 | 312 |
| 346 SendResponse(true); | 313 SendResponse(true); |
| 347 app_window->WindowEventsReady(); | 314 app_window->WindowEventsReady(); |
| 348 | 315 |
| 349 return true; | 316 return true; |
| 350 } | 317 } |
| 351 | 318 |
| 352 bool AppWindowCreateFunction::GetBoundsSpec( | 319 bool AppWindowCreateFunction::GetBoundsSpec( |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 | 491 |
| 525 if (options.frame->as_frame_options->inactive_color.get()) { | 492 if (options.frame->as_frame_options->inactive_color.get()) { |
| 526 error_ = app_window_constants::kInactiveColorWithoutColor; | 493 error_ = app_window_constants::kInactiveColorWithoutColor; |
| 527 return false; | 494 return false; |
| 528 } | 495 } |
| 529 | 496 |
| 530 return true; | 497 return true; |
| 531 } | 498 } |
| 532 | 499 |
| 533 } // namespace extensions | 500 } // namespace extensions |
| OLD | NEW |