diff options
author | asvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-27 15:29:39 +0000 |
---|---|---|
committer | asvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-27 15:29:39 +0000 |
commit | 88cd06107c1280ad59ba96273e49ffdc7558c86c (patch) | |
tree | ce6c10c55031f89680181cc69cbf1462247f5e24 /chrome/browser | |
parent | 35b149f40836c1d2dadafab6300730aa5c5d498f (diff) | |
download | chromium_src-88cd06107c1280ad59ba96273e49ffdc7558c86c.zip chromium_src-88cd06107c1280ad59ba96273e49ffdc7558c86c.tar.gz chromium_src-88cd06107c1280ad59ba96273e49ffdc7558c86c.tar.bz2 |
Revert 208927 "Move ShellWindow into apps component."
broke build:
../../chrome/browser/ui/apps/chrome_shell_window_delegate.cc:7:31: fatal error: base/stringprintf.h: No such file or directory
(I think it was moved to base/strings/stringprintf.h)
> Move ShellWindow into apps component.
>
> This involves creating a new delegate type, ShellWindow::Delegate, which
> is implemented in chrome.
>
> BUG=159366
>
> Review URL: https://chromiumcodereview.appspot.com/16702003
TBR=benwells@chromium.org
Review URL: https://codereview.chromium.org/18062007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@208929 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
53 files changed, 1159 insertions, 408 deletions
diff --git a/chrome/browser/chromeos/app_mode/app_session_lifetime.cc b/chrome/browser/chromeos/app_mode/app_session_lifetime.cc index 48514f0..3e4aadc 100644 --- a/chrome/browser/chromeos/app_mode/app_session_lifetime.cc +++ b/chrome/browser/chromeos/app_mode/app_session_lifetime.cc @@ -36,10 +36,9 @@ class AppWindowWatcher : public ShellWindowRegistry::Observer { private: // extensions::ShellWindowRegistry::Observer overrides: - virtual void OnShellWindowAdded(apps::ShellWindow* shell_window) OVERRIDE {} - virtual void OnShellWindowIconChanged(apps::ShellWindow* shell_window) - OVERRIDE {} - virtual void OnShellWindowRemoved(apps::ShellWindow* shell_window) OVERRIDE { + virtual void OnShellWindowAdded(ShellWindow* shell_window) OVERRIDE {} + virtual void OnShellWindowIconChanged(ShellWindow* shell_window) OVERRIDE {} + virtual void OnShellWindowRemoved(ShellWindow* shell_window) OVERRIDE { if (window_registry_->shell_windows().empty()) { chrome::AttemptUserExit(); window_registry_->RemoveObserver(this); diff --git a/chrome/browser/extensions/DEPS b/chrome/browser/extensions/DEPS index 05df41b..92be07f 100644 --- a/chrome/browser/extensions/DEPS +++ b/chrome/browser/extensions/DEPS @@ -1,10 +1,5 @@ include_rules = [ - # TODO(benwells): Once the extensions component is established - # and there are only chrome specific extension things left in - # chrome/browser/extensions, the restriction of not being able - # to depend on apps will be lifted. "-apps", - "+apps/shell_window.h", # TODO(tfarina): Remove all these. crbug.com/125846. # DO NOT ADD ANY MORE ITEMS TO THE LIST BELOW! 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 2f1b92b..c1912ea 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 @@ -4,15 +4,14 @@ #include "chrome/browser/extensions/api/app_current_window_internal/app_current_window_internal_api.h" -#include "apps/shell_window.h" #include "base/command_line.h" #include "chrome/browser/extensions/shell_window_registry.h" #include "chrome/browser/ui/extensions/native_app_window.h" +#include "chrome/browser/ui/extensions/shell_window.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/api/app_current_window_internal.h" #include "chrome/common/extensions/api/app_window.h" -using apps::ShellWindow; namespace SetBounds = extensions::api::app_current_window_internal::SetBounds; using extensions::api::app_current_window_internal::Bounds; namespace SetIcon = extensions::api::app_current_window_internal::SetIcon; diff --git a/chrome/browser/extensions/api/app_current_window_internal/app_current_window_internal_api.h b/chrome/browser/extensions/api/app_current_window_internal/app_current_window_internal_api.h index 806ae3b..110b5eb 100644 --- a/chrome/browser/extensions/api/app_current_window_internal/app_current_window_internal_api.h +++ b/chrome/browser/extensions/api/app_current_window_internal/app_current_window_internal_api.h @@ -7,9 +7,7 @@ #include "chrome/browser/extensions/extension_function.h" -namespace apps { class ShellWindow; -} namespace extensions { @@ -18,7 +16,7 @@ class AppCurrentWindowInternalExtensionFunction : public SyncExtensionFunction { virtual ~AppCurrentWindowInternalExtensionFunction() {} // Invoked with the current shell window. - virtual bool RunWithWindow(apps::ShellWindow* window) = 0; + virtual bool RunWithWindow(ShellWindow* window) = 0; private: virtual bool RunImpl() OVERRIDE; @@ -32,7 +30,7 @@ class AppCurrentWindowInternalFocusFunction protected: virtual ~AppCurrentWindowInternalFocusFunction() {} - virtual bool RunWithWindow(apps::ShellWindow* window) OVERRIDE; + virtual bool RunWithWindow(ShellWindow* window) OVERRIDE; }; class AppCurrentWindowInternalFullscreenFunction @@ -43,7 +41,7 @@ class AppCurrentWindowInternalFullscreenFunction protected: virtual ~AppCurrentWindowInternalFullscreenFunction() {} - virtual bool RunWithWindow(apps::ShellWindow* window) OVERRIDE; + virtual bool RunWithWindow(ShellWindow* window) OVERRIDE; }; class AppCurrentWindowInternalMaximizeFunction @@ -54,7 +52,7 @@ class AppCurrentWindowInternalMaximizeFunction protected: virtual ~AppCurrentWindowInternalMaximizeFunction() {} - virtual bool RunWithWindow(apps::ShellWindow* window) OVERRIDE; + virtual bool RunWithWindow(ShellWindow* window) OVERRIDE; }; class AppCurrentWindowInternalMinimizeFunction @@ -65,7 +63,7 @@ class AppCurrentWindowInternalMinimizeFunction protected: virtual ~AppCurrentWindowInternalMinimizeFunction() {} - virtual bool RunWithWindow(apps::ShellWindow* window) OVERRIDE; + virtual bool RunWithWindow(ShellWindow* window) OVERRIDE; }; class AppCurrentWindowInternalRestoreFunction @@ -76,7 +74,7 @@ class AppCurrentWindowInternalRestoreFunction protected: virtual ~AppCurrentWindowInternalRestoreFunction() {} - virtual bool RunWithWindow(apps::ShellWindow* window) OVERRIDE; + virtual bool RunWithWindow(ShellWindow* window) OVERRIDE; }; class AppCurrentWindowInternalDrawAttentionFunction @@ -87,7 +85,7 @@ class AppCurrentWindowInternalDrawAttentionFunction protected: virtual ~AppCurrentWindowInternalDrawAttentionFunction() {} - virtual bool RunWithWindow(apps::ShellWindow* window) OVERRIDE; + virtual bool RunWithWindow(ShellWindow* window) OVERRIDE; }; class AppCurrentWindowInternalClearAttentionFunction @@ -98,7 +96,7 @@ class AppCurrentWindowInternalClearAttentionFunction protected: virtual ~AppCurrentWindowInternalClearAttentionFunction() {} - virtual bool RunWithWindow(apps::ShellWindow* window) OVERRIDE; + virtual bool RunWithWindow(ShellWindow* window) OVERRIDE; }; class AppCurrentWindowInternalShowFunction @@ -109,7 +107,7 @@ class AppCurrentWindowInternalShowFunction protected: virtual ~AppCurrentWindowInternalShowFunction() {} - virtual bool RunWithWindow(apps::ShellWindow* window) OVERRIDE; + virtual bool RunWithWindow(ShellWindow* window) OVERRIDE; }; class AppCurrentWindowInternalHideFunction @@ -120,7 +118,7 @@ class AppCurrentWindowInternalHideFunction protected: virtual ~AppCurrentWindowInternalHideFunction() {} - virtual bool RunWithWindow(apps::ShellWindow* window) OVERRIDE; + virtual bool RunWithWindow(ShellWindow* window) OVERRIDE; }; class AppCurrentWindowInternalSetBoundsFunction @@ -130,7 +128,7 @@ class AppCurrentWindowInternalSetBoundsFunction APP_CURRENTWINDOWINTERNAL_SETBOUNDS) protected: virtual ~AppCurrentWindowInternalSetBoundsFunction() {} - virtual bool RunWithWindow(apps::ShellWindow* window) OVERRIDE; + virtual bool RunWithWindow(ShellWindow* window) OVERRIDE; }; class AppCurrentWindowInternalSetIconFunction @@ -141,7 +139,7 @@ class AppCurrentWindowInternalSetIconFunction protected: virtual ~AppCurrentWindowInternalSetIconFunction() {} - virtual bool RunWithWindow(apps::ShellWindow* window) OVERRIDE; + virtual bool RunWithWindow(ShellWindow* window) OVERRIDE; }; } // namespace extensions diff --git a/chrome/browser/extensions/api/app_window/app_window_api.cc b/chrome/browser/extensions/api/app_window/app_window_api.cc index 7283c94..74a004f 100644 --- a/chrome/browser/extensions/api/app_window/app_window_api.cc +++ b/chrome/browser/extensions/api/app_window/app_window_api.cc @@ -4,7 +4,6 @@ #include "chrome/browser/extensions/api/app_window/app_window_api.h" -#include "apps/shell_window.h" #include "base/command_line.h" #include "base/time.h" #include "base/values.h" @@ -13,8 +12,8 @@ #include "chrome/browser/devtools/devtools_window.h" #include "chrome/browser/extensions/shell_window_registry.h" #include "chrome/browser/extensions/window_controller.h" -#include "chrome/browser/ui/apps/chrome_shell_window_delegate.h" #include "chrome/browser/ui/extensions/native_app_window.h" +#include "chrome/browser/ui/extensions/shell_window.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/api/app_window.h" #include "content/public/browser/notification_registrar.h" @@ -34,8 +33,6 @@ #include "ui/aura/window.h" #endif -using apps::ShellWindow; - namespace app_window = extensions::api::app_window; namespace Create = app_window::Create; @@ -292,12 +289,8 @@ bool AppWindowCreateFunction::RunImpl() { if (force_maximize) create_params.state = ui::SHOW_STATE_MAXIMIZED; - ShellWindow* shell_window = ShellWindow::Create( - profile(), - new chrome::ChromeShellWindowDelegate(), - GetExtension(), - url, - create_params); + ShellWindow* shell_window = + ShellWindow::Create(profile(), GetExtension(), url, create_params); if (chrome::ShouldForceFullscreenApp()) shell_window->Fullscreen(); diff --git a/chrome/browser/extensions/api/app_window/app_window_apitest.cc b/chrome/browser/extensions/api/app_window/app_window_apitest.cc index 31eeaf7..a7acfc3 100644 --- a/chrome/browser/extensions/api/app_window/app_window_apitest.cc +++ b/chrome/browser/extensions/api/app_window/app_window_apitest.cc @@ -2,7 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "apps/shell_window.h" #include "base/run_loop.h" #include "base/strings/string_number_conversions.h" #include "chrome/browser/extensions/extension_test_message_listener.h" @@ -10,6 +9,7 @@ #include "chrome/browser/extensions/shell_window_registry.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/extensions/native_app_window.h" +#include "chrome/browser/ui/extensions/shell_window.h" #include "chrome/test/base/testing_profile.h" #include "ui/base/base_window.h" #include "ui/gfx/rect.h" @@ -18,8 +18,6 @@ #include "content/public/test/test_utils.h" #endif -using apps::ShellWindow; - namespace { class TestShellWindowRegistryObserver diff --git a/chrome/browser/extensions/api/developer_private/developer_private_api.cc b/chrome/browser/extensions/api/developer_private/developer_private_api.cc index c54017b..0a72d79 100644 --- a/chrome/browser/extensions/api/developer_private/developer_private_api.cc +++ b/chrome/browser/extensions/api/developer_private/developer_private_api.cc @@ -7,7 +7,6 @@ #include "apps/app_load_service.h" #include "apps/app_restore_service.h" #include "apps/saved_files_service.h" -#include "apps/shell_window.h" #include "base/base64.h" #include "base/command_line.h" #include "base/file_util.h" @@ -33,6 +32,7 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/sync_file_system/drive_file_sync_service.h" #include "chrome/browser/ui/chrome_select_file_policy.h" +#include "chrome/browser/ui/extensions/shell_window.h" #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/chrome_switches.h" @@ -65,7 +65,6 @@ #include "webkit/browser/fileapi/syncable/syncable_file_system_util.h" #include "webkit/common/blob/shareable_file_reference.h" -using apps::ShellWindow; using content::RenderViewHost; namespace extensions { diff --git a/chrome/browser/extensions/api/developer_private/entry_picker.cc b/chrome/browser/extensions/api/developer_private/entry_picker.cc index 91bc1f3..e70ae4a 100644 --- a/chrome/browser/extensions/api/developer_private/entry_picker.cc +++ b/chrome/browser/extensions/api/developer_private/entry_picker.cc @@ -8,8 +8,10 @@ #include "base/files/file_path.h" #include "base/strings/string_util.h" #include "chrome/browser/extensions/api/developer_private/developer_private_api.h" +#include "chrome/browser/extensions/shell_window_registry.h" #include "chrome/browser/platform_util.h" #include "chrome/browser/ui/chrome_select_file_policy.h" +#include "chrome/browser/ui/extensions/shell_window.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_view.h" #include "ui/shell_dialogs/select_file_dialog.h" diff --git a/chrome/browser/extensions/api/file_system/file_system_api.cc b/chrome/browser/extensions/api/file_system/file_system_api.cc index 11234a6..c0241cf 100644 --- a/chrome/browser/extensions/api/file_system/file_system_api.cc +++ b/chrome/browser/extensions/api/file_system/file_system_api.cc @@ -5,7 +5,6 @@ #include "chrome/browser/extensions/api/file_system/file_system_api.h" #include "apps/saved_files_service.h" -#include "apps/shell_window.h" #include "base/bind.h" #include "base/file_util.h" #include "base/files/file_path.h" @@ -20,6 +19,7 @@ #include "chrome/browser/extensions/shell_window_registry.h" #include "chrome/browser/platform_util.h" #include "chrome/browser/ui/chrome_select_file_policy.h" +#include "chrome/browser/ui/extensions/shell_window.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/extensions/api/file_system.h" #include "chrome/common/extensions/permissions/api_permission.h" @@ -50,7 +50,6 @@ using apps::SavedFileEntry; using apps::SavedFilesService; -using apps::ShellWindow; using fileapi::IsolatedContext; const char kInvalidParameters[] = "Invalid parameters"; diff --git a/chrome/browser/extensions/api/identity/web_auth_flow.cc b/chrome/browser/extensions/api/identity/web_auth_flow.cc index 4a8f2ad..84fa56b 100644 --- a/chrome/browser/extensions/api/identity/web_auth_flow.cc +++ b/chrome/browser/extensions/api/identity/web_auth_flow.cc @@ -4,7 +4,6 @@ #include "chrome/browser/extensions/api/identity/web_auth_flow.h" -#include "apps/shell_window.h" #include "base/base64.h" #include "base/location.h" #include "base/message_loop.h" @@ -16,6 +15,7 @@ #include "chrome/browser/extensions/extension_system.h" #include "chrome/browser/extensions/extension_system.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/ui/extensions/shell_window.h" #include "chrome/common/extensions/extension_constants.h" #include "content/public/browser/navigation_details.h" #include "content/public/browser/navigation_entry.h" @@ -30,7 +30,6 @@ #include "googleurl/src/gurl.h" #include "grit/browser_resources.h" -using apps::ShellWindow; using content::RenderViewHost; using content::ResourceRedirectDetails; using content::WebContents; @@ -125,8 +124,6 @@ void WebAuthFlow::OnShellWindowAdded(ShellWindow* shell_window) { } } -void WebAuthFlow::OnShellWindowIconChanged(ShellWindow* shell_window) {} - void WebAuthFlow::OnShellWindowRemoved(ShellWindow* shell_window) { if (shell_window->window_key() == shell_window_key_ && shell_window->extension()->id() == extension_misc::kIdentityApiUiAppId) { diff --git a/chrome/browser/extensions/api/identity/web_auth_flow.h b/chrome/browser/extensions/api/identity/web_auth_flow.h index cbe42c6..df6c0f9 100644 --- a/chrome/browser/extensions/api/identity/web_auth_flow.h +++ b/chrome/browser/extensions/api/identity/web_auth_flow.h @@ -92,10 +92,9 @@ class WebAuthFlow : public content::NotificationObserver, friend class ::WebAuthFlowTest; // ShellWindowRegistry::Observer implementation. - virtual void OnShellWindowAdded(apps::ShellWindow* shell_window) OVERRIDE; - virtual void OnShellWindowIconChanged(apps::ShellWindow* shell_window) - OVERRIDE; - virtual void OnShellWindowRemoved(apps::ShellWindow* shell_window) OVERRIDE; + virtual void OnShellWindowAdded(ShellWindow* shell_window) OVERRIDE; + virtual void OnShellWindowIconChanged(ShellWindow* shell_window) OVERRIDE {} + virtual void OnShellWindowRemoved(ShellWindow* shell_window) OVERRIDE; // NotificationObserver implementation. virtual void Observe(int type, @@ -133,7 +132,7 @@ class WebAuthFlow : public content::NotificationObserver, GURL provider_url_; Mode mode_; - apps::ShellWindow* shell_window_; + ShellWindow* shell_window_; std::string shell_window_key_; bool embedded_window_created_; diff --git a/chrome/browser/extensions/api/media_galleries/media_galleries_api.cc b/chrome/browser/extensions/api/media_galleries/media_galleries_api.cc index 49d55f0..ec33b45 100644 --- a/chrome/browser/extensions/api/media_galleries/media_galleries_api.cc +++ b/chrome/browser/extensions/api/media_galleries/media_galleries_api.cc @@ -10,7 +10,6 @@ #include <string> #include <vector> -#include "apps/shell_window.h" #include "base/memory/scoped_ptr.h" #include "base/platform_file.h" #include "base/stl_util.h" @@ -22,6 +21,7 @@ #include "chrome/browser/media_galleries/media_galleries_dialog_controller.h" #include "chrome/browser/storage_monitor/storage_monitor.h" #include "chrome/browser/ui/chrome_select_file_policy.h" +#include "chrome/browser/ui/extensions/shell_window.h" #include "chrome/common/extensions/api/experimental_media_galleries.h" #include "chrome/common/extensions/api/media_galleries.h" #include "chrome/common/extensions/extension.h" @@ -39,7 +39,6 @@ #include "base/strings/sys_string_conversions.h" #endif -using apps::ShellWindow; using chrome::MediaFileSystemInfo; using chrome::MediaFileSystemRegistry; using chrome::MediaFileSystemsCallback; diff --git a/chrome/browser/extensions/api/tabs/ash_panel_contents.cc b/chrome/browser/extensions/api/tabs/ash_panel_contents.cc index 27b7d5e..37f7a24 100644 --- a/chrome/browser/extensions/api/tabs/ash_panel_contents.cc +++ b/chrome/browser/extensions/api/tabs/ash_panel_contents.cc @@ -13,6 +13,7 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/sessions/session_tab_helper.h" #include "chrome/browser/ui/extensions/native_app_window.h" +#include "chrome/browser/ui/extensions/shell_window.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_messages.h" @@ -20,8 +21,6 @@ #include "content/public/browser/web_contents.h" #include "ui/gfx/image/image.h" -using apps::ShellWindow; - // AshPanelWindowController ---------------------------------------------------- // This class enables a ShellWindow instance to be accessed (to a limited diff --git a/chrome/browser/extensions/api/tabs/ash_panel_contents.h b/chrome/browser/extensions/api/tabs/ash_panel_contents.h index 4f79971..5aa0c46 100644 --- a/chrome/browser/extensions/api/tabs/ash_panel_contents.h +++ b/chrome/browser/extensions/api/tabs/ash_panel_contents.h @@ -7,11 +7,11 @@ #include <vector> -#include "apps/shell_window.h" #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" #include "chrome/browser/extensions/extension_function_dispatcher.h" #include "chrome/browser/ui/ash/launcher/launcher_favicon_loader.h" +#include "chrome/browser/ui/extensions/shell_window.h" #include "content/public/browser/web_contents_observer.h" class AshPanelWindowController; @@ -25,20 +25,20 @@ namespace extensions { struct DraggableRegion; } -// apps::ShellWindowContents class specific to panel windows created by v1 +// ShellWindowContents class specific to panel windows created by v1 // extenstions. This class maintains a WebContents instance and observes it for // the purpose of passing messages to the extensions system. It also creates // an extensions::WindowController instance for interfacing with the v1 // extensions API. -class AshPanelContents : public apps::ShellWindowContents, +class AshPanelContents : public ShellWindowContents, public content::WebContentsObserver, public LauncherFaviconLoader::Delegate, public ExtensionFunctionDispatcher::Delegate { public: - explicit AshPanelContents(apps::ShellWindow* host); + explicit AshPanelContents(ShellWindow* host); virtual ~AshPanelContents(); - // apps::ShellWindowContents + // ShellWindowContents virtual void Initialize(Profile* profile, const GURL& url) OVERRIDE; virtual void LoadContents(int32 creator_process_id) OVERRIDE; virtual void NativeWindowChanged(NativeAppWindow* native_app_window) OVERRIDE; @@ -63,7 +63,7 @@ class AshPanelContents : public apps::ShellWindowContents, void OnRequest(const ExtensionHostMsg_Request_Params& params); - apps::ShellWindow* host_; + ShellWindow* host_; GURL url_; scoped_ptr<content::WebContents> web_contents_; scoped_ptr<ExtensionFunctionDispatcher> extension_function_dispatcher_; diff --git a/chrome/browser/extensions/api/tabs/tabs_api.cc b/chrome/browser/extensions/api/tabs/tabs_api.cc index 1a7027e..911ba62 100644 --- a/chrome/browser/extensions/api/tabs/tabs_api.cc +++ b/chrome/browser/extensions/api/tabs/tabs_api.cc @@ -8,7 +8,6 @@ #include <limits> #include <vector> -#include "apps/shell_window.h" #include "base/base64.h" #include "base/bind.h" #include "base/command_line.h" @@ -35,7 +34,6 @@ #include "chrome/browser/prefs/incognito_mode_prefs.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/translate/translate_tab_helper.h" -#include "chrome/browser/ui/apps/chrome_shell_window_delegate.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_commands.h" #include "chrome/browser/ui/browser_finder.h" @@ -43,6 +41,7 @@ #include "chrome/browser/ui/browser_navigator.h" #include "chrome/browser/ui/browser_tabstrip.h" #include "chrome/browser/ui/browser_window.h" +#include "chrome/browser/ui/extensions/shell_window.h" #include "chrome/browser/ui/host_desktop.h" #include "chrome/browser/ui/panels/panel_manager.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" @@ -98,7 +97,6 @@ #include "chrome/browser/extensions/shell_window_registry.h" #endif -using apps::ShellWindow; using content::BrowserThread; using content::NavigationController; using content::NavigationEntry; @@ -587,9 +585,8 @@ bool WindowsCreateFunction::RunImpl() { create_params.window_type = ShellWindow::WINDOW_TYPE_V1_PANEL; create_params.bounds = window_bounds; create_params.focused = saw_focus_key && focused; - ShellWindow* shell_window = new ShellWindow( - window_profile, new chrome::ChromeShellWindowDelegate(), - GetExtension()); + ShellWindow* shell_window = + new ShellWindow(window_profile, GetExtension()); AshPanelContents* ash_panel_contents = new AshPanelContents(shell_window); shell_window->Init(urls[0], ash_panel_contents, create_params); SetResult(ash_panel_contents->GetExtensionWindowController()-> diff --git a/chrome/browser/extensions/app_window_contents.cc b/chrome/browser/extensions/app_window_contents.cc index 5c6ff07..8a92b25 100644 --- a/chrome/browser/extensions/app_window_contents.cc +++ b/chrome/browser/extensions/app_window_contents.cc @@ -21,8 +21,6 @@ namespace app_window = extensions::api::app_window; -using apps::ShellWindow; - AppWindowContents::AppWindowContents(ShellWindow* host) : host_(host) { } diff --git a/chrome/browser/extensions/app_window_contents.h b/chrome/browser/extensions/app_window_contents.h index bb37787..3cf2a32 100644 --- a/chrome/browser/extensions/app_window_contents.h +++ b/chrome/browser/extensions/app_window_contents.h @@ -7,10 +7,10 @@ #include <vector> -#include "apps/shell_window.h" #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" #include "chrome/browser/extensions/extension_function_dispatcher.h" +#include "chrome/browser/ui/extensions/shell_window.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/web_contents_observer.h" @@ -24,18 +24,18 @@ namespace extensions { struct DraggableRegion; } -// apps::ShellWindowContents class specific to app windows. It maintains a +// ShellWindowContents class specific to app windows. It maintains a // WebContents instance and observes it for the purpose of passing // messages to the extensions system. -class AppWindowContents : public apps::ShellWindowContents, +class AppWindowContents : public ShellWindowContents, public content::NotificationObserver, public content::WebContentsObserver, public ExtensionFunctionDispatcher::Delegate { public: - explicit AppWindowContents(apps::ShellWindow* host); + explicit AppWindowContents(ShellWindow* host); virtual ~AppWindowContents(); - // apps::ShellWindowContents + // ShellWindowContents virtual void Initialize(Profile* profile, const GURL& url) OVERRIDE; virtual void LoadContents(int32 creator_process_id) OVERRIDE; virtual void NativeWindowChanged(NativeAppWindow* native_app_window) OVERRIDE; @@ -61,7 +61,7 @@ class AppWindowContents : public apps::ShellWindowContents, const std::vector<extensions::DraggableRegion>& regions); void SuspendRenderViewHost(content::RenderViewHost* rvh); - apps::ShellWindow* host_; // This class is owned by |host_| + ShellWindow* host_; // This class is owned by |host_| GURL url_; content::NotificationRegistrar registrar_; scoped_ptr<content::WebContents> web_contents_; diff --git a/chrome/browser/extensions/extension_tab_util.cc b/chrome/browser/extensions/extension_tab_util.cc index e8e50b0..02985e0 100644 --- a/chrome/browser/extensions/extension_tab_util.cc +++ b/chrome/browser/extensions/extension_tab_util.cc @@ -4,7 +4,6 @@ #include "chrome/browser/extensions/extension_tab_util.h" -#include "apps/shell_window.h" #include "chrome/browser/extensions/api/tabs/tabs_constants.h" #include "chrome/browser/extensions/shell_window_registry.h" #include "chrome/browser/extensions/tab_helper.h" @@ -17,6 +16,7 @@ #include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/browser_iterator.h" #include "chrome/browser/ui/browser_window.h" +#include "chrome/browser/ui/extensions/shell_window.h" #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/common/extensions/extension.h" @@ -33,7 +33,6 @@ namespace keys = extensions::tabs_constants; namespace tabs = extensions::api::tabs; -using apps::ShellWindow; using content::NavigationEntry; using content::WebContents; using extensions::APIPermission; diff --git a/chrome/browser/extensions/platform_app_browsertest.cc b/chrome/browser/extensions/platform_app_browsertest.cc index 28168bb..03b046c 100644 --- a/chrome/browser/extensions/platform_app_browsertest.cc +++ b/chrome/browser/extensions/platform_app_browsertest.cc @@ -2,7 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "apps/shell_window.h" #include "base/bind.h" #include "base/file_util.h" #include "base/files/scoped_temp_dir.h" @@ -30,6 +29,7 @@ #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/extensions/application_launch.h" #include "chrome/browser/ui/extensions/native_app_window.h" +#include "chrome/browser/ui/extensions/shell_window.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/chrome_switches.h" @@ -45,7 +45,6 @@ #include "net/test/embedded_test_server/embedded_test_server.h" #include "googleurl/src/gurl.h" -using apps::ShellWindow; using content::WebContents; using web_modal::WebContentsModalDialogManager; diff --git a/chrome/browser/extensions/platform_app_browsertest_util.cc b/chrome/browser/extensions/platform_app_browsertest_util.cc index 2d1cdd0..4fb285f 100644 --- a/chrome/browser/extensions/platform_app_browsertest_util.cc +++ b/chrome/browser/extensions/platform_app_browsertest_util.cc @@ -9,7 +9,6 @@ #include "chrome/browser/extensions/api/tabs/tabs_api.h" #include "chrome/browser/extensions/extension_function_test_utils.h" #include "chrome/browser/extensions/shell_window_registry.h" -#include "chrome/browser/ui/apps/chrome_shell_window_delegate.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/extensions/application_launch.h" #include "chrome/browser/ui/extensions/native_app_window.h" @@ -17,7 +16,6 @@ #include "content/public/browser/notification_service.h" #include "content/public/test/test_utils.h" -using apps::ShellWindow; using content::WebContents; namespace utils = extension_function_test_utils; @@ -25,7 +23,7 @@ namespace utils = extension_function_test_utils; namespace extensions { PlatformAppBrowserTest::PlatformAppBrowserTest() { - chrome::ChromeShellWindowDelegate::DisableExternalOpenForTesting(); + ShellWindow::DisableExternalOpenForTesting(); } void PlatformAppBrowserTest::SetUpCommandLine(CommandLine* command_line) { @@ -148,15 +146,13 @@ ShellWindow* PlatformAppBrowserTest::CreateShellWindow( const Extension* extension) { ShellWindow::CreateParams params; return ShellWindow::Create( - browser()->profile(), new chrome::ChromeShellWindowDelegate(), - extension, GURL(std::string()), params); + browser()->profile(), extension, GURL(std::string()), params); } ShellWindow* PlatformAppBrowserTest::CreateShellWindowFromParams( const Extension* extension, const ShellWindow::CreateParams& params) { return ShellWindow::Create( - browser()->profile(), new chrome::ChromeShellWindowDelegate(), - extension, GURL(std::string()), params); + browser()->profile(), extension, GURL(std::string()), params); } void PlatformAppBrowserTest::CloseShellWindow(ShellWindow* window) { diff --git a/chrome/browser/extensions/platform_app_browsertest_util.h b/chrome/browser/extensions/platform_app_browsertest_util.h index 6cc179b..d6147c74 100644 --- a/chrome/browser/extensions/platform_app_browsertest_util.h +++ b/chrome/browser/extensions/platform_app_browsertest_util.h @@ -6,14 +6,15 @@ #define CHROME_BROWSER_EXTENSIONS_PLATFORM_APP_BROWSERTEST_UTIL_H_ -#include "apps/shell_window.h" #include "chrome/browser/extensions/extension_apitest.h" +#include "chrome/browser/ui/extensions/shell_window.h" namespace content { class WebContents; } class CommandLine; +class ShellWindow; namespace extensions { class Extension; @@ -40,7 +41,7 @@ class PlatformAppBrowserTest : public ExtensionApiTest { // Gets the first shell window that is found (most tests only deal with one // platform app window, so this is good enough). - apps::ShellWindow* GetFirstShellWindow(); + ShellWindow* GetFirstShellWindow(); // Runs chrome.windows.getAll for the given extension and returns the number // of windows that the function returns. @@ -63,18 +64,17 @@ class PlatformAppBrowserTest : public ExtensionApiTest { void SetCommandLineArg(const std::string& test_file); // Creates an empty shell window for |extension|. - apps::ShellWindow* CreateShellWindow(const Extension* extension); + ShellWindow* CreateShellWindow(const Extension* extension); - apps::ShellWindow* CreateShellWindowFromParams( - const Extension* extension, - const apps::ShellWindow::CreateParams& params); + ShellWindow* CreateShellWindowFromParams( + const Extension* extension, const ShellWindow::CreateParams& params); // Closes |window| and waits until it's gone. - void CloseShellWindow(apps::ShellWindow* window); + void CloseShellWindow(ShellWindow* window); // Call AdjustBoundsToBeVisibleOnScreen of |window|. void CallAdjustBoundsToBeVisibleOnScreenForShellWindow( - apps::ShellWindow* window, + ShellWindow* window, const gfx::Rect& cached_bounds, const gfx::Rect& cached_screen_bounds, const gfx::Rect& current_screen_bounds, @@ -87,6 +87,6 @@ class ExperimentalPlatformAppBrowserTest : public PlatformAppBrowserTest { virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE; }; -} // namespace extensions +} // namespace extensions #endif // CHROME_BROWSER_EXTENSIONS_PLATFORM_APP_BROWSERTEST_UTIL_H_ diff --git a/chrome/browser/extensions/shell_window_registry.cc b/chrome/browser/extensions/shell_window_registry.cc index 38a8d38..4e4c02a 100644 --- a/chrome/browser/extensions/shell_window_registry.cc +++ b/chrome/browser/extensions/shell_window_registry.cc @@ -2,12 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "apps/shell_window.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/extensions/shell_window_registry.h" #include "chrome/browser/profiles/incognito_helpers.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/ui/extensions/native_app_window.h" +#include "chrome/browser/ui/extensions/shell_window.h" #include "chrome/common/extensions/extension.h" #include "components/browser_context_keyed_service/browser_context_dependency_manager.h" #include "content/public/browser/devtools_agent_host.h" @@ -17,8 +17,6 @@ #include "content/public/browser/site_instance.h" #include "content/public/browser/web_contents.h" -using apps::ShellWindow; - namespace { // Create a key that identifies a ShellWindow in a RenderViewHost across App @@ -43,7 +41,7 @@ std::string GetWindowKeyForRenderViewHost( return key; } -} // namespace +} namespace extensions { diff --git a/chrome/browser/extensions/shell_window_registry.h b/chrome/browser/extensions/shell_window_registry.h index da1072c..ba3dd76 100644 --- a/chrome/browser/extensions/shell_window_registry.h +++ b/chrome/browser/extensions/shell_window_registry.h @@ -16,10 +16,7 @@ #include "ui/gfx/native_widget_types.h" class Profile; - -namespace apps { class ShellWindow; -} namespace content { class DevToolsAgentHost; @@ -40,17 +37,17 @@ class ShellWindowRegistry : public BrowserContextKeyedService { class Observer { public: // Called just after a shell window was added. - virtual void OnShellWindowAdded(apps::ShellWindow* shell_window) = 0; + virtual void OnShellWindowAdded(ShellWindow* shell_window) = 0; // Called when the window icon changes. - virtual void OnShellWindowIconChanged(apps::ShellWindow* shell_window) = 0; + virtual void OnShellWindowIconChanged(ShellWindow* shell_window) = 0; // Called just after a shell window was removed. - virtual void OnShellWindowRemoved(apps::ShellWindow* shell_window) = 0; + virtual void OnShellWindowRemoved(ShellWindow* shell_window) = 0; protected: virtual ~Observer() {} }; - typedef std::list<apps::ShellWindow*> ShellWindowList; + typedef std::list<ShellWindow*> ShellWindowList; typedef ShellWindowList::const_iterator const_iterator; typedef std::set<std::string> InspectedWindowSet; @@ -61,11 +58,11 @@ class ShellWindowRegistry : public BrowserContextKeyedService { // a convenience wrapper around ShellWindowRegistry::Factory::GetForProfile. static ShellWindowRegistry* Get(Profile* profile); - void AddShellWindow(apps::ShellWindow* shell_window); - void ShellWindowIconChanged(apps::ShellWindow* shell_window); + void AddShellWindow(ShellWindow* shell_window); + void ShellWindowIconChanged(ShellWindow* shell_window); // Called by |shell_window| when it is activated. - void ShellWindowActivated(apps::ShellWindow* shell_window); - void RemoveShellWindow(apps::ShellWindow* shell_window); + void ShellWindowActivated(ShellWindow* shell_window); + void RemoveShellWindow(ShellWindow* shell_window); void AddObserver(Observer* observer); void RemoveObserver(Observer* observer); @@ -75,22 +72,19 @@ class ShellWindowRegistry : public BrowserContextKeyedService { const ShellWindowList& shell_windows() const { return shell_windows_; } // Helper functions to find shell windows with particular attributes. - apps::ShellWindow* GetShellWindowForRenderViewHost( + ShellWindow* GetShellWindowForRenderViewHost( content::RenderViewHost* render_view_host) const; - apps::ShellWindow* GetShellWindowForNativeWindow( - gfx::NativeWindow window) const; + ShellWindow* GetShellWindowForNativeWindow(gfx::NativeWindow window) const; // Returns an app window for the given app, or NULL if no shell windows are // open. If there is a window for the given app that is active, that one will // be returned, otherwise an arbitrary window will be returned. - apps::ShellWindow* GetCurrentShellWindowForApp( - const std::string& app_id) const; + ShellWindow* GetCurrentShellWindowForApp(const std::string& app_id) const; // Returns an app window for the given app and window key, or NULL if no shell // window with the key are open. If there is a window for the given app and // key that is active, that one will be returned, otherwise an arbitrary // window will be returned. - apps::ShellWindow* GetShellWindowForAppAndKey( - const std::string& app_id, - const std::string& window_key) const; + ShellWindow* GetShellWindowForAppAndKey(const std::string& app_id, + const std::string& window_key) const; // Returns whether a ShellWindow's ID was last known to have a DevToolsAgent // attached to it, which should be restored during a reload of a corresponding @@ -98,7 +92,7 @@ class ShellWindowRegistry : public BrowserContextKeyedService { bool HadDevToolsAttached(content::RenderViewHost* render_view_host) const; // Returns the shell window for |window|, looking in all profiles. - static apps::ShellWindow* GetShellWindowForNativeWindowAnyProfile( + static ShellWindow* GetShellWindowForNativeWindowAnyProfile( gfx::NativeWindow window); // Returns true if the number of shell windows registered across all profiles @@ -132,11 +126,11 @@ class ShellWindowRegistry : public BrowserContextKeyedService { private: // Ensures the specified |shell_window| is included in |shell_windows_|. // Otherwise adds |shell_window| to the back of |shell_windows_|. - void AddShellWindowToList(apps::ShellWindow* shell_window); + void AddShellWindowToList(ShellWindow* shell_window); // Bring |shell_window| to the front of |shell_windows_|. If it is not in the // list, add it first. - void BringToFront(apps::ShellWindow* shell_window); + void BringToFront(ShellWindow* shell_window); Profile* profile_; ShellWindowList shell_windows_; diff --git a/chrome/browser/extensions/web_view_browsertest.cc b/chrome/browser/extensions/web_view_browsertest.cc index 0553614..91c751d 100644 --- a/chrome/browser/extensions/web_view_browsertest.cc +++ b/chrome/browser/extensions/web_view_browsertest.cc @@ -1084,7 +1084,7 @@ IN_PROC_BROWSER_TEST_F(WebViewTest, TearDownTest) { const extensions::Extension* extension = LoadAndLaunchPlatformApp("web_view/teardown"); ASSERT_TRUE(first_loaded_listener.WaitUntilSatisfied()); - apps::ShellWindow* window = NULL; + ShellWindow* window = NULL; if (!GetShellWindowCount()) window = CreateShellWindow(extension); else diff --git a/chrome/browser/extensions/web_view_interactive_browsertest.cc b/chrome/browser/extensions/web_view_interactive_browsertest.cc index 69b5cbc..eb696e6 100644 --- a/chrome/browser/extensions/web_view_interactive_browsertest.cc +++ b/chrome/browser/extensions/web_view_interactive_browsertest.cc @@ -1,13 +1,13 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// Copyright (c) 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. -#include "apps/shell_window.h" #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" #include "chrome/browser/extensions/extension_test_message_listener.h" #include "chrome/browser/extensions/platform_app_browsertest_util.h" #include "chrome/browser/extensions/shell_window_registry.h" +#include "chrome/browser/ui/extensions/shell_window.h" #include "chrome/test/base/interactive_test_utils.h" #include "chrome/test/base/test_launcher_utils.h" #include "chrome/test/base/ui_test_utils.h" @@ -22,8 +22,6 @@ #include "ui/base/keycodes/keyboard_codes.h" #include "ui/base/test/ui_controls.h" -using apps::ShellWindow; - class WebViewInteractiveTest : public extensions::PlatformAppBrowserTest { public: diff --git a/chrome/browser/sessions/session_id.h b/chrome/browser/sessions/session_id.h index dd9d02d..f4d103b 100644 --- a/chrome/browser/sessions/session_id.h +++ b/chrome/browser/sessions/session_id.h @@ -7,6 +7,8 @@ #include "base/basictypes.h" +class Browser; + namespace content { class WebContents; } diff --git a/chrome/browser/ui/apps/chrome_shell_window_delegate.cc b/chrome/browser/ui/apps/chrome_shell_window_delegate.cc deleted file mode 100644 index 25c1ffb..0000000 --- a/chrome/browser/ui/apps/chrome_shell_window_delegate.cc +++ /dev/null @@ -1,156 +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. - -#include "chrome/browser/ui/apps/chrome_shell_window_delegate.h" - -#include "base/stringprintf.h" -#include "chrome/browser/favicon/favicon_tab_helper.h" -#include "chrome/browser/file_select_helper.h" -#include "chrome/browser/media/media_capture_devices_dispatcher.h" -#include "chrome/browser/platform_util.h" -#include "chrome/browser/ui/browser.h" -#include "chrome/browser/ui/browser_dialogs.h" -#include "chrome/browser/ui/browser_finder.h" -#include "chrome/browser/ui/browser_tabstrip.h" -#include "chrome/browser/ui/browser_window.h" -#include "chrome/common/render_messages.h" -#include "content/public/browser/render_view_host.h" -#include "content/public/browser/web_contents.h" -#include "content/public/browser/web_contents_view.h" - -#if defined(USE_ASH) -#include "ash/launcher/launcher_types.h" -#endif - -namespace chrome { - -namespace { - -bool disable_external_open_for_testing_ = false; - -class ShellWindowLinkDelegate : public content::WebContentsDelegate { - public: - ShellWindowLinkDelegate(); - - private: - virtual content::WebContents* OpenURLFromTab( - content::WebContents* source, - const content::OpenURLParams& params) OVERRIDE; - - DISALLOW_COPY_AND_ASSIGN(ShellWindowLinkDelegate); -}; - -ShellWindowLinkDelegate::ShellWindowLinkDelegate() {} - -// TODO(rockot): Add a test that exercises this code. See -// http://crbug.com/254260. -content::WebContents* ShellWindowLinkDelegate::OpenURLFromTab( - content::WebContents* source, - const content::OpenURLParams& params) { - platform_util::OpenExternal(params.url); - delete source; - return NULL; -} - -} // namespace - -ChromeShellWindowDelegate::ChromeShellWindowDelegate() {} - -ChromeShellWindowDelegate::~ChromeShellWindowDelegate() {} - -void ChromeShellWindowDelegate::DisableExternalOpenForTesting() { - disable_external_open_for_testing_ = true; -} - -void ChromeShellWindowDelegate::InitWebContents( - content::WebContents* web_contents) { - FaviconTabHelper::CreateForWebContents(web_contents); -} - -content::WebContents* ChromeShellWindowDelegate::OpenURLFromTab( - Profile* profile, - content::WebContents* source, - const content::OpenURLParams& params) { - // Force all links to open in a new tab, even if they were trying to open a - // window. - chrome::NavigateParams new_tab_params( - static_cast<Browser*>(NULL), params.url, params.transition); - new_tab_params.disposition = params.disposition == NEW_BACKGROUND_TAB ? - params.disposition : NEW_FOREGROUND_TAB; - new_tab_params.initiating_profile = profile; - chrome::Navigate(&new_tab_params); - - return new_tab_params.target_contents; -} - -void ChromeShellWindowDelegate::AddNewContents( - Profile* profile, - content::WebContents* new_contents, - WindowOpenDisposition disposition, - const gfx::Rect& initial_pos, - bool user_gesture, - bool* was_blocked) { -#if defined(OS_MACOSX) || defined(OS_WIN) || \ - (defined(OS_LINUX) && !defined(OS_CHROMEOS)) - if (!disable_external_open_for_testing_) { - new_contents->SetDelegate(new ShellWindowLinkDelegate()); - return; - } -#endif - Browser* browser = - chrome::FindOrCreateTabbedBrowser(profile, chrome::GetActiveDesktop()); - // Force all links to open in a new tab, even if they were trying to open a - // new window. - disposition = - disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; - chrome::AddWebContents(browser, NULL, new_contents, disposition, initial_pos, - user_gesture, was_blocked); -} - -content::ColorChooser* ChromeShellWindowDelegate::ShowColorChooser( - content::WebContents* web_contents, - SkColor initial_color) { - return chrome::ShowColorChooser(web_contents, initial_color); -} - -void ChromeShellWindowDelegate::RunFileChooser( - content::WebContents* tab, - const content::FileChooserParams& params) { - FileSelectHelper::RunFileChooser(tab, params); -} - -void ChromeShellWindowDelegate::RequestMediaAccessPermission( - content::WebContents* web_contents, - const content::MediaStreamRequest& request, - const content::MediaResponseCallback& callback, - const extensions::Extension* extension) { - MediaCaptureDevicesDispatcher::GetInstance()->ProcessMediaAccessRequest( - web_contents, request, callback, extension); -} - -int ChromeShellWindowDelegate::PreferredIconSize() { -#if defined(USE_ASH) - return ash::kLauncherPreferredSize; -#else - return extension_misc::EXTENSION_ICON_SMALL; -#endif -} - -void ChromeShellWindowDelegate::SetWebContentsBlocked( - content::WebContents* web_contents, - bool blocked) { - // RenderViewHost may be NULL during shutdown. - content::RenderViewHost* host = web_contents->GetRenderViewHost(); - if (host) { - host->Send(new ChromeViewMsg_SetVisuallyDeemphasized( - host->GetRoutingID(), blocked)); - } -} - -bool ChromeShellWindowDelegate::IsWebContentsVisible( - content::WebContents* web_contents) { - return platform_util::IsVisible(web_contents->GetView()->GetNativeView()); -} - -} // namespace chrome diff --git a/chrome/browser/ui/apps/chrome_shell_window_delegate.h b/chrome/browser/ui/apps/chrome_shell_window_delegate.h deleted file mode 100644 index 4bad8b2..0000000 --- a/chrome/browser/ui/apps/chrome_shell_window_delegate.h +++ /dev/null @@ -1,59 +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. - -#ifndef CHROME_BROWSER_UI_APPS_CHROME_SHELL_WINDOW_DELEGATE_H_ -#define CHROME_BROWSER_UI_APPS_CHROME_SHELL_WINDOW_DELEGATE_H_ - -#include "apps/shell_window.h" -#include "chrome/browser/profiles/profile.h" -#include "content/public/browser/web_contents.h" -#include "content/public/browser/web_contents_delegate.h" -#include "ui/base/window_open_disposition.h" -#include "ui/gfx/rect.h" - -namespace chrome { - -class ChromeShellWindowDelegate : public apps::ShellWindow::Delegate { - public: - ChromeShellWindowDelegate(); - virtual ~ChromeShellWindowDelegate(); - - static void DisableExternalOpenForTesting(); - - private: - // apps::ShellWindow::Delegate: - virtual void InitWebContents(content::WebContents* web_contents) OVERRIDE; - virtual content::WebContents* OpenURLFromTab( - Profile* profile, - content::WebContents* source, - const content::OpenURLParams& params) OVERRIDE; - virtual void AddNewContents(Profile* profile, - content::WebContents* new_contents, - WindowOpenDisposition disposition, - const gfx::Rect& initial_pos, - bool user_gesture, - bool* was_blocked) OVERRIDE; - virtual content::ColorChooser* ShowColorChooser( - content::WebContents* web_contents, - SkColor initial_color) OVERRIDE; - virtual void RunFileChooser( - content::WebContents* tab, - const content::FileChooserParams& params) OVERRIDE; - virtual void RequestMediaAccessPermission( - content::WebContents* web_contents, - const content::MediaStreamRequest& request, - const content::MediaResponseCallback& callback, - const extensions::Extension* extension) OVERRIDE; - virtual int PreferredIconSize() OVERRIDE; - virtual void SetWebContentsBlocked(content::WebContents* web_contents, - bool blocked) OVERRIDE; - virtual bool IsWebContentsVisible( - content::WebContents* web_contents) OVERRIDE; - - DISALLOW_COPY_AND_ASSIGN(ChromeShellWindowDelegate); -}; - -} // namespace chrome - -#endif // CHROME_BROWSER_UI_APPS_CHROME_SHELL_WINDOW_DELEGATE_H_ diff --git a/chrome/browser/ui/ash/chrome_shell_delegate.cc b/chrome/browser/ui/ash/chrome_shell_delegate.cc index e00338f..a0a3f3d 100644 --- a/chrome/browser/ui/ash/chrome_shell_delegate.cc +++ b/chrome/browser/ui/ash/chrome_shell_delegate.cc @@ -4,7 +4,6 @@ #include "chrome/browser/ui/ash/chrome_shell_delegate.h" -#include "apps/shell_window.h" #include "ash/ash_switches.h" #include "ash/host/root_window_host_factory.h" #include "ash/launcher/launcher_types.h" @@ -37,6 +36,7 @@ #include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/extensions/native_app_window.h" +#include "chrome/browser/ui/extensions/shell_window.h" #include "chrome/browser/ui/host_desktop.h" #include "chrome/browser/ui/immersive_fullscreen_configuration.h" #include "chrome/common/chrome_notification_types.h" @@ -188,7 +188,7 @@ void ChromeShellDelegate::ToggleFullscreen() { } // |window| may belong to a shell window. - apps::ShellWindow* shell_window = extensions::ShellWindowRegistry:: + ShellWindow* shell_window = extensions::ShellWindowRegistry:: GetShellWindowForNativeWindowAnyProfile(window); if (shell_window) { if (is_fullscreen) diff --git a/chrome/browser/ui/ash/chrome_shell_delegate_browsertest.cc b/chrome/browser/ui/ash/chrome_shell_delegate_browsertest.cc index 66a8927..e7e43e2 100644 --- a/chrome/browser/ui/ash/chrome_shell_delegate_browsertest.cc +++ b/chrome/browser/ui/ash/chrome_shell_delegate_browsertest.cc @@ -4,7 +4,6 @@ #include "chrome/browser/ui/ash/chrome_shell_delegate.h" -#include "apps/shell_window.h" #include "ash/ash_switches.h" #include "ash/shell.h" #include "ash/shell_delegate.h" @@ -174,7 +173,7 @@ IN_PROC_BROWSER_TEST_F(ChromeShellDelegatePlatformAppBrowserTest, ASSERT_TRUE(shell_delegate); const extensions::Extension* extension = LoadAndLaunchPlatformApp("minimal"); - apps::ShellWindow* shell_window = CreateShellWindow(extension); + ShellWindow* shell_window = CreateShellWindow(extension); NativeAppWindow* app_window = shell_window->GetBaseWindow(); ASSERT_TRUE(shell_window->GetBaseWindow()->IsActive()); EXPECT_FALSE(app_window->IsMaximized()); diff --git a/chrome/browser/ui/ash/chrome_shell_delegate_chromeos.cc b/chrome/browser/ui/ash/chrome_shell_delegate_chromeos.cc index 09becbb..f13d629 100644 --- a/chrome/browser/ui/ash/chrome_shell_delegate_chromeos.cc +++ b/chrome/browser/ui/ash/chrome_shell_delegate_chromeos.cc @@ -29,6 +29,7 @@ #include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/extensions/application_launch.h" #include "chrome/browser/ui/extensions/native_app_window.h" +#include "chrome/browser/ui/extensions/shell_window.h" #include "chrome/browser/ui/webui/chrome_web_contents_handler.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/chrome_switches.h" diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_browsertest.cc b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_browsertest.cc index 8bcd379..e584338 100644 --- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_browsertest.cc +++ b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_browsertest.cc @@ -4,7 +4,6 @@ #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" -#include "apps/shell_window.h" #include "ash/ash_switches.h" #include "ash/launcher/launcher.h" #include "ash/launcher/launcher_model.h" @@ -30,6 +29,7 @@ #include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/extensions/application_launch.h" #include "chrome/browser/ui/extensions/native_app_window.h" +#include "chrome/browser/ui/extensions/shell_window.h" #include "chrome/browser/ui/host_desktop.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/common/chrome_notification_types.h" @@ -43,7 +43,6 @@ #include "ui/aura/client/aura_constants.h" #include "ui/aura/window.h" -using apps::ShellWindow; using extensions::Extension; using content::WebContents; diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app_browsertest.cc b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app_browsertest.cc index 621d225..b31c8a7 100644 --- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app_browsertest.cc +++ b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app_browsertest.cc @@ -4,7 +4,6 @@ #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" -#include "apps/shell_window.h" #include "ash/ash_switches.h" #include "ash/display/display_controller.h" #include "ash/launcher/launcher.h" @@ -36,6 +35,7 @@ #include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/extensions/application_launch.h" #include "chrome/browser/ui/extensions/native_app_window.h" +#include "chrome/browser/ui/extensions/shell_window.h" #include "chrome/browser/ui/host_desktop.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/common/chrome_notification_types.h" @@ -51,7 +51,6 @@ #include "ui/aura/window.h" #include "ui/base/events/event.h" -using apps::ShellWindow; using extensions::Extension; using content::WebContents; diff --git a/chrome/browser/ui/ash/launcher/shell_window_launcher_controller.cc b/chrome/browser/ui/ash/launcher/shell_window_launcher_controller.cc index 779a8f9..ffad984 100644 --- a/chrome/browser/ui/ash/launcher/shell_window_launcher_controller.cc +++ b/chrome/browser/ui/ash/launcher/shell_window_launcher_controller.cc @@ -4,17 +4,15 @@ #include "chrome/browser/ui/ash/launcher/shell_window_launcher_controller.h" -#include "apps/shell_window.h" #include "ash/shell.h" #include "ash/wm/window_util.h" #include "base/stl_util.h" #include "base/strings/stringprintf.h" #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" #include "chrome/browser/ui/ash/launcher/shell_window_launcher_item_controller.h" +#include "chrome/browser/ui/extensions/shell_window.h" #include "ui/aura/client/activation_client.h" -using apps::ShellWindow; - namespace { std::string GetAppLauncherId(ShellWindow* shell_window) { diff --git a/chrome/browser/ui/ash/launcher/shell_window_launcher_controller.h b/chrome/browser/ui/ash/launcher/shell_window_launcher_controller.h index c47c357..9c279f6 100644 --- a/chrome/browser/ui/ash/launcher/shell_window_launcher_controller.h +++ b/chrome/browser/ui/ash/launcher/shell_window_launcher_controller.h @@ -13,10 +13,6 @@ #include "ui/aura/client/activation_change_observer.h" #include "ui/aura/window_observer.h" -namespace apps { -class ShellWindow; -} - namespace aura { class Window; @@ -28,6 +24,7 @@ class ActivationClient; } class ChromeLauncherController; +class ShellWindow; class ShellWindowLauncherItemController; // ShellWindowLauncherController observes the Shell Window registry and the @@ -42,10 +39,9 @@ class ShellWindowLauncherController virtual ~ShellWindowLauncherController(); // Overridden from ShellWindowRegistry::Observer: - virtual void OnShellWindowAdded(apps::ShellWindow* shell_window) OVERRIDE; - virtual void OnShellWindowIconChanged( - apps::ShellWindow* shell_window) OVERRIDE; - virtual void OnShellWindowRemoved(apps::ShellWindow* shell_window) OVERRIDE; + virtual void OnShellWindowAdded(ShellWindow* shell_window) OVERRIDE; + virtual void OnShellWindowIconChanged(ShellWindow* shell_window) OVERRIDE; + virtual void OnShellWindowRemoved(ShellWindow* shell_window) OVERRIDE; // Overriden from aura::WindowObserver: virtual void OnWindowDestroying(aura::Window* window) OVERRIDE; diff --git a/chrome/browser/ui/ash/launcher/shell_window_launcher_item_controller.cc b/chrome/browser/ui/ash/launcher/shell_window_launcher_item_controller.cc index 703a8e5..276f899 100644 --- a/chrome/browser/ui/ash/launcher/shell_window_launcher_item_controller.cc +++ b/chrome/browser/ui/ash/launcher/shell_window_launcher_item_controller.cc @@ -4,7 +4,6 @@ #include "chrome/browser/ui/ash/launcher/shell_window_launcher_item_controller.h" -#include "apps/shell_window.h" #include "ash/wm/window_properties.h" #include "ash/wm/window_util.h" #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" @@ -13,14 +12,13 @@ #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.h" #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" #include "chrome/browser/ui/extensions/native_app_window.h" +#include "chrome/browser/ui/extensions/shell_window.h" #include "content/public/browser/web_contents.h" #include "ui/aura/client/aura_constants.h" #include "ui/aura/window.h" #include "ui/base/events/event.h" #include "ui/views/corewm/window_animations.h" -using apps::ShellWindow; - namespace { // Functor for std::find_if used in AppLauncherItemController. diff --git a/chrome/browser/ui/ash/launcher/shell_window_launcher_item_controller.h b/chrome/browser/ui/ash/launcher/shell_window_launcher_item_controller.h index acf4308..182ca98 100644 --- a/chrome/browser/ui/ash/launcher/shell_window_launcher_item_controller.h +++ b/chrome/browser/ui/ash/launcher/shell_window_launcher_item_controller.h @@ -13,10 +13,6 @@ #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" #include "ui/aura/window_observer.h" -namespace apps { -class ShellWindow; -} - namespace aura { class Window; } @@ -26,6 +22,7 @@ class Image; } class ChromeLauncherController; +class ShellWindow; // This is a ShellWindowItemLauncherController for shell windows. There is one // instance per app, per launcher id. @@ -45,7 +42,7 @@ class ShellWindowLauncherItemController : public LauncherItemController, virtual ~ShellWindowLauncherItemController(); - void AddShellWindow(apps::ShellWindow* shell_window, + void AddShellWindow(ShellWindow* shell_window, ash::LauncherItemStatus status); void RemoveShellWindowForWindow(aura::Window* window); @@ -82,19 +79,19 @@ class ShellWindowLauncherItemController : public LauncherItemController, void ActivateIndexedApp(size_t index); private: - typedef std::list<apps::ShellWindow*> ShellWindowList; + typedef std::list<ShellWindow*> ShellWindowList; - void ShowAndActivateOrMinimize(apps::ShellWindow* shell_window); + void ShowAndActivateOrMinimize(ShellWindow* shell_window); // Activate the given |window_to_show|, or - if already selected - advance to // the next window of similar type. - void ActivateOrAdvanceToNextShellWindow(apps::ShellWindow* window_to_show); + void ActivateOrAdvanceToNextShellWindow(ShellWindow* window_to_show); // List of associated shell windows ShellWindowList shell_windows_; // Pointer to the most recently active shell window - apps::ShellWindow* last_active_shell_window_; + ShellWindow* last_active_shell_window_; // The launcher id associated with this set of windows. There is one // AppLauncherItemController for each |app_launcher_id_|. diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc index e8f7e2e..ca9444a 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc @@ -8,7 +8,6 @@ #include <map> #include <string> -#include "apps/shell_window.h" #include "base/base64.h" #include "base/bind.h" #include "base/i18n/rtl.h" @@ -31,6 +30,7 @@ #include "chrome/browser/ui/browser_navigator.h" #include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/extensions/native_app_window.h" +#include "chrome/browser/ui/extensions/shell_window.h" #include "chrome/common/chrome_version_info.h" #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" @@ -225,7 +225,7 @@ ui::BaseWindow* GetBaseWindowForWebContents( gfx::NativeWindow native_window = web_contents->GetView()->GetTopLevelNativeWindow(); - apps::ShellWindow* shell_window = + ShellWindow* shell_window = extensions::ShellWindowRegistry:: GetShellWindowForNativeWindowAnyProfile(native_window); return shell_window->GetBaseWindow(); diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index 29d6050..aeb8983 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -107,6 +107,7 @@ #include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/chrome_pages.h" #include "chrome/browser/ui/chrome_select_file_policy.h" +#include "chrome/browser/ui/extensions/shell_window.h" #include "chrome/browser/ui/find_bar/find_bar.h" #include "chrome/browser/ui/find_bar/find_bar_controller.h" #include "chrome/browser/ui/find_bar/find_tab_helper.h" diff --git a/chrome/browser/ui/chrome_web_modal_dialog_manager_delegate.cc b/chrome/browser/ui/chrome_web_modal_dialog_manager_delegate.cc index da6396e..7155008 100644 --- a/chrome/browser/ui/chrome_web_modal_dialog_manager_delegate.cc +++ b/chrome/browser/ui/chrome_web_modal_dialog_manager_delegate.cc @@ -1,4 +1,4 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// Copyright (c) 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. diff --git a/chrome/browser/ui/chrome_web_modal_dialog_manager_delegate.h b/chrome/browser/ui/chrome_web_modal_dialog_manager_delegate.h index 749debc..2263d75 100644 --- a/chrome/browser/ui/chrome_web_modal_dialog_manager_delegate.h +++ b/chrome/browser/ui/chrome_web_modal_dialog_manager_delegate.h @@ -1,4 +1,4 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// Copyright (c) 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. diff --git a/chrome/browser/ui/cocoa/extensions/native_app_window_cocoa.h b/chrome/browser/ui/cocoa/extensions/native_app_window_cocoa.h index 795dd6b..e32534e 100644 --- a/chrome/browser/ui/cocoa/extensions/native_app_window_cocoa.h +++ b/chrome/browser/ui/cocoa/extensions/native_app_window_cocoa.h @@ -8,11 +8,11 @@ #import <Cocoa/Cocoa.h> #include <vector> -#include "apps/shell_window.h" #include "base/mac/scoped_nsobject.h" #include "base/memory/scoped_ptr.h" #import "chrome/browser/ui/cocoa/browser_command_executor.h" #include "chrome/browser/ui/extensions/native_app_window.h" +#include "chrome/browser/ui/extensions/shell_window.h" #include "content/public/browser/notification_registrar.h" #include "extensions/common/draggable_region.h" #include "ui/gfx/rect.h" @@ -43,8 +43,8 @@ class SkRegion; // Cocoa bridge to AppWindow. class NativeAppWindowCocoa : public NativeAppWindow { public: - NativeAppWindowCocoa(apps::ShellWindow* shell_window, - const apps::ShellWindow::CreateParams& params); + NativeAppWindowCocoa(ShellWindow* shell_window, + const ShellWindow::CreateParams& params); // ui::BaseWindow implementation. virtual bool IsActive() const OVERRIDE; @@ -147,7 +147,7 @@ class NativeAppWindowCocoa : public NativeAppWindow { void UpdateDraggableRegionsForCustomDrag( const std::vector<extensions::DraggableRegion>& regions); - apps::ShellWindow* shell_window_; // weak - ShellWindow owns NativeAppWindow. + ShellWindow* shell_window_; // weak - ShellWindow owns NativeAppWindow. bool has_frame_; diff --git a/chrome/browser/ui/cocoa/extensions/native_app_window_cocoa.mm b/chrome/browser/ui/cocoa/extensions/native_app_window_cocoa.mm index d6ee237..583f7e9 100644 --- a/chrome/browser/ui/cocoa/extensions/native_app_window_cocoa.mm +++ b/chrome/browser/ui/cocoa/extensions/native_app_window_cocoa.mm @@ -20,8 +20,6 @@ #include "content/public/browser/web_contents_view.h" #include "third_party/skia/include/core/SkRegion.h" -using apps::ShellWindow; - @interface NSWindow (NSPrivateApis) - (void)setBottomCornerRounded:(BOOL)rounded; @end diff --git a/chrome/browser/ui/extensions/apps_metro_handler_win.cc b/chrome/browser/ui/extensions/apps_metro_handler_win.cc index 0f253b2..125c8bf 100644 --- a/chrome/browser/ui/extensions/apps_metro_handler_win.cc +++ b/chrome/browser/ui/extensions/apps_metro_handler_win.cc @@ -4,8 +4,8 @@ #include "chrome/browser/ui/extensions/apps_metro_handler_win.h" -#include "apps/shell_window.h" #include "chrome/browser/extensions/shell_window_registry.h" +#include "chrome/browser/ui/extensions/shell_window.h" #include "chrome/browser/ui/simple_message_box.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" @@ -15,7 +15,7 @@ namespace chrome { bool VerifySwitchToMetroForApps(gfx::NativeWindow parent_window) { if (!extensions::ShellWindowRegistry::IsShellWindowRegisteredInAnyProfile( - apps::ShellWindow::WINDOW_TYPE_DEFAULT)) { + ShellWindow::WINDOW_TYPE_DEFAULT)) { return true; } diff --git a/chrome/browser/ui/extensions/native_app_window.h b/chrome/browser/ui/extensions/native_app_window.h index 3e030f2..868b906 100644 --- a/chrome/browser/ui/extensions/native_app_window.h +++ b/chrome/browser/ui/extensions/native_app_window.h @@ -5,7 +5,7 @@ #ifndef CHROME_BROWSER_UI_EXTENSIONS_NATIVE_APP_WINDOW_H_ #define CHROME_BROWSER_UI_EXTENSIONS_NATIVE_APP_WINDOW_H_ -#include "apps/shell_window.h" +#include "chrome/browser/ui/extensions/shell_window.h" #include "components/web_modal/web_contents_modal_dialog_host.h" #include "ui/base/base_window.h" #include "ui/gfx/insets.h" @@ -16,10 +16,9 @@ class NativeAppWindow : public ui::BaseWindow, public web_modal::WebContentsModalDialogHost { public: - // Used by apps::ShellWindow to instantiate the platform-specific - // apps::ShellWindow code. - static NativeAppWindow* Create(apps::ShellWindow* window, - const apps::ShellWindow::CreateParams& params); + // Used by ShellWindow to instantiate the platform-specific ShellWindow code. + static NativeAppWindow* Create(ShellWindow* window, + const ShellWindow::CreateParams& params); // Called when the draggable regions are changed. virtual void UpdateDraggableRegions( diff --git a/chrome/browser/ui/extensions/shell_window.cc b/chrome/browser/ui/extensions/shell_window.cc new file mode 100644 index 0000000..27e55b78 --- /dev/null +++ b/chrome/browser/ui/extensions/shell_window.cc @@ -0,0 +1,703 @@ +// 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/ui/extensions/shell_window.h" + +#include "apps/shell_window_geometry_cache.h" +#include "base/strings/utf_string_conversions.h" +#include "base/values.h" +#include "chrome/browser/extensions/app_window_contents.h" +#include "chrome/browser/extensions/extension_process_manager.h" +#include "chrome/browser/extensions/extension_system.h" +#include "chrome/browser/extensions/image_loader.h" +#include "chrome/browser/extensions/shell_window_registry.h" +#include "chrome/browser/extensions/suggest_permission_util.h" +#include "chrome/browser/favicon/favicon_tab_helper.h" +#include "chrome/browser/file_select_helper.h" +#include "chrome/browser/lifetime/application_lifetime.h" +#include "chrome/browser/media/media_capture_devices_dispatcher.h" +#include "chrome/browser/platform_util.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/sessions/session_id.h" +#include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/browser_dialogs.h" +#include "chrome/browser/ui/browser_finder.h" +#include "chrome/browser/ui/browser_tabstrip.h" +#include "chrome/browser/ui/browser_window.h" +#include "chrome/browser/ui/extensions/native_app_window.h" +#include "chrome/common/chrome_notification_types.h" +#include "chrome/common/extensions/extension.h" +#include "chrome/common/extensions/extension_constants.h" +#include "chrome/common/extensions/extension_messages.h" +#include "chrome/common/extensions/manifest_handlers/icons_handler.h" +#include "components/web_modal/web_contents_modal_dialog_manager.h" +#include "content/public/browser/invalidate_type.h" +#include "content/public/browser/navigation_entry.h" +#include "content/public/browser/notification_details.h" +#include "content/public/browser/notification_service.h" +#include "content/public/browser/notification_source.h" +#include "content/public/browser/notification_types.h" +#include "content/public/browser/render_view_host.h" +#include "content/public/browser/resource_dispatcher_host.h" +#include "content/public/browser/web_contents.h" +#include "content/public/common/media_stream_request.h" +#include "extensions/browser/view_type_utils.h" +#include "skia/ext/image_operations.h" +#include "third_party/skia/include/core/SkRegion.h" +#include "ui/gfx/image/image_skia.h" +#include "ui/gfx/screen.h" + +#if defined(USE_ASH) +#include "ash/launcher/launcher_types.h" +#endif + +using content::ConsoleMessageLevel; +using content::WebContents; +using extensions::APIPermission; +using web_modal::WebContentsModalDialogHost; +using web_modal::WebContentsModalDialogManager; + +namespace { +const int kDefaultWidth = 512; +const int kDefaultHeight = 384; + +// The preferred icon size for displaying the app icon. +#if defined(USE_ASH) +const int kPreferredIconSize = ash::kLauncherPreferredSize; +#else +const int kPreferredIconSize = extension_misc::EXTENSION_ICON_SMALL; +#endif + +static bool disable_external_open_for_testing_ = false; + +class ShellWindowLinkDelegate : public content::WebContentsDelegate { + private: + virtual content::WebContents* OpenURLFromTab( + content::WebContents* source, + const content::OpenURLParams& params) OVERRIDE; +}; + +content::WebContents* ShellWindowLinkDelegate::OpenURLFromTab( + content::WebContents* source, + const content::OpenURLParams& params) { + platform_util::OpenExternal(params.url); + delete source; + return NULL; +} + +} // namespace + +ShellWindow::CreateParams::CreateParams() + : window_type(ShellWindow::WINDOW_TYPE_DEFAULT), + frame(ShellWindow::FRAME_CHROME), + transparent_background(false), + bounds(INT_MIN, INT_MIN, 0, 0), + creator_process_id(0), + state(ui::SHOW_STATE_DEFAULT), + hidden(false), + resizable(true), + focused(true) { +} + +ShellWindow::CreateParams::~CreateParams() { +} + +ShellWindow* ShellWindow::Create(Profile* profile, + const extensions::Extension* extension, + const GURL& url, + const CreateParams& params) { + // This object will delete itself when the window is closed. + ShellWindow* window = new ShellWindow(profile, extension); + window->Init(url, new AppWindowContents(window), params); + extensions::ShellWindowRegistry::Get(profile)->AddShellWindow(window); + return window; +} + +ShellWindow::ShellWindow(Profile* profile, + const extensions::Extension* extension) + : profile_(profile), + extension_(extension), + extension_id_(extension->id()), + window_type_(WINDOW_TYPE_DEFAULT), + image_loader_ptr_factory_(this), + fullscreen_for_window_api_(false), + fullscreen_for_tab_(false) { +} + +void ShellWindow::Init(const GURL& url, + ShellWindowContents* shell_window_contents, + const CreateParams& params) { + // Initialize the render interface and web contents + shell_window_contents_.reset(shell_window_contents); + shell_window_contents_->Initialize(profile(), url); + WebContents* web_contents = shell_window_contents_->GetWebContents(); + WebContentsModalDialogManager::CreateForWebContents(web_contents); + FaviconTabHelper::CreateForWebContents(web_contents); + + web_contents->SetDelegate(this); + WebContentsModalDialogManager::FromWebContents(web_contents)-> + set_delegate(this); + extensions::SetViewType(web_contents, extensions::VIEW_TYPE_APP_SHELL); + + // Initialize the window + window_type_ = params.window_type; + + gfx::Rect bounds = params.bounds; + + if (bounds.width() == 0) + bounds.set_width(kDefaultWidth); + if (bounds.height() == 0) + bounds.set_height(kDefaultHeight); + + // If left and top are left undefined, the native shell window will center + // the window on the main screen in a platform-defined manner. + + ui::WindowShowState cached_state = ui::SHOW_STATE_DEFAULT; + if (!params.window_key.empty()) { + window_key_ = params.window_key; + + apps::ShellWindowGeometryCache* cache = + apps::ShellWindowGeometryCache::Get(profile()); + + gfx::Rect cached_bounds; + gfx::Rect cached_screen_bounds; + if (cache->GetGeometry(extension()->id(), params.window_key, &cached_bounds, + &cached_screen_bounds, &cached_state)) { + bounds = cached_bounds; + // App window has cached screen bounds, make sure it fits on screen in + // case the screen resolution changed. + if (!cached_screen_bounds.IsEmpty()) { + gfx::Screen* screen = gfx::Screen::GetNativeScreen(); + gfx::Display display = screen->GetDisplayMatching(cached_bounds); + gfx::Rect current_screen_bounds = display.work_area(); + AdjustBoundsToBeVisibleOnScreen(cached_bounds, + cached_screen_bounds, + current_screen_bounds, + params.minimum_size, + &bounds); + } + } + } + + CreateParams new_params = params; + + gfx::Size& minimum_size = new_params.minimum_size; + gfx::Size& maximum_size = new_params.maximum_size; + + // In the case that minimum size > maximum size, we consider the minimum + // size to be more important. + if (maximum_size.width() && maximum_size.width() < minimum_size.width()) + maximum_size.set_width(minimum_size.width()); + if (maximum_size.height() && maximum_size.height() < minimum_size.height()) + maximum_size.set_height(minimum_size.height()); + + if (maximum_size.width() && bounds.width() > maximum_size.width()) + bounds.set_width(maximum_size.width()); + if (bounds.width() != INT_MIN && bounds.width() < minimum_size.width()) + bounds.set_width(minimum_size.width()); + + if (maximum_size.height() && bounds.height() > maximum_size.height()) + bounds.set_height(maximum_size.height()); + if (bounds.height() != INT_MIN && bounds.height() < minimum_size.height()) + bounds.set_height(minimum_size.height()); + + new_params.bounds = bounds; + + if (cached_state != ui::SHOW_STATE_DEFAULT) + new_params.state = cached_state; + + native_app_window_.reset(NativeAppWindow::Create(this, new_params)); + + if (!new_params.hidden) { + if (window_type_is_panel()) + GetBaseWindow()->ShowInactive(); // Panels are not activated by default. + else + GetBaseWindow()->Show(); + } + + if (new_params.state == ui::SHOW_STATE_FULLSCREEN) + Fullscreen(); + else if (new_params.state == ui::SHOW_STATE_MAXIMIZED) + Maximize(); + else if (new_params.state == ui::SHOW_STATE_MINIMIZED) + Minimize(); + + OnNativeWindowChanged(); + + // When the render view host is changed, the native window needs to know + // about it in case it has any setup to do to make the renderer appear + // properly. In particular, on Windows, the view's clickthrough region needs + // to be set. + registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, + content::Source<content::NavigationController>( + &web_contents->GetController())); + registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, + content::Source<Profile>(profile_)); + // Close when the browser is exiting. + // TODO(mihaip): we probably don't want this in the long run (when platform + // apps are no longer tied to the browser process). + registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, + content::NotificationService::AllSources()); + + shell_window_contents_->LoadContents(params.creator_process_id); + + // Prevent the browser process from shutting down while this window is open. + chrome::StartKeepAlive(); + + UpdateExtensionAppIcon(); +} + +ShellWindow::~ShellWindow() { + // Unregister now to prevent getting NOTIFICATION_APP_TERMINATING if we're the + // last window open. + registrar_.RemoveAll(); + + // Remove shutdown prevention. + chrome::EndKeepAlive(); +} + +void ShellWindow::RequestMediaAccessPermission( + content::WebContents* web_contents, + const content::MediaStreamRequest& request, + const content::MediaResponseCallback& callback) { + MediaCaptureDevicesDispatcher::GetInstance()->ProcessMediaAccessRequest( + web_contents, request, callback, extension()); +} + +WebContents* ShellWindow::OpenURLFromTab(WebContents* source, + const content::OpenURLParams& params) { + // Don't allow the current tab to be navigated. It would be nice to map all + // anchor tags (even those without target="_blank") to new tabs, but right + // now we can't distinguish between those and <meta> refreshes or window.href + // navigations, which we don't want to allow. + // TOOD(mihaip): Can we check for user gestures instead? + WindowOpenDisposition disposition = params.disposition; + if (disposition == CURRENT_TAB) { + AddMessageToDevToolsConsole( + content::CONSOLE_MESSAGE_LEVEL_ERROR, + base::StringPrintf( + "Can't open same-window link to \"%s\"; try target=\"_blank\".", + params.url.spec().c_str())); + return NULL; + } + + // These dispositions aren't really navigations. + if (disposition == SUPPRESS_OPEN || disposition == SAVE_TO_DISK || + disposition == IGNORE_ACTION) { + return NULL; + } + + // Force all links to open in a new tab, even if they were trying to open a + // window. + chrome::NavigateParams new_tab_params( + static_cast<Browser*>(NULL), params.url, params.transition); + new_tab_params.disposition = + disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; + new_tab_params.initiating_profile = profile_; + chrome::Navigate(&new_tab_params); + + if (!new_tab_params.target_contents) { + AddMessageToDevToolsConsole( + content::CONSOLE_MESSAGE_LEVEL_ERROR, + base::StringPrintf( + "Can't navigate to \"%s\"; apps do not support navigation.", + params.url.spec().c_str())); + } + + return new_tab_params.target_contents; +} + +void ShellWindow::AddNewContents(WebContents* source, + WebContents* new_contents, + WindowOpenDisposition disposition, + const gfx::Rect& initial_pos, + bool user_gesture, + bool* was_blocked) { + DCHECK(Profile::FromBrowserContext(new_contents->GetBrowserContext()) == + profile_); +#if defined(OS_MACOSX) || defined(OS_WIN) || \ + (defined(OS_LINUX) && !defined(OS_CHROMEOS)) + if (disable_external_open_for_testing_) { + Browser* browser = + chrome::FindOrCreateTabbedBrowser(profile_, chrome::GetActiveDesktop()); + // Force all links to open in a new tab, even if they were trying to open a + // new window. + disposition = + disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; + chrome::AddWebContents(browser, NULL, new_contents, disposition, + initial_pos, user_gesture, was_blocked); + } else { + new_contents->SetDelegate(new ShellWindowLinkDelegate()); + } +#else + Browser* browser = + chrome::FindOrCreateTabbedBrowser(profile_, chrome::GetActiveDesktop()); + // Force all links to open in a new tab, even if they were trying to open a + // new window. + disposition = + disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; + chrome::AddWebContents(browser, NULL, new_contents, disposition, initial_pos, + user_gesture, was_blocked); +#endif +} + +void ShellWindow::HandleKeyboardEvent( + WebContents* source, + const content::NativeWebKeyboardEvent& event) { + native_app_window_->HandleKeyboardEvent(event); +} + +void ShellWindow::RequestToLockMouse(WebContents* web_contents, + bool user_gesture, + bool last_unlocked_by_target) { + bool has_permission = IsExtensionWithPermissionOrSuggestInConsole( + APIPermission::kPointerLock, + extension_, + web_contents->GetRenderViewHost()); + + web_contents->GotResponseToLockMouseRequest(has_permission); +} + +void ShellWindow::OnNativeClose() { + extensions::ShellWindowRegistry::Get(profile_)->RemoveShellWindow(this); + if (shell_window_contents_) + shell_window_contents_->NativeWindowClosed(); + delete this; +} + +void ShellWindow::OnNativeWindowChanged() { + SaveWindowPosition(); + if (shell_window_contents_ && native_app_window_) + shell_window_contents_->NativeWindowChanged(native_app_window_.get()); +} + +void ShellWindow::OnNativeWindowActivated() { + extensions::ShellWindowRegistry::Get(profile_)->ShellWindowActivated(this); +} + +scoped_ptr<gfx::Image> ShellWindow::GetAppListIcon() { + // TODO(skuhne): We might want to use LoadImages in UpdateExtensionAppIcon + // instead to let the extension give us pre-defined icons in the launcher + // and the launcher list sizes. Since there is no mock yet, doing this now + // seems a bit premature and we scale for the time being. + if (app_icon_.IsEmpty()) + return make_scoped_ptr(new gfx::Image()); + + SkBitmap bmp = skia::ImageOperations::Resize( + *app_icon_.ToSkBitmap(), skia::ImageOperations::RESIZE_BEST, + extension_misc::EXTENSION_ICON_SMALLISH, + extension_misc::EXTENSION_ICON_SMALLISH); + return make_scoped_ptr( + new gfx::Image(gfx::ImageSkia::CreateFrom1xBitmap(bmp))); +} + +content::WebContents* ShellWindow::web_contents() const { + return shell_window_contents_->GetWebContents(); +} + +NativeAppWindow* ShellWindow::GetBaseWindow() { + return native_app_window_.get(); +} + +gfx::NativeWindow ShellWindow::GetNativeWindow() { + return GetBaseWindow()->GetNativeWindow(); +} + +gfx::Rect ShellWindow::GetClientBounds() const { + gfx::Rect bounds = native_app_window_->GetBounds(); + bounds.Inset(native_app_window_->GetFrameInsets()); + return bounds; +} + +string16 ShellWindow::GetTitle() const { + // WebContents::GetTitle() will return the page's URL if there's no <title> + // specified. However, we'd prefer to show the name of the extension in that + // case, so we directly inspect the NavigationEntry's title. + if (!web_contents() || + !web_contents()->GetController().GetActiveEntry() || + web_contents()->GetController().GetActiveEntry()->GetTitle().empty()) + return UTF8ToUTF16(extension()->name()); + string16 title = web_contents()->GetTitle(); + Browser::FormatTitleForDisplay(&title); + return title; +} + +void ShellWindow::SetAppIconUrl(const GURL& url) { + // Avoid using any previous app icons were are being downloaded. + image_loader_ptr_factory_.InvalidateWeakPtrs(); + + app_icon_url_ = url; + web_contents()->DownloadImage( + url, + true, // is a favicon + kPreferredIconSize, + 0, // no maximum size + base::Bind(&ShellWindow::DidDownloadFavicon, + image_loader_ptr_factory_.GetWeakPtr())); +} + +void ShellWindow::UpdateDraggableRegions( + const std::vector<extensions::DraggableRegion>& regions) { + native_app_window_->UpdateDraggableRegions(regions); +} + +void ShellWindow::UpdateAppIcon(const gfx::Image& image) { + if (image.IsEmpty()) + return; + app_icon_ = image; + native_app_window_->UpdateWindowIcon(); + extensions::ShellWindowRegistry::Get(profile_)->ShellWindowIconChanged(this); +} + +void ShellWindow::Fullscreen() { + fullscreen_for_window_api_ = true; + GetBaseWindow()->SetFullscreen(true); +} + +void ShellWindow::Maximize() { + GetBaseWindow()->Maximize(); +} + +void ShellWindow::Minimize() { + GetBaseWindow()->Minimize(); +} + +void ShellWindow::Restore() { + fullscreen_for_window_api_ = false; + fullscreen_for_tab_ = false; + if (GetBaseWindow()->IsFullscreenOrPending()) { + GetBaseWindow()->SetFullscreen(false); + } else { + GetBaseWindow()->Restore(); + } +} + +//------------------------------------------------------------------------------ +// Private methods + +void ShellWindow::OnImageLoaded(const gfx::Image& image) { + UpdateAppIcon(image); +} + +void ShellWindow::DidDownloadFavicon(int id, + int http_status_code, + const GURL& image_url, + int requested_size, + const std::vector<SkBitmap>& bitmaps) { + if (image_url != app_icon_url_ || bitmaps.empty()) + return; + + // Bitmaps are ordered largest to smallest. Choose the smallest bitmap + // whose height >= the preferred size. + int largest_index = 0; + for (size_t i = 1; i < bitmaps.size(); ++i) { + if (bitmaps[i].height() < kPreferredIconSize) + break; + largest_index = i; + } + const SkBitmap& largest = bitmaps[largest_index]; + UpdateAppIcon(gfx::Image::CreateFrom1xBitmap(largest)); +} + +void ShellWindow::UpdateExtensionAppIcon() { + // Avoid using any previous app icons were are being downloaded. + image_loader_ptr_factory_.InvalidateWeakPtrs(); + + // Enqueue OnImageLoaded callback. + extensions::ImageLoader* loader = extensions::ImageLoader::Get(profile()); + loader->LoadImageAsync( + extension(), + extensions::IconsInfo::GetIconResource(extension(), + kPreferredIconSize, + ExtensionIconSet::MATCH_BIGGER), + gfx::Size(kPreferredIconSize, kPreferredIconSize), + base::Bind(&ShellWindow::OnImageLoaded, + image_loader_ptr_factory_.GetWeakPtr())); +} + +void ShellWindow::CloseContents(WebContents* contents) { + native_app_window_->Close(); +} + +bool ShellWindow::ShouldSuppressDialogs() { + return true; +} + +content::ColorChooser* ShellWindow::OpenColorChooser(WebContents* web_contents, + SkColor initial_color) { + return chrome::ShowColorChooser(web_contents, initial_color); +} + +void ShellWindow::RunFileChooser(WebContents* tab, + const content::FileChooserParams& params) { + if (window_type_is_panel()) { + // Panels can't host a file dialog, abort. TODO(stevenjb): allow file + // dialogs to be unhosted but still close with the owning web contents. + // crbug.com/172502. + LOG(WARNING) << "File dialog opened by panel."; + return; + } + FileSelectHelper::RunFileChooser(tab, params); +} + +bool ShellWindow::IsPopupOrPanel(const WebContents* source) const { + return true; +} + +void ShellWindow::MoveContents(WebContents* source, const gfx::Rect& pos) { + native_app_window_->SetBounds(pos); +} + +void ShellWindow::NavigationStateChanged( + const content::WebContents* source, unsigned changed_flags) { + if (changed_flags & content::INVALIDATE_TYPE_TITLE) + native_app_window_->UpdateWindowTitle(); + else if (changed_flags & content::INVALIDATE_TYPE_TAB) + native_app_window_->UpdateWindowIcon(); +} + +void ShellWindow::ToggleFullscreenModeForTab(content::WebContents* source, + bool enter_fullscreen) { + if (!IsExtensionWithPermissionOrSuggestInConsole( + APIPermission::kFullscreen, + extension_, + source->GetRenderViewHost())) { + return; + } + + fullscreen_for_tab_ = enter_fullscreen; + + if (enter_fullscreen) { + native_app_window_->SetFullscreen(true); + } else if (!fullscreen_for_window_api_) { + native_app_window_->SetFullscreen(false); + } +} + +bool ShellWindow::IsFullscreenForTabOrPending( + const content::WebContents* source) const { + return fullscreen_for_tab_; +} + +void ShellWindow::Observe(int type, + const content::NotificationSource& source, + const content::NotificationDetails& details) { + switch (type) { + case content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED: { + // TODO(jianli): once http://crbug.com/123007 is fixed, we'll no longer + // need to make the native window (ShellWindowViews specially) update + // the clickthrough region for the new RVH. + native_app_window_->RenderViewHostChanged(); + break; + } + case chrome::NOTIFICATION_EXTENSION_UNLOADED: { + const extensions::Extension* unloaded_extension = + content::Details<extensions::UnloadedExtensionInfo>( + details)->extension; + if (extension_ == unloaded_extension) + native_app_window_->Close(); + break; + } + case chrome::NOTIFICATION_APP_TERMINATING: + native_app_window_->Close(); + break; + default: + NOTREACHED() << "Received unexpected notification"; + } +} + +extensions::ActiveTabPermissionGranter* + ShellWindow::GetActiveTabPermissionGranter() { + // Shell windows don't support the activeTab permission. + return NULL; +} + +WebContentsModalDialogHost* ShellWindow::GetWebContentsModalDialogHost() { + return native_app_window_.get(); +} + +void ShellWindow::AddMessageToDevToolsConsole(ConsoleMessageLevel level, + const std::string& message) { + content::RenderViewHost* rvh = web_contents()->GetRenderViewHost(); + rvh->Send(new ExtensionMsg_AddMessageToConsole( + rvh->GetRoutingID(), level, message)); +} + +void ShellWindow::SaveWindowPosition() { + if (window_key_.empty()) + return; + if (!native_app_window_) + return; + + apps::ShellWindowGeometryCache* cache = + apps::ShellWindowGeometryCache::Get(profile()); + + gfx::Rect bounds = native_app_window_->GetRestoredBounds(); + bounds.Inset(native_app_window_->GetFrameInsets()); + gfx::Rect screen_bounds = + gfx::Screen::GetNativeScreen()->GetDisplayMatching(bounds).work_area(); + ui::WindowShowState window_state = native_app_window_->GetRestoredState(); + cache->SaveGeometry(extension()->id(), + window_key_, + bounds, + screen_bounds, + window_state); +} + +void ShellWindow::AdjustBoundsToBeVisibleOnScreen( + const gfx::Rect& cached_bounds, + const gfx::Rect& cached_screen_bounds, + const gfx::Rect& current_screen_bounds, + const gfx::Size& minimum_size, + gfx::Rect* bounds) const { + if (!bounds) + return; + + *bounds = cached_bounds; + + // Reposition and resize the bounds if the cached_screen_bounds is different + // from the current screen bounds and the current screen bounds doesn't + // completely contain the bounds. + if (!cached_screen_bounds.IsEmpty() && + cached_screen_bounds != current_screen_bounds && + !current_screen_bounds.Contains(cached_bounds)) { + bounds->set_width( + std::max(minimum_size.width(), + std::min(bounds->width(), current_screen_bounds.width()))); + bounds->set_height( + std::max(minimum_size.height(), + std::min(bounds->height(), current_screen_bounds.height()))); + bounds->set_x( + std::max(current_screen_bounds.x(), + std::min(bounds->x(), + current_screen_bounds.right() - bounds->width()))); + bounds->set_y( + std::max(current_screen_bounds.y(), + std::min(bounds->y(), + current_screen_bounds.bottom() - bounds->height()))); + } +} + +// static +SkRegion* ShellWindow::RawDraggableRegionsToSkRegion( + const std::vector<extensions::DraggableRegion>& regions) { + SkRegion* sk_region = new SkRegion; + for (std::vector<extensions::DraggableRegion>::const_iterator iter = + regions.begin(); + iter != regions.end(); ++iter) { + const extensions::DraggableRegion& region = *iter; + sk_region->op( + region.bounds.x(), + region.bounds.y(), + region.bounds.right(), + region.bounds.bottom(), + region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); + } + return sk_region; +} + +void ShellWindow::DisableExternalOpenForTesting() { + disable_external_open_for_testing_ = true; +} + diff --git a/chrome/browser/ui/extensions/shell_window.h b/chrome/browser/ui/extensions/shell_window.h new file mode 100644 index 0000000..60a82d2 --- /dev/null +++ b/chrome/browser/ui/extensions/shell_window.h @@ -0,0 +1,328 @@ +// 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_UI_EXTENSIONS_SHELL_WINDOW_H_ +#define CHROME_BROWSER_UI_EXTENSIONS_SHELL_WINDOW_H_ + +#include "base/memory/scoped_ptr.h" +#include "base/memory/weak_ptr.h" +#include "chrome/browser/extensions/extension_keybinding_registry.h" +#include "chrome/browser/sessions/session_id.h" +#include "chrome/browser/ui/chrome_web_modal_dialog_manager_delegate.h" +#include "content/public/browser/notification_observer.h" +#include "content/public/browser/notification_registrar.h" +#include "content/public/browser/web_contents_delegate.h" +#include "content/public/common/console_message_level.h" +#include "ui/base/ui_base_types.h" // WindowShowState +#include "ui/gfx/image/image.h" +#include "ui/gfx/rect.h" + +class GURL; +class Profile; +class NativeAppWindow; +class SkRegion; + +namespace content { +class WebContents; +} + +namespace extensions { +class Extension; +class PlatformAppBrowserTest; +class WindowController; + +struct DraggableRegion; +} + +namespace ui { +class BaseWindow; +} + +// Manages the web contents for Shell Windows. The implementation for this +// class should create and maintain the WebContents for the window, and handle +// any message passing between the web contents and the extension system or +// native window. +class ShellWindowContents { + public: + ShellWindowContents() {} + virtual ~ShellWindowContents() {} + + // Called to initialize the WebContents, before the app window is created. + virtual void Initialize(Profile* profile, const GURL& url) = 0; + + // Called to load the contents, after the app window is created. + virtual void LoadContents(int32 creator_process_id) = 0; + + // Called when the native window changes. + virtual void NativeWindowChanged(NativeAppWindow* native_app_window) = 0; + + // Called when the native window closes. + virtual void NativeWindowClosed() = 0; + + virtual content::WebContents* GetWebContents() const = 0; + + private: + DISALLOW_COPY_AND_ASSIGN(ShellWindowContents); +}; + +// ShellWindow is the type of window used by platform apps. Shell windows +// have a WebContents but none of the chrome of normal browser windows. +class ShellWindow : public content::NotificationObserver, + public content::WebContentsDelegate, + public extensions::ExtensionKeybindingRegistry::Delegate, + public ChromeWebModalDialogManagerDelegate { + public: + enum WindowType { + WINDOW_TYPE_DEFAULT = 1 << 0, // Default shell window. + WINDOW_TYPE_PANEL = 1 << 1, // OS controlled panel window (Ash only). + WINDOW_TYPE_V1_PANEL = 1 << 2, // For apps v1 support in Ash; deprecate + // with v1 apps. + }; + + enum Frame { + FRAME_CHROME, // Chrome-style window frame. + FRAME_NONE, // Frameless window. + }; + + struct CreateParams { + CreateParams(); + ~CreateParams(); + + WindowType window_type; + Frame frame; + bool transparent_background; // Only supported on ash. + + // Specify the initial content bounds of the window (excluding any window + // decorations). INT_MIN designates 'unspecified' for the position + // components, and 0 for the size components. When unspecified, they should + // be replaced with a default value. + gfx::Rect bounds; + + gfx::Size minimum_size; + gfx::Size maximum_size; + + std::string window_key; + + // The process ID of the process that requested the create. + int32 creator_process_id; + + // Initial state of the window. + ui::WindowShowState state; + + // If true, don't show the window after creation. + bool hidden; + + // If true, the window will be resizable by the user. Defaults to true. + bool resizable; + + // If true, the window will be focused on creation. Defaults to true. + bool focused; + }; + + // Helper function for creating and intiailizing a v2 app window. + static ShellWindow* Create(Profile* profile, + const extensions::Extension* extension, + const GURL& url, + const CreateParams& params); + + // Convert draggable regions in raw format to SkRegion format. Caller is + // responsible for deleting the returned SkRegion instance. + static SkRegion* RawDraggableRegionsToSkRegion( + const std::vector<extensions::DraggableRegion>& regions); + + // The constructor and Init methods are public for constructing a ShellWindow + // with a non-standard render interface (e.g. v1 apps using Ash Panels). + // Normally ShellWindow::Create should be used. + ShellWindow(Profile* profile, const extensions::Extension* extension); + + // Initializes the render interface, web contents, and native window. + // |shell_window_contents| will become owned by ShellWindow. + void Init(const GURL& url, + ShellWindowContents* shell_window_contents, + const CreateParams& params); + + + const std::string& window_key() const { return window_key_; } + const SessionID& session_id() const { return session_id_; } + const extensions::Extension* extension() const { return extension_; } + const std::string& extension_id() const { return extension_id_; } + content::WebContents* web_contents() const; + WindowType window_type() const { return window_type_; } + bool window_type_is_panel() const { + return (window_type_ == WINDOW_TYPE_PANEL || + window_type_ == WINDOW_TYPE_V1_PANEL); + } + Profile* profile() const { return profile_; } + const gfx::Image& app_icon() const { return app_icon_; } + const GURL& app_icon_url() { return app_icon_url_; } + + NativeAppWindow* GetBaseWindow(); + gfx::NativeWindow GetNativeWindow(); + + // Returns the bounds that should be reported to the renderer. + gfx::Rect GetClientBounds() const; + + // This will return a slightly smaller icon then the app_icon to be used in + // application lists. + scoped_ptr<gfx::Image> GetAppListIcon(); + + // NativeAppWindows should call this to determine what the window's title + // is on startup and from within UpdateWindowTitle(). + string16 GetTitle() const; + + // Call to notify ShellRegistry and delete the window. Subclasses should + // invoke this method instead of using "delete this". + void OnNativeClose(); + + // Should be called by native implementations when the window size, position, + // or minimized/maximized state has changed. + void OnNativeWindowChanged(); + + // Should be called by native implementations when the window is activated. + void OnNativeWindowActivated(); + + // Specifies a url for the launcher icon. + void SetAppIconUrl(const GURL& icon_url); + + // Called from the render interface to modify the draggable regions. + void UpdateDraggableRegions( + const std::vector<extensions::DraggableRegion>& regions); + + // Updates the app image to |image|. Called internally from the image loader + // callback. Also called externally for v1 apps using Ash Panels. + void UpdateAppIcon(const gfx::Image& image); + + // Transitions window into fullscreen, maximized, minimized or restores based + // on chrome.app.window API. + void Fullscreen(); + void Maximize(); + void Minimize(); + void Restore(); + + ShellWindowContents* shell_window_contents_for_test() { + return shell_window_contents_.get(); + } + + static void DisableExternalOpenForTesting(); + + protected: + virtual ~ShellWindow(); + + private: + // PlatformAppBrowserTest needs access to web_contents() + friend class extensions::PlatformAppBrowserTest; + + // content::WebContentsDelegate implementation. + virtual void CloseContents(content::WebContents* contents) OVERRIDE; + virtual bool ShouldSuppressDialogs() OVERRIDE; + virtual content::ColorChooser* OpenColorChooser( + content::WebContents* web_contents, SkColor color) OVERRIDE; + virtual void RunFileChooser( + content::WebContents* tab, + const content::FileChooserParams& params) OVERRIDE; + virtual bool IsPopupOrPanel( + const content::WebContents* source) const OVERRIDE; + virtual void MoveContents( + content::WebContents* source, const gfx::Rect& pos) OVERRIDE; + virtual void NavigationStateChanged(const content::WebContents* source, + unsigned changed_flags) OVERRIDE; + virtual void ToggleFullscreenModeForTab(content::WebContents* source, + bool enter_fullscreen) OVERRIDE; + virtual bool IsFullscreenForTabOrPending( + const content::WebContents* source) const OVERRIDE; + virtual void RequestMediaAccessPermission( + content::WebContents* web_contents, + const content::MediaStreamRequest& request, + const content::MediaResponseCallback& callback) OVERRIDE; + virtual content::WebContents* OpenURLFromTab( + content::WebContents* source, + const content::OpenURLParams& params) OVERRIDE; + virtual void AddNewContents(content::WebContents* source, + content::WebContents* new_contents, + WindowOpenDisposition disposition, + const gfx::Rect& initial_pos, + bool user_gesture, + bool* was_blocked) OVERRIDE; + virtual void HandleKeyboardEvent( + content::WebContents* source, + const content::NativeWebKeyboardEvent& event) OVERRIDE; + virtual void RequestToLockMouse(content::WebContents* web_contents, + bool user_gesture, + bool last_unlocked_by_target) OVERRIDE; + + // content::NotificationObserver implementation. + virtual void Observe(int type, + const content::NotificationSource& source, + const content::NotificationDetails& details) OVERRIDE; + + // Helper method to add a message to the renderer's DevTools console. + void AddMessageToDevToolsConsole(content::ConsoleMessageLevel level, + const std::string& message); + + // Saves the window geometry/position/screen bounds. + void SaveWindowPosition(); + + // Helper method to adjust the cached bounds so that we can make sure it can + // be visible on the screen. See http://crbug.com/145752 . + void AdjustBoundsToBeVisibleOnScreen( + const gfx::Rect& cached_bounds, + const gfx::Rect& cached_screen_bounds, + const gfx::Rect& current_screen_bounds, + const gfx::Size& minimum_size, + gfx::Rect* bounds) const; + + // Load the app's image, firing a load state change when loaded. + void UpdateExtensionAppIcon(); + + void OnImageLoaded(const gfx::Image& image); + + // extensions::ExtensionKeybindingRegistry::Delegate implementation. + virtual extensions::ActiveTabPermissionGranter* + GetActiveTabPermissionGranter() OVERRIDE; + + // web_modal::WebContentsModalDialogManagerDelegate implementation. + virtual web_modal::WebContentsModalDialogHost* + GetWebContentsModalDialogHost() OVERRIDE; + + // Callback from web_contents()->DownloadFavicon. + void DidDownloadFavicon(int id, + int http_status_code, + const GURL& image_url, + int requested_size, + const std::vector<SkBitmap>& bitmaps); + + Profile* profile_; // weak pointer - owned by ProfileManager. + // weak pointer - owned by ExtensionService. + const extensions::Extension* extension_; + const std::string extension_id_; + + // Identifier that is used when saving and restoring geometry for this + // window. + std::string window_key_; + + const SessionID session_id_; + WindowType window_type_; + content::NotificationRegistrar registrar_; + + // Icon shown in the task bar. + gfx::Image app_icon_; + + // Icon URL to be used for setting the app icon. If not empty, app_icon_ will + // be fetched and set using this URL. + GURL app_icon_url_; + + scoped_ptr<NativeAppWindow> native_app_window_; + scoped_ptr<ShellWindowContents> shell_window_contents_; + + base::WeakPtrFactory<ShellWindow> image_loader_ptr_factory_; + + // Fullscreen entered by app.window api. + bool fullscreen_for_window_api_; + // Fullscreen entered by HTML requestFullscreen. + bool fullscreen_for_tab_; + + DISALLOW_COPY_AND_ASSIGN(ShellWindow); +}; + +#endif // CHROME_BROWSER_UI_EXTENSIONS_SHELL_WINDOW_H_ diff --git a/chrome/browser/ui/gtk/extensions/native_app_window_gtk.cc b/chrome/browser/ui/gtk/extensions/native_app_window_gtk.cc index 76e5b04..b715652 100644 --- a/chrome/browser/ui/gtk/extensions/native_app_window_gtk.cc +++ b/chrome/browser/ui/gtk/extensions/native_app_window_gtk.cc @@ -20,8 +20,6 @@ #include "ui/gfx/image/image.h" #include "ui/gfx/rect.h" -using apps::ShellWindow; - namespace { // The timeout in milliseconds before we'll get the true window position with diff --git a/chrome/browser/ui/gtk/extensions/native_app_window_gtk.h b/chrome/browser/ui/gtk/extensions/native_app_window_gtk.h index 1d6ed2b..e01f9bd 100644 --- a/chrome/browser/ui/gtk/extensions/native_app_window_gtk.h +++ b/chrome/browser/ui/gtk/extensions/native_app_window_gtk.h @@ -7,10 +7,10 @@ #include <gtk/gtk.h> -#include "apps/shell_window.h" #include "base/observer_list.h" #include "base/timer.h" #include "chrome/browser/ui/extensions/native_app_window.h" +#include "chrome/browser/ui/extensions/shell_window.h" #include "chrome/browser/ui/gtk/extensions/extension_view_gtk.h" #include "third_party/skia/include/core/SkRegion.h" #include "ui/base/gtk/gtk_signal.h" @@ -28,8 +28,8 @@ class NativeAppWindowGtk : public NativeAppWindow, public ExtensionViewGtk::Container, public ui::ActiveWindowWatcherXObserver { public: - NativeAppWindowGtk(apps::ShellWindow* shell_window, - const apps::ShellWindow::CreateParams& params); + NativeAppWindowGtk(ShellWindow* shell_window, + const ShellWindow::CreateParams& params); // ui::BaseWindow implementation. virtual bool IsActive() const OVERRIDE; @@ -105,7 +105,7 @@ class NativeAppWindowGtk : public NativeAppWindow, void OnDebouncedBoundsChanged(); - apps::ShellWindow* shell_window_; // weak - ShellWindow owns NativeAppWindow. + ShellWindow* shell_window_; // weak - ShellWindow owns NativeAppWindow. GtkWindow* window_; GdkWindowState state_; diff --git a/chrome/browser/ui/views/extensions/native_app_window_views.cc b/chrome/browser/ui/views/extensions/native_app_window_views.cc index 8d5433a..3fc9b08 100644 --- a/chrome/browser/ui/views/extensions/native_app_window_views.cc +++ b/chrome/browser/ui/views/extensions/native_app_window_views.cc @@ -47,8 +47,6 @@ #include "ui/aura/window.h" #endif -using apps::ShellWindow; - namespace { const int kMinPanelWidth = 100; diff --git a/chrome/browser/ui/views/extensions/native_app_window_views.h b/chrome/browser/ui/views/extensions/native_app_window_views.h index 138a9e0..0b66b57 100644 --- a/chrome/browser/ui/views/extensions/native_app_window_views.h +++ b/chrome/browser/ui/views/extensions/native_app_window_views.h @@ -5,9 +5,9 @@ #ifndef CHROME_BROWSER_UI_VIEWS_EXTENSIONS_NATIVE_APP_WINDOW_VIEWS_H_ #define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_NATIVE_APP_WINDOW_VIEWS_H_ -#include "apps/shell_window.h" #include "base/observer_list.h" #include "chrome/browser/ui/extensions/native_app_window.h" +#include "chrome/browser/ui/extensions/shell_window.h" #include "content/public/browser/web_contents_observer.h" #include "third_party/skia/include/core/SkRegion.h" #include "ui/gfx/image/image_skia.h" @@ -41,18 +41,16 @@ class NativeAppWindowViews : public NativeAppWindow, public views::WidgetObserver, public content::WebContentsObserver { public: - NativeAppWindowViews(apps::ShellWindow* shell_window, - const apps::ShellWindow::CreateParams& params); + NativeAppWindowViews(ShellWindow* shell_window, + const ShellWindow::CreateParams& params); virtual ~NativeAppWindowViews(); bool frameless() const { return frameless_; } SkRegion* draggable_region() { return draggable_region_.get(); } private: - void InitializeDefaultWindow( - const apps::ShellWindow::CreateParams& create_params); - void InitializePanelWindow( - const apps::ShellWindow::CreateParams& create_params); + void InitializeDefaultWindow(const ShellWindow::CreateParams& create_params); + void InitializePanelWindow(const ShellWindow::CreateParams& create_params); void OnViewWasResized(); bool ShouldUseChromeStyleFrame() const; @@ -156,7 +154,7 @@ class NativeAppWindowViews : public NativeAppWindow, return shell_window_->extension(); } - apps::ShellWindow* shell_window_; // weak - ShellWindow owns NativeAppWindow. + ShellWindow* shell_window_; // weak - ShellWindow owns NativeAppWindow. views::WebView* web_view_; views::Widget* window_; bool is_fullscreen_; diff --git a/chrome/browser/ui/views/select_file_dialog_extension.cc b/chrome/browser/ui/views/select_file_dialog_extension.cc index 09e9ee5..c5f4d4f 100644 --- a/chrome/browser/ui/views/select_file_dialog_extension.cc +++ b/chrome/browser/ui/views/select_file_dialog_extension.cc @@ -4,7 +4,6 @@ #include "chrome/browser/ui/views/select_file_dialog_extension.h" -#include "apps/shell_window.h" #include "base/bind.h" #include "base/callback.h" #include "base/logging.h" @@ -25,6 +24,7 @@ #include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/chrome_select_file_policy.h" #include "chrome/browser/ui/extensions/native_app_window.h" +#include "chrome/browser/ui/extensions/shell_window.h" #include "chrome/browser/ui/host_desktop.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/views/extensions/extension_dialog.h" @@ -33,7 +33,6 @@ #include "ui/base/base_window.h" #include "ui/shell_dialogs/selected_file_info.h" -using apps::ShellWindow; using content::BrowserThread; namespace { diff --git a/chrome/browser/ui/webui/extensions/extension_settings_handler.cc b/chrome/browser/ui/webui/extensions/extension_settings_handler.cc index 9720d60..7a370f4 100644 --- a/chrome/browser/ui/webui/extensions/extension_settings_handler.cc +++ b/chrome/browser/ui/webui/extensions/extension_settings_handler.cc @@ -7,7 +7,6 @@ #include "apps/app_load_service.h" #include "apps/app_restore_service.h" #include "apps/saved_files_service.h" -#include "apps/shell_window.h" #include "base/auto_reset.h" #include "base/base64.h" #include "base/bind.h" @@ -44,6 +43,7 @@ #include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/chrome_select_file_policy.h" #include "chrome/browser/ui/extensions/application_launch.h" +#include "chrome/browser/ui/extensions/shell_window.h" #include "chrome/browser/ui/webui/extensions/extension_basic_info.h" #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" #include "chrome/common/chrome_notification_types.h" |