Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: extensions/browser/app_window/app_window.h

Issue 2900783003: Handle app custom icon via aura::Window property. (Closed)
Patch Set: fix mac compile Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 EXTENSIONS_BROWSER_APP_WINDOW_APP_WINDOW_H_ 5 #ifndef EXTENSIONS_BROWSER_APP_WINDOW_APP_WINDOW_H_
6 #define EXTENSIONS_BROWSER_APP_WINDOW_APP_WINDOW_H_ 6 #define EXTENSIONS_BROWSER_APP_WINDOW_APP_WINDOW_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <string> 11 #include <string>
12 #include <utility> 12 #include <utility>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "components/sessions/core/session_id.h" 17 #include "components/sessions/core/session_id.h"
18 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" 18 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h"
19 #include "content/public/browser/web_contents_delegate.h" 19 #include "content/public/browser/web_contents_delegate.h"
20 #include "content/public/browser/web_contents_observer.h" 20 #include "content/public/browser/web_contents_observer.h"
21 #include "extensions/browser/extension_function_dispatcher.h" 21 #include "extensions/browser/extension_function_dispatcher.h"
22 #include "extensions/browser/extension_icon_image.h"
23 #include "extensions/browser/extension_registry_observer.h" 22 #include "extensions/browser/extension_registry_observer.h"
24 #include "ui/base/ui_base_types.h" // WindowShowState 23 #include "ui/base/ui_base_types.h" // WindowShowState
25 #include "ui/gfx/geometry/rect.h" 24 #include "ui/gfx/geometry/rect.h"
26 #include "ui/gfx/image/image.h" 25 #include "ui/gfx/image/image.h"
27 26
28 class GURL; 27 class GURL;
29 class SkRegion; 28 class SkRegion;
30 29
31 namespace base { 30 namespace base {
32 class DictionaryValue; 31 class DictionaryValue;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 79
81 private: 80 private:
82 DISALLOW_COPY_AND_ASSIGN(AppWindowContents); 81 DISALLOW_COPY_AND_ASSIGN(AppWindowContents);
83 }; 82 };
84 83
85 // AppWindow is the type of window used by platform apps. App windows 84 // AppWindow is the type of window used by platform apps. App windows
86 // have a WebContents but none of the chrome of normal browser windows. 85 // have a WebContents but none of the chrome of normal browser windows.
87 class AppWindow : public content::WebContentsDelegate, 86 class AppWindow : public content::WebContentsDelegate,
88 public content::WebContentsObserver, 87 public content::WebContentsObserver,
89 public web_modal::WebContentsModalDialogManagerDelegate, 88 public web_modal::WebContentsModalDialogManagerDelegate,
90 public IconImage::Observer,
91 public ExtensionFunctionDispatcher::Delegate, 89 public ExtensionFunctionDispatcher::Delegate,
92 public ExtensionRegistryObserver { 90 public ExtensionRegistryObserver {
93 public: 91 public:
94 enum WindowType { 92 enum WindowType {
95 WINDOW_TYPE_DEFAULT = 1 << 0, // Default app window. 93 WINDOW_TYPE_DEFAULT = 1 << 0, // Default app window.
96 WINDOW_TYPE_PANEL = 1 << 1, // OS controlled panel window (Ash only). 94 WINDOW_TYPE_PANEL = 1 << 1, // OS controlled panel window (Ash only).
97 }; 95 };
98 96
99 enum Frame { 97 enum Frame {
100 FRAME_CHROME, // Chrome-style window frame. 98 FRAME_CHROME, // Chrome-style window frame.
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 227
230 const std::string& window_key() const { return window_key_; } 228 const std::string& window_key() const { return window_key_; }
231 const SessionID& session_id() const { return session_id_; } 229 const SessionID& session_id() const { return session_id_; }
232 const std::string& extension_id() const { return extension_id_; } 230 const std::string& extension_id() const { return extension_id_; }
233 content::WebContents* web_contents() const; 231 content::WebContents* web_contents() const;
234 WindowType window_type() const { return window_type_; } 232 WindowType window_type() const { return window_type_; }
235 bool window_type_is_panel() const { 233 bool window_type_is_panel() const {
236 return window_type_ == WINDOW_TYPE_PANEL; 234 return window_type_ == WINDOW_TYPE_PANEL;
237 } 235 }
238 content::BrowserContext* browser_context() const { return browser_context_; } 236 content::BrowserContext* browser_context() const { return browser_context_; }
239 const gfx::Image& app_icon() const { return app_icon_; } 237 const gfx::Image& custom_app_icon() const { return custom_app_icon_; }
240 const GURL& app_icon_url() const { return app_icon_url_; } 238 const GURL& app_icon_url() const { return app_icon_url_; }
241 const GURL& initial_url() const { return initial_url_; } 239 const GURL& initial_url() const { return initial_url_; }
242 bool is_hidden() const { return is_hidden_; } 240 bool is_hidden() const { return is_hidden_; }
243 241
244 const Extension* GetExtension() const; 242 const Extension* GetExtension() const;
245 NativeAppWindow* GetBaseWindow(); 243 NativeAppWindow* GetBaseWindow();
246 gfx::NativeWindow GetNativeWindow(); 244 gfx::NativeWindow GetNativeWindow();
247 245
248 // Returns the bounds that should be reported to the renderer. 246 // Returns the bounds that should be reported to the renderer.
249 gfx::Rect GetClientBounds() const; 247 gfx::Rect GetClientBounds() const;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 void RestoreAlwaysOnTop(); 348 void RestoreAlwaysOnTop();
351 349
352 // Retrieve the current state of the app window as a dictionary, to pass to 350 // Retrieve the current state of the app window as a dictionary, to pass to
353 // the renderer. 351 // the renderer.
354 void GetSerializedState(base::DictionaryValue* properties) const; 352 void GetSerializedState(base::DictionaryValue* properties) const;
355 353
356 // Notifies the window's contents that the render view is ready and it can 354 // Notifies the window's contents that the render view is ready and it can
357 // unblock resource requests. 355 // unblock resource requests.
358 void NotifyRenderViewReady(); 356 void NotifyRenderViewReady();
359 357
360 // Returns true if window has custom icon in case either |window_icon_url_| or
361 // |app_icon_url_| is set. Custom icon may be not loaded yet.
362 bool HasCustomIcon() const;
363
364 // Whether the app window wants to be alpha enabled. 358 // Whether the app window wants to be alpha enabled.
365 bool requested_alpha_enabled() const { return requested_alpha_enabled_; } 359 bool requested_alpha_enabled() const { return requested_alpha_enabled_; }
366 360
367 // Whether the app window is created by IME extensions. 361 // Whether the app window is created by IME extensions.
368 // TODO(bshe): rename to hide_app_window_in_launcher if it is not used 362 // TODO(bshe): rename to hide_app_window_in_launcher if it is not used
369 // anywhere other than app_window_launcher_controller after M45. Otherwise, 363 // anywhere other than app_window_launcher_controller after M45. Otherwise,
370 // remove this TODO. 364 // remove this TODO.
371 bool is_ime_window() const { return is_ime_window_; } 365 bool is_ime_window() const { return is_ime_window_; }
372 366
373 bool show_in_shelf() const { return show_in_shelf_; } 367 bool show_in_shelf() const { return show_in_shelf_; }
374 368
375 const GURL& window_icon_url() const { return window_icon_url_; } 369 AppDelegate* app_delegate() { return app_delegate_.get(); }
376 370
377 void SetAppWindowContentsForTesting( 371 void SetAppWindowContentsForTesting(
378 std::unique_ptr<AppWindowContents> contents) { 372 std::unique_ptr<AppWindowContents> contents) {
379 app_window_contents_ = std::move(contents); 373 app_window_contents_ = std::move(contents);
380 } 374 }
381 375
382 protected: 376 protected:
383 ~AppWindow() override; 377 ~AppWindow() override;
384 378
385 private: 379 private:
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 void AdjustBoundsToBeVisibleOnScreen(const gfx::Rect& cached_bounds, 460 void AdjustBoundsToBeVisibleOnScreen(const gfx::Rect& cached_bounds,
467 const gfx::Rect& cached_screen_bounds, 461 const gfx::Rect& cached_screen_bounds,
468 const gfx::Rect& current_screen_bounds, 462 const gfx::Rect& current_screen_bounds,
469 const gfx::Size& minimum_size, 463 const gfx::Size& minimum_size,
470 gfx::Rect* bounds) const; 464 gfx::Rect* bounds) const;
471 465
472 // Loads the appropriate default or cached window bounds. Returns a new 466 // Loads the appropriate default or cached window bounds. Returns a new
473 // CreateParams that should be used to create the window. 467 // CreateParams that should be used to create the window.
474 CreateParams LoadDefaults(CreateParams params) const; 468 CreateParams LoadDefaults(CreateParams params) const;
475 469
476 // Load the app's image, firing a load state change when loaded.
477 void UpdateExtensionAppIcon();
478
479 // Set the fullscreen state in the native app window. 470 // Set the fullscreen state in the native app window.
480 void SetNativeWindowFullscreen(); 471 void SetNativeWindowFullscreen();
481 472
482 // Returns true if there is any overlap between the window and the taskbar 473 // Returns true if there is any overlap between the window and the taskbar
483 // (Windows only). 474 // (Windows only).
484 bool IntersectsWithTaskbar() const; 475 bool IntersectsWithTaskbar() const;
485 476
486 // Update the always-on-top bit in the native app window. 477 // Update the always-on-top bit in the native app window.
487 void UpdateNativeAlwaysOnTop(); 478 void UpdateNativeAlwaysOnTop();
488 479
489 // Sends the onWindowShown event to the app if the window has been shown. Only 480 // Sends the onWindowShown event to the app if the window has been shown. Only
490 // has an effect in tests. 481 // has an effect in tests.
491 void SendOnWindowShownIfShown(); 482 void SendOnWindowShownIfShown();
492 483
493 // web_modal::WebContentsModalDialogManagerDelegate implementation. 484 // web_modal::WebContentsModalDialogManagerDelegate implementation.
494 web_modal::WebContentsModalDialogHost* GetWebContentsModalDialogHost() 485 web_modal::WebContentsModalDialogHost* GetWebContentsModalDialogHost()
495 override; 486 override;
496 487
497 // Callback from web_contents()->DownloadFavicon. 488 // Callback from web_contents()->DownloadFavicon.
498 void DidDownloadFavicon(int id, 489 void DidDownloadFavicon(int id,
499 int http_status_code, 490 int http_status_code,
500 const GURL& image_url, 491 const GURL& image_url,
501 const std::vector<SkBitmap>& bitmaps, 492 const std::vector<SkBitmap>& bitmaps,
502 const std::vector<gfx::Size>& original_bitmap_sizes); 493 const std::vector<gfx::Size>& original_bitmap_sizes);
503 494
504 // IconImage::Observer implementation.
505 void OnExtensionIconImageChanged(IconImage* image) override;
506
507 // The browser context with which this window is associated. AppWindow does 495 // The browser context with which this window is associated. AppWindow does
508 // not own this object. 496 // not own this object.
509 content::BrowserContext* browser_context_; 497 content::BrowserContext* browser_context_;
510 498
511 const std::string extension_id_; 499 const std::string extension_id_;
512 500
513 // Identifier that is used when saving and restoring geometry for this 501 // Identifier that is used when saving and restoring geometry for this
514 // window. 502 // window.
515 std::string window_key_; 503 std::string window_key_;
516 504
517 const SessionID session_id_; 505 const SessionID session_id_;
518 WindowType window_type_; 506 WindowType window_type_;
519 507
520 // Icon shown in the task bar. 508 // Custom icon shown in the task bar or in Chrome OS shelf.
521 gfx::Image app_icon_; 509 gfx::Image custom_app_icon_;
522 510
523 // Icon URL to be used for setting the app icon. If not empty, app_icon_ will 511 // Icon URL to be used for setting the app icon. If not empty, app_icon_ will
524 // be fetched and set using this URL. 512 // be fetched and set using this URL.
525 GURL app_icon_url_; 513 GURL app_icon_url_;
526 514
527 // An object to load the app's icon as an extension resource.
528 std::unique_ptr<IconImage> app_icon_image_;
529
530 std::unique_ptr<NativeAppWindow> native_app_window_; 515 std::unique_ptr<NativeAppWindow> native_app_window_;
531 std::unique_ptr<AppWindowContents> app_window_contents_; 516 std::unique_ptr<AppWindowContents> app_window_contents_;
532 std::unique_ptr<AppDelegate> app_delegate_; 517 std::unique_ptr<AppDelegate> app_delegate_;
533 std::unique_ptr<AppWebContentsHelper> helper_; 518 std::unique_ptr<AppWebContentsHelper> helper_;
534 519
535 // The initial url this AppWindow was navigated to. 520 // The initial url this AppWindow was navigated to.
536 GURL initial_url_; 521 GURL initial_url_;
537 522
538 // Bit field of FullscreenType. 523 // Bit field of FullscreenType.
539 int fullscreen_types_; 524 int fullscreen_types_;
(...skipping 18 matching lines...) Expand all
558 543
559 // Whether |alpha_enabled| was set in the CreateParams. 544 // Whether |alpha_enabled| was set in the CreateParams.
560 bool requested_alpha_enabled_; 545 bool requested_alpha_enabled_;
561 546
562 // Whether |is_ime_window| was set in the CreateParams. 547 // Whether |is_ime_window| was set in the CreateParams.
563 bool is_ime_window_; 548 bool is_ime_window_;
564 549
565 // Whether |show_in_shelf| was set in the CreateParams. 550 // Whether |show_in_shelf| was set in the CreateParams.
566 bool show_in_shelf_; 551 bool show_in_shelf_;
567 552
568 // Icon URL to be used for setting the window icon. If not empty,
569 // app_icon_ will be fetched and set using this URL and will have
570 // app_icon_image_ as a badge.
571 GURL window_icon_url_;
572
573 // PlzNavigate: this is called when the first navigation is ready to commit. 553 // PlzNavigate: this is called when the first navigation is ready to commit.
574 base::Closure on_first_commit_callback_; 554 base::Closure on_first_commit_callback_;
575 555
576 base::WeakPtrFactory<AppWindow> image_loader_ptr_factory_; 556 base::WeakPtrFactory<AppWindow> image_loader_ptr_factory_;
577 557
578 DISALLOW_COPY_AND_ASSIGN(AppWindow); 558 DISALLOW_COPY_AND_ASSIGN(AppWindow);
579 }; 559 };
580 560
581 } // namespace extensions 561 } // namespace extensions
582 562
583 #endif // EXTENSIONS_BROWSER_APP_WINDOW_APP_WINDOW_H_ 563 #endif // EXTENSIONS_BROWSER_APP_WINDOW_APP_WINDOW_H_
OLDNEW
« no previous file with comments | « extensions/browser/app_window/app_delegate.h ('k') | extensions/browser/app_window/app_window.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698