OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/nacl_host/nacl_infobar.h" | 5 #include "chrome/browser/nacl_host/nacl_infobar.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/string16.h" |
| 9 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" |
8 #include "chrome/browser/api/infobars/infobar_service.h" | 10 #include "chrome/browser/api/infobars/infobar_service.h" |
9 #include "chrome/browser/api/infobars/simple_alert_infobar_delegate.h" | |
10 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
11 #include "content/public/browser/render_view_host.h" | 12 #include "content/public/browser/render_view_host.h" |
12 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 14 #include "googleurl/src/gurl.h" |
13 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
14 #include "ppapi/c/private/ppb_nacl_private.h" | 16 #include "ppapi/c/private/ppb_nacl_private.h" |
15 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
16 | 18 |
17 | |
18 using content::BrowserThread; | 19 using content::BrowserThread; |
19 using content::RenderViewHost; | 20 using content::RenderViewHost; |
20 using content::WebContents; | 21 using content::WebContents; |
21 | 22 |
22 namespace { | 23 namespace { |
| 24 // The URL for the "learn more" article. |
| 25 const char kNaClLearnMoreUrl[] = |
| 26 "https://support.google.com/chrome/?p=ib_nacl"; |
| 27 |
| 28 // A simple LinkInfoBarDelegate doesn't support making the link right-aligned |
| 29 // so use a ConfirmInfoBarDelegate without any buttons instead. |
| 30 class NaClInfoBarDelegate : public ConfirmInfoBarDelegate { |
| 31 public: |
| 32 virtual string16 GetMessageText() const OVERRIDE; |
| 33 virtual string16 GetLinkText() const OVERRIDE; |
| 34 virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE; |
| 35 virtual int GetButtons() const OVERRIDE; |
| 36 static void Create(InfoBarService* ibs, WebContents* wc); |
| 37 private: |
| 38 NaClInfoBarDelegate(WebContents* wc, InfoBarService* ibs) : |
| 39 ConfirmInfoBarDelegate(ibs), wc_(wc) {} |
| 40 WebContents* wc_; |
| 41 }; |
| 42 |
| 43 string16 NaClInfoBarDelegate::GetMessageText() const { |
| 44 return l10n_util::GetStringUTF16(IDS_NACL_APP_MISSING_ARCH_MESSAGE); |
| 45 } |
| 46 |
| 47 string16 NaClInfoBarDelegate::GetLinkText() const { |
| 48 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); |
| 49 } |
| 50 |
| 51 bool NaClInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) { |
| 52 content::OpenURLParams params( |
| 53 GURL(kNaClLearnMoreUrl), content::Referrer(), |
| 54 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, |
| 55 content::PAGE_TRANSITION_LINK, |
| 56 false); |
| 57 wc_->OpenURL(params); |
| 58 return false; |
| 59 } |
| 60 |
| 61 int NaClInfoBarDelegate::GetButtons() const { return BUTTON_NONE; } |
| 62 |
| 63 // static |
| 64 void NaClInfoBarDelegate::Create(InfoBarService* ibs, WebContents *wc) { |
| 65 ibs->AddInfoBar(scoped_ptr<InfoBarDelegate>( |
| 66 new NaClInfoBarDelegate(wc, ibs))); |
| 67 } |
23 | 68 |
24 void ShowInfobar(int render_process_id, int render_view_id, | 69 void ShowInfobar(int render_process_id, int render_view_id, |
25 int error_id) { | 70 int error_id) { |
26 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
27 DCHECK(static_cast<PP_NaClError>(error_id) == | 72 DCHECK(static_cast<PP_NaClError>(error_id) == |
28 PP_NACL_MANIFEST_MISSING_ARCH); | 73 PP_NACL_MANIFEST_MISSING_ARCH); |
29 RenderViewHost* rvh = RenderViewHost::FromID(render_process_id, | 74 RenderViewHost* rvh = RenderViewHost::FromID(render_process_id, |
30 render_view_id); | 75 render_view_id); |
31 WebContents* wc = WebContents::FromRenderViewHost(rvh); | 76 WebContents* wc = WebContents::FromRenderViewHost(rvh); |
32 InfoBarService* ibs = InfoBarService::FromWebContents(wc); | 77 NaClInfoBarDelegate::Create(InfoBarService::FromWebContents(wc), wc); |
33 SimpleAlertInfoBarDelegate::Create(ibs, NULL, | |
34 l10n_util::GetStringUTF16(IDS_NACL_APP_MISSING_ARCH_MESSAGE), true); | |
35 } | 78 } |
36 | 79 |
37 } // namespace | 80 } // namespace |
38 | 81 |
39 void ShowNaClInfobar(int render_process_id, int render_view_id, | 82 void ShowNaClInfobar(int render_process_id, int render_view_id, |
40 int error_id) { | 83 int error_id) { |
41 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 84 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
42 base::Bind(&ShowInfobar, render_process_id, render_view_id, | 85 base::Bind(&ShowInfobar, render_process_id, render_view_id, |
43 error_id)); | 86 error_id)); |
44 } | 87 } |
OLD | NEW |