| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef APPS_APP_WINDOW_H_ | 5 #ifndef EXTENSIONS_BROWSER_APP_WINDOW_APP_WINDOW_H_ |
| 6 #define APPS_APP_WINDOW_H_ | 6 #define EXTENSIONS_BROWSER_APP_WINDOW_APP_WINDOW_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "components/sessions/session_id.h" | 13 #include "components/sessions/session_id.h" |
| 14 #include "components/web_modal/popup_manager.h" | 14 #include "components/web_modal/popup_manager.h" |
| 15 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" | 15 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" |
| 16 #include "content/public/browser/notification_observer.h" | 16 #include "content/public/browser/notification_observer.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 namespace base { | 28 namespace base { |
| 29 class DictionaryValue; | 29 class DictionaryValue; |
| 30 } | 30 } |
| 31 | 31 |
| 32 namespace content { | 32 namespace content { |
| 33 class BrowserContext; | 33 class BrowserContext; |
| 34 class WebContents; | 34 class WebContents; |
| 35 } | 35 } |
| 36 | 36 |
| 37 namespace ui { |
| 38 class BaseWindow; |
| 39 } |
| 40 |
| 37 namespace extensions { | 41 namespace extensions { |
| 42 |
| 38 class AppDelegate; | 43 class AppDelegate; |
| 39 class AppWebContentsHelper; | 44 class AppWebContentsHelper; |
| 40 class Extension; | 45 class Extension; |
| 41 class NativeAppWindow; | 46 class NativeAppWindow; |
| 42 class PlatformAppBrowserTest; | 47 class PlatformAppBrowserTest; |
| 43 class WindowController; | 48 class WindowController; |
| 44 | 49 |
| 45 struct DraggableRegion; | 50 struct DraggableRegion; |
| 46 } | |
| 47 | |
| 48 namespace ui { | |
| 49 class BaseWindow; | |
| 50 } | |
| 51 | |
| 52 namespace apps { | |
| 53 | 51 |
| 54 // Manages the web contents for app windows. The implementation for this | 52 // Manages the web contents for app windows. The implementation for this |
| 55 // class should create and maintain the WebContents for the window, and handle | 53 // class should create and maintain the WebContents for the window, and handle |
| 56 // any message passing between the web contents and the extension system or | 54 // any message passing between the web contents and the extension system or |
| 57 // native window. | 55 // native window. |
| 58 class AppWindowContents { | 56 class AppWindowContents { |
| 59 public: | 57 public: |
| 60 AppWindowContents() {} | 58 AppWindowContents() {} |
| 61 virtual ~AppWindowContents() {} | 59 virtual ~AppWindowContents() {} |
| 62 | 60 |
| 63 // Called to initialize the WebContents, before the app window is created. | 61 // Called to initialize the WebContents, before the app window is created. |
| 64 virtual void Initialize(content::BrowserContext* context, | 62 virtual void Initialize(content::BrowserContext* context, |
| 65 const GURL& url) = 0; | 63 const GURL& url) = 0; |
| 66 | 64 |
| 67 // Called to load the contents, after the app window is created. | 65 // Called to load the contents, after the app window is created. |
| 68 virtual void LoadContents(int32 creator_process_id) = 0; | 66 virtual void LoadContents(int32 creator_process_id) = 0; |
| 69 | 67 |
| 70 // Called when the native window changes. | 68 // Called when the native window changes. |
| 71 virtual void NativeWindowChanged( | 69 virtual void NativeWindowChanged(NativeAppWindow* native_app_window) = 0; |
| 72 extensions::NativeAppWindow* native_app_window) = 0; | |
| 73 | 70 |
| 74 // Called when the native window closes. | 71 // Called when the native window closes. |
| 75 virtual void NativeWindowClosed() = 0; | 72 virtual void NativeWindowClosed() = 0; |
| 76 | 73 |
| 77 // Called in tests when the window is shown | 74 // Called in tests when the window is shown |
| 78 virtual void DispatchWindowShownForTests() const = 0; | 75 virtual void DispatchWindowShownForTests() const = 0; |
| 79 | 76 |
| 80 virtual content::WebContents* GetWebContents() const = 0; | 77 virtual content::WebContents* GetWebContents() const = 0; |
| 81 | 78 |
| 82 private: | 79 private: |
| 83 DISALLOW_COPY_AND_ASSIGN(AppWindowContents); | 80 DISALLOW_COPY_AND_ASSIGN(AppWindowContents); |
| 84 }; | 81 }; |
| 85 | 82 |
| 86 // AppWindow is the type of window used by platform apps. App windows | 83 // AppWindow is the type of window used by platform apps. App windows |
| 87 // have a WebContents but none of the chrome of normal browser windows. | 84 // have a WebContents but none of the chrome of normal browser windows. |
| 88 class AppWindow : public content::NotificationObserver, | 85 class AppWindow : public content::NotificationObserver, |
| 89 public content::WebContentsDelegate, | 86 public content::WebContentsDelegate, |
| 90 public content::WebContentsObserver, | 87 public content::WebContentsObserver, |
| 91 public web_modal::WebContentsModalDialogManagerDelegate, | 88 public web_modal::WebContentsModalDialogManagerDelegate, |
| 92 public extensions::IconImage::Observer { | 89 public IconImage::Observer { |
| 93 public: | 90 public: |
| 94 enum WindowType { | 91 enum WindowType { |
| 95 WINDOW_TYPE_DEFAULT = 1 << 0, // Default app window. | 92 WINDOW_TYPE_DEFAULT = 1 << 0, // Default app window. |
| 96 WINDOW_TYPE_PANEL = 1 << 1, // OS controlled panel window (Ash only). | 93 WINDOW_TYPE_PANEL = 1 << 1, // OS controlled panel window (Ash only). |
| 97 WINDOW_TYPE_V1_PANEL = 1 << 2, // For apps v1 support in Ash; deprecate | 94 WINDOW_TYPE_V1_PANEL = 1 << 2, // For apps v1 support in Ash; deprecate |
| 98 // with v1 apps. | 95 // with v1 apps. |
| 99 }; | 96 }; |
| 100 | 97 |
| 101 enum Frame { | 98 enum Frame { |
| 102 FRAME_CHROME, // Chrome-style window frame. | 99 FRAME_CHROME, // Chrome-style window frame. |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 // constraints. | 189 // constraints. |
| 193 gfx::Size GetContentMinimumSize(const gfx::Insets& frame_insets) const; | 190 gfx::Size GetContentMinimumSize(const gfx::Insets& frame_insets) const; |
| 194 gfx::Size GetContentMaximumSize(const gfx::Insets& frame_insets) const; | 191 gfx::Size GetContentMaximumSize(const gfx::Insets& frame_insets) const; |
| 195 gfx::Size GetWindowMinimumSize(const gfx::Insets& frame_insets) const; | 192 gfx::Size GetWindowMinimumSize(const gfx::Insets& frame_insets) const; |
| 196 gfx::Size GetWindowMaximumSize(const gfx::Insets& frame_insets) const; | 193 gfx::Size GetWindowMaximumSize(const gfx::Insets& frame_insets) const; |
| 197 }; | 194 }; |
| 198 | 195 |
| 199 // Convert draggable regions in raw format to SkRegion format. Caller is | 196 // Convert draggable regions in raw format to SkRegion format. Caller is |
| 200 // responsible for deleting the returned SkRegion instance. | 197 // responsible for deleting the returned SkRegion instance. |
| 201 static SkRegion* RawDraggableRegionsToSkRegion( | 198 static SkRegion* RawDraggableRegionsToSkRegion( |
| 202 const std::vector<extensions::DraggableRegion>& regions); | 199 const std::vector<DraggableRegion>& regions); |
| 203 | 200 |
| 204 // The constructor and Init methods are public for constructing a AppWindow | 201 // The constructor and Init methods are public for constructing a AppWindow |
| 205 // with a non-standard render interface (e.g. v1 apps using Ash Panels). | 202 // with a non-standard render interface (e.g. v1 apps using Ash Panels). |
| 206 // Normally AppWindow::Create should be used. | 203 // Normally AppWindow::Create should be used. |
| 207 // Takes ownership of |app_delegate| and |delegate|. | 204 // Takes ownership of |app_delegate| and |delegate|. |
| 208 AppWindow(content::BrowserContext* context, | 205 AppWindow(content::BrowserContext* context, |
| 209 extensions::AppDelegate* app_delegate, | 206 AppDelegate* app_delegate, |
| 210 const extensions::Extension* extension); | 207 const Extension* extension); |
| 211 | 208 |
| 212 // Initializes the render interface, web contents, and native window. | 209 // Initializes the render interface, web contents, and native window. |
| 213 // |app_window_contents| will become owned by AppWindow. | 210 // |app_window_contents| will become owned by AppWindow. |
| 214 void Init(const GURL& url, | 211 void Init(const GURL& url, |
| 215 AppWindowContents* app_window_contents, | 212 AppWindowContents* app_window_contents, |
| 216 const CreateParams& params); | 213 const CreateParams& params); |
| 217 | 214 |
| 218 const std::string& window_key() const { return window_key_; } | 215 const std::string& window_key() const { return window_key_; } |
| 219 const SessionID& session_id() const { return session_id_; } | 216 const SessionID& session_id() const { return session_id_; } |
| 220 const std::string& extension_id() const { return extension_id_; } | 217 const std::string& extension_id() const { return extension_id_; } |
| 221 content::WebContents* web_contents() const; | 218 content::WebContents* web_contents() const; |
| 222 WindowType window_type() const { return window_type_; } | 219 WindowType window_type() const { return window_type_; } |
| 223 bool window_type_is_panel() const { | 220 bool window_type_is_panel() const { |
| 224 return (window_type_ == WINDOW_TYPE_PANEL || | 221 return (window_type_ == WINDOW_TYPE_PANEL || |
| 225 window_type_ == WINDOW_TYPE_V1_PANEL); | 222 window_type_ == WINDOW_TYPE_V1_PANEL); |
| 226 } | 223 } |
| 227 content::BrowserContext* browser_context() const { return browser_context_; } | 224 content::BrowserContext* browser_context() const { return browser_context_; } |
| 228 const gfx::Image& app_icon() const { return app_icon_; } | 225 const gfx::Image& app_icon() const { return app_icon_; } |
| 229 const GURL& app_icon_url() const { return app_icon_url_; } | 226 const GURL& app_icon_url() const { return app_icon_url_; } |
| 230 const gfx::Image& badge_icon() const { return badge_icon_; } | 227 const gfx::Image& badge_icon() const { return badge_icon_; } |
| 231 const GURL& badge_icon_url() const { return badge_icon_url_; } | 228 const GURL& badge_icon_url() const { return badge_icon_url_; } |
| 232 bool is_hidden() const { return is_hidden_; } | 229 bool is_hidden() const { return is_hidden_; } |
| 233 | 230 |
| 234 const extensions::Extension* GetExtension() const; | 231 const Extension* GetExtension() const; |
| 235 extensions::NativeAppWindow* GetBaseWindow(); | 232 NativeAppWindow* GetBaseWindow(); |
| 236 gfx::NativeWindow GetNativeWindow(); | 233 gfx::NativeWindow GetNativeWindow(); |
| 237 | 234 |
| 238 // Returns the bounds that should be reported to the renderer. | 235 // Returns the bounds that should be reported to the renderer. |
| 239 gfx::Rect GetClientBounds() const; | 236 gfx::Rect GetClientBounds() const; |
| 240 | 237 |
| 241 // NativeAppWindows should call this to determine what the window's title | 238 // NativeAppWindows should call this to determine what the window's title |
| 242 // is on startup and from within UpdateWindowTitle(). | 239 // is on startup and from within UpdateWindowTitle(). |
| 243 base::string16 GetTitle() const; | 240 base::string16 GetTitle() const; |
| 244 | 241 |
| 245 // Call to notify ShellRegistry and delete the window. Subclasses should | 242 // Call to notify ShellRegistry and delete the window. Subclasses should |
| (...skipping 13 matching lines...) Expand all Loading... |
| 259 // Specifies a url for the window badge. | 256 // Specifies a url for the window badge. |
| 260 void SetBadgeIconUrl(const GURL& icon_url); | 257 void SetBadgeIconUrl(const GURL& icon_url); |
| 261 | 258 |
| 262 // Clear the current badge. | 259 // Clear the current badge. |
| 263 void ClearBadge(); | 260 void ClearBadge(); |
| 264 | 261 |
| 265 // Set the window shape. Passing a NULL |region| sets the default shape. | 262 // Set the window shape. Passing a NULL |region| sets the default shape. |
| 266 void UpdateShape(scoped_ptr<SkRegion> region); | 263 void UpdateShape(scoped_ptr<SkRegion> region); |
| 267 | 264 |
| 268 // Called from the render interface to modify the draggable regions. | 265 // Called from the render interface to modify the draggable regions. |
| 269 void UpdateDraggableRegions( | 266 void UpdateDraggableRegions(const std::vector<DraggableRegion>& regions); |
| 270 const std::vector<extensions::DraggableRegion>& regions); | |
| 271 | 267 |
| 272 // Updates the app image to |image|. Called internally from the image loader | 268 // Updates the app image to |image|. Called internally from the image loader |
| 273 // callback. Also called externally for v1 apps using Ash Panels. | 269 // callback. Also called externally for v1 apps using Ash Panels. |
| 274 void UpdateAppIcon(const gfx::Image& image); | 270 void UpdateAppIcon(const gfx::Image& image); |
| 275 | 271 |
| 276 // Enable or disable fullscreen mode. |type| specifies which type of | 272 // Enable or disable fullscreen mode. |type| specifies which type of |
| 277 // fullscreen mode to change (note that disabling one type of fullscreen may | 273 // fullscreen mode to change (note that disabling one type of fullscreen may |
| 278 // not exit fullscreen mode because a window may have a different type of | 274 // not exit fullscreen mode because a window may have a different type of |
| 279 // fullscreen enabled). If |type| is not FORCED, checks that the extension has | 275 // fullscreen enabled). If |type| is not FORCED, checks that the extension has |
| 280 // the required permission. | 276 // the required permission. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 | 345 |
| 350 void SetAppWindowContentsForTesting(scoped_ptr<AppWindowContents> contents) { | 346 void SetAppWindowContentsForTesting(scoped_ptr<AppWindowContents> contents) { |
| 351 app_window_contents_ = contents.Pass(); | 347 app_window_contents_ = contents.Pass(); |
| 352 } | 348 } |
| 353 | 349 |
| 354 protected: | 350 protected: |
| 355 virtual ~AppWindow(); | 351 virtual ~AppWindow(); |
| 356 | 352 |
| 357 private: | 353 private: |
| 358 // PlatformAppBrowserTest needs access to web_contents() | 354 // PlatformAppBrowserTest needs access to web_contents() |
| 359 friend class extensions::PlatformAppBrowserTest; | 355 friend class PlatformAppBrowserTest; |
| 360 | 356 |
| 361 // content::WebContentsDelegate implementation. | 357 // content::WebContentsDelegate implementation. |
| 362 virtual void CloseContents(content::WebContents* contents) OVERRIDE; | 358 virtual void CloseContents(content::WebContents* contents) OVERRIDE; |
| 363 virtual bool ShouldSuppressDialogs() OVERRIDE; | 359 virtual bool ShouldSuppressDialogs() OVERRIDE; |
| 364 virtual content::ColorChooser* OpenColorChooser( | 360 virtual content::ColorChooser* OpenColorChooser( |
| 365 content::WebContents* web_contents, | 361 content::WebContents* web_contents, |
| 366 SkColor color, | 362 SkColor color, |
| 367 const std::vector<content::ColorSuggestion>& suggestions) OVERRIDE; | 363 const std::vector<content::ColorSuggestion>& suggestions) OVERRIDE; |
| 368 virtual void RunFileChooser(content::WebContents* tab, | 364 virtual void RunFileChooser(content::WebContents* tab, |
| 369 const content::FileChooserParams& params) | 365 const content::FileChooserParams& params) |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 // callback. | 456 // callback. |
| 461 void UpdateBadgeIcon(const gfx::Image& image); | 457 void UpdateBadgeIcon(const gfx::Image& image); |
| 462 | 458 |
| 463 // Callback from web_contents()->DownloadFavicon. | 459 // Callback from web_contents()->DownloadFavicon. |
| 464 void DidDownloadFavicon(int id, | 460 void DidDownloadFavicon(int id, |
| 465 int http_status_code, | 461 int http_status_code, |
| 466 const GURL& image_url, | 462 const GURL& image_url, |
| 467 const std::vector<SkBitmap>& bitmaps, | 463 const std::vector<SkBitmap>& bitmaps, |
| 468 const std::vector<gfx::Size>& original_bitmap_sizes); | 464 const std::vector<gfx::Size>& original_bitmap_sizes); |
| 469 | 465 |
| 470 // extensions::IconImage::Observer implementation. | 466 // IconImage::Observer implementation. |
| 471 virtual void OnExtensionIconImageChanged(extensions::IconImage* image) | 467 virtual void OnExtensionIconImageChanged(IconImage* image) OVERRIDE; |
| 472 OVERRIDE; | |
| 473 | 468 |
| 474 // The browser context with which this window is associated. AppWindow does | 469 // The browser context with which this window is associated. AppWindow does |
| 475 // not own this object. | 470 // not own this object. |
| 476 content::BrowserContext* browser_context_; | 471 content::BrowserContext* browser_context_; |
| 477 | 472 |
| 478 const std::string extension_id_; | 473 const std::string extension_id_; |
| 479 | 474 |
| 480 // Identifier that is used when saving and restoring geometry for this | 475 // Identifier that is used when saving and restoring geometry for this |
| 481 // window. | 476 // window. |
| 482 std::string window_key_; | 477 std::string window_key_; |
| 483 | 478 |
| 484 const SessionID session_id_; | 479 const SessionID session_id_; |
| 485 WindowType window_type_; | 480 WindowType window_type_; |
| 486 content::NotificationRegistrar registrar_; | 481 content::NotificationRegistrar registrar_; |
| 487 | 482 |
| 488 // Icon shown in the task bar. | 483 // Icon shown in the task bar. |
| 489 gfx::Image app_icon_; | 484 gfx::Image app_icon_; |
| 490 | 485 |
| 491 // Icon URL to be used for setting the app icon. If not empty, app_icon_ will | 486 // Icon URL to be used for setting the app icon. If not empty, app_icon_ will |
| 492 // be fetched and set using this URL. | 487 // be fetched and set using this URL. |
| 493 GURL app_icon_url_; | 488 GURL app_icon_url_; |
| 494 | 489 |
| 495 // An object to load the app's icon as an extension resource. | 490 // An object to load the app's icon as an extension resource. |
| 496 scoped_ptr<extensions::IconImage> app_icon_image_; | 491 scoped_ptr<IconImage> app_icon_image_; |
| 497 | 492 |
| 498 // Badge for icon shown in the task bar. | 493 // Badge for icon shown in the task bar. |
| 499 gfx::Image badge_icon_; | 494 gfx::Image badge_icon_; |
| 500 | 495 |
| 501 // URL to be used for setting the badge on the app icon. | 496 // URL to be used for setting the badge on the app icon. |
| 502 GURL badge_icon_url_; | 497 GURL badge_icon_url_; |
| 503 | 498 |
| 504 // An object to load the badge as an extension resource. | 499 // An object to load the badge as an extension resource. |
| 505 scoped_ptr<extensions::IconImage> badge_icon_image_; | 500 scoped_ptr<IconImage> badge_icon_image_; |
| 506 | 501 |
| 507 scoped_ptr<extensions::NativeAppWindow> native_app_window_; | 502 scoped_ptr<NativeAppWindow> native_app_window_; |
| 508 scoped_ptr<AppWindowContents> app_window_contents_; | 503 scoped_ptr<AppWindowContents> app_window_contents_; |
| 509 scoped_ptr<extensions::AppDelegate> app_delegate_; | 504 scoped_ptr<AppDelegate> app_delegate_; |
| 510 scoped_ptr<extensions::AppWebContentsHelper> helper_; | 505 scoped_ptr<AppWebContentsHelper> helper_; |
| 511 | 506 |
| 512 // Manages popup windows (bubbles, tab-modals) visible overlapping the | 507 // Manages popup windows (bubbles, tab-modals) visible overlapping the |
| 513 // app window. | 508 // app window. |
| 514 scoped_ptr<web_modal::PopupManager> popup_manager_; | 509 scoped_ptr<web_modal::PopupManager> popup_manager_; |
| 515 | 510 |
| 516 base::WeakPtrFactory<AppWindow> image_loader_ptr_factory_; | 511 base::WeakPtrFactory<AppWindow> image_loader_ptr_factory_; |
| 517 | 512 |
| 518 // Bit field of FullscreenType. | 513 // Bit field of FullscreenType. |
| 519 int fullscreen_types_; | 514 int fullscreen_types_; |
| 520 | 515 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 548 // reinstated when the window exits fullscreen and moves away from the | 543 // reinstated when the window exits fullscreen and moves away from the |
| 549 // taskbar. | 544 // taskbar. |
| 550 bool cached_always_on_top_; | 545 bool cached_always_on_top_; |
| 551 | 546 |
| 552 // Whether |alpha_enabled| was set in the CreateParams. | 547 // Whether |alpha_enabled| was set in the CreateParams. |
| 553 bool requested_alpha_enabled_; | 548 bool requested_alpha_enabled_; |
| 554 | 549 |
| 555 DISALLOW_COPY_AND_ASSIGN(AppWindow); | 550 DISALLOW_COPY_AND_ASSIGN(AppWindow); |
| 556 }; | 551 }; |
| 557 | 552 |
| 558 } // namespace apps | 553 } // namespace extensions |
| 559 | 554 |
| 560 #endif // APPS_APP_WINDOW_H_ | 555 #endif // EXTENSIONS_BROWSER_APP_WINDOW_APP_WINDOW_H_ |
| OLD | NEW |