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

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

Issue 2405013002: Move some global feature defines to buildflags (Closed)
Patch Set: Comment Created 4 years, 2 months 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
« no previous file with comments | « chrome/browser/plugins/plugin_observer.h ('k') | chrome/browser/prefs/browser_prefs.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) 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/plugins/plugin_observer.h" 5 #include "chrome/browser/plugins/plugin_observer.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/debug/crash_logging.h" 11 #include "base/debug/crash_logging.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/metrics/histogram_macros.h" 13 #include "base/metrics/histogram_macros.h"
14 #include "base/stl_util.h" 14 #include "base/stl_util.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "build/build_config.h" 16 #include "build/build_config.h"
17 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/infobars/infobar_service.h" 18 #include "chrome/browser/infobars/infobar_service.h"
19 #include "chrome/browser/lifetime/application_lifetime.h" 19 #include "chrome/browser/lifetime/application_lifetime.h"
20 #include "chrome/browser/plugins/flash_download_interception.h" 20 #include "chrome/browser/plugins/flash_download_interception.h"
21 #include "chrome/browser/plugins/plugin_finder.h" 21 #include "chrome/browser/plugins/plugin_finder.h"
22 #include "chrome/browser/plugins/plugin_infobar_delegates.h" 22 #include "chrome/browser/plugins/plugin_infobar_delegates.h"
23 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/ui/tab_modal_confirm_dialog.h" 24 #include "chrome/browser/ui/tab_modal_confirm_dialog.h"
25 #include "chrome/common/features.h"
25 #include "chrome/common/render_messages.h" 26 #include "chrome/common/render_messages.h"
26 #include "chrome/common/url_constants.h" 27 #include "chrome/common/url_constants.h"
27 #include "chrome/grit/generated_resources.h" 28 #include "chrome/grit/generated_resources.h"
28 #include "chrome/grit/theme_resources.h" 29 #include "chrome/grit/theme_resources.h"
29 #include "components/component_updater/component_updater_service.h" 30 #include "components/component_updater/component_updater_service.h"
30 #include "components/content_settings/core/browser/host_content_settings_map.h" 31 #include "components/content_settings/core/browser/host_content_settings_map.h"
31 #include "components/infobars/core/confirm_infobar_delegate.h" 32 #include "components/infobars/core/confirm_infobar_delegate.h"
32 #include "components/infobars/core/infobar.h" 33 #include "components/infobars/core/infobar.h"
33 #include "components/infobars/core/infobar_delegate.h" 34 #include "components/infobars/core/infobar_delegate.h"
34 #include "components/infobars/core/simple_alert_infobar_delegate.h" 35 #include "components/infobars/core/simple_alert_infobar_delegate.h"
35 #include "components/metrics_services_manager/metrics_services_manager.h" 36 #include "components/metrics_services_manager/metrics_services_manager.h"
36 #include "content/public/browser/browser_thread.h" 37 #include "content/public/browser/browser_thread.h"
37 #include "content/public/browser/plugin_service.h" 38 #include "content/public/browser/plugin_service.h"
38 #include "content/public/browser/render_frame_host.h" 39 #include "content/public/browser/render_frame_host.h"
39 #include "content/public/browser/render_view_host.h" 40 #include "content/public/browser/render_view_host.h"
40 #include "content/public/browser/web_contents.h" 41 #include "content/public/browser/web_contents.h"
41 #include "content/public/browser/web_contents_delegate.h" 42 #include "content/public/browser/web_contents_delegate.h"
42 #include "content/public/common/webplugininfo.h" 43 #include "content/public/common/webplugininfo.h"
43 #include "ui/base/l10n/l10n_util.h" 44 #include "ui/base/l10n/l10n_util.h"
44 #include "ui/gfx/vector_icons_public.h" 45 #include "ui/gfx/vector_icons_public.h"
45 46
46 #if defined(ENABLE_PLUGIN_INSTALLATION) 47 #if BUILDFLAG(ENABLE_PLUGIN_INSTALLATION)
47 #include "chrome/browser/plugins/plugin_installer.h" 48 #include "chrome/browser/plugins/plugin_installer.h"
48 #include "chrome/browser/plugins/plugin_installer_observer.h" 49 #include "chrome/browser/plugins/plugin_installer_observer.h"
49 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" 50 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h"
50 #endif // defined(ENABLE_PLUGIN_INSTALLATION) 51 #endif // BUILDFLAG(ENABLE_PLUGIN_INSTALLATION)
51 52
52 using content::OpenURLParams; 53 using content::OpenURLParams;
53 using content::PluginService; 54 using content::PluginService;
54 using content::Referrer; 55 using content::Referrer;
55 using content::WebContents; 56 using content::WebContents;
56 57
57 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PluginObserver); 58 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PluginObserver);
58 59
59 namespace { 60 namespace {
60 61
61 #if defined(ENABLE_PLUGIN_INSTALLATION) 62 #if BUILDFLAG(ENABLE_PLUGIN_INSTALLATION)
62 63
63 // ConfirmInstallDialogDelegate ------------------------------------------------ 64 // ConfirmInstallDialogDelegate ------------------------------------------------
64 65
65 class ConfirmInstallDialogDelegate : public TabModalConfirmDialogDelegate, 66 class ConfirmInstallDialogDelegate : public TabModalConfirmDialogDelegate,
66 public WeakPluginInstallerObserver { 67 public WeakPluginInstallerObserver {
67 public: 68 public:
68 ConfirmInstallDialogDelegate(content::WebContents* web_contents, 69 ConfirmInstallDialogDelegate(content::WebContents* web_contents,
69 PluginInstaller* installer, 70 PluginInstaller* installer,
70 std::unique_ptr<PluginMetadata> plugin_metadata); 71 std::unique_ptr<PluginMetadata> plugin_metadata);
71 72
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 void ConfirmInstallDialogDelegate::OnCanceled() { 117 void ConfirmInstallDialogDelegate::OnCanceled() {
117 } 118 }
118 119
119 void ConfirmInstallDialogDelegate::DownloadStarted() { 120 void ConfirmInstallDialogDelegate::DownloadStarted() {
120 Cancel(); 121 Cancel();
121 } 122 }
122 123
123 void ConfirmInstallDialogDelegate::OnlyWeakObserversLeft() { 124 void ConfirmInstallDialogDelegate::OnlyWeakObserversLeft() {
124 Cancel(); 125 Cancel();
125 } 126 }
126 #endif // defined(ENABLE_PLUGIN_INSTALLATION) 127 #endif // BUILDFLAG(ENABLE_PLUGIN_INSTALLATION)
127 128
128 // ReloadPluginInfoBarDelegate ------------------------------------------------- 129 // ReloadPluginInfoBarDelegate -------------------------------------------------
129 130
130 class ReloadPluginInfoBarDelegate : public ConfirmInfoBarDelegate { 131 class ReloadPluginInfoBarDelegate : public ConfirmInfoBarDelegate {
131 public: 132 public:
132 static void Create(InfoBarService* infobar_service, 133 static void Create(InfoBarService* infobar_service,
133 content::NavigationController* controller, 134 content::NavigationController* controller,
134 const base::string16& message); 135 const base::string16& message);
135 136
136 private: 137 private:
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 194
194 bool ReloadPluginInfoBarDelegate::Accept() { 195 bool ReloadPluginInfoBarDelegate::Accept() {
195 controller_->Reload(true); 196 controller_->Reload(true);
196 return true; 197 return true;
197 } 198 }
198 199
199 } // namespace 200 } // namespace
200 201
201 // PluginObserver ------------------------------------------------------------- 202 // PluginObserver -------------------------------------------------------------
202 203
203 #if defined(ENABLE_PLUGIN_INSTALLATION) 204 #if BUILDFLAG(ENABLE_PLUGIN_INSTALLATION)
204 class PluginObserver::PluginPlaceholderHost : public PluginInstallerObserver { 205 class PluginObserver::PluginPlaceholderHost : public PluginInstallerObserver {
205 public: 206 public:
206 PluginPlaceholderHost(PluginObserver* observer, 207 PluginPlaceholderHost(PluginObserver* observer,
207 int routing_id, 208 int routing_id,
208 base::string16 plugin_name, 209 base::string16 plugin_name,
209 PluginInstaller* installer) 210 PluginInstaller* installer)
210 : PluginInstallerObserver(installer), 211 : PluginInstallerObserver(installer),
211 observer_(observer), 212 observer_(observer),
212 routing_id_(routing_id) { 213 routing_id_(routing_id) {
213 DCHECK(installer); 214 DCHECK(installer);
(...skipping 26 matching lines...) Expand all
240 void DownloadFinished() override { 241 void DownloadFinished() override {
241 observer_->Send(new ChromeViewMsg_FinishedDownloadingPlugin(routing_id_)); 242 observer_->Send(new ChromeViewMsg_FinishedDownloadingPlugin(routing_id_));
242 } 243 }
243 244
244 private: 245 private:
245 // Weak pointer; owns us. 246 // Weak pointer; owns us.
246 PluginObserver* observer_; 247 PluginObserver* observer_;
247 248
248 int routing_id_; 249 int routing_id_;
249 }; 250 };
250 #endif // defined(ENABLE_PLUGIN_INSTALLATION) 251 #endif // BUILDFLAG(ENABLE_PLUGIN_INSTALLATION)
251 252
252 class PluginObserver::ComponentObserver 253 class PluginObserver::ComponentObserver
253 : public update_client::UpdateClient::Observer { 254 : public update_client::UpdateClient::Observer {
254 public: 255 public:
255 using Events = update_client::UpdateClient::Observer::Events; 256 using Events = update_client::UpdateClient::Observer::Events;
256 ComponentObserver(PluginObserver* observer, 257 ComponentObserver(PluginObserver* observer,
257 int routing_id, 258 int routing_id,
258 const std::string& component_id) 259 const std::string& component_id)
259 : observer_(observer), 260 : observer_(observer),
260 routing_id_(routing_id), 261 routing_id_(routing_id),
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 std::string component_id_; 297 std::string component_id_;
297 DISALLOW_COPY_AND_ASSIGN(ComponentObserver); 298 DISALLOW_COPY_AND_ASSIGN(ComponentObserver);
298 }; 299 };
299 300
300 PluginObserver::PluginObserver(content::WebContents* web_contents) 301 PluginObserver::PluginObserver(content::WebContents* web_contents)
301 : content::WebContentsObserver(web_contents), 302 : content::WebContentsObserver(web_contents),
302 weak_ptr_factory_(this) { 303 weak_ptr_factory_(this) {
303 } 304 }
304 305
305 PluginObserver::~PluginObserver() { 306 PluginObserver::~PluginObserver() {
306 #if defined(ENABLE_PLUGIN_INSTALLATION) 307 #if BUILDFLAG(ENABLE_PLUGIN_INSTALLATION)
307 base::STLDeleteValues(&plugin_placeholders_); 308 base::STLDeleteValues(&plugin_placeholders_);
308 #endif 309 #endif
309 } 310 }
310 311
311 void PluginObserver::PluginCrashed(const base::FilePath& plugin_path, 312 void PluginObserver::PluginCrashed(const base::FilePath& plugin_path,
312 base::ProcessId plugin_pid) { 313 base::ProcessId plugin_pid) {
313 DCHECK(!plugin_path.value().empty()); 314 DCHECK(!plugin_path.value().empty());
314 315
315 base::string16 plugin_name = 316 base::string16 plugin_name =
316 PluginService::GetInstance()->GetPluginDisplayNameByPath(plugin_path); 317 PluginService::GetInstance()->GetPluginDisplayNameByPath(plugin_path);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 } 359 }
359 360
360 bool PluginObserver::OnMessageReceived( 361 bool PluginObserver::OnMessageReceived(
361 const IPC::Message& message, 362 const IPC::Message& message,
362 content::RenderFrameHost* render_frame_host) { 363 content::RenderFrameHost* render_frame_host) {
363 IPC_BEGIN_MESSAGE_MAP(PluginObserver, message) 364 IPC_BEGIN_MESSAGE_MAP(PluginObserver, message)
364 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_BlockedOutdatedPlugin, 365 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_BlockedOutdatedPlugin,
365 OnBlockedOutdatedPlugin) 366 OnBlockedOutdatedPlugin)
366 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_BlockedComponentUpdatedPlugin, 367 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_BlockedComponentUpdatedPlugin,
367 OnBlockedComponentUpdatedPlugin) 368 OnBlockedComponentUpdatedPlugin)
368 #if defined(ENABLE_PLUGIN_INSTALLATION) 369 #if BUILDFLAG(ENABLE_PLUGIN_INSTALLATION)
369 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RemovePluginPlaceholderHost, 370 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RemovePluginPlaceholderHost,
370 OnRemovePluginPlaceholderHost) 371 OnRemovePluginPlaceholderHost)
371 #endif 372 #endif
372 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_OpenAboutPlugins, 373 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_OpenAboutPlugins,
373 OnOpenAboutPlugins) 374 OnOpenAboutPlugins)
374 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ShowFlashPermissionBubble, 375 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ShowFlashPermissionBubble,
375 OnShowFlashPermissionBubble) 376 OnShowFlashPermissionBubble)
376 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_CouldNotLoadPlugin, 377 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_CouldNotLoadPlugin,
377 OnCouldNotLoadPlugin) 378 OnCouldNotLoadPlugin)
378 379
379 IPC_MESSAGE_UNHANDLED(return false) 380 IPC_MESSAGE_UNHANDLED(return false)
380 IPC_END_MESSAGE_MAP() 381 IPC_END_MESSAGE_MAP()
381 382
382 return true; 383 return true;
383 } 384 }
384 385
385 void PluginObserver::OnBlockedOutdatedPlugin(int placeholder_id, 386 void PluginObserver::OnBlockedOutdatedPlugin(int placeholder_id,
386 const std::string& identifier) { 387 const std::string& identifier) {
387 #if defined(ENABLE_PLUGIN_INSTALLATION) 388 #if BUILDFLAG(ENABLE_PLUGIN_INSTALLATION)
388 PluginFinder* finder = PluginFinder::GetInstance(); 389 PluginFinder* finder = PluginFinder::GetInstance();
389 // Find plugin to update. 390 // Find plugin to update.
390 PluginInstaller* installer = NULL; 391 PluginInstaller* installer = NULL;
391 std::unique_ptr<PluginMetadata> plugin; 392 std::unique_ptr<PluginMetadata> plugin;
392 if (finder->FindPluginWithIdentifier(identifier, &installer, &plugin)) { 393 if (finder->FindPluginWithIdentifier(identifier, &installer, &plugin)) {
393 plugin_placeholders_[placeholder_id] = new PluginPlaceholderHost( 394 plugin_placeholders_[placeholder_id] = new PluginPlaceholderHost(
394 this, placeholder_id, plugin->name(), installer); 395 this, placeholder_id, plugin->name(), installer);
395 OutdatedPluginInfoBarDelegate::Create( 396 OutdatedPluginInfoBarDelegate::Create(
396 InfoBarService::FromWebContents(web_contents()), installer, 397 InfoBarService::FromWebContents(web_contents()), installer,
397 std::move(plugin)); 398 std::move(plugin));
398 } else { 399 } else {
399 NOTREACHED(); 400 NOTREACHED();
400 } 401 }
401 #else 402 #else
402 // If we don't support third-party plugin installation, we shouldn't have 403 // If we don't support third-party plugin installation, we shouldn't have
403 // outdated plugins. 404 // outdated plugins.
404 NOTREACHED(); 405 NOTREACHED();
405 #endif // defined(ENABLE_PLUGIN_INSTALLATION) 406 #endif // BUILDFLAG(ENABLE_PLUGIN_INSTALLATION)
406 } 407 }
407 408
408 void PluginObserver::OnBlockedComponentUpdatedPlugin( 409 void PluginObserver::OnBlockedComponentUpdatedPlugin(
409 int placeholder_id, 410 int placeholder_id,
410 const std::string& identifier) { 411 const std::string& identifier) {
411 component_observers_[placeholder_id] = 412 component_observers_[placeholder_id] =
412 base::MakeUnique<ComponentObserver>(this, placeholder_id, identifier); 413 base::MakeUnique<ComponentObserver>(this, placeholder_id, identifier);
413 g_browser_process->component_updater()->GetOnDemandUpdater().OnDemandUpdate( 414 g_browser_process->component_updater()->GetOnDemandUpdater().OnDemandUpdate(
414 identifier, 415 identifier,
415 component_updater::ComponentUpdateService::CompletionCallback()); 416 component_updater::ComponentUpdateService::CompletionCallback());
416 } 417 }
417 418
418 void PluginObserver::RemoveComponentObserver(int placeholder_id) { 419 void PluginObserver::RemoveComponentObserver(int placeholder_id) {
419 auto it = component_observers_.find(placeholder_id); 420 auto it = component_observers_.find(placeholder_id);
420 DCHECK(it != component_observers_.end()); 421 DCHECK(it != component_observers_.end());
421 component_observers_.erase(it); 422 component_observers_.erase(it);
422 } 423 }
423 424
424 #if defined(ENABLE_PLUGIN_INSTALLATION) 425 #if BUILDFLAG(ENABLE_PLUGIN_INSTALLATION)
425 void PluginObserver::OnRemovePluginPlaceholderHost(int placeholder_id) { 426 void PluginObserver::OnRemovePluginPlaceholderHost(int placeholder_id) {
426 std::map<int, PluginPlaceholderHost*>::iterator it = 427 std::map<int, PluginPlaceholderHost*>::iterator it =
427 plugin_placeholders_.find(placeholder_id); 428 plugin_placeholders_.find(placeholder_id);
428 if (it == plugin_placeholders_.end()) { 429 if (it == plugin_placeholders_.end()) {
429 NOTREACHED(); 430 NOTREACHED();
430 return; 431 return;
431 } 432 }
432 delete it->second; 433 delete it->second;
433 plugin_placeholders_.erase(it); 434 plugin_placeholders_.erase(it);
434 } 435 }
435 #endif // defined(ENABLE_PLUGIN_INSTALLATION) 436 #endif // BUILDFLAG(ENABLE_PLUGIN_INSTALLATION)
436 437
437 void PluginObserver::OnOpenAboutPlugins() { 438 void PluginObserver::OnOpenAboutPlugins() {
438 web_contents()->OpenURL( 439 web_contents()->OpenURL(
439 OpenURLParams(GURL(chrome::kChromeUIPluginsURL), 440 OpenURLParams(GURL(chrome::kChromeUIPluginsURL),
440 content::Referrer::SanitizeForRequest( 441 content::Referrer::SanitizeForRequest(
441 GURL(chrome::kChromeUIPluginsURL), 442 GURL(chrome::kChromeUIPluginsURL),
442 content::Referrer(web_contents()->GetURL(), 443 content::Referrer(web_contents()->GetURL(),
443 blink::WebReferrerPolicyDefault)), 444 blink::WebReferrerPolicyDefault)),
444 WindowOpenDisposition::NEW_FOREGROUND_TAB, 445 WindowOpenDisposition::NEW_FOREGROUND_TAB,
445 ui::PAGE_TRANSITION_AUTO_BOOKMARK, false)); 446 ui::PAGE_TRANSITION_AUTO_BOOKMARK, false));
(...skipping 12 matching lines...) Expand all
458 base::string16 plugin_name = 459 base::string16 plugin_name =
459 PluginService::GetInstance()->GetPluginDisplayNameByPath(plugin_path); 460 PluginService::GetInstance()->GetPluginDisplayNameByPath(plugin_path);
460 SimpleAlertInfoBarDelegate::Create( 461 SimpleAlertInfoBarDelegate::Create(
461 InfoBarService::FromWebContents(web_contents()), 462 InfoBarService::FromWebContents(web_contents()),
462 infobars::InfoBarDelegate::PLUGIN_OBSERVER, 0, 463 infobars::InfoBarDelegate::PLUGIN_OBSERVER, 0,
463 gfx::VectorIconId::EXTENSION_CRASHED, 464 gfx::VectorIconId::EXTENSION_CRASHED,
464 l10n_util::GetStringFUTF16(IDS_PLUGIN_INITIALIZATION_ERROR_PROMPT, 465 l10n_util::GetStringFUTF16(IDS_PLUGIN_INITIALIZATION_ERROR_PROMPT,
465 plugin_name), 466 plugin_name),
466 true); 467 true);
467 } 468 }
OLDNEW
« no previous file with comments | « chrome/browser/plugins/plugin_observer.h ('k') | chrome/browser/prefs/browser_prefs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698