Home | History | Annotate | Download | only in runtime
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_EXTENSIONS_API_RUNTIME_RUNTIME_API_H_
      6 #define CHROME_BROWSER_EXTENSIONS_API_RUNTIME_RUNTIME_API_H_
      7 
      8 #include <string>
      9 
     10 #include "chrome/browser/extensions/extension_function.h"
     11 #include "chrome/common/extensions/api/runtime.h"
     12 #include "content/public/browser/notification_observer.h"
     13 #include "content/public/browser/notification_registrar.h"
     14 
     15 class Profile;
     16 
     17 namespace base {
     18 class Version;
     19 }
     20 
     21 namespace extensions {
     22 class Extension;
     23 class ExtensionHost;
     24 
     25 class RuntimeEventRouter {
     26  public:
     27   // Dispatches the onStartup event to all currently-loaded extensions.
     28   static void DispatchOnStartupEvent(Profile* profile,
     29                                      const std::string& extension_id);
     30 
     31   // Dispatches the onInstalled event to the given extension.
     32   static void DispatchOnInstalledEvent(Profile* profile,
     33                                        const std::string& extension_id,
     34                                        const base::Version& old_version,
     35                                        bool chrome_updated);
     36 
     37   // Dispatches the onUpdateAvailable event to the given extension.
     38   static void DispatchOnUpdateAvailableEvent(
     39       Profile* profile,
     40       const std::string& extension_id,
     41       const base::DictionaryValue* manifest);
     42 
     43   // Dispatches the onBrowserUpdateAvailable event to all extensions.
     44   static void DispatchOnBrowserUpdateAvailableEvent(Profile* profile);
     45 
     46   // Dispatches the onRestartRequired event to the given app.
     47   static void DispatchOnRestartRequiredEvent(
     48       Profile* profile,
     49       const std::string& app_id,
     50       api::runtime::OnRestartRequired::Reason reason);
     51 
     52   // Does any work needed at extension uninstall (e.g. load uninstall url).
     53   static void OnExtensionUninstalled(Profile* profile,
     54                                      const std::string& extension_id);
     55 };
     56 
     57 class RuntimeGetBackgroundPageFunction : public AsyncExtensionFunction {
     58  public:
     59   DECLARE_EXTENSION_FUNCTION("runtime.getBackgroundPage",
     60                              RUNTIME_GETBACKGROUNDPAGE)
     61 
     62  protected:
     63   virtual ~RuntimeGetBackgroundPageFunction() {}
     64   virtual bool RunImpl() OVERRIDE;
     65 
     66  private:
     67   void OnPageLoaded(ExtensionHost*);
     68 };
     69 
     70 class RuntimeSetUninstallUrlFunction : public SyncExtensionFunction {
     71  public:
     72   DECLARE_EXTENSION_FUNCTION("runtime.setUninstallUrl",
     73                              RUNTIME_SETUNINSTALLURL)
     74 
     75  protected:
     76   virtual ~RuntimeSetUninstallUrlFunction() {}
     77   virtual bool RunImpl() OVERRIDE;
     78 };
     79 
     80 class RuntimeReloadFunction : public SyncExtensionFunction {
     81  public:
     82   DECLARE_EXTENSION_FUNCTION("runtime.reload", RUNTIME_RELOAD)
     83 
     84  protected:
     85   virtual ~RuntimeReloadFunction() {}
     86   virtual bool RunImpl() OVERRIDE;
     87 };
     88 
     89 class RuntimeRequestUpdateCheckFunction : public AsyncExtensionFunction,
     90                                           public content::NotificationObserver {
     91  public:
     92   DECLARE_EXTENSION_FUNCTION("runtime.requestUpdateCheck",
     93                              RUNTIME_REQUESTUPDATECHECK)
     94 
     95   RuntimeRequestUpdateCheckFunction();
     96  protected:
     97   virtual ~RuntimeRequestUpdateCheckFunction() {}
     98   virtual bool RunImpl() OVERRIDE;
     99 
    100   // Implements content::NotificationObserver interface.
    101   virtual void Observe(int type,
    102                        const content::NotificationSource& source,
    103                        const content::NotificationDetails& details) OVERRIDE;
    104  private:
    105   void CheckComplete();
    106   void ReplyUpdateFound(const std::string& version);
    107 
    108   content::NotificationRegistrar registrar_;
    109   bool did_reply_;
    110 };
    111 
    112 class RuntimeGetPlatformInfoFunction : public SyncExtensionFunction {
    113  public:
    114   DECLARE_EXTENSION_FUNCTION("runtime.getPlatformInfo",
    115                              RUNTIME_GETPLATFORMINFO);
    116  protected:
    117   virtual ~RuntimeGetPlatformInfoFunction() {}
    118   virtual bool RunImpl() OVERRIDE;
    119 };
    120 
    121 class RuntimeGetPackageDirectoryEntryFunction : public SyncExtensionFunction {
    122  public:
    123   DECLARE_EXTENSION_FUNCTION("runtime.getPackageDirectoryEntry",
    124                              RUNTIME_GETPACKAGEDIRECTORYENTRY)
    125 
    126  protected:
    127   virtual ~RuntimeGetPackageDirectoryEntryFunction() {}
    128   virtual bool RunImpl() OVERRIDE;
    129 };
    130 
    131 }  // namespace extensions
    132 
    133 #endif  // CHROME_BROWSER_EXTENSIONS_API_RUNTIME_RUNTIME_API_H_
    134