summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/bug_report_window_controller.h
blob: 116044a109aec46f0060c141414d85fc10c8f6cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_COCOA_BUG_REPORT_WINDOW_CONTROLLER_H_
#define CHROME_BROWSER_COCOA_BUG_REPORT_WINDOW_CONTROLLER_H_
#pragma once

#import <Cocoa/Cocoa.h>

#include <vector>

#include "base/scoped_nsobject.h"

class Profile;
class TabContents;

// A window controller for managing the "Report Bug" feature. Modally
// presents a dialog that allows the user to either file a bug report on
// a broken page, or go directly to Google's "Report Phishing" page and
// file a report there.
@interface BugReportWindowController : NSWindowController {
 @private
  TabContents* currentTab_;  // Weak, owned by browser.
  Profile* profile_;  // Weak, owned by browser.

  // Holds screenshot of current tab.
  std::vector<unsigned char> pngData_;
  // Width and height of the current tab's screenshot.
  int pngWidth_;
  int pngHeight_;

  // Values bound to data in the dialog box. These values cannot be boxed in
  // scoped_nsobjects because we use them for bindings.
  NSString* bugDescription_;  // Strong.
  NSUInteger bugTypeIndex_;
  NSString* pageTitle_;  // Strong.
  NSString* pageURL_;  // Strong.

  // We keep a pointer to this button so we can change its title.
  IBOutlet NSButton* sendReportButton_;

  // This button must be moved when the send report button changes title.
  IBOutlet NSButton* cancelButton_;

  // The popup button that allows choice of bug type.
  IBOutlet NSPopUpButton* bugTypePopUpButton_;

  // YES sends a screenshot along with the bug report.
  BOOL sendScreenshot_;

  // Disable screenshot if no browser window is open.
  BOOL disableScreenshotCheckbox_;

  // Menu for the bug type popup button.  We create it here instead of in
  // IB so that we can nicely check whether the phishing page is selected,
  // and so that we can create a menu without "page" options when no browser
  // window is open.
  NSMutableArray* bugTypeList_;  // Strong.

  // When dialog switches from regular bug reports to phishing page, "save
  // screenshot" and "description" are disabled. Save the state of this value
  // to restore if the user switches back to a regular bug report before
  // sending.
  BOOL saveSendScreenshot_;
  scoped_nsobject<NSString> saveBugDescription_;  // Strong

  // Maps bug type menu item title strings to BugReportUtil::BugType ints.
  NSDictionary* bugTypeDictionary_;  // Strong
}

// Initialize with the contents of the tab to be reported as buggy / wrong.
// If dialog is called without an open window, currentTab may be null; in
// that case, a dialog is opened with options for reporting a bugs not
// related to a specific page.  Profile is passed to BugReportUtil, who
// will not send a report if the value is null.
- (id)initWithTabContents:(TabContents*)currentTab profile:(Profile*)profile;

// Run the dialog with an application-modal event loop.  If the user accepts,
// send the report of the bug or broken web site.
- (void)runModalDialog;

// IBActions for the dialog buttons.
- (IBAction)sendReport:(id)sender;
- (IBAction)cancel:(id)sender;

// YES if the user has selected the phishing report option.
- (BOOL)isPhishingReport;

// Converts the bug type from the menu into the correct value for the bug type
// from BugReportUtil::BugType.
- (int)bugTypeFromIndex;

// Force the description text field to allow "return" to go to the next line
// within the description field. Without this delegate method, "return" falls
// back to the "Send Report" action, because this button has been bound to
// the return key in IB.
- (BOOL)control:(NSControl*)control textView:(NSTextView*)textView
    doCommandBySelector:(SEL)commandSelector;

// Properties for bindings.
@property (nonatomic, copy) NSString* bugDescription;
@property (nonatomic) NSUInteger bugTypeIndex;
@property (nonatomic, copy) NSString* pageTitle;
@property (nonatomic, copy) NSString* pageURL;
@property (nonatomic) BOOL sendScreenshot;
@property (nonatomic) BOOL disableScreenshotCheckbox;
@property (nonatomic, readonly) NSArray* bugTypeList;

@end

#endif  // CHROME_BROWSER_COCOA_BUG_REPORT_WINDOW_CONTROLLER_H_