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/tab_contents/tab_contents.h" | 5 #include "chrome/browser/tab_contents/tab_contents.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 params->current_history_list_length = controller.entry_count(); | 241 params->current_history_list_length = controller.entry_count(); |
242 params->url = entry.url(); | 242 params->url = entry.url(); |
243 params->referrer = entry.referrer(); | 243 params->referrer = entry.referrer(); |
244 params->transition = entry.transition_type(); | 244 params->transition = entry.transition_type(); |
245 params->state = entry.content_state(); | 245 params->state = entry.content_state(); |
246 params->navigation_type = | 246 params->navigation_type = |
247 GetNavigationType(controller.profile(), entry, reload_type); | 247 GetNavigationType(controller.profile(), entry, reload_type); |
248 params->request_time = base::Time::Now(); | 248 params->request_time = base::Time::Now(); |
249 } | 249 } |
250 | 250 |
| 251 // PluginInfoBar -------------------------------------------------------------- |
| 252 |
| 253 class PluginInfoBar : public ConfirmInfoBarDelegate { |
| 254 public: |
| 255 PluginInfoBar(TabContents* tab_contents, const string16& name); |
| 256 |
| 257 // ConfirmInfoBarDelegate: |
| 258 virtual void InfoBarClosed() = 0; |
| 259 virtual SkBitmap* GetIcon() const; |
| 260 virtual string16 GetMessageText() const = 0; |
| 261 virtual int GetButtons() const; |
| 262 virtual string16 GetButtonLabel(InfoBarButton button) const = 0; |
| 263 virtual bool Accept() = 0; |
| 264 virtual bool Cancel() = 0; |
| 265 virtual string16 GetLinkText(); |
| 266 virtual bool LinkClicked(WindowOpenDisposition disposition) = 0; |
| 267 |
| 268 protected: |
| 269 virtual ~PluginInfoBar(); |
| 270 |
| 271 void CommonCancel(); |
| 272 void CommonClose(); |
| 273 void CommonLearnMore(WindowOpenDisposition disposition); |
| 274 |
| 275 string16 name_; |
| 276 TabContents* tab_contents_; |
| 277 |
| 278 private: |
| 279 DISALLOW_COPY_AND_ASSIGN(PluginInfoBar); |
| 280 }; |
| 281 |
| 282 PluginInfoBar::PluginInfoBar(TabContents* tab_contents, const string16& name) |
| 283 : ConfirmInfoBarDelegate(tab_contents), |
| 284 name_(name), |
| 285 tab_contents_(tab_contents) { |
| 286 } |
| 287 |
| 288 PluginInfoBar::~PluginInfoBar() { |
| 289 } |
| 290 |
| 291 void PluginInfoBar::CommonClose() { |
| 292 delete this; |
| 293 } |
| 294 |
| 295 SkBitmap* PluginInfoBar::GetIcon() const { |
| 296 return ResourceBundle::GetSharedInstance().GetBitmapNamed( |
| 297 IDR_INFOBAR_PLUGIN_INSTALL); |
| 298 } |
| 299 |
| 300 int PluginInfoBar::GetButtons() const { |
| 301 return BUTTON_OK | BUTTON_CANCEL; |
| 302 } |
| 303 |
| 304 void PluginInfoBar::CommonCancel() { |
| 305 tab_contents_->render_view_host()->LoadBlockedPlugins(); |
| 306 } |
| 307 |
| 308 string16 PluginInfoBar::GetLinkText() { |
| 309 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); |
| 310 } |
| 311 |
| 312 void PluginInfoBar::CommonLearnMore(WindowOpenDisposition disposition) { |
| 313 // TODO(bauerb): Navigate to a help page explaining why we disabled |
| 314 // or blocked the plugin, once we have one. |
| 315 } |
| 316 |
| 317 |
| 318 // BlockedPluginInfoBar ------------------------------------------------------- |
| 319 |
| 320 class BlockedPluginInfoBar : public PluginInfoBar { |
| 321 public: |
| 322 BlockedPluginInfoBar(TabContents* tab_contents, |
| 323 const string16& name); |
| 324 |
| 325 // ConfirmInfoBarDelegate: |
| 326 virtual string16 GetMessageText() const; |
| 327 virtual string16 GetButtonLabel(InfoBarButton button) const; |
| 328 virtual bool Accept(); |
| 329 virtual bool Cancel(); |
| 330 virtual void InfoBarClosed(); |
| 331 virtual bool LinkClicked(WindowOpenDisposition disposition); |
| 332 |
| 333 protected: |
| 334 virtual ~BlockedPluginInfoBar(); |
| 335 |
| 336 private: |
| 337 DISALLOW_COPY_AND_ASSIGN(BlockedPluginInfoBar); |
| 338 }; |
| 339 |
| 340 BlockedPluginInfoBar::BlockedPluginInfoBar(TabContents* tab_contents, |
| 341 const string16& name) |
| 342 : PluginInfoBar(tab_contents, name) { |
| 343 tab_contents->AddInfoBar(this); |
| 344 UserMetrics::RecordAction(UserMetricsAction("BlockedPluginInfobar.Shown")); |
| 345 } |
| 346 |
| 347 BlockedPluginInfoBar::~BlockedPluginInfoBar() { |
| 348 } |
| 349 |
| 350 string16 BlockedPluginInfoBar::GetMessageText() const { |
| 351 return l10n_util::GetStringFUTF16(IDS_PLUGIN_NOT_AUTHORIZED, name_); |
| 352 } |
| 353 |
| 354 string16 BlockedPluginInfoBar::GetButtonLabel(InfoBarButton button) const { |
| 355 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? |
| 356 IDS_PLUGIN_ENABLE_ALWAYS : IDS_PLUGIN_ENABLE_TEMPORARILY); |
| 357 } |
| 358 |
| 359 bool BlockedPluginInfoBar::Accept() { |
| 360 UserMetrics::RecordAction( |
| 361 UserMetricsAction("BlockedPluginInfobar.AlwaysAllow")); |
| 362 tab_contents_->profile()->GetHostContentSettingsMap()->AddExceptionForURL( |
| 363 tab_contents_->GetURL(), CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), |
| 364 CONTENT_SETTING_ALLOW); |
| 365 tab_contents_->render_view_host()->LoadBlockedPlugins(); |
| 366 return false; |
| 367 } |
| 368 |
| 369 bool BlockedPluginInfoBar::Cancel() { |
| 370 UserMetrics::RecordAction( |
| 371 UserMetricsAction("BlockedPluginInfobar.AllowThisTime")); |
| 372 CommonCancel(); |
| 373 return false; |
| 374 } |
| 375 |
| 376 void BlockedPluginInfoBar::InfoBarClosed() { |
| 377 UserMetrics::RecordAction(UserMetricsAction("BlockedPluginInfobar.Closed")); |
| 378 CommonClose(); |
| 379 } |
| 380 |
| 381 bool BlockedPluginInfoBar::LinkClicked(WindowOpenDisposition disposition) { |
| 382 UserMetrics::RecordAction( |
| 383 UserMetricsAction("BlockedPluginInfobar.LearnMore")); |
| 384 CommonLearnMore(disposition); |
| 385 return false; |
| 386 } |
251 | 387 |
252 // OutdatedPluginInfoBar ------------------------------------------------------ | 388 // OutdatedPluginInfoBar ------------------------------------------------------ |
253 | 389 |
254 class OutdatedPluginInfoBar : public ConfirmInfoBarDelegate { | 390 class OutdatedPluginInfoBar : public PluginInfoBar { |
255 public: | 391 public: |
256 OutdatedPluginInfoBar(TabContents* tab_contents, | 392 OutdatedPluginInfoBar(TabContents* tab_contents, |
257 const string16& name, | 393 const string16& name, |
258 const GURL& update_url); | 394 const GURL& update_url); |
259 | 395 |
260 private: | |
261 virtual ~OutdatedPluginInfoBar(); | |
262 | |
263 // ConfirmInfoBarDelegate: | 396 // ConfirmInfoBarDelegate: |
264 virtual void InfoBarClosed(); | |
265 virtual SkBitmap* GetIcon() const; | |
266 virtual string16 GetMessageText() const; | 397 virtual string16 GetMessageText() const; |
267 virtual int GetButtons() const; | |
268 virtual string16 GetButtonLabel(InfoBarButton button) const; | 398 virtual string16 GetButtonLabel(InfoBarButton button) const; |
269 virtual bool Accept(); | 399 virtual bool Accept(); |
270 virtual bool Cancel(); | 400 virtual bool Cancel(); |
271 virtual string16 GetLinkText(); | 401 virtual void InfoBarClosed(); |
272 virtual bool LinkClicked(WindowOpenDisposition disposition); | 402 virtual bool LinkClicked(WindowOpenDisposition disposition); |
273 | 403 |
274 TabContents* tab_contents_; | 404 protected: |
275 string16 name_; | 405 virtual ~OutdatedPluginInfoBar(); |
| 406 |
| 407 private: |
276 GURL update_url_; | 408 GURL update_url_; |
| 409 |
| 410 DISALLOW_COPY_AND_ASSIGN(OutdatedPluginInfoBar); |
277 }; | 411 }; |
278 | 412 |
279 OutdatedPluginInfoBar::OutdatedPluginInfoBar(TabContents* tab_contents, | 413 OutdatedPluginInfoBar::OutdatedPluginInfoBar(TabContents* tab_contents, |
280 const string16& name, | 414 const string16& name, |
281 const GURL& update_url) | 415 const GURL& update_url) |
282 : ConfirmInfoBarDelegate(tab_contents), | 416 : PluginInfoBar(tab_contents, name), update_url_(update_url) { |
283 tab_contents_(tab_contents), | 417 tab_contents->AddInfoBar(this); |
284 name_(name), | |
285 update_url_(update_url) { | |
286 UserMetrics::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Shown")); | 418 UserMetrics::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Shown")); |
287 tab_contents->AddInfoBar(this); | |
288 } | 419 } |
289 | 420 |
290 OutdatedPluginInfoBar::~OutdatedPluginInfoBar() { | 421 OutdatedPluginInfoBar::~OutdatedPluginInfoBar() { |
291 } | 422 } |
292 | 423 |
293 void OutdatedPluginInfoBar::InfoBarClosed() { | |
294 UserMetrics::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Closed")); | |
295 delete this; | |
296 } | |
297 | |
298 SkBitmap* OutdatedPluginInfoBar::GetIcon() const { | |
299 return ResourceBundle::GetSharedInstance().GetBitmapNamed( | |
300 IDR_INFOBAR_PLUGIN_INSTALL); | |
301 } | |
302 | |
303 string16 OutdatedPluginInfoBar::GetMessageText() const { | 424 string16 OutdatedPluginInfoBar::GetMessageText() const { |
304 return l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED_PROMPT, name_); | 425 return l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED_PROMPT, name_); |
305 } | 426 } |
306 | 427 |
307 int OutdatedPluginInfoBar::GetButtons() const { | |
308 return BUTTON_OK | BUTTON_CANCEL; | |
309 } | |
310 | |
311 string16 OutdatedPluginInfoBar::GetButtonLabel(InfoBarButton button) const { | 428 string16 OutdatedPluginInfoBar::GetButtonLabel(InfoBarButton button) const { |
312 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? | 429 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? |
313 IDS_PLUGIN_UPDATE : IDS_PLUGIN_ENABLE_TEMPORARILY); | 430 IDS_PLUGIN_UPDATE : IDS_PLUGIN_ENABLE_TEMPORARILY); |
314 } | 431 } |
315 | 432 |
316 bool OutdatedPluginInfoBar::Accept() { | 433 bool OutdatedPluginInfoBar::Accept() { |
317 UserMetrics::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Update")); | 434 UserMetrics::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Update")); |
318 tab_contents_->OpenURL(update_url_, GURL(), NEW_FOREGROUND_TAB, | 435 tab_contents_->OpenURL(update_url_, GURL(), NEW_FOREGROUND_TAB, |
319 PageTransition::LINK); | 436 PageTransition::LINK); |
320 return false; | 437 return false; |
321 } | 438 } |
322 | 439 |
323 bool OutdatedPluginInfoBar::Cancel() { | 440 bool OutdatedPluginInfoBar::Cancel() { |
324 UserMetrics::RecordAction( | 441 UserMetrics::RecordAction( |
325 UserMetricsAction("OutdatedPluginInfobar.AllowThisTime")); | 442 UserMetricsAction("OutdatedPluginInfobar.AllowThisTime")); |
326 tab_contents_->render_view_host()->LoadBlockedPlugins(); | 443 CommonCancel(); |
327 return false; | 444 return false; |
328 } | 445 } |
329 | 446 |
330 string16 OutdatedPluginInfoBar::GetLinkText() { | 447 void OutdatedPluginInfoBar::InfoBarClosed() { |
331 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); | 448 UserMetrics::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Closed")); |
| 449 CommonClose(); |
332 } | 450 } |
333 | 451 |
334 bool OutdatedPluginInfoBar::LinkClicked(WindowOpenDisposition disposition) { | 452 bool OutdatedPluginInfoBar::LinkClicked(WindowOpenDisposition disposition) { |
335 UserMetrics::RecordAction( | 453 UserMetrics::RecordAction( |
336 UserMetricsAction("OutdatedPluginInfobar.LearnMore")); | 454 UserMetricsAction("OutdatedPluginInfobar.LearnMore")); |
337 // TODO(bauerb): Navigate to a help page explaining why we disabled | 455 CommonLearnMore(disposition); |
338 // the plugin, once we have one. | |
339 return false; | 456 return false; |
340 } | 457 } |
341 | 458 |
342 } // namespace | 459 } // namespace |
343 | 460 |
344 | 461 |
345 // TabContents ---------------------------------------------------------------- | 462 // TabContents ---------------------------------------------------------------- |
346 | 463 |
347 // static | 464 // static |
348 int TabContents::find_request_id_counter_ = -1; | 465 int TabContents::find_request_id_counter_ = -1; |
(...skipping 2010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2359 delegate()->OnDidGetApplicationInfo(this, page_id); | 2476 delegate()->OnDidGetApplicationInfo(this, page_id); |
2360 } | 2477 } |
2361 | 2478 |
2362 void TabContents::OnInstallApplication(const WebApplicationInfo& info) { | 2479 void TabContents::OnInstallApplication(const WebApplicationInfo& info) { |
2363 if (delegate()) | 2480 if (delegate()) |
2364 delegate()->OnInstallApplication(this, info); | 2481 delegate()->OnInstallApplication(this, info); |
2365 } | 2482 } |
2366 | 2483 |
2367 void TabContents::OnBlockedOutdatedPlugin(const string16& name, | 2484 void TabContents::OnBlockedOutdatedPlugin(const string16& name, |
2368 const GURL& update_url) { | 2485 const GURL& update_url) { |
2369 new OutdatedPluginInfoBar(this, name, update_url); | 2486 if (!update_url.is_empty()) |
| 2487 new OutdatedPluginInfoBar(this, name, update_url); |
| 2488 else |
| 2489 new BlockedPluginInfoBar(this, name); |
2370 } | 2490 } |
2371 | 2491 |
2372 void TabContents::OnPageContents(const GURL& url, | 2492 void TabContents::OnPageContents(const GURL& url, |
2373 int32 page_id, | 2493 int32 page_id, |
2374 const string16& contents, | 2494 const string16& contents, |
2375 const std::string& language, | 2495 const std::string& language, |
2376 bool page_translatable) { | 2496 bool page_translatable) { |
2377 // Don't index any https pages. People generally don't want their bank | 2497 // Don't index any https pages. People generally don't want their bank |
2378 // accounts, etc. indexed on their computer, especially since some of these | 2498 // accounts, etc. indexed on their computer, especially since some of these |
2379 // things are not marked cachable. | 2499 // things are not marked cachable. |
(...skipping 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3395 if (pm != NULL) { | 3515 if (pm != NULL) { |
3396 if (pm->MaybeUsePreloadedPage(this, url)) { | 3516 if (pm->MaybeUsePreloadedPage(this, url)) { |
3397 // TODO(tburkard): If the preloaded page has not finished preloading | 3517 // TODO(tburkard): If the preloaded page has not finished preloading |
3398 // yet, we should not do this. | 3518 // yet, we should not do this. |
3399 DidStopLoading(); | 3519 DidStopLoading(); |
3400 return true; | 3520 return true; |
3401 } | 3521 } |
3402 } | 3522 } |
3403 return false; | 3523 return false; |
3404 } | 3524 } |
OLD | NEW |