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