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/mojom/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::InlineInstaller { | |
| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 | 124 |
| 122 // Different types of action when web app info is available. | 125 // Different types of action when web app info is available. |
| 123 // OnDidGetApplicationInfo uses this to dispatch calls. | 126 // OnDidGetApplicationInfo uses this to dispatch calls. |
| 124 enum WebAppAction { | 127 enum WebAppAction { |
| 125 NONE, // No action at all. | 128 NONE, // No action at all. |
| 126 CREATE_HOSTED_APP, // Create and install a hosted app. | 129 CREATE_HOSTED_APP, // Create and install a hosted app. |
| 127 UPDATE_SHORTCUT // Update icon for app shortcut. | 130 UPDATE_SHORTCUT // Update icon for app shortcut. |
| 128 }; | 131 }; |
| 129 | 132 |
| 130 explicit TabHelper(content::WebContents* web_contents); | 133 explicit TabHelper(content::WebContents* web_contents); |
| 134 | |
| 131 friend class content::WebContentsUserData<TabHelper>; | 135 friend class content::WebContentsUserData<TabHelper>; |
| 132 | 136 |
| 133 // Displays UI for completion of creating a bookmark hosted app. | 137 // Displays UI for completion of creating a bookmark hosted app. |
| 134 void FinishCreateBookmarkApp(const extensions::Extension* extension, | 138 void FinishCreateBookmarkApp(const Extension* extension, |
| 135 const WebApplicationInfo& web_app_info); | 139 const WebApplicationInfo& web_app_info); |
| 136 | 140 |
| 137 // content::WebContentsObserver overrides. | 141 // content::WebContentsObserver overrides. |
| 138 void RenderFrameCreated(content::RenderFrameHost* host) override; | 142 void RenderFrameCreated(content::RenderFrameHost* host) override; |
| 139 void DidFinishNavigation( | 143 void DidFinishNavigation( |
| 140 content::NavigationHandle* navigation_handle) override; | 144 content::NavigationHandle* navigation_handle) override; |
| 141 bool OnMessageReceived(const IPC::Message& message) override; | 145 bool OnMessageReceived(const IPC::Message& message) override; |
| 142 bool OnMessageReceived(const IPC::Message& message, | 146 bool OnMessageReceived(const IPC::Message& message, |
| 143 content::RenderFrameHost* render_frame_host) override; | 147 content::RenderFrameHost* render_frame_host) override; |
| 144 void DidCloneToNewWebContents( | 148 void DidCloneToNewWebContents( |
| 145 content::WebContents* old_web_contents, | 149 content::WebContents* old_web_contents, |
| 146 content::WebContents* new_web_contents) override; | 150 content::WebContents* new_web_contents) override; |
| 147 | 151 |
| 148 // extensions::ExtensionFunctionDispatcher::Delegate overrides. | 152 // ExtensionFunctionDispatcher::Delegate overrides. |
| 149 extensions::WindowController* GetExtensionWindowController() const override; | 153 WindowController* GetExtensionWindowController() const override; |
| 150 content::WebContents* GetAssociatedWebContents() const override; | 154 content::WebContents* GetAssociatedWebContents() const override; |
| 151 | 155 |
| 152 // ExtensionRegistryObserver: | 156 // ExtensionRegistryObserver: |
| 153 void OnExtensionUnloaded(content::BrowserContext* browser_context, | 157 void OnExtensionUnloaded(content::BrowserContext* browser_context, |
| 154 const Extension* extension, | 158 const Extension* extension, |
| 155 UnloadedExtensionReason reason) override; | 159 UnloadedExtensionReason reason) override; |
| 156 | 160 |
| 161 // mojom::InlineInstall: | |
| 162 void DoInlineInstall( | |
| 163 int install_id, | |
| 164 const std::string& webstore_item_id, | |
| 165 int listeners_mask, | |
| 166 mojom::InlineInstallProgressListenerPtr install_progress_listener, | |
| 167 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(int install_id, |
| 185 int return_route_id, | |
| 186 const ExtensionId& extension_id, | 192 const ExtensionId& extension_id, |
| 187 bool success, | 193 bool success, |
| 188 const std::string& error, | 194 const std::string& error, |
| 189 webstore_install::Result result); | 195 webstore_install::Result result); |
| 190 | 196 |
| 191 // ExtensionReenabler::Callback. | 197 // ExtensionReenabler::Callback. |
| 192 void OnReenableComplete(int install_id, | 198 void OnReenableComplete(int install_id, |
| 193 int return_route_id, | |
| 194 const ExtensionId& extension_id, | 199 const ExtensionId& extension_id, |
| 195 ExtensionReenabler::ReenableResult result); | 200 ExtensionReenabler::ReenableResult result); |
| 196 | 201 |
| 197 // content::NotificationObserver. | 202 // content::NotificationObserver. |
| 198 void Observe(int type, | 203 void Observe(int type, |
| 199 const content::NotificationSource& source, | 204 const content::NotificationSource& source, |
| 200 const content::NotificationDetails& details) override; | 205 const content::NotificationDetails& details) override; |
| 201 | 206 |
| 202 // Requests application info for the specified page. This is an asynchronous | 207 // Requests application info for the specified page. This is an asynchronous |
| 203 // request. The delegate is notified by way of OnDidGetApplicationInfo when | 208 // request. The delegate is notified by way of OnDidGetApplicationInfo when |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 253 std::unique_ptr<ExtensionReenabler> extension_reenabler_; | 258 std::unique_ptr<ExtensionReenabler> extension_reenabler_; |
| 254 | 259 |
| 255 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> | 260 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
| 256 registry_observer_; | 261 registry_observer_; |
| 257 | 262 |
| 258 // Map of InlineInstallObservers for inline installations that have progress | 263 // Map of InlineInstallObservers for inline installations that have progress |
| 259 // listeners. | 264 // listeners. |
| 260 std::map<ExtensionId, std::unique_ptr<InlineInstallObserver>> | 265 std::map<ExtensionId, std::unique_ptr<InlineInstallObserver>> |
| 261 install_observers_; | 266 install_observers_; |
| 262 | 267 |
| 263 // The set of extension ids that are currently being installed. | 268 // Map of function callback that are invoked when the inline installation, for |
|
palmer
2017/05/23 22:41:47
Nit: "...callbacks that are...", and then no ",".
catmullings
2017/05/25 00:14:44
Done.
| |
| 264 std::set<ExtensionId> pending_inline_installations_; | 269 // a particular extension (hence ExtensionId) completes. |
| 270 std::map<ExtensionId, DoInlineInstallCallback> install_callbacks_; | |
| 271 | |
| 272 content::WebContentsFrameBindingSet<mojom::InlineInstaller> bindings_; | |
| 273 | |
| 274 std::map<ExtensionId, mojom::InlineInstallProgressListenerPtr> | |
| 275 inline_install_progress_listeners_; | |
| 265 | 276 |
| 266 // Vend weak pointers that can be invalidated to stop in-progress loads. | 277 // Vend weak pointers that can be invalidated to stop in-progress loads. |
| 267 base::WeakPtrFactory<TabHelper> image_loader_ptr_factory_; | 278 base::WeakPtrFactory<TabHelper> image_loader_ptr_factory_; |
| 268 | 279 |
| 269 // Generic weak ptr factory for posting callbacks. | 280 // Generic weak ptr factory for posting callbacks. |
| 270 base::WeakPtrFactory<TabHelper> weak_ptr_factory_; | 281 base::WeakPtrFactory<TabHelper> weak_ptr_factory_; |
| 271 | 282 |
| 272 DISALLOW_COPY_AND_ASSIGN(TabHelper); | 283 DISALLOW_COPY_AND_ASSIGN(TabHelper); |
| 273 }; | 284 }; |
| 274 | 285 |
| 275 } // namespace extensions | 286 } // namespace extensions |
| 276 | 287 |
| 277 #endif // CHROME_BROWSER_EXTENSIONS_TAB_HELPER_H_ | 288 #endif // CHROME_BROWSER_EXTENSIONS_TAB_HELPER_H_ |
| OLD | NEW |