diff options
author | bauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-08 21:52:28 +0000 |
---|---|---|
committer | bauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-08 21:52:28 +0000 |
commit | 37be0496a06a27af6158078ab4f8954ebdf53d9a (patch) | |
tree | 627c6bef11069c6c1549a4f4674abbfc8380db20 | |
parent | 6e1a25d163b44a7c1f09ad36ac378655a025738c (diff) | |
download | chromium_src-37be0496a06a27af6158078ab4f8954ebdf53d9a.zip chromium_src-37be0496a06a27af6158078ab4f8954ebdf53d9a.tar.gz chromium_src-37be0496a06a27af6158078ab4f8954ebdf53d9a.tar.bz2 |
Use PluginInstaller to update outdated plug-ins.
TBR=arv@chromium.org
BUG=92796
TEST=TBD
Review URL: http://codereview.chromium.org/9107038
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@121057 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/app/generated_resources.grd | 6 | ||||
-rw-r--r-- | chrome/browser/browser_resources.grd | 3 | ||||
-rw-r--r-- | chrome/browser/plugin_finder.cc | 138 | ||||
-rw-r--r-- | chrome/browser/plugin_finder.h | 17 | ||||
-rw-r--r-- | chrome/browser/plugin_infobar_delegates.cc | 387 | ||||
-rw-r--r-- | chrome/browser/plugin_infobar_delegates.h | 164 | ||||
-rw-r--r-- | chrome/browser/plugin_installer.cc | 14 | ||||
-rw-r--r-- | chrome/browser/plugin_installer.h | 15 | ||||
-rw-r--r-- | chrome/browser/plugin_installer_infobar_delegate.cc | 128 | ||||
-rw-r--r-- | chrome/browser/plugin_installer_infobar_delegate.h | 63 | ||||
-rw-r--r-- | chrome/browser/plugin_observer.cc | 314 | ||||
-rw-r--r-- | chrome/browser/plugin_observer.h | 16 | ||||
-rw-r--r-- | chrome/browser/resources/plugins_linux.json | 66 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 6 | ||||
-rw-r--r-- | chrome/common/render_messages.h | 4 | ||||
-rw-r--r-- | chrome/renderer/chrome_content_renderer_client.cc | 8 | ||||
-rw-r--r-- | chrome/renderer/plugins/plugin_placeholder.cc | 5 |
17 files changed, 805 insertions, 549 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index 1a9170b..d2889d9 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -5312,6 +5312,9 @@ Because search results are requested even while you're typing your query, your d <message name="IDS_PLUGIN_INSTALLING" desc="The placeholder text when installing a missing plug-in."> After installing the plug-in, reload the page. </message> + <message name="IDS_PLUGIN_UPDATING" desc="The placeholder text when updating an out-of-date plug-in."> + After updating the plug-in, reload the page. + </message> <message name="IDS_PLUGIN_FOUND" desc="The placeholder text for a known plug-in that is not installed."> The <ph name="PLUGIN_NAME">$1<ex>Quicktime</ex></ph> plug-in is required to display this content. </message> @@ -9570,6 +9573,9 @@ experiment id: "<ph name="EXPERIMENT_ID">$5<ex>ar1</ex></ph>" <message name="IDS_PLUGININSTALLER_PROBLEMSINSTALLING" desc="Infobar text for link to help center"> Problems installing? </message> + <message name="IDS_PLUGININSTALLER_PROBLEMSUPDATING" desc="Infobar text for link to help center"> + Problems updating? + </message> <message name="IDS_PLUGIN_OUTDATED_PROMPT" desc="Info Bar message when an outdated plugin was disabled"> The <ph name="PLUGIN_NAME">$1<ex>Flash</ex></ph> plug-in was blocked because it is out of date. </message> diff --git a/chrome/browser/browser_resources.grd b/chrome/browser/browser_resources.grd index 4084b92..7571a7d 100644 --- a/chrome/browser/browser_resources.grd +++ b/chrome/browser/browser_resources.grd @@ -98,6 +98,9 @@ <if expr="is_macosx"> <include name="IDR_PLUGIN_DB_JSON" file="resources\plugins_mac.json" type="BINDATA" /> </if> + <if expr="is_linux"> + <include name="IDR_PLUGIN_DB_JSON" file="resources\plugins_linux.json" type="BINDATA" /> + </if> <include name="IDR_POLICY_CSS" file="resources\policy.css" type="BINDATA"/> <include name="IDR_POLICY_HTML" file="resources\policy.html" flattenhtml="true" allowexternalscript="true" type="BINDATA"/> <include name="IDR_POLICY_JS" file="resources\policy.js" type="BINDATA"/> diff --git a/chrome/browser/plugin_finder.cc b/chrome/browser/plugin_finder.cc index f33253b..2e90b54 100644 --- a/chrome/browser/plugin_finder.cc +++ b/chrome/browser/plugin_finder.cc @@ -36,7 +36,7 @@ scoped_ptr<base::ListValue> PluginFinder::LoadPluginList() { } base::ListValue* PluginFinder::LoadPluginListInternal() { -#if defined(OS_WIN) || defined(OS_MACOSX) +#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) base::StringPiece json_resource( ResourceBundle::GetSharedInstance().GetRawDataResource( IDR_PLUGIN_DB_JSON)); @@ -70,60 +70,100 @@ PluginFinder::~PluginFinder() { void PluginFinder::FindPlugin( const std::string& mime_type, const std::string& language, - const FindPluginCallback& found_callback, - const base::Closure& not_found_callback) { - if (g_browser_process->local_state()->GetBoolean( - prefs::kDisablePluginFinder)) { - MessageLoop::current()->PostTask(FROM_HERE, not_found_callback); - return; - } - for (ListValue::const_iterator plugin_it = plugin_list_->begin(); - plugin_it != plugin_list_->end(); ++plugin_it) { - const base::DictionaryValue* plugin = NULL; - if (!(*plugin_it)->GetAsDictionary(&plugin)) { - NOTREACHED(); - continue; + const FindPluginCallback& callback) { + PluginInstaller* installer = FindPluginInternal(mime_type, language); + MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, installer)); +} + +void PluginFinder::FindPluginWithIdentifier( + const std::string& identifier, + const FindPluginCallback& found_callback) { + PluginInstaller* installer = NULL; + std::map<std::string, PluginInstaller*>::const_iterator it = + installers_.find(identifier); + if (it != installers_.end()) { + installer = it->second; + } else { + for (ListValue::const_iterator plugin_it = plugin_list_->begin(); + plugin_it != plugin_list_->end(); ++plugin_it) { + const base::DictionaryValue* plugin = NULL; + if (!(*plugin_it)->GetAsDictionary(&plugin)) { + NOTREACHED(); + continue; + } + std::string id; + bool success = plugin->GetString("identifier", &id); + DCHECK(success); + if (id == identifier) { + installer = CreateInstaller(identifier, plugin); + break; + } } - std::string language_str; - bool success = plugin->GetString("lang", &language_str); - DCHECK(success); - if (language_str != language) - continue; - ListValue* mime_types = NULL; - success = plugin->GetList("mime_types", &mime_types); - DCHECK(success); - for (ListValue::const_iterator mime_type_it = mime_types->begin(); - mime_type_it != mime_types->end(); ++mime_type_it) { - std::string mime_type_str; - success = (*mime_type_it)->GetAsString(&mime_type_str); + } + MessageLoop::current()->PostTask(FROM_HERE, + base::Bind(found_callback, installer)); +} + +PluginInstaller* PluginFinder::CreateInstaller( + const std::string& identifier, + const base::DictionaryValue* plugin_dict) { + DCHECK(!installers_[identifier]); + std::string url; + bool success = plugin_dict->GetString("url", &url); + DCHECK(success); + std::string help_url; + plugin_dict->GetString("help_url", &help_url); + string16 name; + success = plugin_dict->GetString("name", &name); + DCHECK(success); + bool display_url = false; + plugin_dict->GetBoolean("displayurl", &display_url); + PluginInstaller*installer = new PluginInstaller(identifier, + GURL(url), + GURL(help_url), + name, + display_url); + installers_[identifier] = installer; + return installer; +} + +PluginInstaller* PluginFinder::FindPluginInternal( + const std::string& mime_type, + const std::string& language) { + if (!g_browser_process->local_state()->GetBoolean( + prefs::kDisablePluginFinder)) { + for (ListValue::const_iterator plugin_it = plugin_list_->begin(); + plugin_it != plugin_list_->end(); ++plugin_it) { + const base::DictionaryValue* plugin = NULL; + if (!(*plugin_it)->GetAsDictionary(&plugin)) { + NOTREACHED(); + continue; + } + std::string language_str; + bool success = plugin->GetString("lang", &language_str); DCHECK(success); - if (mime_type_str == mime_type) { - std::string identifier; - success = plugin->GetString("identifier", &identifier); + if (language_str != language) + continue; + ListValue* mime_types = NULL; + success = plugin->GetList("mime_types", &mime_types); + DCHECK(success); + for (ListValue::const_iterator mime_type_it = mime_types->begin(); + mime_type_it != mime_types->end(); ++mime_type_it) { + std::string mime_type_str; + success = (*mime_type_it)->GetAsString(&mime_type_str); DCHECK(success); - PluginInstaller* installer = installers_[identifier]; - if (!installer) { - std::string url; - success = plugin->GetString("url", &url); - DCHECK(success); - std::string help_url; - plugin->GetString("help_url", &help_url); - string16 name; - success = plugin->GetString("name", &name); + if (mime_type_str == mime_type) { + std::string identifier; + bool success = plugin->GetString("identifier", &identifier); 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; + std::map<std::string, PluginInstaller*>::const_iterator it = + installers_.find(identifier); + if (it != installers_.end()) + return it->second; + return CreateInstaller(identifier, plugin); } - MessageLoop::current()->PostTask( - FROM_HERE, - base::Bind(found_callback, installer)); - return; } } } - MessageLoop::current()->PostTask(FROM_HERE, not_found_callback); + return NULL; } diff --git a/chrome/browser/plugin_finder.h b/chrome/browser/plugin_finder.h index a0e88b7..2b1bd49 100644 --- a/chrome/browser/plugin_finder.h +++ b/chrome/browser/plugin_finder.h @@ -15,6 +15,7 @@ #include "base/string16.h" namespace base { +class DictionaryValue; class ListValue; } @@ -32,12 +33,15 @@ class PluginFinder { static scoped_ptr<base::ListValue> LoadPluginList(); // Finds a plug-in for the given MIME type and language (specified as an IETF - // language tag, i.e. en-US) and calls one of the two passed in callbacks, - // depending on whether a plug-in is found. + // language tag, i.e. en-US) and calls the callback with the PluginInstaller + // for the plug-in, or NULL if no plug-in is found. void FindPlugin(const std::string& mime_type, const std::string& language, - const FindPluginCallback& found_callback, - const base::Closure& not_found_callback); + const FindPluginCallback& callback); + + // Finds the plug-in with the given identifier and calls the callback. + void FindPluginWithIdentifier(const std::string& identifier, + const FindPluginCallback& callback); private: friend struct DefaultSingletonTraits<PluginFinder>; @@ -47,6 +51,11 @@ class PluginFinder { static base::ListValue* LoadPluginListInternal(); + PluginInstaller* CreateInstaller(const std::string& identifier, + const base::DictionaryValue* plugin_dict); + PluginInstaller* FindPluginInternal(const std::string& mime_type, + const std::string& language); + scoped_ptr<base::ListValue> plugin_list_; std::map<std::string, PluginInstaller*> installers_; diff --git a/chrome/browser/plugin_infobar_delegates.cc b/chrome/browser/plugin_infobar_delegates.cc new file mode 100644 index 0000000..9d0b0ef2 --- /dev/null +++ b/chrome/browser/plugin_infobar_delegates.cc @@ -0,0 +1,387 @@ +// Copyright (c) 2012 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_infobar_delegates.h" + +#include "base/utf_string_conversions.h" +#include "chrome/browser/content_settings/host_content_settings_map.h" +#include "chrome/browser/google/google_util.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" +#include "chrome/browser/plugin_installer.h" +#include "chrome/browser/plugin_observer.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" +#include "chrome/common/render_messages.h" +#include "chrome/common/url_constants.h" +#include "content/browser/renderer_host/render_view_host.h" +#include "content/public/browser/user_metrics.h" +#include "content/public/browser/web_contents.h" +#include "grit/generated_resources.h" +#include "grit/locale_settings.h" +#include "grit/theme_resources_standard.h" +#include "ui/base/l10n/l10n_util.h" +#include "ui/base/resource/resource_bundle.h" +#include "webkit/plugins/npapi/plugin_group.h" + +using content::OpenURLParams; +using content::Referrer; +using content::UserMetricsAction; + +PluginInfoBarDelegate::PluginInfoBarDelegate(InfoBarTabHelper* infobar_helper, + const string16& name) + : ConfirmInfoBarDelegate(infobar_helper), + name_(name) { +} + +PluginInfoBarDelegate::~PluginInfoBarDelegate() { +} + +bool PluginInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) { + OpenURLParams params( + GURL(GetLearnMoreURL()), Referrer(), + (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, + content::PAGE_TRANSITION_LINK, + false); + owner()->web_contents()->OpenURL(params); + return false; +} + +void PluginInfoBarDelegate::LoadBlockedPlugins() { + owner()->Send(new ChromeViewMsg_LoadBlockedPlugins(owner()->routing_id())); +} + +gfx::Image* PluginInfoBarDelegate::GetIcon() const { + return &ResourceBundle::GetSharedInstance().GetNativeImageNamed( + IDR_INFOBAR_PLUGIN_INSTALL); +} + +string16 PluginInfoBarDelegate::GetLinkText() const { + return l10n_util::GetStringUTF16(IDS_LEARN_MORE); +} + +// UnauthorizedPluginInfoBarDelegate ------------------------------------------ + +UnauthorizedPluginInfoBarDelegate::UnauthorizedPluginInfoBarDelegate( + InfoBarTabHelper* infobar_helper, + HostContentSettingsMap* content_settings, + const string16& utf16_name) + : PluginInfoBarDelegate(infobar_helper, utf16_name), + content_settings_(content_settings) { + content::RecordAction(UserMetricsAction("BlockedPluginInfobar.Shown")); + std::string name = UTF16ToUTF8(utf16_name); + if (name == webkit::npapi::PluginGroup::kJavaGroupName) + content::RecordAction( + UserMetricsAction("BlockedPluginInfobar.Shown.Java")); + else if (name == webkit::npapi::PluginGroup::kQuickTimeGroupName) + content::RecordAction( + UserMetricsAction("BlockedPluginInfobar.Shown.QuickTime")); + else if (name == webkit::npapi::PluginGroup::kShockwaveGroupName) + content::RecordAction( + UserMetricsAction("BlockedPluginInfobar.Shown.Shockwave")); + else if (name == webkit::npapi::PluginGroup::kRealPlayerGroupName) + content::RecordAction( + UserMetricsAction("BlockedPluginInfobar.Shown.RealPlayer")); + else if (name == webkit::npapi::PluginGroup::kWindowsMediaPlayerGroupName) + content::RecordAction( + UserMetricsAction("BlockedPluginInfobar.Shown.WindowsMediaPlayer")); +} + +UnauthorizedPluginInfoBarDelegate::~UnauthorizedPluginInfoBarDelegate() { + content::RecordAction(UserMetricsAction("BlockedPluginInfobar.Closed")); +} + +std::string UnauthorizedPluginInfoBarDelegate::GetLearnMoreURL() const { + return chrome::kBlockedPluginLearnMoreURL; +} + +string16 UnauthorizedPluginInfoBarDelegate::GetMessageText() const { + return l10n_util::GetStringFUTF16(IDS_PLUGIN_NOT_AUTHORIZED, name_); +} + +string16 UnauthorizedPluginInfoBarDelegate::GetButtonLabel( + InfoBarButton button) const { + return l10n_util::GetStringUTF16((button == BUTTON_OK) ? + IDS_PLUGIN_ENABLE_TEMPORARILY : IDS_PLUGIN_ENABLE_ALWAYS); +} + +bool UnauthorizedPluginInfoBarDelegate::Accept() { + content::RecordAction( + UserMetricsAction("BlockedPluginInfobar.AllowThisTime")); + LoadBlockedPlugins(); + return true; +} + +bool UnauthorizedPluginInfoBarDelegate::Cancel() { + content::RecordAction( + UserMetricsAction("BlockedPluginInfobar.AlwaysAllow")); + content_settings_->AddExceptionForURL(owner()->web_contents()->GetURL(), + owner()->web_contents()->GetURL(), + CONTENT_SETTINGS_TYPE_PLUGINS, + std::string(), + CONTENT_SETTING_ALLOW); + LoadBlockedPlugins(); + return true; +} + +void UnauthorizedPluginInfoBarDelegate::InfoBarDismissed() { + content::RecordAction( + UserMetricsAction("BlockedPluginInfobar.Dismissed")); +} + +bool UnauthorizedPluginInfoBarDelegate::LinkClicked( + WindowOpenDisposition disposition) { + content::RecordAction( + UserMetricsAction("BlockedPluginInfobar.LearnMore")); + return PluginInfoBarDelegate::LinkClicked(disposition); +} + +// OutdatedPluginInfoBarDelegate ---------------------------------------------- + +InfoBarDelegate* OutdatedPluginInfoBarDelegate::Create( + PluginObserver* observer, + PluginInstaller* installer) { + string16 message; + switch (installer->state()) { + case PluginInstaller::kStateIdle: + message = l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED_PROMPT, + installer->name()); + break; + case PluginInstaller::kStateDownloading: + message = l10n_util::GetStringUTF16(IDS_PLUGIN_DOWNLOADING); + break; + } + return new OutdatedPluginInfoBarDelegate( + observer, installer, message); +} + +OutdatedPluginInfoBarDelegate::OutdatedPluginInfoBarDelegate( + PluginObserver* observer, + PluginInstaller* installer, + const string16& message) + : PluginInfoBarDelegate( + observer->tab_contents_wrapper()->infobar_tab_helper(), + installer->name()), + WeakPluginInstallerObserver(installer), + observer_(observer), + message_(message) { + content::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Shown")); + std::string name = UTF16ToUTF8(installer->name()); + if (name == webkit::npapi::PluginGroup::kJavaGroupName) + content::RecordAction( + UserMetricsAction("OutdatedPluginInfobar.Shown.Java")); + else if (name == webkit::npapi::PluginGroup::kQuickTimeGroupName) + content::RecordAction( + UserMetricsAction("OutdatedPluginInfobar.Shown.QuickTime")); + else if (name == webkit::npapi::PluginGroup::kShockwaveGroupName) + content::RecordAction( + UserMetricsAction("OutdatedPluginInfobar.Shown.Shockwave")); + else if (name == webkit::npapi::PluginGroup::kRealPlayerGroupName) + content::RecordAction( + UserMetricsAction("OutdatedPluginInfobar.Shown.RealPlayer")); + else if (name == webkit::npapi::PluginGroup::kSilverlightGroupName) + content::RecordAction( + UserMetricsAction("OutdatedPluginInfobar.Shown.Silverlight")); + else if (name == webkit::npapi::PluginGroup::kAdobeReaderGroupName) + content::RecordAction( + UserMetricsAction("OutdatedPluginInfobar.Shown.Reader")); +} + +OutdatedPluginInfoBarDelegate::~OutdatedPluginInfoBarDelegate() { + content::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Closed")); +} + +std::string OutdatedPluginInfoBarDelegate::GetLearnMoreURL() const { + return chrome::kOutdatedPluginLearnMoreURL; +} + +string16 OutdatedPluginInfoBarDelegate::GetMessageText() const { + return message_; +} + +string16 OutdatedPluginInfoBarDelegate::GetButtonLabel( + InfoBarButton button) const { + return l10n_util::GetStringUTF16((button == BUTTON_OK) ? + IDS_PLUGIN_UPDATE : IDS_PLUGIN_ENABLE_TEMPORARILY); +} + +bool OutdatedPluginInfoBarDelegate::Accept() { + content::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Update")); + if (installer()->state() != PluginInstaller::kStateIdle) { + NOTREACHED(); + return false; + } + + content::WebContents* web_contents = owner()->web_contents(); + if (installer()->url_for_display()) { + installer()->OpenDownloadURL(web_contents); + } else { + installer()->StartInstalling(web_contents); + } + return false; +} + +bool OutdatedPluginInfoBarDelegate::Cancel() { + content::RecordAction( + UserMetricsAction("OutdatedPluginInfobar.AllowThisTime")); + LoadBlockedPlugins(); + return true; +} + +void OutdatedPluginInfoBarDelegate::InfoBarDismissed() { + content::RecordAction( + UserMetricsAction("OutdatedPluginInfobar.Dismissed")); +} + +bool OutdatedPluginInfoBarDelegate::LinkClicked( + WindowOpenDisposition disposition) { + content::RecordAction( + UserMetricsAction("OutdatedPluginInfobar.LearnMore")); + return PluginInfoBarDelegate::LinkClicked(disposition); +} + +void OutdatedPluginInfoBarDelegate::DidStartDownload() { + ReplaceWithInfoBar(l10n_util::GetStringUTF16(IDS_PLUGIN_DOWNLOADING)); +} + +void OutdatedPluginInfoBarDelegate::DidFinishDownload() { + ReplaceWithInfoBar(l10n_util::GetStringUTF16(IDS_PLUGIN_UPDATING)); +} + +void OutdatedPluginInfoBarDelegate::DownloadError(const std::string& message) { + ReplaceWithInfoBar( + l10n_util::GetStringUTF16(IDS_PLUGIN_DOWNLOAD_ERROR_SHORT)); +} + +void OutdatedPluginInfoBarDelegate::OnlyWeakObserversLeft() { + if (owner()) + owner()->RemoveInfoBar(this); +} + +void OutdatedPluginInfoBarDelegate::ReplaceWithInfoBar( + const string16& message) { + // Return early if the message doesn't change. This is important in case the + // PluginInstaller is still iterating over its observers (otherwise we would + // keep replacing infobar delegates infinitely). + if (message_ == message) + return; + if (!owner()) + return; + InfoBarDelegate* delegate = new PluginInstallerInfoBarDelegate( + owner(), installer(), base::Closure(), false, message); + owner()->ReplaceInfoBar(this, delegate); +} + +// PluginInstallerInfoBarDelegate --------------------------------------------- + +PluginInstallerInfoBarDelegate::PluginInstallerInfoBarDelegate( + InfoBarTabHelper* infobar_helper, + PluginInstaller* installer, + const base::Closure& callback, + bool new_install, + const string16& message) + : ConfirmInfoBarDelegate(infobar_helper), + WeakPluginInstallerObserver(installer), + callback_(callback), + new_install_(new_install), + message_(message) { +} + +PluginInstallerInfoBarDelegate::~PluginInstallerInfoBarDelegate() { +} + +InfoBarDelegate* PluginInstallerInfoBarDelegate::Create( + InfoBarTabHelper* infobar_helper, + PluginInstaller* installer, + const base::Closure& callback) { + string16 message; + switch (installer->state()) { + case PluginInstaller::kStateIdle: + message = l10n_util::GetStringFUTF16( + IDS_PLUGININSTALLER_INSTALLPLUGIN_PROMPT, installer->name()); + break; + case PluginInstaller::kStateDownloading: + message = l10n_util::GetStringUTF16(IDS_PLUGIN_DOWNLOADING); + break; + } + return new PluginInstallerInfoBarDelegate( + infobar_helper, installer, callback, true, message); +} + +gfx::Image* PluginInstallerInfoBarDelegate::GetIcon() const { + return &ResourceBundle::GetSharedInstance().GetNativeImageNamed( + IDR_INFOBAR_PLUGIN_INSTALL); +} + +string16 PluginInstallerInfoBarDelegate::GetMessageText() const { + return message_; +} + +int PluginInstallerInfoBarDelegate::GetButtons() const { + return callback_.is_null() ? BUTTON_NONE : BUTTON_OK; +} + +string16 PluginInstallerInfoBarDelegate::GetButtonLabel( + InfoBarButton button) const { + DCHECK_EQ(BUTTON_OK, button); + return l10n_util::GetStringUTF16(IDS_PLUGININSTALLER_INSTALLPLUGIN_BUTTON); +} + +bool PluginInstallerInfoBarDelegate::Accept() { + callback_.Run(); + return false; +} + +string16 PluginInstallerInfoBarDelegate::GetLinkText() const { + return l10n_util::GetStringUTF16( + new_install_ ? IDS_PLUGININSTALLER_PROBLEMSINSTALLING + : IDS_PLUGININSTALLER_PROBLEMSUPDATING); +} + +bool PluginInstallerInfoBarDelegate::LinkClicked( + WindowOpenDisposition disposition) { + GURL url(installer()->help_url()); + if (url.is_empty()) { + url = google_util::AppendGoogleLocaleParam(GURL( + "https://www.google.com/support/chrome/bin/answer.py?answer=142064")); + } + + OpenURLParams params( + url, Referrer(), + (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, + content::PAGE_TRANSITION_LINK, false); + owner()->web_contents()->OpenURL(params); + return false; +} + +void PluginInstallerInfoBarDelegate::DidStartDownload() { + ReplaceWithInfoBar(l10n_util::GetStringUTF16(IDS_PLUGIN_DOWNLOADING)); +} + +void PluginInstallerInfoBarDelegate::DidFinishDownload() { + ReplaceWithInfoBar(l10n_util::GetStringUTF16( + new_install_ ? IDS_PLUGIN_INSTALLING : IDS_PLUGIN_UPDATING)); +} + +void PluginInstallerInfoBarDelegate::DownloadError(const std::string& message) { + ReplaceWithInfoBar( + l10n_util::GetStringUTF16(IDS_PLUGIN_DOWNLOAD_ERROR_SHORT)); +} + +void PluginInstallerInfoBarDelegate::OnlyWeakObserversLeft() { + if (owner()) + owner()->RemoveInfoBar(this); +} + +void PluginInstallerInfoBarDelegate::ReplaceWithInfoBar( + const string16& message) { + // Return early if the message doesn't change. This is important in case the + // PluginInstaller is still iterating over its observers (otherwise we would + // keep replacing infobar delegates infinitely). + if (message_ == message) + return; + if (!owner()) + return; + InfoBarDelegate* delegate = new PluginInstallerInfoBarDelegate( + owner(), installer(), base::Closure(), new_install_, message); + owner()->ReplaceInfoBar(this, delegate); +} diff --git a/chrome/browser/plugin_infobar_delegates.h b/chrome/browser/plugin_infobar_delegates.h new file mode 100644 index 0000000..f4e9096 --- /dev/null +++ b/chrome/browser/plugin_infobar_delegates.h @@ -0,0 +1,164 @@ +// Copyright (c) 2012 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_INFOBAR_DELEGATES_H_ +#define CHROME_BROWSER_PLUGIN_INFOBAR_DELEGATES_H_ +#pragma once + +#include "base/callback.h" +#include "chrome/browser/plugin_installer_observer.h" +#include "chrome/browser/tab_contents/confirm_infobar_delegate.h" +#include "chrome/browser/tab_contents/link_infobar_delegate.h" +#include "googleurl/src/gurl.h" + +class HostContentSettingsMap; +class PluginObserver; + +// Base class for blocked plug-in infobars. +class PluginInfoBarDelegate : public ConfirmInfoBarDelegate { + public: + PluginInfoBarDelegate(InfoBarTabHelper* infobar_helper, const string16& name); + + protected: + virtual ~PluginInfoBarDelegate(); + + // ConfirmInfoBarDelegate: + virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE; + + virtual std::string GetLearnMoreURL() const = 0; + + void LoadBlockedPlugins(); + + string16 name_; + + private: + // ConfirmInfoBarDelegate: + virtual gfx::Image* GetIcon() const OVERRIDE; + virtual string16 GetLinkText() const OVERRIDE; + + DISALLOW_COPY_AND_ASSIGN(PluginInfoBarDelegate); +}; + +// Infobar that's shown when a plug-in requires user authorization to run. +class UnauthorizedPluginInfoBarDelegate : public PluginInfoBarDelegate { + public: + UnauthorizedPluginInfoBarDelegate(InfoBarTabHelper* infobar_helper, + HostContentSettingsMap* content_settings, + const string16& name); + + private: + virtual ~UnauthorizedPluginInfoBarDelegate(); + + // PluginInfoBarDelegate: + virtual string16 GetMessageText() const OVERRIDE; + virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; + virtual bool Accept() OVERRIDE; + virtual bool Cancel() OVERRIDE; + virtual void InfoBarDismissed() OVERRIDE; + virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE; + virtual std::string GetLearnMoreURL() const OVERRIDE; + + HostContentSettingsMap* content_settings_; + + DISALLOW_COPY_AND_ASSIGN(UnauthorizedPluginInfoBarDelegate); +}; + +// Infobar that's shown when a plug-in is out of date. +class OutdatedPluginInfoBarDelegate : public PluginInfoBarDelegate, + public WeakPluginInstallerObserver { + public: + static InfoBarDelegate* Create(PluginObserver* observer, + PluginInstaller* installer); + + private: + OutdatedPluginInfoBarDelegate(PluginObserver* observer, + PluginInstaller* installer, + const string16& message); + virtual ~OutdatedPluginInfoBarDelegate(); + + // PluginInfoBarDelegate: + virtual string16 GetMessageText() const OVERRIDE; + virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; + virtual bool Accept() OVERRIDE; + virtual bool Cancel() OVERRIDE; + virtual void InfoBarDismissed() OVERRIDE; + virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE; + virtual std::string GetLearnMoreURL() const OVERRIDE; + + // PluginInstallerObserver: + virtual void DidStartDownload() OVERRIDE; + virtual void DidFinishDownload() OVERRIDE; + virtual void DownloadError(const std::string& message) OVERRIDE; + + // WeakPluginInstallerObserver: + virtual void OnlyWeakObserversLeft() OVERRIDE; + + // Replaces this infobar with one showing |message|. The new infobar will + // not have any buttons (and not call the callback). + void ReplaceWithInfoBar(const string16& message); + + // Has the same lifetime as TabContentsWrapper, which owns us + // (transitively via InfoBarTabHelper). + PluginObserver* observer_; + + string16 message_; + + DISALLOW_COPY_AND_ASSIGN(OutdatedPluginInfoBarDelegate); +}; + +// The main purpose for this class is to popup/close the infobar when there is +// a missing plugin. +class PluginInstallerInfoBarDelegate : public ConfirmInfoBarDelegate, + public WeakPluginInstallerObserver { + public: + // Shows an infobar asking whether to install the plugin represented by + // |installer|. When the user accepts, |callback| is called. + // During installation of the plug-in, the infobar will change to reflect the + // installation state. + static InfoBarDelegate* Create(InfoBarTabHelper* infobar_helper, + PluginInstaller* installer, + const base::Closure& callback); + + private: + friend class OutdatedPluginInfoBarDelegate; + + PluginInstallerInfoBarDelegate(InfoBarTabHelper* infobar_helper, + PluginInstaller* installer, + const base::Closure& callback, + bool new_install, + const string16& message); + virtual ~PluginInstallerInfoBarDelegate(); + + // ConfirmInfoBarDelegate: + virtual gfx::Image* GetIcon() const OVERRIDE; + virtual string16 GetMessageText() const OVERRIDE; + virtual int GetButtons() const OVERRIDE; + virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; + virtual bool Accept() OVERRIDE; + virtual string16 GetLinkText() const OVERRIDE; + virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE; + + // PluginInstallerObserver: + virtual void DidStartDownload() OVERRIDE; + virtual void DidFinishDownload() OVERRIDE; + virtual void DownloadError(const std::string& message) OVERRIDE; + + // WeakPluginInstallerObserver: + virtual void OnlyWeakObserversLeft() OVERRIDE; + + // Replaces this infobar with one showing |message|. The new infobar will + // not have any buttons (and not call the callback). + void ReplaceWithInfoBar(const string16& message); + + base::Closure callback_; + + // True iff the plug-in isn't installed yet. + bool new_install_; + + string16 message_; + + DISALLOW_COPY_AND_ASSIGN(PluginInstallerInfoBarDelegate); +}; + +#endif // CHROME_BROWSER_PLUGIN_INFOBAR_DELEGATES_H_ diff --git a/chrome/browser/plugin_installer.cc b/chrome/browser/plugin_installer.cc index e812282..a69b06c 100644 --- a/chrome/browser/plugin_installer.cc +++ b/chrome/browser/plugin_installer.cc @@ -10,6 +10,8 @@ #include "chrome/browser/platform_util.h" #include "chrome/browser/plugin_download_helper.h" #include "chrome/browser/plugin_installer_observer.h" +#include "content/public/browser/browser_context.h" +#include "content/public/browser/web_contents.h" PluginInstaller::~PluginInstaller() { } @@ -48,8 +50,7 @@ void PluginInstaller::RemoveWeakObserver( weak_observers_.RemoveObserver(observer); } -void PluginInstaller::StartInstalling( - net::URLRequestContextGetter* request_context) { +void PluginInstaller::StartInstalling(content::WebContents* web_contents) { DCHECK(state_ == kStateIdle); DCHECK(!url_for_display_); state_ = kStateDownloading; @@ -58,14 +59,19 @@ void PluginInstaller::StartInstalling( PluginDownloadUrlHelper* downloader = new PluginDownloadUrlHelper(); downloader->InitiateDownload( plugin_url_, - request_context, + web_contents->GetBrowserContext()->GetRequestContext(), base::Bind(&PluginInstaller::DidFinishDownload, base::Unretained(this)), base::Bind(&PluginInstaller::DownloadError, base::Unretained(this))); } -void PluginInstaller::DidOpenDownloadURL() { +void PluginInstaller::OpenDownloadURL(content::WebContents* web_contents) { DCHECK(state_ == kStateIdle); DCHECK(url_for_display_); + web_contents->OpenURL(content::OpenURLParams( + plugin_url_, + content::Referrer(web_contents->GetURL(), + WebKit::WebReferrerPolicyDefault), + NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_TYPED, false)); FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DidFinishDownload()); } diff --git a/chrome/browser/plugin_installer.h b/chrome/browser/plugin_installer.h index 6f76967..a405354 100644 --- a/chrome/browser/plugin_installer.h +++ b/chrome/browser/plugin_installer.h @@ -14,8 +14,8 @@ class FilePath; class PluginInstallerObserver; class WeakPluginInstallerObserver; -namespace net { -class URLRequestContextGetter; +namespace content { +class WebContents; } class PluginInstaller { @@ -57,11 +57,14 @@ class PluginInstaller { // URL to open when the user clicks on the "Problems installing?" link. const GURL& help_url() const { return help_url_; } - void StartInstalling(net::URLRequestContextGetter* request_context); + // Opens the download URL in a new tab. This method should only be called if + // |url_for_display| returns true. + void OpenDownloadURL(content::WebContents* web_contents); - // Called when the browser opened the download URL in a new tab, to notify - // observers. - void DidOpenDownloadURL(); + // Starts downloading the download URL and opens the downloaded file + // when finished. This method should only be called if |url_for_display| + // returns false. + void StartInstalling(content::WebContents* web_contents); private: void DidFinishDownload(const FilePath& downloaded_file); diff --git a/chrome/browser/plugin_installer_infobar_delegate.cc b/chrome/browser/plugin_installer_infobar_delegate.cc deleted file mode 100644 index 4716e40..0000000 --- a/chrome/browser/plugin_installer_infobar_delegate.cc +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright (c) 2012 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_infobar_delegate.h" - -#include "base/utf_string_conversions.h" -#include "chrome/browser/google/google_util.h" -#include "chrome/browser/infobars/infobar_tab_helper.h" -#include "chrome/browser/plugin_installer.h" -#include "content/browser/renderer_host/render_view_host.h" -#include "content/public/browser/web_contents.h" -#include "grit/generated_resources.h" -#include "grit/locale_settings.h" -#include "grit/theme_resources_standard.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/resource/resource_bundle.h" - -using content::OpenURLParams; -using content::Referrer; - -PluginInstallerInfoBarDelegate::PluginInstallerInfoBarDelegate( - InfoBarTabHelper* infobar_helper, - PluginInstaller* installer, - const base::Closure& callback, - const string16& message) - : ConfirmInfoBarDelegate(infobar_helper), - WeakPluginInstallerObserver(installer), - callback_(callback), - message_(message) { -} - -PluginInstallerInfoBarDelegate::~PluginInstallerInfoBarDelegate() { -} - -InfoBarDelegate* PluginInstallerInfoBarDelegate::Create( - InfoBarTabHelper* infobar_helper, - PluginInstaller* installer, - const base::Closure& callback) { - string16 message; - switch (installer->state()) { - case PluginInstaller::kStateIdle: - message = l10n_util::GetStringFUTF16( - IDS_PLUGININSTALLER_INSTALLPLUGIN_PROMPT, installer->name()); - break; - case PluginInstaller::kStateDownloading: - message = l10n_util::GetStringUTF16(IDS_PLUGIN_DOWNLOADING); - break; - } - return new PluginInstallerInfoBarDelegate( - infobar_helper, installer, callback, message); -} - -gfx::Image* PluginInstallerInfoBarDelegate::GetIcon() const { - return &ResourceBundle::GetSharedInstance().GetNativeImageNamed( - IDR_INFOBAR_PLUGIN_INSTALL); -} - -string16 PluginInstallerInfoBarDelegate::GetMessageText() const { - return message_; -} - -int PluginInstallerInfoBarDelegate::GetButtons() const { - return callback_.is_null() ? BUTTON_NONE : BUTTON_OK; -} - -string16 PluginInstallerInfoBarDelegate::GetButtonLabel( - InfoBarButton button) const { - DCHECK_EQ(BUTTON_OK, button); - return l10n_util::GetStringUTF16(IDS_PLUGININSTALLER_INSTALLPLUGIN_BUTTON); -} - -bool PluginInstallerInfoBarDelegate::Accept() { - callback_.Run(); - return false; -} - -string16 PluginInstallerInfoBarDelegate::GetLinkText() const { - return l10n_util::GetStringUTF16(IDS_PLUGININSTALLER_PROBLEMSINSTALLING); -} - -bool PluginInstallerInfoBarDelegate::LinkClicked( - WindowOpenDisposition disposition) { - GURL url(installer()->help_url()); - if (url.is_empty()) { - url = google_util::AppendGoogleLocaleParam(GURL( - "https://www.google.com/support/chrome/bin/answer.py?answer=142064")); - } - - OpenURLParams params( - url, Referrer(), - (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, - content::PAGE_TRANSITION_LINK, false); - owner()->web_contents()->OpenURL(params); - return false; -} - -void PluginInstallerInfoBarDelegate::DidStartDownload() { - ReplaceWithInfoBar(l10n_util::GetStringUTF16(IDS_PLUGIN_DOWNLOADING)); -} - -void PluginInstallerInfoBarDelegate::DidFinishDownload() { - ReplaceWithInfoBar(l10n_util::GetStringUTF16(IDS_PLUGIN_INSTALLING)); -} - -void PluginInstallerInfoBarDelegate::DownloadError(const std::string& message) { - ReplaceWithInfoBar( - l10n_util::GetStringUTF16(IDS_PLUGIN_DOWNLOAD_ERROR_SHORT)); -} - -void PluginInstallerInfoBarDelegate::OnlyWeakObserversLeft() { - if (owner()) - owner()->RemoveInfoBar(this); -} - -void PluginInstallerInfoBarDelegate::ReplaceWithInfoBar( - const string16& message) { - // Return early if the message doesn't change. This is important in case the - // PluginInstaller is still iterating over its observers (otherwise we would - // keep replacing infobar delegates infinitely). - if (message_ == message) - return; - if (!owner()) - return; - InfoBarDelegate* delegate = new PluginInstallerInfoBarDelegate( - owner(), installer(), base::Closure(), message); - owner()->ReplaceInfoBar(this, delegate); -} diff --git a/chrome/browser/plugin_installer_infobar_delegate.h b/chrome/browser/plugin_installer_infobar_delegate.h deleted file mode 100644 index 5dad51e..0000000 --- a/chrome/browser/plugin_installer_infobar_delegate.h +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (c) 2012 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_INFOBAR_DELEGATE_H_ -#define CHROME_BROWSER_PLUGIN_INSTALLER_INFOBAR_DELEGATE_H_ -#pragma once - -#include "base/callback.h" -#include "chrome/browser/plugin_installer_observer.h" -#include "chrome/browser/tab_contents/confirm_infobar_delegate.h" -#include "chrome/browser/tab_contents/link_infobar_delegate.h" -#include "googleurl/src/gurl.h" - -// The main purpose for this class is to popup/close the infobar when there is -// a missing plugin. -class PluginInstallerInfoBarDelegate : public ConfirmInfoBarDelegate, - public WeakPluginInstallerObserver { - public: - // Shows an infobar asking whether to install the plugin represented by - // |installer|. When the user accepts, |callback| is called. - // During installation of the plug-in, the infobar will change to reflect the - // installation state. - static InfoBarDelegate* Create(InfoBarTabHelper* infobar_helper, - PluginInstaller* installer, - const base::Closure& callback); - - private: - PluginInstallerInfoBarDelegate(InfoBarTabHelper* infobar_helper, - PluginInstaller* installer, - const base::Closure& callback, - const string16& message); - virtual ~PluginInstallerInfoBarDelegate(); - - // ConfirmInfoBarDelegate: - virtual gfx::Image* GetIcon() const OVERRIDE; - virtual string16 GetMessageText() const OVERRIDE; - virtual int GetButtons() const OVERRIDE; - virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; - virtual bool Accept() OVERRIDE; - virtual string16 GetLinkText() const OVERRIDE; - virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE; - - // PluginInstallerObserver: - virtual void DidStartDownload() OVERRIDE; - virtual void DidFinishDownload() OVERRIDE; - virtual void DownloadError(const std::string& message) OVERRIDE; - - // WeakPluginInstallerObserver: - virtual void OnlyWeakObserversLeft() OVERRIDE; - - // Replaces this infobar with one showing |message|. The new infobar will - // not have any buttons (and not call the callback). - void ReplaceWithInfoBar(const string16& message); - - base::Closure callback_; - - string16 message_; - - DISALLOW_COPY_AND_ASSIGN(PluginInstallerInfoBarDelegate); -}; - -#endif // CHROME_BROWSER_PLUGIN_INSTALLER_INFOBAR_DELEGATE_H_ diff --git a/chrome/browser/plugin_observer.cc b/chrome/browser/plugin_observer.cc index 39afcd5..a221c85 100644 --- a/chrome/browser/plugin_observer.cc +++ b/chrome/browser/plugin_observer.cc @@ -19,7 +19,6 @@ #include "chrome/common/render_messages.h" #include "chrome/common/url_constants.h" #include "content/browser/renderer_host/render_view_host.h" -#include "content/public/browser/user_metrics.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_delegate.h" #include "grit/generated_resources.h" @@ -27,278 +26,25 @@ #include "grit/theme_resources.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" -#include "webkit/plugins/npapi/plugin_group.h" #include "webkit/plugins/webplugininfo.h" #if defined(ENABLE_PLUGIN_INSTALLATION) +#include "chrome/browser/plugin_infobar_delegates.h" #include "chrome/browser/plugin_installer.h" -#include "chrome/browser/plugin_installer_infobar_delegate.h" #include "chrome/browser/plugin_installer_observer.h" #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" #endif // defined(ENABLE_PLUGIN_INSTALLATION) using content::OpenURLParams; using content::Referrer; -using content::UserMetricsAction; using content::WebContents; namespace { -// PluginInfoBarDelegate ------------------------------------------------------ - -class PluginInfoBarDelegate : public ConfirmInfoBarDelegate { - public: - PluginInfoBarDelegate(InfoBarTabHelper* infobar_helper, const string16& name); - - protected: - virtual ~PluginInfoBarDelegate(); - - // ConfirmInfoBarDelegate: - virtual bool Cancel() OVERRIDE; - virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE; - - virtual std::string GetLearnMoreURL() const = 0; - - string16 name_; - - private: - // ConfirmInfoBarDelegate: - virtual gfx::Image* GetIcon() const OVERRIDE; - virtual string16 GetLinkText() const OVERRIDE; - - DISALLOW_COPY_AND_ASSIGN(PluginInfoBarDelegate); -}; - -PluginInfoBarDelegate::PluginInfoBarDelegate(InfoBarTabHelper* infobar_helper, - const string16& name) - : ConfirmInfoBarDelegate(infobar_helper), - name_(name) { -} - -PluginInfoBarDelegate::~PluginInfoBarDelegate() { -} - -bool PluginInfoBarDelegate::Cancel() { - owner()->Send(new ChromeViewMsg_LoadBlockedPlugins(owner()->routing_id())); - return true; -} - -bool PluginInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) { - OpenURLParams params( - GURL(GetLearnMoreURL()), Referrer(), - (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, - content::PAGE_TRANSITION_LINK, - false); - owner()->web_contents()->OpenURL(params); - return false; -} - -gfx::Image* PluginInfoBarDelegate::GetIcon() const { - return &ResourceBundle::GetSharedInstance().GetNativeImageNamed( - IDR_INFOBAR_PLUGIN_INSTALL); -} - -string16 PluginInfoBarDelegate::GetLinkText() const { - return l10n_util::GetStringUTF16(IDS_LEARN_MORE); -} - - -// BlockedPluginInfoBarDelegate ----------------------------------------------- - -class BlockedPluginInfoBarDelegate : public PluginInfoBarDelegate { - public: - BlockedPluginInfoBarDelegate(InfoBarTabHelper* infobar_helper, - HostContentSettingsMap* content_settings, - const string16& name); - - private: - virtual ~BlockedPluginInfoBarDelegate(); - - // PluginInfoBarDelegate: - virtual string16 GetMessageText() const OVERRIDE; - virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; - virtual bool Accept() OVERRIDE; - virtual bool Cancel() OVERRIDE; - virtual void InfoBarDismissed() OVERRIDE; - virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE; - virtual std::string GetLearnMoreURL() const OVERRIDE; - - HostContentSettingsMap* content_settings_; - - DISALLOW_COPY_AND_ASSIGN(BlockedPluginInfoBarDelegate); -}; - -BlockedPluginInfoBarDelegate::BlockedPluginInfoBarDelegate( - InfoBarTabHelper* infobar_helper, - HostContentSettingsMap* content_settings, - const string16& utf16_name) - : PluginInfoBarDelegate(infobar_helper, utf16_name), - content_settings_(content_settings) { - content::RecordAction(UserMetricsAction("BlockedPluginInfobar.Shown")); - std::string name = UTF16ToUTF8(utf16_name); - if (name == webkit::npapi::PluginGroup::kJavaGroupName) - content::RecordAction( - UserMetricsAction("BlockedPluginInfobar.Shown.Java")); - else if (name == webkit::npapi::PluginGroup::kQuickTimeGroupName) - content::RecordAction( - UserMetricsAction("BlockedPluginInfobar.Shown.QuickTime")); - else if (name == webkit::npapi::PluginGroup::kShockwaveGroupName) - content::RecordAction( - UserMetricsAction("BlockedPluginInfobar.Shown.Shockwave")); - else if (name == webkit::npapi::PluginGroup::kRealPlayerGroupName) - content::RecordAction( - UserMetricsAction("BlockedPluginInfobar.Shown.RealPlayer")); - else if (name == webkit::npapi::PluginGroup::kWindowsMediaPlayerGroupName) - content::RecordAction( - UserMetricsAction("BlockedPluginInfobar.Shown.WindowsMediaPlayer")); -} - -BlockedPluginInfoBarDelegate::~BlockedPluginInfoBarDelegate() { - content::RecordAction(UserMetricsAction("BlockedPluginInfobar.Closed")); -} - -std::string BlockedPluginInfoBarDelegate::GetLearnMoreURL() const { - return chrome::kBlockedPluginLearnMoreURL; -} - -string16 BlockedPluginInfoBarDelegate::GetMessageText() const { - return l10n_util::GetStringFUTF16(IDS_PLUGIN_NOT_AUTHORIZED, name_); -} - -string16 BlockedPluginInfoBarDelegate::GetButtonLabel( - InfoBarButton button) const { - return l10n_util::GetStringUTF16((button == BUTTON_OK) ? - IDS_PLUGIN_ENABLE_TEMPORARILY : IDS_PLUGIN_ENABLE_ALWAYS); -} - -bool BlockedPluginInfoBarDelegate::Accept() { - content::RecordAction( - UserMetricsAction("BlockedPluginInfobar.AllowThisTime")); - return PluginInfoBarDelegate::Cancel(); -} - -bool BlockedPluginInfoBarDelegate::Cancel() { - content::RecordAction( - UserMetricsAction("BlockedPluginInfobar.AlwaysAllow")); - content_settings_->AddExceptionForURL(owner()->web_contents()->GetURL(), - owner()->web_contents()->GetURL(), - CONTENT_SETTINGS_TYPE_PLUGINS, - std::string(), - CONTENT_SETTING_ALLOW); - return PluginInfoBarDelegate::Cancel(); -} - -void BlockedPluginInfoBarDelegate::InfoBarDismissed() { - content::RecordAction( - UserMetricsAction("BlockedPluginInfobar.Dismissed")); -} - -bool BlockedPluginInfoBarDelegate::LinkClicked( - WindowOpenDisposition disposition) { - content::RecordAction( - UserMetricsAction("BlockedPluginInfobar.LearnMore")); - return PluginInfoBarDelegate::LinkClicked(disposition); -} - -// OutdatedPluginInfoBarDelegate ---------------------------------------------- - -class OutdatedPluginInfoBarDelegate : public PluginInfoBarDelegate { - public: - OutdatedPluginInfoBarDelegate(InfoBarTabHelper* infobar_helper, - const string16& name, - const GURL& update_url); - - private: - virtual ~OutdatedPluginInfoBarDelegate(); - - // PluginInfoBarDelegate: - virtual string16 GetMessageText() const OVERRIDE; - virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; - virtual bool Accept() OVERRIDE; - virtual bool Cancel() OVERRIDE; - virtual void InfoBarDismissed() OVERRIDE; - virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE; - virtual std::string GetLearnMoreURL() const OVERRIDE; - - GURL update_url_; - - DISALLOW_COPY_AND_ASSIGN(OutdatedPluginInfoBarDelegate); -}; - -OutdatedPluginInfoBarDelegate::OutdatedPluginInfoBarDelegate( - InfoBarTabHelper* infobar_helper, - const string16& utf16_name, - const GURL& update_url) - : PluginInfoBarDelegate(infobar_helper, utf16_name), - update_url_(update_url) { - content::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Shown")); - std::string name = UTF16ToUTF8(utf16_name); - if (name == webkit::npapi::PluginGroup::kJavaGroupName) - content::RecordAction( - UserMetricsAction("OutdatedPluginInfobar.Shown.Java")); - else if (name == webkit::npapi::PluginGroup::kQuickTimeGroupName) - content::RecordAction( - UserMetricsAction("OutdatedPluginInfobar.Shown.QuickTime")); - else if (name == webkit::npapi::PluginGroup::kShockwaveGroupName) - content::RecordAction( - UserMetricsAction("OutdatedPluginInfobar.Shown.Shockwave")); - else if (name == webkit::npapi::PluginGroup::kRealPlayerGroupName) - content::RecordAction( - UserMetricsAction("OutdatedPluginInfobar.Shown.RealPlayer")); - else if (name == webkit::npapi::PluginGroup::kSilverlightGroupName) - content::RecordAction( - UserMetricsAction("OutdatedPluginInfobar.Shown.Silverlight")); - else if (name == webkit::npapi::PluginGroup::kAdobeReaderGroupName) - content::RecordAction( - UserMetricsAction("OutdatedPluginInfobar.Shown.Reader")); -} - -OutdatedPluginInfoBarDelegate::~OutdatedPluginInfoBarDelegate() { - content::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Closed")); -} - -std::string OutdatedPluginInfoBarDelegate::GetLearnMoreURL() const { - return chrome::kOutdatedPluginLearnMoreURL; -} - -string16 OutdatedPluginInfoBarDelegate::GetMessageText() const { - return l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED_PROMPT, name_); -} - -string16 OutdatedPluginInfoBarDelegate::GetButtonLabel( - InfoBarButton button) const { - return l10n_util::GetStringUTF16((button == BUTTON_OK) ? - IDS_PLUGIN_UPDATE : IDS_PLUGIN_ENABLE_TEMPORARILY); -} - -bool OutdatedPluginInfoBarDelegate::Accept() { - content::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Update")); - OpenURLParams params( - update_url_, Referrer(), NEW_FOREGROUND_TAB, - content::PAGE_TRANSITION_LINK, false); - owner()->web_contents()->OpenURL(params); - return false; -} - -bool OutdatedPluginInfoBarDelegate::Cancel() { - content::RecordAction( - UserMetricsAction("OutdatedPluginInfobar.AllowThisTime")); - return PluginInfoBarDelegate::Cancel(); -} - -void OutdatedPluginInfoBarDelegate::InfoBarDismissed() { - content::RecordAction( - UserMetricsAction("OutdatedPluginInfobar.Dismissed")); -} +#if defined(ENABLE_PLUGIN_INSTALLATION) -bool OutdatedPluginInfoBarDelegate::LinkClicked( - WindowOpenDisposition disposition) { - content::RecordAction( - UserMetricsAction("OutdatedPluginInfobar.LearnMore")); - return PluginInfoBarDelegate::LinkClicked(disposition); -} +// ConfirmInstallDialogDelegate ------------------------------------------------ -#if defined(ENABLE_PLUGIN_INSTALLATION) class ConfirmInstallDialogDelegate : public TabModalConfirmDialogDelegate, public WeakPluginInstallerObserver { public: @@ -317,7 +63,7 @@ class ConfirmInstallDialogDelegate : public TabModalConfirmDialogDelegate, virtual void OnlyWeakObserversLeft() OVERRIDE; private: - net::URLRequestContextGetter* request_context_; + content::WebContents* web_contents_; }; ConfirmInstallDialogDelegate::ConfirmInstallDialogDelegate( @@ -325,7 +71,7 @@ ConfirmInstallDialogDelegate::ConfirmInstallDialogDelegate( PluginInstaller* installer) : TabModalConfirmDialogDelegate(web_contents), WeakPluginInstallerObserver(installer), - request_context_(web_contents->GetBrowserContext()->GetRequestContext()) { + web_contents_(web_contents) { } string16 ConfirmInstallDialogDelegate::GetTitle() { @@ -344,7 +90,7 @@ string16 ConfirmInstallDialogDelegate::GetAcceptButtonTitle() { } void ConfirmInstallDialogDelegate::OnAccepted() { - installer()->StartInstalling(request_context_); + installer()->StartInstalling(web_contents_); } void ConfirmInstallDialogDelegate::OnCanceled() { @@ -439,19 +185,31 @@ bool PluginObserver::OnMessageReceived(const IPC::Message& message) { return true; } -void PluginObserver::OnBlockedOutdatedPlugin(const string16& name, - const GURL& update_url) { +void PluginObserver::OnBlockedUnauthorizedPlugin(const string16& name) { InfoBarTabHelper* infobar_helper = tab_contents_->infobar_tab_helper(); infobar_helper->AddInfoBar( - new OutdatedPluginInfoBarDelegate(infobar_helper, name, update_url)); + new UnauthorizedPluginInfoBarDelegate( + infobar_helper, + tab_contents_->profile()->GetHostContentSettingsMap(), + name)); } -void PluginObserver::OnBlockedUnauthorizedPlugin(const string16& name) { +void PluginObserver::OnBlockedOutdatedPlugin(int placeholder_id, + const std::string& identifier) { + PluginFinder* plugin_finder = PluginFinder::GetInstance(); + plugin_finder->FindPluginWithIdentifier( + identifier, + base::Bind(&PluginObserver::FoundPluginToUpdate, + weak_ptr_factory_.GetWeakPtr(), placeholder_id)); +} + +void PluginObserver::FoundPluginToUpdate(int placeholder_id, + PluginInstaller* installer) { + plugin_placeholders_[placeholder_id] = + new PluginPlaceholderHost(this, placeholder_id, installer); InfoBarTabHelper* infobar_helper = tab_contents_->infobar_tab_helper(); - infobar_helper->AddInfoBar(new BlockedPluginInfoBarDelegate( - infobar_helper, - tab_contents_->profile()->GetHostContentSettingsMap(), - name)); + infobar_helper->AddInfoBar( + OutdatedPluginInfoBarDelegate::Create(this, installer)); } #if defined(ENABLE_PLUGIN_INSTALLATION) @@ -462,14 +220,17 @@ void PluginObserver::OnFindMissingPlugin(int placeholder_id, plugin_finder->FindPlugin( mime_type, lang, base::Bind(&PluginObserver::FoundMissingPlugin, - weak_ptr_factory_.GetWeakPtr(), placeholder_id, mime_type), - base::Bind(&PluginObserver::DidNotFindMissingPlugin, - weak_ptr_factory_.GetWeakPtr(), placeholder_id)); + weak_ptr_factory_.GetWeakPtr(), placeholder_id, mime_type)); } void PluginObserver::FoundMissingPlugin(int placeholder_id, const std::string& mime_type, PluginInstaller* installer) { + if (!installer) { + Send(new ChromeViewMsg_DidNotFindMissingPlugin(placeholder_id)); + return; + } + plugin_placeholders_[placeholder_id] = new PluginPlaceholderHost(this, placeholder_id, installer); InfoBarTabHelper* infobar_helper = tab_contents_->infobar_tab_helper(); @@ -480,18 +241,9 @@ void PluginObserver::FoundMissingPlugin(int placeholder_id, infobar_helper->AddInfoBar(delegate); } -void PluginObserver::DidNotFindMissingPlugin(int placeholder_id) { - Send(new ChromeViewMsg_DidNotFindMissingPlugin(placeholder_id)); -} - void PluginObserver::InstallMissingPlugin(PluginInstaller* installer) { if (installer->url_for_display()) { - web_contents()->OpenURL(OpenURLParams( - installer->plugin_url(), - content::Referrer(web_contents()->GetURL(), - WebKit::WebReferrerPolicyDefault), - NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_TYPED, false)); - installer->DidOpenDownloadURL(); + installer->OpenDownloadURL(web_contents()); } else { browser::ShowTabModalConfirmDialog( new ConfirmInstallDialogDelegate(web_contents(), installer), diff --git a/chrome/browser/plugin_observer.h b/chrome/browser/plugin_observer.h index 4000fce..36e039f 100644 --- a/chrome/browser/plugin_observer.h +++ b/chrome/browser/plugin_observer.h @@ -20,6 +20,7 @@ class TabContentsWrapper; #if defined(ENABLE_PLUGIN_INSTALLATION) class PluginInstaller; +class PluginPlaceholderHost; #endif class PluginObserver : public content::WebContentsObserver { @@ -30,21 +31,26 @@ class PluginObserver : public content::WebContentsObserver { // content::WebContentsObserver implementation. virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; - private: #if defined(ENABLE_PLUGIN_INSTALLATION) - class PluginPlaceholderHost; + void InstallMissingPlugin(PluginInstaller* installer); #endif - void OnBlockedOutdatedPlugin(const string16& name, const GURL& update_url); + TabContentsWrapper* tab_contents_wrapper() { return tab_contents_; } + + private: + class PluginPlaceholderHost; + void OnBlockedUnauthorizedPlugin(const string16& name); + void OnBlockedOutdatedPlugin(int placeholder_id, + const std::string& identifier); #if defined(ENABLE_PLUGIN_INSTALLATION) void OnFindMissingPlugin(int placeholder_id, const std::string& mime_type); void FoundMissingPlugin(int placeholder_id, const std::string& mime_type, PluginInstaller* installer); - void DidNotFindMissingPlugin(int placeholder_id); - void InstallMissingPlugin(PluginInstaller* installer); + void FoundPluginToUpdate(int placeholder_id, + PluginInstaller* installer); #endif void OnOpenAboutPlugins(); void OnRemovePluginPlaceholderHost(int placeholder_id); diff --git a/chrome/browser/resources/plugins_linux.json b/chrome/browser/resources/plugins_linux.json new file mode 100644 index 0000000..d410de0 --- /dev/null +++ b/chrome/browser/resources/plugins_linux.json @@ -0,0 +1,66 @@ +{ + "plugins": [ + { + "mime_types": [ + "application/x-java-applet", + "application/x-java-applet,version=1.1", + "application/x-java-applet,version=1.1.1", + "application/x-java-applet,version=1.1.2", + "application/x-java-applet,version=1.1.3", + "application/x-java-applet,version=1.2", + "application/x-java-applet,version=1.2.1", + "application/x-java-applet,version=1.2.2", + "application/x-java-applet,version=1.3", + "application/x-java-applet,version=1.3.1", + "application/x-java-applet,version=1.4", + "application/x-java-applet,version=1.4.1", + "application/x-java-applet,version=1.4.2", + "application/x-java-applet,version=1.5", + "application/x-java-applet,version=1.6", + "application/x-java-bean", + "application/x-java-bean,version=1.1", + "application/x-java-bean,version=1.1.1", + "application/x-java-bean,version=1.1.2", + "application/x-java-bean,version=1.1.3", + "application/x-java-bean,version=1.2", + "application/x-java-bean,version=1.2.1", + "application/x-java-bean,version=1.2.2", + "application/x-java-bean,version=1.3", + "application/x-java-bean,version=1.3.1", + "application/x-java-bean,version=1.4", + "application/x-java-bean,version=1.4.1", + "application/x-java-bean,version=1.4.2", + "application/x-java-bean,version=1.5", + "application/x-java-bean,version=1.6", + "application/x-java-vm" + ], + "lang": "en-US", + "name": "Java(TM)", + "identifier": "java-runtime-environment", + "help_url": "https://support.google.com/chrome/?p=plugin_java", + "url": "http://java.com/download", + "displayurl": true + }, + { + "mime_types": [ + "application/futuresplash", + "application/x-shockwave-flash" + ], + "lang": "en-US", + "name": "Adobe Flash Player", + "identifier": "adobe-flash-player", + "help_url": "https://support.google.com/chrome/?p=plugin_flash", + "url": "http://get.adobe.com/flashplayer/", + "displayurl": true + }, + { + "mime_types": [ + ], + "lang": "en-US", + "name": "IcedTea", + "identifier": "redhat-icetea-java", + "url": "http://icedtea.classpath.org/", + "displayurl": true + } + ] +} diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 5786125..0ed88b7 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1804,8 +1804,8 @@ 'browser/plugin_finder.h', 'browser/plugin_installer.cc', 'browser/plugin_installer.h', - 'browser/plugin_installer_infobar_delegate.cc', - 'browser/plugin_installer_infobar_delegate.h', + 'browser/plugin_infobar_delegates.cc', + 'browser/plugin_infobar_delegates.h', 'browser/plugin_installer_observer.cc', 'browser/plugin_installer_observer.h', 'browser/plugin_observer.cc', @@ -5422,8 +5422,6 @@ 'browser/plugin_finder.h', 'browser/plugin_installer.cc', 'browser/plugin_installer.h', - 'browser/plugin_installer_infobar_delegate.cc', - 'browser/plugin_installer_infobar_delegate.h', 'browser/plugin_installer_observer.cc', 'browser/plugin_installer_observer.h', ], diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h index 327f2f5..1649487 100644 --- a/chrome/common/render_messages.h +++ b/chrome/common/render_messages.h @@ -534,8 +534,8 @@ IPC_MESSAGE_CONTROL1(ChromeViewHostMsg_DnsPrefetch, // Notifies when a plugin couldn't be loaded because it's outdated. IPC_MESSAGE_ROUTED2(ChromeViewHostMsg_BlockedOutdatedPlugin, - string16, /* name */ - GURL /* update_url */) + int /* placeholder ID */, + std::string /* plug-in group identifier */) // Notifies when a plugin couldn't be loaded because it requires // user authorization. diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer/chrome_content_renderer_client.cc index e565ee4..66a7744 100644 --- a/chrome/renderer/chrome_content_renderer_client.cc +++ b/chrome/renderer/chrome_content_renderer_client.cc @@ -432,13 +432,17 @@ WebPlugin* ChromeContentRendererClient::CreatePlugin( break; } case ChromeViewHostMsg_GetPluginInfo_Status::kOutdatedBlocked: { +#if defined(ENABLE_PLUGIN_INSTALLATION) placeholder = PluginPlaceholder::CreateBlockedPlugin( render_view, frame, params, plugin, name, IDR_BLOCKED_PLUGIN_HTML, IDS_PLUGIN_OUTDATED); placeholder->set_allow_loading(true); render_view->Send(new ChromeViewHostMsg_BlockedOutdatedPlugin( - render_view->GetRoutingId(), group->GetGroupName(), - GURL(group->GetUpdateURL()))); + render_view->GetRoutingId(), placeholder->CreateRoutingId(), + group->identifier())); +#else + NOTREACHED(); +#endif break; } case ChromeViewHostMsg_GetPluginInfo_Status::kOutdatedDisallowed: { diff --git a/chrome/renderer/plugins/plugin_placeholder.cc b/chrome/renderer/plugins/plugin_placeholder.cc index 651dd75..f49fc72 100644 --- a/chrome/renderer/plugins/plugin_placeholder.cc +++ b/chrome/renderer/plugins/plugin_placeholder.cc @@ -310,7 +310,10 @@ void PluginPlaceholder::OnStartedDownloadingPlugin() { } void PluginPlaceholder::OnFinishedDownloadingPlugin() { - SetMessage(l10n_util::GetStringUTF16(IDS_PLUGIN_INSTALLING)); + bool is_installing = + status_->value == ChromeViewHostMsg_GetPluginInfo_Status::kNotFound; + SetMessage(l10n_util::GetStringUTF16( + is_installing ? IDS_PLUGIN_INSTALLING : IDS_PLUGIN_UPDATING)); } void PluginPlaceholder::OnErrorDownloadingPlugin(const std::string& error) { |