| Index: chrome/browser/plugin_observer.cc
|
| diff --git a/chrome/browser/plugin_observer.cc b/chrome/browser/plugin_observer.cc
|
| index b01c08379a980c12f120dbfba5307e5e5ced6dc3..39852d4b245d84a3903fac0d132b66a0a7596959 100644
|
| --- a/chrome/browser/plugin_observer.cc
|
| +++ b/chrome/browser/plugin_observer.cc
|
| @@ -4,6 +4,7 @@
|
|
|
| #include "chrome/browser/plugin_observer.h"
|
|
|
| +#include "base/auto_reset.h"
|
| #include "base/bind.h"
|
| #include "base/utf_string_conversions.h"
|
| #include "chrome/browser/browser_process.h"
|
| @@ -13,9 +14,11 @@
|
| #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_observer.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| #include "chrome/browser/tab_contents/confirm_infobar_delegate.h"
|
| #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
|
| +#include "chrome/browser/ui/tab_modal_dialog_delegate.h"
|
| #include "chrome/common/render_messages.h"
|
| #include "chrome/common/url_constants.h"
|
| #include "content/browser/renderer_host/render_view_host.h"
|
| @@ -24,10 +27,12 @@
|
| #include "content/browser/user_metrics.h"
|
| #include "grit/generated_resources.h"
|
| #include "grit/theme_resources_standard.h"
|
| +#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"
|
| +#include "../webkit/grit/webkit_strings.h" // XXX
|
|
|
| namespace {
|
|
|
| @@ -281,11 +286,118 @@ bool OutdatedPluginInfoBarDelegate::LinkClicked(
|
| return PluginInfoBarDelegate::LinkClicked(disposition);
|
| }
|
|
|
| -} // namespace
|
| +class ConfirmInstallDialogDelegate : public TabModalDialogDelegate,
|
| + public PluginInstallerObserver {
|
| + public:
|
| + ConfirmInstallDialogDelegate(TabContents* tab_contents,
|
| + PluginInstaller* installer);
|
| +
|
| + // TabModalDialogDelegate methods:
|
| + virtual string16 GetTitle() OVERRIDE;
|
| + virtual string16 GetMessage() OVERRIDE;
|
| + virtual string16 GetAcceptButtonTitle() OVERRIDE;
|
| + virtual string16 GetCancelButtonTitle() OVERRIDE;
|
| + virtual void OnAccepted() OVERRIDE;
|
| + virtual void OnCanceled() OVERRIDE;
|
| +
|
| + // PluginInstallerObserver methods:
|
| + virtual void DidStartDownload() OVERRIDE;
|
| +
|
| + private:
|
| + net::URLRequestContextGetter* request_context_;
|
| + bool installing_;
|
| +};
|
|
|
| +ConfirmInstallDialogDelegate::ConfirmInstallDialogDelegate(
|
| + TabContents* tab_contents,
|
| + PluginInstaller* installer)
|
| + : TabModalDialogDelegate(tab_contents),
|
| + PluginInstallerObserver(installer),
|
| + request_context_(tab_contents->browser_context()->GetRequestContext()),
|
| + installing_(false) {
|
| +}
|
| +
|
| +string16 ConfirmInstallDialogDelegate::GetTitle() {
|
| + return l10n_util::GetStringFUTF16(
|
| + IDS_DEFAULT_PLUGIN_CONFIRMATION_DIALOG_TITLE, installer()->name());
|
| +}
|
| +
|
| +string16 ConfirmInstallDialogDelegate::GetMessage() {
|
| + return l10n_util::GetStringFUTF16(IDS_DEFAULT_PLUGIN_USER_OPTION_MSG,
|
| + installer()->name());
|
| +}
|
| +
|
| +string16 ConfirmInstallDialogDelegate::GetAcceptButtonTitle() {
|
| + return l10n_util::GetStringUTF16(IDS_DEFAULT_PLUGIN_GET_THE_PLUGIN_BTN_MSG);
|
| +}
|
| +
|
| +string16 ConfirmInstallDialogDelegate::GetCancelButtonTitle() {
|
| + return l10n_util::GetStringUTF16(
|
| + IDS_DEFAULT_PLUGIN_CANCEL_PLUGIN_DOWNLOAD_MSG);
|
| +}
|
| +
|
| +void ConfirmInstallDialogDelegate::OnAccepted() {
|
| + AutoReset<bool> auto_reset(&installing_, true);
|
| + installer()->StartInstalling(request_context_);
|
| +}
|
| +
|
| +void ConfirmInstallDialogDelegate::OnCanceled() {
|
| +}
|
| +
|
| +void ConfirmInstallDialogDelegate::DidStartDownload() {
|
| + if (!installing_)
|
| + Cancel();
|
| +}
|
| +
|
| +} // namespace
|
|
|
| // PluginObserver -------------------------------------------------------------
|
|
|
| +class PluginObserver::MissingPluginHost : public PluginInstallerObserver {
|
| + public:
|
| + MissingPluginHost(PluginObserver* observer,
|
| + int routing_id,
|
| + PluginInstaller* installer)
|
| + : PluginInstallerObserver(installer),
|
| + observer_(observer),
|
| + routing_id_(routing_id) {
|
| + switch (installer->state()) {
|
| + case PluginInstaller::kStateIdle: {
|
| + observer->Send(new ChromeViewMsg_FoundMissingPlugin(routing_id_,
|
| + installer->name()));
|
| + break;
|
| + }
|
| + case PluginInstaller::kStateDownloading: {
|
| + DidStartDownload();
|
| + break;
|
| + }
|
| + case PluginInstaller::kStateInstalling: {
|
| + DidFinishDownload();
|
| + break;
|
| + }
|
| + }
|
| + }
|
| +
|
| + // PluginInstallerObserver methods:
|
| + virtual void DidStartDownload() OVERRIDE {
|
| + observer_->Send(new ChromeViewMsg_StartedDownloadingPlugin(routing_id_));
|
| + }
|
| +
|
| + virtual void DidFinishDownload() OVERRIDE {
|
| + observer_->Send(new ChromeViewMsg_FinishedDownloadingPlugin(routing_id_));
|
| + }
|
| +
|
| + virtual void DidFinishInstallation() OVERRIDE {
|
| + LOG(ERROR) << "DidFinishInstallation";
|
| + }
|
| +
|
| + private:
|
| + // Weak pointer; owns us.
|
| + PluginObserver* observer_;
|
| +
|
| + int routing_id_;
|
| +};
|
| +
|
| PluginObserver::PluginObserver(TabContentsWrapper* tab_contents)
|
| : TabContentsObserver(tab_contents->tab_contents()),
|
| ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)),
|
| @@ -333,14 +445,17 @@ void PluginObserver::OnFindMissingPlugin(int placeholder_id,
|
| void PluginObserver::FoundMissingPlugin(int placeholder_id,
|
| const std::string& mime_type,
|
| PluginInstaller* installer) {
|
| - Send(new ChromeViewMsg_FoundMissingPlugin(placeholder_id, installer->name()));
|
| + missing_plugins_.push_back(
|
| + new MissingPluginHost(this, placeholder_id, installer));
|
| InfoBarTabHelper* infobar_helper = tab_contents_->infobar_tab_helper();
|
| - infobar_helper->AddInfoBar(new PluginInstallerInfoBarDelegate(
|
| + PluginInstallerInfoBarDelegate* delegate = new PluginInstallerInfoBarDelegate(
|
| + installer,
|
| infobar_helper,
|
| installer->name(),
|
| installer->help_url(),
|
| base::Bind(&PluginObserver::InstallMissingPlugin,
|
| - weak_ptr_factory_.GetWeakPtr(), installer)));
|
| + weak_ptr_factory_.GetWeakPtr(), installer));
|
| + infobar_helper->AddInfoBar(delegate);
|
| }
|
|
|
| void PluginObserver::DidNotFindMissingPlugin(int placeholder_id,
|
| @@ -356,6 +471,8 @@ void PluginObserver::InstallMissingPlugin(PluginInstaller* installer) {
|
| WebKit::WebReferrerPolicyDefault),
|
| NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_TYPED, false));
|
| } else {
|
| - NOTIMPLEMENTED();
|
| + TabModalDialogDelegate* delegate =
|
| + new ConfirmInstallDialogDelegate(tab_contents(), installer);
|
| + tab_contents()->delegate()->ShowTabModalDialog(delegate, tab_contents());
|
| }
|
| }
|
|
|