summaryrefslogtreecommitdiffstats
path: root/chrome/browser/nacl_host/nacl_infobar.cc
blob: 7583c22bf862f00626709d5715cbeba5ba35f769 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// 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/nacl_host/nacl_infobar.h"

#include "base/bind.h"
#include "base/strings/string16.h"
#include "chrome/browser/infobars/confirm_infobar_delegate.h"
#include "chrome/browser/infobars/infobar_service.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "googleurl/src/gurl.h"
#include "grit/generated_resources.h"
#include "ppapi/c/private/ppb_nacl_private.h"
#include "ui/base/l10n/l10n_util.h"

using content::BrowserThread;
using content::RenderViewHost;
using content::WebContents;

namespace {
// The URL for the "learn more" article.
const char kNaClLearnMoreUrl[] =
    "https://support.google.com/chrome/?p=ib_nacl";

// A simple LinkInfoBarDelegate doesn't support making the link right-aligned
// so use a ConfirmInfoBarDelegate without any buttons instead.
class NaClInfoBarDelegate : public ConfirmInfoBarDelegate {
 public:
  static void Create(InfoBarService* ibs, WebContents* wc);

 private:
  NaClInfoBarDelegate(WebContents* wc, InfoBarService* ibs) :
      ConfirmInfoBarDelegate(ibs), wc_(wc) {}

  virtual string16 GetMessageText() const OVERRIDE;
  virtual int GetButtons() const OVERRIDE;
  virtual string16 GetLinkText() const OVERRIDE;
  virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE;

  WebContents* wc_;

  DISALLOW_COPY_AND_ASSIGN(NaClInfoBarDelegate);
};

// static
void NaClInfoBarDelegate::Create(InfoBarService* ibs, WebContents *wc) {
  ibs->AddInfoBar(scoped_ptr<InfoBarDelegate>(
      new NaClInfoBarDelegate(wc, ibs)));
}

string16 NaClInfoBarDelegate::GetMessageText() const {
  return l10n_util::GetStringUTF16(IDS_NACL_APP_MISSING_ARCH_MESSAGE);
}

int NaClInfoBarDelegate::GetButtons() const { return BUTTON_NONE; }

string16 NaClInfoBarDelegate::GetLinkText() const {
  return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
}

bool NaClInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) {
  content::OpenURLParams params(
      GURL(kNaClLearnMoreUrl), content::Referrer(),
      (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition,
      content::PAGE_TRANSITION_LINK,
      false);
  wc_->OpenURL(params);
  return false;
}

void ShowInfobar(int render_process_id, int render_view_id,
                 int error_id) {
  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
  DCHECK(static_cast<PP_NaClError>(error_id) ==
        PP_NACL_MANIFEST_MISSING_ARCH);
  RenderViewHost* rvh = RenderViewHost::FromID(render_process_id,
                                               render_view_id);
  if (!rvh)
    return;

  WebContents* wc = WebContents::FromRenderViewHost(rvh);
  if (!wc)
    return;

  InfoBarService* infobar_service = InfoBarService::FromWebContents(wc);
  if (infobar_service)
    NaClInfoBarDelegate::Create(infobar_service, wc);
}

}  // namespace

void ShowNaClInfobar(int render_process_id, int render_view_id,
                     int error_id) {
  BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
      base::Bind(&ShowInfobar, render_process_id, render_view_id,
                 error_id));
}