| OLD | NEW |
| 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/content_settings/host_content_settings_map.h" | 10 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 11 #include "chrome/browser/google/google_util.h" | 11 #include "chrome/browser/google/google_util.h" |
| 12 #include "chrome/browser/infobars/infobar_tab_helper.h" | 12 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| 13 #include "chrome/browser/plugin_finder.h" | 13 #include "chrome/browser/plugin_finder.h" |
| 14 #include "chrome/browser/plugin_installer.h" | 14 #include "chrome/browser/plugin_installer.h" |
| 15 #include "chrome/browser/plugin_installer_infobar_delegate.h" | 15 #include "chrome/browser/plugin_installer_infobar_delegate.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" | 17 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
| 18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 19 #include "chrome/common/render_messages.h" | 19 #include "chrome/common/render_messages.h" |
| 20 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
| 21 #include "content/browser/renderer_host/render_view_host.h" | 21 #include "content/browser/renderer_host/render_view_host.h" |
| 22 #include "content/browser/tab_contents/tab_contents.h" | 22 #include "content/browser/tab_contents/tab_contents.h" |
| 23 #include "content/browser/tab_contents/tab_contents_delegate.h" | 23 #include "content/browser/tab_contents/tab_contents_delegate.h" |
| 24 #include "content/browser/user_metrics.h" | 24 #include "content/public/browser/user_metrics.h" |
| 25 #include "grit/generated_resources.h" | 25 #include "grit/generated_resources.h" |
| 26 #include "grit/theme_resources_standard.h" | 26 #include "grit/theme_resources_standard.h" |
| 27 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
| 28 #include "ui/base/resource/resource_bundle.h" | 28 #include "ui/base/resource/resource_bundle.h" |
| 29 #include "webkit/plugins/npapi/plugin_group.h" | 29 #include "webkit/plugins/npapi/plugin_group.h" |
| 30 #include "webkit/plugins/webplugininfo.h" | 30 #include "webkit/plugins/webplugininfo.h" |
| 31 | 31 |
| 32 using content::UserMetricsAction; |
| 33 |
| 32 namespace { | 34 namespace { |
| 33 | 35 |
| 34 // PluginInfoBarDelegate ------------------------------------------------------ | 36 // PluginInfoBarDelegate ------------------------------------------------------ |
| 35 | 37 |
| 36 class PluginInfoBarDelegate : public ConfirmInfoBarDelegate { | 38 class PluginInfoBarDelegate : public ConfirmInfoBarDelegate { |
| 37 public: | 39 public: |
| 38 PluginInfoBarDelegate(InfoBarTabHelper* infobar_helper, const string16& name); | 40 PluginInfoBarDelegate(InfoBarTabHelper* infobar_helper, const string16& name); |
| 39 | 41 |
| 40 protected: | 42 protected: |
| 41 virtual ~PluginInfoBarDelegate(); | 43 virtual ~PluginInfoBarDelegate(); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 | 114 |
| 113 DISALLOW_COPY_AND_ASSIGN(BlockedPluginInfoBarDelegate); | 115 DISALLOW_COPY_AND_ASSIGN(BlockedPluginInfoBarDelegate); |
| 114 }; | 116 }; |
| 115 | 117 |
| 116 BlockedPluginInfoBarDelegate::BlockedPluginInfoBarDelegate( | 118 BlockedPluginInfoBarDelegate::BlockedPluginInfoBarDelegate( |
| 117 InfoBarTabHelper* infobar_helper, | 119 InfoBarTabHelper* infobar_helper, |
| 118 HostContentSettingsMap* content_settings, | 120 HostContentSettingsMap* content_settings, |
| 119 const string16& utf16_name) | 121 const string16& utf16_name) |
| 120 : PluginInfoBarDelegate(infobar_helper, utf16_name), | 122 : PluginInfoBarDelegate(infobar_helper, utf16_name), |
| 121 content_settings_(content_settings) { | 123 content_settings_(content_settings) { |
| 122 UserMetrics::RecordAction(UserMetricsAction("BlockedPluginInfobar.Shown")); | 124 content::RecordAction(UserMetricsAction("BlockedPluginInfobar.Shown")); |
| 123 std::string name = UTF16ToUTF8(utf16_name); | 125 std::string name = UTF16ToUTF8(utf16_name); |
| 124 if (name == webkit::npapi::PluginGroup::kJavaGroupName) | 126 if (name == webkit::npapi::PluginGroup::kJavaGroupName) |
| 125 UserMetrics::RecordAction( | 127 content::RecordAction( |
| 126 UserMetricsAction("BlockedPluginInfobar.Shown.Java")); | 128 UserMetricsAction("BlockedPluginInfobar.Shown.Java")); |
| 127 else if (name == webkit::npapi::PluginGroup::kQuickTimeGroupName) | 129 else if (name == webkit::npapi::PluginGroup::kQuickTimeGroupName) |
| 128 UserMetrics::RecordAction( | 130 content::RecordAction( |
| 129 UserMetricsAction("BlockedPluginInfobar.Shown.QuickTime")); | 131 UserMetricsAction("BlockedPluginInfobar.Shown.QuickTime")); |
| 130 else if (name == webkit::npapi::PluginGroup::kShockwaveGroupName) | 132 else if (name == webkit::npapi::PluginGroup::kShockwaveGroupName) |
| 131 UserMetrics::RecordAction( | 133 content::RecordAction( |
| 132 UserMetricsAction("BlockedPluginInfobar.Shown.Shockwave")); | 134 UserMetricsAction("BlockedPluginInfobar.Shown.Shockwave")); |
| 133 else if (name == webkit::npapi::PluginGroup::kRealPlayerGroupName) | 135 else if (name == webkit::npapi::PluginGroup::kRealPlayerGroupName) |
| 134 UserMetrics::RecordAction( | 136 content::RecordAction( |
| 135 UserMetricsAction("BlockedPluginInfobar.Shown.RealPlayer")); | 137 UserMetricsAction("BlockedPluginInfobar.Shown.RealPlayer")); |
| 136 else if (name == webkit::npapi::PluginGroup::kWindowsMediaPlayerGroupName) | 138 else if (name == webkit::npapi::PluginGroup::kWindowsMediaPlayerGroupName) |
| 137 UserMetrics::RecordAction( | 139 content::RecordAction( |
| 138 UserMetricsAction("BlockedPluginInfobar.Shown.WindowsMediaPlayer")); | 140 UserMetricsAction("BlockedPluginInfobar.Shown.WindowsMediaPlayer")); |
| 139 } | 141 } |
| 140 | 142 |
| 141 BlockedPluginInfoBarDelegate::~BlockedPluginInfoBarDelegate() { | 143 BlockedPluginInfoBarDelegate::~BlockedPluginInfoBarDelegate() { |
| 142 UserMetrics::RecordAction(UserMetricsAction("BlockedPluginInfobar.Closed")); | 144 content::RecordAction(UserMetricsAction("BlockedPluginInfobar.Closed")); |
| 143 } | 145 } |
| 144 | 146 |
| 145 std::string BlockedPluginInfoBarDelegate::GetLearnMoreURL() const { | 147 std::string BlockedPluginInfoBarDelegate::GetLearnMoreURL() const { |
| 146 return chrome::kBlockedPluginLearnMoreURL; | 148 return chrome::kBlockedPluginLearnMoreURL; |
| 147 } | 149 } |
| 148 | 150 |
| 149 string16 BlockedPluginInfoBarDelegate::GetMessageText() const { | 151 string16 BlockedPluginInfoBarDelegate::GetMessageText() const { |
| 150 return l10n_util::GetStringFUTF16(IDS_PLUGIN_NOT_AUTHORIZED, name_); | 152 return l10n_util::GetStringFUTF16(IDS_PLUGIN_NOT_AUTHORIZED, name_); |
| 151 } | 153 } |
| 152 | 154 |
| 153 string16 BlockedPluginInfoBarDelegate::GetButtonLabel( | 155 string16 BlockedPluginInfoBarDelegate::GetButtonLabel( |
| 154 InfoBarButton button) const { | 156 InfoBarButton button) const { |
| 155 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? | 157 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? |
| 156 IDS_PLUGIN_ENABLE_TEMPORARILY : IDS_PLUGIN_ENABLE_ALWAYS); | 158 IDS_PLUGIN_ENABLE_TEMPORARILY : IDS_PLUGIN_ENABLE_ALWAYS); |
| 157 } | 159 } |
| 158 | 160 |
| 159 bool BlockedPluginInfoBarDelegate::Accept() { | 161 bool BlockedPluginInfoBarDelegate::Accept() { |
| 160 UserMetrics::RecordAction( | 162 content::RecordAction( |
| 161 UserMetricsAction("BlockedPluginInfobar.AllowThisTime")); | 163 UserMetricsAction("BlockedPluginInfobar.AllowThisTime")); |
| 162 return PluginInfoBarDelegate::Cancel(); | 164 return PluginInfoBarDelegate::Cancel(); |
| 163 } | 165 } |
| 164 | 166 |
| 165 bool BlockedPluginInfoBarDelegate::Cancel() { | 167 bool BlockedPluginInfoBarDelegate::Cancel() { |
| 166 UserMetrics::RecordAction( | 168 content::RecordAction( |
| 167 UserMetricsAction("BlockedPluginInfobar.AlwaysAllow")); | 169 UserMetricsAction("BlockedPluginInfobar.AlwaysAllow")); |
| 168 content_settings_->AddExceptionForURL(owner()->tab_contents()->GetURL(), | 170 content_settings_->AddExceptionForURL(owner()->tab_contents()->GetURL(), |
| 169 owner()->tab_contents()->GetURL(), | 171 owner()->tab_contents()->GetURL(), |
| 170 CONTENT_SETTINGS_TYPE_PLUGINS, | 172 CONTENT_SETTINGS_TYPE_PLUGINS, |
| 171 std::string(), | 173 std::string(), |
| 172 CONTENT_SETTING_ALLOW); | 174 CONTENT_SETTING_ALLOW); |
| 173 return PluginInfoBarDelegate::Cancel(); | 175 return PluginInfoBarDelegate::Cancel(); |
| 174 } | 176 } |
| 175 | 177 |
| 176 void BlockedPluginInfoBarDelegate::InfoBarDismissed() { | 178 void BlockedPluginInfoBarDelegate::InfoBarDismissed() { |
| 177 UserMetrics::RecordAction( | 179 content::RecordAction( |
| 178 UserMetricsAction("BlockedPluginInfobar.Dismissed")); | 180 UserMetricsAction("BlockedPluginInfobar.Dismissed")); |
| 179 } | 181 } |
| 180 | 182 |
| 181 bool BlockedPluginInfoBarDelegate::LinkClicked( | 183 bool BlockedPluginInfoBarDelegate::LinkClicked( |
| 182 WindowOpenDisposition disposition) { | 184 WindowOpenDisposition disposition) { |
| 183 UserMetrics::RecordAction( | 185 content::RecordAction( |
| 184 UserMetricsAction("BlockedPluginInfobar.LearnMore")); | 186 UserMetricsAction("BlockedPluginInfobar.LearnMore")); |
| 185 return PluginInfoBarDelegate::LinkClicked(disposition); | 187 return PluginInfoBarDelegate::LinkClicked(disposition); |
| 186 } | 188 } |
| 187 | 189 |
| 188 // OutdatedPluginInfoBarDelegate ---------------------------------------------- | 190 // OutdatedPluginInfoBarDelegate ---------------------------------------------- |
| 189 | 191 |
| 190 class OutdatedPluginInfoBarDelegate : public PluginInfoBarDelegate { | 192 class OutdatedPluginInfoBarDelegate : public PluginInfoBarDelegate { |
| 191 public: | 193 public: |
| 192 OutdatedPluginInfoBarDelegate(InfoBarTabHelper* infobar_helper, | 194 OutdatedPluginInfoBarDelegate(InfoBarTabHelper* infobar_helper, |
| 193 const string16& name, | 195 const string16& name, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 209 | 211 |
| 210 DISALLOW_COPY_AND_ASSIGN(OutdatedPluginInfoBarDelegate); | 212 DISALLOW_COPY_AND_ASSIGN(OutdatedPluginInfoBarDelegate); |
| 211 }; | 213 }; |
| 212 | 214 |
| 213 OutdatedPluginInfoBarDelegate::OutdatedPluginInfoBarDelegate( | 215 OutdatedPluginInfoBarDelegate::OutdatedPluginInfoBarDelegate( |
| 214 InfoBarTabHelper* infobar_helper, | 216 InfoBarTabHelper* infobar_helper, |
| 215 const string16& utf16_name, | 217 const string16& utf16_name, |
| 216 const GURL& update_url) | 218 const GURL& update_url) |
| 217 : PluginInfoBarDelegate(infobar_helper, utf16_name), | 219 : PluginInfoBarDelegate(infobar_helper, utf16_name), |
| 218 update_url_(update_url) { | 220 update_url_(update_url) { |
| 219 UserMetrics::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Shown")); | 221 content::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Shown")); |
| 220 std::string name = UTF16ToUTF8(utf16_name); | 222 std::string name = UTF16ToUTF8(utf16_name); |
| 221 if (name == webkit::npapi::PluginGroup::kJavaGroupName) | 223 if (name == webkit::npapi::PluginGroup::kJavaGroupName) |
| 222 UserMetrics::RecordAction( | 224 content::RecordAction( |
| 223 UserMetricsAction("OutdatedPluginInfobar.Shown.Java")); | 225 UserMetricsAction("OutdatedPluginInfobar.Shown.Java")); |
| 224 else if (name == webkit::npapi::PluginGroup::kQuickTimeGroupName) | 226 else if (name == webkit::npapi::PluginGroup::kQuickTimeGroupName) |
| 225 UserMetrics::RecordAction( | 227 content::RecordAction( |
| 226 UserMetricsAction("OutdatedPluginInfobar.Shown.QuickTime")); | 228 UserMetricsAction("OutdatedPluginInfobar.Shown.QuickTime")); |
| 227 else if (name == webkit::npapi::PluginGroup::kShockwaveGroupName) | 229 else if (name == webkit::npapi::PluginGroup::kShockwaveGroupName) |
| 228 UserMetrics::RecordAction( | 230 content::RecordAction( |
| 229 UserMetricsAction("OutdatedPluginInfobar.Shown.Shockwave")); | 231 UserMetricsAction("OutdatedPluginInfobar.Shown.Shockwave")); |
| 230 else if (name == webkit::npapi::PluginGroup::kRealPlayerGroupName) | 232 else if (name == webkit::npapi::PluginGroup::kRealPlayerGroupName) |
| 231 UserMetrics::RecordAction( | 233 content::RecordAction( |
| 232 UserMetricsAction("OutdatedPluginInfobar.Shown.RealPlayer")); | 234 UserMetricsAction("OutdatedPluginInfobar.Shown.RealPlayer")); |
| 233 else if (name == webkit::npapi::PluginGroup::kSilverlightGroupName) | 235 else if (name == webkit::npapi::PluginGroup::kSilverlightGroupName) |
| 234 UserMetrics::RecordAction( | 236 content::RecordAction( |
| 235 UserMetricsAction("OutdatedPluginInfobar.Shown.Silverlight")); | 237 UserMetricsAction("OutdatedPluginInfobar.Shown.Silverlight")); |
| 236 else if (name == webkit::npapi::PluginGroup::kAdobeReaderGroupName) | 238 else if (name == webkit::npapi::PluginGroup::kAdobeReaderGroupName) |
| 237 UserMetrics::RecordAction( | 239 content::RecordAction( |
| 238 UserMetricsAction("OutdatedPluginInfobar.Shown.Reader")); | 240 UserMetricsAction("OutdatedPluginInfobar.Shown.Reader")); |
| 239 } | 241 } |
| 240 | 242 |
| 241 OutdatedPluginInfoBarDelegate::~OutdatedPluginInfoBarDelegate() { | 243 OutdatedPluginInfoBarDelegate::~OutdatedPluginInfoBarDelegate() { |
| 242 UserMetrics::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Closed")); | 244 content::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Closed")); |
| 243 } | 245 } |
| 244 | 246 |
| 245 std::string OutdatedPluginInfoBarDelegate::GetLearnMoreURL() const { | 247 std::string OutdatedPluginInfoBarDelegate::GetLearnMoreURL() const { |
| 246 return chrome::kOutdatedPluginLearnMoreURL; | 248 return chrome::kOutdatedPluginLearnMoreURL; |
| 247 } | 249 } |
| 248 | 250 |
| 249 string16 OutdatedPluginInfoBarDelegate::GetMessageText() const { | 251 string16 OutdatedPluginInfoBarDelegate::GetMessageText() const { |
| 250 return l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED_PROMPT, name_); | 252 return l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED_PROMPT, name_); |
| 251 } | 253 } |
| 252 | 254 |
| 253 string16 OutdatedPluginInfoBarDelegate::GetButtonLabel( | 255 string16 OutdatedPluginInfoBarDelegate::GetButtonLabel( |
| 254 InfoBarButton button) const { | 256 InfoBarButton button) const { |
| 255 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? | 257 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? |
| 256 IDS_PLUGIN_UPDATE : IDS_PLUGIN_ENABLE_TEMPORARILY); | 258 IDS_PLUGIN_UPDATE : IDS_PLUGIN_ENABLE_TEMPORARILY); |
| 257 } | 259 } |
| 258 | 260 |
| 259 bool OutdatedPluginInfoBarDelegate::Accept() { | 261 bool OutdatedPluginInfoBarDelegate::Accept() { |
| 260 UserMetrics::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Update")); | 262 content::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Update")); |
| 261 owner()->tab_contents()->OpenURL(update_url_, GURL(), NEW_FOREGROUND_TAB, | 263 owner()->tab_contents()->OpenURL(update_url_, GURL(), NEW_FOREGROUND_TAB, |
| 262 content::PAGE_TRANSITION_LINK); | 264 content::PAGE_TRANSITION_LINK); |
| 263 return false; | 265 return false; |
| 264 } | 266 } |
| 265 | 267 |
| 266 bool OutdatedPluginInfoBarDelegate::Cancel() { | 268 bool OutdatedPluginInfoBarDelegate::Cancel() { |
| 267 UserMetrics::RecordAction( | 269 content::RecordAction( |
| 268 UserMetricsAction("OutdatedPluginInfobar.AllowThisTime")); | 270 UserMetricsAction("OutdatedPluginInfobar.AllowThisTime")); |
| 269 return PluginInfoBarDelegate::Cancel(); | 271 return PluginInfoBarDelegate::Cancel(); |
| 270 } | 272 } |
| 271 | 273 |
| 272 void OutdatedPluginInfoBarDelegate::InfoBarDismissed() { | 274 void OutdatedPluginInfoBarDelegate::InfoBarDismissed() { |
| 273 UserMetrics::RecordAction( | 275 content::RecordAction( |
| 274 UserMetricsAction("OutdatedPluginInfobar.Dismissed")); | 276 UserMetricsAction("OutdatedPluginInfobar.Dismissed")); |
| 275 } | 277 } |
| 276 | 278 |
| 277 bool OutdatedPluginInfoBarDelegate::LinkClicked( | 279 bool OutdatedPluginInfoBarDelegate::LinkClicked( |
| 278 WindowOpenDisposition disposition) { | 280 WindowOpenDisposition disposition) { |
| 279 UserMetrics::RecordAction( | 281 content::RecordAction( |
| 280 UserMetricsAction("OutdatedPluginInfobar.LearnMore")); | 282 UserMetricsAction("OutdatedPluginInfobar.LearnMore")); |
| 281 return PluginInfoBarDelegate::LinkClicked(disposition); | 283 return PluginInfoBarDelegate::LinkClicked(disposition); |
| 282 } | 284 } |
| 283 | 285 |
| 284 } // namespace | 286 } // namespace |
| 285 | 287 |
| 286 | 288 |
| 287 // PluginObserver ------------------------------------------------------------- | 289 // PluginObserver ------------------------------------------------------------- |
| 288 | 290 |
| 289 PluginObserver::PluginObserver(TabContentsWrapper* tab_contents) | 291 PluginObserver::PluginObserver(TabContentsWrapper* tab_contents) |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 if (installer->url_for_display()) { | 354 if (installer->url_for_display()) { |
| 353 tab_contents()->OpenURL(OpenURLParams( | 355 tab_contents()->OpenURL(OpenURLParams( |
| 354 installer->plugin_url(), | 356 installer->plugin_url(), |
| 355 content::Referrer(tab_contents()->GetURL(), | 357 content::Referrer(tab_contents()->GetURL(), |
| 356 WebKit::WebReferrerPolicyDefault), | 358 WebKit::WebReferrerPolicyDefault), |
| 357 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_TYPED, false)); | 359 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_TYPED, false)); |
| 358 } else { | 360 } else { |
| 359 NOTIMPLEMENTED(); | 361 NOTIMPLEMENTED(); |
| 360 } | 362 } |
| 361 } | 363 } |
| OLD | NEW |