| OLD | NEW |
| (Empty) | |
| 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_EXTENSOIN_TAB_HELPER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSOIN_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 "third_party/skia/include/core/SkBitmap.h" |
| 12 |
| 13 class Extension; |
| 14 |
| 15 // Per-tab extension helper. |
| 16 class ExtensionTabHelper : public TabContentsObserver, |
| 17 public ImageLoadingTracker::Observer { |
| 18 public: |
| 19 explicit ExtensionTabHelper(TabContents* tab_contents); |
| 20 virtual ~ExtensionTabHelper(); |
| 21 |
| 22 // Copies the internal state from another ExtensionTabHelper. |
| 23 void CopyStateFrom(const ExtensionTabHelper& source); |
| 24 |
| 25 // Call this after updating a page action to notify clients about the changes. |
| 26 void PageActionStateChanged(); |
| 27 |
| 28 // App extensions ------------------------------------------------------------ |
| 29 |
| 30 // Sets the extension denoting this as an app. If |extension| is non-null this |
| 31 // tab becomes an app-tab. TabContents does not listen for unload events for |
| 32 // the extension. It's up to consumers of TabContents to do that. |
| 33 // |
| 34 // NOTE: this should only be manipulated before the tab is added to a browser. |
| 35 // TODO(sky): resolve if this is the right way to identify an app tab. If it |
| 36 // is, than this should be passed in the constructor. |
| 37 void SetExtensionApp(const Extension* extension); |
| 38 |
| 39 // Convenience for setting the app extension by id. This does nothing if |
| 40 // |extension_app_id| is empty, or an extension can't be found given the |
| 41 // specified id. |
| 42 void SetExtensionAppById(const std::string& extension_app_id); |
| 43 |
| 44 const Extension* extension_app() const { return extension_app_; } |
| 45 bool is_app() const { return extension_app_ != NULL; } |
| 46 |
| 47 // If an app extension has been explicitly set for this TabContents its icon |
| 48 // is returned. |
| 49 // |
| 50 // NOTE: the returned icon is larger than 16x16 (its size is |
| 51 // Extension::EXTENSION_ICON_SMALLISH). |
| 52 SkBitmap* GetExtensionAppIcon(); |
| 53 |
| 54 TabContents* tab_contents() const { |
| 55 return TabContentsObserver::tab_contents(); |
| 56 } |
| 57 |
| 58 private: |
| 59 // TabContentsObserver overrides. |
| 60 virtual void DidNavigateMainFramePostCommit( |
| 61 const NavigationController::LoadCommittedDetails& details, |
| 62 const ViewHostMsg_FrameNavigate_Params& params) OVERRIDE; |
| 63 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 64 |
| 65 // App extensions related methods: |
| 66 |
| 67 // Resets app_icon_ and if |extension| is non-null creates a new |
| 68 // ImageLoadingTracker to load the extension's image. |
| 69 void UpdateExtensionAppIcon(const Extension* extension); |
| 70 |
| 71 // ImageLoadingTracker::Observer. |
| 72 virtual void OnImageLoaded(SkBitmap* image, const ExtensionResource& resource, |
| 73 int index); |
| 74 |
| 75 // Message handlers. |
| 76 void OnPostMessage(int port_id, const std::string& message); |
| 77 |
| 78 // Data for app extensions --------------------------------------------------- |
| 79 |
| 80 // If non-null this tab is an app tab and this is the extension the tab was |
| 81 // created for. |
| 82 const Extension* extension_app_; |
| 83 |
| 84 // Icon for extension_app_ (if non-null) or extension_for_current_page_. |
| 85 SkBitmap extension_app_icon_; |
| 86 |
| 87 // Used for loading extension_app_icon_. |
| 88 scoped_ptr<ImageLoadingTracker> extension_app_image_loader_; |
| 89 |
| 90 DISALLOW_COPY_AND_ASSIGN(ExtensionTabHelper); |
| 91 }; |
| 92 |
| 93 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSOIN_TAB_HELPER_H_ |
| OLD | NEW |