2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2007-08-16 07:53:10 -07:00
|
|
|
* Steven Michaud <smichaud@pobox.com>
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "nsString.h"
|
|
|
|
|
2010-03-10 11:30:11 -08:00
|
|
|
#import <CoreServices/CoreServices.h>
|
2007-08-16 07:53:10 -07:00
|
|
|
#import <Cocoa/Cocoa.h>
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
2008-02-20 09:34:21 -08:00
|
|
|
#include "nsObjCExceptions.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsNativeAppSupportBase.h"
|
|
|
|
|
|
|
|
#include "nsIAppShellService.h"
|
|
|
|
#include "nsIAppStartup.h"
|
|
|
|
#include "nsIBaseWindow.h"
|
|
|
|
#include "nsICommandLineRunner.h"
|
2011-07-15 03:31:34 -07:00
|
|
|
#include "nsIDOMWindow.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDocShellTreeItem.h"
|
|
|
|
#include "nsIDocShellTreeOwner.h"
|
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIWebNavigation.h"
|
|
|
|
#include "nsIWidget.h"
|
|
|
|
#include "nsIWindowMediator.h"
|
|
|
|
|
|
|
|
nsresult
|
2011-07-15 03:31:34 -07:00
|
|
|
GetNativeWindowPointerFromDOMWindow(nsIDOMWindow *a_window, NSWindow **a_nativeWindow)
|
2010-03-10 11:30:11 -08:00
|
|
|
{
|
|
|
|
*a_nativeWindow = nil;
|
|
|
|
if (!a_window)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWebNavigation> mruWebNav(do_GetInterface(a_window));
|
|
|
|
if (mruWebNav) {
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> mruTreeItem(do_QueryInterface(mruWebNav));
|
|
|
|
nsCOMPtr<nsIDocShellTreeOwner> mruTreeOwner = nsnull;
|
|
|
|
mruTreeItem->GetTreeOwner(getter_AddRefs(mruTreeOwner));
|
|
|
|
if(mruTreeOwner) {
|
|
|
|
nsCOMPtr<nsIBaseWindow> mruBaseWindow(do_QueryInterface(mruTreeOwner));
|
|
|
|
if (mruBaseWindow) {
|
|
|
|
nsCOMPtr<nsIWidget> mruWidget = nsnull;
|
|
|
|
mruBaseWindow->GetMainWidget(getter_AddRefs(mruWidget));
|
|
|
|
if (mruWidget) {
|
|
|
|
*a_nativeWindow = (NSWindow*)mruWidget->GetNativeData(NS_NATIVE_WINDOW);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-10 11:30:11 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-08-16 07:53:10 -07:00
|
|
|
class nsNativeAppSupportCocoa : public nsNativeAppSupportBase
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
2007-08-16 07:53:10 -07:00
|
|
|
nsNativeAppSupportCocoa() :
|
2011-10-17 07:59:28 -07:00
|
|
|
mCanShowUI(false) { }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHOD Start(bool* aRetVal);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHOD ReOpen();
|
|
|
|
NS_IMETHOD Enable();
|
|
|
|
|
|
|
|
private:
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mCanShowUI;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2007-08-16 07:53:10 -07:00
|
|
|
nsNativeAppSupportCocoa::Enable()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
mCanShowUI = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP nsNativeAppSupportCocoa::Start(bool *_retval)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-02-20 09:34:21 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2009-09-18 09:37:22 -07:00
|
|
|
SInt32 response = 0;
|
2007-06-26 21:25:30 -07:00
|
|
|
OSErr err = ::Gestalt (gestaltSystemVersion, &response);
|
2007-08-16 07:53:10 -07:00
|
|
|
response &= 0xFFFF; // The system version is in the low order word
|
2007-06-26 21:25:30 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
// Check that the OS version is supported, if not return false,
|
2007-08-16 07:53:10 -07:00
|
|
|
// which will make the browser quit. In principle we could display an
|
|
|
|
// alert here. But the alert's message and buttons would require custom
|
|
|
|
// localization. So (for now at least) we just log an English message
|
|
|
|
// to the console before quitting.
|
2010-03-25 09:07:50 -07:00
|
|
|
#ifdef __LP64__
|
|
|
|
SInt32 minimumOS = 0x00001060;
|
|
|
|
#else
|
|
|
|
SInt32 minimumOS = 0x00001050;
|
|
|
|
#endif
|
|
|
|
if ((err != noErr) || response < minimumOS) {
|
|
|
|
NSLog(@"Minimum OS version requirement not met!");
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
*_retval = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
2008-02-20 09:34:21 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2007-08-16 07:53:10 -07:00
|
|
|
nsNativeAppSupportCocoa::ReOpen()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-02-20 09:34:21 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!mCanShowUI)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool haveNonMiniaturized = false;
|
|
|
|
bool haveOpenWindows = false;
|
|
|
|
bool done = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIWindowMediator>
|
|
|
|
wm(do_GetService(NS_WINDOWMEDIATOR_CONTRACTID));
|
2009-03-09 14:27:48 -07:00
|
|
|
if (!wm) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2009-03-09 14:27:48 -07:00
|
|
|
else {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsISimpleEnumerator> windowList;
|
|
|
|
wm->GetXULWindowEnumerator(nsnull, getter_AddRefs(windowList));
|
2011-09-28 23:19:26 -07:00
|
|
|
bool more;
|
2007-03-22 10:30:00 -07:00
|
|
|
windowList->HasMoreElements(&more);
|
2009-03-09 14:27:48 -07:00
|
|
|
while (more) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsISupports> nextWindow = nsnull;
|
|
|
|
windowList->GetNext(getter_AddRefs(nextWindow));
|
|
|
|
nsCOMPtr<nsIBaseWindow> baseWindow(do_QueryInterface(nextWindow));
|
2009-03-09 14:27:48 -07:00
|
|
|
if (!baseWindow) {
|
2007-03-22 10:30:00 -07:00
|
|
|
windowList->HasMoreElements(&more);
|
|
|
|
continue;
|
|
|
|
}
|
2009-03-09 14:27:48 -07:00
|
|
|
else {
|
2011-10-17 07:59:28 -07:00
|
|
|
haveOpenWindows = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWidget> widget = nsnull;
|
|
|
|
baseWindow->GetMainWidget(getter_AddRefs(widget));
|
2009-03-09 14:27:48 -07:00
|
|
|
if (!widget) {
|
2007-03-22 10:30:00 -07:00
|
|
|
windowList->HasMoreElements(&more);
|
|
|
|
continue;
|
|
|
|
}
|
2007-08-16 07:53:10 -07:00
|
|
|
NSWindow *cocoaWindow = (NSWindow*)widget->GetNativeData(NS_NATIVE_WINDOW);
|
|
|
|
if (![cocoaWindow isMiniaturized]) {
|
2011-10-17 07:59:28 -07:00
|
|
|
haveNonMiniaturized = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
break; //have un-minimized windows, nothing to do
|
|
|
|
}
|
|
|
|
windowList->HasMoreElements(&more);
|
|
|
|
} // end while
|
|
|
|
|
2009-03-09 14:27:48 -07:00
|
|
|
if (!haveNonMiniaturized) {
|
2007-08-16 07:53:10 -07:00
|
|
|
// Deminiaturize the most recenty used window
|
2011-07-15 03:31:34 -07:00
|
|
|
nsCOMPtr<nsIDOMWindow> mru;
|
2007-03-22 10:30:00 -07:00
|
|
|
wm->GetMostRecentWindow(nsnull, getter_AddRefs(mru));
|
|
|
|
|
2009-03-09 14:27:48 -07:00
|
|
|
if (mru) {
|
2007-08-16 07:53:10 -07:00
|
|
|
NSWindow *cocoaMru = nil;
|
|
|
|
GetNativeWindowPointerFromDOMWindow(mru, &cocoaMru);
|
|
|
|
if (cocoaMru) {
|
|
|
|
[cocoaMru deminiaturize:nil];
|
2011-10-17 07:59:28 -07:00
|
|
|
done = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-16 07:53:10 -07:00
|
|
|
} // end if have non miniaturized
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-03-09 14:27:48 -07:00
|
|
|
if (!haveOpenWindows && !done) {
|
2007-03-22 10:30:00 -07:00
|
|
|
char* argv[] = { nsnull };
|
|
|
|
|
|
|
|
// use an empty command line to make the right kind(s) of window open
|
|
|
|
nsCOMPtr<nsICommandLineRunner> cmdLine
|
|
|
|
(do_CreateInstance("@mozilla.org/toolkit/command-line;1"));
|
|
|
|
NS_ENSURE_TRUE(cmdLine, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
rv = cmdLine->Init(0, argv, nsnull,
|
|
|
|
nsICommandLine::STATE_REMOTE_EXPLICIT);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return cmdLine->Run();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // got window mediator
|
|
|
|
return NS_OK;
|
2008-02-20 09:34:21 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
2007-08-16 07:53:10 -07:00
|
|
|
// Create and return an instance of class nsNativeAppSupportCocoa.
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult NS_CreateNativeAppSupport(nsINativeAppSupport**aResult)
|
|
|
|
{
|
2007-08-16 07:53:10 -07:00
|
|
|
*aResult = new nsNativeAppSupportCocoa;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!*aResult) return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2007-08-16 07:53:10 -07:00
|
|
|
NS_ADDREF(*aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|