diff options
author | hashimoto <hashimoto@chromium.org> | 2014-09-04 19:38:31 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-05 02:41:17 +0000 |
commit | f784afd4de115dba788b0adc7034a15846765ff5 (patch) | |
tree | 75117182c4981f46f725cafe2d894f626b2aa71e /chrome | |
parent | 81145970e2b1c0ceff32af1de3239c48cb4b1d7e (diff) | |
download | chromium_src-f784afd4de115dba788b0adc7034a15846765ff5.zip chromium_src-f784afd4de115dba788b0adc7034a15846765ff5.tar.gz chromium_src-f784afd4de115dba788b0adc7034a15846765ff5.tar.bz2 |
Move app.window API implementation to extensions
Move files:
-Move chrome/browser/extensions/api/app_window/* to extensions/browser.
-Move app_window.idl, app_window_custom_bindings.{cc,h}, app_window_custom_bindings.js to extensions.
-Move window_controls.js and window_controls_template.html to extensions.
Move switches and code:
- Move kEnableAppWindowControls switch to extensions/common/switches.h.
- Move dummy WebContentsModalDialogManager::CreateNativeWebModalManager implementation from athena's web_contents_view_delegate_factory_impl.cc to a new file shell_web_contents_modal_dialog_manager.cc.
Fix dispatchers:
- Move code from chrome_extensions_dispatcher_delegate.cc to extensions/renderer/dispatcher.cc
BUG=387288
Review URL: https://codereview.chromium.org/534163002
Cr-Commit-Position: refs/heads/master@{#293409}
Diffstat (limited to 'chrome')
22 files changed, 6 insertions, 1890 deletions
diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc index 612d4e7..df8639f 100644 --- a/chrome/browser/about_flags.cc +++ b/chrome/browser/about_flags.cc @@ -684,7 +684,7 @@ const Experiment kExperiments[] = { IDS_FLAGS_ENABLE_APP_WINDOW_CONTROLS_NAME, IDS_FLAGS_ENABLE_APP_WINDOW_CONTROLS_DESCRIPTION, kOsDesktop, - SINGLE_VALUE_TYPE(switches::kEnableAppWindowControls) + SINGLE_VALUE_TYPE(extensions::switches::kEnableAppWindowControls) }, { "disable-hyperlink-auditing", diff --git a/chrome/browser/apps/window_controls_browsertest.cc b/chrome/browser/apps/window_controls_browsertest.cc index c88ec8c..7a6936e 100644 --- a/chrome/browser/apps/window_controls_browsertest.cc +++ b/chrome/browser/apps/window_controls_browsertest.cc @@ -5,15 +5,15 @@ #include "chrome/browser/apps/app_browsertest_util.h" #include "chrome/browser/extensions/extension_test_message_listener.h" #include "chrome/browser/profiles/profile.h" -#include "chrome/common/chrome_switches.h" #include "content/public/test/browser_test_utils.h" #include "extensions/browser/process_manager.h" +#include "extensions/common/switches.h" class WindowControlsTest : public extensions::PlatformAppBrowserTest { protected: virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); - command_line->AppendSwitch(switches::kEnableAppWindowControls); + command_line->AppendSwitch(extensions::switches::kEnableAppWindowControls); } content::WebContents* GetWebContentsForExtensionWindow( const extensions::Extension* extension); diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc index 654ce14..ad2739f 100644 --- a/chrome/browser/chrome_content_browser_client.cc +++ b/chrome/browser/chrome_content_browser_client.cc @@ -1331,6 +1331,7 @@ void ChromeContentBrowserClient::AppendExtraCommandLineSwitches( extensions::switches::kAllowHTTPBackgroundPage, extensions::switches::kAllowLegacyExtensionManifests, extensions::switches::kEnableAppView, + extensions::switches::kEnableAppWindowControls, extensions::switches::kEnableEmbeddedExtensionOptions, extensions::switches::kEnableExperimentalExtensionApis, extensions::switches::kEnableScriptsRequireAction, @@ -1341,7 +1342,6 @@ void ChromeContentBrowserClient::AppendExtraCommandLineSwitches( switches::kCloudPrintURL, switches::kCloudPrintXmppEndpoint, switches::kDisableBundledPpapiFlash, - switches::kEnableAppWindowControls, switches::kEnableBenchmarking, switches::kEnableNaCl, #if !defined(DISABLE_NACL) diff --git a/chrome/browser/extensions/api/app_current_window_internal/app_current_window_internal_api.cc b/chrome/browser/extensions/api/app_current_window_internal/app_current_window_internal_api.cc index 2f826d7..28ffe4e 100644 --- a/chrome/browser/extensions/api/app_current_window_internal/app_current_window_internal_api.cc +++ b/chrome/browser/extensions/api/app_current_window_internal/app_current_window_internal_api.cc @@ -7,7 +7,6 @@ #include "base/command_line.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/extensions/api/app_current_window_internal.h" -#include "chrome/common/extensions/api/app_window.h" #include "chrome/common/extensions/features/feature_channel.h" #include "extensions/browser/app_window/app_window.h" #include "extensions/browser/app_window/app_window_registry.h" diff --git a/chrome/browser/extensions/api/app_window/OWNERS b/chrome/browser/extensions/api/app_window/OWNERS deleted file mode 100644 index 79c559b..0000000 --- a/chrome/browser/extensions/api/app_window/OWNERS +++ /dev/null @@ -1,2 +0,0 @@ -benwells@chromium.org -scheib@chromium.org diff --git a/chrome/browser/extensions/api/app_window/app_window_api.cc b/chrome/browser/extensions/api/app_window/app_window_api.cc deleted file mode 100644 index 9b591a7..0000000 --- a/chrome/browser/extensions/api/app_window/app_window_api.cc +++ /dev/null @@ -1,497 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/extensions/api/app_window/app_window_api.h" - -#include "base/command_line.h" -#include "base/strings/string_number_conversions.h" -#include "base/strings/string_util.h" -#include "base/time/time.h" -#include "base/values.h" -#include "chrome/common/extensions/api/app_window.h" -#include "content/public/browser/notification_registrar.h" -#include "content/public/browser/notification_types.h" -#include "content/public/browser/render_process_host.h" -#include "content/public/browser/render_view_host.h" -#include "content/public/browser/web_contents.h" -#include "content/public/common/url_constants.h" -#include "extensions/browser/app_window/app_window.h" -#include "extensions/browser/app_window/app_window_contents.h" -#include "extensions/browser/app_window/app_window_registry.h" -#include "extensions/browser/app_window/apps_client.h" -#include "extensions/browser/app_window/native_app_window.h" -#include "extensions/browser/extensions_browser_client.h" -#include "extensions/browser/image_util.h" -#include "extensions/common/features/simple_feature.h" -#include "extensions/common/permissions/permissions_data.h" -#include "extensions/common/switches.h" -#include "third_party/skia/include/core/SkColor.h" -#include "ui/base/ui_base_types.h" -#include "ui/gfx/rect.h" -#include "url/gurl.h" - -namespace app_window = extensions::api::app_window; -namespace Create = app_window::Create; - -namespace extensions { - -namespace app_window_constants { -const char kInvalidWindowId[] = - "The window id can not be more than 256 characters long."; -const char kInvalidColorSpecification[] = - "The color specification could not be parsed."; -const char kColorWithFrameNone[] = "Windows with no frame cannot have a color."; -const char kInactiveColorWithoutColor[] = - "frame.inactiveColor must be used with frame.color."; -const char kConflictingBoundsOptions[] = - "The $1 property cannot be specified for both inner and outer bounds."; -const char kAlwaysOnTopPermission[] = - "The \"app.window.alwaysOnTop\" permission is required."; -const char kInvalidUrlParameter[] = - "The URL used for window creation must be local for security reasons."; -const char kAlphaEnabledWrongChannel[] = - "The alphaEnabled option requires dev channel or newer."; -const char kAlphaEnabledMissingPermission[] = - "The alphaEnabled option requires app.window.alpha permission."; -const char kAlphaEnabledNeedsFrameNone[] = - "The alphaEnabled option can only be used with \"frame: 'none'\"."; -} // namespace app_window_constants - -const char kNoneFrameOption[] = "none"; - // TODO(benwells): Remove HTML titlebar injection. -const char kHtmlFrameOption[] = "experimental-html"; - -namespace { - -// If the same property is specified for the inner and outer bounds, raise an -// error. -bool CheckBoundsConflict(const scoped_ptr<int>& inner_property, - const scoped_ptr<int>& outer_property, - const std::string& property_name, - std::string* error) { - if (inner_property.get() && outer_property.get()) { - std::vector<std::string> subst; - subst.push_back(property_name); - *error = ReplaceStringPlaceholders( - app_window_constants::kConflictingBoundsOptions, subst, NULL); - return false; - } - - return true; -} - -// Copy over the bounds specification properties from the API to the -// AppWindow::CreateParams. -void CopyBoundsSpec( - const extensions::api::app_window::BoundsSpecification* input_spec, - AppWindow::BoundsSpecification* create_spec) { - if (!input_spec) - return; - - if (input_spec->left.get()) - create_spec->bounds.set_x(*input_spec->left); - if (input_spec->top.get()) - create_spec->bounds.set_y(*input_spec->top); - if (input_spec->width.get()) - create_spec->bounds.set_width(*input_spec->width); - if (input_spec->height.get()) - create_spec->bounds.set_height(*input_spec->height); - if (input_spec->min_width.get()) - create_spec->minimum_size.set_width(*input_spec->min_width); - if (input_spec->min_height.get()) - create_spec->minimum_size.set_height(*input_spec->min_height); - if (input_spec->max_width.get()) - create_spec->maximum_size.set_width(*input_spec->max_width); - if (input_spec->max_height.get()) - create_spec->maximum_size.set_height(*input_spec->max_height); -} - -} // namespace - -AppWindowCreateFunction::AppWindowCreateFunction() - : inject_html_titlebar_(false) {} - -bool AppWindowCreateFunction::RunAsync() { - // Don't create app window if the system is shutting down. - if (extensions::ExtensionsBrowserClient::Get()->IsShuttingDown()) - return false; - - scoped_ptr<Create::Params> params(Create::Params::Create(*args_)); - EXTENSION_FUNCTION_VALIDATE(params.get()); - - GURL url = extension()->GetResourceURL(params->url); - // Allow absolute URLs for component apps, otherwise prepend the extension - // path. - GURL absolute = GURL(params->url); - if (absolute.has_scheme()) { - if (extension()->location() == extensions::Manifest::COMPONENT) { - url = absolute; - } else { - // Show error when url passed isn't local. - error_ = app_window_constants::kInvalidUrlParameter; - return false; - } - } - - // TODO(jeremya): figure out a way to pass the opening WebContents through to - // AppWindow::Create so we can set the opener at create time rather than - // with a hack in AppWindowCustomBindings::GetView(). - AppWindow::CreateParams create_params; - app_window::CreateWindowOptions* options = params->options.get(); - if (options) { - if (options->id.get()) { - // TODO(mek): use URL if no id specified? - // Limit length of id to 256 characters. - if (options->id->length() > 256) { - error_ = app_window_constants::kInvalidWindowId; - return false; - } - - create_params.window_key = *options->id; - - if (options->singleton && *options->singleton == false) { - WriteToConsole( - content::CONSOLE_MESSAGE_LEVEL_WARNING, - "The 'singleton' option in chrome.apps.window.create() is deprecated!" - " Change your code to no longer rely on this."); - } - - if (!options->singleton || *options->singleton) { - AppWindow* window = AppWindowRegistry::Get(browser_context()) - ->GetAppWindowForAppAndKey( - extension_id(), create_params.window_key); - if (window) { - content::RenderViewHost* created_view = - window->web_contents()->GetRenderViewHost(); - int view_id = MSG_ROUTING_NONE; - if (render_view_host_->GetProcess()->GetID() == - created_view->GetProcess()->GetID()) { - view_id = created_view->GetRoutingID(); - } - - if (options->hidden.get() && !*options->hidden.get()) { - if (options->focused.get() && !*options->focused.get()) - window->Show(AppWindow::SHOW_INACTIVE); - else - window->Show(AppWindow::SHOW_ACTIVE); - } - - base::DictionaryValue* result = new base::DictionaryValue; - result->Set("viewId", new base::FundamentalValue(view_id)); - window->GetSerializedState(result); - result->SetBoolean("existingWindow", true); - // TODO(benwells): Remove HTML titlebar injection. - result->SetBoolean("injectTitlebar", false); - SetResult(result); - SendResponse(true); - return true; - } - } - } - - if (!GetBoundsSpec(*options, &create_params, &error_)) - return false; - - if (!AppsClient::Get()->IsCurrentChannelOlderThanDev() || - extension()->location() == extensions::Manifest::COMPONENT) { - if (options->type == extensions::api::app_window::WINDOW_TYPE_PANEL) { - create_params.window_type = AppWindow::WINDOW_TYPE_PANEL; - } - } - - if (!GetFrameOptions(*options, &create_params)) - return false; - - if (options->alpha_enabled.get()) { - const char* whitelist[] = { - "0F42756099D914A026DADFA182871C015735DD95", // http://crbug.com/323773 - "2D22CDB6583FD0A13758AEBE8B15E45208B4E9A7", - "E7E2461CE072DF036CF9592740196159E2D7C089", // http://crbug.com/356200 - "A74A4D44C7CFCD8844830E6140C8D763E12DD8F3", - "312745D9BF916161191143F6490085EEA0434997", - "53041A2FA309EECED01FFC751E7399186E860B2C" - }; - if (AppsClient::Get()->IsCurrentChannelOlderThanDev() && - !extensions::SimpleFeature::IsIdInList( - extension_id(), - std::set<std::string>(whitelist, - whitelist + arraysize(whitelist)))) { - error_ = app_window_constants::kAlphaEnabledWrongChannel; - return false; - } - if (!extension()->permissions_data()->HasAPIPermission( - APIPermission::kAlphaEnabled)) { - error_ = app_window_constants::kAlphaEnabledMissingPermission; - return false; - } - if (create_params.frame != AppWindow::FRAME_NONE) { - error_ = app_window_constants::kAlphaEnabledNeedsFrameNone; - return false; - } -#if defined(USE_AURA) - create_params.alpha_enabled = *options->alpha_enabled; -#else - // Transparency is only supported on Aura. - // Fallback to creating an opaque window (by ignoring alphaEnabled). -#endif - } - - if (options->hidden.get()) - create_params.hidden = *options->hidden.get(); - - if (options->resizable.get()) - create_params.resizable = *options->resizable.get(); - - if (options->always_on_top.get()) { - create_params.always_on_top = *options->always_on_top.get(); - - if (create_params.always_on_top && - !extension()->permissions_data()->HasAPIPermission( - APIPermission::kAlwaysOnTopWindows)) { - error_ = app_window_constants::kAlwaysOnTopPermission; - return false; - } - } - - if (options->focused.get()) - create_params.focused = *options->focused.get(); - - if (options->type != extensions::api::app_window::WINDOW_TYPE_PANEL) { - switch (options->state) { - case extensions::api::app_window::STATE_NONE: - case extensions::api::app_window::STATE_NORMAL: - break; - case extensions::api::app_window::STATE_FULLSCREEN: - create_params.state = ui::SHOW_STATE_FULLSCREEN; - break; - case extensions::api::app_window::STATE_MAXIMIZED: - create_params.state = ui::SHOW_STATE_MAXIMIZED; - break; - case extensions::api::app_window::STATE_MINIMIZED: - create_params.state = ui::SHOW_STATE_MINIMIZED; - break; - } - } - } - - create_params.creator_process_id = - render_view_host_->GetProcess()->GetID(); - - AppWindow* app_window = - AppsClient::Get()->CreateAppWindow(browser_context(), extension()); - app_window->Init(url, new AppWindowContentsImpl(app_window), create_params); - - if (ExtensionsBrowserClient::Get()->IsRunningInForcedAppMode()) - app_window->ForcedFullscreen(); - - content::RenderViewHost* created_view = - app_window->web_contents()->GetRenderViewHost(); - int view_id = MSG_ROUTING_NONE; - if (create_params.creator_process_id == created_view->GetProcess()->GetID()) - view_id = created_view->GetRoutingID(); - - base::DictionaryValue* result = new base::DictionaryValue; - result->Set("viewId", new base::FundamentalValue(view_id)); - result->Set("injectTitlebar", - new base::FundamentalValue(inject_html_titlebar_)); - result->Set("id", new base::StringValue(app_window->window_key())); - app_window->GetSerializedState(result); - SetResult(result); - - if (AppWindowRegistry::Get(browser_context()) - ->HadDevToolsAttached(created_view)) { - AppsClient::Get()->OpenDevToolsWindow( - app_window->web_contents(), - base::Bind(&AppWindowCreateFunction::SendResponse, this, true)); - return true; - } - - SendResponse(true); - app_window->WindowEventsReady(); - - return true; -} - -bool AppWindowCreateFunction::GetBoundsSpec( - const extensions::api::app_window::CreateWindowOptions& options, - AppWindow::CreateParams* params, - std::string* error) { - DCHECK(params); - DCHECK(error); - - if (options.inner_bounds.get() || options.outer_bounds.get()) { - // Parse the inner and outer bounds specifications. If developers use the - // new API, the deprecated fields will be ignored - do not attempt to merge - // them. - - const extensions::api::app_window::BoundsSpecification* inner_bounds = - options.inner_bounds.get(); - const extensions::api::app_window::BoundsSpecification* outer_bounds = - options.outer_bounds.get(); - if (inner_bounds && outer_bounds) { - if (!CheckBoundsConflict( - inner_bounds->left, outer_bounds->left, "left", error)) { - return false; - } - if (!CheckBoundsConflict( - inner_bounds->top, outer_bounds->top, "top", error)) { - return false; - } - if (!CheckBoundsConflict( - inner_bounds->width, outer_bounds->width, "width", error)) { - return false; - } - if (!CheckBoundsConflict( - inner_bounds->height, outer_bounds->height, "height", error)) { - return false; - } - if (!CheckBoundsConflict(inner_bounds->min_width, - outer_bounds->min_width, - "minWidth", - error)) { - return false; - } - if (!CheckBoundsConflict(inner_bounds->min_height, - outer_bounds->min_height, - "minHeight", - error)) { - return false; - } - if (!CheckBoundsConflict(inner_bounds->max_width, - outer_bounds->max_width, - "maxWidth", - error)) { - return false; - } - if (!CheckBoundsConflict(inner_bounds->max_height, - outer_bounds->max_height, - "maxHeight", - error)) { - return false; - } - } - - CopyBoundsSpec(inner_bounds, &(params->content_spec)); - CopyBoundsSpec(outer_bounds, &(params->window_spec)); - } else { - // Parse deprecated fields. - // Due to a bug in NativeAppWindow::GetFrameInsets() on Windows and ChromeOS - // the bounds set the position of the window and the size of the content. - // This will be preserved as apps may be relying on this behavior. - - if (options.default_width.get()) - params->content_spec.bounds.set_width(*options.default_width.get()); - if (options.default_height.get()) - params->content_spec.bounds.set_height(*options.default_height.get()); - if (options.default_left.get()) - params->window_spec.bounds.set_x(*options.default_left.get()); - if (options.default_top.get()) - params->window_spec.bounds.set_y(*options.default_top.get()); - - if (options.width.get()) - params->content_spec.bounds.set_width(*options.width.get()); - if (options.height.get()) - params->content_spec.bounds.set_height(*options.height.get()); - if (options.left.get()) - params->window_spec.bounds.set_x(*options.left.get()); - if (options.top.get()) - params->window_spec.bounds.set_y(*options.top.get()); - - if (options.bounds.get()) { - app_window::ContentBounds* bounds = options.bounds.get(); - if (bounds->width.get()) - params->content_spec.bounds.set_width(*bounds->width.get()); - if (bounds->height.get()) - params->content_spec.bounds.set_height(*bounds->height.get()); - if (bounds->left.get()) - params->window_spec.bounds.set_x(*bounds->left.get()); - if (bounds->top.get()) - params->window_spec.bounds.set_y(*bounds->top.get()); - } - - gfx::Size& minimum_size = params->content_spec.minimum_size; - if (options.min_width.get()) - minimum_size.set_width(*options.min_width); - if (options.min_height.get()) - minimum_size.set_height(*options.min_height); - gfx::Size& maximum_size = params->content_spec.maximum_size; - if (options.max_width.get()) - maximum_size.set_width(*options.max_width); - if (options.max_height.get()) - maximum_size.set_height(*options.max_height); - } - - return true; -} - -AppWindow::Frame AppWindowCreateFunction::GetFrameFromString( - const std::string& frame_string) { - if (frame_string == kHtmlFrameOption && - (extension()->permissions_data()->HasAPIPermission( - APIPermission::kExperimental) || - CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableExperimentalExtensionApis))) { - inject_html_titlebar_ = true; - return AppWindow::FRAME_NONE; - } - - if (frame_string == kNoneFrameOption) - return AppWindow::FRAME_NONE; - - return AppWindow::FRAME_CHROME; -} - -bool AppWindowCreateFunction::GetFrameOptions( - const app_window::CreateWindowOptions& options, - AppWindow::CreateParams* create_params) { - if (!options.frame) - return true; - - DCHECK(options.frame->as_string || options.frame->as_frame_options); - if (options.frame->as_string) { - create_params->frame = GetFrameFromString(*options.frame->as_string); - return true; - } - - if (options.frame->as_frame_options->type) - create_params->frame = - GetFrameFromString(*options.frame->as_frame_options->type); - - if (options.frame->as_frame_options->color.get()) { - if (create_params->frame != AppWindow::FRAME_CHROME) { - error_ = app_window_constants::kColorWithFrameNone; - return false; - } - - if (!image_util::ParseCSSColorString( - *options.frame->as_frame_options->color, - &create_params->active_frame_color)) { - error_ = app_window_constants::kInvalidColorSpecification; - return false; - } - - create_params->has_frame_color = true; - create_params->inactive_frame_color = create_params->active_frame_color; - - if (options.frame->as_frame_options->inactive_color.get()) { - if (!image_util::ParseCSSColorString( - *options.frame->as_frame_options->inactive_color, - &create_params->inactive_frame_color)) { - error_ = app_window_constants::kInvalidColorSpecification; - return false; - } - } - - return true; - } - - if (options.frame->as_frame_options->inactive_color.get()) { - error_ = app_window_constants::kInactiveColorWithoutColor; - return false; - } - - return true; -} - -} // namespace extensions diff --git a/chrome/browser/extensions/api/app_window/app_window_api.h b/chrome/browser/extensions/api/app_window/app_window_api.h deleted file mode 100644 index 1648182..0000000 --- a/chrome/browser/extensions/api/app_window/app_window_api.h +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_EXTENSIONS_API_APP_WINDOW_APP_WINDOW_API_H_ -#define CHROME_BROWSER_EXTENSIONS_API_APP_WINDOW_APP_WINDOW_API_H_ - -#include "extensions/browser/app_window/app_window.h" -#include "extensions/browser/extension_function.h" - -namespace extensions { - -namespace api { -namespace app_window { -struct CreateWindowOptions; -} -} - -class AppWindowCreateFunction : public AsyncExtensionFunction { - public: - AppWindowCreateFunction(); - DECLARE_EXTENSION_FUNCTION("app.window.create", APP_WINDOW_CREATE) - - protected: - virtual ~AppWindowCreateFunction() {} - virtual bool RunAsync() OVERRIDE; - - private: - bool GetBoundsSpec( - const extensions::api::app_window::CreateWindowOptions& options, - AppWindow::CreateParams* params, - std::string* error); - - AppWindow::Frame GetFrameFromString(const std::string& frame_string); - bool GetFrameOptions( - const extensions::api::app_window::CreateWindowOptions& options, - AppWindow::CreateParams* create_params); - void UpdateFrameOptionsForChannel(AppWindow::CreateParams* create_params); - - bool inject_html_titlebar_; -}; - -} // namespace extensions - -#endif // CHROME_BROWSER_EXTENSIONS_API_APP_WINDOW_APP_WINDOW_API_H_ diff --git a/chrome/browser/extensions/api/app_window/app_window_apitest.cc b/chrome/browser/extensions/api/app_window/app_window_apitest.cc deleted file mode 100644 index 6d63e15..0000000 --- a/chrome/browser/extensions/api/app_window/app_window_apitest.cc +++ /dev/null @@ -1,163 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/run_loop.h" -#include "base/strings/string_number_conversions.h" -#include "chrome/browser/apps/app_browsertest_util.h" -#include "chrome/browser/extensions/extension_test_message_listener.h" -#include "chrome/browser/ui/browser.h" -#include "chrome/common/extensions/features/feature_channel.h" -#include "chrome/test/base/testing_profile.h" -#include "extensions/browser/app_window/app_window.h" -#include "extensions/browser/app_window/app_window_registry.h" -#include "extensions/browser/app_window/native_app_window.h" -#include "ui/base/base_window.h" -#include "ui/gfx/rect.h" - -#if defined(OS_WIN) -#include "ui/base/win/shell.h" -#endif - -namespace extensions { - -namespace { - -class TestAppWindowRegistryObserver : public AppWindowRegistry::Observer { - public: - explicit TestAppWindowRegistryObserver(Profile* profile) - : profile_(profile), icon_updates_(0) { - AppWindowRegistry::Get(profile_)->AddObserver(this); - } - virtual ~TestAppWindowRegistryObserver() { - AppWindowRegistry::Get(profile_)->RemoveObserver(this); - } - - // Overridden from AppWindowRegistry::Observer: - virtual void OnAppWindowIconChanged(AppWindow* app_window) OVERRIDE { - ++icon_updates_; - } - - int icon_updates() { return icon_updates_; } - - private: - Profile* profile_; - int icon_updates_; - - DISALLOW_COPY_AND_ASSIGN(TestAppWindowRegistryObserver); -}; - -} // namespace - -// Tests chrome.app.window.setIcon. -IN_PROC_BROWSER_TEST_F(ExperimentalPlatformAppBrowserTest, WindowsApiSetIcon) { - scoped_ptr<TestAppWindowRegistryObserver> test_observer( - new TestAppWindowRegistryObserver(browser()->profile())); - ExtensionTestMessageListener listener("ready", true); - - // Launch the app and wait for it to be ready. - LoadAndLaunchPlatformApp("windows_api_set_icon", &listener); - EXPECT_EQ(0, test_observer->icon_updates()); - listener.Reply(""); - - // Now wait until the WebContent has decoded the icon and chrome has - // processed it. This needs to be in a loop since the renderer runs in a - // different process. - while (test_observer->icon_updates() < 1) { - base::RunLoop run_loop; - run_loop.RunUntilIdle(); - } - AppWindow* app_window = GetFirstAppWindow(); - ASSERT_TRUE(app_window); - EXPECT_NE(std::string::npos, - app_window->app_icon_url().spec().find("icon.png")); - EXPECT_EQ(1, test_observer->icon_updates()); -} - -// TODO(asargent) - Figure out what to do about the fact that minimize events -// don't work under ubuntu unity. -// (crbug.com/162794 and https://bugs.launchpad.net/unity/+bug/998073). -// TODO(linux_aura) http://crbug.com/163931 -// Flaky on Mac, http://crbug.com/232330 -#if defined(TOOLKIT_VIEWS) && !(defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)) - -IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiProperties) { - EXPECT_TRUE( - RunExtensionTest("platform_apps/windows_api_properties")) << message_; -} - -#endif // defined(TOOLKIT_VIEWS) - -IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, - WindowsApiAlwaysOnTopWithPermissions) { - EXPECT_TRUE(RunPlatformAppTest( - "platform_apps/windows_api_always_on_top/has_permissions")) << message_; -} - -IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, - WindowsApiAlwaysOnTopWithOldPermissions) { - EXPECT_TRUE(RunPlatformAppTest( - "platform_apps/windows_api_always_on_top/has_old_permissions")) - << message_; -} - -IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, - WindowsApiAlwaysOnTopNoPermissions) { - EXPECT_TRUE(RunPlatformAppTest( - "platform_apps/windows_api_always_on_top/no_permissions")) << message_; -} - -IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiGet) { - EXPECT_TRUE(RunPlatformAppTest("platform_apps/windows_api_get")) - << message_; -} - -IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiSetShape) { - EXPECT_TRUE(RunPlatformAppTest("platform_apps/windows_api_shape")) - << message_; -} - -IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, - WindowsApiAlphaEnabledHasPermissions) { - const char* no_alpha_dir = - "platform_apps/windows_api_alpha_enabled/has_permissions_no_alpha"; - const char* test_dir = no_alpha_dir; - -#if defined(USE_AURA) && (defined(OS_CHROMEOS) || !defined(OS_LINUX)) - test_dir = - "platform_apps/windows_api_alpha_enabled/has_permissions_has_alpha"; -#if defined(OS_WIN) - if (!ui::win::IsAeroGlassEnabled()) { - test_dir = no_alpha_dir; - } -#endif // OS_WIN -#endif // USE_AURA && (OS_CHROMEOS || !OS_LINUX) - - EXPECT_TRUE(RunPlatformAppTest(test_dir)) << message_; -} - -IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, - WindowsApiAlphaEnabledNoPermissions) { - EXPECT_TRUE(RunPlatformAppTest( - "platform_apps/windows_api_alpha_enabled/no_permissions")) - << message_; -} - -IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiAlphaEnabledInStable) { - extensions::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_STABLE); - EXPECT_TRUE(RunPlatformAppTestWithFlags( - "platform_apps/windows_api_alpha_enabled/in_stable", - // Ignore manifest warnings because the extension will not load at all - // in stable. - kFlagIgnoreManifestWarnings)) - << message_; -} - -IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, - WindowsApiAlphaEnabledWrongFrameType) { - EXPECT_TRUE(RunPlatformAppTest( - "platform_apps/windows_api_alpha_enabled/wrong_frame_type")) - << message_; -} - -} // namespace extensions diff --git a/chrome/chrome_browser_extensions.gypi b/chrome/chrome_browser_extensions.gypi index f9d6e77..b5249d0 100644 --- a/chrome/chrome_browser_extensions.gypi +++ b/chrome/chrome_browser_extensions.gypi @@ -104,8 +104,6 @@ 'browser/extensions/api/alarms/alarms_api.h', 'browser/extensions/api/app_current_window_internal/app_current_window_internal_api.cc', 'browser/extensions/api/app_current_window_internal/app_current_window_internal_api.h', - 'browser/extensions/api/app_window/app_window_api.cc', - 'browser/extensions/api/app_window/app_window_api.h', 'browser/extensions/api/audio/audio_api.cc', 'browser/extensions/api/audio/audio_api.h', 'browser/extensions/api/audio/audio_service.h', diff --git a/chrome/chrome_renderer.gypi b/chrome/chrome_renderer.gypi index 285cdf3..81c6a6a 100644 --- a/chrome/chrome_renderer.gypi +++ b/chrome/chrome_renderer.gypi @@ -123,8 +123,6 @@ 'chrome_renderer_extensions_sources': [ 'renderer/extensions/app_bindings.cc', 'renderer/extensions/app_bindings.h', - 'renderer/extensions/app_window_custom_bindings.cc', - 'renderer/extensions/app_window_custom_bindings.h', 'renderer/extensions/automation_internal_custom_bindings.cc', 'renderer/extensions/automation_internal_custom_bindings.h', 'renderer/extensions/chrome_v8_extension_handler.cc', @@ -149,7 +147,6 @@ 'renderer/extensions/webstore_bindings.h', 'renderer/resources/extensions/app_custom_bindings.js', 'renderer/resources/extensions/app_view.js', - 'renderer/resources/extensions/app_window_custom_bindings.js', 'renderer/resources/extensions/automation_custom_bindings.js', 'renderer/resources/extensions/browser_action_custom_bindings.js', 'renderer/resources/extensions/chrome_direct_setting.js', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 3227fc3..4b83c8b 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -879,6 +879,7 @@ '../components/autofill/content/renderer/test_password_generation_agent.h', '../components/autofill/content/renderer/test_password_generation_agent.cc', # TODO(rockot): Remove this once extensions_browsertests exists. + '../extensions/browser/api/app_window/app_window_apitest.cc', '../extensions/browser/api/bluetooth/bluetooth_apitest.cc', '../extensions/browser/api/bluetooth/bluetooth_private_apitest.cc', '../extensions/browser/api/bluetooth_low_energy/bluetooth_low_energy_apitest.cc', @@ -1075,7 +1076,6 @@ 'browser/extensions/alert_apitest.cc', 'browser/extensions/all_urls_apitest.cc', 'browser/extensions/api/activity_log_private/activity_log_private_apitest.cc', - 'browser/extensions/api/app_window/app_window_apitest.cc', 'browser/extensions/api/audio/audio_apitest.cc', 'browser/extensions/api/automation/automation_apitest.cc', 'browser/extensions/api/autotest_private/autotest_private_apitest.cc', diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index 1971f5ba..64b0337 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -399,9 +399,6 @@ extern const char kEasyUnlockAppPath[] = "easy-unlock-app-path"; // If set, the app list will be enabled as if enabled from CWS. const char kEnableAppList[] = "enable-app-list"; -// Enables the <window-controls> tag in platform apps. -const char kEnableAppWindowControls[] = "enable-app-window-controls"; - // Enable OS integration for Chrome app file associations. const char kEnableAppsFileAssociations[] = "enable-apps-file-associations"; diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index 4ad34ff..2c70bf5 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -116,7 +116,6 @@ extern const char kDnsPrefetchDisable[]; extern const char kDumpBrowserHistograms[]; extern const char kEasyUnlockAppPath[]; extern const char kEnableAppList[]; -extern const char kEnableAppWindowControls[]; extern const char kEnableAppsFileAssociations[]; extern const char kEnableAsyncDns[]; extern const char kEnableAuthNegotiatePort[]; diff --git a/chrome/common/extensions/api/app_window.idl b/chrome/common/extensions/api/app_window.idl deleted file mode 100644 index caff663..0000000 --- a/chrome/common/extensions/api/app_window.idl +++ /dev/null @@ -1,460 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Use the <code>chrome.app.window</code> API to create windows. Windows -// have an optional frame with title bar and size controls. They are not -// associated with any Chrome browser windows. See the <a -// href="https://github.com/GoogleChrome/chrome-app-samples/tree/master/window-state"> -// Window State Sample</a> for a demonstration of these options. -namespace app.window { - - // Previously named Bounds. - dictionary ContentBounds { - long? left; - long? top; - long? width; - long? height; - }; - - dictionary BoundsSpecification { - // The X coordinate of the content or window. - long? left; - - // The Y coordinate of the content or window. - long? top; - - // The width of the content or window. - long? width; - - // The height of the content or window. - long? height; - - // The minimum width of the content or window. - long? minWidth; - - // The minimum height of the content or window. - long? minHeight; - - // The maximum width of the content or window. - long? maxWidth; - - // The maximum height of the content or window. - long? maxHeight; - }; - - dictionary Bounds { - // This property can be used to read or write the current X coordinate of - // the content or window. - long left; - - // This property can be used to read or write the current Y coordinate of - // the content or window. - long top; - - // This property can be used to read or write the current width of the - // content or window. - long width; - - // This property can be used to read or write the current height of the - // content or window. - long height; - - // This property can be used to read or write the current minimum width of - // the content or window. A value of <code>null</code> indicates - // 'unspecified'. - long? minWidth; - - // This property can be used to read or write the current minimum height of - // the content or window. A value of <code>null</code> indicates - // 'unspecified'. - long? minHeight; - - // This property can be used to read or write the current maximum width of - // the content or window. A value of <code>null</code> indicates - // 'unspecified'. - long? maxWidth; - - // This property can be used to read or write the current maximum height of - // the content or window. A value of <code>null</code> indicates - // 'unspecified'. - long? maxHeight; - - // Set the left and top position of the content or window. - static void setPosition(long left, long top); - - // Set the width and height of the content or window. - static void setSize(long width, long height); - - // Set the minimum size constraints of the content or window. The minimum - // width or height can be set to <code>null</code> to remove the constraint. - // A value of <code>undefined</code> will leave a constraint unchanged. - static void setMinimumSize(long minWidth, long minHeight); - - // Set the maximum size constraints of the content or window. The maximum - // width or height can be set to <code>null</code> to remove the constraint. - // A value of <code>undefined</code> will leave a constraint unchanged. - static void setMaximumSize(long maxWidth, long maxHeight); - }; - - dictionary FrameOptions { - // Frame type: <code>none</code> or <code>chrome</code> (defaults to - // <code>chrome</code>). - // - // For <code>none</code>, the <code>-webkit-app-region</code> CSS property - // can be used to apply draggability to the app's window. - // - // <code>-webkit-app-region: drag</code> can be used to mark regions - // draggable. <code>no-drag</code> can be used to disable this style on - // nested elements. - DOMString? type; - // Allows the frame color to be set. Frame coloring is only available if the - // frame type is <code>chrome</code>. - // - // Frame coloring is new in Chrome 36. - DOMString? color; - // Allows the frame color of the window when active to be set. Frame - // coloring is only available if the frame type is <code>chrome</code>. - // - // Frame coloring is only available if the frame type is - // <code>chrome</code>. - // - // Frame coloring is new in Chrome 36. - DOMString? activeColor; - // Allows the frame color of the window when inactive to be set differently - // to the active color. Frame - // coloring is only available if the frame type is <code>chrome</code>. - // - // <code>inactiveColor</code> must be used in conjunction with <code> - // color</code>. - // - // Frame coloring is new in Chrome 36. - DOMString? inactiveColor; - }; - - // State of a window: normal, fullscreen, maximized, minimized. - enum State { normal, fullscreen, maximized, minimized }; - - // 'shell' is the default window type. 'panel' is managed by the OS - // (Currently experimental, Ash only). - [nodoc] enum WindowType { shell, panel }; - - [noinline_doc] dictionary CreateWindowOptions { - // Id to identify the window. This will be used to remember the size - // and position of the window and restore that geometry when a window - // with the same id is later opened. - // If a window with a given id is created while another window with the same - // id already exists, the currently opened window will be focused instead of - // creating a new window. - DOMString? id; - - // Used to specify the initial position, initial size and constraints of the - // window's content (excluding window decorations). - // If an <code>id</code> is also specified and a window with a matching - // <code>id</code> has been shown before, the remembered bounds will be used - // instead. - // - // Note that the padding between the inner and outer bounds is determined by - // the OS. Therefore setting the same bounds property for both the - // <code>innerBounds</code> and <code>outerBounds</code> will result in an - // error. - // - // This property is new in Chrome 36. - BoundsSpecification? innerBounds; - - // Used to specify the initial position, initial size and constraints of the - // window (including window decorations such as the title bar and frame). - // If an <code>id</code> is also specified and a window with a matching - // <code>id</code> has been shown before, the remembered bounds will be used - // instead. - // - // Note that the padding between the inner and outer bounds is determined by - // the OS. Therefore setting the same bounds property for both the - // <code>innerBounds</code> and <code>outerBounds</code> will result in an - // error. - // - // This property is new in Chrome 36. - BoundsSpecification? outerBounds; - - // Default width of the window. - [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? defaultWidth; - - // Default height of the window. - [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? defaultHeight; - - // Default X coordinate of the window. - [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? defaultLeft; - - // Default Y coordinate of the window. - [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? defaultTop; - - // Width of the window. - [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? width; - - // Height of the window. - [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? height; - - // X coordinate of the window. - [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? left; - - // Y coordinate of the window. - [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? top; - - // Minimum width of the window. - [deprecated="Use innerBounds or outerBounds."] long? minWidth; - - // Minimum height of the window. - [deprecated="Use innerBounds or outerBounds."] long? minHeight; - - // Maximum width of the window. - [deprecated="Use innerBounds or outerBounds."] long? maxWidth; - - // Maximum height of the window. - [deprecated="Use innerBounds or outerBounds."] long? maxHeight; - - // Type of window to create. - [nodoc] WindowType? type; - - // Frame type: <code>none</code> or <code>chrome</code> (defaults to - // <code>chrome</code>). For <code>none</code>, the - // <code>-webkit-app-region</code> CSS property can be used to apply - // draggability to the app's window. <code>-webkit-app-region: drag</code> - // can be used to mark regions draggable. <code>no-drag</code> can be used - // to disable this style on nested elements. - // - // Use of <code>FrameOptions</code> is new in M36. - (DOMString or FrameOptions)? frame; - - // Size and position of the content in the window (excluding the titlebar). - // If an id is also specified and a window with a matching id has been shown - // before, the remembered bounds of the window will be used instead. - [deprecated="Use innerBounds or outerBounds."] ContentBounds? bounds; - - // Enable window background transparency. - // Only supported in ash. Requires app.window.alpha API permission. - boolean? alphaEnabled; - - // The initial state of the window, allowing it to be created already - // fullscreen, maximized, or minimized. Defaults to 'normal'. - State? state; - - // If true, the window will be created in a hidden state. Call show() on - // the window to show it once it has been created. Defaults to false. - boolean? hidden; - - // If true, the window will be resizable by the user. Defaults to true. - boolean? resizable; - - // By default if you specify an id for the window, the window will only be - // created if another window with the same id doesn't already exist. If a - // window with the same id already exists that window is activated instead. - // If you do want to create multiple windows with the same id, you can - // set this property to false. - [deprecated="Multiple windows with the same id is no longer supported."] boolean? singleton; - - // If true, the window will stay above most other windows. If there are - // multiple windows of this kind, the currently focused window will be in - // the foreground. Requires the <code>"alwaysOnTopWindows"</code> - // permission. Defaults to false. - // - // Call <code>setAlwaysOnTop()</code> on the window to change this property - // after creation. - boolean? alwaysOnTop; - - // If true, the window will be focused when created. Defaults to true. - boolean? focused; - }; - - // Called in the creating window (parent) before the load event is called in - // the created window (child). The parent can set fields or functions on the - // child usable from onload. E.g. background.js: - // - // <code>function(createdWindow) { createdWindow.contentWindow.foo = - // function () { }; };</code> - // - // window.js: - // - // <code>window.onload = function () { foo(); }</code> - callback CreateWindowCallback = - void ([instanceOf=AppWindow] object createdWindow); - - [noinline_doc] dictionary AppWindow { - // Focus the window. - static void focus(); - - // Fullscreens the window. - // - // The user will be able to restore the window by pressing ESC. An - // application can prevent the fullscreen state to be left when ESC is - // pressed by requesting the <b>overrideEscFullscreen</b> permission and - // canceling the event by calling .preventDefault(), like this: - // - // <code>window.onKeyDown = function(e) { if (e.keyCode == 27 /* ESC */) { - // e.preventDefault(); } };</code> - static void fullscreen(); - - // Is the window fullscreen? - static boolean isFullscreen(); - - // Minimize the window. - static void minimize(); - - // Is the window minimized? - static boolean isMinimized(); - - // Maximize the window. - static void maximize(); - - // Is the window maximized? - static boolean isMaximized(); - - // Restore the window, exiting a maximized, minimized, or fullscreen state. - static void restore(); - - // Move the window to the position (|left|, |top|). - static void moveTo(long left, long top); - - // Resize the window to |width|x|height| pixels in size. - static void resizeTo(long width, long height); - - // Draw attention to the window. - static void drawAttention(); - - // Clear attention to the window. - static void clearAttention(); - - // Close the window. - static void close(); - - // Show the window. Does nothing if the window is already visible. - // Focus the window if |focused| is set to true or omitted. - static void show(optional boolean focused); - - // Hide the window. Does nothing if the window is already hidden. - static void hide(); - - // Get the window's inner bounds as a $(ref:ContentBounds) object. - [nocompile, deprecated="Use innerBounds or outerBounds."] static ContentBounds getBounds(); - - // Set the window's inner bounds. - [nocompile, deprecated="Use innerBounds or outerBounds."] static void setBounds(ContentBounds bounds); - - // Set the app icon for the window (experimental). - // Currently this is only being implemented on Ash. - // TODO(stevenjb): Investigate implementing this on Windows and OSX. - [nodoc] static void setIcon(DOMString iconUrl); - - // Set a badge icon for the window. - // TODO(benwells): Document this properly before going to stable. - [nodoc] static void setBadgeIcon(DOMString iconUrl); - - // Clear the current for the window. - // TODO(benwells): Document this properly before going to stable. - [nodoc] static void clearBadge(); - - // Is the window always on top? - static boolean isAlwaysOnTop(); - - // Accessors for testing. - [nodoc] boolean hasFrameColor; - [nodoc] long activeFrameColor; - [nodoc] long inactiveFrameColor; - [nodoc] boolean? firstShowHasHappened; - - // Set whether the window should stay above most other windows. Requires the - // <code>"alwaysOnTopWindows"</code> permission. - static void setAlwaysOnTop(boolean alwaysOnTop); - - // Can the window use alpha transparency? - // TODO(jackhou): Document this properly before going to stable. - [nodoc] static boolean alphaEnabled(); - - // The JavaScript 'window' object for the created child. - [instanceOf=Window] object contentWindow; - - // The id the window was created with. - DOMString id; - - // The position, size and constraints of the window's content, which does - // not include window decorations. - // This property is new in Chrome 36. - Bounds innerBounds; - - // The position, size and constraints of the window, which includes window - // decorations, such as the title bar and frame. - // This property is new in Chrome 36. - Bounds outerBounds; - }; - - interface Functions { - // The size and position of a window can be specified in a number of - // different ways. The most simple option is not specifying anything at - // all, in which case a default size and platform dependent position will - // be used. - // - // To set the position, size and constraints of the window, use the - // <code>innerBounds</code> or <code>outerBounds</code> properties. Inner - // bounds do not include window decorations. Outer bounds include the - // window's title bar and frame. Note that the padding between the inner and - // outer bounds is determined by the OS. Therefore setting the same property - // for both inner and outer bounds is considered an error (for example, - // setting both <code>innerBounds.left</code> and - // <code>outerBounds.left</code>). - // - // To automatically remember the positions of windows you can give them ids. - // If a window has an id, This id is used to remember the size and position - // of the window whenever it is moved or resized. This size and position is - // then used instead of the specified bounds on subsequent opening of a - // window with the same id. If you need to open a window with an id at a - // location other than the remembered default, you can create it hidden, - // move it to the desired location, then show it. - static void create(DOMString url, - optional CreateWindowOptions options, - optional CreateWindowCallback callback); - - // Returns an $(ref:AppWindow) object for the - // current script context (ie JavaScript 'window' object). This can also be - // called on a handle to a script context for another page, for example: - // otherWindow.chrome.app.window.current(). - [nocompile] static AppWindow current(); - [nocompile, nodoc] static void initializeAppWindow(object state); - - // Gets an array of all currently created app windows. This method is new in - // Chrome 33. - [nocompile] static AppWindow[] getAll(); - - // Gets an $(ref:AppWindow) with the given id. If no window with the given id - // exists null is returned. This method is new in Chrome 33. - [nocompile] static AppWindow get(DOMString id); - }; - - interface Events { - // Fired when the window is resized. - [nocompile] static void onBoundsChanged(); - - // Fired when the window is closed. Note, this should be listened to from - // a window other than the window being closed, for example from the - // background page. This is because the window being closed will be in the - // process of being torn down when the event is fired, which means not all - // APIs in the window's script context will be functional. - [nocompile] static void onClosed(); - - // Fired when the window is fullscreened. - [nocompile] static void onFullscreened(); - - // Fired when the window is maximized. - [nocompile] static void onMaximized(); - - // Fired when the window is minimized. - [nocompile] static void onMinimized(); - - // Fired when the window is restored from being minimized or maximized. - [nocompile] static void onRestored(); - - // Fired when the window's ability to use alpha transparency changes. - [nocompile, nodoc] static void onAlphaEnabledChanged(); - - // Event for testing. Lets tests wait until a window has been shown. - [nocompile, nodoc] static void onWindowFirstShown(); - }; -}; diff --git a/chrome/common/extensions/api/schemas.gypi b/chrome/common/extensions/api/schemas.gypi index 0c82c44..3cd9af7 100644 --- a/chrome/common/extensions/api/schemas.gypi +++ b/chrome/common/extensions/api/schemas.gypi @@ -19,7 +19,6 @@ 'activity_log_private.json', 'alarms.idl', 'app_current_window_internal.idl', - 'app_window.idl', 'audio.idl', 'automation.idl', 'automation_internal.idl', diff --git a/chrome/renderer/extensions/app_window_custom_bindings.cc b/chrome/renderer/extensions/app_window_custom_bindings.cc deleted file mode 100644 index 35dd1bea..0000000 --- a/chrome/renderer/extensions/app_window_custom_bindings.cc +++ /dev/null @@ -1,131 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/renderer/extensions/app_window_custom_bindings.h" - -#include <string> - -#include "base/command_line.h" -#include "chrome/common/chrome_switches.h" -#include "chrome/grit/renderer_resources.h" -#include "content/public/renderer/render_thread.h" -#include "content/public/renderer/render_view.h" -#include "content/public/renderer/render_view_observer.h" -#include "content/public/renderer/render_view_visitor.h" -#include "content/public/renderer/v8_value_converter.h" -#include "extensions/common/extension_messages.h" -#include "extensions/renderer/dispatcher.h" -#include "extensions/renderer/scoped_persistent.h" -#include "extensions/renderer/script_context.h" -#include "extensions/renderer/script_context_set.h" -#include "third_party/WebKit/public/web/WebLocalFrame.h" -#include "third_party/WebKit/public/web/WebView.h" -#include "ui/base/resource/resource_bundle.h" -#include "v8/include/v8.h" - -namespace extensions { - -class DidCreateDocumentElementObserver : public content::RenderViewObserver { - public: - DidCreateDocumentElementObserver(content::RenderView* view, - Dispatcher* dispatcher) - : content::RenderViewObserver(view), dispatcher_(dispatcher) {} - - virtual void DidCreateDocumentElement(blink::WebLocalFrame* frame) OVERRIDE { - DCHECK(frame); - DCHECK(dispatcher_); - // Don't attempt to inject the titlebar into iframes. - if (frame->parent()) - return; - v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); - ScriptContext* script_context = - dispatcher_->script_context_set().GetByV8Context( - frame->mainWorldScriptContext()); - - if (!script_context) - return; - v8::Context::Scope context_scope(script_context->v8_context()); - script_context->module_system()->CallModuleMethod( - "injectAppTitlebar", "didCreateDocumentElement"); - } - - private: - Dispatcher* dispatcher_; -}; - -AppWindowCustomBindings::AppWindowCustomBindings(Dispatcher* dispatcher, - ScriptContext* context) - : ObjectBackedNativeHandler(context), dispatcher_(dispatcher) { - RouteFunction("GetView", - base::Bind(&AppWindowCustomBindings::GetView, - base::Unretained(this))); - - RouteFunction("GetWindowControlsHtmlTemplate", - base::Bind(&AppWindowCustomBindings::GetWindowControlsHtmlTemplate, - base::Unretained(this))); -} - -void AppWindowCustomBindings::GetView( - const v8::FunctionCallbackInfo<v8::Value>& args) { - // TODO(jeremya): convert this to IDL nocompile to get validation, and turn - // these argument checks into CHECK(). - if (args.Length() != 2) - return; - - if (!args[0]->IsInt32()) - return; - - if (!args[1]->IsBoolean()) - return; - - int view_id = args[0]->Int32Value(); - - bool inject_titlebar = args[1]->BooleanValue(); - - if (view_id == MSG_ROUTING_NONE) - return; - - content::RenderView* view = content::RenderView::FromRoutingID(view_id); - if (!view) - return; - - if (inject_titlebar) - new DidCreateDocumentElementObserver(view, dispatcher_); - - // TODO(jeremya): it doesn't really make sense to set the opener here, but we - // need to make sure the security origin is set up before returning the DOM - // reference. A better way to do this would be to have the browser pass the - // opener through so opener_id is set in RenderViewImpl's constructor. - content::RenderView* render_view = context()->GetRenderView(); - if (!render_view) - return; - blink::WebFrame* opener = render_view->GetWebView()->mainFrame(); - blink::WebFrame* frame = view->GetWebView()->mainFrame(); - frame->setOpener(opener); - content::RenderThread::Get()->Send( - new ExtensionHostMsg_ResumeRequests(view->GetRoutingID())); - - v8::Local<v8::Value> window = frame->mainWorldScriptContext()->Global(); - args.GetReturnValue().Set(window); -} - -void AppWindowCustomBindings::GetWindowControlsHtmlTemplate( - const v8::FunctionCallbackInfo<v8::Value>& args) { - CHECK_EQ(args.Length(), 0); - - v8::Handle<v8::Value> result = v8::String::Empty(args.GetIsolate()); - if (CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableAppWindowControls)) { - base::StringValue value( - ResourceBundle::GetSharedInstance() - .GetRawDataResource(IDR_WINDOW_CONTROLS_TEMPLATE_HTML) - .as_string()); - scoped_ptr<content::V8ValueConverter> converter( - content::V8ValueConverter::create()); - result = converter->ToV8Value(&value, context()->v8_context()); - } - args.GetReturnValue().Set(result); -} - -} // namespace extensions diff --git a/chrome/renderer/extensions/app_window_custom_bindings.h b/chrome/renderer/extensions/app_window_custom_bindings.h deleted file mode 100644 index e0f942a..0000000 --- a/chrome/renderer/extensions/app_window_custom_bindings.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_RENDERER_EXTENSIONS_APP_WINDOW_CUSTOM_BINDINGS_H_ -#define CHROME_RENDERER_EXTENSIONS_APP_WINDOW_CUSTOM_BINDINGS_H_ - -#include "extensions/renderer/object_backed_native_handler.h" - -namespace extensions { -class Dispatcher; - -// Implements custom bindings for the app.window API. -class AppWindowCustomBindings : public ObjectBackedNativeHandler { - public: - AppWindowCustomBindings(Dispatcher* dispatcher, ScriptContext* context); - - private: - void GetView(const v8::FunctionCallbackInfo<v8::Value>& args); - - // Return string containing the HTML <template> for the <window-controls> - // custom element. - void GetWindowControlsHtmlTemplate( - const v8::FunctionCallbackInfo<v8::Value>& args); - - // Dispatcher handle. Not owned. - Dispatcher* dispatcher_; - - DISALLOW_COPY_AND_ASSIGN(AppWindowCustomBindings); -}; - -} // namespace extensions - -#endif // CHROME_RENDERER_EXTENSIONS_APP_WINDOW_CUSTOM_BINDINGS_H_ diff --git a/chrome/renderer/extensions/chrome_extensions_dispatcher_delegate.cc b/chrome/renderer/extensions/chrome_extensions_dispatcher_delegate.cc index 0e0fefa..3b7bbbd 100644 --- a/chrome/renderer/extensions/chrome_extensions_dispatcher_delegate.cc +++ b/chrome/renderer/extensions/chrome_extensions_dispatcher_delegate.cc @@ -14,7 +14,6 @@ #include "chrome/common/url_constants.h" #include "chrome/grit/renderer_resources.h" #include "chrome/renderer/extensions/app_bindings.h" -#include "chrome/renderer/extensions/app_window_custom_bindings.h" #include "chrome/renderer/extensions/automation_internal_custom_bindings.h" #include "chrome/renderer/extensions/chrome_v8_context.h" #include "chrome/renderer/extensions/enterprise_platform_keys_natives.h" @@ -98,10 +97,6 @@ void ChromeExtensionsDispatcherDelegate::RegisterNativeHandlers( scoped_ptr<NativeHandler>( new extensions::AppBindings(dispatcher, context))); module_system->RegisterNativeHandler( - "app_window_natives", - scoped_ptr<NativeHandler>( - new extensions::AppWindowCustomBindings(dispatcher, context))); - module_system->RegisterNativeHandler( "sync_file_system", scoped_ptr<NativeHandler>( new extensions::SyncFileSystemCustomBindings(context))); @@ -151,7 +146,6 @@ void ChromeExtensionsDispatcherDelegate::PopulateSourceMap( extensions::ResourceBundleSourceMap* source_map) { // Custom bindings. source_map->RegisterSource("app", IDR_APP_CUSTOM_BINDINGS_JS); - source_map->RegisterSource("app.window", IDR_APP_WINDOW_CUSTOM_BINDINGS_JS); source_map->RegisterSource("automation", IDR_AUTOMATION_CUSTOM_BINDINGS_JS); source_map->RegisterSource("automationEvent", IDR_AUTOMATION_EVENT_JS); source_map->RegisterSource("automationNode", IDR_AUTOMATION_NODE_JS); @@ -224,7 +218,6 @@ void ChromeExtensionsDispatcherDelegate::PopulateSourceMap( IDR_CAST_STREAMING_UDP_TRANSPORT_CUSTOM_BINDINGS_JS); #endif source_map->RegisterSource("webstore", IDR_WEBSTORE_CUSTOM_BINDINGS_JS); - source_map->RegisterSource("windowControls", IDR_WINDOW_CONTROLS_JS); // Custom types sources. source_map->RegisterSource("ChromeSetting", IDR_CHROME_SETTING_JS); @@ -268,7 +261,7 @@ void ChromeExtensionsDispatcherDelegate::RequireAdditionalModules( is_within_platform_app && extensions::GetCurrentChannel() <= chrome::VersionInfo::CHANNEL_DEV && CommandLine::ForCurrentProcess()->HasSwitch( - ::switches::kEnableAppWindowControls)) { + extensions::switches::kEnableAppWindowControls)) { module_system->Require("windowControls"); } diff --git a/chrome/renderer/resources/extensions/app_window_custom_bindings.js b/chrome/renderer/resources/extensions/app_window_custom_bindings.js deleted file mode 100644 index 812d3d6..0000000 --- a/chrome/renderer/resources/extensions/app_window_custom_bindings.js +++ /dev/null @@ -1,401 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Custom binding for the app_window API. - -var appWindowNatives = requireNative('app_window_natives'); -var runtimeNatives = requireNative('runtime'); -var Binding = require('binding').Binding; -var Event = require('event_bindings').Event; -var forEach = require('utils').forEach; -var renderViewObserverNatives = requireNative('renderViewObserverNatives'); - -var appWindowData = null; -var currentAppWindow = null; -var currentWindowInternal = null; - -var kSetBoundsFunction = 'setBounds'; -var kSetSizeConstraintsFunction = 'setSizeConstraints'; - -// Bounds class definition. -var Bounds = function(boundsKey) { - privates(this).boundsKey_ = boundsKey; -}; -Object.defineProperty(Bounds.prototype, 'left', { - get: function() { - return appWindowData[privates(this).boundsKey_].left; - }, - set: function(left) { - this.setPosition(left, null); - }, - enumerable: true -}); -Object.defineProperty(Bounds.prototype, 'top', { - get: function() { - return appWindowData[privates(this).boundsKey_].top; - }, - set: function(top) { - this.setPosition(null, top); - }, - enumerable: true -}); -Object.defineProperty(Bounds.prototype, 'width', { - get: function() { - return appWindowData[privates(this).boundsKey_].width; - }, - set: function(width) { - this.setSize(width, null); - }, - enumerable: true -}); -Object.defineProperty(Bounds.prototype, 'height', { - get: function() { - return appWindowData[privates(this).boundsKey_].height; - }, - set: function(height) { - this.setSize(null, height); - }, - enumerable: true -}); -Object.defineProperty(Bounds.prototype, 'minWidth', { - get: function() { - return appWindowData[privates(this).boundsKey_].minWidth; - }, - set: function(minWidth) { - updateSizeConstraints(privates(this).boundsKey_, { minWidth: minWidth }); - }, - enumerable: true -}); -Object.defineProperty(Bounds.prototype, 'maxWidth', { - get: function() { - return appWindowData[privates(this).boundsKey_].maxWidth; - }, - set: function(maxWidth) { - updateSizeConstraints(privates(this).boundsKey_, { maxWidth: maxWidth }); - }, - enumerable: true -}); -Object.defineProperty(Bounds.prototype, 'minHeight', { - get: function() { - return appWindowData[privates(this).boundsKey_].minHeight; - }, - set: function(minHeight) { - updateSizeConstraints(privates(this).boundsKey_, { minHeight: minHeight }); - }, - enumerable: true -}); -Object.defineProperty(Bounds.prototype, 'maxHeight', { - get: function() { - return appWindowData[privates(this).boundsKey_].maxHeight; - }, - set: function(maxHeight) { - updateSizeConstraints(privates(this).boundsKey_, { maxHeight: maxHeight }); - }, - enumerable: true -}); -Bounds.prototype.setPosition = function(left, top) { - updateBounds(privates(this).boundsKey_, { left: left, top: top }); -}; -Bounds.prototype.setSize = function(width, height) { - updateBounds(privates(this).boundsKey_, { width: width, height: height }); -}; -Bounds.prototype.setMinimumSize = function(minWidth, minHeight) { - updateSizeConstraints(privates(this).boundsKey_, - { minWidth: minWidth, minHeight: minHeight }); -}; -Bounds.prototype.setMaximumSize = function(maxWidth, maxHeight) { - updateSizeConstraints(privates(this).boundsKey_, - { maxWidth: maxWidth, maxHeight: maxHeight }); -}; - -var appWindow = Binding.create('app.window'); -appWindow.registerCustomHook(function(bindingsAPI) { - var apiFunctions = bindingsAPI.apiFunctions; - - apiFunctions.setCustomCallback('create', - function(name, request, windowParams) { - var view = null; - - // When window creation fails, |windowParams| will be undefined. - if (windowParams && windowParams.viewId) { - view = appWindowNatives.GetView( - windowParams.viewId, windowParams.injectTitlebar); - } - - if (!view) { - // No route to created window. If given a callback, trigger it with an - // undefined object. - if (request.callback) { - request.callback(); - delete request.callback; - } - return; - } - - if (windowParams.existingWindow) { - // Not creating a new window, but activating an existing one, so trigger - // callback with existing window and don't do anything else. - if (request.callback) { - request.callback(view.chrome.app.window.current()); - delete request.callback; - } - return; - } - - // Initialize appWindowData in the newly created JS context - view.chrome.app.window.initializeAppWindow(windowParams); - - var callback = request.callback; - if (callback) { - delete request.callback; - if (!view) { - callback(undefined); - return; - } - - var willCallback = - renderViewObserverNatives.OnDocumentElementCreated( - windowParams.viewId, - function(success) { - if (success) { - callback(view.chrome.app.window.current()); - } else { - callback(undefined); - } - }); - if (!willCallback) { - callback(undefined); - } - } - }); - - apiFunctions.setHandleRequest('current', function() { - if (!currentAppWindow) { - console.error('The JavaScript context calling ' + - 'chrome.app.window.current() has no associated AppWindow.'); - return null; - } - return currentAppWindow; - }); - - apiFunctions.setHandleRequest('getAll', function() { - var views = runtimeNatives.GetExtensionViews(-1, 'APP_WINDOW'); - return $Array.map(views, function(win) { - return win.chrome.app.window.current(); - }); - }); - - apiFunctions.setHandleRequest('get', function(id) { - var windows = $Array.filter(chrome.app.window.getAll(), function(win) { - return win.id == id; - }); - return windows.length > 0 ? windows[0] : null; - }); - - // This is an internal function, but needs to be bound into a closure - // so the correct JS context is used for global variables such as - // currentWindowInternal, appWindowData, etc. - apiFunctions.setHandleRequest('initializeAppWindow', function(params) { - currentWindowInternal = - Binding.create('app.currentWindowInternal').generate(); - var AppWindow = function() { - this.innerBounds = new Bounds('innerBounds'); - this.outerBounds = new Bounds('outerBounds'); - }; - forEach(currentWindowInternal, function(key, value) { - // Do not add internal functions that should not appear in the AppWindow - // interface. They are called by Bounds mutators. - if (key !== kSetBoundsFunction && key !== kSetSizeConstraintsFunction) - AppWindow.prototype[key] = value; - }); - AppWindow.prototype.moveTo = $Function.bind(window.moveTo, window); - AppWindow.prototype.resizeTo = $Function.bind(window.resizeTo, window); - AppWindow.prototype.contentWindow = window; - AppWindow.prototype.onClosed = new Event(); - AppWindow.prototype.onWindowFirstShownForTests = new Event(); - AppWindow.prototype.close = function() { - this.contentWindow.close(); - }; - AppWindow.prototype.getBounds = function() { - // This is to maintain backcompatibility with a bug on Windows and - // ChromeOS, which returns the position of the window but the size of - // the content. - var innerBounds = appWindowData.innerBounds; - var outerBounds = appWindowData.outerBounds; - return { left: outerBounds.left, top: outerBounds.top, - width: innerBounds.width, height: innerBounds.height }; - }; - AppWindow.prototype.setBounds = function(bounds) { - updateBounds('bounds', bounds); - }; - AppWindow.prototype.isFullscreen = function() { - return appWindowData.fullscreen; - }; - AppWindow.prototype.isMinimized = function() { - return appWindowData.minimized; - }; - AppWindow.prototype.isMaximized = function() { - return appWindowData.maximized; - }; - AppWindow.prototype.isAlwaysOnTop = function() { - return appWindowData.alwaysOnTop; - }; - AppWindow.prototype.alphaEnabled = function() { - return appWindowData.alphaEnabled; - }; - AppWindow.prototype.handleWindowFirstShownForTests = function(callback) { - // This allows test apps to get have their callback run even if they - // call this after the first show has happened. - if (this.firstShowHasHappened) { - callback(); - return; - } - this.onWindowFirstShownForTests.addListener(callback); - } - - Object.defineProperty(AppWindow.prototype, 'id', {get: function() { - return appWindowData.id; - }}); - - // These properties are for testing. - Object.defineProperty( - AppWindow.prototype, 'hasFrameColor', {get: function() { - return appWindowData.hasFrameColor; - }}); - - Object.defineProperty(AppWindow.prototype, 'activeFrameColor', - {get: function() { - return appWindowData.activeFrameColor; - }}); - - Object.defineProperty(AppWindow.prototype, 'inactiveFrameColor', - {get: function() { - return appWindowData.inactiveFrameColor; - }}); - - appWindowData = { - id: params.id || '', - innerBounds: { - left: params.innerBounds.left, - top: params.innerBounds.top, - width: params.innerBounds.width, - height: params.innerBounds.height, - - minWidth: params.innerBounds.minWidth, - minHeight: params.innerBounds.minHeight, - maxWidth: params.innerBounds.maxWidth, - maxHeight: params.innerBounds.maxHeight - }, - outerBounds: { - left: params.outerBounds.left, - top: params.outerBounds.top, - width: params.outerBounds.width, - height: params.outerBounds.height, - - minWidth: params.outerBounds.minWidth, - minHeight: params.outerBounds.minHeight, - maxWidth: params.outerBounds.maxWidth, - maxHeight: params.outerBounds.maxHeight - }, - fullscreen: params.fullscreen, - minimized: params.minimized, - maximized: params.maximized, - alwaysOnTop: params.alwaysOnTop, - hasFrameColor: params.hasFrameColor, - activeFrameColor: params.activeFrameColor, - inactiveFrameColor: params.inactiveFrameColor, - alphaEnabled: params.alphaEnabled - }; - currentAppWindow = new AppWindow; - }); -}); - -function boundsEqual(bounds1, bounds2) { - if (!bounds1 || !bounds2) - return false; - return (bounds1.left == bounds2.left && bounds1.top == bounds2.top && - bounds1.width == bounds2.width && bounds1.height == bounds2.height); -} - -function dispatchEventIfExists(target, name) { - // Sometimes apps like to put their own properties on the window which - // break our assumptions. - var event = target[name]; - if (event && (typeof event.dispatch == 'function')) - event.dispatch(); - else - console.warn('Could not dispatch ' + name + ', event has been clobbered'); -} - -function updateAppWindowProperties(update) { - if (!appWindowData) - return; - - var oldData = appWindowData; - update.id = oldData.id; - appWindowData = update; - - var currentWindow = currentAppWindow; - - if (!boundsEqual(oldData.innerBounds, update.innerBounds)) - dispatchEventIfExists(currentWindow, "onBoundsChanged"); - - if (!oldData.fullscreen && update.fullscreen) - dispatchEventIfExists(currentWindow, "onFullscreened"); - if (!oldData.minimized && update.minimized) - dispatchEventIfExists(currentWindow, "onMinimized"); - if (!oldData.maximized && update.maximized) - dispatchEventIfExists(currentWindow, "onMaximized"); - - if ((oldData.fullscreen && !update.fullscreen) || - (oldData.minimized && !update.minimized) || - (oldData.maximized && !update.maximized)) - dispatchEventIfExists(currentWindow, "onRestored"); - - if (oldData.alphaEnabled !== update.alphaEnabled) - dispatchEventIfExists(currentWindow, "onAlphaEnabledChanged"); -}; - -function onAppWindowShownForTests() { - if (!currentAppWindow) - return; - - if (!currentAppWindow.firstShowHasHappened) - dispatchEventIfExists(currentAppWindow, "onWindowFirstShownForTests"); - - currentAppWindow.firstShowHasHappened = true; -} - -function onAppWindowClosed() { - if (!currentAppWindow) - return; - dispatchEventIfExists(currentAppWindow, "onClosed"); -} - -function updateBounds(boundsType, bounds) { - if (!currentWindowInternal) - return; - - currentWindowInternal.setBounds(boundsType, bounds); -} - -function updateSizeConstraints(boundsType, constraints) { - if (!currentWindowInternal) - return; - - forEach(constraints, function(key, value) { - // From the perspective of the API, null is used to reset constraints. - // We need to convert this to 0 because a value of null is interpreted - // the same as undefined in the browser and leaves the constraint unchanged. - if (value === null) - constraints[key] = 0; - }); - - currentWindowInternal.setSizeConstraints(boundsType, constraints); -} - -exports.binding = appWindow.generate(); -exports.onAppWindowClosed = onAppWindowClosed; -exports.updateAppWindowProperties = updateAppWindowProperties; -exports.appWindowShownForTests = onAppWindowShownForTests;
\ No newline at end of file diff --git a/chrome/renderer/resources/extensions/window_controls.js b/chrome/renderer/resources/extensions/window_controls.js deleted file mode 100644 index 75c88e6..0000000 --- a/chrome/renderer/resources/extensions/window_controls.js +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// -// <window-controls> shadow element implementation. -// - -var chrome = requireNative('chrome').GetChrome(); -var forEach = require('utils').forEach; -var addTagWatcher = require('tagWatcher').addTagWatcher; -var appWindow = require('app.window'); -var getHtmlTemplate = - requireNative('app_window_natives').GetWindowControlsHtmlTemplate; - -/** - * @constructor - */ -function WindowControls(node) { - this.node_ = node; - this.shadowRoot_ = this.createShadowRoot_(node); - this.setupWindowControls_(); -} - -/** - * @private - */ -WindowControls.prototype.template_element = null; - -/** - * @private - */ -WindowControls.prototype.createShadowRoot_ = function(node) { - // Initialize |template| from HTML template resource and cache result. - var template = WindowControls.prototype.template_element; - if (!template) { - var element = document.createElement('div'); - element.innerHTML = getHtmlTemplate(); - WindowControls.prototype.template_element = element.firstChild; - template = WindowControls.prototype.template_element; - } - // Create shadow root element with template clone as first child. - var shadowRoot = node.createShadowRoot(); - shadowRoot.appendChild(template.content.cloneNode(true)); - return shadowRoot; -} - -/** - * @private - */ -WindowControls.prototype.setupWindowControls_ = function() { - var self = this; - this.shadowRoot_.querySelector("#close-control").addEventListener('click', - function(e) { - chrome.app.window.current().close(); - }); - - this.shadowRoot_.querySelector("#maximize-control").addEventListener('click', - function(e) { - self.maxRestore_(); - }); -} - -/** - * @private - * Restore or maximize depending on current state - */ -WindowControls.prototype.maxRestore_ = function() { - if (chrome.app.window.current().isMaximized()) { - chrome.app.window.current().restore(); - } else { - chrome.app.window.current().maximize(); - } -} - -addTagWatcher('WINDOW-CONTROLS', function(addedNode) { - new WindowControls(addedNode); -}); diff --git a/chrome/renderer/resources/extensions/window_controls_template.html b/chrome/renderer/resources/extensions/window_controls_template.html deleted file mode 100644 index 6f468bc..0000000 --- a/chrome/renderer/resources/extensions/window_controls_template.html +++ /dev/null @@ -1,52 +0,0 @@ -<template id="window-controls-template"> - <style> - .controls { - width:32px; - height:32px; - position:absolute; - z-index:200; - } - #close-control { - top:8px; - right:10px; - } - #maximize-control { - top:8px; - right:52px; - } - #close { - top:0; - right:0; - -webkit-mask-image:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAALNJREFUeNrsllEOwyAIhmVXwIu487dXKEdy2PBgWuxwm/VhkPwvSuALAhFyzmGmPcJkcwAHcAAHMAMAQGItLGSFhlB8kpmgrGKL2NbiziIWKqHK2SY+qzluBwBKcg2iTr7fjQBoQZySd1W2E0CD2LSqjAQ4Qqh9YY37zRj+5iPx4RPUZac7n6DVhHRHE74bQxo9hvUiio1FRCMXURKIeNFSKD5Pa1zwX7EDOIAD/D3AS4ABAKWdkCCeGGsrAAAAAElFTkSuQmCC'); - } - .windowbutton { - width:32px; - height:32px; - position:absolute; - background-color:rgba(0, 0, 0, 0.49); - } - .windowbuttonbackground { - width:32px; - height:32px; - position:absolute; - } - .windowbuttonbackground:hover { - background-image:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAEBJREFUeNrszrENAEAIw8A8EvU32X9RGsQUaewFfM/2l9TKNBWcX10KBwAAAAAAAAAAAAAAAAAAABxggv9ZAQYAhakDi3I15kgAAAAASUVORK5CYII='); - - } - .windowbuttonbackground:active { - background-image:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAFtJREFUeNrs1zESgCAMRNEAkSZD5VW8/1k8hFaCCqfY5u9M6v/apIh2mH1hkqXba92uUvxU5Mfoe57xx0Rb7WziAQAAAAAAAAAAAAAAAAAAOcDXkzqvifrvL8AAWBcLpapo5CcAAAAASUVORK5CYII='); - } - #maximize { - -webkit-mask-image:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAFFJREFUeNrs1jsOACAIREHWeP8royWdnwaDj9pi2OhGubtlTrPkAQAAAIC+e1DSUWXOhlWtBGIYq+W5hAAA1GzC23f+fALiVwwAAIDvAUOAAQAv/Aw+jTHzugAAAABJRU5ErkJggg=='); - } - </style> - <div id="close-control" class="controls"> - <div id="close" class="windowbutton"> </div> - <div id="close-background" class="windowbuttonbackground"> </div> - </div> - <div id="maximize-control" class="controls"> - <div id="maximize" class="windowbutton"></div> - <div id="maximize-background" class="windowbuttonbackground"></div> - </div> -</template> diff --git a/chrome/renderer/resources/renderer_resources.grd b/chrome/renderer/resources/renderer_resources.grd index b31f007..9ad5486 100644 --- a/chrome/renderer/resources/renderer_resources.grd +++ b/chrome/renderer/resources/renderer_resources.grd @@ -33,7 +33,6 @@ <include name="IDR_APP_CUSTOM_BINDINGS_JS" file="extensions\app_custom_bindings.js" type="BINDATA" /> <include name="IDR_APP_VIEW_DENY_JS" file="extensions\app_view_deny.js" type="BINDATA" /> <include name="IDR_APP_VIEW_JS" file="extensions\app_view.js" type="BINDATA" /> - <include name="IDR_APP_WINDOW_CUSTOM_BINDINGS_JS" file="extensions\app_window_custom_bindings.js" type="BINDATA" /> <include name="IDR_AUTOMATION_CUSTOM_BINDINGS_JS" file="extensions\automation_custom_bindings.js" type="BINDATA" /> <include name="IDR_AUTOMATION_EVENT_JS" file="extensions\automation\automation_event.js" type="BINDATA" /> <include name="IDR_AUTOMATION_NODE_JS" file="extensions\automation\automation_node.js" type="BINDATA" /> @@ -82,8 +81,6 @@ <include name="IDR_TAG_WATCHER_JS" file="extensions\tag_watcher.js" type="BINDATA" /> <include name="IDR_TTS_CUSTOM_BINDINGS_JS" file="extensions\tts_custom_bindings.js" type="BINDATA" /> <include name="IDR_TTS_ENGINE_CUSTOM_BINDINGS_JS" file="extensions\tts_engine_custom_bindings.js" type="BINDATA" /> - <include name="IDR_WINDOW_CONTROLS_JS" file="extensions\window_controls.js" type="BINDATA" /> - <include name="IDR_WINDOW_CONTROLS_TEMPLATE_HTML" file="extensions\window_controls_template.html" type="BINDATA" /> <include name="IDR_WEB_REQUEST_CUSTOM_BINDINGS_JS" file="extensions\web_request_custom_bindings.js" type="BINDATA" /> <include name="IDR_WEB_REQUEST_INTERNAL_CUSTOM_BINDINGS_JS" file="extensions\web_request_internal_custom_bindings.js" type="BINDATA" /> <include name="IDR_WEBSTORE_CUSTOM_BINDINGS_JS" file="extensions\webstore_custom_bindings.js" type="BINDATA" /> |