Commit f99c87d5 authored by bauerb@chromium.org's avatar bauerb@chromium.org

Add PluginInstaller to encapsulate information about a missing plug-in, and...

Add PluginInstaller to encapsulate information about a missing plug-in, and add a separate help URL for each plug-in.


TBR=arv@chromium.org
BUG=62079,102987
TEST=none


Review URL: http://codereview.chromium.org/8664027

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112610 0039d316-1c4b-4281-b951-d872f2087c98
parent aa8f1cc5
...@@ -7,8 +7,10 @@ ...@@ -7,8 +7,10 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/json/json_reader.h" #include "base/json/json_reader.h"
#include "base/message_loop.h" #include "base/message_loop.h"
#include "base/stl_util.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/plugin_installer.h"
#include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/prefs/pref_service.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
...@@ -47,6 +49,7 @@ PluginFinder::PluginFinder() { ...@@ -47,6 +49,7 @@ PluginFinder::PluginFinder() {
} }
PluginFinder::~PluginFinder() { PluginFinder::~PluginFinder() {
STLDeleteValues(&installers_);
} }
void PluginFinder::FindPlugin( void PluginFinder::FindPlugin(
...@@ -81,17 +84,29 @@ void PluginFinder::FindPlugin( ...@@ -81,17 +84,29 @@ void PluginFinder::FindPlugin(
success = (*mime_type_it)->GetAsString(&mime_type_str); success = (*mime_type_it)->GetAsString(&mime_type_str);
DCHECK(success); DCHECK(success);
if (mime_type_str == mime_type) { if (mime_type_str == mime_type) {
std::string url; std::string identifier;
success = plugin->GetString("url", &url); success = plugin->GetString("identifier", &identifier);
DCHECK(success); DCHECK(success);
string16 name; PluginInstaller* installer = installers_[identifier];
success = plugin->GetString("name", &name); if (!installer) {
DCHECK(success); std::string url;
bool display_url = false; success = plugin->GetString("url", &url);
plugin->GetBoolean("displayurl", &display_url); DCHECK(success);
std::string help_url;
plugin->GetString("help_url", &help_url);
string16 name;
success = plugin->GetString("name", &name);
DCHECK(success);
bool display_url = false;
plugin->GetBoolean("displayurl", &display_url);
installer = new PluginInstaller(identifier,
GURL(url), GURL(help_url), name,
display_url);
installers_[identifier] = installer;
}
MessageLoop::current()->PostTask( MessageLoop::current()->PostTask(
FROM_HERE, FROM_HERE,
base::Bind(found_callback, GURL(url), name, display_url)); base::Bind(found_callback, installer));
return; return;
} }
} }
......
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
#define CHROME_BROWSER_PLUGIN_FINDER_H_ #define CHROME_BROWSER_PLUGIN_FINDER_H_
#pragma once #pragma once
#include <map>
#include <string> #include <string>
#include <vector>
#include "base/callback.h" #include "base/callback.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
...@@ -19,16 +19,11 @@ class ListValue; ...@@ -19,16 +19,11 @@ class ListValue;
} }
class GURL; class GURL;
class PluginInstaller;
class PluginFinder { class PluginFinder {
public: public:
// If |display_url| is false, |plugin_url| is the URL of the download page for typedef base::Callback<void(PluginInstaller*)> FindPluginCallback;
// the plug-in, which should be opened in a new tab. If it is true,
// |plugin_url| is the URL of the plug-in installer binary, which can be
// directly downloaded.
typedef base::Callback<void(GURL /* plugin_url */,
string16 /* name */,
bool /* display_url */)> FindPluginCallback;
static PluginFinder* GetInstance(); static PluginFinder* GetInstance();
...@@ -47,6 +42,7 @@ class PluginFinder { ...@@ -47,6 +42,7 @@ class PluginFinder {
~PluginFinder(); ~PluginFinder();
scoped_ptr<base::ListValue> plugin_list_; scoped_ptr<base::ListValue> plugin_list_;
std::map<std::string, PluginInstaller*> installers_;
DISALLOW_COPY_AND_ASSIGN(PluginFinder); DISALLOW_COPY_AND_ASSIGN(PluginFinder);
}; };
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/plugin_installer.h"
PluginInstaller::~PluginInstaller() {
}
PluginInstaller::PluginInstaller(const std::string& identifier,
const GURL& plugin_url,
const GURL& help_url,
const string16& name,
bool url_for_display)
: identifier_(identifier),
plugin_url_(plugin_url),
help_url_(help_url),
name_(name),
url_for_display_(url_for_display) {
}
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_PLUGIN_INSTALLER_H_
#define CHROME_BROWSER_PLUGIN_INSTALLER_H_
#pragma once
#include "base/string16.h"
#include "googleurl/src/gurl.h"
class PluginInstaller {
public:
PluginInstaller(const std::string& identifier,
const GURL& plugin_url,
const GURL& help_url,
const string16& name,
bool url_for_display);
~PluginInstaller();
// Unique identifier for the plug-in. Should be kept in sync with the
// identifier in plugin_list.cc.
const std::string& identifier() const { return identifier_; }
// Human-readable name of the plug-in.
const string16& name() const { return name_; }
// If |url_for_display| is false, |plugin_url| is the URL of the download page
// for the plug-in, which should be opened in a new tab. If it is true,
// |plugin_url| is the URL of the plug-in installer binary, which can be
// directly downloaded.
bool url_for_display() const { return url_for_display_; }
const GURL& plugin_url() const { return plugin_url_; }
// URL to open when the user clicks on the "Problems installing?" link.
const GURL& help_url() const { return help_url_; }
private:
std::string identifier_;
GURL plugin_url_;
GURL help_url_;
string16 name_;
bool url_for_display_;
DISALLOW_COPY_AND_ASSIGN(PluginInstaller);
};
#endif // CHROME_BROWSER_PLUGIN_INSTALLER_H_
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "chrome/browser/google/google_util.h" #include "chrome/browser/google/google_util.h"
#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/infobars/infobar_tab_helper.h"
#include "chrome/browser/plugin_finder.h" #include "chrome/browser/plugin_finder.h"
#include "chrome/browser/plugin_installer.h"
#include "chrome/browser/plugin_installer_infobar_delegate.h" #include "chrome/browser/plugin_installer_infobar_delegate.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/tab_contents/confirm_infobar_delegate.h" #include "chrome/browser/tab_contents/confirm_infobar_delegate.h"
...@@ -19,6 +20,7 @@ ...@@ -19,6 +20,7 @@
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
#include "content/browser/renderer_host/render_view_host.h" #include "content/browser/renderer_host/render_view_host.h"
#include "content/browser/tab_contents/tab_contents.h" #include "content/browser/tab_contents/tab_contents.h"
#include "content/browser/tab_contents/tab_contents_delegate.h"
#include "content/browser/user_metrics.h" #include "content/browser/user_metrics.h"
#include "grit/generated_resources.h" #include "grit/generated_resources.h"
#include "grit/theme_resources_standard.h" #include "grit/theme_resources_standard.h"
...@@ -330,17 +332,15 @@ void PluginObserver::OnFindMissingPlugin(int placeholder_id, ...@@ -330,17 +332,15 @@ void PluginObserver::OnFindMissingPlugin(int placeholder_id,
void PluginObserver::FoundMissingPlugin(int placeholder_id, void PluginObserver::FoundMissingPlugin(int placeholder_id,
const std::string& mime_type, const std::string& mime_type,
const GURL& url, PluginInstaller* installer) {
const string16& name, Send(new ChromeViewMsg_FoundMissingPlugin(placeholder_id, installer->name()));
bool display_url) {
Send(new ChromeViewMsg_FoundMissingPlugin(placeholder_id, name));
InfoBarTabHelper* infobar_helper = tab_contents_->infobar_tab_helper(); InfoBarTabHelper* infobar_helper = tab_contents_->infobar_tab_helper();
infobar_helper->AddInfoBar(new PluginInstallerInfoBarDelegate( infobar_helper->AddInfoBar(new PluginInstallerInfoBarDelegate(
infobar_helper, infobar_helper,
name, installer->name(),
GURL(), // TODO(bauerb): Get URL from JSON file. installer->help_url(),
base::Bind(&PluginObserver::InstallMissingPlugin, base::Bind(&PluginObserver::InstallMissingPlugin,
weak_ptr_factory_.GetWeakPtr(), url, display_url))); weak_ptr_factory_.GetWeakPtr(), installer)));
} }
void PluginObserver::DidNotFindMissingPlugin(int placeholder_id, void PluginObserver::DidNotFindMissingPlugin(int placeholder_id,
...@@ -348,11 +348,10 @@ void PluginObserver::DidNotFindMissingPlugin(int placeholder_id, ...@@ -348,11 +348,10 @@ void PluginObserver::DidNotFindMissingPlugin(int placeholder_id,
Send(new ChromeViewMsg_DidNotFindMissingPlugin(placeholder_id)); Send(new ChromeViewMsg_DidNotFindMissingPlugin(placeholder_id));
} }
void PluginObserver::InstallMissingPlugin(const GURL& url, void PluginObserver::InstallMissingPlugin(PluginInstaller* installer) {
bool display_url) { if (installer->url_for_display()) {
if (display_url) { tab_contents()->OpenURL(installer->plugin_url(), tab_contents()->GetURL(),
tab_contents()->OpenURL(url, tab_contents()->GetURL(), NEW_FOREGROUND_TAB, NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_TYPED);
content::PAGE_TRANSITION_TYPED);
} else { } else {
NOTIMPLEMENTED(); NOTIMPLEMENTED();
} }
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
class GURL; class GURL;
class InfoBarDelegate; class InfoBarDelegate;
class PluginInstaller;
class TabContentsWrapper; class TabContentsWrapper;
class PluginObserver : public TabContentsObserver { class PluginObserver : public TabContentsObserver {
...@@ -27,17 +28,14 @@ class PluginObserver : public TabContentsObserver { ...@@ -27,17 +28,14 @@ class PluginObserver : public TabContentsObserver {
void FoundMissingPlugin(int placeholder_id, void FoundMissingPlugin(int placeholder_id,
const std::string& mime_type, const std::string& mime_type,
const GURL& url, PluginInstaller* installer);
const string16& name,
bool display_url);
void DidNotFindMissingPlugin(int placeholder_id, void DidNotFindMissingPlugin(int placeholder_id,
const std::string& mime_type); const std::string& mime_type);
void InstallMissingPlugin(const GURL& url, bool display_url); void InstallMissingPlugin(PluginInstaller* installer);
base::WeakPtrFactory<PluginObserver> weak_ptr_factory_; base::WeakPtrFactory<PluginObserver> weak_ptr_factory_;
TabContentsWrapper* tab_contents_; TabContentsWrapper* tab_contents_;
scoped_ptr<InfoBarDelegate> plugin_installer_; // Lazily created.
DISALLOW_COPY_AND_ASSIGN(PluginObserver); DISALLOW_COPY_AND_ASSIGN(PluginObserver);
}; };
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
], ],
"lang": "en-US", "lang": "en-US",
"name": "Java(TM)", "name": "Java(TM)",
"identifier": "java-runtime-environment",
"url": "http://java.com/en/download/apple_manual.jsp", "url": "http://java.com/en/download/apple_manual.jsp",
"displayurl": true "displayurl": true
}, },
...@@ -48,6 +49,7 @@ ...@@ -48,6 +49,7 @@
], ],
"lang": "en-US", "lang": "en-US",
"name": "RealPlayer", "name": "RealPlayer",
"identifier": "realplayer",
"url": "http://www.real.com/realplayer/download", "url": "http://www.real.com/realplayer/download",
"displayurl": true "displayurl": true
}, },
...@@ -58,6 +60,7 @@ ...@@ -58,6 +60,7 @@
], ],
"lang": "en-US", "lang": "en-US",
"name": "Adobe Flash Player", "name": "Adobe Flash Player",
"identifier": "adobe-flash-player",
"url": "http://get.adobe.com/flashplayer/", "url": "http://get.adobe.com/flashplayer/",
"displayurl": true "displayurl": true
}, },
...@@ -67,6 +70,7 @@ ...@@ -67,6 +70,7 @@
], ],
"lang": "en-US", "lang": "en-US",
"name": "Adobe Shockwave Player", "name": "Adobe Shockwave Player",
"identifier": "shockwave",
"url": "http://www.adobe.com/shockwave/download/", "url": "http://www.adobe.com/shockwave/download/",
"displayurl": true "displayurl": true
}, },
...@@ -81,6 +85,7 @@ ...@@ -81,6 +85,7 @@
], ],
"lang": "en-US", "lang": "en-US",
"name": "Adobe Reader", "name": "Adobe Reader",
"identifier": "adobe-reader",
"url": "http://get.adobe.com/reader/", "url": "http://get.adobe.com/reader/",
"displayurl": true "displayurl": true
}, },
...@@ -138,6 +143,7 @@ ...@@ -138,6 +143,7 @@
], ],
"lang": "en-US", "lang": "en-US",
"name": "QuickTime Player", "name": "QuickTime Player",
"identifier": "apple-quicktime",
"url": "http://www.apple.com/quicktime/download/", "url": "http://www.apple.com/quicktime/download/",
"displayurl": true "displayurl": true
}, },
...@@ -156,6 +162,7 @@ ...@@ -156,6 +162,7 @@
], ],
"lang": "en-US", "lang": "en-US",
"name": "Flip4Mac", "name": "Flip4Mac",
"identifier": "flip4mac",
"url": "http://www.telestream.net/flip4mac-wmv/overview.htm", "url": "http://www.telestream.net/flip4mac-wmv/overview.htm",
"displayurl": true "displayurl": true
}, },
...@@ -166,6 +173,7 @@ ...@@ -166,6 +173,7 @@
], ],
"lang": "en-US", "lang": "en-US",
"name": "DivX Web Player", "name": "DivX Web Player",
"identifier": "divx-player",
"url": "http://www.divx.com/en/downloads/divx/mac", "url": "http://www.divx.com/en/downloads/divx/mac",
"displayurl": true "displayurl": true
} }
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
], ],
"lang": "en-US", "lang": "en-US",
"name": "Java(TM)", "name": "Java(TM)",
"identifier": "java-runtime-environment",
"url": "http://java.com/download", "url": "http://java.com/download",
"displayurl": true "displayurl": true
}, },
...@@ -48,6 +49,7 @@ ...@@ -48,6 +49,7 @@
], ],
"lang": "en-US", "lang": "en-US",
"name": "RealPlayer", "name": "RealPlayer",
"identifier": "realplayer",
"url": "http://forms.real.com/real/realone/download.html?type=rpsp_us" "url": "http://forms.real.com/real/realone/download.html?type=rpsp_us"
}, },
{ {
...@@ -57,6 +59,7 @@ ...@@ -57,6 +59,7 @@
], ],
"lang": "en-US", "lang": "en-US",
"name": "Adobe Flash Player", "name": "Adobe Flash Player",
"identifier": "adobe-flash-player",
"url": "http://fpdownload.adobe.com/get/flashplayer/current/install_flash_player.exe" "url": "http://fpdownload.adobe.com/get/flashplayer/current/install_flash_player.exe"
}, },
{ {
...@@ -65,6 +68,7 @@ ...@@ -65,6 +68,7 @@
], ],
"lang": "en-US", "lang": "en-US",
"name": "Adobe Shockwave Player", "name": "Adobe Shockwave Player",
"identifier": "shockwave",
"url": "http://fpdownload.macromedia.com/get/shockwave/default/english/win95nt/latest/Shockwave_Installer_Slim.exe" "url": "http://fpdownload.macromedia.com/get/shockwave/default/english/win95nt/latest/Shockwave_Installer_Slim.exe"
}, },
{ {
...@@ -78,6 +82,7 @@ ...@@ -78,6 +82,7 @@
], ],
"lang": "en-US", "lang": "en-US",
"name": "Adobe Reader", "name": "Adobe Reader",
"identifier": "adobe-reader",
"url": "http://ardownload.adobe.com/pub/adobe/reader/win/9.x/9.1/enu/AdbeRdr910_en_US.exe" "url": "http://ardownload.adobe.com/pub/adobe/reader/win/9.x/9.1/enu/AdbeRdr910_en_US.exe"
}, },
{ {
...@@ -134,6 +139,7 @@ ...@@ -134,6 +139,7 @@
], ],
"lang": "en-US", "lang": "en-US",
"name": "QuickTime Player", "name": "QuickTime Player",
"identifier": "apple-quicktime",
"url": "http://appldnld.apple.com.edgesuite.net/content.info.apple.com/QuickTime/061-6118.20090601.Pq3V9/QuickTimeInstaller.exe" "url": "http://appldnld.apple.com.edgesuite.net/content.info.apple.com/QuickTime/061-6118.20090601.Pq3V9/QuickTimeInstaller.exe"
}, },
{ {
...@@ -151,6 +157,7 @@ ...@@ -151,6 +157,7 @@
], ],
"lang": "en-US", "lang": "en-US",
"name": "Windows Media Player", "name": "Windows Media Player",
"identifier": "windows-media-player",
"url": "http://port25.technet.com/videos/downloads/wmpfirefoxplugin.exe" "url": "http://port25.technet.com/videos/downloads/wmpfirefoxplugin.exe"
}, },
{ {
...@@ -160,6 +167,7 @@ ...@@ -160,6 +167,7 @@
], ],
"lang": "en-US", "lang": "en-US",
"name": "DivX Web Player", "name": "DivX Web Player",
"identifier": "divx-player",
"url": "http://download.divx.com/player/divxdotcom/DivXWebPlayerInstaller.exe" "url": "http://download.divx.com/player/divxdotcom/DivXWebPlayerInstaller.exe"
} }
] ]
......
...@@ -1731,6 +1731,8 @@ ...@@ -1731,6 +1731,8 @@
'browser/plugin_download_helper.h', 'browser/plugin_download_helper.h',
'browser/plugin_finder.cc', 'browser/plugin_finder.cc',
'browser/plugin_finder.h', 'browser/plugin_finder.h',
'browser/plugin_installer.cc',
'browser/plugin_installer.h',
'browser/plugin_installer_infobar_delegate.cc', 'browser/plugin_installer_infobar_delegate.cc',
'browser/plugin_installer_infobar_delegate.h', 'browser/plugin_installer_infobar_delegate.h',
'browser/plugin_observer.cc', 'browser/plugin_observer.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment