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

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: git pull && gclient sync 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
« no previous file with comments | « chrome/browser/plugins/plugin_observer.h ('k') | chrome/common/render_messages.h » ('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/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 class PluginObserver::ComponentObserver
261 : public update_client::UpdateClient::Observer {
262 public:
263 using Events = update_client::UpdateClient::Observer::Events;
264 ComponentObserver(PluginObserver* observer,
265 int routing_id,
266 const std::string& component_id)
267 : observer_(observer),
268 routing_id_(routing_id),
269 component_id_(component_id) {
270 g_browser_process->component_updater()->AddObserver(this);
271 }
272
273 ~ComponentObserver() override {
274 g_browser_process->component_updater()->RemoveObserver(this);
275 }
276
277 void OnEvent(Events event, const std::string& id) override {
278 if (id != component_id_)
279 return;
280 switch (event) {
281 case Events::COMPONENT_UPDATED:
282 observer_->Send(
283 new ChromeViewMsg_PluginComponentUpdateSuccess(routing_id_));
284 observer_->RemoveComponentObserver(routing_id_);
285 break;
286 case Events::COMPONENT_UPDATE_FOUND:
287 observer_->Send(
288 new ChromeViewMsg_PluginComponentUpdateDownloading(routing_id_));
289 break;
290 case Events::COMPONENT_NOT_UPDATED:
291 observer_->Send(
292 new ChromeViewMsg_PluginComponentUpdateFailure(routing_id_));
293 observer_->RemoveComponentObserver(routing_id_);
294 break;
295 default:
296 // No message to send.
297 break;
298 }
299 }
300
301 private:
302 PluginObserver* observer_;
303 int routing_id_;
304 std::string component_id_;
305 DISALLOW_COPY_AND_ASSIGN(ComponentObserver);
306 };
307
258 PluginObserver::PluginObserver(content::WebContents* web_contents) 308 PluginObserver::PluginObserver(content::WebContents* web_contents)
259 : content::WebContentsObserver(web_contents), 309 : content::WebContentsObserver(web_contents),
260 weak_ptr_factory_(this) { 310 weak_ptr_factory_(this) {
261 } 311 }
262 312
263 PluginObserver::~PluginObserver() { 313 PluginObserver::~PluginObserver() {
264 #if defined(ENABLE_PLUGIN_INSTALLATION) 314 #if defined(ENABLE_PLUGIN_INSTALLATION)
265 STLDeleteValues(&plugin_placeholders_); 315 STLDeleteValues(&plugin_placeholders_);
266 #endif 316 #endif
267 } 317 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 &web_contents()->GetController(), 364 &web_contents()->GetController(),
315 infobar_text); 365 infobar_text);
316 } 366 }
317 367
318 bool PluginObserver::OnMessageReceived( 368 bool PluginObserver::OnMessageReceived(
319 const IPC::Message& message, 369 const IPC::Message& message,
320 content::RenderFrameHost* render_frame_host) { 370 content::RenderFrameHost* render_frame_host) {
321 IPC_BEGIN_MESSAGE_MAP(PluginObserver, message) 371 IPC_BEGIN_MESSAGE_MAP(PluginObserver, message)
322 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_BlockedOutdatedPlugin, 372 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_BlockedOutdatedPlugin,
323 OnBlockedOutdatedPlugin) 373 OnBlockedOutdatedPlugin)
374 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_BlockedComponentUpdatedPlugin,
375 OnBlockedComponentUpdatedPlugin)
324 #if defined(ENABLE_PLUGIN_INSTALLATION) 376 #if defined(ENABLE_PLUGIN_INSTALLATION)
325 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RemovePluginPlaceholderHost, 377 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RemovePluginPlaceholderHost,
326 OnRemovePluginPlaceholderHost) 378 OnRemovePluginPlaceholderHost)
327 #endif 379 #endif
328 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_OpenAboutPlugins, 380 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_OpenAboutPlugins,
329 OnOpenAboutPlugins) 381 OnOpenAboutPlugins)
330 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_CouldNotLoadPlugin, 382 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_CouldNotLoadPlugin,
331 OnCouldNotLoadPlugin) 383 OnCouldNotLoadPlugin)
332 384
333 IPC_MESSAGE_UNHANDLED(return false) 385 IPC_MESSAGE_UNHANDLED(return false)
(...skipping 18 matching lines...) Expand all
352 } else { 404 } else {
353 NOTREACHED(); 405 NOTREACHED();
354 } 406 }
355 #else 407 #else
356 // If we don't support third-party plugin installation, we shouldn't have 408 // If we don't support third-party plugin installation, we shouldn't have
357 // outdated plugins. 409 // outdated plugins.
358 NOTREACHED(); 410 NOTREACHED();
359 #endif // defined(ENABLE_PLUGIN_INSTALLATION) 411 #endif // defined(ENABLE_PLUGIN_INSTALLATION)
360 } 412 }
361 413
414 void PluginObserver::OnBlockedComponentUpdatedPlugin(
415 int placeholder_id,
416 const std::string& identifier) {
417 component_observers_[placeholder_id] =
418 base::MakeUnique<ComponentObserver>(this, placeholder_id, identifier);
419 g_browser_process->component_updater()->GetOnDemandUpdater().OnDemandUpdate(
420 identifier);
421 }
422
423 void PluginObserver::RemoveComponentObserver(int placeholder_id) {
424 auto it = component_observers_.find(placeholder_id);
425 DCHECK(it != component_observers_.end());
426 component_observers_.erase(it);
427 }
428
362 #if defined(ENABLE_PLUGIN_INSTALLATION) 429 #if defined(ENABLE_PLUGIN_INSTALLATION)
363 void PluginObserver::OnRemovePluginPlaceholderHost(int placeholder_id) { 430 void PluginObserver::OnRemovePluginPlaceholderHost(int placeholder_id) {
364 std::map<int, PluginPlaceholderHost*>::iterator it = 431 std::map<int, PluginPlaceholderHost*>::iterator it =
365 plugin_placeholders_.find(placeholder_id); 432 plugin_placeholders_.find(placeholder_id);
366 if (it == plugin_placeholders_.end()) { 433 if (it == plugin_placeholders_.end()) {
367 NOTREACHED(); 434 NOTREACHED();
368 return; 435 return;
369 } 436 }
370 delete it->second; 437 delete it->second;
371 plugin_placeholders_.erase(it); 438 plugin_placeholders_.erase(it);
(...skipping 21 matching lines...) Expand all
393 IDR_INFOBAR_PLUGIN_CRASHED, 460 IDR_INFOBAR_PLUGIN_CRASHED,
394 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) 461 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
395 gfx::VectorIconId::EXTENSION_CRASHED, 462 gfx::VectorIconId::EXTENSION_CRASHED,
396 #else 463 #else
397 gfx::VectorIconId::VECTOR_ICON_NONE, 464 gfx::VectorIconId::VECTOR_ICON_NONE,
398 #endif 465 #endif
399 l10n_util::GetStringFUTF16(IDS_PLUGIN_INITIALIZATION_ERROR_PROMPT, 466 l10n_util::GetStringFUTF16(IDS_PLUGIN_INITIALIZATION_ERROR_PROMPT,
400 plugin_name), 467 plugin_name),
401 true); 468 true);
402 } 469 }
OLDNEW
« no previous file with comments | « chrome/browser/plugins/plugin_observer.h ('k') | chrome/common/render_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698