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

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

Issue 2900783003: Handle app custom icon via aura::Window property. (Closed)
Patch Set: cleanup Created 3 years, 7 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 WINDOW_TYPE_V1_PANEL = 1 << 2, // For apps v1 support in Ash; deprecate 95 WINDOW_TYPE_V1_PANEL = 1 << 2, // For apps v1 support in Ash; deprecate
98 // with v1 apps. 96 // with v1 apps.
99 }; 97 };
100 98
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 const std::string& window_key() const { return window_key_; } 230 const std::string& window_key() const { return window_key_; }
233 const SessionID& session_id() const { return session_id_; } 231 const SessionID& session_id() const { return session_id_; }
234 const std::string& extension_id() const { return extension_id_; } 232 const std::string& extension_id() const { return extension_id_; }
235 content::WebContents* web_contents() const; 233 content::WebContents* web_contents() const;
236 WindowType window_type() const { return window_type_; } 234 WindowType window_type() const { return window_type_; }
237 bool window_type_is_panel() const { 235 bool window_type_is_panel() const {
238 return (window_type_ == WINDOW_TYPE_PANEL || 236 return (window_type_ == WINDOW_TYPE_PANEL ||
239 window_type_ == WINDOW_TYPE_V1_PANEL); 237 window_type_ == WINDOW_TYPE_V1_PANEL);
240 } 238 }
241 content::BrowserContext* browser_context() const { return browser_context_; } 239 content::BrowserContext* browser_context() const { return browser_context_; }
242 const gfx::Image& app_icon() const { return app_icon_; } 240 const gfx::Image& custom_app_icon() const { return custom_app_icon_; }
243 const GURL& app_icon_url() const { return app_icon_url_; } 241 const GURL& app_icon_url() const { return app_icon_url_; }
244 const GURL& initial_url() const { return initial_url_; } 242 const GURL& initial_url() const { return initial_url_; }
245 bool is_hidden() const { return is_hidden_; } 243 bool is_hidden() const { return is_hidden_; }
246 244
247 const Extension* GetExtension() const; 245 const Extension* GetExtension() const;
248 NativeAppWindow* GetBaseWindow(); 246 NativeAppWindow* GetBaseWindow();
249 gfx::NativeWindow GetNativeWindow(); 247 gfx::NativeWindow GetNativeWindow();
250 248
251 // Returns the bounds that should be reported to the renderer. 249 // Returns the bounds that should be reported to the renderer.
252 gfx::Rect GetClientBounds() const; 250 gfx::Rect GetClientBounds() const;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 void RestoreAlwaysOnTop(); 351 void RestoreAlwaysOnTop();
354 352
355 // Retrieve the current state of the app window as a dictionary, to pass to 353 // Retrieve the current state of the app window as a dictionary, to pass to
356 // the renderer. 354 // the renderer.
357 void GetSerializedState(base::DictionaryValue* properties) const; 355 void GetSerializedState(base::DictionaryValue* properties) const;
358 356
359 // Notifies the window's contents that the render view is ready and it can 357 // Notifies the window's contents that the render view is ready and it can
360 // unblock resource requests. 358 // unblock resource requests.
361 void NotifyRenderViewReady(); 359 void NotifyRenderViewReady();
362 360
363 // Returns true if window has custom icon in case either |window_icon_url_| or
364 // |app_icon_url_| is set. Custom icon may be not loaded yet.
365 bool HasCustomIcon() const;
366
367 // Whether the app window wants to be alpha enabled. 361 // Whether the app window wants to be alpha enabled.
368 bool requested_alpha_enabled() const { return requested_alpha_enabled_; } 362 bool requested_alpha_enabled() const { return requested_alpha_enabled_; }
369 363
370 // Whether the app window is created by IME extensions. 364 // Whether the app window is created by IME extensions.
371 // TODO(bshe): rename to hide_app_window_in_launcher if it is not used 365 // TODO(bshe): rename to hide_app_window_in_launcher if it is not used
372 // anywhere other than app_window_launcher_controller after M45. Otherwise, 366 // anywhere other than app_window_launcher_controller after M45. Otherwise,
373 // remove this TODO. 367 // remove this TODO.
374 bool is_ime_window() const { return is_ime_window_; } 368 bool is_ime_window() const { return is_ime_window_; }
375 369
376 bool show_in_shelf() const { return show_in_shelf_; } 370 bool show_in_shelf() const { return show_in_shelf_; }
377 371
378 const GURL& window_icon_url() const { return window_icon_url_; } 372 AppDelegate* app_delegate() { return app_delegate_.get(); }
379 373
380 void SetAppWindowContentsForTesting( 374 void SetAppWindowContentsForTesting(
381 std::unique_ptr<AppWindowContents> contents) { 375 std::unique_ptr<AppWindowContents> contents) {
382 app_window_contents_ = std::move(contents); 376 app_window_contents_ = std::move(contents);
383 } 377 }
384 378
385 protected: 379 protected:
386 ~AppWindow() override; 380 ~AppWindow() override;
387 381
388 private: 382 private:
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 void AdjustBoundsToBeVisibleOnScreen(const gfx::Rect& cached_bounds, 463 void AdjustBoundsToBeVisibleOnScreen(const gfx::Rect& cached_bounds,
470 const gfx::Rect& cached_screen_bounds, 464 const gfx::Rect& cached_screen_bounds,
471 const gfx::Rect& current_screen_bounds, 465 const gfx::Rect& current_screen_bounds,
472 const gfx::Size& minimum_size, 466 const gfx::Size& minimum_size,
473 gfx::Rect* bounds) const; 467 gfx::Rect* bounds) const;
474 468
475 // Loads the appropriate default or cached window bounds. Returns a new 469 // Loads the appropriate default or cached window bounds. Returns a new
476 // CreateParams that should be used to create the window. 470 // CreateParams that should be used to create the window.
477 CreateParams LoadDefaults(CreateParams params) const; 471 CreateParams LoadDefaults(CreateParams params) const;
478 472
479 // Load the app's image, firing a load state change when loaded.
480 void UpdateExtensionAppIcon();
481
482 // Set the fullscreen state in the native app window. 473 // Set the fullscreen state in the native app window.
483 void SetNativeWindowFullscreen(); 474 void SetNativeWindowFullscreen();
484 475
485 // Returns true if there is any overlap between the window and the taskbar 476 // Returns true if there is any overlap between the window and the taskbar
486 // (Windows only). 477 // (Windows only).
487 bool IntersectsWithTaskbar() const; 478 bool IntersectsWithTaskbar() const;
488 479
489 // Update the always-on-top bit in the native app window. 480 // Update the always-on-top bit in the native app window.
490 void UpdateNativeAlwaysOnTop(); 481 void UpdateNativeAlwaysOnTop();
491 482
492 // Sends the onWindowShown event to the app if the window has been shown. Only 483 // Sends the onWindowShown event to the app if the window has been shown. Only
493 // has an effect in tests. 484 // has an effect in tests.
494 void SendOnWindowShownIfShown(); 485 void SendOnWindowShownIfShown();
495 486
496 // web_modal::WebContentsModalDialogManagerDelegate implementation. 487 // web_modal::WebContentsModalDialogManagerDelegate implementation.
497 web_modal::WebContentsModalDialogHost* GetWebContentsModalDialogHost() 488 web_modal::WebContentsModalDialogHost* GetWebContentsModalDialogHost()
498 override; 489 override;
499 490
500 // Callback from web_contents()->DownloadFavicon. 491 // Callback from web_contents()->DownloadFavicon.
501 void DidDownloadFavicon(int id, 492 void DidDownloadFavicon(int id,
502 int http_status_code, 493 int http_status_code,
503 const GURL& image_url, 494 const GURL& image_url,
504 const std::vector<SkBitmap>& bitmaps, 495 const std::vector<SkBitmap>& bitmaps,
505 const std::vector<gfx::Size>& original_bitmap_sizes); 496 const std::vector<gfx::Size>& original_bitmap_sizes);
506 497
507 // IconImage::Observer implementation.
508 void OnExtensionIconImageChanged(IconImage* image) override;
509
510 // The browser context with which this window is associated. AppWindow does 498 // The browser context with which this window is associated. AppWindow does
511 // not own this object. 499 // not own this object.
512 content::BrowserContext* browser_context_; 500 content::BrowserContext* browser_context_;
513 501
514 const std::string extension_id_; 502 const std::string extension_id_;
515 503
516 // Identifier that is used when saving and restoring geometry for this 504 // Identifier that is used when saving and restoring geometry for this
517 // window. 505 // window.
518 std::string window_key_; 506 std::string window_key_;
519 507
520 const SessionID session_id_; 508 const SessionID session_id_;
521 WindowType window_type_; 509 WindowType window_type_;
522 510
523 // Icon shown in the task bar. 511 // Custom icon shown in the task bar or in shelf.
msw 2017/05/23 00:02:30 nit: the shelf is chrome's 'task bar', so you can
khmel 2017/05/23 16:11:44 Done.
524 gfx::Image app_icon_; 512 gfx::Image custom_app_icon_;
525 513
526 // Icon URL to be used for setting the app icon. If not empty, app_icon_ will 514 // Icon URL to be used for setting the app icon. If not empty, app_icon_ will
527 // be fetched and set using this URL. 515 // be fetched and set using this URL.
528 GURL app_icon_url_; 516 GURL app_icon_url_;
529 517
530 // An object to load the app's icon as an extension resource.
531 std::unique_ptr<IconImage> app_icon_image_;
532
533 std::unique_ptr<NativeAppWindow> native_app_window_; 518 std::unique_ptr<NativeAppWindow> native_app_window_;
534 std::unique_ptr<AppWindowContents> app_window_contents_; 519 std::unique_ptr<AppWindowContents> app_window_contents_;
535 std::unique_ptr<AppDelegate> app_delegate_; 520 std::unique_ptr<AppDelegate> app_delegate_;
536 std::unique_ptr<AppWebContentsHelper> helper_; 521 std::unique_ptr<AppWebContentsHelper> helper_;
537 522
538 // The initial url this AppWindow was navigated to. 523 // The initial url this AppWindow was navigated to.
539 GURL initial_url_; 524 GURL initial_url_;
540 525
541 // Bit field of FullscreenType. 526 // Bit field of FullscreenType.
542 int fullscreen_types_; 527 int fullscreen_types_;
(...skipping 18 matching lines...) Expand all
561 546
562 // Whether |alpha_enabled| was set in the CreateParams. 547 // Whether |alpha_enabled| was set in the CreateParams.
563 bool requested_alpha_enabled_; 548 bool requested_alpha_enabled_;
564 549
565 // Whether |is_ime_window| was set in the CreateParams. 550 // Whether |is_ime_window| was set in the CreateParams.
566 bool is_ime_window_; 551 bool is_ime_window_;
567 552
568 // Whether |show_in_shelf| was set in the CreateParams. 553 // Whether |show_in_shelf| was set in the CreateParams.
569 bool show_in_shelf_; 554 bool show_in_shelf_;
570 555
571 // Icon URL to be used for setting the window icon. If not empty,
572 // app_icon_ will be fetched and set using this URL and will have
573 // app_icon_image_ as a badge.
574 GURL window_icon_url_;
575
576 // PlzNavigate: this is called when the first navigation is ready to commit. 556 // PlzNavigate: this is called when the first navigation is ready to commit.
577 base::Closure on_first_commit_callback_; 557 base::Closure on_first_commit_callback_;
578 558
579 base::WeakPtrFactory<AppWindow> image_loader_ptr_factory_; 559 base::WeakPtrFactory<AppWindow> image_loader_ptr_factory_;
580 560
581 DISALLOW_COPY_AND_ASSIGN(AppWindow); 561 DISALLOW_COPY_AND_ASSIGN(AppWindow);
582 }; 562 };
583 563
584 } // namespace extensions 564 } // namespace extensions
585 565
586 #endif // EXTENSIONS_BROWSER_APP_WINDOW_APP_WINDOW_H_ 566 #endif // EXTENSIONS_BROWSER_APP_WINDOW_APP_WINDOW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698