| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2006-2008 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_WEB_APP_H__ | |
| 6 #define CHROME_BROWSER_WEB_APP_H__ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/ref_counted.h" | |
| 11 #include "chrome/browser/cancelable_request.h" | |
| 12 #include "chrome/browser/gears_integration.h" | |
| 13 #include "chrome/browser/history/history.h" | |
| 14 #include "chrome/browser/webdata/web_data_service.h" | |
| 15 #include "googleurl/src/gurl.h" | |
| 16 #include "skia/include/SkBitmap.h" | |
| 17 | |
| 18 class Profile; | |
| 19 class WebContents; | |
| 20 | |
| 21 // A WebApp represents a page that Gears has installed a shortcut for. A WebApp | |
| 22 // has a name, url and set of images (potentially empty). The images are lazily | |
| 23 // loaded when asked for. | |
| 24 // | |
| 25 // The images are first loaded from the WebDatabase. If the images are not in | |
| 26 // the WebDB, the list of images is obtained from Gears then downloaded via the | |
| 27 // WebContents set by SetWebContents. As images are loaded they are pushed to | |
| 28 // the WebDatabase. Observers are notified any time the set of images changes. | |
| 29 class WebApp : public base::RefCounted<WebApp>, public WebDataServiceConsumer { | |
| 30 public: | |
| 31 typedef std::vector<SkBitmap> Images; | |
| 32 | |
| 33 // The Observer is notified any time the set of images contained in the WebApp | |
| 34 // changes. | |
| 35 class Observer { | |
| 36 public: | |
| 37 virtual void WebAppImagesChanged(WebApp* web_app) = 0; | |
| 38 }; | |
| 39 | |
| 40 // Creates a WebApp by name and url. This variant is only used if Gears | |
| 41 // doesn't know about the shortcut. | |
| 42 WebApp(Profile* profile, | |
| 43 const GURL& url, | |
| 44 const std::wstring& name); | |
| 45 | |
| 46 // Creates a WebApp from a Gears shortcut. | |
| 47 WebApp(Profile* profile, | |
| 48 const GearsShortcutData& shortcut); | |
| 49 ~WebApp(); | |
| 50 | |
| 51 // Sets the specified image. This is invoked from the WebContents when an | |
| 52 // image finishes downloading. If image_url is one of the images this WebApp | |
| 53 // asked to download, it is pushed to the database and the observer is | |
| 54 // notified. If the image isn't one that was asked for by this WebApp, nothing | |
| 55 // happens. | |
| 56 void SetImage(const GURL& image_url, const SkBitmap& image); | |
| 57 | |
| 58 // Returns the set of images. If the images haven't been loaded yet, they are | |
| 59 // asked for. | |
| 60 const Images& GetImages(); | |
| 61 | |
| 62 // Convenience to get the favicon from the set of images. If a favicon sized | |
| 63 // image isn't found, an empty image is returned. | |
| 64 SkBitmap GetFavIcon(); | |
| 65 | |
| 66 // Name of the app. | |
| 67 const std::wstring& name() const { return name_; } | |
| 68 | |
| 69 // URL to the app. | |
| 70 const GURL& url() const { return url_; } | |
| 71 | |
| 72 // Sets the WebContents that is using this WebApp. This is used if the | |
| 73 // database doesn't have all the images. If NULL, images won't be downloaded | |
| 74 // if they aren't in the db. | |
| 75 void SetWebContents(WebContents* host); | |
| 76 | |
| 77 // WebContents used to download images; may be null. | |
| 78 WebContents* web_contents() { return web_contents_; } | |
| 79 | |
| 80 void AddObserver(Observer* obs); | |
| 81 void RemoveObserver(Observer* obs); | |
| 82 | |
| 83 private: | |
| 84 // Requests the images for this app from the web db. Does nothing if the | |
| 85 // images have already been requested. | |
| 86 void LoadImagesFromWebData(); | |
| 87 | |
| 88 // Notification from the WebDB that our request for the images has completed. | |
| 89 // This adds all the images from the request to this WebApp, and if not all | |
| 90 // images have been downloaded, the images are requested from the webContents. | |
| 91 // Similarly if a favicon sized image isn't available, one is asked for from | |
| 92 // history. | |
| 93 virtual void OnWebDataServiceRequestDone(WebDataService::Handle h, | |
| 94 const WDTypedResult* result); | |
| 95 | |
| 96 // Callback from history when the favicon is available. If we don't have a | |
| 97 // favicon sized image, the image is added to this WebApp's list of images. | |
| 98 void OnFavIconFromHistory(HistoryService::Handle handle, | |
| 99 bool know_favicon, | |
| 100 scoped_refptr<RefCountedBytes> data, | |
| 101 bool expired, | |
| 102 GURL icon_url); | |
| 103 | |
| 104 // Requests the favicon from history. | |
| 105 void LoadFavIconFromHistory(); | |
| 106 | |
| 107 // Asks the hosting WebApp to download all the images. | |
| 108 void DownloadImagesFromSite(); | |
| 109 | |
| 110 // Returns the position of the favicon, or images_.end() if no favicon sized | |
| 111 // image is available | |
| 112 Images::iterator GetFavIconIterator(); | |
| 113 | |
| 114 // An URLs in image_urls_ that are data encoded PNGs are extracted and added | |
| 115 // to images_. | |
| 116 void ExtractPNGEncodedURLs(); | |
| 117 | |
| 118 void NotifyObservers(); | |
| 119 | |
| 120 // WebContents used to download images, may be null. | |
| 121 WebContents* web_contents_; | |
| 122 | |
| 123 // Profile used for WebDataservice and History. | |
| 124 Profile* profile_; | |
| 125 | |
| 126 // URL of the app. | |
| 127 const GURL url_; | |
| 128 | |
| 129 // Name of the app. | |
| 130 const std::wstring name_; | |
| 131 | |
| 132 // Have the images been loaded from the WebDB? This is initially false and set | |
| 133 // true when GetImages is invoked. | |
| 134 bool loaded_images_from_web_data_; | |
| 135 | |
| 136 // If non-zero, indicates we have a loading pending from the WebDB. | |
| 137 WebDataService::Handle image_load_handle_; | |
| 138 | |
| 139 // Set of images. | |
| 140 Images images_; | |
| 141 | |
| 142 // Set of image urls. | |
| 143 std::set<GURL> image_urls_; | |
| 144 | |
| 145 // Should the images be downloaded from the page? This is false if we don't | |
| 146 // know the set of image urls (weren't created from a GearsShortcutData) or | |
| 147 // the image urls in the GearsShortcutData were empty. | |
| 148 bool download_images_; | |
| 149 | |
| 150 // Used for history request for the favicon. | |
| 151 CancelableRequestConsumer request_consumer_; | |
| 152 | |
| 153 ObserverList<Observer> observer_list_; | |
| 154 | |
| 155 DISALLOW_EVIL_CONSTRUCTORS(WebApp); | |
| 156 }; | |
| 157 | |
| 158 #endif // CHROME_BROWSER_WEB_APP_H__ | |
| 159 | |
| OLD | NEW |