| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_EXTENSIONS_TAB_HELPER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_TAB_HELPER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_TAB_HELPER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_TAB_HELPER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
| 16 #include "base/scoped_observer.h" | 16 #include "base/scoped_observer.h" |
| 17 #include "chrome/browser/extensions/active_tab_permission_granter.h" | 17 #include "chrome/browser/extensions/active_tab_permission_granter.h" |
| 18 #include "chrome/browser/extensions/extension_reenabler.h" | 18 #include "chrome/browser/extensions/extension_reenabler.h" |
| 19 #include "chrome/common/extensions/mojo/inline_install.mojom.h" |
| 19 #include "chrome/common/extensions/webstore_install_result.h" | 20 #include "chrome/common/extensions/webstore_install_result.h" |
| 20 #include "chrome/common/web_application_info.h" | 21 #include "chrome/common/web_application_info.h" |
| 21 #include "content/public/browser/notification_observer.h" | 22 #include "content/public/browser/notification_observer.h" |
| 22 #include "content/public/browser/notification_registrar.h" | 23 #include "content/public/browser/notification_registrar.h" |
| 24 #include "content/public/browser/web_contents_binding_set.h" |
| 23 #include "content/public/browser/web_contents_observer.h" | 25 #include "content/public/browser/web_contents_observer.h" |
| 24 #include "content/public/browser/web_contents_user_data.h" | 26 #include "content/public/browser/web_contents_user_data.h" |
| 25 #include "extensions/browser/extension_function_dispatcher.h" | 27 #include "extensions/browser/extension_function_dispatcher.h" |
| 26 #include "extensions/browser/extension_registry_observer.h" | 28 #include "extensions/browser/extension_registry_observer.h" |
| 27 #include "extensions/browser/script_execution_observer.h" | 29 #include "extensions/browser/script_execution_observer.h" |
| 28 #include "extensions/browser/script_executor.h" | 30 #include "extensions/browser/script_executor.h" |
| 29 #include "extensions/common/extension_id.h" | 31 #include "extensions/common/extension_id.h" |
| 30 #include "extensions/common/stack_frame.h" | 32 #include "extensions/common/stack_frame.h" |
| 31 #include "third_party/skia/include/core/SkBitmap.h" | 33 #include "third_party/skia/include/core/SkBitmap.h" |
| 32 | 34 |
| 33 namespace gfx { | 35 namespace gfx { |
| 34 class Image; | 36 class Image; |
| 35 } | 37 } |
| 36 | 38 |
| 37 namespace extensions { | 39 namespace extensions { |
| 38 class ExtensionActionRunner; | 40 class ExtensionActionRunner; |
| 39 class BookmarkAppHelper; | 41 class BookmarkAppHelper; |
| 40 class Extension; | 42 class Extension; |
| 41 class WebstoreInlineInstallerFactory; | 43 class WebstoreInlineInstallerFactory; |
| 42 | 44 |
| 43 // Per-tab extension helper. Also handles non-extension apps. | 45 // Per-tab extension helper. Also handles non-extension apps. |
| 44 class TabHelper : public content::WebContentsObserver, | 46 class TabHelper : public content::WebContentsObserver, |
| 45 public ExtensionFunctionDispatcher::Delegate, | 47 public ExtensionFunctionDispatcher::Delegate, |
| 46 public ExtensionRegistryObserver, | 48 public ExtensionRegistryObserver, |
| 47 public content::NotificationObserver, | 49 public content::NotificationObserver, |
| 48 public content::WebContentsUserData<TabHelper> { | 50 public content::WebContentsUserData<TabHelper>, |
| 51 public mojom::InlineInstall { |
| 49 public: | 52 public: |
| 50 ~TabHelper() override; | 53 ~TabHelper() override; |
| 51 | 54 |
| 52 void CreateHostedAppFromWebContents(); | 55 void CreateHostedAppFromWebContents(); |
| 53 bool CanCreateBookmarkApp() const; | 56 bool CanCreateBookmarkApp() const; |
| 54 | 57 |
| 55 void UpdateShortcutOnLoadComplete() { | 58 void UpdateShortcutOnLoadComplete() { |
| 56 update_shortcut_on_load_complete_ = true; | 59 update_shortcut_on_load_complete_ = true; |
| 57 } | 60 } |
| 58 | 61 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 void SetAppIcon(const SkBitmap& app_icon); | 110 void SetAppIcon(const SkBitmap& app_icon); |
| 108 | 111 |
| 109 // Sets the factory used to create inline webstore item installers. | 112 // Sets the factory used to create inline webstore item installers. |
| 110 // Used for testing. Takes ownership of the factory instance. | 113 // Used for testing. Takes ownership of the factory instance. |
| 111 void SetWebstoreInlineInstallerFactoryForTests( | 114 void SetWebstoreInlineInstallerFactoryForTests( |
| 112 WebstoreInlineInstallerFactory* factory); | 115 WebstoreInlineInstallerFactory* factory); |
| 113 | 116 |
| 114 private: | 117 private: |
| 115 class InlineInstallObserver; | 118 class InlineInstallObserver; |
| 116 | 119 |
| 120 extensions::mojom::InlineInstallStatusPtr inline_install_status_; |
| 121 |
| 117 // Utility function to invoke member functions on all relevant | 122 // Utility function to invoke member functions on all relevant |
| 118 // ContentRulesRegistries. | 123 // ContentRulesRegistries. |
| 119 template <class Func> | 124 template <class Func> |
| 120 void InvokeForContentRulesRegistries(const Func& func); | 125 void InvokeForContentRulesRegistries(const Func& func); |
| 121 | 126 |
| 122 // Different types of action when web app info is available. | 127 // Different types of action when web app info is available. |
| 123 // OnDidGetApplicationInfo uses this to dispatch calls. | 128 // OnDidGetApplicationInfo uses this to dispatch calls. |
| 124 enum WebAppAction { | 129 enum WebAppAction { |
| 125 NONE, // No action at all. | 130 NONE, // No action at all. |
| 126 CREATE_HOSTED_APP, // Create and install a hosted app. | 131 CREATE_HOSTED_APP, // Create and install a hosted app. |
| 127 UPDATE_SHORTCUT // Update icon for app shortcut. | 132 UPDATE_SHORTCUT // Update icon for app shortcut. |
| 128 }; | 133 }; |
| 129 | 134 |
| 130 explicit TabHelper(content::WebContents* web_contents); | 135 explicit TabHelper(content::WebContents* web_contents); |
| 136 |
| 131 friend class content::WebContentsUserData<TabHelper>; | 137 friend class content::WebContentsUserData<TabHelper>; |
| 132 | 138 |
| 133 // Displays UI for completion of creating a bookmark hosted app. | 139 // Displays UI for completion of creating a bookmark hosted app. |
| 134 void FinishCreateBookmarkApp(const extensions::Extension* extension, | 140 void FinishCreateBookmarkApp(const extensions::Extension* extension, |
| 135 const WebApplicationInfo& web_app_info); | 141 const WebApplicationInfo& web_app_info); |
| 136 | 142 |
| 137 // content::WebContentsObserver overrides. | 143 // content::WebContentsObserver overrides. |
| 138 void RenderFrameCreated(content::RenderFrameHost* host) override; | 144 void RenderFrameCreated(content::RenderFrameHost* host) override; |
| 139 void DidFinishNavigation( | 145 void DidFinishNavigation( |
| 140 content::NavigationHandle* navigation_handle) override; | 146 content::NavigationHandle* navigation_handle) override; |
| 141 bool OnMessageReceived(const IPC::Message& message) override; | 147 bool OnMessageReceived(const IPC::Message& message) override; |
| 142 bool OnMessageReceived(const IPC::Message& message, | 148 bool OnMessageReceived(const IPC::Message& message, |
| 143 content::RenderFrameHost* render_frame_host) override; | 149 content::RenderFrameHost* render_frame_host) override; |
| 144 void DidCloneToNewWebContents( | 150 void DidCloneToNewWebContents( |
| 145 content::WebContents* old_web_contents, | 151 content::WebContents* old_web_contents, |
| 146 content::WebContents* new_web_contents) override; | 152 content::WebContents* new_web_contents) override; |
| 147 | 153 |
| 148 // extensions::ExtensionFunctionDispatcher::Delegate overrides. | 154 // extensions::ExtensionFunctionDispatcher::Delegate overrides. |
| 149 extensions::WindowController* GetExtensionWindowController() const override; | 155 extensions::WindowController* GetExtensionWindowController() const override; |
| 150 content::WebContents* GetAssociatedWebContents() const override; | 156 content::WebContents* GetAssociatedWebContents() const override; |
| 151 | 157 |
| 152 // ExtensionRegistryObserver: | 158 // ExtensionRegistryObserver: |
| 153 void OnExtensionUnloaded(content::BrowserContext* browser_context, | 159 void OnExtensionUnloaded(content::BrowserContext* browser_context, |
| 154 const Extension* extension, | 160 const Extension* extension, |
| 155 UnloadedExtensionInfo::Reason reason) override; | 161 UnloadedExtensionInfo::Reason reason) override; |
| 156 | 162 |
| 163 // mojom::InlineInstall: |
| 164 void DoInlineInstall(int install_id, |
| 165 const std::string& webstore_item_id, |
| 166 int listeners_mask, |
| 167 const DoInlineInstallCallback& callback) override; |
| 168 |
| 157 // Message handlers. | 169 // Message handlers. |
| 158 void OnDidGetWebApplicationInfo(const WebApplicationInfo& info); | 170 void OnDidGetWebApplicationInfo(const WebApplicationInfo& info); |
| 159 void OnInlineWebstoreInstall(content::RenderFrameHost* host, | |
| 160 int install_id, | |
| 161 int return_route_id, | |
| 162 const std::string& webstore_item_id, | |
| 163 int listeners_mask); | |
| 164 void OnGetAppInstallState(content::RenderFrameHost* host, | 171 void OnGetAppInstallState(content::RenderFrameHost* host, |
| 165 const GURL& requestor_url, | 172 const GURL& requestor_url, |
| 166 int return_route_id, | 173 int return_route_id, |
| 167 int callback_id); | 174 int callback_id); |
| 168 void OnContentScriptsExecuting( | 175 void OnContentScriptsExecuting( |
| 169 content::RenderFrameHost* host, | 176 content::RenderFrameHost* host, |
| 170 const ScriptExecutionObserver::ExecutingScriptsMap& extension_ids, | 177 const ScriptExecutionObserver::ExecutingScriptsMap& extension_ids, |
| 171 const GURL& on_url); | 178 const GURL& on_url); |
| 172 | 179 |
| 173 // App extensions related methods: | 180 // App extensions related methods: |
| 174 | 181 |
| 175 // Resets app_icon_ and if |extension| is non-null uses ImageLoader to load | 182 // Resets app_icon_ and if |extension| is non-null uses ImageLoader to load |
| 176 // the extension's image asynchronously. | 183 // the extension's image asynchronously. |
| 177 void UpdateExtensionAppIcon(const Extension* extension); | 184 void UpdateExtensionAppIcon(const Extension* extension); |
| 178 | 185 |
| 179 const Extension* GetExtension(const ExtensionId& extension_app_id); | 186 const Extension* GetExtension(const ExtensionId& extension_app_id); |
| 180 | 187 |
| 181 void OnImageLoaded(const gfx::Image& image); | 188 void OnImageLoaded(const gfx::Image& image); |
| 182 | 189 |
| 183 // WebstoreStandaloneInstaller::Callback. | 190 // WebstoreStandaloneInstaller::Callback. |
| 184 void OnInlineInstallComplete(int install_id, | 191 void OnInlineInstallComplete(const DoInlineInstallCallback& callback, |
| 185 int return_route_id, | 192 int install_id, |
| 186 const ExtensionId& extension_id, | 193 const ExtensionId& extension_id, |
| 187 bool success, | 194 bool success, |
| 188 const std::string& error, | 195 const std::string& error, |
| 189 webstore_install::Result result); | 196 webstore_install::Result result); |
| 190 | 197 |
| 191 // ExtensionReenabler::Callback. | 198 // ExtensionReenabler::Callback. |
| 192 void OnReenableComplete(int install_id, | 199 void OnReenableComplete(int install_id, |
| 193 int return_route_id, | |
| 194 const ExtensionId& extension_id, | 200 const ExtensionId& extension_id, |
| 201 const DoInlineInstallCallback& callback, |
| 195 ExtensionReenabler::ReenableResult result); | 202 ExtensionReenabler::ReenableResult result); |
| 196 | 203 |
| 197 // content::NotificationObserver. | 204 // content::NotificationObserver. |
| 198 void Observe(int type, | 205 void Observe(int type, |
| 199 const content::NotificationSource& source, | 206 const content::NotificationSource& source, |
| 200 const content::NotificationDetails& details) override; | 207 const content::NotificationDetails& details) override; |
| 201 | 208 |
| 202 // Requests application info for the specified page. This is an asynchronous | 209 // Requests application info for the specified page. This is an asynchronous |
| 203 // request. The delegate is notified by way of OnDidGetApplicationInfo when | 210 // request. The delegate is notified by way of OnDidGetApplicationInfo when |
| 204 // the data is available. | 211 // the data is available. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 registry_observer_; | 263 registry_observer_; |
| 257 | 264 |
| 258 // Map of InlineInstallObservers for inline installations that have progress | 265 // Map of InlineInstallObservers for inline installations that have progress |
| 259 // listeners. | 266 // listeners. |
| 260 std::map<ExtensionId, std::unique_ptr<InlineInstallObserver>> | 267 std::map<ExtensionId, std::unique_ptr<InlineInstallObserver>> |
| 261 install_observers_; | 268 install_observers_; |
| 262 | 269 |
| 263 // The set of extension ids that are currently being installed. | 270 // The set of extension ids that are currently being installed. |
| 264 std::set<ExtensionId> pending_inline_installations_; | 271 std::set<ExtensionId> pending_inline_installations_; |
| 265 | 272 |
| 273 content::WebContentsFrameBindingSet<extensions::mojom::InlineInstall> |
| 274 bindings_; |
| 275 |
| 266 // Vend weak pointers that can be invalidated to stop in-progress loads. | 276 // Vend weak pointers that can be invalidated to stop in-progress loads. |
| 267 base::WeakPtrFactory<TabHelper> image_loader_ptr_factory_; | 277 base::WeakPtrFactory<TabHelper> image_loader_ptr_factory_; |
| 268 | 278 |
| 269 // Generic weak ptr factory for posting callbacks. | 279 // Generic weak ptr factory for posting callbacks. |
| 270 base::WeakPtrFactory<TabHelper> weak_ptr_factory_; | 280 base::WeakPtrFactory<TabHelper> weak_ptr_factory_; |
| 271 | 281 |
| 272 DISALLOW_COPY_AND_ASSIGN(TabHelper); | 282 DISALLOW_COPY_AND_ASSIGN(TabHelper); |
| 273 }; | 283 }; |
| 274 | 284 |
| 275 } // namespace extensions | 285 } // namespace extensions |
| 276 | 286 |
| 277 #endif // CHROME_BROWSER_EXTENSIONS_TAB_HELPER_H_ | 287 #endif // CHROME_BROWSER_EXTENSIONS_TAB_HELPER_H_ |
| OLD | NEW |