Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: chrome/browser/custom_handlers/register_protocol_handler_infobar_delegate.cc

Issue 22694006: Infobar system refactor. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/custom_handlers/register_protocol_handler_infobar_deleg ate.h" 5 #include "chrome/browser/custom_handlers/register_protocol_handler_infobar_deleg ate.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" 8 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
9 #include "chrome/browser/infobars/infobar.h"
9 #include "chrome/browser/infobars/infobar_service.h" 10 #include "chrome/browser/infobars/infobar_service.h"
10 #include "chrome/common/url_constants.h" 11 #include "chrome/common/url_constants.h"
11 #include "content/public/browser/user_metrics.h" 12 #include "content/public/browser/user_metrics.h"
12 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
13 #include "grit/generated_resources.h" 14 #include "grit/generated_resources.h"
14 #include "ui/base/l10n/l10n_util.h" 15 #include "ui/base/l10n/l10n_util.h"
15 16
16 // static 17 // static
17 void RegisterProtocolHandlerInfoBarDelegate::Create( 18 void RegisterProtocolHandlerInfoBarDelegate::Create(
18 InfoBarService* infobar_service, 19 InfoBarService* infobar_service,
19 ProtocolHandlerRegistry* registry, 20 ProtocolHandlerRegistry* registry,
20 const ProtocolHandler& handler) { 21 const ProtocolHandler& handler) {
21 content::RecordAction( 22 content::RecordAction(
22 content::UserMetricsAction("RegisterProtocolHandler.InfoBar_Shown")); 23 content::UserMetricsAction("RegisterProtocolHandler.InfoBar_Shown"));
23 24
24 scoped_ptr<InfoBarDelegate> infobar( 25 scoped_ptr<InfoBar> infobar(ConfirmInfoBarDelegate::CreateInfoBar(
25 new RegisterProtocolHandlerInfoBarDelegate(infobar_service, registry, 26 scoped_ptr<ConfirmInfoBarDelegate>(
26 handler)); 27 new RegisterProtocolHandlerInfoBarDelegate(registry, handler))));
27 28
28 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { 29 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) {
30 InfoBar* existing_infobar = infobar_service->infobar_at(i);
29 RegisterProtocolHandlerInfoBarDelegate* existing_delegate = 31 RegisterProtocolHandlerInfoBarDelegate* existing_delegate =
30 infobar_service->infobar_at(i)-> 32 existing_infobar->delegate()->
31 AsRegisterProtocolHandlerInfoBarDelegate(); 33 AsRegisterProtocolHandlerInfoBarDelegate();
32 if ((existing_delegate != NULL) && 34 if ((existing_delegate != NULL) &&
33 existing_delegate->handler_.IsEquivalent(handler)) { 35 existing_delegate->handler_.IsEquivalent(handler)) {
34 infobar_service->ReplaceInfoBar(existing_delegate, infobar.Pass()); 36 infobar_service->ReplaceInfoBar(existing_infobar, infobar.Pass());
35 return; 37 return;
36 } 38 }
37 } 39 }
38 40
39 infobar_service->AddInfoBar(infobar.Pass()); 41 infobar_service->AddInfoBar(infobar.Pass());
40 } 42 }
41 43
42 RegisterProtocolHandlerInfoBarDelegate::RegisterProtocolHandlerInfoBarDelegate( 44 RegisterProtocolHandlerInfoBarDelegate::RegisterProtocolHandlerInfoBarDelegate(
43 InfoBarService* infobar_service,
44 ProtocolHandlerRegistry* registry, 45 ProtocolHandlerRegistry* registry,
45 const ProtocolHandler& handler) 46 const ProtocolHandler& handler)
46 : ConfirmInfoBarDelegate(infobar_service), 47 : ConfirmInfoBarDelegate(),
47 registry_(registry), 48 registry_(registry),
48 handler_(handler) { 49 handler_(handler) {
49 } 50 }
50 51
51 RegisterProtocolHandlerInfoBarDelegate:: 52 RegisterProtocolHandlerInfoBarDelegate::
52 ~RegisterProtocolHandlerInfoBarDelegate() { 53 ~RegisterProtocolHandlerInfoBarDelegate() {
53 } 54 }
54 55
55 InfoBarDelegate::InfoBarAutomationType 56 InfoBarDelegate::InfoBarAutomationType
56 RegisterProtocolHandlerInfoBarDelegate::GetInfoBarAutomationType() const { 57 RegisterProtocolHandlerInfoBarDelegate::GetInfoBarAutomationType() const {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 } 123 }
123 124
124 string16 RegisterProtocolHandlerInfoBarDelegate::GetProtocolName( 125 string16 RegisterProtocolHandlerInfoBarDelegate::GetProtocolName(
125 const ProtocolHandler& handler) const { 126 const ProtocolHandler& handler) const {
126 if (handler.protocol() == "mailto") 127 if (handler.protocol() == "mailto")
127 return l10n_util::GetStringUTF16(IDS_REGISTER_PROTOCOL_HANDLER_MAILTO_NAME); 128 return l10n_util::GetStringUTF16(IDS_REGISTER_PROTOCOL_HANDLER_MAILTO_NAME);
128 if (handler.protocol() == "webcal") 129 if (handler.protocol() == "webcal")
129 return l10n_util::GetStringUTF16(IDS_REGISTER_PROTOCOL_HANDLER_WEBCAL_NAME); 130 return l10n_util::GetStringUTF16(IDS_REGISTER_PROTOCOL_HANDLER_WEBCAL_NAME);
130 return UTF8ToUTF16(handler.protocol()); 131 return UTF8ToUTF16(handler.protocol());
131 } 132 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698