Chromium Code Reviews| 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 LocationBarController; | 43 class LocationBarController; |
| 42 class WebstoreInlineInstallerFactory; | 44 class WebstoreInlineInstallerFactory; |
| 43 | 45 |
| 44 // Per-tab extension helper. Also handles non-extension apps. | 46 // Per-tab extension helper. Also handles non-extension apps. |
| 45 class TabHelper : public content::WebContentsObserver, | 47 class TabHelper : public content::WebContentsObserver, |
| 46 public ExtensionFunctionDispatcher::Delegate, | 48 public ExtensionFunctionDispatcher::Delegate, |
| 47 public ExtensionRegistryObserver, | 49 public ExtensionRegistryObserver, |
| 48 public content::NotificationObserver, | 50 public content::NotificationObserver, |
| 49 public content::WebContentsUserData<TabHelper> { | 51 public content::WebContentsUserData<TabHelper>, |
| 52 public mojom::InlineInstall { | |
| 50 public: | 53 public: |
| 51 ~TabHelper() override; | 54 ~TabHelper() override; |
| 52 | 55 |
| 53 void CreateApplicationShortcuts(); | 56 void CreateApplicationShortcuts(); |
| 54 void CreateHostedAppFromWebContents(); | 57 void CreateHostedAppFromWebContents(); |
| 55 bool CanCreateApplicationShortcuts() const; | 58 bool CanCreateApplicationShortcuts() const; |
| 56 bool CanCreateBookmarkApp() const; | 59 bool CanCreateBookmarkApp() const; |
| 57 | 60 |
| 58 void UpdateShortcutOnLoadComplete() { | 61 void UpdateShortcutOnLoadComplete() { |
| 59 update_shortcut_on_load_complete_ = true; | 62 update_shortcut_on_load_complete_ = true; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 111 | 114 |
| 112 // Sets a non-extension app icon associated with WebContents and fires an | 115 // Sets a non-extension app icon associated with WebContents and fires an |
| 113 // INVALIDATE_TYPE_TITLE navigation state change to trigger repaint of title. | 116 // INVALIDATE_TYPE_TITLE navigation state change to trigger repaint of title. |
| 114 void SetAppIcon(const SkBitmap& app_icon); | 117 void SetAppIcon(const SkBitmap& app_icon); |
| 115 | 118 |
| 116 // Sets the factory used to create inline webstore item installers. | 119 // Sets the factory used to create inline webstore item installers. |
| 117 // Used for testing. Takes ownership of the factory instance. | 120 // Used for testing. Takes ownership of the factory instance. |
| 118 void SetWebstoreInlineInstallerFactoryForTests( | 121 void SetWebstoreInlineInstallerFactoryForTests( |
| 119 WebstoreInlineInstallerFactory* factory); | 122 WebstoreInlineInstallerFactory* factory); |
| 120 | 123 |
| 124 explicit TabHelper(content::WebContents* web_contents); | |
|
Devlin
2017/04/12 01:16:07
Is this change still necessary?
catmullings
2017/04/14 20:59:40
Done.
| |
| 125 | |
| 121 private: | 126 private: |
| 122 class InlineInstallObserver; | 127 class InlineInstallObserver; |
| 123 | 128 |
| 129 protected: | |
|
Devlin
2017/04/12 01:16:07
Why protected?
catmullings
2017/04/14 20:59:40
Done.
| |
| 130 extensions::mojom::InlineInstallStatusPtr inline_install_status_; | |
| 131 | |
| 124 // Utility function to invoke member functions on all relevant | 132 // Utility function to invoke member functions on all relevant |
| 125 // ContentRulesRegistries. | 133 // ContentRulesRegistries. |
| 126 template <class Func> | 134 template <class Func> |
| 127 void InvokeForContentRulesRegistries(const Func& func); | 135 void InvokeForContentRulesRegistries(const Func& func); |
| 128 | 136 |
| 129 // Different types of action when web app info is available. | 137 // Different types of action when web app info is available. |
| 130 // OnDidGetApplicationInfo uses this to dispatch calls. | 138 // OnDidGetApplicationInfo uses this to dispatch calls. |
| 131 enum WebAppAction { | 139 enum WebAppAction { |
| 132 NONE, // No action at all. | 140 NONE, // No action at all. |
| 133 CREATE_SHORTCUT, // Bring up create application shortcut dialog. | 141 CREATE_SHORTCUT, // Bring up create application shortcut dialog. |
| 134 CREATE_HOSTED_APP, // Create and install a hosted app. | 142 CREATE_HOSTED_APP, // Create and install a hosted app. |
| 135 UPDATE_SHORTCUT // Update icon for app shortcut. | 143 UPDATE_SHORTCUT // Update icon for app shortcut. |
| 136 }; | 144 }; |
| 137 | 145 |
| 138 explicit TabHelper(content::WebContents* web_contents); | |
| 139 friend class content::WebContentsUserData<TabHelper>; | 146 friend class content::WebContentsUserData<TabHelper>; |
| 140 | 147 |
| 141 // Displays UI for completion of creating a bookmark hosted app. | 148 // Displays UI for completion of creating a bookmark hosted app. |
| 142 void FinishCreateBookmarkApp(const extensions::Extension* extension, | 149 void FinishCreateBookmarkApp(const extensions::Extension* extension, |
| 143 const WebApplicationInfo& web_app_info); | 150 const WebApplicationInfo& web_app_info); |
| 144 | 151 |
| 145 // content::WebContentsObserver overrides. | 152 // content::WebContentsObserver overrides. |
| 146 void RenderFrameCreated(content::RenderFrameHost* host) override; | 153 void RenderFrameCreated(content::RenderFrameHost* host) override; |
| 147 void DidFinishNavigation( | 154 void DidFinishNavigation( |
| 148 content::NavigationHandle* navigation_handle) override; | 155 content::NavigationHandle* navigation_handle) override; |
| 149 bool OnMessageReceived(const IPC::Message& message) override; | 156 bool OnMessageReceived(const IPC::Message& message) override; |
| 150 bool OnMessageReceived(const IPC::Message& message, | 157 bool OnMessageReceived(const IPC::Message& message, |
| 151 content::RenderFrameHost* render_frame_host) override; | 158 content::RenderFrameHost* render_frame_host) override; |
| 152 void DidCloneToNewWebContents( | 159 void DidCloneToNewWebContents( |
| 153 content::WebContents* old_web_contents, | 160 content::WebContents* old_web_contents, |
| 154 content::WebContents* new_web_contents) override; | 161 content::WebContents* new_web_contents) override; |
| 155 | 162 |
| 156 // extensions::ExtensionFunctionDispatcher::Delegate overrides. | 163 // extensions::ExtensionFunctionDispatcher::Delegate overrides. |
| 157 extensions::WindowController* GetExtensionWindowController() const override; | 164 extensions::WindowController* GetExtensionWindowController() const override; |
| 158 content::WebContents* GetAssociatedWebContents() const override; | 165 content::WebContents* GetAssociatedWebContents() const override; |
| 159 | 166 |
| 160 // ExtensionRegistryObserver: | 167 // ExtensionRegistryObserver: |
| 161 void OnExtensionUnloaded(content::BrowserContext* browser_context, | 168 void OnExtensionUnloaded(content::BrowserContext* browser_context, |
| 162 const Extension* extension, | 169 const Extension* extension, |
| 163 UnloadedExtensionInfo::Reason reason) override; | 170 UnloadedExtensionInfo::Reason reason) override; |
| 164 | 171 |
| 172 // mojom::InlineInstall: | |
| 173 void DoInlineInstall(int install_id, | |
| 174 int return_route_id, | |
| 175 const std::string& webstore_item_id, | |
| 176 int listeners_mask, | |
| 177 const DoInlineInstallCallback& callback) override; | |
| 178 | |
| 165 // Message handlers. | 179 // Message handlers. |
| 166 void OnDidGetWebApplicationInfo(const WebApplicationInfo& info); | 180 void OnDidGetWebApplicationInfo(const WebApplicationInfo& info); |
| 167 void OnInlineWebstoreInstall(content::RenderFrameHost* host, | |
| 168 int install_id, | |
| 169 int return_route_id, | |
| 170 const std::string& webstore_item_id, | |
| 171 int listeners_mask); | |
| 172 void OnGetAppInstallState(content::RenderFrameHost* host, | 181 void OnGetAppInstallState(content::RenderFrameHost* host, |
| 173 const GURL& requestor_url, | 182 const GURL& requestor_url, |
| 174 int return_route_id, | 183 int return_route_id, |
| 175 int callback_id); | 184 int callback_id); |
| 176 void OnContentScriptsExecuting( | 185 void OnContentScriptsExecuting( |
| 177 content::RenderFrameHost* host, | 186 content::RenderFrameHost* host, |
| 178 const ScriptExecutionObserver::ExecutingScriptsMap& extension_ids, | 187 const ScriptExecutionObserver::ExecutingScriptsMap& extension_ids, |
| 179 const GURL& on_url); | 188 const GURL& on_url); |
| 180 | 189 |
| 181 // App extensions related methods: | 190 // App extensions related methods: |
| 182 | 191 |
| 183 // Resets app_icon_ and if |extension| is non-null uses ImageLoader to load | 192 // Resets app_icon_ and if |extension| is non-null uses ImageLoader to load |
| 184 // the extension's image asynchronously. | 193 // the extension's image asynchronously. |
| 185 void UpdateExtensionAppIcon(const Extension* extension); | 194 void UpdateExtensionAppIcon(const Extension* extension); |
| 186 | 195 |
| 187 const Extension* GetExtension(const ExtensionId& extension_app_id); | 196 const Extension* GetExtension(const ExtensionId& extension_app_id); |
| 188 | 197 |
| 189 void OnImageLoaded(const gfx::Image& image); | 198 void OnImageLoaded(const gfx::Image& image); |
| 190 | 199 |
| 191 // WebstoreStandaloneInstaller::Callback. | 200 // WebstoreStandaloneInstaller::Callback. |
| 192 void OnInlineInstallComplete(int install_id, | 201 void OnInlineInstallComplete(const DoInlineInstallCallback& callback, |
| 202 int install_id, | |
| 193 int return_route_id, | 203 int return_route_id, |
| 194 const ExtensionId& extension_id, | 204 const ExtensionId& extension_id, |
| 195 bool success, | 205 bool success, |
| 196 const std::string& error, | 206 const std::string& error, |
| 197 webstore_install::Result result); | 207 webstore_install::Result result); |
| 198 | 208 |
| 199 // ExtensionReenabler::Callback. | 209 // ExtensionReenabler::Callback. |
| 200 void OnReenableComplete(int install_id, | 210 void OnReenableComplete(int install_id, |
| 201 int return_route_id, | 211 int return_route_id, |
| 202 const ExtensionId& extension_id, | 212 const ExtensionId& extension_id, |
| 213 const DoInlineInstallCallback& callback, | |
| 203 ExtensionReenabler::ReenableResult result); | 214 ExtensionReenabler::ReenableResult result); |
| 204 | 215 |
| 205 // content::NotificationObserver. | 216 // content::NotificationObserver. |
| 206 void Observe(int type, | 217 void Observe(int type, |
| 207 const content::NotificationSource& source, | 218 const content::NotificationSource& source, |
| 208 const content::NotificationDetails& details) override; | 219 const content::NotificationDetails& details) override; |
| 209 | 220 |
| 210 // Requests application info for the specified page. This is an asynchronous | 221 // Requests application info for the specified page. This is an asynchronous |
| 211 // request. The delegate is notified by way of OnDidGetApplicationInfo when | 222 // request. The delegate is notified by way of OnDidGetApplicationInfo when |
| 212 // the data is available. | 223 // the data is available. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 registry_observer_; | 277 registry_observer_; |
| 267 | 278 |
| 268 // Map of InlineInstallObservers for inline installations that have progress | 279 // Map of InlineInstallObservers for inline installations that have progress |
| 269 // listeners. | 280 // listeners. |
| 270 std::map<ExtensionId, std::unique_ptr<InlineInstallObserver>> | 281 std::map<ExtensionId, std::unique_ptr<InlineInstallObserver>> |
| 271 install_observers_; | 282 install_observers_; |
| 272 | 283 |
| 273 // The set of extension ids that are currently being installed. | 284 // The set of extension ids that are currently being installed. |
| 274 std::set<ExtensionId> pending_inline_installations_; | 285 std::set<ExtensionId> pending_inline_installations_; |
| 275 | 286 |
| 287 content::WebContentsFrameBindingSet<extensions::mojom::InlineInstall> | |
| 288 bindings_; | |
| 289 | |
| 276 // Vend weak pointers that can be invalidated to stop in-progress loads. | 290 // Vend weak pointers that can be invalidated to stop in-progress loads. |
| 277 base::WeakPtrFactory<TabHelper> image_loader_ptr_factory_; | 291 base::WeakPtrFactory<TabHelper> image_loader_ptr_factory_; |
| 278 | 292 |
| 279 // Generic weak ptr factory for posting callbacks. | 293 // Generic weak ptr factory for posting callbacks. |
| 280 base::WeakPtrFactory<TabHelper> weak_ptr_factory_; | 294 base::WeakPtrFactory<TabHelper> weak_ptr_factory_; |
| 281 | 295 |
| 282 DISALLOW_COPY_AND_ASSIGN(TabHelper); | 296 DISALLOW_COPY_AND_ASSIGN(TabHelper); |
| 283 }; | 297 }; |
| 284 | 298 |
| 285 } // namespace extensions | 299 } // namespace extensions |
| 286 | 300 |
| 287 #endif // CHROME_BROWSER_EXTENSIONS_TAB_HELPER_H_ | 301 #endif // CHROME_BROWSER_EXTENSIONS_TAB_HELPER_H_ |
| OLD | NEW |