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

Side by Side Diff: chrome/browser/cocoa/bug_report_window_controller.mm

Issue 340039: Add "Report Bug" dialog to Mac OSX.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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
Property Changes:
Name: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2009 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/cocoa/bug_report_window_controller.h"
6
7 #include "app/l10n_util_mac.h"
8 #include "base/mac_util.h"
9 #include "base/sys_string_conversions.h"
10 #include "chrome/browser/bug_report_util.h"
11 #include "chrome/browser/tab_contents/tab_contents.h"
12 #include "chrome/browser/tab_contents/tab_contents_view.h"
13 #include "grit/chromium_strings.h"
14 #include "grit/generated_resources.h"
15 #include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h"
16
17 @implementation BugReportWindowController
18
19 @synthesize bugDescription = bugDescription_;
20 @synthesize bugType = bugType_;
21 @synthesize pageURL = pageURL_;
22 @synthesize pageTitle = pageTitle_;
23 @synthesize sendReportButton = sendReportButton_;
24 @synthesize sendScreenshot = sendScreenshot_;
25 @synthesize disableScreenshot = disableScreenshot_;
26 @synthesize bugTypeList = bugTypeList_;
27
28 - (id)initWithTabContents:(TabContents*)currentTab
29 profile:(Profile*)profile {
30 NSString* nibpath = [mac_util::MainAppBundle() pathForResource:@"ReportBug"
31 ofType:@"nib"];
32 if ((self = [super initWithWindowNibPath:nibpath owner:self])) {
33 currentTab_ = currentTab;
34 profile_ = profile;
35 [self setBugDescription:@""];
36
37 if (currentTab_ != NULL) {
38 // Get data from current tab, if one exists. This dialog could be called
39 // from the main menu with no tab contents, so currentTab_ is not
40 // guaranteed to be non-NULL.
41 // TODO(mirandac): This dialog should be a tab-modal sheet if a browser
42 // window exists.
43 [self setSendScreenshot:YES];
44 [self setDisableScreenshot:NO];
45 bugTypeList_ = [[NSArray alloc] initWithObjects:
46 l10n_util::GetNSStringWithFixup(IDS_BUGREPORT_PAGE_WONT_LOAD),
47 l10n_util::GetNSStringWithFixup(IDS_BUGREPORT_PAGE_LOOKS_ODD),
48 l10n_util::GetNSStringWithFixup(IDS_BUGREPORT_PHISHING_PAGE),
49 l10n_util::GetNSStringWithFixup(IDS_BUGREPORT_CANT_SIGN_IN),
50 l10n_util::GetNSStringWithFixup(IDS_BUGREPORT_CHROME_MISBEHAVES),
51 l10n_util::GetNSStringWithFixup(IDS_BUGREPORT_SOMETHING_MISSING),
52 l10n_util::GetNSStringWithFixup(IDS_BUGREPORT_BROWSER_CRASH),
53 l10n_util::GetNSStringWithFixup(IDS_BUGREPORT_OTHER_PROBLEM),
54 nil];
55 [self setPageURL:base::SysUTF8ToNSString(
56 currentTab_->controller().GetActiveEntry()->url().spec())];
57 [self setPageTitle:base::SysUTF16ToNSString(currentTab_->GetTitle())];
58 mac_util::GrabWindowSnapshot(
59 currentTab_->view()->GetTopLevelNativeWindow(), &pngData_);
60 } else {
61 // If no current tab exists, create a menu without the "broken page"
62 // options, with page URL and title empty, and screenshot disabled.
63 [self setSendScreenshot:NO];
64 [self setDisableScreenshot:YES];
65 bugTypeList_ = [[NSArray alloc] initWithObjects:
66 l10n_util::GetNSStringWithFixup(IDS_BUGREPORT_CHROME_MISBEHAVES),
67 l10n_util::GetNSStringWithFixup(IDS_BUGREPORT_SOMETHING_MISSING),
68 l10n_util::GetNSStringWithFixup(IDS_BUGREPORT_BROWSER_CRASH),
69 l10n_util::GetNSStringWithFixup(IDS_BUGREPORT_OTHER_PROBLEM),
70 nil];
71 // Because "Report Bug" is being called with no browser open in this
72 // case, make URL and title empty.
73 [self setPageURL:@""];
74 [self setPageTitle:@""];
75 }
76 }
77 return self;
78 }
79
80 - (void)dealloc {
81 [pageURL_ release];
82 [pageTitle_ release];
83 [bugDescription_ release];
84 [bugTypeList_ release];
85 [super dealloc];
86 }
87
88 // Delegate callback so that closing the window deletes the controller.
89 - (void)windowWillClose:(NSNotification*)notification {
90 [self autorelease];
91 }
92
93 - (void)closeDialog {
94 [NSApp stopModal];
95 [[self window] close];
96 }
97
98 - (void)runModalDialog {
99 [NSApp runModalForWindow:[self window]];
100 }
101
102 - (IBAction)sendReport:(id)sender {
103 if ([self isPhishingReport]) {
104 BugReportUtil::ReportPhishing(currentTab_,
105 base::SysNSStringToUTF8(pageURL_));
106 } else {
107 BugReportUtil::SendReport(
108 profile_,
109 base::SysNSStringToUTF8(pageTitle_),
110 bugType_,
111 base::SysNSStringToUTF8(pageURL_),
112 base::SysNSStringToUTF8(bugDescription_),
113 sendScreenshot_ && !pngData_.empty() ?
114 reinterpret_cast<const char *>(&(pngData_[0])) : NULL,
115 pngData_.size());
116 }
117 [self closeDialog];
118 }
119
120 - (IBAction)cancel:(id)sender {
121 [self closeDialog];
122 }
123
124 - (BOOL)isPhishingReport {
125 return bugType_ == [bugTypeList_ indexOfObject:
126 l10n_util::GetNSStringWithFixup(IDS_BUGREPORT_PHISHING_PAGE)];
127 }
128
129 - (void)menu:(NSMenu *)menu willHighlightItem:(NSMenuItem *)item {
130 NSString* buttonTitle = [[item title] isEqualToString:
131 l10n_util::GetNSStringWithFixup(IDS_BUGREPORT_PHISHING_PAGE)] ?
132 l10n_util::GetNSStringWithFixup(IDS_BUGREPORT_SEND_PHISHING_REPORT) :
133 l10n_util::GetNSStringWithFixup(IDS_BUGREPORT_SEND_REPORT);
134 if (![buttonTitle isEqualToString:[sendReportButton_ title]]) {
135 [sendReportButton_ setTitle:buttonTitle];
136 CGFloat deltaWidth =
137 [GTMUILocalizerAndLayoutTweaker sizeToFitView:sendReportButton_].width;
138 NSRect newButtonFrame = [sendReportButton_ frame];
139 newButtonFrame.origin.x -= deltaWidth;
140 [sendReportButton_ setFrame:newButtonFrame];
141 }
142 }
143
144 // BugReportWindowController needs to change the title of the Send Report
145 // button when the user chooses the phishing bug type, so we need to bind
146 // the function that changes the button title to the bug type key.
147 + (NSSet*)keyPathsForValuesAffectingValueForKey:(NSString*)key {
148 NSSet* paths = [super keyPathsForValuesAffectingValueForKey:key];
149 if ([key isEqualToString:@"isPhishingReport"]) {
150 paths = [paths setByAddingObject:@"bugType"];
151 }
152 return paths;
153 }
154
155 @end
156
157
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/bug_report_window_controller.h ('k') | chrome/browser/cocoa/bug_report_window_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698