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

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

Issue 6410115: Adds navigator.registerProtocolHandler. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Sync'd, disallow non-same origin rph, adds hostname to the infobar. Created 9 years, 10 months 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
(Empty)
1 // Copyright (c) 2010 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 #include "chrome/browser/custom_handlers/register_protocol_handler_infobar_deleg ate.h"
6
7 #include "base/metrics/histogram.h"
8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/autofill/autofill_cc_infobar.h"
10 #include "chrome/browser/autofill/autofill_manager.h"
11 #include "chrome/browser/browser_list.h"
12 #include "chrome/browser/prefs/pref_service.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/tab_contents/tab_contents.h"
15 #include "chrome/browser/tab_contents/tab_contents_delegate.h"
16 #include "chrome/common/pref_names.h"
17 #include "grit/chromium_strings.h"
18 #include "grit/generated_resources.h"
19 #include "grit/theme_resources.h"
20 #include "third_party/skia/include/core/SkBitmap.h"
21 #include "ui/base/l10n/l10n_util.h"
22 #include "ui/base/resource/resource_bundle.h"
23
24 RegisterProtocolHandlerInfoBarDelegate::RegisterProtocolHandlerInfoBarDelegate(
25 TabContents* tab_contents, ProtocolHandlerRegistry* registry,
26 ProtocolHandler* handler)
27 : ConfirmInfoBarDelegate(tab_contents),
28 tab_contents_(tab_contents),
29 registry_(registry),
30 handler_(handler) {
31 }
32
33 void RegisterProtocolHandlerInfoBarDelegate::AttemptRegisterProtocolHandler(
34 TabContents* tab_contents,
35 ProtocolHandlerRegistry* registry,
36 ProtocolHandler* handler) {
37 if (!registry->CanSchemeBeOverridden(handler->protocol())) {
38 return;
39 }
40
41 if (registry->IsAlreadyRegistered(handler)) {
42 tab_contents->AddInfoBar(new SimpleAlertInfoBarDelegate(tab_contents,
43 NULL,
44 l10n_util::GetStringFUTF16(
45 IDS_REGISTER_PROTOCOL_HANDLER_ALREADY_REGISTERED,
46 handler->title(), UTF8ToUTF16(handler->protocol())), true));
47 return;
48 }
49
50 RegisterProtocolHandlerInfoBarDelegate* delegate =
51 new RegisterProtocolHandlerInfoBarDelegate(tab_contents,
52 registry,
53 handler);
54 tab_contents->AddInfoBar(delegate);
55 }
56
57 bool RegisterProtocolHandlerInfoBarDelegate::ShouldExpire(
58 const NavigationController::LoadCommittedDetails& details) const {
59 // The user has submitted a form, causing the page to navigate elsewhere. We
60 // don't want the infobar to be expired at this point, because the user won't
61 // get a chance to answer the question.
62 return false;
63 }
64
65 void RegisterProtocolHandlerInfoBarDelegate::InfoBarClosed() {
66 delete this;
67 }
68
69 string16 RegisterProtocolHandlerInfoBarDelegate::GetMessageText() const {
70 ProtocolHandler* old_handler = registry_->GetHandlerFor(handler_->protocol());
71 if (old_handler) {
72 return l10n_util::GetStringFUTF16(
73 IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM_REPLACE, handler_->title(),
74 UTF8ToUTF16(handler_->url().host()), UTF8ToUTF16(handler_->protocol()),
75 old_handler->title());
76 }
77 return l10n_util::GetStringFUTF16(IDS_REGISTER_PROTOCOL_HANDLER_CONFIRM,
78 handler_->title(), UTF8ToUTF16(handler_->url().host()),
79 UTF8ToUTF16(handler_->protocol()));
80 }
81
82 SkBitmap* RegisterProtocolHandlerInfoBarDelegate::GetIcon() const {
83 return NULL;
84 }
85
86 int RegisterProtocolHandlerInfoBarDelegate::GetButtons() const {
87 return BUTTON_OK | BUTTON_CANCEL;
88 }
89
90 string16 RegisterProtocolHandlerInfoBarDelegate::GetButtonLabel(
91 ConfirmInfoBarDelegate::InfoBarButton button) const {
92 if (button == BUTTON_OK) {
93 return l10n_util::GetStringFUTF16(IDS_REGISTER_PROTOCOL_HANDLER_ACCEPT,
94 handler_->title());
95 } else if (button == BUTTON_CANCEL) {
96 return l10n_util::GetStringUTF16(IDS_REGISTER_PROTOCOL_HANDLER_DENY);
97 } else {
98 NOTREACHED();
99 }
100
101 return string16();
102 }
103
104 bool RegisterProtocolHandlerInfoBarDelegate::Accept() {
105 registry_->OnAcceptRegisterProtocolHandler(handler_);
106 return true;
107 }
108
109 bool RegisterProtocolHandlerInfoBarDelegate::Cancel() {
110 registry_->OnDenyRegisterProtocolHandler(handler_);
111 return true;
112 }
113
114 string16 RegisterProtocolHandlerInfoBarDelegate::GetLinkText() {
115 // TODO(koz): Make this a 'learn more' link.
116 return string16();
117 }
118
119 bool RegisterProtocolHandlerInfoBarDelegate::LinkClicked(
120 WindowOpenDisposition disposition) {
121 return false;
122 }
123
124 InfoBarDelegate::Type RegisterProtocolHandlerInfoBarDelegate::GetInfoBarType() {
125 return PAGE_ACTION_TYPE;
126 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698