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

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

Issue 10961051: Switch PluginObserver to use WebContentsUserData. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: commentary Created 8 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/plugins/plugin_observer.h ('k') | chrome/browser/ui/tab_contents/tab_contents.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 "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 28 matching lines...) Expand all
39 39
40 #if defined(OS_WIN) 40 #if defined(OS_WIN)
41 #include "base/win/metro.h" 41 #include "base/win/metro.h"
42 #endif 42 #endif
43 43
44 using content::OpenURLParams; 44 using content::OpenURLParams;
45 using content::PluginService; 45 using content::PluginService;
46 using content::Referrer; 46 using content::Referrer;
47 using content::WebContents; 47 using content::WebContents;
48 48
49 int PluginObserver::kUserDataKey;
50
49 namespace { 51 namespace {
50 52
51 #if defined(ENABLE_PLUGIN_INSTALLATION) 53 #if defined(ENABLE_PLUGIN_INSTALLATION)
52 54
53 // ConfirmInstallDialogDelegate ------------------------------------------------ 55 // ConfirmInstallDialogDelegate ------------------------------------------------
54 56
55 class ConfirmInstallDialogDelegate : public TabModalConfirmDialogDelegate, 57 class ConfirmInstallDialogDelegate : public TabModalConfirmDialogDelegate,
56 public WeakPluginInstallerObserver { 58 public WeakPluginInstallerObserver {
57 public: 59 public:
58 ConfirmInstallDialogDelegate(TabContents* tab_contents, 60 ConfirmInstallDialogDelegate(content::WebContents* web_contents,
59 PluginInstaller* installer); 61 PluginInstaller* installer);
60 62
61 // TabModalConfirmDialogDelegate methods: 63 // TabModalConfirmDialogDelegate methods:
62 virtual string16 GetTitle() OVERRIDE; 64 virtual string16 GetTitle() OVERRIDE;
63 virtual string16 GetMessage() OVERRIDE; 65 virtual string16 GetMessage() OVERRIDE;
64 virtual string16 GetAcceptButtonTitle() OVERRIDE; 66 virtual string16 GetAcceptButtonTitle() OVERRIDE;
65 virtual void OnAccepted() OVERRIDE; 67 virtual void OnAccepted() OVERRIDE;
66 virtual void OnCanceled() OVERRIDE; 68 virtual void OnCanceled() OVERRIDE;
67 69
68 // WeakPluginInstallerObserver methods: 70 // WeakPluginInstallerObserver methods:
69 virtual void DownloadStarted() OVERRIDE; 71 virtual void DownloadStarted() OVERRIDE;
70 virtual void OnlyWeakObserversLeft() OVERRIDE; 72 virtual void OnlyWeakObserversLeft() OVERRIDE;
71 73
72 private: 74 private:
73 TabContents* tab_contents_; 75 content::WebContents* web_contents_;
74 }; 76 };
75 77
76 ConfirmInstallDialogDelegate::ConfirmInstallDialogDelegate( 78 ConfirmInstallDialogDelegate::ConfirmInstallDialogDelegate(
77 TabContents* tab_contents, 79 content::WebContents* web_contents,
78 PluginInstaller* installer) 80 PluginInstaller* installer)
79 : TabModalConfirmDialogDelegate(tab_contents->web_contents()), 81 : TabModalConfirmDialogDelegate(web_contents),
80 WeakPluginInstallerObserver(installer), 82 WeakPluginInstallerObserver(installer),
81 tab_contents_(tab_contents) { 83 web_contents_(web_contents) {
82 } 84 }
83 85
84 string16 ConfirmInstallDialogDelegate::GetTitle() { 86 string16 ConfirmInstallDialogDelegate::GetTitle() {
85 return l10n_util::GetStringFUTF16( 87 return l10n_util::GetStringFUTF16(
86 IDS_PLUGIN_CONFIRM_INSTALL_DIALOG_TITLE, installer()->name()); 88 IDS_PLUGIN_CONFIRM_INSTALL_DIALOG_TITLE, installer()->name());
87 } 89 }
88 90
89 string16 ConfirmInstallDialogDelegate::GetMessage() { 91 string16 ConfirmInstallDialogDelegate::GetMessage() {
90 return l10n_util::GetStringFUTF16(IDS_PLUGIN_CONFIRM_INSTALL_DIALOG_MSG, 92 return l10n_util::GetStringFUTF16(IDS_PLUGIN_CONFIRM_INSTALL_DIALOG_MSG,
91 installer()->name()); 93 installer()->name());
92 } 94 }
93 95
94 string16 ConfirmInstallDialogDelegate::GetAcceptButtonTitle() { 96 string16 ConfirmInstallDialogDelegate::GetAcceptButtonTitle() {
95 return l10n_util::GetStringUTF16( 97 return l10n_util::GetStringUTF16(
96 IDS_PLUGIN_CONFIRM_INSTALL_DIALOG_ACCEPT_BUTTON); 98 IDS_PLUGIN_CONFIRM_INSTALL_DIALOG_ACCEPT_BUTTON);
97 } 99 }
98 100
99 void ConfirmInstallDialogDelegate::OnAccepted() { 101 void ConfirmInstallDialogDelegate::OnAccepted() {
100 installer()->StartInstalling(tab_contents_); 102 installer()->StartInstalling(TabContents::FromWebContents(web_contents_));
101 } 103 }
102 104
103 void ConfirmInstallDialogDelegate::OnCanceled() { 105 void ConfirmInstallDialogDelegate::OnCanceled() {
104 } 106 }
105 107
106 void ConfirmInstallDialogDelegate::DownloadStarted() { 108 void ConfirmInstallDialogDelegate::DownloadStarted() {
107 Cancel(); 109 Cancel();
108 } 110 }
109 111
110 void ConfirmInstallDialogDelegate::OnlyWeakObserversLeft() { 112 void ConfirmInstallDialogDelegate::OnlyWeakObserversLeft() {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 } 159 }
158 160
159 private: 161 private:
160 // Weak pointer; owns us. 162 // Weak pointer; owns us.
161 PluginObserver* observer_; 163 PluginObserver* observer_;
162 164
163 int routing_id_; 165 int routing_id_;
164 }; 166 };
165 #endif // defined(ENABLE_PLUGIN_INSTALLATION) 167 #endif // defined(ENABLE_PLUGIN_INSTALLATION)
166 168
167 PluginObserver::PluginObserver(TabContents* tab_contents) 169 PluginObserver::PluginObserver(content::WebContents* web_contents)
168 : content::WebContentsObserver(tab_contents->web_contents()), 170 : content::WebContentsObserver(web_contents),
169 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), 171 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
170 tab_contents_(tab_contents) {
171 } 172 }
172 173
173 PluginObserver::~PluginObserver() { 174 PluginObserver::~PluginObserver() {
174 #if defined(ENABLE_PLUGIN_INSTALLATION) 175 #if defined(ENABLE_PLUGIN_INSTALLATION)
175 STLDeleteValues(&plugin_placeholders_); 176 STLDeleteValues(&plugin_placeholders_);
176 #endif 177 #endif
177 } 178 }
178 179
179 void PluginObserver::PluginCrashed(const FilePath& plugin_path) { 180 void PluginObserver::PluginCrashed(const FilePath& plugin_path) {
180 DCHECK(!plugin_path.value().empty()); 181 DCHECK(!plugin_path.value().empty());
181 182
182 string16 plugin_name = 183 string16 plugin_name =
183 PluginService::GetInstance()->GetPluginDisplayNameByPath(plugin_path); 184 PluginService::GetInstance()->GetPluginDisplayNameByPath(plugin_path);
184 gfx::Image* icon = &ResourceBundle::GetSharedInstance().GetNativeImageNamed( 185 gfx::Image* icon = &ResourceBundle::GetSharedInstance().GetNativeImageNamed(
185 IDR_INFOBAR_PLUGIN_CRASHED); 186 IDR_INFOBAR_PLUGIN_CRASHED);
186 InfoBarTabHelper* infobar_helper = tab_contents_->infobar_tab_helper(); 187 TabContents* tab_contents = TabContents::FromWebContents(web_contents());
188 InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper();
187 infobar_helper->AddInfoBar( 189 infobar_helper->AddInfoBar(
188 new SimpleAlertInfoBarDelegate( 190 new SimpleAlertInfoBarDelegate(
189 infobar_helper, 191 infobar_helper,
190 icon, 192 icon,
191 l10n_util::GetStringFUTF16(IDS_PLUGIN_CRASHED_PROMPT, plugin_name), 193 l10n_util::GetStringFUTF16(IDS_PLUGIN_CRASHED_PROMPT, plugin_name),
192 true)); 194 true));
193 } 195 }
194 196
195 bool PluginObserver::OnMessageReceived(const IPC::Message& message) { 197 bool PluginObserver::OnMessageReceived(const IPC::Message& message) {
196 IPC_BEGIN_MESSAGE_MAP(PluginObserver, message) 198 IPC_BEGIN_MESSAGE_MAP(PluginObserver, message)
(...skipping 14 matching lines...) Expand all
211 213
212 IPC_MESSAGE_UNHANDLED(return false) 214 IPC_MESSAGE_UNHANDLED(return false)
213 IPC_END_MESSAGE_MAP() 215 IPC_END_MESSAGE_MAP()
214 216
215 return true; 217 return true;
216 } 218 }
217 219
218 void PluginObserver::OnBlockedUnauthorizedPlugin( 220 void PluginObserver::OnBlockedUnauthorizedPlugin(
219 const string16& name, 221 const string16& name,
220 const std::string& identifier) { 222 const std::string& identifier) {
221 InfoBarTabHelper* infobar_helper = tab_contents_->infobar_tab_helper(); 223 TabContents* tab_contents = TabContents::FromWebContents(web_contents());
224 InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper();
222 infobar_helper->AddInfoBar( 225 infobar_helper->AddInfoBar(
223 new UnauthorizedPluginInfoBarDelegate( 226 new UnauthorizedPluginInfoBarDelegate(
224 infobar_helper, 227 infobar_helper,
225 tab_contents_->profile()->GetHostContentSettingsMap(), 228 tab_contents->profile()->GetHostContentSettingsMap(),
226 name, identifier)); 229 name, identifier));
227 } 230 }
228 231
229 void PluginObserver::OnBlockedOutdatedPlugin(int placeholder_id, 232 void PluginObserver::OnBlockedOutdatedPlugin(int placeholder_id,
230 const std::string& identifier) { 233 const std::string& identifier) {
231 #if defined(ENABLE_PLUGIN_INSTALLATION) 234 #if defined(ENABLE_PLUGIN_INSTALLATION)
232 PluginFinder::Get(base::Bind(&PluginObserver::FindPluginToUpdate, 235 PluginFinder::Get(base::Bind(&PluginObserver::FindPluginToUpdate,
233 weak_ptr_factory_.GetWeakPtr(), 236 weak_ptr_factory_.GetWeakPtr(),
234 placeholder_id, identifier)); 237 placeholder_id, identifier));
235 #else 238 #else
236 // If we don't support third-party plug-in installation, we shouldn't have 239 // If we don't support third-party plug-in installation, we shouldn't have
237 // outdated plug-ins. 240 // outdated plug-ins.
238 NOTREACHED(); 241 NOTREACHED();
239 #endif // defined(ENABLE_PLUGIN_INSTALLATION) 242 #endif // defined(ENABLE_PLUGIN_INSTALLATION)
240 } 243 }
241 244
242 #if defined(ENABLE_PLUGIN_INSTALLATION) 245 #if defined(ENABLE_PLUGIN_INSTALLATION)
243 void PluginObserver::FindPluginToUpdate(int placeholder_id, 246 void PluginObserver::FindPluginToUpdate(int placeholder_id,
244 const std::string& identifier, 247 const std::string& identifier,
245 PluginFinder* plugin_finder) { 248 PluginFinder* plugin_finder) {
246 PluginInstaller* installer = 249 PluginInstaller* installer =
247 plugin_finder->FindPluginWithIdentifier(identifier); 250 plugin_finder->FindPluginWithIdentifier(identifier);
248 DCHECK(installer) << "Couldn't find PluginInstaller for identifier " 251 DCHECK(installer) << "Couldn't find PluginInstaller for identifier "
249 << identifier; 252 << identifier;
250 plugin_placeholders_[placeholder_id] = 253 plugin_placeholders_[placeholder_id] =
251 new PluginPlaceholderHost(this, placeholder_id, installer); 254 new PluginPlaceholderHost(this, placeholder_id, installer);
252 InfoBarTabHelper* infobar_helper = tab_contents_->infobar_tab_helper(); 255 TabContents* tab_contents = TabContents::FromWebContents(web_contents());
256 InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper();
253 infobar_helper->AddInfoBar( 257 infobar_helper->AddInfoBar(
254 OutdatedPluginInfoBarDelegate::Create(this, installer)); 258 OutdatedPluginInfoBarDelegate::Create(this, installer));
255 } 259 }
256 260
257 void PluginObserver::OnFindMissingPlugin(int placeholder_id, 261 void PluginObserver::OnFindMissingPlugin(int placeholder_id,
258 const std::string& mime_type) { 262 const std::string& mime_type) {
259 PluginFinder::Get(base::Bind(&PluginObserver::FindMissingPlugin, 263 PluginFinder::Get(base::Bind(&PluginObserver::FindMissingPlugin,
260 weak_ptr_factory_.GetWeakPtr(), 264 weak_ptr_factory_.GetWeakPtr(),
261 placeholder_id, mime_type)); 265 placeholder_id, mime_type));
262 } 266 }
263 267
264 void PluginObserver::FindMissingPlugin(int placeholder_id, 268 void PluginObserver::FindMissingPlugin(int placeholder_id,
265 const std::string& mime_type, 269 const std::string& mime_type,
266 PluginFinder* plugin_finder) { 270 PluginFinder* plugin_finder) {
267 std::string lang = "en-US"; // Oh yes. 271 std::string lang = "en-US"; // Oh yes.
268 PluginInstaller* installer = plugin_finder->FindPlugin(mime_type, lang); 272 PluginInstaller* installer = plugin_finder->FindPlugin(mime_type, lang);
269 if (!installer) { 273 if (!installer) {
270 Send(new ChromeViewMsg_DidNotFindMissingPlugin(placeholder_id)); 274 Send(new ChromeViewMsg_DidNotFindMissingPlugin(placeholder_id));
271 return; 275 return;
272 } 276 }
273 277
274 plugin_placeholders_[placeholder_id] = 278 plugin_placeholders_[placeholder_id] =
275 new PluginPlaceholderHost(this, placeholder_id, installer); 279 new PluginPlaceholderHost(this, placeholder_id, installer);
276 InfoBarTabHelper* infobar_helper = tab_contents_->infobar_tab_helper(); 280 TabContents* tab_contents = TabContents::FromWebContents(web_contents());
281 InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper();
277 InfoBarDelegate* delegate; 282 InfoBarDelegate* delegate;
278 #if !defined(OS_WIN) 283 #if !defined(OS_WIN)
279 delegate = PluginInstallerInfoBarDelegate::Create( 284 delegate = PluginInstallerInfoBarDelegate::Create(
280 infobar_helper, installer, 285 infobar_helper, installer,
281 base::Bind(&PluginObserver::InstallMissingPlugin, 286 base::Bind(&PluginObserver::InstallMissingPlugin,
282 weak_ptr_factory_.GetWeakPtr(), installer)); 287 weak_ptr_factory_.GetWeakPtr(), installer));
283 #else 288 #else
284 delegate = base::win::IsMetroProcess() ? 289 delegate = base::win::IsMetroProcess() ?
285 PluginMetroModeInfoBarDelegate::Create( 290 PluginMetroModeInfoBarDelegate::Create(
286 infobar_helper, installer->name()) : 291 infobar_helper, installer->name()) :
287 PluginInstallerInfoBarDelegate::Create( 292 PluginInstallerInfoBarDelegate::Create(
288 infobar_helper, installer, 293 infobar_helper, installer,
289 base::Bind(&PluginObserver::InstallMissingPlugin, 294 base::Bind(&PluginObserver::InstallMissingPlugin,
290 weak_ptr_factory_.GetWeakPtr(), installer)); 295 weak_ptr_factory_.GetWeakPtr(), installer));
291 #endif 296 #endif
292 infobar_helper->AddInfoBar(delegate); 297 infobar_helper->AddInfoBar(delegate);
293 } 298 }
294 299
295 void PluginObserver::InstallMissingPlugin(PluginInstaller* installer) { 300 void PluginObserver::InstallMissingPlugin(PluginInstaller* installer) {
296 if (installer->url_for_display()) { 301 if (installer->url_for_display()) {
297 installer->OpenDownloadURL(web_contents()); 302 installer->OpenDownloadURL(web_contents());
298 } else { 303 } else {
299 chrome::ShowTabModalConfirmDialog( 304 chrome::ShowTabModalConfirmDialog(
300 new ConfirmInstallDialogDelegate(tab_contents_, installer), 305 new ConfirmInstallDialogDelegate(web_contents(), installer),
301 tab_contents_); 306 TabContents::FromWebContents(web_contents()));
302 } 307 }
303 } 308 }
304 309
305 void PluginObserver::OnRemovePluginPlaceholderHost(int placeholder_id) { 310 void PluginObserver::OnRemovePluginPlaceholderHost(int placeholder_id) {
306 std::map<int, PluginPlaceholderHost*>::iterator it = 311 std::map<int, PluginPlaceholderHost*>::iterator it =
307 plugin_placeholders_.find(placeholder_id); 312 plugin_placeholders_.find(placeholder_id);
308 if (it == plugin_placeholders_.end()) { 313 if (it == plugin_placeholders_.end()) {
309 NOTREACHED(); 314 NOTREACHED();
310 return; 315 return;
311 } 316 }
312 delete it->second; 317 delete it->second;
313 plugin_placeholders_.erase(it); 318 plugin_placeholders_.erase(it);
314 } 319 }
315 #endif // defined(ENABLE_PLUGIN_INSTALLATION) 320 #endif // defined(ENABLE_PLUGIN_INSTALLATION)
316 321
317 void PluginObserver::OnOpenAboutPlugins() { 322 void PluginObserver::OnOpenAboutPlugins() {
318 web_contents()->OpenURL(OpenURLParams( 323 web_contents()->OpenURL(OpenURLParams(
319 GURL(chrome::kAboutPluginsURL), 324 GURL(chrome::kAboutPluginsURL),
320 content::Referrer(web_contents()->GetURL(), 325 content::Referrer(web_contents()->GetURL(),
321 WebKit::WebReferrerPolicyDefault), 326 WebKit::WebReferrerPolicyDefault),
322 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_AUTO_BOOKMARK, false)); 327 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_AUTO_BOOKMARK, false));
323 } 328 }
324 329
325 void PluginObserver::OnCouldNotLoadPlugin(const FilePath& plugin_path) { 330 void PluginObserver::OnCouldNotLoadPlugin(const FilePath& plugin_path) {
326 g_browser_process->metrics_service()->LogPluginLoadingError(plugin_path); 331 g_browser_process->metrics_service()->LogPluginLoadingError(plugin_path);
327 string16 plugin_name = 332 string16 plugin_name =
328 PluginService::GetInstance()->GetPluginDisplayNameByPath(plugin_path); 333 PluginService::GetInstance()->GetPluginDisplayNameByPath(plugin_path);
329 InfoBarTabHelper* infobar_helper = tab_contents_->infobar_tab_helper(); 334 TabContents* tab_contents = TabContents::FromWebContents(web_contents());
335 InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper();
330 infobar_helper->AddInfoBar(new SimpleAlertInfoBarDelegate( 336 infobar_helper->AddInfoBar(new SimpleAlertInfoBarDelegate(
331 infobar_helper, 337 infobar_helper,
332 &ResourceBundle::GetSharedInstance().GetNativeImageNamed( 338 &ResourceBundle::GetSharedInstance().GetNativeImageNamed(
333 IDR_INFOBAR_PLUGIN_CRASHED), 339 IDR_INFOBAR_PLUGIN_CRASHED),
334 l10n_util::GetStringFUTF16(IDS_PLUGIN_INITIALIZATION_ERROR_PROMPT, 340 l10n_util::GetStringFUTF16(IDS_PLUGIN_INITIALIZATION_ERROR_PROMPT,
335 plugin_name), 341 plugin_name),
336 true /* auto_expire */)); 342 true /* auto_expire */));
337 } 343 }
338 344
OLDNEW
« no previous file with comments | « chrome/browser/plugins/plugin_observer.h ('k') | chrome/browser/ui/tab_contents/tab_contents.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698