Home | History | Annotate | Download | only in infobars
      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
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/browser/infobars/infobar_delegate.h"
      6 
      7 #include "base/logging.h"
      8 #include "build/build_config.h"
      9 #include "chrome/browser/infobars/infobar_service.h"
     10 #include "content/public/browser/navigation_controller.h"
     11 #include "content/public/browser/navigation_details.h"
     12 #include "content/public/browser/navigation_entry.h"
     13 #include "content/public/browser/web_contents.h"
     14 #include "ui/base/resource/resource_bundle.h"
     15 
     16 using content::NavigationEntry;
     17 
     18 // InfoBarDelegate ------------------------------------------------------------
     19 
     20 const int InfoBarDelegate::kNoIconID = 0;
     21 
     22 InfoBarDelegate::~InfoBarDelegate() {
     23 }
     24 
     25 InfoBarDelegate::InfoBarAutomationType
     26     InfoBarDelegate::GetInfoBarAutomationType() const {
     27   return UNKNOWN_INFOBAR;
     28 }
     29 
     30 bool InfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const {
     31   return false;
     32 }
     33 
     34 bool InfoBarDelegate::ShouldExpire(
     35     const content::LoadCommittedDetails& details) const {
     36   if (!details.is_navigation_to_different_page())
     37     return false;
     38 
     39   return ShouldExpireInternal(details);
     40 }
     41 
     42 void InfoBarDelegate::InfoBarDismissed() {
     43 }
     44 
     45 int InfoBarDelegate::GetIconID() const {
     46   return kNoIconID;
     47 }
     48 
     49 InfoBarDelegate::Type InfoBarDelegate::GetInfoBarType() const {
     50   return WARNING_TYPE;
     51 }
     52 
     53 AutoLoginInfoBarDelegate* InfoBarDelegate::AsAutoLoginInfoBarDelegate() {
     54   return NULL;
     55 }
     56 
     57 ConfirmInfoBarDelegate* InfoBarDelegate::AsConfirmInfoBarDelegate() {
     58   return NULL;
     59 }
     60 
     61 ExtensionInfoBarDelegate* InfoBarDelegate::AsExtensionInfoBarDelegate() {
     62   return NULL;
     63 }
     64 
     65 InsecureContentInfoBarDelegate*
     66     InfoBarDelegate::AsInsecureContentInfoBarDelegate() {
     67   return NULL;
     68 }
     69 
     70 MediaStreamInfoBarDelegate* InfoBarDelegate::AsMediaStreamInfoBarDelegate() {
     71   return NULL;
     72 }
     73 
     74 RegisterProtocolHandlerInfoBarDelegate*
     75     InfoBarDelegate::AsRegisterProtocolHandlerInfoBarDelegate() {
     76   return NULL;
     77 }
     78 
     79 ScreenCaptureInfoBarDelegate*
     80     InfoBarDelegate::AsScreenCaptureInfoBarDelegate() {
     81   return NULL;
     82 }
     83 
     84 ThemeInstalledInfoBarDelegate*
     85     InfoBarDelegate::AsThemePreviewInfobarDelegate() {
     86   return NULL;
     87 }
     88 
     89 ThreeDAPIInfoBarDelegate* InfoBarDelegate::AsThreeDAPIInfoBarDelegate() {
     90   return NULL;
     91 }
     92 
     93 TranslateInfoBarDelegate* InfoBarDelegate::AsTranslateInfoBarDelegate() {
     94   return NULL;
     95 }
     96 
     97 gfx::Image InfoBarDelegate::GetIcon() const {
     98   int icon_id = GetIconID();
     99   return (icon_id == kNoIconID) ? gfx::Image() :
    100       ResourceBundle::GetSharedInstance().GetNativeImageNamed(icon_id);
    101 }
    102 
    103 InfoBarDelegate::InfoBarDelegate(InfoBarService* owner)
    104     : contents_unique_id_(0),
    105       owner_(owner) {
    106   if (owner_)
    107     StoreActiveEntryUniqueID();
    108 }
    109 
    110 void InfoBarDelegate::StoreActiveEntryUniqueID() {
    111   DCHECK(web_contents());
    112   NavigationEntry* active_entry =
    113       web_contents()->GetController().GetActiveEntry();
    114   contents_unique_id_ = active_entry ? active_entry->GetUniqueID() : 0;
    115 }
    116 
    117 bool InfoBarDelegate::ShouldExpireInternal(
    118     const content::LoadCommittedDetails& details) const {
    119   // NOTE: If you change this, be sure to check and adjust the behavior of
    120   // anyone who overrides this as necessary!
    121   return (contents_unique_id_ != details.entry->GetUniqueID()) ||
    122       (content::PageTransitionStripQualifier(
    123           details.entry->GetTransitionType()) ==
    124               content::PAGE_TRANSITION_RELOAD);
    125 }
    126 
    127 void InfoBarDelegate::RemoveSelf() {
    128   if (owner_)
    129     owner_->RemoveInfoBar(this);  // Clears |owner_|.
    130 }
    131