| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/alternate_nav_url_fetcher.h" | 5 #include "chrome/browser/alternate_nav_url_fetcher.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | |
| 8 #include "chrome/browser/api/infobars/infobar_service.h" | 7 #include "chrome/browser/api/infobars/infobar_service.h" |
| 9 #include "chrome/browser/api/infobars/link_infobar_delegate.h" | 8 #include "chrome/browser/infobars/alternate_nav_infobar_delegate.h" |
| 10 #include "chrome/browser/intranet_redirect_detector.h" | 9 #include "chrome/browser/intranet_redirect_detector.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/common/chrome_notification_types.h" | 11 #include "chrome/common/chrome_notification_types.h" |
| 13 #include "content/public/browser/navigation_controller.h" | 12 #include "content/public/browser/navigation_controller.h" |
| 14 #include "content/public/browser/notification_service.h" | 13 #include "content/public/browser/notification_service.h" |
| 15 #include "content/public/browser/render_process_host.h" | 14 #include "content/public/browser/render_process_host.h" |
| 16 #include "content/public/browser/render_view_host.h" | 15 #include "content/public/browser/render_view_host.h" |
| 17 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 18 #include "grit/generated_resources.h" | |
| 19 #include "grit/theme_resources.h" | |
| 20 #include "net/base/load_flags.h" | 17 #include "net/base/load_flags.h" |
| 21 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 18 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 22 #include "net/url_request/url_fetcher.h" | 19 #include "net/url_request/url_fetcher.h" |
| 23 #include "net/url_request/url_request.h" | 20 #include "net/url_request/url_request.h" |
| 24 #include "ui/base/l10n/l10n_util.h" | |
| 25 #include "ui/base/resource/resource_bundle.h" | |
| 26 | 21 |
| 27 using content::NavigationController; | 22 using content::NavigationController; |
| 28 using content::OpenURLParams; | |
| 29 using content::Referrer; | |
| 30 | |
| 31 // AlternateNavInfoBarDelegate ------------------------------------------------ | |
| 32 | |
| 33 class AlternateNavInfoBarDelegate : public LinkInfoBarDelegate { | |
| 34 public: | |
| 35 AlternateNavInfoBarDelegate(InfoBarService* owner, | |
| 36 const GURL& alternate_nav_url); | |
| 37 virtual ~AlternateNavInfoBarDelegate(); | |
| 38 | |
| 39 private: | |
| 40 // LinkInfoBarDelegate | |
| 41 virtual gfx::Image* GetIcon() const OVERRIDE; | |
| 42 virtual Type GetInfoBarType() const OVERRIDE; | |
| 43 virtual string16 GetMessageTextWithOffset(size_t* link_offset) const OVERRIDE; | |
| 44 virtual string16 GetLinkText() const OVERRIDE; | |
| 45 virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE; | |
| 46 | |
| 47 GURL alternate_nav_url_; | |
| 48 | |
| 49 DISALLOW_COPY_AND_ASSIGN(AlternateNavInfoBarDelegate); | |
| 50 }; | |
| 51 | |
| 52 AlternateNavInfoBarDelegate::AlternateNavInfoBarDelegate( | |
| 53 InfoBarService* owner, | |
| 54 const GURL& alternate_nav_url) | |
| 55 : LinkInfoBarDelegate(owner), | |
| 56 alternate_nav_url_(alternate_nav_url) { | |
| 57 } | |
| 58 | |
| 59 AlternateNavInfoBarDelegate::~AlternateNavInfoBarDelegate() { | |
| 60 } | |
| 61 | |
| 62 gfx::Image* AlternateNavInfoBarDelegate::GetIcon() const { | |
| 63 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed( | |
| 64 IDR_INFOBAR_ALT_NAV_URL); | |
| 65 } | |
| 66 | |
| 67 InfoBarDelegate::Type AlternateNavInfoBarDelegate::GetInfoBarType() const { | |
| 68 return PAGE_ACTION_TYPE; | |
| 69 } | |
| 70 | |
| 71 string16 AlternateNavInfoBarDelegate::GetMessageTextWithOffset( | |
| 72 size_t* link_offset) const { | |
| 73 const string16 label = l10n_util::GetStringFUTF16( | |
| 74 IDS_ALTERNATE_NAV_URL_VIEW_LABEL, string16(), link_offset); | |
| 75 return label; | |
| 76 } | |
| 77 | |
| 78 string16 AlternateNavInfoBarDelegate::GetLinkText() const { | |
| 79 return UTF8ToUTF16(alternate_nav_url_.spec()); | |
| 80 } | |
| 81 | |
| 82 bool AlternateNavInfoBarDelegate::LinkClicked( | |
| 83 WindowOpenDisposition disposition) { | |
| 84 OpenURLParams params( | |
| 85 alternate_nav_url_, Referrer(), disposition, | |
| 86 // Pretend the user typed this URL, so that navigating to | |
| 87 // it will be the default action when it's typed again in | |
| 88 // the future. | |
| 89 content::PAGE_TRANSITION_TYPED, | |
| 90 false); | |
| 91 owner()->GetWebContents()->OpenURL(params); | |
| 92 | |
| 93 // We should always close, even if the navigation did not occur within this | |
| 94 // WebContents. | |
| 95 return true; | |
| 96 } | |
| 97 | |
| 98 | |
| 99 // AlternateNavURLFetcher ----------------------------------------------------- | |
| 100 | 23 |
| 101 AlternateNavURLFetcher::AlternateNavURLFetcher( | 24 AlternateNavURLFetcher::AlternateNavURLFetcher( |
| 102 const GURL& alternate_nav_url) | 25 const GURL& alternate_nav_url) |
| 103 : alternate_nav_url_(alternate_nav_url), | 26 : alternate_nav_url_(alternate_nav_url), |
| 104 controller_(NULL), | 27 controller_(NULL), |
| 105 state_(NOT_STARTED), | 28 state_(NOT_STARTED), |
| 106 navigated_to_entry_(false) { | 29 navigated_to_entry_(false) { |
| 107 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING, | 30 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING, |
| 108 content::NotificationService::AllSources()); | 31 content::NotificationService::AllSources()); |
| 109 registrar_.Add(this, chrome::NOTIFICATION_INSTANT_COMMITTED, | 32 registrar_.Add(this, chrome::NOTIFICATION_INSTANT_COMMITTED, |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 if (navigated_to_entry_ && (state_ == SUCCEEDED)) { | 144 if (navigated_to_entry_ && (state_ == SUCCEEDED)) { |
| 222 InfoBarService* infobar_service = | 145 InfoBarService* infobar_service = |
| 223 InfoBarService::FromWebContents(controller_->GetWebContents()); | 146 InfoBarService::FromWebContents(controller_->GetWebContents()); |
| 224 infobar_service->AddInfoBar( | 147 infobar_service->AddInfoBar( |
| 225 new AlternateNavInfoBarDelegate(infobar_service, alternate_nav_url_)); | 148 new AlternateNavInfoBarDelegate(infobar_service, alternate_nav_url_)); |
| 226 } else if (state_ != FAILED) { | 149 } else if (state_ != FAILED) { |
| 227 return; | 150 return; |
| 228 } | 151 } |
| 229 delete this; | 152 delete this; |
| 230 } | 153 } |
| OLD | NEW |