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_EXTENSIONS_EXTENSION_TAB_HELPER_H_ 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_TAB_HELPER_H_ 7 #pragma once 8 9 #include "content/browser/tab_contents/tab_contents_observer.h" 10 #include "chrome/browser/extensions/image_loading_tracker.h" 11 #include "chrome/common/web_apps.h" 12 #include "third_party/skia/include/core/SkBitmap.h" 13 14 class Extension; 15 class TabContentsWrapper; 16 struct WebApplicationInfo; 17 18 // Per-tab extension helper. Also handles non-extension apps. 19 class ExtensionTabHelper : public TabContentsObserver, 20 public ImageLoadingTracker::Observer { 21 public: 22 explicit ExtensionTabHelper(TabContentsWrapper* wrapper); 23 virtual ~ExtensionTabHelper(); 24 25 // Copies the internal state from another ExtensionTabHelper. 26 void CopyStateFrom(const ExtensionTabHelper& source); 27 28 // Call this after updating a page action to notify clients about the changes. 29 void PageActionStateChanged(); 30 31 // Requests application info for the specified page. This is an asynchronous 32 // request. The delegate is notified by way of OnDidGetApplicationInfo when 33 // the data is available. 34 void GetApplicationInfo(int32 page_id); 35 36 // App extensions ------------------------------------------------------------ 37 38 // Sets the extension denoting this as an app. If |extension| is non-null this 39 // tab becomes an app-tab. TabContents does not listen for unload events for 40 // the extension. It's up to consumers of TabContents to do that. 41 // 42 // NOTE: this should only be manipulated before the tab is added to a browser. 43 // TODO(sky): resolve if this is the right way to identify an app tab. If it 44 // is, than this should be passed in the constructor. 45 void SetExtensionApp(const Extension* extension); 46 47 // Convenience for setting the app extension by id. This does nothing if 48 // |extension_app_id| is empty, or an extension can't be found given the 49 // specified id. 50 void SetExtensionAppById(const std::string& extension_app_id); 51 52 const Extension* extension_app() const { return extension_app_; } 53 bool is_app() const { return extension_app_ != NULL; } 54 const WebApplicationInfo& web_app_info() const { 55 return web_app_info_; 56 } 57 58 // If an app extension has been explicitly set for this TabContents its icon 59 // is returned. 60 // 61 // NOTE: the returned icon is larger than 16x16 (its size is 62 // Extension::EXTENSION_ICON_SMALLISH). 63 SkBitmap* GetExtensionAppIcon(); 64 65 TabContents* tab_contents() const { 66 return TabContentsObserver::tab_contents(); 67 } 68 69 // Sets a non-extension app icon associated with TabContents and fires an 70 // INVALIDATE_TITLE navigation state change to trigger repaint of title. 71 void SetAppIcon(const SkBitmap& app_icon); 72 73 private: 74 // TabContentsObserver overrides. 75 virtual void DidNavigateMainFramePostCommit( 76 const NavigationController::LoadCommittedDetails& details, 77 const ViewHostMsg_FrameNavigate_Params& params) OVERRIDE; 78 virtual bool OnMessageReceived(const IPC::Message& message); 79 80 // Message handlers. 81 void OnDidGetApplicationInfo(int32 page_id, const WebApplicationInfo& info); 82 void OnInstallApplication(const WebApplicationInfo& info); 83 84 // App extensions related methods: 85 86 // Resets app_icon_ and if |extension| is non-null creates a new 87 // ImageLoadingTracker to load the extension's image. 88 void UpdateExtensionAppIcon(const Extension* extension); 89 90 // ImageLoadingTracker::Observer. 91 virtual void OnImageLoaded(SkBitmap* image, const ExtensionResource& resource, 92 int index); 93 94 // Data for app extensions --------------------------------------------------- 95 96 // If non-null this tab is an app tab and this is the extension the tab was 97 // created for. 98 const Extension* extension_app_; 99 100 // Icon for extension_app_ (if non-null) or a manually-set icon for 101 // non-extension apps. 102 SkBitmap extension_app_icon_; 103 104 // Used for loading extension_app_icon_. 105 scoped_ptr<ImageLoadingTracker> extension_app_image_loader_; 106 107 // Cached web app info data. 108 WebApplicationInfo web_app_info_; 109 110 TabContentsWrapper* wrapper_; 111 112 DISALLOW_COPY_AND_ASSIGN(ExtensionTabHelper); 113 }; 114 115 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TAB_HELPER_H_ 116