1// Copyright (c) 2011 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_UI_VIEWS_CREATE_APPLICATION_SHORTCUT_VIEW_H_ 6#define CHROME_BROWSER_UI_VIEWS_CREATE_APPLICATION_SHORTCUT_VIEW_H_ 7#pragma once 8 9#include <string> 10 11#include "chrome/browser/extensions/image_loading_tracker.h" 12#include "chrome/browser/web_applications/web_app.h" 13#include "views/controls/label.h" 14#include "views/view.h" 15#include "views/window/dialog_delegate.h" 16#include "third_party/skia/include/core/SkBitmap.h" 17 18namespace views { 19class Checkbox; 20class Label; 21class Window; 22}; // namespace views 23 24class Extension; 25class MessageLoop; 26class Profile; 27class TabContents; 28class TabContentsWrapper; 29 30// CreateShortcutViewCommon implements a dialog that asks user where to create 31// the shortcut for given web app. There are two variants of this dialog: 32// Shortcuts that load a URL in an app-like window, and shortcuts that load 33// a chrome app (the kind you see under "apps" on the new tabs page) in an app 34// window. These are implemented as subclasses of CreateShortcutViewCommon. 35class CreateApplicationShortcutView : public views::View, 36 public views::DialogDelegate, 37 public views::ButtonListener { 38 public: 39 explicit CreateApplicationShortcutView(Profile* profile); 40 virtual ~CreateApplicationShortcutView(); 41 42 // Initialize the controls on the dialog. 43 void InitControls(); 44 45 // Overridden from views::View: 46 virtual gfx::Size GetPreferredSize(); 47 48 // Overridden from views::DialogDelegate: 49 virtual std::wstring GetDialogButtonLabel( 50 MessageBoxFlags::DialogButton button) const; 51 virtual bool IsDialogButtonEnabled( 52 MessageBoxFlags::DialogButton button) const; 53 virtual bool CanResize() const; 54 virtual bool CanMaximize() const; 55 virtual bool IsAlwaysOnTop() const; 56 virtual bool HasAlwaysOnTopMenu() const; 57 virtual bool IsModal() const; 58 virtual std::wstring GetWindowTitle() const; 59 virtual bool Accept(); 60 virtual views::View* GetContentsView(); 61 62 // Overridden from views::ButtonListener: 63 virtual void ButtonPressed(views::Button* sender, const views::Event& event); 64 65 protected: 66 // Adds a new check-box as a child to the view. 67 views::Checkbox* AddCheckbox(const std::wstring& text, bool checked); 68 69 // Profile in which the shortcuts will be created. 70 Profile* profile_; 71 72 // UI elements on the dialog. 73 views::View* app_info_; 74 views::Label* create_shortcuts_label_; 75 views::Checkbox* desktop_check_box_; 76 views::Checkbox* menu_check_box_; 77 views::Checkbox* quick_launch_check_box_; 78 79 // Target shortcut info. 80 ShellIntegration::ShortcutInfo shortcut_info_; 81 82 DISALLOW_COPY_AND_ASSIGN(CreateApplicationShortcutView); 83}; 84 85// Create an application shortcut pointing to a URL. 86class CreateUrlApplicationShortcutView : public CreateApplicationShortcutView { 87 public: 88 explicit CreateUrlApplicationShortcutView(TabContentsWrapper* tab_contents); 89 virtual ~CreateUrlApplicationShortcutView(); 90 91 virtual bool Accept(); 92 93 private: 94 // Fetch the largest unprocessed icon. 95 // The first largest icon downloaded and decoded successfully will be used. 96 void FetchIcon(); 97 98 // Callback of icon download. 99 void OnIconDownloaded(bool errored, const SkBitmap& image); 100 101 // The tab whose URL is being turned into an app. 102 TabContentsWrapper* tab_contents_; 103 104 // Pending app icon download tracked by us. 105 class IconDownloadCallbackFunctor; 106 IconDownloadCallbackFunctor* pending_download_; 107 108 // Unprocessed icons from the WebApplicationInfo passed in. 109 web_app::IconInfoList unprocessed_icons_; 110 111 DISALLOW_COPY_AND_ASSIGN(CreateUrlApplicationShortcutView); 112}; 113 114// Create an application shortcut pointing to a chrome application. 115class CreateChromeApplicationShortcutView 116 : public CreateApplicationShortcutView, 117 public ImageLoadingTracker::Observer { 118 public: 119 explicit CreateChromeApplicationShortcutView(Profile* profile, 120 const Extension* app); 121 virtual ~CreateChromeApplicationShortcutView(); 122 123 // Implement ImageLoadingTracker::Observer. |tracker_| is used to 124 // load the app's icon. This method recieves the icon, and adds 125 // it to the "Create Shortcut" dailog box. 126 virtual void OnImageLoaded(SkBitmap* image, 127 const ExtensionResource& resource, 128 int index); 129 130 private: 131 const Extension* app_; 132 ImageLoadingTracker tracker_; 133 134 DISALLOW_COPY_AND_ASSIGN(CreateChromeApplicationShortcutView); 135}; 136 137 138#endif // CHROME_BROWSER_UI_VIEWS_CREATE_APPLICATION_SHORTCUT_VIEW_H_ 139