| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_EXTENSION_FUNCTION_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <list> | 9 #include <list> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/process.h" | 16 #include "base/process.h" |
| 17 #include "chrome/browser/extensions/extension_info_map.h" | 17 #include "chrome/browser/extensions/extension_info_map.h" |
| 18 #include "chrome/common/extensions/extension.h" | 18 #include "chrome/common/extensions/extension.h" |
| 19 #include "content/browser/renderer_host/render_view_host_observer.h" |
| 19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/browser/notification_observer.h" | 21 #include "content/public/browser/notification_observer.h" |
| 21 #include "content/public/browser/notification_registrar.h" | 22 #include "content/public/browser/notification_registrar.h" |
| 22 #include "ipc/ipc_message.h" | 23 #include "ipc/ipc_message.h" |
| 23 | 24 |
| 24 class Browser; | 25 class Browser; |
| 25 class ChromeRenderMessageFilter; | 26 class ChromeRenderMessageFilter; |
| 26 class ExtensionFunction; | 27 class ExtensionFunction; |
| 27 class ExtensionFunctionDispatcher; | 28 class ExtensionFunctionDispatcher; |
| 28 class UIThreadExtensionFunction; | 29 class UIThreadExtensionFunction; |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 }; | 206 }; |
| 206 | 207 |
| 207 // Extension functions that run on the UI thread. Most functions fall into | 208 // Extension functions that run on the UI thread. Most functions fall into |
| 208 // this category. | 209 // this category. |
| 209 class UIThreadExtensionFunction : public ExtensionFunction { | 210 class UIThreadExtensionFunction : public ExtensionFunction { |
| 210 public: | 211 public: |
| 211 UIThreadExtensionFunction(); | 212 UIThreadExtensionFunction(); |
| 212 | 213 |
| 213 virtual UIThreadExtensionFunction* AsUIThreadExtensionFunction() OVERRIDE; | 214 virtual UIThreadExtensionFunction* AsUIThreadExtensionFunction() OVERRIDE; |
| 214 | 215 |
| 216 // Called when a message was received. |
| 217 // Should return true if it processed the message. |
| 218 virtual bool OnMessageReceivedFromRenderView(const IPC::Message& message); |
| 219 |
| 215 // Set the profile which contains the extension that has originated this | 220 // Set the profile which contains the extension that has originated this |
| 216 // function call. | 221 // function call. |
| 217 void set_profile(Profile* profile) { profile_ = profile; } | 222 void set_profile(Profile* profile) { profile_ = profile; } |
| 218 Profile* profile() const { return profile_; } | 223 Profile* profile() const { return profile_; } |
| 219 | 224 |
| 220 void SetRenderViewHost(RenderViewHost* render_view_host); | 225 void SetRenderViewHost(RenderViewHost* render_view_host); |
| 221 RenderViewHost* render_view_host() const { return render_view_host_; } | 226 RenderViewHost* render_view_host() const { return render_view_host_; } |
| 222 | 227 |
| 223 void set_dispatcher( | 228 void set_dispatcher( |
| 224 const base::WeakPtr<ExtensionFunctionDispatcher>& dispatcher) { | 229 const base::WeakPtr<ExtensionFunctionDispatcher>& dispatcher) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 base::WeakPtr<ExtensionFunctionDispatcher> dispatcher_; | 264 base::WeakPtr<ExtensionFunctionDispatcher> dispatcher_; |
| 260 | 265 |
| 261 // The RenderViewHost we will send responses too. | 266 // The RenderViewHost we will send responses too. |
| 262 RenderViewHost* render_view_host_; | 267 RenderViewHost* render_view_host_; |
| 263 | 268 |
| 264 // The Profile of this function's extension. | 269 // The Profile of this function's extension. |
| 265 Profile* profile_; | 270 Profile* profile_; |
| 266 | 271 |
| 267 private: | 272 private: |
| 268 // Helper class to track the lifetime of ExtensionFunction's RenderViewHost | 273 // Helper class to track the lifetime of ExtensionFunction's RenderViewHost |
| 269 // pointer and NULL it out when it dies. We use this separate class (instead | 274 // pointer and NULL it out when it dies. It also allows us to filter IPC |
| 270 // of implementing NotificationObserver on ExtensionFunction) because it is | 275 // messages comming from the RenderViewHost. We use this separate class |
| 271 // common for subclasses of ExtensionFunction to be NotificationObservers, and | 276 // (instead of implementing NotificationObserver on ExtensionFunction) because |
| 272 // it would be an easy error to forget to call the base class's Observe() | 277 // it is/ common for subclasses of ExtensionFunction to be |
| 273 // method. | 278 // NotificationObservers, and it would be an easy error to forget to call the |
| 274 class RenderViewHostTracker : public content::NotificationObserver { | 279 // base class's Observe() method. |
| 280 class RenderViewHostTracker : public content::NotificationObserver, |
| 281 public RenderViewHostObserver { |
| 275 public: | 282 public: |
| 276 explicit RenderViewHostTracker(UIThreadExtensionFunction* function); | 283 RenderViewHostTracker(UIThreadExtensionFunction* function, |
| 284 RenderViewHost* render_view_host); |
| 277 private: | 285 private: |
| 278 virtual void Observe(int type, | 286 virtual void Observe(int type, |
| 279 const content::NotificationSource& source, | 287 const content::NotificationSource& source, |
| 280 const content::NotificationDetails& details) OVERRIDE; | 288 const content::NotificationDetails& details) OVERRIDE; |
| 289 |
| 290 virtual void RenderViewHostDestroyed( |
| 291 RenderViewHost* render_view_host) OVERRIDE; |
| 292 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 293 |
| 281 UIThreadExtensionFunction* function_; | 294 UIThreadExtensionFunction* function_; |
| 282 content::NotificationRegistrar registrar_; | 295 content::NotificationRegistrar registrar_; |
| 296 |
| 297 DISALLOW_COPY_AND_ASSIGN(RenderViewHostTracker); |
| 283 }; | 298 }; |
| 284 | 299 |
| 285 virtual void Destruct() const; | 300 virtual void Destruct() const; |
| 286 | 301 |
| 287 scoped_ptr<RenderViewHostTracker> tracker_; | 302 scoped_ptr<RenderViewHostTracker> tracker_; |
| 288 }; | 303 }; |
| 289 | 304 |
| 290 // Extension functions that run on the IO thread. This type of function avoids | 305 // Extension functions that run on the IO thread. This type of function avoids |
| 291 // a roundtrip to and from the UI thread (because communication with the | 306 // a roundtrip to and from the UI thread (because communication with the |
| 292 // extension process happens on the IO thread). It's intended to be used when | 307 // extension process happens on the IO thread). It's intended to be used when |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 public: | 396 public: |
| 382 SyncIOThreadExtensionFunction(); | 397 SyncIOThreadExtensionFunction(); |
| 383 | 398 |
| 384 virtual void Run() OVERRIDE; | 399 virtual void Run() OVERRIDE; |
| 385 | 400 |
| 386 protected: | 401 protected: |
| 387 virtual ~SyncIOThreadExtensionFunction(); | 402 virtual ~SyncIOThreadExtensionFunction(); |
| 388 }; | 403 }; |
| 389 | 404 |
| 390 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_H_ | 405 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_H_ |
| OLD | NEW |