| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 EXTENSIONS_BROWSER_EXTENSION_HOST_H_ | 5 #ifndef EXTENSIONS_BROWSER_EXTENSION_HOST_H_ |
| 6 #define EXTENSIONS_BROWSER_EXTENSION_HOST_H_ | 6 #define EXTENSIONS_BROWSER_EXTENSION_HOST_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
| 15 #include "base/timer/elapsed_timer.h" | 15 #include "base/timer/elapsed_timer.h" |
| 16 #include "content/public/browser/notification_observer.h" | 16 #include "content/public/browser/notification_observer.h" |
| 17 #include "content/public/browser/notification_registrar.h" | 17 #include "content/public/browser/notification_registrar.h" |
| 18 #include "content/public/browser/web_contents_delegate.h" | 18 #include "content/public/browser/web_contents_delegate.h" |
| 19 #include "content/public/browser/web_contents_observer.h" | 19 #include "content/public/browser/web_contents_observer.h" |
| 20 #include "extensions/browser/delayed_start_render_host.h" |
| 20 #include "extensions/browser/extension_function_dispatcher.h" | 21 #include "extensions/browser/extension_function_dispatcher.h" |
| 21 #include "extensions/common/stack_frame.h" | 22 #include "extensions/common/stack_frame.h" |
| 22 #include "extensions/common/view_type.h" | 23 #include "extensions/common/view_type.h" |
| 23 | 24 |
| 24 class PrefsTabHelper; | 25 class PrefsTabHelper; |
| 25 | 26 |
| 26 namespace content { | 27 namespace content { |
| 27 class BrowserContext; | 28 class BrowserContext; |
| 28 class RenderProcessHost; | 29 class RenderProcessHost; |
| 29 class RenderWidgetHostView; | 30 class RenderWidgetHostView; |
| 30 class SiteInstance; | 31 class SiteInstance; |
| 31 } | 32 } |
| 32 | 33 |
| 33 namespace extensions { | 34 namespace extensions { |
| 34 class Extension; | 35 class Extension; |
| 35 class ExtensionHostDelegate; | 36 class ExtensionHostDelegate; |
| 36 class ExtensionHostObserver; | 37 class ExtensionHostObserver; |
| 37 class ExtensionHostQueue; | 38 class ExtensionHostQueue; |
| 38 class WindowController; | 39 class WindowController; |
| 39 | 40 |
| 40 // This class is the browser component of an extension component's RenderView. | 41 // This class is the browser component of an extension component's RenderView. |
| 41 // It handles setting up the renderer process, if needed, with special | 42 // It handles setting up the renderer process, if needed, with special |
| 42 // privileges available to extensions. It may have a view to be shown in the | 43 // privileges available to extensions. It may have a view to be shown in the |
| 43 // browser UI, or it may be hidden. | 44 // browser UI, or it may be hidden. |
| 44 // | 45 // |
| 45 // If you are adding code that only affects visible extension views (and not | 46 // If you are adding code that only affects visible extension views (and not |
| 46 // invisible background pages) you should add it to ExtensionViewHost. | 47 // invisible background pages) you should add it to ExtensionViewHost. |
| 47 class ExtensionHost : public content::WebContentsDelegate, | 48 class ExtensionHost : public DelayedStartRenderHost, |
| 49 public content::WebContentsDelegate, |
| 48 public content::WebContentsObserver, | 50 public content::WebContentsObserver, |
| 49 public ExtensionFunctionDispatcher::Delegate, | 51 public ExtensionFunctionDispatcher::Delegate, |
| 50 public content::NotificationObserver { | 52 public content::NotificationObserver { |
| 51 public: | 53 public: |
| 52 ExtensionHost(const Extension* extension, | 54 ExtensionHost(const Extension* extension, |
| 53 content::SiteInstance* site_instance, | 55 content::SiteInstance* site_instance, |
| 54 const GURL& url, ViewType host_type); | 56 const GURL& url, ViewType host_type); |
| 55 ~ExtensionHost() override; | 57 ~ExtensionHost() override; |
| 56 | 58 |
| 57 const Extension* extension() const { return extension_; } | 59 const Extension* extension() const { return extension_; } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 71 | 73 |
| 72 // Returns true if the render view is initialized and didn't crash. | 74 // Returns true if the render view is initialized and didn't crash. |
| 73 bool IsRenderViewLive() const; | 75 bool IsRenderViewLive() const; |
| 74 | 76 |
| 75 // Prepares to initializes our RenderViewHost by creating its RenderView and | 77 // Prepares to initializes our RenderViewHost by creating its RenderView and |
| 76 // navigating to this host's url. Uses host_view for the RenderViewHost's view | 78 // navigating to this host's url. Uses host_view for the RenderViewHost's view |
| 77 // (can be NULL). This happens delayed to avoid locking the UI. | 79 // (can be NULL). This happens delayed to avoid locking the UI. |
| 78 void CreateRenderViewSoon(); | 80 void CreateRenderViewSoon(); |
| 79 | 81 |
| 80 // DO NOT CALL THIS. Always use CreateRenderViewSoon(). | 82 // DO NOT CALL THIS. Always use CreateRenderViewSoon(). |
| 81 // (Unless you're implementing an ExtensionHostQueue). | 83 // (Unless you're implementing an ExtensionHostQueue.) |
| 82 void CreateRenderViewNow(); | 84 // DelayedStartRenderHost: |
| 85 void CreateRenderViewNow() override; |
| 83 | 86 |
| 84 // Closes this host (results in [possibly asynchronous] deletion). | 87 // Closes this host (results in [possibly asynchronous] deletion). |
| 85 void Close(); | 88 void Close(); |
| 86 | 89 |
| 87 // Typical observer interface. | 90 // Typical observer interface. |
| 88 void AddObserver(ExtensionHostObserver* observer); | 91 void AddObserver(ExtensionHostObserver* observer); |
| 89 void RemoveObserver(ExtensionHostObserver* observer); | 92 void RemoveObserver(ExtensionHostObserver* observer); |
| 90 | 93 |
| 91 // Called when an IPC message is dispatched to the RenderView associated with | 94 // Called when an IPC message is dispatched to the RenderView associated with |
| 92 // this ExtensionHost. | 95 // this ExtensionHost. |
| 93 void OnMessageDispatched(const std::string& event_name, int message_id); | 96 void OnMessageDispatched(const std::string& event_name, int message_id); |
| 94 | 97 |
| 95 // Called by the ProcessManager when a network request is started by the | 98 // Called by the ProcessManager when a network request is started by the |
| 96 // extension corresponding to this ExtensionHost. | 99 // extension corresponding to this ExtensionHost. |
| 97 void OnNetworkRequestStarted(uint64 request_id); | 100 void OnNetworkRequestStarted(uint64 request_id); |
| 98 | 101 |
| 99 // Called by the ProcessManager when a previously started network request is | 102 // Called by the ProcessManager when a previously started network request is |
| 100 // finished. | 103 // finished. |
| 101 void OnNetworkRequestDone(uint64 request_id); | 104 void OnNetworkRequestDone(uint64 request_id); |
| 102 | 105 |
| 103 // content::WebContentsObserver | 106 // content::WebContentsObserver: |
| 104 bool OnMessageReceived(const IPC::Message& message) override; | 107 bool OnMessageReceived(const IPC::Message& message) override; |
| 105 void RenderViewCreated(content::RenderViewHost* render_view_host) override; | 108 void RenderViewCreated(content::RenderViewHost* render_view_host) override; |
| 106 void RenderViewDeleted(content::RenderViewHost* render_view_host) override; | 109 void RenderViewDeleted(content::RenderViewHost* render_view_host) override; |
| 107 void RenderViewReady() override; | 110 void RenderViewReady() override; |
| 108 void RenderProcessGone(base::TerminationStatus status) override; | 111 void RenderProcessGone(base::TerminationStatus status) override; |
| 109 void DocumentAvailableInMainFrame() override; | 112 void DocumentAvailableInMainFrame() override; |
| 110 void DidStopLoading(content::RenderViewHost* render_view_host) override; | 113 void DidStopLoading(content::RenderViewHost* render_view_host) override; |
| 111 | 114 |
| 112 // content::WebContentsDelegate | 115 // content::WebContentsDelegate: |
| 113 content::JavaScriptDialogManager* GetJavaScriptDialogManager( | 116 content::JavaScriptDialogManager* GetJavaScriptDialogManager( |
| 114 content::WebContents* source) override; | 117 content::WebContents* source) override; |
| 115 void AddNewContents(content::WebContents* source, | 118 void AddNewContents(content::WebContents* source, |
| 116 content::WebContents* new_contents, | 119 content::WebContents* new_contents, |
| 117 WindowOpenDisposition disposition, | 120 WindowOpenDisposition disposition, |
| 118 const gfx::Rect& initial_rect, | 121 const gfx::Rect& initial_rect, |
| 119 bool user_gesture, | 122 bool user_gesture, |
| 120 bool* was_blocked) override; | 123 bool* was_blocked) override; |
| 121 void CloseContents(content::WebContents* contents) override; | 124 void CloseContents(content::WebContents* contents) override; |
| 122 void RequestMediaAccessPermission( | 125 void RequestMediaAccessPermission( |
| 123 content::WebContents* web_contents, | 126 content::WebContents* web_contents, |
| 124 const content::MediaStreamRequest& request, | 127 const content::MediaStreamRequest& request, |
| 125 const content::MediaResponseCallback& callback) override; | 128 const content::MediaResponseCallback& callback) override; |
| 126 bool CheckMediaAccessPermission(content::WebContents* web_contents, | 129 bool CheckMediaAccessPermission(content::WebContents* web_contents, |
| 127 const GURL& security_origin, | 130 const GURL& security_origin, |
| 128 content::MediaStreamType type) override; | 131 content::MediaStreamType type) override; |
| 129 bool IsNeverVisible(content::WebContents* web_contents) override; | 132 bool IsNeverVisible(content::WebContents* web_contents) override; |
| 130 | 133 |
| 131 // content::NotificationObserver | 134 // content::NotificationObserver: |
| 132 void Observe(int type, | 135 void Observe(int type, |
| 133 const content::NotificationSource& source, | 136 const content::NotificationSource& source, |
| 134 const content::NotificationDetails& details) override; | 137 const content::NotificationDetails& details) override; |
| 135 | 138 |
| 136 protected: | 139 protected: |
| 137 content::NotificationRegistrar* registrar() { return ®istrar_; } | 140 content::NotificationRegistrar* registrar() { return ®istrar_; } |
| 138 | 141 |
| 139 // Called after the extension page finishes loading but before the | 142 // Called after the extension page finishes loading but before the |
| 140 // EXTENSION_HOST_DID_STOP_LOADING notification is sent. | 143 // EXTENSION_HOST_DID_STOP_LOADING notification is sent. |
| 141 virtual void OnDidStopLoading(); | 144 virtual void OnDidStopLoading(); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 scoped_ptr<base::ElapsedTimer> load_start_; | 199 scoped_ptr<base::ElapsedTimer> load_start_; |
| 197 | 200 |
| 198 ObserverList<ExtensionHostObserver> observer_list_; | 201 ObserverList<ExtensionHostObserver> observer_list_; |
| 199 | 202 |
| 200 DISALLOW_COPY_AND_ASSIGN(ExtensionHost); | 203 DISALLOW_COPY_AND_ASSIGN(ExtensionHost); |
| 201 }; | 204 }; |
| 202 | 205 |
| 203 } // namespace extensions | 206 } // namespace extensions |
| 204 | 207 |
| 205 #endif // EXTENSIONS_BROWSER_EXTENSION_HOST_H_ | 208 #endif // EXTENSIONS_BROWSER_EXTENSION_HOST_H_ |
| OLD | NEW |