15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 51320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#ifndef EXTENSIONS_BROWSER_APP_WINDOW_APP_WINDOW_H_ 61320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#define EXTENSIONS_BROWSER_APP_WINDOW_APP_WINDOW_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include <string> 9116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include <vector> 10116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h" 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/memory/weak_ptr.h" 1303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "components/sessions/session_id.h" 14116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "components/web_modal/popup_manager.h" 15eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" 1634680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)#include "content/public/browser/notification_observer.h" 1734680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)#include "content/public/browser/notification_registrar.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/web_contents_delegate.h" 19f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "content/public/browser/web_contents_observer.h" 206d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)#include "extensions/browser/extension_icon_image.h" 21b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "ui/base/ui_base_types.h" // WindowShowState 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/image/image.h" 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/rect.h" 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class GURL; 2690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class SkRegion; 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace base { 295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class DictionaryValue; 305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content { 335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class BrowserContext; 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WebContents; 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 371320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccinamespace ui { 381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass BaseWindow; 391320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci} 401320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace extensions { 421320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 4303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)class AppDelegate; 4403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)class AppWebContentsHelper; 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Extension; 4603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)class NativeAppWindow; 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class PlatformAppBrowserTest; 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WindowController; 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct DraggableRegion; 51eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Manages the web contents for app windows. The implementation for this 532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// class should create and maintain the WebContents for the window, and handle 542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// any message passing between the web contents and the extension system or 552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// native window. 565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class AppWindowContents { 572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) AppWindowContents() {} 595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual ~AppWindowContents() {} 602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Called to initialize the WebContents, before the app window is created. 625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void Initialize(content::BrowserContext* context, 635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const GURL& url) = 0; 642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Called to load the contents, after the app window is created. 662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void LoadContents(int32 creator_process_id) = 0; 672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Called when the native window changes. 691320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual void NativeWindowChanged(NativeAppWindow* native_app_window) = 0; 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Called when the native window closes. 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void NativeWindowClosed() = 0; 732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // Called in tests when the window is shown 7546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) virtual void DispatchWindowShownForTests() const = 0; 7646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual content::WebContents* GetWebContents() const = 0; 782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(AppWindowContents); 812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// AppWindow is the type of window used by platform apps. App windows 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// have a WebContents but none of the chrome of normal browser windows. 8534680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles)class AppWindow : public content::NotificationObserver, 8634680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles) public content::WebContentsDelegate, 875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public content::WebContentsObserver, 885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public web_modal::WebContentsModalDialogManagerDelegate, 8934680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles) public IconImage::Observer { 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) enum WindowType { 925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) WINDOW_TYPE_DEFAULT = 1 << 0, // Default app window. 935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) WINDOW_TYPE_PANEL = 1 << 1, // OS controlled panel window (Ash only). 94c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) WINDOW_TYPE_V1_PANEL = 1 << 2, // For apps v1 support in Ash; deprecate 95c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // with v1 apps. 962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) }; 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) enum Frame { 992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) FRAME_CHROME, // Chrome-style window frame. 1005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) FRAME_NONE, // Frameless window. 1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) }; 1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 103f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) enum FullscreenType { 104f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Not fullscreen. 105f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) FULLSCREEN_TYPE_NONE = 0, 106f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 107f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Fullscreen entered by the app.window api. 108f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) FULLSCREEN_TYPE_WINDOW_API = 1 << 0, 109f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 110f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Fullscreen entered by HTML requestFullscreen(). 111f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) FULLSCREEN_TYPE_HTML_API = 1 << 1, 112f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 113f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Fullscreen entered by the OS. ChromeOS uses this type of fullscreen to 114f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // enter immersive fullscreen when the user hits the <F4> key. 1155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) FULLSCREEN_TYPE_OS = 1 << 2, 1165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Fullscreen mode that could not be exited by the user. ChromeOS uses 1185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // this type of fullscreen to run an app in kiosk mode. 1195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) FULLSCREEN_TYPE_FORCED = 1 << 3, 120f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) }; 121f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 122a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) struct BoundsSpecification { 123a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // INT_MIN represents an unspecified position component. 124a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) static const int kUnspecifiedPosition; 1258bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 126a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) BoundsSpecification(); 127a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ~BoundsSpecification(); 1288bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 129a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // INT_MIN designates 'unspecified' for the position components, and 0 130a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // designates 'unspecified' for the size components. When unspecified, 131a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // they should be replaced with a default value. 132a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) gfx::Rect bounds; 1338bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 134a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) gfx::Size minimum_size; 135a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) gfx::Size maximum_size; 1368bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 137a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Reset the bounds fields to their 'unspecified' values. The minimum and 138a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // maximum size constraints remain unchanged. 139a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) void ResetBounds(); 1408bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) }; 1418bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) struct CreateParams { 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CreateParams(); 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ~CreateParams(); 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) WindowType window_type; 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Frame frame; 148a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 149a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) bool has_frame_color; 1505c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu SkColor active_frame_color; 1515c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu SkColor inactive_frame_color; 1526e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) bool alpha_enabled; 1532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 154a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // The initial content/inner bounds specification (excluding any window 155a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // decorations). 156a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) BoundsSpecification content_spec; 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 158a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // The initial window/outer bounds specification (including window 159a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // decorations). 160a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) BoundsSpecification window_spec; 1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string window_key; 1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The process ID of the process that requested the create. 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int32 creator_process_id; 1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 167c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Initial state of the window. 168b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) ui::WindowShowState state; 169c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If true, don't show the window after creation. 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool hidden; 1722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // If true, the window will be resizable by the user. Defaults to true. 1742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool resizable; 175c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 176c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // If true, the window will be focused on creation. Defaults to true. 177c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) bool focused; 1784e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1794e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // If true, the window will stay on top of other windows that are not 1804e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // configured to be always on top. Defaults to false. 1814e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) bool always_on_top; 182a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 1831320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // If true, the window will be visible on all workspaces. Defaults to false. 1841320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci bool visible_on_all_workspaces; 1851320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 186a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // The API enables developers to specify content or window bounds. This 187a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // function combines them into a single, constrained window size. 188a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) gfx::Rect GetInitialWindowBounds(const gfx::Insets& frame_insets) const; 189a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 190a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // The API enables developers to specify content or window size constraints. 191a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // These functions combine them so that we can work with one set of 192a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // constraints. 193a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) gfx::Size GetContentMinimumSize(const gfx::Insets& frame_insets) const; 194a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) gfx::Size GetContentMaximumSize(const gfx::Insets& frame_insets) const; 195a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) gfx::Size GetWindowMinimumSize(const gfx::Insets& frame_insets) const; 196a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) gfx::Size GetWindowMaximumSize(const gfx::Insets& frame_insets) const; 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Convert draggable regions in raw format to SkRegion format. Caller is 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // responsible for deleting the returned SkRegion instance. 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static SkRegion* RawDraggableRegionsToSkRegion( 2021320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci const std::vector<DraggableRegion>& regions); 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // The constructor and Init methods are public for constructing a AppWindow 2052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // with a non-standard render interface (e.g. v1 apps using Ash Panels). 2065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Normally AppWindow::Create should be used. 2075f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Takes ownership of |app_delegate| and |delegate|. 2085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) AppWindow(content::BrowserContext* context, 2091320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci AppDelegate* app_delegate, 2101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci const Extension* extension); 2112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Initializes the render interface, web contents, and native window. 2135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // |app_window_contents| will become owned by AppWindow. 2142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void Init(const GURL& url, 2155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) AppWindowContents* app_window_contents, 2162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const CreateParams& params); 2172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& window_key() const { return window_key_; } 2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const SessionID& session_id() const { return session_id_; } 22090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const std::string& extension_id() const { return extension_id_; } 2212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* web_contents() const; 2222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) WindowType window_type() const { return window_type_; } 2232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool window_type_is_panel() const { 2242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return (window_type_ == WINDOW_TYPE_PANEL || 2252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) window_type_ == WINDOW_TYPE_V1_PANEL); 2262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 2275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) content::BrowserContext* browser_context() const { return browser_context_; } 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const gfx::Image& app_icon() const { return app_icon_; } 2295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const GURL& app_icon_url() const { return app_icon_url_; } 2305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const gfx::Image& badge_icon() const { return badge_icon_; } 2315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const GURL& badge_icon_url() const { return badge_icon_url_; } 232cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) bool is_hidden() const { return is_hidden_; } 2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2341320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci const Extension* GetExtension() const; 2351320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci NativeAppWindow* GetBaseWindow(); 2362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::NativeWindow GetNativeWindow(); 2372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Returns the bounds that should be reported to the renderer. 2392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Rect GetClientBounds() const; 2402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // NativeAppWindows should call this to determine what the window's title 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // is on startup and from within UpdateWindowTitle(). 2435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::string16 GetTitle() const; 2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Call to notify ShellRegistry and delete the window. Subclasses should 2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // invoke this method instead of using "delete this". 2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void OnNativeClose(); 2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Should be called by native implementations when the window size, position, 2500f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // or minimized/maximized state has changed. 2512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void OnNativeWindowChanged(); 2522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 25390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Should be called by native implementations when the window is activated. 25490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void OnNativeWindowActivated(); 25590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 2562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Specifies a url for the launcher icon. 2572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void SetAppIconUrl(const GURL& icon_url); 2582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Specifies a url for the window badge. 2605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void SetBadgeIconUrl(const GURL& icon_url); 2615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Clear the current badge. 2635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void ClearBadge(); 2645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 265f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Set the window shape. Passing a NULL |region| sets the default shape. 266f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) void UpdateShape(scoped_ptr<SkRegion> region); 2673551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 2682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Called from the render interface to modify the draggable regions. 2691320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci void UpdateDraggableRegions(const std::vector<DraggableRegion>& regions); 2702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Updates the app image to |image|. Called internally from the image loader 2722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // callback. Also called externally for v1 apps using Ash Panels. 2732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void UpdateAppIcon(const gfx::Image& image); 2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2755f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Enable or disable fullscreen mode. |type| specifies which type of 2765f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // fullscreen mode to change (note that disabling one type of fullscreen may 2775f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // not exit fullscreen mode because a window may have a different type of 2785f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // fullscreen enabled). If |type| is not FORCED, checks that the extension has 2795f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // the required permission. 2805f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void SetFullscreen(FullscreenType type, bool enable); 2815f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 2825f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Returns true if the app window is in a fullscreen state. 2835f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool IsFullscreen() const; 2845f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 2855f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Returns true if the app window is in a forced fullscreen state (one that 2865f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // cannot be exited by the user). 2875f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool IsForcedFullscreen() const; 2885f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 2895f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Returns true if the app window is in a fullscreen state entered from an 2905f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // HTML API request. 2915f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool IsHtmlApiFullscreen() const; 2925f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 293c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Transitions window into fullscreen, maximized, minimized or restores based 294c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // on chrome.app.window API. 295c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) void Fullscreen(); 296c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) void Maximize(); 297c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) void Minimize(); 298c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) void Restore(); 299c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 300f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Transitions to OS fullscreen. See FULLSCREEN_TYPE_OS for more details. 301f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) void OSFullscreen(); 302f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 3035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Transitions to forced fullscreen. See FULLSCREEN_TYPE_FORCED for more 3045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // details. 3055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void ForcedFullscreen(); 3065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 307a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Set the minimum and maximum size of the content bounds. 308a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) void SetContentSizeConstraints(const gfx::Size& min_size, 309a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const gfx::Size& max_size); 3108bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 3115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) enum ShowType { SHOW_ACTIVE, SHOW_INACTIVE }; 312f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 313f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Shows the window if its contents have been painted; otherwise flags the 314f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // window to be shown as soon as its contents are painted for the first time. 315f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) void Show(ShowType show_type); 316f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 317f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Hides the window. If the window was previously flagged to be shown on 318f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // first paint, it will be unflagged. 319f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) void Hide(); 320f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 3215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) AppWindowContents* app_window_contents_for_test() { 3225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return app_window_contents_.get(); 323c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 324c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 325cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) int fullscreen_types_for_test() { 326cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) return fullscreen_types_; 327cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) } 328cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 329f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Set whether the window should stay above other windows which are not 330f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // configured to be always-on-top. 331f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) void SetAlwaysOnTop(bool always_on_top); 332f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 333f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Whether the always-on-top property has been set by the chrome.app.window 334f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // API. Note that the actual value of this property in the native app window 3355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // may be false if the bit is silently switched off for security reasons. 336f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) bool IsAlwaysOnTop() const; 337f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 3385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Retrieve the current state of the app window as a dictionary, to pass to 3395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // the renderer. 3405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void GetSerializedState(base::DictionaryValue* properties) const; 3415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 34246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // Called by the window API when events can be sent to the window for this 34346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // app. 34446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) void WindowEventsReady(); 34546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 3466e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // Whether the app window wants to be alpha enabled. 3476e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) bool requested_alpha_enabled() const { return requested_alpha_enabled_; } 348116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 3491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci void SetAppWindowContentsForTesting(scoped_ptr<AppWindowContents> contents) { 3501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci app_window_contents_ = contents.Pass(); 3511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci } 3521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 3545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual ~AppWindow(); 3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // PlatformAppBrowserTest needs access to web_contents() 3581320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci friend class PlatformAppBrowserTest; 3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // content::WebContentsDelegate implementation. 3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void CloseContents(content::WebContents* contents) OVERRIDE; 3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool ShouldSuppressDialogs() OVERRIDE; 36390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual content::ColorChooser* OpenColorChooser( 364a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) content::WebContents* web_contents, 365a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) SkColor color, 366a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const std::vector<content::ColorSuggestion>& suggestions) OVERRIDE; 3675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void RunFileChooser(content::WebContents* tab, 3685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const content::FileChooserParams& params) 3695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) OVERRIDE; 3705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual bool IsPopupOrPanel(const content::WebContents* source) 3715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const OVERRIDE; 3725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void MoveContents(content::WebContents* source, 3735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const gfx::Rect& pos) OVERRIDE; 3746e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) virtual void NavigationStateChanged( 3756e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) const content::WebContents* source, 3766e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) content::InvalidateTypes changed_flags) OVERRIDE; 3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void ToggleFullscreenModeForTab(content::WebContents* source, 3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool enter_fullscreen) OVERRIDE; 3795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual bool IsFullscreenForTabOrPending(const content::WebContents* source) 3805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const OVERRIDE; 3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void RequestMediaAccessPermission( 3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::WebContents* web_contents, 3832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const content::MediaStreamRequest& request, 3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const content::MediaResponseCallback& callback) OVERRIDE; 3851320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual bool CheckMediaAccessPermission( 3861320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci content::WebContents* web_contents, 3871320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci const GURL& security_origin, 3881320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci content::MediaStreamType type) OVERRIDE; 3895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual content::WebContents* OpenURLFromTab( 3905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::WebContents* source, 3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const content::OpenURLParams& params) OVERRIDE; 3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void AddNewContents(content::WebContents* source, 3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::WebContents* new_contents, 3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowOpenDisposition disposition, 3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const gfx::Rect& initial_pos, 3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool user_gesture, 3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool* was_blocked) OVERRIDE; 398f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual bool PreHandleKeyboardEvent( 399f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) content::WebContents* source, 400f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const content::NativeWebKeyboardEvent& event, 401f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) bool* is_keyboard_shortcut) OVERRIDE; 4025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void HandleKeyboardEvent(content::WebContents* source, 4035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const content::NativeWebKeyboardEvent& event) 4045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) OVERRIDE; 4052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void RequestToLockMouse(content::WebContents* web_contents, 4062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool user_gesture, 4072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool last_unlocked_by_target) OVERRIDE; 4085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual bool PreHandleGestureEvent(content::WebContents* source, 4095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const blink::WebGestureEvent& event) 4105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) OVERRIDE; 4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 412f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // content::WebContentsObserver implementation. 413010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) virtual void DidFirstVisuallyNonEmptyPaint() OVERRIDE; 414f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 41534680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles) // content::NotificationObserver implementation. 41634680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles) virtual void Observe(int type, 41734680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles) const content::NotificationSource& source, 41834680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles) const content::NotificationDetails& details) OVERRIDE; 4195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 420eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // web_modal::WebContentsModalDialogManagerDelegate implementation. 421eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch virtual void SetWebContentsBlocked(content::WebContents* web_contents, 422eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch bool blocked) OVERRIDE; 4235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual bool IsWebContentsVisible(content::WebContents* web_contents) 4245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) OVERRIDE; 425eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 426eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Saves the window geometry/position/screen bounds. 4272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void SaveWindowPosition(); 4285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 429eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Helper method to adjust the cached bounds so that we can make sure it can 430a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // be visible on the screen. See http://crbug.com/145752. 4315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void AdjustBoundsToBeVisibleOnScreen(const gfx::Rect& cached_bounds, 4325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const gfx::Rect& cached_screen_bounds, 4335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const gfx::Rect& current_screen_bounds, 4345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const gfx::Size& minimum_size, 4355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gfx::Rect* bounds) const; 436eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 437a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Loads the appropriate default or cached window bounds. Returns a new 438a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // CreateParams that should be used to create the window. 439a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) CreateParams LoadDefaults(CreateParams params) const; 4408bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 4415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Load the app's image, firing a load state change when loaded. 4425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void UpdateExtensionAppIcon(); 4435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 444f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Set the fullscreen state in the native app window. 4455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void SetNativeWindowFullscreen(); 4465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Returns true if there is any overlap between the window and the taskbar 4485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // (Windows only). 4495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool IntersectsWithTaskbar() const; 4505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Update the always-on-top bit in the native app window. 4525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void UpdateNativeAlwaysOnTop(); 453f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 45446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // Sends the onWindowShown event to the app if the window has been shown. Only 45546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // has an effect in tests. 45646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) void SendOnWindowShownIfShown(); 45746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 45890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // web_modal::WebContentsModalDialogManagerDelegate implementation. 4595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual web_modal::WebContentsModalDialogHost* GetWebContentsModalDialogHost() 4605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) OVERRIDE; 4615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Updates the badge to |image|. Called internally from the image loader 4635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // callback. 4645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void UpdateBadgeIcon(const gfx::Image& image); 465c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 4662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Callback from web_contents()->DownloadFavicon. 4672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void DidDownloadFavicon(int id, 46890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) int http_status_code, 4692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const GURL& image_url, 470d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) const std::vector<SkBitmap>& bitmaps, 471d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) const std::vector<gfx::Size>& original_bitmap_sizes); 4722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4731320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // IconImage::Observer implementation. 4741320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual void OnExtensionIconImageChanged(IconImage* image) OVERRIDE; 4755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // The browser context with which this window is associated. AppWindow does 4775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // not own this object. 4785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) content::BrowserContext* browser_context_; 479a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 48090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const std::string extension_id_; 4815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Identifier that is used when saving and restoring geometry for this 4835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // window. 4845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string window_key_; 4855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const SessionID session_id_; 4872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) WindowType window_type_; 48834680572440d7894ef8dafce81d8039ed80726a2Torne (Richard Coles) content::NotificationRegistrar registrar_; 4895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Icon shown in the task bar. 4915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Image app_icon_; 4925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Icon URL to be used for setting the app icon. If not empty, app_icon_ will 4942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // be fetched and set using this URL. 4952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GURL app_icon_url_; 4962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 497a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // An object to load the app's icon as an extension resource. 4981320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci scoped_ptr<IconImage> app_icon_image_; 499a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 5005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Badge for icon shown in the task bar. 5015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gfx::Image badge_icon_; 5025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 5035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // URL to be used for setting the badge on the app icon. 5045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) GURL badge_icon_url_; 5055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 5065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // An object to load the badge as an extension resource. 5071320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci scoped_ptr<IconImage> badge_icon_image_; 5085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 5091320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci scoped_ptr<NativeAppWindow> native_app_window_; 5105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) scoped_ptr<AppWindowContents> app_window_contents_; 5111320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci scoped_ptr<AppDelegate> app_delegate_; 5121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci scoped_ptr<AppWebContentsHelper> helper_; 5135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 514116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Manages popup windows (bubbles, tab-modals) visible overlapping the 515116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // app window. 516116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch scoped_ptr<web_modal::PopupManager> popup_manager_; 517116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 5185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::WeakPtrFactory<AppWindow> image_loader_ptr_factory_; 5195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 520f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Bit field of FullscreenType. 521f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) int fullscreen_types_; 522c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 523f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Show has been called, so the window should be shown once the first visually 524f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // non-empty paint occurs. 525f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) bool show_on_first_paint_; 526f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 527f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // The first visually non-empty paint has completed. 528f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) bool first_paint_complete_; 529f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 53046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // Whether the window has been shown or not. 53146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) bool has_been_shown_; 53246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 53346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // Whether events can be sent to the window. 53446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) bool can_send_events_; 53546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 536cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Whether the window is hidden or not. Hidden in this context means actively 537cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // by the chrome.app.window API, not in an operating system context. For 538cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // example windows which are minimized are not hidden, and windows which are 539cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // part of a hidden app on OS X are not hidden. Windows which were created 540cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // with the |hidden| flag set to true, or which have been programmatically 541cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // hidden, are considered hidden. 542cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) bool is_hidden_; 543cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 544f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Whether the delayed Show() call was for an active or inactive window. 545f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) ShowType delayed_show_type_; 546f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 547f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Cache the desired value of the always-on-top property. When windows enter 5485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // fullscreen or overlap the Windows taskbar, this property will be 5495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // automatically and silently switched off for security reasons. It is 5505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // reinstated when the window exits fullscreen and moves away from the 5515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // taskbar. 552f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) bool cached_always_on_top_; 553f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 5546e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // Whether |alpha_enabled| was set in the CreateParams. 5556e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) bool requested_alpha_enabled_; 556116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 5575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(AppWindow); 5585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 5595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5601320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci} // namespace extensions 561eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 5621320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#endif // EXTENSIONS_BROWSER_APP_WINDOW_APP_WINDOW_H_ 563