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

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

Issue 2154773002: Implement Just-In-Time Flash updates. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Through #27 + lint/format + offline comments Created 4 years, 4 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
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/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
13 #include "base/stl_util.h" 14 #include "base/stl_util.h"
14 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
15 #include "build/build_config.h" 16 #include "build/build_config.h"
16 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/infobars/infobar_service.h" 18 #include "chrome/browser/infobars/infobar_service.h"
18 #include "chrome/browser/lifetime/application_lifetime.h" 19 #include "chrome/browser/lifetime/application_lifetime.h"
19 #include "chrome/browser/plugins/plugin_finder.h" 20 #include "chrome/browser/plugins/plugin_finder.h"
20 #include "chrome/browser/plugins/plugin_infobar_delegates.h" 21 #include "chrome/browser/plugins/plugin_infobar_delegates.h"
21 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/ui/tab_modal_confirm_dialog.h" 23 #include "chrome/browser/ui/tab_modal_confirm_dialog.h"
23 #include "chrome/common/render_messages.h" 24 #include "chrome/common/render_messages.h"
24 #include "chrome/common/url_constants.h" 25 #include "chrome/common/url_constants.h"
25 #include "chrome/grit/generated_resources.h" 26 #include "chrome/grit/generated_resources.h"
27 #include "components/component_updater/component_updater_service.h"
26 #include "components/content_settings/content/common/content_settings_messages.h " 28 #include "components/content_settings/content/common/content_settings_messages.h "
27 #include "components/content_settings/core/browser/host_content_settings_map.h" 29 #include "components/content_settings/core/browser/host_content_settings_map.h"
28 #include "components/infobars/core/confirm_infobar_delegate.h" 30 #include "components/infobars/core/confirm_infobar_delegate.h"
29 #include "components/infobars/core/infobar.h" 31 #include "components/infobars/core/infobar.h"
30 #include "components/infobars/core/infobar_delegate.h" 32 #include "components/infobars/core/infobar_delegate.h"
31 #include "components/infobars/core/simple_alert_infobar_delegate.h" 33 #include "components/infobars/core/simple_alert_infobar_delegate.h"
32 #include "components/metrics_services_manager/metrics_services_manager.h" 34 #include "components/metrics_services_manager/metrics_services_manager.h"
33 #include "content/public/browser/plugin_service.h" 35 #include "content/public/browser/plugin_service.h"
34 #include "content/public/browser/render_frame_host.h" 36 #include "content/public/browser/render_frame_host.h"
35 #include "content/public/browser/render_view_host.h" 37 #include "content/public/browser/render_view_host.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 std::unique_ptr<ConfirmInfoBarDelegate>( 159 std::unique_ptr<ConfirmInfoBarDelegate>(
158 new ReloadPluginInfoBarDelegate(controller, message)))); 160 new ReloadPluginInfoBarDelegate(controller, message))));
159 } 161 }
160 162
161 ReloadPluginInfoBarDelegate::ReloadPluginInfoBarDelegate( 163 ReloadPluginInfoBarDelegate::ReloadPluginInfoBarDelegate(
162 content::NavigationController* controller, 164 content::NavigationController* controller,
163 const base::string16& message) 165 const base::string16& message)
164 : controller_(controller), 166 : controller_(controller),
165 message_(message) {} 167 message_(message) {}
166 168
167 ReloadPluginInfoBarDelegate::~ReloadPluginInfoBarDelegate(){ } 169 ReloadPluginInfoBarDelegate::~ReloadPluginInfoBarDelegate() { }
168 170
169 infobars::InfoBarDelegate::InfoBarIdentifier 171 infobars::InfoBarDelegate::InfoBarIdentifier
170 ReloadPluginInfoBarDelegate::GetIdentifier() const { 172 ReloadPluginInfoBarDelegate::GetIdentifier() const {
171 return RELOAD_PLUGIN_INFOBAR_DELEGATE; 173 return RELOAD_PLUGIN_INFOBAR_DELEGATE;
172 } 174 }
173 175
174 int ReloadPluginInfoBarDelegate::GetIconId() const { 176 int ReloadPluginInfoBarDelegate::GetIconId() const {
175 return IDR_INFOBAR_PLUGIN_CRASHED; 177 return IDR_INFOBAR_PLUGIN_CRASHED;
176 } 178 }
177 179
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 } 250 }
249 251
250 private: 252 private:
251 // Weak pointer; owns us. 253 // Weak pointer; owns us.
252 PluginObserver* observer_; 254 PluginObserver* observer_;
253 255
254 int routing_id_; 256 int routing_id_;
255 }; 257 };
256 #endif // defined(ENABLE_PLUGIN_INSTALLATION) 258 #endif // defined(ENABLE_PLUGIN_INSTALLATION)
257 259
260 PluginObserver::ComponentObserver::ComponentObserver(
261 PluginObserver* observer,
262 int routing_id,
263 const std::string& component_id)
264 : observer_(observer),
265 routing_id_(routing_id),
266 component_id_(component_id) {}
267
268 void PluginObserver::ComponentObserver::OnEvent(Events event,
269 const std::string& id) {
270 if (id != component_id_)
271 return;
272 switch (event) {
273 case Events::COMPONENT_UPDATED:
274 observer_->Send(
275 new ChromeViewMsg_PluginComponentUpdateSuccess(routing_id_));
276 observer_->RemoveComponentObserver(routing_id_);
277 break;
278 case Events::COMPONENT_UPDATE_FOUND:
279 observer_->Send(
280 new ChromeViewMsg_PluginComponentUpdateDownloading(routing_id_));
281 break;
282 case Events::COMPONENT_NOT_UPDATED:
283 observer_->Send(
284 new ChromeViewMsg_PluginComponentUpdateFailure(routing_id_));
285 observer_->RemoveComponentObserver(routing_id_);
286 break;
287 default:
288 // No message to send.
289 break;
290 }
291 }
292
258 PluginObserver::PluginObserver(content::WebContents* web_contents) 293 PluginObserver::PluginObserver(content::WebContents* web_contents)
259 : content::WebContentsObserver(web_contents), 294 : content::WebContentsObserver(web_contents),
260 weak_ptr_factory_(this) { 295 weak_ptr_factory_(this) {
261 } 296 }
262 297
263 PluginObserver::~PluginObserver() { 298 PluginObserver::~PluginObserver() {
264 #if defined(ENABLE_PLUGIN_INSTALLATION) 299 #if defined(ENABLE_PLUGIN_INSTALLATION)
265 STLDeleteValues(&plugin_placeholders_); 300 STLDeleteValues(&plugin_placeholders_);
266 #endif 301 #endif
302 auto cus = g_browser_process->component_updater();
303 for (const auto& observer : component_observers_) {
304 cus->RemoveObserver(observer.second.get());
305 }
267 } 306 }
268 307
269 void PluginObserver::PluginCrashed(const base::FilePath& plugin_path, 308 void PluginObserver::PluginCrashed(const base::FilePath& plugin_path,
270 base::ProcessId plugin_pid) { 309 base::ProcessId plugin_pid) {
271 DCHECK(!plugin_path.value().empty()); 310 DCHECK(!plugin_path.value().empty());
272 311
273 base::string16 plugin_name = 312 base::string16 plugin_name =
274 PluginService::GetInstance()->GetPluginDisplayNameByPath(plugin_path); 313 PluginService::GetInstance()->GetPluginDisplayNameByPath(plugin_path);
275 base::string16 infobar_text; 314 base::string16 infobar_text;
276 #if defined(OS_WIN) 315 #if defined(OS_WIN)
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 &web_contents()->GetController(), 353 &web_contents()->GetController(),
315 infobar_text); 354 infobar_text);
316 } 355 }
317 356
318 bool PluginObserver::OnMessageReceived( 357 bool PluginObserver::OnMessageReceived(
319 const IPC::Message& message, 358 const IPC::Message& message,
320 content::RenderFrameHost* render_frame_host) { 359 content::RenderFrameHost* render_frame_host) {
321 IPC_BEGIN_MESSAGE_MAP(PluginObserver, message) 360 IPC_BEGIN_MESSAGE_MAP(PluginObserver, message)
322 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_BlockedOutdatedPlugin, 361 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_BlockedOutdatedPlugin,
323 OnBlockedOutdatedPlugin) 362 OnBlockedOutdatedPlugin)
363 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_BlockedComponentUpdatedPlugin,
364 OnBlockedComponentUpdatedPlugin)
324 #if defined(ENABLE_PLUGIN_INSTALLATION) 365 #if defined(ENABLE_PLUGIN_INSTALLATION)
325 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RemovePluginPlaceholderHost, 366 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RemovePluginPlaceholderHost,
326 OnRemovePluginPlaceholderHost) 367 OnRemovePluginPlaceholderHost)
327 #endif 368 #endif
328 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_OpenAboutPlugins, 369 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_OpenAboutPlugins,
329 OnOpenAboutPlugins) 370 OnOpenAboutPlugins)
330 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_CouldNotLoadPlugin, 371 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_CouldNotLoadPlugin,
331 OnCouldNotLoadPlugin) 372 OnCouldNotLoadPlugin)
332 373
333 IPC_MESSAGE_UNHANDLED(return false) 374 IPC_MESSAGE_UNHANDLED(return false)
(...skipping 18 matching lines...) Expand all
352 } else { 393 } else {
353 NOTREACHED(); 394 NOTREACHED();
354 } 395 }
355 #else 396 #else
356 // If we don't support third-party plugin installation, we shouldn't have 397 // If we don't support third-party plugin installation, we shouldn't have
357 // outdated plugins. 398 // outdated plugins.
358 NOTREACHED(); 399 NOTREACHED();
359 #endif // defined(ENABLE_PLUGIN_INSTALLATION) 400 #endif // defined(ENABLE_PLUGIN_INSTALLATION)
360 } 401 }
361 402
403 void PluginObserver::OnBlockedComponentUpdatedPlugin(
404 int placeholder_id,
405 const std::string& identifier) {
406 auto observer = new ComponentObserver(this, placeholder_id, identifier);
Sorin Jianu 2016/07/28 21:04:05 Clarify the ownership of the ComponentObserver by
waffles 2016/07/28 23:05:52 Done.
407 component_observers_[placeholder_id] =
408 base::WrapUnique<ComponentObserver>(observer);
409 component_updater::ComponentUpdateService* cus =
410 g_browser_process->component_updater();
411 cus->AddObserver(observer);
412 cus->GetOnDemandUpdater().OnDemandUpdate(identifier);
413 }
414
415 void PluginObserver::RemoveComponentObserver(int placeholder_id) {
416 auto it = component_observers_.find(placeholder_id);
417 if (it == component_observers_.end()) {
418 NOTREACHED();
Sorin Jianu 2016/07/28 21:04:05 https://chromium.googlesource.com/chromium/src/+/m
waffles 2016/07/28 23:05:52 Done.
Bernhard Bauer 2016/07/29 09:14:24 I would be careful there -- this is handling an IP
waffles 2016/07/29 21:07:25 In this case, RemoveComponentObserver is only trig
Bernhard Bauer 2016/08/01 09:30:39 Oh, right. Cool!
419 return;
420 }
421 g_browser_process->component_updater()->RemoveObserver(it->second.get());
422 component_observers_.erase(it);
423 }
424
362 #if defined(ENABLE_PLUGIN_INSTALLATION) 425 #if defined(ENABLE_PLUGIN_INSTALLATION)
363 void PluginObserver::OnRemovePluginPlaceholderHost(int placeholder_id) { 426 void PluginObserver::OnRemovePluginPlaceholderHost(int placeholder_id) {
364 std::map<int, PluginPlaceholderHost*>::iterator it = 427 std::map<int, PluginPlaceholderHost*>::iterator it =
365 plugin_placeholders_.find(placeholder_id); 428 plugin_placeholders_.find(placeholder_id);
366 if (it == plugin_placeholders_.end()) { 429 if (it == plugin_placeholders_.end()) {
367 NOTREACHED(); 430 NOTREACHED();
368 return; 431 return;
369 } 432 }
370 delete it->second; 433 delete it->second;
371 plugin_placeholders_.erase(it); 434 plugin_placeholders_.erase(it);
(...skipping 21 matching lines...) Expand all
393 IDR_INFOBAR_PLUGIN_CRASHED, 456 IDR_INFOBAR_PLUGIN_CRASHED,
394 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) 457 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
395 gfx::VectorIconId::EXTENSION_CRASHED, 458 gfx::VectorIconId::EXTENSION_CRASHED,
396 #else 459 #else
397 gfx::VectorIconId::VECTOR_ICON_NONE, 460 gfx::VectorIconId::VECTOR_ICON_NONE,
398 #endif 461 #endif
399 l10n_util::GetStringFUTF16(IDS_PLUGIN_INITIALIZATION_ERROR_PROMPT, 462 l10n_util::GetStringFUTF16(IDS_PLUGIN_INITIALIZATION_ERROR_PROMPT,
400 plugin_name), 463 plugin_name),
401 true); 464 true);
402 } 465 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698