Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / components / google / core / browser / google_url_tracker_infobar_delegate.h
1 // Copyright 2014 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 #ifndef COMPONENTS_GOOGLE_CORE_BROWSER_GOOGLE_URL_TRACKER_INFOBAR_DELEGATE_H_
6 #define COMPONENTS_GOOGLE_CORE_BROWSER_GOOGLE_URL_TRACKER_INFOBAR_DELEGATE_H_
7
8 #include "components/infobars/core/confirm_infobar_delegate.h"
9 #include "url/gurl.h"
10
11 class GoogleURLTracker;
12 class GoogleURLTrackerNavigationHelper;
13
14 namespace infobars {
15 class InfoBarManager;
16 }
17
18 // This infobar is shown by the GoogleURLTracker when the Google base URL has
19 // changed.
20 class GoogleURLTrackerInfoBarDelegate : public ConfirmInfoBarDelegate {
21  public:
22   // Creates a Google URL tracker infobar and delegate and adds the infobar to
23   // |infobar_manager|.  Returns the infobar if it was successfully added.
24   static infobars::InfoBar* Create(
25       infobars::InfoBarManager* infobar_manager,
26       GoogleURLTracker* google_url_tracker,
27       const GURL& search_url);
28
29   // ConfirmInfoBarDelegate:
30   bool Accept() override;
31   bool Cancel() override;
32
33   GoogleURLTrackerNavigationHelper* navigation_helper() {
34     return navigation_helper_weak_ptr_;
35   }
36
37   void set_navigation_helper(
38       scoped_ptr<GoogleURLTrackerNavigationHelper> navigation_helper) {
39     navigation_helper_ = navigation_helper.Pass();
40     navigation_helper_weak_ptr_ = navigation_helper_.get();
41   }
42
43   // Other than set_pending_id(), these accessors are only used by test code.
44   const GURL& search_url() const { return search_url_; }
45   void set_search_url(const GURL& search_url) { search_url_ = search_url; }
46   int pending_id() const { return pending_id_; }
47   void set_pending_id(int pending_id) { pending_id_ = pending_id; }
48
49   // These are virtual so test code can override them in a subclass.
50   virtual void Update(const GURL& search_url);
51   virtual void Close(bool redo_search);
52
53  protected:
54   GoogleURLTrackerInfoBarDelegate(
55       GoogleURLTracker* google_url_tracker,
56       const GURL& search_url);
57   ~GoogleURLTrackerInfoBarDelegate() override;
58
59  private:
60   // ConfirmInfoBarDelegate:
61   base::string16 GetMessageText() const override;
62   base::string16 GetButtonLabel(InfoBarButton button) const override;
63   base::string16 GetLinkText() const override;
64   bool LinkClicked(WindowOpenDisposition disposition) override;
65   bool ShouldExpireInternal(const NavigationDetails& details) const override;
66
67   GoogleURLTracker* google_url_tracker_;
68   scoped_ptr<GoogleURLTrackerNavigationHelper> navigation_helper_;
69
70   // During Close(), this object gives up ownership of |navigation_helper_|,
71   // which then outlives this object. Sometimes after this point, other classes
72   // still attempt to call navigation_helper() to access the (still-valid)
73   // instance. The NavigationHelper instance is stored as a weak pointer in
74   // addition to a strong pointer to facilitate this case.
75   GoogleURLTrackerNavigationHelper* navigation_helper_weak_ptr_;
76   GURL search_url_;
77   int pending_id_;
78
79   DISALLOW_COPY_AND_ASSIGN(GoogleURLTrackerInfoBarDelegate);
80 };
81
82 #endif  // COMPONENTS_GOOGLE_CORE_BROWSER_GOOGLE_URL_TRACKER_INFOBAR_DELEGATE_H_