| 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 <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/observer_list.h" |
| 13 #include "base/timer/elapsed_timer.h" | 14 #include "base/timer/elapsed_timer.h" |
| 14 #include "content/public/browser/notification_observer.h" | 15 #include "content/public/browser/notification_observer.h" |
| 15 #include "content/public/browser/notification_registrar.h" | 16 #include "content/public/browser/notification_registrar.h" |
| 16 #include "content/public/browser/web_contents_delegate.h" | 17 #include "content/public/browser/web_contents_delegate.h" |
| 17 #include "content/public/browser/web_contents_observer.h" | 18 #include "content/public/browser/web_contents_observer.h" |
| 18 #include "extensions/browser/extension_function_dispatcher.h" | 19 #include "extensions/browser/extension_function_dispatcher.h" |
| 19 #include "extensions/common/stack_frame.h" | 20 #include "extensions/common/stack_frame.h" |
| 20 #include "extensions/common/view_type.h" | 21 #include "extensions/common/view_type.h" |
| 21 | 22 |
| 22 class PrefsTabHelper; | 23 class PrefsTabHelper; |
| 23 | 24 |
| 24 namespace content { | 25 namespace content { |
| 25 class BrowserContext; | 26 class BrowserContext; |
| 26 class RenderProcessHost; | 27 class RenderProcessHost; |
| 27 class RenderWidgetHostView; | 28 class RenderWidgetHostView; |
| 28 class SiteInstance; | 29 class SiteInstance; |
| 29 } | 30 } |
| 30 | 31 |
| 31 namespace extensions { | 32 namespace extensions { |
| 32 class Extension; | 33 class Extension; |
| 33 class ExtensionHostDelegate; | 34 class ExtensionHostDelegate; |
| 35 class ExtensionHostObserver; |
| 34 class WindowController; | 36 class WindowController; |
| 35 | 37 |
| 36 // This class is the browser component of an extension component's RenderView. | 38 // This class is the browser component of an extension component's RenderView. |
| 37 // It handles setting up the renderer process, if needed, with special | 39 // It handles setting up the renderer process, if needed, with special |
| 38 // privileges available to extensions. It may have a view to be shown in the | 40 // privileges available to extensions. It may have a view to be shown in the |
| 39 // browser UI, or it may be hidden. | 41 // browser UI, or it may be hidden. |
| 40 // | 42 // |
| 41 // If you are adding code that only affects visible extension views (and not | 43 // If you are adding code that only affects visible extension views (and not |
| 42 // invisible background pages) you should add it to ExtensionViewHost. | 44 // invisible background pages) you should add it to ExtensionViewHost. |
| 43 class ExtensionHost : public content::WebContentsDelegate, | 45 class ExtensionHost : public content::WebContentsDelegate, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 68 const GURL& GetURL() const; | 70 const GURL& GetURL() const; |
| 69 | 71 |
| 70 // Returns true if the render view is initialized and didn't crash. | 72 // Returns true if the render view is initialized and didn't crash. |
| 71 bool IsRenderViewLive() const; | 73 bool IsRenderViewLive() const; |
| 72 | 74 |
| 73 // Prepares to initializes our RenderViewHost by creating its RenderView and | 75 // Prepares to initializes our RenderViewHost by creating its RenderView and |
| 74 // navigating to this host's url. Uses host_view for the RenderViewHost's view | 76 // navigating to this host's url. Uses host_view for the RenderViewHost's view |
| 75 // (can be NULL). This happens delayed to avoid locking the UI. | 77 // (can be NULL). This happens delayed to avoid locking the UI. |
| 76 void CreateRenderViewSoon(); | 78 void CreateRenderViewSoon(); |
| 77 | 79 |
| 80 // Typical observer interface. |
| 81 void AddObserver(ExtensionHostObserver* observer); |
| 82 void RemoveObserver(ExtensionHostObserver* observer); |
| 83 |
| 84 // Called when an IPC message is dispatched to the RenderView associated with |
| 85 // this ExtensionHost. |
| 86 void OnMessageDispatched(const std::string& event_name, int message_id); |
| 87 |
| 88 // Called by the ProcessManager when a network request is started by the |
| 89 // extension corresponding to this ExtensionHost. |
| 90 void OnNetworkRequestStarted(uint64 request_id); |
| 91 |
| 92 // Called by the ProcessManager when a previously started network request is |
| 93 // finished. |
| 94 void OnNetworkRequestDone(uint64 request_id); |
| 95 |
| 78 // content::WebContentsObserver | 96 // content::WebContentsObserver |
| 79 bool OnMessageReceived(const IPC::Message& message) override; | 97 bool OnMessageReceived(const IPC::Message& message) override; |
| 80 void RenderViewCreated(content::RenderViewHost* render_view_host) override; | 98 void RenderViewCreated(content::RenderViewHost* render_view_host) override; |
| 81 void RenderViewDeleted(content::RenderViewHost* render_view_host) override; | 99 void RenderViewDeleted(content::RenderViewHost* render_view_host) override; |
| 82 void RenderViewReady() override; | 100 void RenderViewReady() override; |
| 83 void RenderProcessGone(base::TerminationStatus status) override; | 101 void RenderProcessGone(base::TerminationStatus status) override; |
| 84 void DocumentAvailableInMainFrame() override; | 102 void DocumentAvailableInMainFrame() override; |
| 85 void DidStopLoading(content::RenderViewHost* render_view_host) override; | 103 void DidStopLoading(content::RenderViewHost* render_view_host) override; |
| 86 | 104 |
| 87 // content::WebContentsDelegate | 105 // content::WebContentsDelegate |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 void Close(); | 146 void Close(); |
| 129 | 147 |
| 130 private: | 148 private: |
| 131 friend class ProcessCreationQueue; | 149 friend class ProcessCreationQueue; |
| 132 | 150 |
| 133 // Actually create the RenderView for this host. See CreateRenderViewSoon. | 151 // Actually create the RenderView for this host. See CreateRenderViewSoon. |
| 134 void CreateRenderViewNow(); | 152 void CreateRenderViewNow(); |
| 135 | 153 |
| 136 // Message handlers. | 154 // Message handlers. |
| 137 void OnRequest(const ExtensionHostMsg_Request_Params& params); | 155 void OnRequest(const ExtensionHostMsg_Request_Params& params); |
| 138 void OnEventAck(); | 156 void OnEventAck(int message_id); |
| 139 void OnIncrementLazyKeepaliveCount(); | 157 void OnIncrementLazyKeepaliveCount(); |
| 140 void OnDecrementLazyKeepaliveCount(); | 158 void OnDecrementLazyKeepaliveCount(); |
| 141 | 159 |
| 142 // Delegate for functionality that cannot exist in the extensions module. | 160 // Delegate for functionality that cannot exist in the extensions module. |
| 143 scoped_ptr<ExtensionHostDelegate> delegate_; | 161 scoped_ptr<ExtensionHostDelegate> delegate_; |
| 144 | 162 |
| 145 // The extension that we're hosting in this view. | 163 // The extension that we're hosting in this view. |
| 146 const Extension* extension_; | 164 const Extension* extension_; |
| 147 | 165 |
| 148 // Id of extension that we're hosting in this view. | 166 // Id of extension that we're hosting in this view. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 171 content::NotificationRegistrar registrar_; | 189 content::NotificationRegistrar registrar_; |
| 172 | 190 |
| 173 ExtensionFunctionDispatcher extension_function_dispatcher_; | 191 ExtensionFunctionDispatcher extension_function_dispatcher_; |
| 174 | 192 |
| 175 // The type of view being hosted. | 193 // The type of view being hosted. |
| 176 ViewType extension_host_type_; | 194 ViewType extension_host_type_; |
| 177 | 195 |
| 178 // Used to measure how long it's been since the host was created. | 196 // Used to measure how long it's been since the host was created. |
| 179 base::ElapsedTimer since_created_; | 197 base::ElapsedTimer since_created_; |
| 180 | 198 |
| 199 ObserverList<ExtensionHostObserver> observer_list_; |
| 200 |
| 181 DISALLOW_COPY_AND_ASSIGN(ExtensionHost); | 201 DISALLOW_COPY_AND_ASSIGN(ExtensionHost); |
| 182 }; | 202 }; |
| 183 | 203 |
| 184 } // namespace extensions | 204 } // namespace extensions |
| 185 | 205 |
| 186 #endif // EXTENSIONS_BROWSER_EXTENSION_HOST_H_ | 206 #endif // EXTENSIONS_BROWSER_EXTENSION_HOST_H_ |
| OLD | NEW |