title: NSSavePanel and the Sandbox
body: <p>I have some problems understanding the new Lion's Sandbox.</p>
  <p>I know that Lion includes a trusted daemon process called <code>Powerbox</code> whose job is to present and control open/save dialog boxes on behalf of sandboxed applications.</p>
  <p>Like the <a href="http://developer.apple.com/library/mac/#documentation/Security/Conceptual/CodeSigningGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40005929-CH1-SW1" rel="noreferrer">Code Signing And Application Sandboxing Guide</a> says:</p>
  <blockquote>
  <p>Any time an application running inside a sandbox invokes an NSOpenPanel or NSSavePanel dialog, rather than showing the panels directly, AppKit automatically asks the Powerbox to present the dialog. From a developer perspective, there are no code changes required in terms of how these panels are used; this process is fully transparent.</p>
  <p>After the user selects a set of files or directories, the Powerbox uses new functionality in the sandbox kernel module to expand the invoking application's sandbox to allow access to the selected files. By the time the application code queries the panel for the returned URLs or filenames, it already has permission to access those files, and can continue to use the files through almost any API it already uses.</p>
  </blockquote>
  <p>Ok. I did some practical tests using this code:</p>
  <pre><code>NSSavePanel *savePanel = [NSSavePanel savePanel];
  savePanel.delegate = self;
  
  savePanel.directoryURL = ...;
  savePanel.nameFieldStringValue = ...;
  
  [savePanel beginSheetModalForWindow:self.window
                    completionHandler:^(NSInteger returnCode) {
  /* the completion handler */
  }];
  </code></pre>
  <p>The strange thing is that the <code>NSOpenSavePanelDelegate</code> method's, that are called BEFORE the completion handler, <em>do not have access to files on the filesystem</em>.</p>
  <p>Is this correct?</p>
  <p>But if so, the delegate's methods like <code>panel:validateURL:error:</code> becomes useless!</p>
  <p>Can you help me explaining in more detail the connections between the app and <code>Powerbox</code>?</p>