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/translate/translate_infobar_delegate.h" | 5 #include "chrome/browser/translate/translate_infobar_delegate.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/i18n/string_compare.h" | 9 #include "base/i18n/string_compare.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/infobars/infobar.h" | 13 #include "chrome/browser/infobars/infobar.h" |
| 14 #include "chrome/browser/infobars/infobar_manager.h" |
14 #include "chrome/browser/infobars/infobar_service.h" | 15 #include "chrome/browser/infobars/infobar_service.h" |
15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/translate/translate_manager.h" | 17 #include "chrome/browser/translate/translate_manager.h" |
17 #include "chrome/browser/translate/translate_tab_helper.h" | 18 #include "chrome/browser/translate/translate_tab_helper.h" |
18 #include "components/translate/core/browser/translate_accept_languages.h" | 19 #include "components/translate/core/browser/translate_accept_languages.h" |
19 #include "components/translate/core/browser/translate_download_manager.h" | 20 #include "components/translate/core/browser/translate_download_manager.h" |
20 #include "components/translate/core/common/translate_constants.h" | 21 #include "components/translate/core/common/translate_constants.h" |
21 #include "content/public/browser/navigation_details.h" | 22 #include "content/public/browser/navigation_details.h" |
22 #include "content/public/browser/navigation_entry.h" | 23 #include "content/public/browser/navigation_entry.h" |
23 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 TranslateTabHelper::FromWebContents(web_contents); | 83 TranslateTabHelper::FromWebContents(web_contents); |
83 if (!translate_tab_helper || | 84 if (!translate_tab_helper || |
84 translate_tab_helper->GetLanguageState().InTranslateNavigation()) | 85 translate_tab_helper->GetLanguageState().InTranslateNavigation()) |
85 return; | 86 return; |
86 } | 87 } |
87 | 88 |
88 // Find any existing translate infobar delegate. | 89 // Find any existing translate infobar delegate. |
89 InfoBar* old_infobar = NULL; | 90 InfoBar* old_infobar = NULL; |
90 InfoBarService* infobar_service = | 91 InfoBarService* infobar_service = |
91 InfoBarService::FromWebContents(web_contents); | 92 InfoBarService::FromWebContents(web_contents); |
| 93 InfoBarManager* infobar_manager = infobar_service->infobar_manager(); |
92 TranslateInfoBarDelegate* old_delegate = NULL; | 94 TranslateInfoBarDelegate* old_delegate = NULL; |
93 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { | 95 for (size_t i = 0; i < infobar_manager->infobar_count(); ++i) { |
94 old_infobar = infobar_service->infobar_at(i); | 96 old_infobar = infobar_manager->infobar_at(i); |
95 old_delegate = old_infobar->delegate()->AsTranslateInfoBarDelegate(); | 97 old_delegate = old_infobar->delegate()->AsTranslateInfoBarDelegate(); |
96 if (old_delegate) { | 98 if (old_delegate) { |
97 if (!replace_existing_infobar) | 99 if (!replace_existing_infobar) |
98 return; | 100 return; |
99 break; | 101 break; |
100 } | 102 } |
101 } | 103 } |
102 | 104 |
103 // Add the new delegate. | 105 // Add the new delegate. |
104 scoped_ptr<InfoBar> infobar(CreateInfoBar( | 106 scoped_ptr<InfoBar> infobar(CreateInfoBar( |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 if (!details.is_navigation_to_different_page() && !details.is_main_frame) | 374 if (!details.is_navigation_to_different_page() && !details.is_main_frame) |
373 return false; | 375 return false; |
374 | 376 |
375 return InfoBarDelegate::ShouldExpireInternal(details); | 377 return InfoBarDelegate::ShouldExpireInternal(details); |
376 } | 378 } |
377 | 379 |
378 TranslateInfoBarDelegate* | 380 TranslateInfoBarDelegate* |
379 TranslateInfoBarDelegate::AsTranslateInfoBarDelegate() { | 381 TranslateInfoBarDelegate::AsTranslateInfoBarDelegate() { |
380 return this; | 382 return this; |
381 } | 383 } |
OLD | NEW |