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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/plugins/plugin_infobar_delegates.h"
6
7 #include "base/path_service.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/content_settings/host_content_settings_map.h"
10 #include "chrome/browser/google/google_util.h"
11 #include "chrome/browser/infobars/infobar.h"
12 #include "chrome/browser/infobars/infobar_service.h"
13 #include "chrome/browser/lifetime/application_lifetime.h"
14 #include "chrome/browser/plugins/chrome_plugin_service_filter.h"
15 #include "chrome/browser/plugins/plugin_metadata.h"
16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/shell_integration.h"
18 #include "chrome/browser/ui/browser_commands.h"
19 #include "chrome/common/render_messages.h"
20 #include "chrome/common/url_constants.h"
21 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/render_process_host.h"
23 #include "content/public/browser/render_view_host.h"
24 #include "content/public/browser/user_metrics.h"
25 #include "content/public/browser/web_contents.h"
26 #include "grit/generated_resources.h"
27 #include "grit/locale_settings.h"
28 #include "grit/theme_resources.h"
29 #include "ui/base/l10n/l10n_util.h"
30
31 #if defined(ENABLE_PLUGIN_INSTALLATION)
32 #if defined(OS_WIN)
33 #include "base/win/metro.h"
34 #endif
35 #include "chrome/browser/plugins/plugin_installer.h"
36 #endif
37
38 #if defined(OS_WIN)
39 #include <shellapi.h>
40 #include "ui/base/win/shell.h"
41
42 #if defined(USE_AURA)
43 #include "ui/aura/remote_root_window_host_win.h"
44 #endif
45 #endif
46
47 using content::UserMetricsAction;
48
49
50 // PluginInfoBarDelegate ------------------------------------------------------
51
PluginInfoBarDelegate(const std::string & identifier)52 PluginInfoBarDelegate::PluginInfoBarDelegate(const std::string& identifier)
53 : ConfirmInfoBarDelegate(),
54 identifier_(identifier) {
55 }
56
~PluginInfoBarDelegate()57 PluginInfoBarDelegate::~PluginInfoBarDelegate() {
58 }
59
LinkClicked(WindowOpenDisposition disposition)60 bool PluginInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) {
61 web_contents()->OpenURL(content::OpenURLParams(
62 GURL(GetLearnMoreURL()), content::Referrer(),
63 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition,
64 content::PAGE_TRANSITION_LINK, false));
65 return false;
66 }
67
LoadBlockedPlugins()68 void PluginInfoBarDelegate::LoadBlockedPlugins() {
69 content::RenderViewHost* host = web_contents()->GetRenderViewHost();
70 ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins(
71 host->GetProcess()->GetID());
72 host->Send(new ChromeViewMsg_LoadBlockedPlugins(
73 host->GetRoutingID(), identifier_));
74 }
75
GetIconID() const76 int PluginInfoBarDelegate::GetIconID() const {
77 return IDR_INFOBAR_PLUGIN_INSTALL;
78 }
79
GetLinkText() const80 base::string16 PluginInfoBarDelegate::GetLinkText() const {
81 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
82 }
83
84
85 // UnauthorizedPluginInfoBarDelegate ------------------------------------------
86
87 // static
Create(InfoBarService * infobar_service,HostContentSettingsMap * content_settings,const base::string16 & name,const std::string & identifier)88 void UnauthorizedPluginInfoBarDelegate::Create(
89 InfoBarService* infobar_service,
90 HostContentSettingsMap* content_settings,
91 const base::string16& name,
92 const std::string& identifier) {
93 infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar(
94 scoped_ptr<ConfirmInfoBarDelegate>(new UnauthorizedPluginInfoBarDelegate(
95 content_settings, name, identifier))));
96
97 content::RecordAction(UserMetricsAction("BlockedPluginInfobar.Shown"));
98 std::string utf8_name(UTF16ToUTF8(name));
99 if (utf8_name == PluginMetadata::kJavaGroupName) {
100 content::RecordAction(UserMetricsAction("BlockedPluginInfobar.Shown.Java"));
101 } else if (utf8_name == PluginMetadata::kQuickTimeGroupName) {
102 content::RecordAction(
103 UserMetricsAction("BlockedPluginInfobar.Shown.QuickTime"));
104 } else if (utf8_name == PluginMetadata::kShockwaveGroupName) {
105 content::RecordAction(
106 UserMetricsAction("BlockedPluginInfobar.Shown.Shockwave"));
107 } else if (utf8_name == PluginMetadata::kRealPlayerGroupName) {
108 content::RecordAction(
109 UserMetricsAction("BlockedPluginInfobar.Shown.RealPlayer"));
110 } else if (utf8_name == PluginMetadata::kWindowsMediaPlayerGroupName) {
111 content::RecordAction(
112 UserMetricsAction("BlockedPluginInfobar.Shown.WindowsMediaPlayer"));
113 }
114 }
115
UnauthorizedPluginInfoBarDelegate(HostContentSettingsMap * content_settings,const base::string16 & name,const std::string & identifier)116 UnauthorizedPluginInfoBarDelegate::UnauthorizedPluginInfoBarDelegate(
117 HostContentSettingsMap* content_settings,
118 const base::string16& name,
119 const std::string& identifier)
120 : PluginInfoBarDelegate(identifier),
121 content_settings_(content_settings),
122 name_(name) {
123 }
124
~UnauthorizedPluginInfoBarDelegate()125 UnauthorizedPluginInfoBarDelegate::~UnauthorizedPluginInfoBarDelegate() {
126 content::RecordAction(UserMetricsAction("BlockedPluginInfobar.Closed"));
127 }
128
GetLearnMoreURL() const129 std::string UnauthorizedPluginInfoBarDelegate::GetLearnMoreURL() const {
130 return chrome::kBlockedPluginLearnMoreURL;
131 }
132
GetMessageText() const133 base::string16 UnauthorizedPluginInfoBarDelegate::GetMessageText() const {
134 return l10n_util::GetStringFUTF16(IDS_PLUGIN_NOT_AUTHORIZED, name_);
135 }
136
GetButtonLabel(InfoBarButton button) const137 base::string16 UnauthorizedPluginInfoBarDelegate::GetButtonLabel(
138 InfoBarButton button) const {
139 return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
140 IDS_PLUGIN_ENABLE_TEMPORARILY : IDS_PLUGIN_ENABLE_ALWAYS);
141 }
142
Accept()143 bool UnauthorizedPluginInfoBarDelegate::Accept() {
144 content::RecordAction(
145 UserMetricsAction("BlockedPluginInfobar.AllowThisTime"));
146 LoadBlockedPlugins();
147 return true;
148 }
149
Cancel()150 bool UnauthorizedPluginInfoBarDelegate::Cancel() {
151 content::RecordAction(UserMetricsAction("BlockedPluginInfobar.AlwaysAllow"));
152 const GURL& url = web_contents()->GetURL();
153 content_settings_->AddExceptionForURL(url, url, CONTENT_SETTINGS_TYPE_PLUGINS,
154 CONTENT_SETTING_ALLOW);
155 LoadBlockedPlugins();
156 return true;
157 }
158
InfoBarDismissed()159 void UnauthorizedPluginInfoBarDelegate::InfoBarDismissed() {
160 content::RecordAction(UserMetricsAction("BlockedPluginInfobar.Dismissed"));
161 }
162
LinkClicked(WindowOpenDisposition disposition)163 bool UnauthorizedPluginInfoBarDelegate::LinkClicked(
164 WindowOpenDisposition disposition) {
165 content::RecordAction(UserMetricsAction("BlockedPluginInfobar.LearnMore"));
166 return PluginInfoBarDelegate::LinkClicked(disposition);
167 }
168
169
170 #if defined(ENABLE_PLUGIN_INSTALLATION)
171
172 // OutdatedPluginInfoBarDelegate ----------------------------------------------
173
Create(InfoBarService * infobar_service,PluginInstaller * installer,scoped_ptr<PluginMetadata> plugin_metadata)174 void OutdatedPluginInfoBarDelegate::Create(
175 InfoBarService* infobar_service,
176 PluginInstaller* installer,
177 scoped_ptr<PluginMetadata> plugin_metadata) {
178 // Copy the name out of |plugin_metadata| now, since the Pass() call below
179 // will make it impossible to get at.
180 base::string16 name(plugin_metadata->name());
181 infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar(
182 scoped_ptr<ConfirmInfoBarDelegate>(new OutdatedPluginInfoBarDelegate(
183 installer, plugin_metadata.Pass(), l10n_util::GetStringFUTF16(
184 (installer->state() == PluginInstaller::INSTALLER_STATE_IDLE) ?
185 IDS_PLUGIN_OUTDATED_PROMPT : IDS_PLUGIN_DOWNLOADING,
186 name)))));
187 }
188
OutdatedPluginInfoBarDelegate(PluginInstaller * installer,scoped_ptr<PluginMetadata> plugin_metadata,const base::string16 & message)189 OutdatedPluginInfoBarDelegate::OutdatedPluginInfoBarDelegate(
190 PluginInstaller* installer,
191 scoped_ptr<PluginMetadata> plugin_metadata,
192 const base::string16& message)
193 : PluginInfoBarDelegate(plugin_metadata->identifier()),
194 WeakPluginInstallerObserver(installer),
195 plugin_metadata_(plugin_metadata.Pass()),
196 message_(message) {
197 content::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Shown"));
198 std::string name = UTF16ToUTF8(plugin_metadata_->name());
199 if (name == PluginMetadata::kJavaGroupName) {
200 content::RecordAction(
201 UserMetricsAction("OutdatedPluginInfobar.Shown.Java"));
202 } else if (name == PluginMetadata::kQuickTimeGroupName) {
203 content::RecordAction(
204 UserMetricsAction("OutdatedPluginInfobar.Shown.QuickTime"));
205 } else if (name == PluginMetadata::kShockwaveGroupName) {
206 content::RecordAction(
207 UserMetricsAction("OutdatedPluginInfobar.Shown.Shockwave"));
208 } else if (name == PluginMetadata::kRealPlayerGroupName) {
209 content::RecordAction(
210 UserMetricsAction("OutdatedPluginInfobar.Shown.RealPlayer"));
211 } else if (name == PluginMetadata::kSilverlightGroupName) {
212 content::RecordAction(
213 UserMetricsAction("OutdatedPluginInfobar.Shown.Silverlight"));
214 } else if (name == PluginMetadata::kAdobeReaderGroupName) {
215 content::RecordAction(
216 UserMetricsAction("OutdatedPluginInfobar.Shown.Reader"));
217 }
218 }
219
~OutdatedPluginInfoBarDelegate()220 OutdatedPluginInfoBarDelegate::~OutdatedPluginInfoBarDelegate() {
221 content::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Closed"));
222 }
223
GetLearnMoreURL() const224 std::string OutdatedPluginInfoBarDelegate::GetLearnMoreURL() const {
225 return chrome::kOutdatedPluginLearnMoreURL;
226 }
227
GetMessageText() const228 base::string16 OutdatedPluginInfoBarDelegate::GetMessageText() const {
229 return message_;
230 }
231
GetButtonLabel(InfoBarButton button) const232 base::string16 OutdatedPluginInfoBarDelegate::GetButtonLabel(
233 InfoBarButton button) const {
234 return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
235 IDS_PLUGIN_UPDATE : IDS_PLUGIN_ENABLE_TEMPORARILY);
236 }
237
Accept()238 bool OutdatedPluginInfoBarDelegate::Accept() {
239 DCHECK_EQ(PluginInstaller::INSTALLER_STATE_IDLE, installer()->state());
240 content::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Update"));
241 // A call to any of |OpenDownloadURL()| or |StartInstalling()| will
242 // result in deleting ourselves. Accordingly, we make sure to
243 // not pass a reference to an object that can go away.
244 GURL plugin_url(plugin_metadata_->plugin_url());
245 if (plugin_metadata_->url_for_display())
246 installer()->OpenDownloadURL(plugin_url, web_contents());
247 else
248 installer()->StartInstalling(plugin_url, web_contents());
249 return false;
250 }
251
Cancel()252 bool OutdatedPluginInfoBarDelegate::Cancel() {
253 content::RecordAction(
254 UserMetricsAction("OutdatedPluginInfobar.AllowThisTime"));
255 LoadBlockedPlugins();
256 return true;
257 }
258
InfoBarDismissed()259 void OutdatedPluginInfoBarDelegate::InfoBarDismissed() {
260 content::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Dismissed"));
261 }
262
LinkClicked(WindowOpenDisposition disposition)263 bool OutdatedPluginInfoBarDelegate::LinkClicked(
264 WindowOpenDisposition disposition) {
265 content::RecordAction(UserMetricsAction("OutdatedPluginInfobar.LearnMore"));
266 return PluginInfoBarDelegate::LinkClicked(disposition);
267 }
268
DownloadStarted()269 void OutdatedPluginInfoBarDelegate::DownloadStarted() {
270 ReplaceWithInfoBar(l10n_util::GetStringFUTF16(IDS_PLUGIN_DOWNLOADING,
271 plugin_metadata_->name()));
272 }
273
DownloadError(const std::string & message)274 void OutdatedPluginInfoBarDelegate::DownloadError(const std::string& message) {
275 ReplaceWithInfoBar(l10n_util::GetStringFUTF16(IDS_PLUGIN_DOWNLOAD_ERROR_SHORT,
276 plugin_metadata_->name()));
277 }
278
DownloadCancelled()279 void OutdatedPluginInfoBarDelegate::DownloadCancelled() {
280 ReplaceWithInfoBar(l10n_util::GetStringFUTF16(IDS_PLUGIN_DOWNLOAD_CANCELLED,
281 plugin_metadata_->name()));
282 }
283
DownloadFinished()284 void OutdatedPluginInfoBarDelegate::DownloadFinished() {
285 ReplaceWithInfoBar(l10n_util::GetStringFUTF16(IDS_PLUGIN_UPDATING,
286 plugin_metadata_->name()));
287 }
288
OnlyWeakObserversLeft()289 void OutdatedPluginInfoBarDelegate::OnlyWeakObserversLeft() {
290 infobar()->RemoveSelf();
291 }
292
ReplaceWithInfoBar(const base::string16 & message)293 void OutdatedPluginInfoBarDelegate::ReplaceWithInfoBar(
294 const base::string16& message) {
295 // Return early if the message doesn't change. This is important in case the
296 // PluginInstaller is still iterating over its observers (otherwise we would
297 // keep replacing infobar delegates infinitely).
298 if ((message_ == message) || !infobar()->owner())
299 return;
300 PluginInstallerInfoBarDelegate::Replace(
301 infobar(), installer(), plugin_metadata_->Clone(), false, message);
302 }
303
304
305 // PluginInstallerInfoBarDelegate ---------------------------------------------
306
Create(InfoBarService * infobar_service,PluginInstaller * installer,scoped_ptr<PluginMetadata> plugin_metadata,const InstallCallback & callback)307 void PluginInstallerInfoBarDelegate::Create(
308 InfoBarService* infobar_service,
309 PluginInstaller* installer,
310 scoped_ptr<PluginMetadata> plugin_metadata,
311 const InstallCallback& callback) {
312 base::string16 name(plugin_metadata->name());
313 #if defined(OS_WIN)
314 if (base::win::IsMetroProcess()) {
315 PluginMetroModeInfoBarDelegate::Create(
316 infobar_service, PluginMetroModeInfoBarDelegate::MISSING_PLUGIN, name);
317 return;
318 }
319 #endif
320 infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar(
321 scoped_ptr<ConfirmInfoBarDelegate>(new PluginInstallerInfoBarDelegate(
322 installer, plugin_metadata.Pass(), callback, true,
323 l10n_util::GetStringFUTF16(
324 (installer->state() == PluginInstaller::INSTALLER_STATE_IDLE) ?
325 IDS_PLUGININSTALLER_INSTALLPLUGIN_PROMPT :
326 IDS_PLUGIN_DOWNLOADING,
327 name)))));
328 }
329
330
Replace(InfoBar * infobar,PluginInstaller * installer,scoped_ptr<PluginMetadata> plugin_metadata,bool new_install,const base::string16 & message)331 void PluginInstallerInfoBarDelegate::Replace(
332 InfoBar* infobar,
333 PluginInstaller* installer,
334 scoped_ptr<PluginMetadata> plugin_metadata,
335 bool new_install,
336 const base::string16& message) {
337 DCHECK(infobar->owner());
338 infobar->owner()->ReplaceInfoBar(infobar,
339 ConfirmInfoBarDelegate::CreateInfoBar(scoped_ptr<ConfirmInfoBarDelegate>(
340 new PluginInstallerInfoBarDelegate(
341 installer, plugin_metadata.Pass(),
342 PluginInstallerInfoBarDelegate::InstallCallback(), new_install,
343 message))));
344 }
345
PluginInstallerInfoBarDelegate(PluginInstaller * installer,scoped_ptr<PluginMetadata> plugin_metadata,const InstallCallback & callback,bool new_install,const base::string16 & message)346 PluginInstallerInfoBarDelegate::PluginInstallerInfoBarDelegate(
347 PluginInstaller* installer,
348 scoped_ptr<PluginMetadata> plugin_metadata,
349 const InstallCallback& callback,
350 bool new_install,
351 const base::string16& message)
352 : ConfirmInfoBarDelegate(),
353 WeakPluginInstallerObserver(installer),
354 plugin_metadata_(plugin_metadata.Pass()),
355 callback_(callback),
356 new_install_(new_install),
357 message_(message) {
358 }
359
~PluginInstallerInfoBarDelegate()360 PluginInstallerInfoBarDelegate::~PluginInstallerInfoBarDelegate() {
361 }
362
GetIconID() const363 int PluginInstallerInfoBarDelegate::GetIconID() const {
364 return IDR_INFOBAR_PLUGIN_INSTALL;
365 }
366
GetMessageText() const367 base::string16 PluginInstallerInfoBarDelegate::GetMessageText() const {
368 return message_;
369 }
370
GetButtons() const371 int PluginInstallerInfoBarDelegate::GetButtons() const {
372 return callback_.is_null() ? BUTTON_NONE : BUTTON_OK;
373 }
374
GetButtonLabel(InfoBarButton button) const375 base::string16 PluginInstallerInfoBarDelegate::GetButtonLabel(
376 InfoBarButton button) const {
377 DCHECK_EQ(BUTTON_OK, button);
378 return l10n_util::GetStringUTF16(IDS_PLUGININSTALLER_INSTALLPLUGIN_BUTTON);
379 }
380
Accept()381 bool PluginInstallerInfoBarDelegate::Accept() {
382 callback_.Run(plugin_metadata_.get());
383 return false;
384 }
385
GetLinkText() const386 base::string16 PluginInstallerInfoBarDelegate::GetLinkText() const {
387 return l10n_util::GetStringUTF16(new_install_ ?
388 IDS_PLUGININSTALLER_PROBLEMSINSTALLING :
389 IDS_PLUGININSTALLER_PROBLEMSUPDATING);
390 }
391
LinkClicked(WindowOpenDisposition disposition)392 bool PluginInstallerInfoBarDelegate::LinkClicked(
393 WindowOpenDisposition disposition) {
394 GURL url(plugin_metadata_->help_url());
395 if (url.is_empty()) {
396 url = google_util::AppendGoogleLocaleParam(GURL(
397 "https://www.google.com/support/chrome/bin/answer.py?answer=142064"));
398 }
399 web_contents()->OpenURL(content::OpenURLParams(
400 url, content::Referrer(),
401 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition,
402 content::PAGE_TRANSITION_LINK, false));
403 return false;
404 }
405
DownloadStarted()406 void PluginInstallerInfoBarDelegate::DownloadStarted() {
407 ReplaceWithInfoBar(l10n_util::GetStringFUTF16(IDS_PLUGIN_DOWNLOADING,
408 plugin_metadata_->name()));
409 }
410
DownloadCancelled()411 void PluginInstallerInfoBarDelegate::DownloadCancelled() {
412 ReplaceWithInfoBar(l10n_util::GetStringFUTF16(IDS_PLUGIN_DOWNLOAD_CANCELLED,
413 plugin_metadata_->name()));
414 }
415
DownloadError(const std::string & message)416 void PluginInstallerInfoBarDelegate::DownloadError(const std::string& message) {
417 ReplaceWithInfoBar(l10n_util::GetStringFUTF16(IDS_PLUGIN_DOWNLOAD_ERROR_SHORT,
418 plugin_metadata_->name()));
419 }
420
DownloadFinished()421 void PluginInstallerInfoBarDelegate::DownloadFinished() {
422 ReplaceWithInfoBar(
423 l10n_util::GetStringFUTF16(
424 new_install_ ? IDS_PLUGIN_INSTALLING : IDS_PLUGIN_UPDATING,
425 plugin_metadata_->name()));
426 }
427
OnlyWeakObserversLeft()428 void PluginInstallerInfoBarDelegate::OnlyWeakObserversLeft() {
429 infobar()->RemoveSelf();
430 }
431
ReplaceWithInfoBar(const base::string16 & message)432 void PluginInstallerInfoBarDelegate::ReplaceWithInfoBar(
433 const base::string16& message) {
434 // Return early if the message doesn't change. This is important in case the
435 // PluginInstaller is still iterating over its observers (otherwise we would
436 // keep replacing infobar delegates infinitely).
437 if ((message_ == message) || !infobar()->owner())
438 return;
439 Replace(infobar(), installer(), plugin_metadata_->Clone(), new_install_,
440 message);
441 }
442
443
444 #if defined(OS_WIN)
445
446 // PluginMetroModeInfoBarDelegate ---------------------------------------------
447
448 // static
Create(InfoBarService * infobar_service,PluginMetroModeInfoBarDelegate::Mode mode,const base::string16 & name)449 void PluginMetroModeInfoBarDelegate::Create(
450 InfoBarService* infobar_service,
451 PluginMetroModeInfoBarDelegate::Mode mode,
452 const base::string16& name) {
453 infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar(
454 scoped_ptr<ConfirmInfoBarDelegate>(
455 new PluginMetroModeInfoBarDelegate(mode, name))));
456 }
457
PluginMetroModeInfoBarDelegate(PluginMetroModeInfoBarDelegate::Mode mode,const base::string16 & name)458 PluginMetroModeInfoBarDelegate::PluginMetroModeInfoBarDelegate(
459 PluginMetroModeInfoBarDelegate::Mode mode,
460 const base::string16& name)
461 : ConfirmInfoBarDelegate(),
462 mode_(mode),
463 name_(name) {
464 }
465
~PluginMetroModeInfoBarDelegate()466 PluginMetroModeInfoBarDelegate::~PluginMetroModeInfoBarDelegate() {
467 }
468
GetIconID() const469 int PluginMetroModeInfoBarDelegate::GetIconID() const {
470 return IDR_INFOBAR_PLUGIN_INSTALL;
471 }
472
GetMessageText() const473 base::string16 PluginMetroModeInfoBarDelegate::GetMessageText() const {
474 return l10n_util::GetStringFUTF16((mode_ == MISSING_PLUGIN) ?
475 IDS_METRO_MISSING_PLUGIN_PROMPT : IDS_METRO_NPAPI_PLUGIN_PROMPT, name_);
476 }
477
GetButtons() const478 int PluginMetroModeInfoBarDelegate::GetButtons() const {
479 return BUTTON_OK;
480 }
481
GetButtonLabel(InfoBarButton button) const482 base::string16 PluginMetroModeInfoBarDelegate::GetButtonLabel(
483 InfoBarButton button) const {
484 #if defined(USE_AURA) && defined(USE_ASH)
485 return l10n_util::GetStringUTF16(IDS_WIN8_DESKTOP_RESTART);
486 #else
487 return l10n_util::GetStringUTF16((mode_ == MISSING_PLUGIN) ?
488 IDS_WIN8_DESKTOP_RESTART : IDS_WIN8_DESKTOP_OPEN);
489 #endif
490 }
491
492 #if defined(USE_AURA) && defined(USE_ASH)
LaunchDesktopInstanceHelper(const base::string16 & url)493 void LaunchDesktopInstanceHelper(const base::string16& url) {
494 base::FilePath exe_path;
495 if (!PathService::Get(base::FILE_EXE, &exe_path))
496 return;
497 base::FilePath shortcut_path(
498 ShellIntegration::GetStartMenuShortcut(exe_path));
499
500 // Actually launching the process needs to happen in the metro viewer,
501 // otherwise it won't automatically transition to desktop. So we have
502 // to send an IPC to the viewer to do the ShellExecute.
503 aura::RemoteRootWindowHostWin::Instance()->HandleOpenURLOnDesktop(
504 shortcut_path, url);
505 }
506 #endif
507
Accept()508 bool PluginMetroModeInfoBarDelegate::Accept() {
509 chrome::AttemptRestartToDesktopMode();
510 return true;
511 }
512
GetLinkText() const513 base::string16 PluginMetroModeInfoBarDelegate::GetLinkText() const {
514 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
515 }
516
LinkClicked(WindowOpenDisposition disposition)517 bool PluginMetroModeInfoBarDelegate::LinkClicked(
518 WindowOpenDisposition disposition) {
519 // TODO(shrikant): We may need to change language a little at following
520 // support URLs. With new approach we will just restart for both missing
521 // and not missing mode.
522 web_contents()->OpenURL(content::OpenURLParams(
523 GURL((mode_ == MISSING_PLUGIN) ?
524 "https://support.google.com/chrome/?p=ib_display_in_desktop" :
525 "https://support.google.com/chrome/?p=ib_redirect_to_desktop"),
526 content::Referrer(),
527 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition,
528 content::PAGE_TRANSITION_LINK, false));
529 return false;
530 }
531
532 #endif // defined(OS_WIN)
533
534 #endif // defined(ENABLE_PLUGIN_INSTALLATION)
535