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

Side by Side Diff: chrome/browser/ui/cocoa/external_protocol_dialog.mm

Issue 2632653002: MacViews: Enable views based External Protocol dialog behind secondary-ui-md flag. (Closed)
Patch Set: Address review. Created 3 years, 11 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "chrome/browser/ui/cocoa/external_protocol_dialog.h"
6
7 #include "base/message_loop/message_loop.h"
8 #include "base/metrics/histogram_macros.h"
9 #include "chrome/browser/external_protocol/external_protocol_handler.h"
10 #include "chrome/browser/shell_integration.h"
11 #include "chrome/browser/tab_contents/tab_util.h"
12 #include "chrome/grit/chromium_strings.h"
13 #include "chrome/grit/generated_resources.h"
14 #include "components/strings/grit/components_strings.h"
15 #include "ui/base/l10n/l10n_util_mac.h"
16 #include "ui/gfx/text_elider.h"
17
18 ///////////////////////////////////////////////////////////////////////////////
19 // ExternalProtocolHandler
20
21 // static
22 void ExternalProtocolHandler::RunExternalProtocolDialog(
23 const GURL& url, int render_process_host_id, int routing_id,
24 ui::PageTransition page_transition, bool has_user_gesture) {
25 [[ExternalProtocolDialogController alloc] initWithGURL:&url
26 renderProcessHostId:render_process_host_id
27 routingId:routing_id];
28 }
29
30 ///////////////////////////////////////////////////////////////////////////////
31 // ExternalProtocolDialogController
32
33 @interface ExternalProtocolDialogController(Private)
34 - (void)alertEnded:(NSAlert *)alert
35 returnCode:(int)returnCode
36 contextInfo:(void*)contextInfo;
37 @end
38
39 @implementation ExternalProtocolDialogController
40 - (id)initWithGURL:(const GURL*)url
41 renderProcessHostId:(int)renderProcessHostId
42 routingId:(int)routingId {
43 DCHECK(base::MessageLoopForUI::IsCurrent());
44
45 if (!(self = [super init]))
46 return nil;
47
48 url_ = *url;
49 render_process_host_id_ = renderProcessHostId;
50 routing_id_ = routingId;
51 creation_time_ = base::Time::Now();
52
53 base::string16 appName =
54 shell_integration::GetApplicationNameForProtocol(url_);
55 if (appName.length() == 0) {
56 // No registered apps for this protocol; give up and go home.
57 [self autorelease];
58 return nil;
59 }
60
61 alert_ = [[NSAlert alloc] init];
62
63 [alert_ setMessageText:
64 l10n_util::GetNSStringFWithFixup(IDS_EXTERNAL_PROTOCOL_TITLE, appName)];
65
66 NSButton* allowButton = [alert_
67 addButtonWithTitle:l10n_util::GetNSStringFWithFixup(
68 IDS_EXTERNAL_PROTOCOL_OK_BUTTON_TEXT, appName)];
69 [allowButton setKeyEquivalent:@""]; // disallow as default
70 [alert_ addButtonWithTitle:
71 l10n_util::GetNSStringWithFixup(
72 IDS_EXTERNAL_PROTOCOL_CANCEL_BUTTON_TEXT)];
73
74 [alert_ setShowsSuppressionButton:YES];
75 [[alert_ suppressionButton]
76 setTitle:l10n_util::GetNSStringFWithFixup(
77 IDS_EXTERNAL_PROTOCOL_CHECKBOX_TEXT, appName)];
78
79 [alert_ beginSheetModalForWindow:nil // nil here makes it app-modal
80 modalDelegate:self
81 didEndSelector:@selector(alertEnded:returnCode:contextInfo:)
82 contextInfo:nil];
83
84 return self;
85 }
86
87 - (void)dealloc {
88 [alert_ release];
89
90 [super dealloc];
91 }
92
93 - (void)alertEnded:(NSAlert *)alert
94 returnCode:(int)returnCode
95 contextInfo:(void*)contextInfo {
96 ExternalProtocolHandler::BlockState blockState =
97 ExternalProtocolHandler::UNKNOWN;
98 switch (returnCode) {
99 case NSAlertFirstButtonReturn:
100 blockState = ExternalProtocolHandler::DONT_BLOCK;
101 break;
102 case NSAlertSecondButtonReturn:
103 blockState = ExternalProtocolHandler::BLOCK;
104 break;
105 default:
106 NOTREACHED();
107 }
108
109 // Set the "don't warn me again" info.
110 if ([[alert_ suppressionButton] state] == NSOnState) {
111 ExternalProtocolHandler::SetBlockState(url_.scheme(), blockState);
112 ExternalProtocolHandler::RecordMetrics(true);
113 } else {
114 ExternalProtocolHandler::RecordMetrics(false);
115 }
116
117 if (blockState == ExternalProtocolHandler::DONT_BLOCK) {
118 UMA_HISTOGRAM_LONG_TIMES("clickjacking.launch_url",
119 base::Time::Now() - creation_time_);
120
121 content::WebContents* web_contents =
122 tab_util::GetWebContentsByID(render_process_host_id_, routing_id_);
123
124 ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(url_, web_contents);
125 }
126
127 [self autorelease];
128 }
129
130 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698