- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / plugins / plugin_installer.h
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_PLUGINS_PLUGIN_INSTALLER_H_
6 #define CHROME_BROWSER_PLUGINS_PLUGIN_INSTALLER_H_
7
8 #include "base/observer_list.h"
9 #include "base/strings/string16.h"
10 #include "base/version.h"
11 #include "chrome/browser/plugins/plugin_metadata.h"
12 #include "content/public/browser/download_item.h"
13 #include "net/base/net_errors.h"
14 #include "url/gurl.h"
15
16 class PluginInstallerObserver;
17 class WeakPluginInstallerObserver;
18
19 namespace content {
20 class WebContents;
21 struct WebPluginInfo;
22 }
23
24 class PluginInstaller : public content::DownloadItem::Observer {
25  public:
26   enum InstallerState {
27     INSTALLER_STATE_IDLE,
28     INSTALLER_STATE_DOWNLOADING,
29   };
30
31   PluginInstaller();
32   virtual ~PluginInstaller();
33
34   virtual void OnDownloadUpdated(content::DownloadItem* download) OVERRIDE;
35   virtual void OnDownloadDestroyed(content::DownloadItem* download) OVERRIDE;
36
37   void AddObserver(PluginInstallerObserver* observer);
38   void RemoveObserver(PluginInstallerObserver* observer);
39
40   void AddWeakObserver(WeakPluginInstallerObserver* observer);
41   void RemoveWeakObserver(WeakPluginInstallerObserver* observer);
42
43   InstallerState state() const { return state_; }
44
45   // Opens the download URL in a new tab.
46   void OpenDownloadURL(const GURL& plugin_url,
47                        content::WebContents* web_contents);
48
49   // Starts downloading the download URL and opens the downloaded file
50   // when finished.
51   void StartInstalling(const GURL& plugin_url,
52                        content::WebContents* web_contents);
53
54  private:
55   void DownloadStarted(content::DownloadItem* item, net::Error error);
56   void DownloadError(const std::string& msg);
57   void DownloadCancelled();
58
59   InstallerState state_;
60   ObserverList<PluginInstallerObserver> observers_;
61   int strong_observer_count_;
62   ObserverList<WeakPluginInstallerObserver> weak_observers_;
63
64   DISALLOW_COPY_AND_ASSIGN(PluginInstaller);
65 };
66
67 #endif  // CHROME_BROWSER_PLUGINS_PLUGIN_INSTALLER_H_