Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(536)

Side by Side Diff: chrome/browser/plugin_observer.cc

Issue 8851007: WIP / Do not commit (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/plugin_observer.h ('k') | chrome/browser/plugin_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/plugin_observer.h" 5 #include "chrome/browser/plugin_observer.h"
6 6
7 #include "base/auto_reset.h"
7 #include "base/bind.h" 8 #include "base/bind.h"
8 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/content_settings/host_content_settings_map.h" 11 #include "chrome/browser/content_settings/host_content_settings_map.h"
11 #include "chrome/browser/google/google_util.h" 12 #include "chrome/browser/google/google_util.h"
12 #include "chrome/browser/infobars/infobar_tab_helper.h" 13 #include "chrome/browser/infobars/infobar_tab_helper.h"
13 #include "chrome/browser/plugin_finder.h" 14 #include "chrome/browser/plugin_finder.h"
14 #include "chrome/browser/plugin_installer.h" 15 #include "chrome/browser/plugin_installer.h"
15 #include "chrome/browser/plugin_installer_infobar_delegate.h" 16 #include "chrome/browser/plugin_installer_infobar_delegate.h"
17 #include "chrome/browser/plugin_installer_observer.h"
16 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" 19 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h"
18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 20 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
21 #include "chrome/browser/ui/tab_modal_dialog_delegate.h"
19 #include "chrome/common/render_messages.h" 22 #include "chrome/common/render_messages.h"
20 #include "chrome/common/url_constants.h" 23 #include "chrome/common/url_constants.h"
21 #include "content/browser/renderer_host/render_view_host.h" 24 #include "content/browser/renderer_host/render_view_host.h"
22 #include "content/browser/tab_contents/tab_contents.h" 25 #include "content/browser/tab_contents/tab_contents.h"
23 #include "content/browser/tab_contents/tab_contents_delegate.h" 26 #include "content/browser/tab_contents/tab_contents_delegate.h"
24 #include "content/browser/user_metrics.h" 27 #include "content/browser/user_metrics.h"
25 #include "grit/generated_resources.h" 28 #include "grit/generated_resources.h"
26 #include "grit/theme_resources_standard.h" 29 #include "grit/theme_resources_standard.h"
30 #include "grit/theme_resources.h"
27 #include "ui/base/l10n/l10n_util.h" 31 #include "ui/base/l10n/l10n_util.h"
28 #include "ui/base/resource/resource_bundle.h" 32 #include "ui/base/resource/resource_bundle.h"
29 #include "webkit/plugins/npapi/plugin_group.h" 33 #include "webkit/plugins/npapi/plugin_group.h"
30 #include "webkit/plugins/webplugininfo.h" 34 #include "webkit/plugins/webplugininfo.h"
35 #include "../webkit/grit/webkit_strings.h" // XXX
31 36
32 namespace { 37 namespace {
33 38
34 // PluginInfoBarDelegate ------------------------------------------------------ 39 // PluginInfoBarDelegate ------------------------------------------------------
35 40
36 class PluginInfoBarDelegate : public ConfirmInfoBarDelegate { 41 class PluginInfoBarDelegate : public ConfirmInfoBarDelegate {
37 public: 42 public:
38 PluginInfoBarDelegate(InfoBarTabHelper* infobar_helper, const string16& name); 43 PluginInfoBarDelegate(InfoBarTabHelper* infobar_helper, const string16& name);
39 44
40 protected: 45 protected:
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 UserMetricsAction("OutdatedPluginInfobar.Dismissed")); 279 UserMetricsAction("OutdatedPluginInfobar.Dismissed"));
275 } 280 }
276 281
277 bool OutdatedPluginInfoBarDelegate::LinkClicked( 282 bool OutdatedPluginInfoBarDelegate::LinkClicked(
278 WindowOpenDisposition disposition) { 283 WindowOpenDisposition disposition) {
279 UserMetrics::RecordAction( 284 UserMetrics::RecordAction(
280 UserMetricsAction("OutdatedPluginInfobar.LearnMore")); 285 UserMetricsAction("OutdatedPluginInfobar.LearnMore"));
281 return PluginInfoBarDelegate::LinkClicked(disposition); 286 return PluginInfoBarDelegate::LinkClicked(disposition);
282 } 287 }
283 288
289 class ConfirmInstallDialogDelegate : public TabModalDialogDelegate,
290 public PluginInstallerObserver {
291 public:
292 ConfirmInstallDialogDelegate(TabContents* tab_contents,
293 PluginInstaller* installer);
294
295 // TabModalDialogDelegate methods:
296 virtual string16 GetTitle() OVERRIDE;
297 virtual string16 GetMessage() OVERRIDE;
298 virtual string16 GetAcceptButtonTitle() OVERRIDE;
299 virtual string16 GetCancelButtonTitle() OVERRIDE;
300 virtual void OnAccepted() OVERRIDE;
301 virtual void OnCanceled() OVERRIDE;
302
303 // PluginInstallerObserver methods:
304 virtual void DidStartDownload() OVERRIDE;
305
306 private:
307 net::URLRequestContextGetter* request_context_;
308 bool installing_;
309 };
310
311 ConfirmInstallDialogDelegate::ConfirmInstallDialogDelegate(
312 TabContents* tab_contents,
313 PluginInstaller* installer)
314 : TabModalDialogDelegate(tab_contents),
315 PluginInstallerObserver(installer),
316 request_context_(tab_contents->browser_context()->GetRequestContext()),
317 installing_(false) {
318 }
319
320 string16 ConfirmInstallDialogDelegate::GetTitle() {
321 return l10n_util::GetStringFUTF16(
322 IDS_DEFAULT_PLUGIN_CONFIRMATION_DIALOG_TITLE, installer()->name());
323 }
324
325 string16 ConfirmInstallDialogDelegate::GetMessage() {
326 return l10n_util::GetStringFUTF16(IDS_DEFAULT_PLUGIN_USER_OPTION_MSG,
327 installer()->name());
328 }
329
330 string16 ConfirmInstallDialogDelegate::GetAcceptButtonTitle() {
331 return l10n_util::GetStringUTF16(IDS_DEFAULT_PLUGIN_GET_THE_PLUGIN_BTN_MSG);
332 }
333
334 string16 ConfirmInstallDialogDelegate::GetCancelButtonTitle() {
335 return l10n_util::GetStringUTF16(
336 IDS_DEFAULT_PLUGIN_CANCEL_PLUGIN_DOWNLOAD_MSG);
337 }
338
339 void ConfirmInstallDialogDelegate::OnAccepted() {
340 AutoReset<bool> auto_reset(&installing_, true);
341 installer()->StartInstalling(request_context_);
342 }
343
344 void ConfirmInstallDialogDelegate::OnCanceled() {
345 }
346
347 void ConfirmInstallDialogDelegate::DidStartDownload() {
348 if (!installing_)
349 Cancel();
350 }
351
284 } // namespace 352 } // namespace
285 353
354 // PluginObserver -------------------------------------------------------------
286 355
287 // PluginObserver ------------------------------------------------------------- 356 class PluginObserver::MissingPluginHost : public PluginInstallerObserver {
357 public:
358 MissingPluginHost(PluginObserver* observer,
359 int routing_id,
360 PluginInstaller* installer)
361 : PluginInstallerObserver(installer),
362 observer_(observer),
363 routing_id_(routing_id) {
364 switch (installer->state()) {
365 case PluginInstaller::kStateIdle: {
366 observer->Send(new ChromeViewMsg_FoundMissingPlugin(routing_id_,
367 installer->name()));
368 break;
369 }
370 case PluginInstaller::kStateDownloading: {
371 DidStartDownload();
372 break;
373 }
374 case PluginInstaller::kStateInstalling: {
375 DidFinishDownload();
376 break;
377 }
378 }
379 }
380
381 // PluginInstallerObserver methods:
382 virtual void DidStartDownload() OVERRIDE {
383 observer_->Send(new ChromeViewMsg_StartedDownloadingPlugin(routing_id_));
384 }
385
386 virtual void DidFinishDownload() OVERRIDE {
387 observer_->Send(new ChromeViewMsg_FinishedDownloadingPlugin(routing_id_));
388 }
389
390 virtual void DidFinishInstallation() OVERRIDE {
391 LOG(ERROR) << "DidFinishInstallation";
392 }
393
394 private:
395 // Weak pointer; owns us.
396 PluginObserver* observer_;
397
398 int routing_id_;
399 };
288 400
289 PluginObserver::PluginObserver(TabContentsWrapper* tab_contents) 401 PluginObserver::PluginObserver(TabContentsWrapper* tab_contents)
290 : TabContentsObserver(tab_contents->tab_contents()), 402 : TabContentsObserver(tab_contents->tab_contents()),
291 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), 403 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)),
292 tab_contents_(tab_contents) { 404 tab_contents_(tab_contents) {
293 } 405 }
294 406
295 PluginObserver::~PluginObserver() { 407 PluginObserver::~PluginObserver() {
296 } 408 }
297 409
(...skipping 28 matching lines...) Expand all
326 mime_type, lang, 438 mime_type, lang,
327 base::Bind(&PluginObserver::FoundMissingPlugin, 439 base::Bind(&PluginObserver::FoundMissingPlugin,
328 weak_ptr_factory_.GetWeakPtr(), placeholder_id, mime_type), 440 weak_ptr_factory_.GetWeakPtr(), placeholder_id, mime_type),
329 base::Bind(&PluginObserver::DidNotFindMissingPlugin, 441 base::Bind(&PluginObserver::DidNotFindMissingPlugin,
330 weak_ptr_factory_.GetWeakPtr(), placeholder_id, mime_type)); 442 weak_ptr_factory_.GetWeakPtr(), placeholder_id, mime_type));
331 } 443 }
332 444
333 void PluginObserver::FoundMissingPlugin(int placeholder_id, 445 void PluginObserver::FoundMissingPlugin(int placeholder_id,
334 const std::string& mime_type, 446 const std::string& mime_type,
335 PluginInstaller* installer) { 447 PluginInstaller* installer) {
336 Send(new ChromeViewMsg_FoundMissingPlugin(placeholder_id, installer->name())); 448 missing_plugins_.push_back(
449 new MissingPluginHost(this, placeholder_id, installer));
337 InfoBarTabHelper* infobar_helper = tab_contents_->infobar_tab_helper(); 450 InfoBarTabHelper* infobar_helper = tab_contents_->infobar_tab_helper();
338 infobar_helper->AddInfoBar(new PluginInstallerInfoBarDelegate( 451 PluginInstallerInfoBarDelegate* delegate = new PluginInstallerInfoBarDelegate(
452 installer,
339 infobar_helper, 453 infobar_helper,
340 installer->name(), 454 installer->name(),
341 installer->help_url(), 455 installer->help_url(),
342 base::Bind(&PluginObserver::InstallMissingPlugin, 456 base::Bind(&PluginObserver::InstallMissingPlugin,
343 weak_ptr_factory_.GetWeakPtr(), installer))); 457 weak_ptr_factory_.GetWeakPtr(), installer));
458 infobar_helper->AddInfoBar(delegate);
344 } 459 }
345 460
346 void PluginObserver::DidNotFindMissingPlugin(int placeholder_id, 461 void PluginObserver::DidNotFindMissingPlugin(int placeholder_id,
347 const std::string& mime_type) { 462 const std::string& mime_type) {
348 Send(new ChromeViewMsg_DidNotFindMissingPlugin(placeholder_id)); 463 Send(new ChromeViewMsg_DidNotFindMissingPlugin(placeholder_id));
349 } 464 }
350 465
351 void PluginObserver::InstallMissingPlugin(PluginInstaller* installer) { 466 void PluginObserver::InstallMissingPlugin(PluginInstaller* installer) {
352 if (installer->url_for_display()) { 467 if (installer->url_for_display()) {
353 tab_contents()->OpenURL(OpenURLParams( 468 tab_contents()->OpenURL(OpenURLParams(
354 installer->plugin_url(), 469 installer->plugin_url(),
355 content::Referrer(tab_contents()->GetURL(), 470 content::Referrer(tab_contents()->GetURL(),
356 WebKit::WebReferrerPolicyDefault), 471 WebKit::WebReferrerPolicyDefault),
357 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_TYPED, false)); 472 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_TYPED, false));
358 } else { 473 } else {
359 NOTIMPLEMENTED(); 474 TabModalDialogDelegate* delegate =
475 new ConfirmInstallDialogDelegate(tab_contents(), installer);
476 tab_contents()->delegate()->ShowTabModalDialog(delegate, tab_contents());
360 } 477 }
361 } 478 }
OLDNEW
« no previous file with comments | « chrome/browser/plugin_observer.h ('k') | chrome/browser/plugin_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698