15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#ifndef CHROME_BROWSER_INFOBARS_INFOBAR_DELEGATE_H_
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define CHROME_BROWSER_INFOBARS_INFOBAR_DELEGATE_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h"
9868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/string16.h"
10c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/browser/infobars/infobar_service.h"
112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/base/window_open_disposition.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class AutoLoginInfoBarDelegate;
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ConfirmInfoBarDelegate;
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ExtensionInfoBarDelegate;
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class InfoBar;
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class InsecureContentInfoBarDelegate;
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class MediaStreamInfoBarDelegate;
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class RegisterProtocolHandlerInfoBarDelegate;
202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class ScreenCaptureInfoBarDelegate;
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ThemeInstalledInfoBarDelegate;
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class ThreeDAPIInfoBarDelegate;
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class TranslateInfoBarDelegate;
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace gfx {
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Image;
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// An interface implemented by objects wishing to control an InfoBar.
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Implementing this interface is not sufficient to use an InfoBar, since it
312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// does not map to a specific InfoBar type. Instead, you must implement
322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// ConfirmInfoBarDelegate, or override with your own delegate for your own
332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// InfoBar variety.
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class InfoBarDelegate {
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The type of the infobar. It controls its appearance, such as its background
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // color.
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum Type {
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    WARNING_TYPE,
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    PAGE_ACTION_TYPE,
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum InfoBarAutomationType {
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    CONFIRM_INFOBAR,
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    PASSWORD_INFOBAR,
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    RPH_INFOBAR,
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    UNKNOWN_INFOBAR,
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Value to use when the InfoBar has no icon to show.
5190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  static const int kNoIconID;
5290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~InfoBarDelegate();
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual InfoBarAutomationType GetInfoBarAutomationType() const;
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called to create the InfoBar. Implementation of this method is
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // platform-specific.
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual InfoBar* CreateInfoBar(InfoBarService* owner) = 0;
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(pkasting): Move to InfoBar once InfoBars own their delegates.
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  InfoBarService* owner() { return owner_; }
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void clear_owner() { owner_ = NULL; }
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the supplied |delegate| is equal to this one. Equality is
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // left to the implementation to define. This function is called by the
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // InfoBarService when determining whether or not a delegate should be
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // added because a matching one already exists. If this function returns true,
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the InfoBarService will not add the new delegate because it considers
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // one to already be present.
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool EqualsDelegate(InfoBarDelegate* delegate) const;
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the InfoBar should be closed automatically after the page
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // is navigated. By default this returns true if the navigation is to a new
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // page (not including reloads).  Subclasses wishing to change this behavior
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // can override either this function or ShouldExpireInternal(), depending on
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // what level of control they need.
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool ShouldExpire(const content::LoadCommittedDetails& details) const;
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called when the user clicks on the close button to dismiss the infobar.
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void InfoBarDismissed();
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Return the resource ID of the icon to be shown for this InfoBar.  If the
8590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // value is equal to |kNoIconID|, no icon is shown.
8690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  virtual int GetIconID() const;
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the type of the infobar.  The type determines the appearance (such
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // as background color) of the infobar.
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual Type GetInfoBarType() const;
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Type-checking downcast routines:
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual AutoLoginInfoBarDelegate* AsAutoLoginInfoBarDelegate();
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ConfirmInfoBarDelegate* AsConfirmInfoBarDelegate();
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ExtensionInfoBarDelegate* AsExtensionInfoBarDelegate();
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual InsecureContentInfoBarDelegate* AsInsecureContentInfoBarDelegate();
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual MediaStreamInfoBarDelegate* AsMediaStreamInfoBarDelegate();
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual RegisterProtocolHandlerInfoBarDelegate*
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      AsRegisterProtocolHandlerInfoBarDelegate();
1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ScreenCaptureInfoBarDelegate* AsScreenCaptureInfoBarDelegate();
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ThemeInstalledInfoBarDelegate* AsThemePreviewInfobarDelegate();
1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ThreeDAPIInfoBarDelegate* AsThreeDAPIInfoBarDelegate();
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual TranslateInfoBarDelegate* AsTranslateInfoBarDelegate();
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Return the icon to be shown for this InfoBar. If the returned Image is
10690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // empty, no icon is shown.
10790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  virtual gfx::Image GetIcon() const;
10890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
109c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  content::WebContents* web_contents() {
110c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return owner_ ? owner_->web_contents() : NULL;
111c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
112c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If |contents| is non-NULL, its active entry's unique ID will be stored
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // using StoreActiveEntryUniqueID automatically.
1167dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  explicit InfoBarDelegate(InfoBarService* owner);
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Store the unique id for the active entry in our WebContents, to be used
1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // later upon navigation to determine if this InfoBarDelegate should be
1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // expired.
1212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void StoreActiveEntryUniqueID();
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int contents_unique_id() const { return contents_unique_id_; }
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the navigation is to a new URL or a reload occured.
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool ShouldExpireInternal(
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const content::LoadCommittedDetails& details) const;
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Removes ourself from |owner_| if we haven't already been removed.
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(pkasting): Move to InfoBar.
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void RemoveSelf();
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The unique id of the active NavigationEntry of the WebContents that we were
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // opened for. Used to help expire on navigations.
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int contents_unique_id_;
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(pkasting): Remove.
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  InfoBarService* owner_;
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(InfoBarDelegate);
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif  // CHROME_BROWSER_INFOBARS_INFOBAR_DELEGATE_H_
145