1ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen// Copyright (c) 2011 The Chromium Authors. All rights reserved.
2c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Use of this source code is governed by a BSD-style license that can be
3c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// found in the LICENSE file.
4c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
521d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen#ifndef CHROME_BROWSER_UI_COCOA_BUG_REPORT_WINDOW_CONTROLLER_H_
621d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen#define CHROME_BROWSER_UI_COCOA_BUG_REPORT_WINDOW_CONTROLLER_H_
73345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick#pragma once
8c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
9c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#import <Cocoa/Cocoa.h>
10c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
11c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include <vector>
12c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
13ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen#include "base/memory/scoped_nsobject.h"
14c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
15c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass Profile;
16c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass TabContents;
17c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
18c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// A window controller for managing the "Report Bug" feature. Modally
19c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// presents a dialog that allows the user to either file a bug report on
20c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// a broken page, or go directly to Google's "Report Phishing" page and
21c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// file a report there.
22c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch@interface BugReportWindowController : NSWindowController {
23c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch @private
24c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  TabContents* currentTab_;  // Weak, owned by browser.
25c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  Profile* profile_;  // Weak, owned by browser.
26c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
27c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Holds screenshot of current tab.
28c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  std::vector<unsigned char> pngData_;
29c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Width and height of the current tab's screenshot.
30c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  int pngWidth_;
31c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  int pngHeight_;
32c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
33c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Values bound to data in the dialog box. These values cannot be boxed in
34c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // scoped_nsobjects because we use them for bindings.
35c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  NSString* bugDescription_;  // Strong.
36c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  NSUInteger bugTypeIndex_;
37c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  NSString* pageTitle_;  // Strong.
38c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  NSString* pageURL_;  // Strong.
39c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
40c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // We keep a pointer to this button so we can change its title.
41c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  IBOutlet NSButton* sendReportButton_;
42c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
43c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // This button must be moved when the send report button changes title.
44c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  IBOutlet NSButton* cancelButton_;
45c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
46c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The popup button that allows choice of bug type.
47c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  IBOutlet NSPopUpButton* bugTypePopUpButton_;
48c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
49c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // YES sends a screenshot along with the bug report.
50c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  BOOL sendScreenshot_;
51c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
52c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Disable screenshot if no browser window is open.
53c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  BOOL disableScreenshotCheckbox_;
54c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
55c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Menu for the bug type popup button.  We create it here instead of in
56c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // IB so that we can nicely check whether the phishing page is selected,
57c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // and so that we can create a menu without "page" options when no browser
58c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // window is open.
59c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  NSMutableArray* bugTypeList_;  // Strong.
60c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
61c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // When dialog switches from regular bug reports to phishing page, "save
62c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // screenshot" and "description" are disabled. Save the state of this value
63c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // to restore if the user switches back to a regular bug report before
64c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // sending.
65c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  BOOL saveSendScreenshot_;
66c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  scoped_nsobject<NSString> saveBugDescription_;  // Strong
67c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
68c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Maps bug type menu item title strings to BugReportUtil::BugType ints.
69c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  NSDictionary* bugTypeDictionary_;  // Strong
70c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch}
71c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
7272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen// Properties for bindings.
7372a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen@property(nonatomic, copy) NSString* bugDescription;
7472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen@property(nonatomic) NSUInteger bugTypeIndex;
7572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen@property(nonatomic, copy) NSString* pageTitle;
7672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen@property(nonatomic, copy) NSString* pageURL;
7772a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen@property(nonatomic) BOOL sendScreenshot;
7872a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen@property(nonatomic) BOOL disableScreenshotCheckbox;
7972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen@property(nonatomic, readonly) NSArray* bugTypeList;
8072a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
81c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Initialize with the contents of the tab to be reported as buggy / wrong.
82c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// If dialog is called without an open window, currentTab may be null; in
83c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// that case, a dialog is opened with options for reporting a bugs not
84c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// related to a specific page.  Profile is passed to BugReportUtil, who
85c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// will not send a report if the value is null.
86c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch- (id)initWithTabContents:(TabContents*)currentTab profile:(Profile*)profile;
87c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
88c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Run the dialog with an application-modal event loop.  If the user accepts,
89c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// send the report of the bug or broken web site.
90c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch- (void)runModalDialog;
91c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
92c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// IBActions for the dialog buttons.
93c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch- (IBAction)sendReport:(id)sender;
94c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch- (IBAction)cancel:(id)sender;
95c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
96c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// YES if the user has selected the phishing report option.
97c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch- (BOOL)isPhishingReport;
98c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
99c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Converts the bug type from the menu into the correct value for the bug type
100c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// from BugReportUtil::BugType.
101c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch- (int)bugTypeFromIndex;
102c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
103c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Force the description text field to allow "return" to go to the next line
104c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// within the description field. Without this delegate method, "return" falls
105c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// back to the "Send Report" action, because this button has been bound to
106c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// the return key in IB.
107c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch- (BOOL)control:(NSControl*)control textView:(NSTextView*)textView
108c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    doCommandBySelector:(SEL)commandSelector;
109c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
110c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch@end
111c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
11221d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen#endif  // CHROME_BROWSER_UI_COCOA_BUG_REPORT_WINDOW_CONTROLLER_H_
113