View | Details | Raw Unified | Return to bug 777415
Collapse All | Expand All

(-)a/modules/libpref/src/Makefile.in (+2 lines)
Lines 77-90 GREPREF_FILES = $(topsrcdir)/netwerk/bas Link Here
77
# Optimizer bug with GCC 3.2.2 on OS/2
77
# Optimizer bug with GCC 3.2.2 on OS/2
78
ifeq ($(OS_ARCH), OS2)
78
ifeq ($(OS_ARCH), OS2)
79
nsPrefService.$(OBJ_SUFFIX): nsPrefService.cpp
79
nsPrefService.$(OBJ_SUFFIX): nsPrefService.cpp
80
	$(REPORT_BUILD)
80
	$(REPORT_BUILD)
81
	@$(MAKE_DEPS_AUTO_CXX)
81
	@$(MAKE_DEPS_AUTO_CXX)
82
	$(ELOG) $(CCC) $(OUTOPTION)$@ -c $(COMPILE_CXXFLAGS:-O2=-O1) $(_VPATH_SRCS)
82
	$(ELOG) $(CCC) $(OUTOPTION)$@ -c $(COMPILE_CXXFLAGS:-O2=-O1) $(_VPATH_SRCS)
83
endif
83
endif
84
84
85
LOCAL_INCLUDES += -I$(topsrcdir)/toolkit/xre
86
85
87
86
greprefs.js: $(GREPREF_FILES)
88
greprefs.js: $(GREPREF_FILES)
87
	$(PYTHON) $(topsrcdir)/config/Preprocessor.py $(PREF_PPFLAGS) $(DEFINES) $(ACDEFINES) $(XULPPFLAGS) $^ > $@
89
	$(PYTHON) $(topsrcdir)/config/Preprocessor.py $(PREF_PPFLAGS) $(DEFINES) $(ACDEFINES) $(XULPPFLAGS) $^ > $@
88
90
89
libs:: greprefs.js
91
libs:: greprefs.js
90
	$(INSTALL) $^ $(DIST)/bin/
92
	$(INSTALL) $^ $(DIST)/bin/
(-)a/modules/libpref/src/Preferences.cpp (-1 / +32 lines)
Lines 57-72 Link Here
57
#include "nsIStringEnumerator.h"
57
#include "nsIStringEnumerator.h"
58
#include "nsIZipReader.h"
58
#include "nsIZipReader.h"
59
#include "nsPrefBranch.h"
59
#include "nsPrefBranch.h"
60
#include "nsXPIDLString.h"
60
#include "nsXPIDLString.h"
61
#include "nsCRT.h"
61
#include "nsCRT.h"
62
#include "nsCOMArray.h"
62
#include "nsCOMArray.h"
63
#include "nsXPCOMCID.h"
63
#include "nsXPCOMCID.h"
64
#include "nsAutoPtr.h"
64
#include "nsAutoPtr.h"
65
#include "nsKDEUtils.h"
65
66
66
#include "nsQuickSort.h"
67
#include "nsQuickSort.h"
67
#include "prmem.h"
68
#include "prmem.h"
68
#include "pldhash.h"
69
#include "pldhash.h"
69
70
70
#include "prefapi.h"
71
#include "prefapi.h"
71
#include "prefread.h"
72
#include "prefread.h"
72
#include "prefapi_private_data.h"
73
#include "prefapi_private_data.h"
Lines 941-956 pref_LoadPrefsInDir(nsIFile* aDir, char Link Here
941
942
942
static nsresult pref_LoadPrefsInDirList(const char *listId)
943
static nsresult pref_LoadPrefsInDirList(const char *listId)
943
{
944
{
944
  nsresult rv;
945
  nsresult rv;
945
  nsCOMPtr<nsIProperties> dirSvc(do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv));
946
  nsCOMPtr<nsIProperties> dirSvc(do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv));
946
  if (NS_FAILED(rv))
947
  if (NS_FAILED(rv))
947
    return rv;
948
    return rv;
948
949
950
  // make sure we load these special files after all the others
951
  static const char* specialFiles[] = {
952
#if defined(XP_UNIX)
953
    ""
954
#endif
955
  };
956
957
  if (nsKDEUtils::kdeSession()) {
958
    for(int i = 0;
959
        i < NS_ARRAY_LENGTH(specialFiles);
960
        ++i ) {
961
      if (*specialFiles[ i ] == '\0') {
962
        specialFiles[ i ] = "kde.js";
963
        break;
964
      }
965
    }
966
  }
967
949
  nsCOMPtr<nsISimpleEnumerator> list;
968
  nsCOMPtr<nsISimpleEnumerator> list;
950
  dirSvc->Get(listId,
969
  dirSvc->Get(listId,
951
              NS_GET_IID(nsISimpleEnumerator),
970
              NS_GET_IID(nsISimpleEnumerator),
952
              getter_AddRefs(list));
971
              getter_AddRefs(list));
953
  if (!list)
972
  if (!list)
954
    return NS_OK;
973
    return NS_OK;
955
974
956
  bool hasMore;
975
  bool hasMore;
Lines 966-982 static nsresult pref_LoadPrefsInDirList( Link Here
966
985
967
    nsCAutoString leaf;
986
    nsCAutoString leaf;
968
    path->GetNativeLeafName(leaf);
987
    path->GetNativeLeafName(leaf);
969
988
970
    // Do we care if a file provided by this process fails to load?
989
    // Do we care if a file provided by this process fails to load?
971
    if (Substring(leaf, leaf.Length() - 4).Equals(NS_LITERAL_CSTRING(".xpi")))
990
    if (Substring(leaf, leaf.Length() - 4).Equals(NS_LITERAL_CSTRING(".xpi")))
972
      ReadExtensionPrefs(path);
991
      ReadExtensionPrefs(path);
973
    else
992
    else
974
      pref_LoadPrefsInDir(path, nsnull, 0);
993
      pref_LoadPrefsInDir(path, specialFiles, NS_ARRAY_LENGTH(specialFiles));
975
  }
994
  }
976
  return NS_OK;
995
  return NS_OK;
977
}
996
}
978
997
979
static nsresult pref_ReadPrefFromJar(nsZipArchive* jarReader, const char *name)
998
static nsresult pref_ReadPrefFromJar(nsZipArchive* jarReader, const char *name)
980
{
999
{
981
  nsZipItemPtr<char> manifest(jarReader, name, true);
1000
  nsZipItemPtr<char> manifest(jarReader, name, true);
982
  NS_ENSURE_TRUE(manifest.Buffer(), NS_ERROR_NOT_AVAILABLE);
1001
  NS_ENSURE_TRUE(manifest.Buffer(), NS_ERROR_NOT_AVAILABLE);
Lines 1070-1097 static nsresult pref_InitInitialObjects( Link Here
1070
  /* these pref file names should not be used: we process them after all other application pref files for backwards compatibility */
1089
  /* these pref file names should not be used: we process them after all other application pref files for backwards compatibility */
1071
  static const char* specialFiles[] = {
1090
  static const char* specialFiles[] = {
1072
#if defined(XP_MACOSX)
1091
#if defined(XP_MACOSX)
1073
    "macprefs.js"
1092
    "macprefs.js"
1074
#elif defined(XP_WIN)
1093
#elif defined(XP_WIN)
1075
    "winpref.js"
1094
    "winpref.js"
1076
#elif defined(XP_UNIX)
1095
#elif defined(XP_UNIX)
1077
    "unix.js"
1096
    "unix.js"
1097
    , "" // placeholder for KDE  (empty is otherwise harmless)
1078
#if defined(VMS)
1098
#if defined(VMS)
1079
    , "openvms.js"
1099
    , "openvms.js"
1080
#elif defined(_AIX)
1100
#elif defined(_AIX)
1081
    , "aix.js"
1101
    , "aix.js"
1082
#endif
1102
#endif
1083
#elif defined(XP_OS2)
1103
#elif defined(XP_OS2)
1084
    "os2pref.js"
1104
    "os2pref.js"
1085
#elif defined(XP_BEOS)
1105
#elif defined(XP_BEOS)
1086
    "beos.js"
1106
    "beos.js"
1087
#endif
1107
#endif
1088
  };
1108
  };
1089
1109
1110
  if(nsKDEUtils::kdeSession()) { // TODO what if some setup actually requires the helper?
1111
    for(int i = 0;
1112
        i < NS_ARRAY_LENGTH(specialFiles);
1113
        ++i ) {
1114
      if( *specialFiles[ i ] == '\0' ) {
1115
        specialFiles[ i ] = "kde.js";
1116
        break;
1117
      }
1118
    }
1119
  }
1120
1090
  rv = pref_LoadPrefsInDir(defaultPrefDir, specialFiles, ArrayLength(specialFiles));
1121
  rv = pref_LoadPrefsInDir(defaultPrefDir, specialFiles, ArrayLength(specialFiles));
1091
  if (NS_FAILED(rv))
1122
  if (NS_FAILED(rv))
1092
    NS_WARNING("Error parsing application default preferences.");
1123
    NS_WARNING("Error parsing application default preferences.");
1093
1124
1094
  // Load jar:$app/omni.jar!/defaults/preferences/*.js
1125
  // Load jar:$app/omni.jar!/defaults/preferences/*.js
1095
  // or jar:$gre/omni.jar!/defaults/preferences/*.js.
1126
  // or jar:$gre/omni.jar!/defaults/preferences/*.js.
1096
  nsRefPtr<nsZipArchive> appJarReader = mozilla::Omnijar::GetReader(mozilla::Omnijar::APP);
1127
  nsRefPtr<nsZipArchive> appJarReader = mozilla::Omnijar::GetReader(mozilla::Omnijar::APP);
1097
  // GetReader(mozilla::Omnijar::APP) returns null when $app == $gre, in which
1128
  // GetReader(mozilla::Omnijar::APP) returns null when $app == $gre, in which
(-)a/toolkit/components/downloads/Makefile.in (+3 lines)
Lines 73-80 EXTRA_COMPONENTS = \ Link Here
73
  nsDownloadManagerUI.js \
73
  nsDownloadManagerUI.js \
74
  nsDownloadManagerUI.manifest \
74
  nsDownloadManagerUI.manifest \
75
  $(NULL)
75
  $(NULL)
76
endif
76
endif
77
77
78
TEST_DIRS += test
78
TEST_DIRS += test
79
79
80
include $(topsrcdir)/config/rules.mk
80
include $(topsrcdir)/config/rules.mk
81
82
LOCAL_INCLUDES += -I$(topsrcdir)/toolkit/xre
83
(-)a/toolkit/components/downloads/nsDownloadManager.cpp (-1 / +15 lines)
Lines 74-89 Link Here
74
74
75
#ifdef XP_WIN
75
#ifdef XP_WIN
76
#include <shlobj.h>
76
#include <shlobj.h>
77
#ifdef DOWNLOAD_SCANNER
77
#ifdef DOWNLOAD_SCANNER
78
#include "nsDownloadScanner.h"
78
#include "nsDownloadScanner.h"
79
#endif
79
#endif
80
#endif
80
#endif
81
81
82
#if defined(XP_UNIX) && !defined(XP_MACOSX)
83
#include "nsKDEUtils.h"
84
#endif
85
82
#ifdef XP_MACOSX
86
#ifdef XP_MACOSX
83
#include <CoreFoundation/CoreFoundation.h>
87
#include <CoreFoundation/CoreFoundation.h>
84
#endif
88
#endif
85
89
86
#ifdef MOZ_WIDGET_ANDROID
90
#ifdef MOZ_WIDGET_ANDROID
87
#include "AndroidBridge.h"
91
#include "AndroidBridge.h"
88
#endif
92
#endif
89
93
Lines 2259-2274 nsDownload::SetState(DownloadState aStat Link Here
2259
      nsCOMPtr<nsIPrefBranch> pref(do_GetService(NS_PREFSERVICE_CONTRACTID));
2263
      nsCOMPtr<nsIPrefBranch> pref(do_GetService(NS_PREFSERVICE_CONTRACTID));
2260
2264
2261
      // Master pref to control this function.
2265
      // Master pref to control this function.
2262
      bool showTaskbarAlert = true;
2266
      bool showTaskbarAlert = true;
2263
      if (pref)
2267
      if (pref)
2264
        pref->GetBoolPref(PREF_BDM_SHOWALERTONCOMPLETE, &showTaskbarAlert);
2268
        pref->GetBoolPref(PREF_BDM_SHOWALERTONCOMPLETE, &showTaskbarAlert);
2265
2269
2266
      if (showTaskbarAlert) {
2270
      if (showTaskbarAlert) {
2271
        if( nsKDEUtils::kdeSupport()) {
2272
          nsTArray<nsCString> command;
2273
          command.AppendElement( NS_LITERAL_CSTRING( "DOWNLOADFINISHED" ));
2274
          nsAutoString displayName;
2275
          GetDisplayName( displayName );
2276
          command.AppendElement( nsCAutoString( ToNewUTF8String( displayName )));
2277
          nsKDEUtils::command( command );
2278
        } else {
2279
        // begin non-KDE block
2267
        PRInt32 alertInterval = 2000;
2280
        PRInt32 alertInterval = 2000;
2268
        if (pref)
2281
        if (pref)
2269
          pref->GetIntPref(PREF_BDM_SHOWALERTINTERVAL, &alertInterval);
2282
          pref->GetIntPref(PREF_BDM_SHOWALERTINTERVAL, &alertInterval);
2270
2283
2271
        PRInt64 alertIntervalUSec = alertInterval * PR_USEC_PER_MSEC;
2284
        PRInt64 alertIntervalUSec = alertInterval * PR_USEC_PER_MSEC;
2272
        PRInt64 goat = PR_Now() - mStartTime;
2285
        PRInt64 goat = PR_Now() - mStartTime;
2273
        showTaskbarAlert = goat > alertIntervalUSec;
2286
        showTaskbarAlert = goat > alertIntervalUSec;
2274
2287
Lines 2292-2310 nsDownload::SetState(DownloadState aStat Link Here
2292
              // If downloads are automatically removed per the user's
2305
              // If downloads are automatically removed per the user's
2293
              // retention policy, there's no reason to make the text clickable
2306
              // retention policy, there's no reason to make the text clickable
2294
              // because if it is, they'll click open the download manager and
2307
              // because if it is, they'll click open the download manager and
2295
              // the items they downloaded will have been removed.
2308
              // the items they downloaded will have been removed.
2296
              alerts->ShowAlertNotification(
2309
              alerts->ShowAlertNotification(
2297
                  NS_LITERAL_STRING(DOWNLOAD_MANAGER_ALERT_ICON), title,
2310
                  NS_LITERAL_STRING(DOWNLOAD_MANAGER_ALERT_ICON), title,
2298
                  message, !removeWhenDone, EmptyString(), mDownloadManager,
2311
                  message, !removeWhenDone, EmptyString(), mDownloadManager,
2299
                  EmptyString());
2312
                  EmptyString());
2300
            }
2313
          }
2301
        }
2314
        }
2302
      }
2315
      }
2316
      }
2303
2317
2304
#if defined(XP_WIN) || defined(XP_MACOSX) || defined(MOZ_WIDGET_ANDROID)
2318
#if defined(XP_WIN) || defined(XP_MACOSX) || defined(MOZ_WIDGET_ANDROID)
2305
      nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(mTarget);
2319
      nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(mTarget);
2306
      nsCOMPtr<nsIFile> file;
2320
      nsCOMPtr<nsIFile> file;
2307
      nsAutoString path;
2321
      nsAutoString path;
2308
2322
2309
      if (fileURL &&
2323
      if (fileURL &&
2310
          NS_SUCCEEDED(fileURL->GetFile(getter_AddRefs(file))) &&
2324
          NS_SUCCEEDED(fileURL->GetFile(getter_AddRefs(file))) &&
(-)a/toolkit/content/jar.mn (+4 lines)
Lines 44-72 toolkit.jar: Link Here
44
*+ content/global/viewZoomOverlay.js          (viewZoomOverlay.js)
44
*+ content/global/viewZoomOverlay.js          (viewZoomOverlay.js)
45
*+ content/global/bindings/autocomplete.xml    (widgets/autocomplete.xml)
45
*+ content/global/bindings/autocomplete.xml    (widgets/autocomplete.xml)
46
*+ content/global/bindings/browser.xml         (widgets/browser.xml)
46
*+ content/global/bindings/browser.xml         (widgets/browser.xml)
47
*+ content/global/bindings/button.xml          (widgets/button.xml)
47
*+ content/global/bindings/button.xml          (widgets/button.xml)
48
*+ content/global/bindings/checkbox.xml        (widgets/checkbox.xml)
48
*+ content/global/bindings/checkbox.xml        (widgets/checkbox.xml)
49
*+ content/global/bindings/colorpicker.xml     (widgets/colorpicker.xml)
49
*+ content/global/bindings/colorpicker.xml     (widgets/colorpicker.xml)
50
*+ content/global/bindings/datetimepicker.xml  (widgets/datetimepicker.xml)
50
*+ content/global/bindings/datetimepicker.xml  (widgets/datetimepicker.xml)
51
*+ content/global/bindings/dialog.xml          (widgets/dialog.xml)
51
*+ content/global/bindings/dialog.xml          (widgets/dialog.xml)
52
*+ content/global/bindings/dialog-kde.xml      (widgets/dialog-kde.xml)
53
% override chrome://global/content/bindings/dialog.xml chrome://global/content/bindings/dialog-kde.xml desktop=kde
52
*+ content/global/bindings/editor.xml          (widgets/editor.xml)
54
*+ content/global/bindings/editor.xml          (widgets/editor.xml)
53
*  content/global/bindings/expander.xml        (widgets/expander.xml)
55
*  content/global/bindings/expander.xml        (widgets/expander.xml)
54
*  content/global/bindings/filefield.xml       (widgets/filefield.xml)
56
*  content/global/bindings/filefield.xml       (widgets/filefield.xml)
55
*+ content/global/bindings/findbar.xml         (widgets/findbar.xml)
57
*+ content/global/bindings/findbar.xml         (widgets/findbar.xml)
56
*+ content/global/bindings/general.xml         (widgets/general.xml)
58
*+ content/global/bindings/general.xml         (widgets/general.xml)
57
*+ content/global/bindings/groupbox.xml        (widgets/groupbox.xml)
59
*+ content/global/bindings/groupbox.xml        (widgets/groupbox.xml)
58
*+ content/global/bindings/listbox.xml         (widgets/listbox.xml)
60
*+ content/global/bindings/listbox.xml         (widgets/listbox.xml)
59
*+ content/global/bindings/menu.xml            (widgets/menu.xml)
61
*+ content/global/bindings/menu.xml            (widgets/menu.xml)
60
*+ content/global/bindings/menulist.xml        (widgets/menulist.xml)
62
*+ content/global/bindings/menulist.xml        (widgets/menulist.xml)
61
*+ content/global/bindings/notification.xml    (widgets/notification.xml)
63
*+ content/global/bindings/notification.xml    (widgets/notification.xml)
62
*+ content/global/bindings/numberbox.xml       (widgets/numberbox.xml)
64
*+ content/global/bindings/numberbox.xml       (widgets/numberbox.xml)
63
*+ content/global/bindings/popup.xml           (widgets/popup.xml)
65
*+ content/global/bindings/popup.xml           (widgets/popup.xml)
64
*+ content/global/bindings/preferences.xml     (widgets/preferences.xml)
66
*+ content/global/bindings/preferences.xml     (widgets/preferences.xml)
67
*+ content/global/bindings/preferences-kde.xml (widgets/preferences-kde.xml)
68
% override chrome://global/content/bindings/preferences.xml chrome://global/content/bindings/preferences-kde.xml desktop=kde
65
*+ content/global/bindings/progressmeter.xml   (widgets/progressmeter.xml)
69
*+ content/global/bindings/progressmeter.xml   (widgets/progressmeter.xml)
66
*+ content/global/bindings/radio.xml           (widgets/radio.xml)
70
*+ content/global/bindings/radio.xml           (widgets/radio.xml)
67
*+ content/global/bindings/resizer.xml         (widgets/resizer.xml)
71
*+ content/global/bindings/resizer.xml         (widgets/resizer.xml)
68
*+ content/global/bindings/richlistbox.xml     (widgets/richlistbox.xml)
72
*+ content/global/bindings/richlistbox.xml     (widgets/richlistbox.xml)
69
*+ content/global/bindings/scale.xml           (widgets/scale.xml)
73
*+ content/global/bindings/scale.xml           (widgets/scale.xml)
70
*+ content/global/bindings/scrollbar.xml       (widgets/scrollbar.xml)
74
*+ content/global/bindings/scrollbar.xml       (widgets/scrollbar.xml)
71
*+ content/global/bindings/scrollbox.xml       (widgets/scrollbox.xml)
75
*+ content/global/bindings/scrollbox.xml       (widgets/scrollbox.xml)
72
*+ content/global/bindings/splitter.xml        (widgets/splitter.xml)
76
*+ content/global/bindings/splitter.xml        (widgets/splitter.xml)
(-)a/toolkit/content/widgets/dialog-kde.xml (+447 lines)
Line 0 Link Here
1
<?xml version="1.0"?>
2
3
<bindings id="dialogBindings"
4
          xmlns="http://www.mozilla.org/xbl"
5
          xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
6
          xmlns:xbl="http://www.mozilla.org/xbl">
7
  
8
  <binding id="dialog" extends="chrome://global/content/bindings/general.xml#root-element">
9
    <resources>
10
      <stylesheet src="chrome://global/skin/dialog.css"/>
11
    </resources>
12
    <content>
13
      <xul:vbox class="box-inherit dialog-content-box" flex="1">
14
        <children/>
15
      </xul:vbox>
16
          
17
      <xul:hbox class="dialog-button-box" anonid="buttons"
18
                xbl:inherits="pack=buttonpack,align=buttonalign,dir=buttondir,orient=buttonorient"
19
#ifdef XP_UNIX_GNOME
20
                >
21
        <xul:button dlgtype="disclosure" class="dialog-button" hidden="true"/>
22
        <xul:button dlgtype="help" class="dialog-button" hidden="true"/>
23
        <xul:button dlgtype="extra2" class="dialog-button" hidden="true"/>
24
        <xul:button dlgtype="extra1" class="dialog-button" hidden="true"/>
25
        <xul:spacer anonid="spacer" flex="1"/>
26
        <xul:button dlgtype="cancel" class="dialog-button"/>
27
        <xul:button dlgtype="accept" class="dialog-button" xbl:inherits="disabled=buttondisabledaccept"/>
28
#elif XP_UNIX
29
                pack="end">
30
	<xul:button dlgtype="help" class="dialog-button" hidden="true"/>
31
	<xul:button dlgtype="extra2" class="dialog-button" hidden="true"/>
32
	<xul:spacer anonid="spacer" flex="1" hidden="true"/>
33
	<xul:button dlgtype="accept" class="dialog-button" xbl:inherits="disabled=buttondisabledaccept"/>
34
	<xul:button dlgtype="extra1" class="dialog-button" hidden="true"/>
35
	<xul:button dlgtype="cancel" class="dialog-button"/>
36
	<xul:button dlgtype="disclosure" class="dialog-button" hidden="true"/>
37
#else
38
                pack="end">
39
        <xul:button dlgtype="extra2" class="dialog-button" hidden="true"/>
40
        <xul:spacer anonid="spacer" flex="1" hidden="true"/>
41
        <xul:button dlgtype="accept" class="dialog-button" xbl:inherits="disabled=buttondisabledaccept"/>
42
        <xul:button dlgtype="extra1" class="dialog-button" hidden="true"/>
43
        <xul:button dlgtype="cancel" class="dialog-button"/>
44
        <xul:button dlgtype="help" class="dialog-button" hidden="true"/>
45
        <xul:button dlgtype="disclosure" class="dialog-button" hidden="true"/>
46
#endif
47
      </xul:hbox>
48
    </content>
49
50
    <implementation>
51
      <field name="_mStrBundle">null</field>
52
      <field name="_closeHandler">(function(event) {
53
        if (!document.documentElement.cancelDialog())
54
          event.preventDefault();
55
      })</field>
56
57
      <property name="buttons"
58
                onget="return this.getAttribute('buttons');"
59
                onset="this._configureButtons(val); return val;"/>
60
61
      <property name="defaultButton">
62
        <getter>
63
        <![CDATA[
64
          if (this.hasAttribute("defaultButton"))
65
            return this.getAttribute("defaultButton");
66
          else // default to the accept button
67
            return "accept";
68
        ]]>
69
        </getter>
70
        <setter>
71
        <![CDATA[
72
          this._setDefaultButton(val);
73
          return val;
74
        ]]>
75
        </setter>
76
      </property>
77
78
      <method name="acceptDialog">
79
        <body>
80
        <![CDATA[
81
          return this._doButtonCommand("accept");
82
        ]]>
83
        </body>
84
      </method>
85
      
86
      <method name="cancelDialog">
87
        <body>
88
        <![CDATA[
89
          return this._doButtonCommand("cancel");
90
        ]]>
91
        </body>
92
      </method>
93
      
94
      <method name="getButton">
95
        <parameter name="aDlgType"/>
96
        <body>
97
        <![CDATA[
98
          return this._buttons[aDlgType];
99
        ]]>
100
        </body>
101
      </method>
102
103
      <method name="moveToAlertPosition">
104
        <body>
105
        <![CDATA[
106
          // hack. we need this so the window has something like its final size
107
          if (window.outerWidth == 1) {
108
            dump("Trying to position a sizeless window; caller should have called sizeToContent() or sizeTo(). See bug 75649.\n");
109
            sizeToContent();
110
          }
111
112
          var xOffset = (opener.outerWidth - window.outerWidth) / 2;
113
          var yOffset = opener.outerHeight / 5;
114
115
          var newX = opener.screenX + xOffset;
116
          var newY = opener.screenY + yOffset;
117
118
          // ensure the window is fully onscreen (if smaller than the screen)
119
          if (newX < screen.availLeft)
120
            newX = screen.availLeft + 20;
121
          if ((newX + window.outerWidth) > (screen.availLeft + screen.availWidth))
122
            newX = (screen.availLeft + screen.availWidth) - window.outerWidth - 20;
123
124
          if (newY < screen.availTop)
125
            newY = screen.availTop + 20;
126
          if ((newY + window.outerHeight) > (screen.availTop + screen.availHeight))
127
            newY = (screen.availTop + screen.availHeight) - window.outerHeight - 60;
128
129
          window.moveTo( newX, newY );
130
        ]]>
131
        </body>
132
      </method>
133
134
      <method name="centerWindowOnScreen">
135
        <body>
136
        <![CDATA[
137
          var xOffset = screen.availWidth/2 - window.outerWidth/2;
138
          var yOffset = screen.availHeight/2 - window.outerHeight/2; //(opener.outerHeight *2)/10;
139
  
140
          xOffset = xOffset > 0 ? xOffset : 0;
141
          yOffset = yOffset > 0 ? yOffset : 0;
142
          window.moveTo(xOffset, yOffset);
143
        ]]>
144
        </body>
145
      </method>
146
147
      <constructor>
148
      <![CDATA[
149
        this._configureButtons(this.buttons);
150
151
        // listen for when window is closed via native close buttons
152
        window.addEventListener("close", this._closeHandler, false);
153
154
        // for things that we need to initialize after onload fires
155
        window.addEventListener("load", this.postLoadInit, false);
156
157
        window.moveToAlertPosition = this.moveToAlertPosition;
158
        window.centerWindowOnScreen = this.centerWindowOnScreen;
159
      ]]>
160
      </constructor>
161
162
      <method name="postLoadInit">
163
        <parameter name="aEvent"/>
164
        <body>
165
        <![CDATA[
166
          function focusInit() {
167
            const dialog = document.documentElement;
168
            const defaultButton = dialog.getButton(dialog.defaultButton);
169
            // give focus to the first focusable element in the dialog
170
            if (!document.commandDispatcher.focusedElement) {
171
              document.commandDispatcher.advanceFocusIntoSubtree(dialog);
172
173
              var focusedElt = document.commandDispatcher.focusedElement;
174
              if (focusedElt) {
175
                var initialFocusedElt = focusedElt;
176
                while (focusedElt.localName == "tab" ||
177
                       focusedElt.getAttribute("noinitialfocus") == "true") {
178
                  document.commandDispatcher.advanceFocusIntoSubtree(focusedElt);
179
                  focusedElt = document.commandDispatcher.focusedElement;
180
                  if (focusedElt == initialFocusedElt)
181
                    break;
182
                }
183
184
                if (initialFocusedElt.localName == "tab") {
185
                  if (focusedElt.hasAttribute("dlgtype")) {
186
                    // We don't want to focus on anonymous OK, Cancel, etc. buttons,
187
                    // so return focus to the tab itself
188
                    initialFocusedElt.focus();
189
                  }
190
                }
191
#ifndef XP_MACOSX
192
                else if (focusedElt.hasAttribute("dlgtype") && focusedElt != defaultButton) {
193
                  defaultButton.focus();
194
                }
195
#endif
196
              }
197
            }
198
199
            try {
200
              if (defaultButton)
201
                window.notifyDefaultButtonLoaded(defaultButton);
202
            } catch (e) { }
203
          }
204
205
          // Give focus after onload completes, see bug 103197.
206
          setTimeout(focusInit, 0);
207
        ]]>
208
        </body>
209
      </method>                
210
211
      <property name="mStrBundle">
212
        <getter>
213
        <![CDATA[
214
          if (!this._mStrBundle) {
215
            // need to create string bundle manually instead of using <xul:stringbundle/>
216
            // see bug 63370 for details
217
            this._mStrBundle = Components.classes["@mozilla.org/intl/stringbundle;1"]
218
                                         .getService(Components.interfaces.nsIStringBundleService)
219
                                         .createBundle("chrome://global/locale/dialog.properties");
220
          }
221
          return this._mStrBundle;
222
        ]]></getter>
223
      </property>
224
      
225
      <method name="_configureButtons">
226
        <parameter name="aButtons"/>
227
        <body>
228
        <![CDATA[
229
          // by default, get all the anonymous button elements
230
          var buttons = {};
231
          this._buttons = buttons;
232
          buttons.accept = document.getAnonymousElementByAttribute(this, "dlgtype", "accept");
233
          buttons.cancel = document.getAnonymousElementByAttribute(this, "dlgtype", "cancel");
234
          buttons.extra1 = document.getAnonymousElementByAttribute(this, "dlgtype", "extra1");
235
          buttons.extra2 = document.getAnonymousElementByAttribute(this, "dlgtype", "extra2");
236
          buttons.help = document.getAnonymousElementByAttribute(this, "dlgtype", "help");
237
          buttons.disclosure = document.getAnonymousElementByAttribute(this, "dlgtype", "disclosure");
238
239
          // look for any overriding explicit button elements
240
          var exBtns = this.getElementsByAttribute("dlgtype", "*");
241
          var dlgtype;
242
          var i;
243
          for (i = 0; i < exBtns.length; ++i) {
244
            dlgtype = exBtns[i].getAttribute("dlgtype");
245
            buttons[dlgtype].hidden = true; // hide the anonymous button
246
            buttons[dlgtype] = exBtns[i];
247
          }
248
249
          // add the label and oncommand handler to each button
250
          for (dlgtype in buttons) {
251
            var button = buttons[dlgtype];
252
            button.addEventListener("command", this._handleButtonCommand, true);
253
254
            // don't override custom labels with pre-defined labels on explicit buttons
255
            if (!button.hasAttribute("label")) {
256
              // dialog attributes override the default labels in dialog.properties
257
              if (this.hasAttribute("buttonlabel"+dlgtype)) {
258
                button.setAttribute("label", this.getAttribute("buttonlabel"+dlgtype));
259
                if (this.hasAttribute("buttonaccesskey"+dlgtype))
260
                  button.setAttribute("accesskey", this.getAttribute("buttonaccesskey"+dlgtype));
261
              } else if (dlgtype != "extra1" && dlgtype != "extra2") {
262
                button.setAttribute("label", this.mStrBundle.GetStringFromName("button-"+dlgtype));
263
                var accessKey = this.mStrBundle.GetStringFromName("accesskey-"+dlgtype);
264
                if (accessKey)
265
                  button.setAttribute("accesskey", accessKey);
266
              }
267
            }
268
            // allow specifying alternate icons in the dialog header
269
            if (!button.hasAttribute("icon")) {
270
              // if there's an icon specified, use that
271
              if (this.hasAttribute("buttonicon"+dlgtype))
272
                button.setAttribute("icon", this.getAttribute("buttonicon"+dlgtype));
273
              // otherwise set defaults
274
              else
275
                switch (dlgtype) {
276
                  case "accept":
277
                    button.setAttribute("icon","accept");
278
                    break;
279
                  case "cancel":
280
                    button.setAttribute("icon","cancel");
281
                    break;
282
                  case "disclosure":
283
                    button.setAttribute("icon","properties");
284
                    break;
285
                  case "help":
286
                    button.setAttribute("icon","help");
287
                    break;
288
                  default:
289
                    break;
290
                }
291
            }
292
          }
293
294
          // ensure that hitting enter triggers the default button command
295
          this.defaultButton = this.defaultButton;
296
          
297
          // if there is a special button configuration, use it
298
          if (aButtons) {
299
            // expect a comma delimited list of dlgtype values
300
            var list = aButtons.split(",");
301
302
            // mark shown dlgtypes as true
303
            var shown = { accept: false, cancel: false, help: false,
304
                          disclosure: false, extra1: false, extra2: false };
305
            for (i = 0; i < list.length; ++i)
306
              shown[list[i].replace(/ /g, "")] = true;
307
308
            // hide/show the buttons we want
309
            for (dlgtype in buttons) 
310
              buttons[dlgtype].hidden = !shown[dlgtype];
311
312
#ifdef XP_WIN
313
#           show the spacer on Windows only when the extra2 button is present
314
            var spacer = document.getAnonymousElementByAttribute(this, "anonid", "spacer");
315
            spacer.removeAttribute("hidden");
316
            spacer.setAttribute("flex", shown["extra2"]?"1":"0");
317
#endif
318
319
          }
320
        ]]>
321
        </body>
322
      </method>
323
324
      <method name="_setDefaultButton">
325
        <parameter name="aNewDefault"/>
326
        <body>
327
        <![CDATA[
328
          // remove the default attribute from the previous default button, if any
329
          var oldDefaultButton = this.getButton(this.defaultButton);
330
          if (oldDefaultButton)
331
            oldDefaultButton.removeAttribute("default");
332
333
          var newDefaultButton = this.getButton(aNewDefault);
334
          if (newDefaultButton) {
335
            this.setAttribute("defaultButton", aNewDefault);
336
            newDefaultButton.setAttribute("default", "true");
337
          }
338
          else {
339
            this.setAttribute("defaultButton", "none");
340
            if (aNewDefault != "none")
341
              dump("invalid new default button: " +  aNewDefault + ", assuming: none\n");
342
          }
343
        ]]>
344
        </body>
345
      </method>
346
347
      <method name="_handleButtonCommand">
348
        <parameter name="aEvent"/>
349
        <body>
350
        <![CDATA[
351
          return document.documentElement._doButtonCommand(
352
                                        aEvent.target.getAttribute("dlgtype"));
353
        ]]>
354
        </body>
355
      </method>
356
      
357
      <method name="_doButtonCommand">
358
        <parameter name="aDlgType"/>
359
        <body>
360
        <![CDATA[
361
          var button = this.getButton(aDlgType);
362
          if (!button.disabled) {
363
            var noCancel = this._fireButtonEvent(aDlgType);
364
            if (noCancel) {
365
              if (aDlgType == "accept" || aDlgType == "cancel")
366
                window.close();
367
            }
368
            return noCancel;
369
          }
370
          return true;
371
        ]]>
372
        </body>
373
      </method>
374
      
375
      <method name="_fireButtonEvent">
376
        <parameter name="aDlgType"/>
377
        <body>
378
        <![CDATA[
379
          var event = document.createEvent("Events");
380
          event.initEvent("dialog"+aDlgType, true, true);
381
          
382
          // handle dom event handlers
383
          var noCancel = this.dispatchEvent(event);
384
          
385
          // handle any xml attribute event handlers
386
          var handler = this.getAttribute("ondialog"+aDlgType);
387
          if (handler != "") {
388
            var fn = new Function("event", handler);
389
            var returned = fn(event);
390
            if (returned == false)
391
              noCancel = false;
392
          }
393
          
394
          return noCancel;
395
        ]]>
396
        </body>
397
      </method>
398
399
      <method name="_hitEnter">
400
        <parameter name="evt"/>
401
        <body>
402
        <![CDATA[
403
          if (evt.defaultPrevented)
404
            return;
405
406
          var btn = this.getButton(this.defaultButton);
407
          if (btn)
408
            this._doButtonCommand(this.defaultButton);
409
        ]]>
410
        </body>
411
      </method>
412
413
    </implementation>
414
    
415
    <handlers>
416
      <handler event="keypress" keycode="VK_ENTER"
417
               group="system" action="this._hitEnter(event);"/>
418
      <handler event="keypress" keycode="VK_RETURN"
419
               group="system" action="this._hitEnter(event);"/>
420
      <handler event="keypress" keycode="VK_ESCAPE" group="system">
421
        if (!event.defaultPrevented)
422
          this.cancelDialog();
423
      </handler>
424
#ifdef XP_MACOSX
425
      <handler event="keypress" key="." modifiers="meta" phase="capturing" action="this.cancelDialog();"/>
426
#else
427
      <handler event="focus" phase="capturing">
428
        var btn = this.getButton(this.defaultButton);
429
        if (btn)
430
          btn.setAttribute("default", event.originalTarget == btn || !(event.originalTarget instanceof Components.interfaces.nsIDOMXULButtonElement));
431
      </handler>
432
#endif
433
    </handlers>
434
435
  </binding>
436
437
  <binding id="dialogheader">
438
    <resources>
439
      <stylesheet src="chrome://global/skin/dialog.css"/>
440
    </resources>
441
    <content>
442
      <xul:label class="dialogheader-title" xbl:inherits="value=title,crop" crop="right" flex="1"/>
443
      <xul:label class="dialogheader-description" xbl:inherits="value=description"/>
444
    </content>
445
  </binding>
446
447
</bindings>
(-)a/toolkit/content/widgets/preferences-kde.xml (+1373 lines)
Line 0 Link Here
1
<?xml version="1.0"?>
2
3
<!DOCTYPE bindings [
4
  <!ENTITY % preferencesDTD SYSTEM "chrome://global/locale/preferences.dtd">
5
  %preferencesDTD;
6
  <!ENTITY % globalKeysDTD SYSTEM "chrome://global/locale/globalKeys.dtd">
7
  %globalKeysDTD;
8
]>
9
10
<bindings id="preferencesBindings"
11
          xmlns="http://www.mozilla.org/xbl"
12
          xmlns:xbl="http://www.mozilla.org/xbl"
13
          xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
14
15
#
16
# = Preferences Window Framework
17
#
18
#   The syntax for use looks something like:
19
#
20
#   <prefwindow>
21
#     <prefpane id="prefPaneA">
22
#       <preferences>
23
#         <preference id="preference1" name="app.preference1" type="bool" onchange="foo();"/>
24
#         <preference id="preference2" name="app.preference2" type="bool" useDefault="true"/>
25
#       </preferences>
26
#       <checkbox label="Preference" preference="preference1"/>
27
#     </prefpane>
28
#   </prefwindow>
29
#
30
31
  <binding id="preferences">
32
    <implementation implements="nsIObserver">
33
      <method name="observe">
34
        <parameter name="aSubject"/>
35
        <parameter name="aTopic"/>
36
        <parameter name="aData"/>
37
        <body>
38
        <![CDATA[
39
          for (var i = 0; i < this.childNodes.length; ++i) {
40
            var preference = this.childNodes[i];
41
            if (preference.name == aData) {
42
              preference.value = preference.valueFromPreferences;
43
            }
44
          }
45
        ]]>
46
        </body>
47
      </method>
48
      
49
      <method name="fireChangedEvent">
50
        <parameter name="aPreference"/>
51
        <body>
52
        <![CDATA[
53
          // Value changed, synthesize an event
54
          try {
55
            var event = document.createEvent("Events");
56
            event.initEvent("change", true, true);
57
            aPreference.dispatchEvent(event);
58
          }
59
          catch (e) {
60
            Components.utils.reportError(e);
61
          }
62
        ]]>
63
        </body>
64
      </method>
65
      
66
      <field name="service">
67
        Components.classes["@mozilla.org/preferences-service;1"]
68
                  .getService(Components.interfaces.nsIPrefService);
69
      </field>
70
      <field name="rootBranch">
71
        Components.classes["@mozilla.org/preferences-service;1"]
72
                  .getService(Components.interfaces.nsIPrefBranch);
73
      </field>
74
      <field name="defaultBranch">
75
        this.service.getDefaultBranch("");
76
      </field>
77
      <field name="rootBranchInternal">
78
        Components.classes["@mozilla.org/preferences-service;1"]
79
                  .getService(Components.interfaces.nsIPrefBranchInternal);
80
      </field>
81
      <property name="type" readonly="true">
82
        <getter>
83
          <![CDATA[
84
            return document.documentElement.type || "";
85
          ]]>
86
        </getter>
87
      </property>
88
      <property name="instantApply" readonly="true">
89
        <getter>
90
          <![CDATA[
91
            var doc = document.documentElement;
92
            return this.type == "child" ? doc.instantApply
93
                                        : doc.instantApply || this.rootBranch.getBoolPref("browser.preferences.instantApply");
94
          ]]>
95
        </getter>
96
      </property>
97
    </implementation>
98
  </binding>
99
100
  <binding id="preference">
101
    <implementation>
102
      <constructor>
103
      <![CDATA[
104
        // if the element has been inserted without the name attribute set,
105
        // we have nothing to do here
106
        if (!this.name)
107
          return;
108
109
        this.preferences.rootBranchInternal
110
            .addObserver(this.name, this.preferences, false);
111
        // In non-instant apply mode, we must try and use the last saved state
112
        // from any previous opens of a child dialog instead of the value from
113
        // preferences, to pick up any edits a user may have made. 
114
        if (this.preferences.type == "child" && 
115
            !this.instantApply && window.opener) {
116
          var pdoc = window.opener.document;
117
118
          // Try to find a preference element for the same preference.
119
          var preference = null;
120
          var parentPreferences = pdoc.getElementsByTagName("preferences");
121
          for (var k = 0; (k < parentPreferences.length && !preference); ++k) {
122
            var parentPrefs = parentPreferences[k]
123
                                    .getElementsByAttribute("name", this.name);
124
            for (var l = 0; (l < parentPrefs.length && !preference); ++l) {
125
              if (parentPrefs[l].localName == "preference")
126
                preference = parentPrefs[l];
127
            }
128
          }
129
          this._setValue(preference ? preference.value 
130
                                    : this.valueFromPreferences, false);
131
        }
132
        else
133
          this._setValue(this.valueFromPreferences, false);
134
      ]]>
135
      </constructor>
136
      <destructor>
137
        this.preferences.rootBranchInternal
138
            .removeObserver(this.name, this.preferences);
139
      </destructor>
140
      
141
      <property name="instantApply">
142
        <getter>
143
          return this.getAttribute("instantApply") == "true" || this.preferences.instantApply;
144
        </getter>
145
      </property>
146
147
      <property name="preferences" onget="return this.parentNode"/>
148
      <property name="name" onget="return this.getAttribute('name');">
149
        <setter>
150
          if (val == this.name)
151
            return val;
152
            
153
          this.preferences.rootBranchInternal
154
              .removeObserver(this.name, this.preferences);
155
          this.setAttribute('name', val);
156
          this.preferences.rootBranchInternal
157
              .addObserver(val, this.preferences, false);
158
              
159
          return val;
160
        </setter>
161
      </property>
162
      <property name="type" onget="return this.getAttribute('type');"
163
                            onset="this.setAttribute('type', val); return val;"/>
164
      <property name="inverted" onget="return this.getAttribute('inverted') == 'true';"
165
                                onset="this.setAttribute('inverted', val); return val;"/>
166
      <property name="readonly" onget="return this.getAttribute('readonly') == 'true';"
167
                                onset="this.setAttribute('readonly', val); return val;"/>
168
169
      <field name="_value">null</field>
170
      <method name="_setValue">
171
        <parameter name="aValue"/>
172
        <parameter name="aUpdate"/>
173
        <body>
174
        <![CDATA[
175
          if (aUpdate && this.value !== aValue) {
176
            this._value = aValue;
177
            if (this.instantApply)
178
              this.valueFromPreferences = aValue;
179
            this.preferences.fireChangedEvent(this);
180
          }
181
          else if (!aUpdate) {
182
            this._value = aValue;
183
            this.updateElements();
184
          }
185
          return aValue;
186
        ]]>
187
        </body>
188
      </method>
189
      <property name="value" onget="return this._value" onset="return this._setValue(val, true);"/>
190
      
191
      <property name="locked">
192
        <getter>
193
          return this.preferences.rootBranch.prefIsLocked(this.name);
194
        </getter>
195
      </property>
196
      
197
      <property name="disabled">
198
        <getter>
199
          return this.getAttribute("disabled") == "true";
200
        </getter>
201
        <setter>
202
        <![CDATA[
203
          if (val) 
204
            this.setAttribute("disabled", "true");
205
          else
206
            this.removeAttribute("disabled");
207
208
          if (!this.id)
209
            return val;
210
211
          var elements = document.getElementsByAttribute("preference", this.id);
212
          for (var i = 0; i < elements.length; ++i) {
213
            elements[i].disabled = val;
214
            
215
            var labels = document.getElementsByAttribute("control", elements[i].id);
216
            for (var j = 0; j < labels.length; ++j)
217
              labels[j].disabled = val;
218
          }
219
            
220
          return val;
221
        ]]>
222
        </setter>
223
      </property>
224
      
225
      <property name="tabIndex">
226
        <getter>
227
          return parseInt(this.getAttribute("tabindex"));
228
        </getter>
229
        <setter>
230
        <![CDATA[
231
          if (val) 
232
            this.setAttribute("tabindex", val);
233
          else
234
            this.removeAttribute("tabindex");
235
236
          if (!this.id)
237
            return val;
238
239
          var elements = document.getElementsByAttribute("preference", this.id);
240
          for (var i = 0; i < elements.length; ++i) {
241
            elements[i].tabIndex = val;
242
            
243
            var labels = document.getElementsByAttribute("control", elements[i].id);
244
            for (var j = 0; j < labels.length; ++j)
245
              labels[j].tabIndex = val;
246
          }
247
            
248
          return val;
249
        ]]>
250
        </setter>
251
      </property>
252
253
      <property name="hasUserValue">
254
        <getter>
255
        <![CDATA[
256
          return this.preferences.rootBranch.prefHasUserValue(this.name) &&
257
                 this.value !== undefined;
258
        ]]>
259
        </getter>
260
      </property>
261
      
262
      <method name="reset">
263
        <body>
264
          // defer reset until preference update
265
          this.value = undefined;
266
        </body>
267
      </method>
268
269
      <field name="_useDefault">false</field>      
270
      <property name="defaultValue">
271
        <getter>
272
        <![CDATA[
273
          this._useDefault = true;
274
          var val = this.valueFromPreferences;
275
          this._useDefault = false;
276
          return val;
277
        ]]>
278
        </getter>
279
      </property>
280
      
281
      <property name="_branch">
282
        <getter>
283
          return this._useDefault ? this.preferences.defaultBranch : this.preferences.rootBranch;
284
        </getter>
285
      </property>
286
      
287
      <field name="batching">false</field>
288
      
289
      <method name="_reportUnknownType">
290
        <body>
291
        <![CDATA[
292
          var consoleService = Components.classes["@mozilla.org/consoleservice;1"]
293
                                         .getService(Components.interfaces.nsIConsoleService);
294
          var msg = "<preference> with id='" + this.id + "' and name='" + 
295
                    this.name + "' has unknown type '" + this.type + "'.";
296
          consoleService.logStringMessage(msg);
297
        ]]>
298
        </body>
299
      </method>
300
      
301
      <property name="valueFromPreferences">
302
        <getter>
303
        <![CDATA[
304
          try {
305
            // Force a resync of value with preferences.
306
            switch (this.type) {
307
            case "int":
308
              return this._branch.getIntPref(this.name);
309
            case "bool":
310
              var val = this._branch.getBoolPref(this.name);
311
              return this.inverted ? !val : val;
312
            case "wstring":
313
              return this._branch
314
                         .getComplexValue(this.name, Components.interfaces.nsIPrefLocalizedString)
315
                         .data;
316
            case "string":
317
            case "unichar":
318
              return this._branch
319
                         .getComplexValue(this.name, Components.interfaces.nsISupportsString)
320
                         .data;
321
            case "fontname":
322
              var family = this._branch
323
                               .getComplexValue(this.name, Components.interfaces.nsISupportsString)
324
                               .data;
325
              var fontEnumerator = Components.classes["@mozilla.org/gfx/fontenumerator;1"]
326
                                             .createInstance(Components.interfaces.nsIFontEnumerator);
327
              return fontEnumerator.getStandardFamilyName(family);
328
            case "file":
329
              var f = this._branch
330
                          .getComplexValue(this.name, Components.interfaces.nsILocalFile);
331
              return f;
332
            default:
333
              this._reportUnknownType();
334
            }
335
          }
336
          catch (e) { }
337
          return null;
338
        ]]>
339
        </getter>
340
        <setter>
341
        <![CDATA[
342
          // Exit early if nothing to do.
343
          if (this.readonly || this.valueFromPreferences == val)
344
            return val;
345
346
          // The special value undefined means 'reset preference to default'.
347
          if (val === undefined) {
348
            this.preferences.rootBranch.clearUserPref(this.name);
349
            return val;
350
          }
351
352
          // Force a resync of preferences with value.
353
          switch (this.type) {
354
          case "int":
355
            this.preferences.rootBranch.setIntPref(this.name, val);
356
            break;
357
          case "bool":
358
            this.preferences.rootBranch.setBoolPref(this.name, this.inverted ? !val : val);
359
            break;
360
          case "wstring":
361
            var pls = Components.classes["@mozilla.org/pref-localizedstring;1"]
362
                                .createInstance(Components.interfaces.nsIPrefLocalizedString);
363
            pls.data = val;
364
            this.preferences.rootBranch
365
                .setComplexValue(this.name, Components.interfaces.nsIPrefLocalizedString, pls);
366
            break;
367
          case "string":
368
          case "unichar":
369
          case "fontname":
370
            var iss = Components.classes["@mozilla.org/supports-string;1"]
371
                                .createInstance(Components.interfaces.nsISupportsString);
372
            iss.data = val;
373
            this.preferences.rootBranch
374
                .setComplexValue(this.name, Components.interfaces.nsISupportsString, iss);
375
            break;
376
          case "file":
377
            var lf;
378
            if (typeof(val) == "string") {
379
              lf = Components.classes["@mozilla.org/file/local;1"]
380
                             .createInstance(Components.interfaces.nsILocalFile);
381
              lf.persistentDescriptor = val;
382
              if (!lf.exists())
383
                lf.initWithPath(val);
384
            }
385
            else 
386
              lf = val.QueryInterface(Components.interfaces.nsILocalFile);
387
            this.preferences.rootBranch
388
                .setComplexValue(this.name, Components.interfaces.nsILocalFile, lf);
389
            break;
390
          default:
391
            this._reportUnknownType();
392
          }
393
          if (!this.batching)
394
            this.preferences.service.savePrefFile(null);
395
          return val;
396
        ]]>
397
        </setter>
398
      </property>
399
      
400
      <method name="setElementValue">
401
        <parameter name="aElement"/>
402
        <body>
403
        <![CDATA[
404
          if (this.locked)
405
            aElement.disabled = true;
406
407
          if (!this.isElementEditable(aElement))
408
            return;
409
410
          var rv = undefined;
411
          if (aElement.hasAttribute("onsyncfrompreference")) {
412
            // Value changed, synthesize an event
413
            try {
414
              var event = document.createEvent("Events");
415
              event.initEvent("syncfrompreference", true, true);
416
              var f = new Function ("event", 
417
                                    aElement.getAttribute("onsyncfrompreference"));
418
              rv = f.call(aElement, event);
419
            }
420
            catch (e) {
421
              Components.utils.reportError(e);
422
            }
423
          }
424
          var val = rv !== undefined ? rv : (this.instantApply ? this.valueFromPreferences : this.value);
425
          // if the preference is marked for reset, show default value in UI
426
          if (val === undefined)
427
            val = this.defaultValue;
428
429
          /**
430
           * Initialize a UI element property with a value. Handles the case 
431
           * where an element has not yet had a XBL binding attached for it and
432
           * the property setter does not yet exist by setting the same attribute
433
           * on the XUL element using DOM apis and assuming the element's 
434
           * constructor or property getters appropriately handle this state. 
435
           */
436
          function setValue(element, attribute, value) {
437
            if (attribute in element) 
438
              element[attribute] = value;
439
            else
440
              element.setAttribute(attribute, value);
441
          }
442
          if (aElement.localName == "checkbox" ||
443
              aElement.localName == "listitem")
444
            setValue(aElement, "checked", val);
445
          else if (aElement.localName == "colorpicker")
446
            setValue(aElement, "color", val);
447
          else if (aElement.localName == "textbox") {
448
            // XXXmano Bug 303998: Avoid a caret placement issue if either the
449
            // preference observer or its setter calls updateElements as a result
450
            // of the input event handler.
451
            if (aElement.value !== val)
452
              setValue(aElement, "value", val);
453
          }
454
          else
455
            setValue(aElement, "value", val);
456
        ]]>
457
        </body>
458
      </method>
459
460
      <method name="getElementValue">
461
        <parameter name="aElement"/>
462
        <body>
463
        <![CDATA[
464
          if (aElement.hasAttribute("onsynctopreference")) {
465
            // Value changed, synthesize an event
466
            try {
467
              var event = document.createEvent("Events");
468
              event.initEvent("synctopreference", true, true);
469
              var f = new Function ("event", 
470
                                    aElement.getAttribute("onsynctopreference"));
471
              var rv = f.call(aElement, event);
472
              if (rv !== undefined) 
473
                return rv;
474
            }
475
            catch (e) {
476
              Components.utils.reportError(e);
477
            }
478
          }
479
          
480
          /**
481
           * Read the value of an attribute from an element, assuming the 
482
           * attribute is a property on the element's node API. If the property
483
           * is not present in the API, then assume its value is contained in
484
           * an attribute, as is the case before a binding has been attached.
485
           */
486
          function getValue(element, attribute) {
487
            if (attribute in element)
488
              return element[attribute];
489
            return element.getAttribute(attribute);
490
          }
491
          if (aElement.localName == "checkbox" ||
492
              aElement.localName == "listitem")
493
            var value = getValue(aElement, "checked");
494
          else if (aElement.localName == "colorpicker")
495
            value = getValue(aElement, "color");
496
          else
497
            value = getValue(aElement, "value");
498
499
          switch (this.type) {
500
          case "int":
501
            return parseInt(value, 10) || 0;
502
          case "bool":
503
            return typeof(value) == "boolean" ? value : value == "true";
504
          }
505
          return value;
506
        ]]>
507
        </body>
508
      </method>
509
      
510
      <method name="isElementEditable">
511
        <parameter name="aElement"/>
512
        <body>
513
        <![CDATA[
514
          switch (aElement.localName) {
515
          case "checkbox":
516
          case "colorpicker":
517
          case "radiogroup":
518
          case "textbox":
519
          case "listitem":
520
          case "listbox":
521
          case "menulist":
522
            return true;
523
          }
524
          return aElement.getAttribute("preference-editable") == "true";
525
        ]]> 
526
        </body>
527
      </method>
528
      
529
      <method name="updateElements">
530
        <body>
531
        <![CDATA[
532
          if (!this.id)
533
            return;
534
535
          // This "change" event handler tracks changes made to preferences by 
536
          // sources other than the user in this window. 
537
          var elements = document.getElementsByAttribute("preference", this.id);
538
          for (var i = 0; i < elements.length; ++i) 
539
            this.setElementValue(elements[i]);
540
        ]]>
541
        </body>
542
      </method>
543
    </implementation>
544
    
545
    <handlers>
546
      <handler event="change">
547
        this.updateElements();
548
      </handler>
549
    </handlers>
550
  </binding>
551
552
  <binding id="prefwindow"
553
           extends="chrome://global/content/bindings/dialog.xml#dialog">
554
    <resources>
555
      <stylesheet src="chrome://global/skin/preferences.css"/>
556
    </resources>
557
    <content dlgbuttons="accept,cancel" persist="lastSelected screenX screenY"
558
             closebuttonlabel="&preferencesCloseButton.label;"
559
             closebuttonaccesskey="&preferencesCloseButton.accesskey;"
560
             role="dialog"
561
#ifdef XP_WIN
562
             title="&preferencesDefaultTitleWin.title;">
563
#else
564
             title="&preferencesDefaultTitleMac.title;">
565
#endif
566
      <xul:windowdragbox orient="vertical">
567
        <xul:radiogroup anonid="selector" orient="horizontal" class="paneSelector chromeclass-toolbar"
568
                        role="listbox"/> <!-- Expose to accessibility APIs as a listbox -->
569
      </xul:windowdragbox>
570
      <xul:hbox flex="1" class="paneDeckContainer">
571
        <xul:deck anonid="paneDeck" flex="1">
572
          <children includes="prefpane"/>
573
        </xul:deck>
574
      </xul:hbox>
575
      <xul:hbox anonid="dlg-buttons" class="prefWindow-dlgbuttons"
576
#ifdef XP_UNIX_GNOME
577
                >
578
        <xul:button dlgtype="disclosure" class="dialog-button" hidden="true"/>
579
        <xul:button dlgtype="help" class="dialog-button" hidden="true" icon="help"/>
580
        <xul:button dlgtype="extra2" class="dialog-button" hidden="true"/>
581
        <xul:button dlgtype="extra1" class="dialog-button" hidden="true"/>
582
        <xul:spacer anonid="spacer" flex="1"/>
583
        <xul:button dlgtype="cancel" class="dialog-button" icon="cancel"/>
584
        <xul:button dlgtype="accept" class="dialog-button" icon="accept"/>
585
#elif XP_UNIX
586
                pack="end">
587
	<xul:button dlgtype="help" class="dialog-button" hidden="true" icon="help"/>
588
	<xul:button dlgtype="extra2" class="dialog-button" hidden="true"/>
589
	<xul:spacer anonid="spacer" flex="1"/>
590
	<xul:button dlgtype="accept" class="dialog-button" icon="accept"/>
591
	<xul:button dlgtype="extra1" class="dialog-button" hidden="true"/>
592
	<xul:button dlgtype="cancel" class="dialog-button" icon="cancel"/>
593
	<xul:button dlgtype="disclosure" class="dialog-button" hidden="true"/>
594
#else
595
                pack="end">
596
        <xul:button dlgtype="extra2" class="dialog-button" hidden="true"/>
597
        <xul:spacer anonid="spacer" flex="1"/>
598
        <xul:button dlgtype="accept" class="dialog-button" icon="accept"/>
599
        <xul:button dlgtype="extra1" class="dialog-button" hidden="true"/>
600
        <xul:button dlgtype="cancel" class="dialog-button" icon="cancel"/>
601
        <xul:button dlgtype="help" class="dialog-button" hidden="true" icon="help"/>
602
        <xul:button dlgtype="disclosure" class="dialog-button" hidden="true"/>
603
#endif
604
      </xul:hbox>
605
      <xul:hbox>
606
        <children/>
607
      </xul:hbox>
608
    </content>
609
    <implementation implements="nsITimerCallback">
610
      <constructor>
611
      <![CDATA[
612
        if (this.type != "child") {
613
          var psvc = Components.classes["@mozilla.org/preferences-service;1"]
614
                               .getService(Components.interfaces.nsIPrefBranch);
615
          this.instantApply = psvc.getBoolPref("browser.preferences.instantApply");
616
          if (this.instantApply) {
617
            var docElt = document.documentElement;
618
            var acceptButton = docElt.getButton("accept");
619
            acceptButton.hidden = true;
620
            var cancelButton  = docElt.getButton("cancel");
621
#ifdef XP_MACOSX
622
            // no buttons on Mac except Help
623
            cancelButton.hidden = true;
624
            // Also, don't fire onDialogAccept on enter
625
            acceptButton.disabled = true;
626
#else
627
            // morph the Cancel button into the Close button
628
            cancelButton.setAttribute ("icon", "close");
629
            cancelButton.label = docElt.getAttribute("closebuttonlabel");
630
            cancelButton.accesskey = docElt.getAttribute("closebuttonaccesskey");
631
#endif
632
          }
633
        }
634
        this.setAttribute("animated", this._shouldAnimate ? "true" : "false");
635
        var panes = this.preferencePanes;
636
637
        var lastPane = null;
638
        if (this.lastSelected) {
639
          lastPane = document.getElementById(this.lastSelected);
640
          if (!lastPane) {
641
            this.lastSelected = null;
642
          }
643
        }
644
645
        var paneToLoad;
646
        if ("arguments" in window && window.arguments[0] && document.getElementById(window.arguments[0]) && document.getElementById(window.arguments[0]).nodeName == "prefpane") {
647
          paneToLoad = document.getElementById(window.arguments[0]);
648
          this.lastSelected = paneToLoad.id;
649
        }
650
        else if (lastPane)
651
          paneToLoad = lastPane;
652
        else
653
          paneToLoad = panes[0];
654
655
        for (var i = 0; i < panes.length; ++i) {
656
          this._makePaneButton(panes[i]);
657
          if (panes[i].loaded) {
658
            // Inline pane content, fire load event to force initialization.
659
            this._fireEvent("paneload", panes[i]);
660
          }
661
        }
662
        this.showPane(paneToLoad);
663
664
        if (panes.length == 1)
665
          this._selector.setAttribute("collapsed", "true");
666
      ]]>
667
      </constructor>
668
669
      <destructor>
670
      <![CDATA[
671
        // Release timers to avoid reference cycles.
672
        if (this._animateTimer) {
673
          this._animateTimer.cancel();
674
          this._animateTimer = null;
675
        }
676
        if (this._fadeTimer) {
677
          this._fadeTimer.cancel();
678
          this._fadeTimer = null;
679
        }
680
      ]]>
681
      </destructor>
682
683
      <field name="instantApply">false</field>
684
      
685
      <property name="preferencePanes"
686
                onget="return this.getElementsByTagName('prefpane');"/>
687
688
      <property name="type" onget="return this.getAttribute('type');"/>
689
      <property name="_paneDeck"
690
                onget="return document.getAnonymousElementByAttribute(this, 'anonid', 'paneDeck');"/>
691
      <property name="_paneDeckContainer"
692
                onget="return document.getAnonymousElementByAttribute(this, 'class', 'paneDeckContainer');"/>
693
      <property name="_selector"
694
                onget="return document.getAnonymousElementByAttribute(this, 'anonid', 'selector');"/>
695
      <property name="lastSelected" 
696
                onget="return this.getAttribute('lastSelected');">
697
        <setter>
698
          this.setAttribute("lastSelected", val); 
699
          document.persist(this.id, "lastSelected");
700
          return val;
701
        </setter>          
702
      </property>
703
      <property name="currentPane"
704
                onset="return this._currentPane = val;">
705
        <getter>
706
          if (!this._currentPane)
707
            this._currentPane = this.preferencePanes[0];
708
          
709
          return this._currentPane;
710
        </getter> 
711
      </property>
712
      <field name="_currentPane">null</field>
713
      
714
      
715
      <method name="_makePaneButton">
716
        <parameter name="aPaneElement"/>
717
        <body>
718
        <![CDATA[
719
          var radio = document.createElement("radio");
720
          radio.setAttribute("pane", aPaneElement.id);
721
          radio.setAttribute("label", aPaneElement.label);
722
          // Expose preference group choice to accessibility APIs as an unchecked list item
723
          // The parent group is exposed to accessibility APIs as a list
724
          if (aPaneElement.image)
725
            radio.setAttribute("src", aPaneElement.image);
726
          radio.style.listStyleImage = aPaneElement.style.listStyleImage;
727
          this._selector.appendChild(radio);
728
          return radio;
729
        ]]>
730
        </body>
731
      </method>
732
733
      <method name="showPane">
734
        <parameter name="aPaneElement"/>
735
        <body>
736
        <![CDATA[
737
          if (!aPaneElement)
738
            return;
739
740
          this._selector.selectedItem = document.getAnonymousElementByAttribute(this, "pane", aPaneElement.id);
741
          if (!aPaneElement.loaded) {
742
            function OverlayLoadObserver(aPane)
743
            {
744
              this._pane = aPane;
745
            }
746
            OverlayLoadObserver.prototype = { 
747
              _outer: this,
748
              observe: function (aSubject, aTopic, aData) 
749
              {
750
                this._pane.loaded = true;
751
                this._outer._fireEvent("paneload", this._pane);
752
                this._outer._selectPane(this._pane);
753
              }
754
            };
755
            
756
            var obs = new OverlayLoadObserver(aPaneElement);
757
            document.loadOverlay(aPaneElement.src, obs);
758
          }
759
          else
760
            this._selectPane(aPaneElement);
761
        ]]>
762
        </body>
763
      </method>
764
      
765
      <method name="_fireEvent">
766
        <parameter name="aEventName"/>
767
        <parameter name="aTarget"/>
768
        <body>
769
        <![CDATA[
770
          // Panel loaded, synthesize a load event. 
771
          try {
772
            var event = document.createEvent("Events");
773
            event.initEvent(aEventName, true, true);
774
            var cancel = !aTarget.dispatchEvent(event);
775
            if (aTarget.hasAttribute("on" + aEventName)) {
776
              var fn = new Function ("event", aTarget.getAttribute("on" + aEventName));
777
              var rv = fn.call(aTarget, event);
778
              if (rv == false)
779
                cancel = true;
780
            }
781
            return !cancel;  
782
          }
783
          catch (e) { 
784
            Components.utils.reportError(e);
785
          }
786
          return false;
787
        ]]>
788
        </body>
789
      </method>
790
      
791
      <field name="_initialized">false</field>
792
      <method name="_selectPane">
793
        <parameter name="aPaneElement"/>
794
        <body>
795
        <![CDATA[
796
#ifdef XP_MACOSX
797
          var paneTitle = aPaneElement.label;
798
          if (paneTitle != "")
799
            document.title = paneTitle;
800
#endif
801
          var helpButton = document.documentElement.getButton("help");
802
          if (aPaneElement.helpTopic)
803
            helpButton.hidden = false;
804
          else
805
            helpButton.hidden = true;
806
807
          // Find this pane's index in the deck and set the deck's 
808
          // selectedIndex to that value to switch to it.
809
          var prefpanes = this.preferencePanes;
810
          for (var i = 0; i < prefpanes.length; ++i) {
811
            if (prefpanes[i] == aPaneElement) {
812
              this._paneDeck.selectedIndex = i;
813
              
814
              if (this.type != "child") {
815
                if (aPaneElement.hasAttribute("flex") && this._shouldAnimate &&
816
                    prefpanes.length > 1)
817
                  aPaneElement.removeAttribute("flex");
818
                // Calling sizeToContent after the first prefpane is loaded
819
                // will size the windows contents so style information is
820
                // available to calculate correct sizing.
821
                if (!this._initialized && prefpanes.length > 1) {
822
                  if (this._shouldAnimate)
823
                    this.style.minHeight = 0;
824
                  window.sizeToContent();
825
                }
826
827
                var oldPane = this.lastSelected ? document.getElementById(this.lastSelected) : this.preferencePanes[0];
828
                oldPane.selected = !(aPaneElement.selected = true);
829
                this.lastSelected = aPaneElement.id;
830
                this.currentPane = aPaneElement;
831
                this._initialized = true;
832
833
                // Only animate if we've switched between prefpanes
834
                if (this._shouldAnimate && oldPane.id != aPaneElement.id) {
835
                  aPaneElement.style.opacity = 0.0;
836
                  this.animate(oldPane, aPaneElement);
837
                }
838
                else if (!this._shouldAnimate && prefpanes.length > 1) {
839
                  var targetHeight = parseInt(window.getComputedStyle(this._paneDeckContainer, "").height);
840
                  var verticalPadding = parseInt(window.getComputedStyle(aPaneElement, "").paddingTop);
841
                  verticalPadding += parseInt(window.getComputedStyle(aPaneElement, "").paddingBottom);
842
                  if (aPaneElement.contentHeight > targetHeight - verticalPadding) {
843
                    // To workaround the bottom border of a groupbox from being
844
                    // cutoff an hbox with a class of bottomBox may enclose it.
845
                    // This needs to include its padding to resize properly.
846
                    // See bug 394433
847
                    var bottomPadding = 0;
848
                    var bottomBox = aPaneElement.getElementsByAttribute("class", "bottomBox")[0];
849
                    if (bottomBox)
850
                      bottomPadding = parseInt(window.getComputedStyle(bottomBox, "").paddingBottom);
851
                    window.innerHeight += bottomPadding + verticalPadding + aPaneElement.contentHeight - targetHeight;
852
                  }
853
854
                  // XXX rstrong - extend the contents of the prefpane to
855
                  // prevent elements from being cutoff (see bug 349098).
856
                  if (aPaneElement.contentHeight + verticalPadding < targetHeight)
857
                    aPaneElement._content.style.height = targetHeight - verticalPadding + "px";
858
                }
859
              }
860
              break;
861
            }
862
          }
863
        ]]>
864
        </body>
865
      </method>
866
      
867
      <property name="_shouldAnimate">
868
        <getter>
869
        <![CDATA[
870
          var psvc = Components.classes["@mozilla.org/preferences-service;1"]
871
                               .getService(Components.interfaces.nsIPrefBranch);
872
#ifdef XP_MACOSX
873
          var animate = true;
874
#else
875
          var animate = false;
876
#endif
877
          try {
878
            animate = psvc.getBoolPref("browser.preferences.animateFadeIn");
879
          }
880
          catch (e) { }
881
          return animate;
882
        ]]>
883
        </getter>
884
      </property>
885
      
886
      <method name="animate">
887
        <parameter name="aOldPane"/>
888
        <parameter name="aNewPane"/>
889
        <body>
890
        <![CDATA[
891
          // if we are already resizing, use currentHeight
892
          var oldHeight = this._currentHeight ? this._currentHeight : aOldPane.contentHeight;
893
          
894
          this._multiplier = aNewPane.contentHeight > oldHeight ? 1 : -1;
895
          var sizeDelta = Math.abs(oldHeight - aNewPane.contentHeight);
896
          this._animateRemainder = sizeDelta % this._animateIncrement;
897
898
          this._setUpAnimationTimer(oldHeight);
899
        ]]>
900
        </body>
901
      </method>
902
      
903
      <property name="_sizeIncrement">
904
        <getter>
905
        <![CDATA[
906
          var lastSelectedPane = document.getElementById(this.lastSelected);
907
          var increment = this._animateIncrement * this._multiplier;
908
          var newHeight = this._currentHeight + increment;
909
          if ((this._multiplier > 0 && this._currentHeight >= lastSelectedPane.contentHeight) ||
910
              (this._multiplier < 0 && this._currentHeight <= lastSelectedPane.contentHeight))
911
            return 0;
912
          
913
          if ((this._multiplier > 0 && newHeight > lastSelectedPane.contentHeight) ||
914
              (this._multiplier < 0 && newHeight < lastSelectedPane.contentHeight))
915
            increment = this._animateRemainder * this._multiplier;
916
          return increment;
917
        ]]>
918
        </getter>
919
      </property>
920
      
921
      <method name="notify">
922
        <parameter name="aTimer"/>
923
        <body>
924
        <![CDATA[
925
          if (!document)
926
            aTimer.cancel();
927
          
928
          if (aTimer == this._animateTimer) {
929
            var increment = this._sizeIncrement;
930
            if (increment != 0) {
931
              window.innerHeight += increment;
932
              this._currentHeight += increment;
933
            }
934
            else {
935
              aTimer.cancel();
936
              this._setUpFadeTimer();
937
            }
938
          } else if (aTimer == this._fadeTimer) {
939
            var elt = document.getElementById(this.lastSelected);
940
            var newOpacity = parseFloat(window.getComputedStyle(elt, "").opacity) + this._fadeIncrement;
941
            if (newOpacity < 1.0)
942
              elt.style.opacity = newOpacity;
943
            else {
944
              aTimer.cancel();
945
              elt.style.opacity = 1.0;
946
            }
947
          }
948
        ]]>
949
        </body>
950
      </method>
951
      
952
      <method name="_setUpAnimationTimer">
953
        <parameter name="aStartHeight"/>
954
        <body>
955
        <![CDATA[
956
          if (!this._animateTimer) 
957
            this._animateTimer = Components.classes["@mozilla.org/timer;1"]
958
                                           .createInstance(Components.interfaces.nsITimer);
959
          else
960
            this._animateTimer.cancel();
961
          this._currentHeight = aStartHeight;
962
          
963
          this._animateTimer.initWithCallback(this, this._animateDelay, 
964
                                              Components.interfaces.nsITimer.TYPE_REPEATING_SLACK);
965
        ]]>
966
        </body>
967
      </method>
968
      
969
      <method name="_setUpFadeTimer">
970
        <body>
971
        <![CDATA[
972
          if (!this._fadeTimer) 
973
            this._fadeTimer = Components.classes["@mozilla.org/timer;1"]
974
                                        .createInstance(Components.interfaces.nsITimer);
975
          else
976
            this._fadeTimer.cancel();
977
          
978
          this._fadeTimer.initWithCallback(this, this._fadeDelay, 
979
                                           Components.interfaces.nsITimer.TYPE_REPEATING_SLACK);
980
        ]]>
981
        </body>
982
      </method>
983
      
984
      <field name="_animateTimer">null</field>
985
      <field name="_fadeTimer">null</field>
986
      <field name="_animateDelay">15</field>
987
      <field name="_animateIncrement">40</field>
988
      <field name="_fadeDelay">5</field>
989
      <field name="_fadeIncrement">0.40</field>
990
      <field name="_animateRemainder">0</field>
991
      <field name="_currentHeight">0</field>
992
      <field name="_multiplier">0</field>
993
994
      <method name="addPane">
995
        <parameter name="aPaneElement"/>
996
        <body>
997
        <![CDATA[
998
          this.appendChild(aPaneElement);
999
          
1000
          // Set up pane button
1001
          this._makePaneButton(aPaneElement);
1002
        ]]>
1003
        </body>
1004
      </method>
1005
      
1006
      <method name="openSubDialog">
1007
        <parameter name="aURL"/>
1008
        <parameter name="aFeatures"/>
1009
        <parameter name="aParams"/>
1010
        <body>
1011
          return openDialog(aURL, "", "modal,centerscreen,resizable=no" + (aFeatures != "" ? ("," + aFeatures) : ""), aParams);
1012
        </body>
1013
      </method>
1014
      
1015
      <method name="openWindow">
1016
        <parameter name="aWindowType"/>
1017
        <parameter name="aURL"/>
1018
        <parameter name="aFeatures"/>
1019
        <parameter name="aParams"/>
1020
        <body>
1021
        <![CDATA[
1022
          var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
1023
                             .getService(Components.interfaces.nsIWindowMediator);
1024
          var win = aWindowType ? wm.getMostRecentWindow(aWindowType) : null;
1025
          if (win) {
1026
            if ("initWithParams" in win)
1027
              win.initWithParams(aParams);
1028
            win.focus();
1029
          }
1030
          else {
1031
            var features = "resizable,dialog=no,centerscreen" + (aFeatures != "" ? ("," + aFeatures) : "");
1032
            var parentWindow = (this.instantApply || !window.opener || window.opener.closed) ? window : window.opener;
1033
            win = parentWindow.openDialog(aURL, "_blank", features, aParams);
1034
          }
1035
          return win;
1036
        ]]>
1037
        </body>
1038
      </method>
1039
    </implementation>
1040
    <handlers>
1041
      <handler event="dialogaccept">
1042
      <![CDATA[
1043
        if (!this._fireEvent("beforeaccept", this)) 
1044
          return;
1045
        
1046
        if (this.type == "child" && window.opener) {
1047
          var psvc = Components.classes["@mozilla.org/preferences-service;1"]
1048
                               .getService(Components.interfaces.nsIPrefBranch);
1049
          var instantApply = psvc.getBoolPref("browser.preferences.instantApply");
1050
          if (instantApply) {
1051
            var panes = this.preferencePanes;
1052
            for (var i = 0; i < panes.length; ++i)
1053
              panes[i].writePreferences(true);
1054
          }
1055
          else {
1056
            // Clone all the preferences elements from the child document and
1057
            // insert them into the pane collection of the parent. 
1058
            var pdoc = window.opener.document;
1059
            if (pdoc.documentElement.localName == "prefwindow") {
1060
              var currentPane = pdoc.documentElement.currentPane;
1061
              var id = window.location.href + "#childprefs";
1062
              var childPrefs = pdoc.getElementById(id);
1063
              if (!childPrefs) {
1064
                var childPrefs = pdoc.createElement("preferences");
1065
                currentPane.appendChild(childPrefs);
1066
                childPrefs.id = id;
1067
              }
1068
              var panes = this.preferencePanes;
1069
              for (var i = 0; i < panes.length; ++i) {
1070
                var preferences = panes[i].preferences;
1071
                for (var j = 0; j < preferences.length; ++j) {
1072
                  // Try to find a preference element for the same preference.
1073
                  var preference = null;
1074
                  var parentPreferences = pdoc.getElementsByTagName("preferences");
1075
                  for (var k = 0; (k < parentPreferences.length && !preference); ++k) {
1076
                    var parentPrefs = parentPreferences[k]
1077
                                         .getElementsByAttribute("name", preferences[j].name);
1078
                    for (var l = 0; (l < parentPrefs.length && !preference); ++l) {
1079
                      if (parentPrefs[l].localName == "preference")
1080
                        preference = parentPrefs[l];
1081
                    }
1082
                  }
1083
                  if (!preference) {
1084
                    // No matching preference in the parent window.
1085
                    preference = pdoc.createElement("preference");
1086
                    childPrefs.appendChild(preference);
1087
                    preference.name     = preferences[j].name;
1088
                    preference.type     = preferences[j].type;
1089
                    preference.inverted = preferences[j].inverted;
1090
                    preference.readonly = preferences[j].readonly;
1091
                    preference.disabled = preferences[j].disabled;
1092
                  }
1093
                  preference.value = preferences[j].value;
1094
                }
1095
              }
1096
            }
1097
          }
1098
        }
1099
        else {
1100
          var panes = this.preferencePanes;
1101
          for (var i = 0; i < panes.length; ++i)
1102
            panes[i].writePreferences(false);
1103
1104
          var psvc = Components.classes["@mozilla.org/preferences-service;1"]
1105
                               .getService(Components.interfaces.nsIPrefService);
1106
          psvc.savePrefFile(null);
1107
        }
1108
      ]]>
1109
      </handler>
1110
      <handler event="command">
1111
        if (event.originalTarget.hasAttribute("pane")) {
1112
          var pane = document.getElementById(event.originalTarget.getAttribute("pane"));
1113
          this.showPane(pane);
1114
        }
1115
      </handler>
1116
1117
      <handler event="keypress" key="&windowClose.key;" modifiers="accel" phase="capturing">
1118
      <![CDATA[
1119
        if (this.instantApply)
1120
          window.close();
1121
        event.stopPropagation();
1122
        event.preventDefault();
1123
      ]]>
1124
      </handler>
1125
1126
      <handler event="keypress"
1127
#ifdef XP_MACOSX
1128
               key="&openHelpMac.commandkey;" modifiers="accel"
1129
#else
1130
               keycode="&openHelp.commandkey;"
1131
#endif
1132
               phase="capturing">
1133
      <![CDATA[
1134
        var helpButton = this.getButton("help");
1135
        if (helpButton.disabled || helpButton.hidden)
1136
          return;
1137
        this._fireEvent("dialoghelp", this);
1138
        event.stopPropagation();
1139
        event.preventDefault();
1140
      ]]>
1141
      </handler>
1142
    </handlers>
1143
  </binding>
1144
  
1145
  <binding id="prefpane">
1146
    <resources>
1147
      <stylesheet src="chrome://global/skin/preferences.css"/>
1148
    </resources>
1149
    <content>
1150
      <xul:vbox class="content-box" xbl:inherits="flex">
1151
        <children/>
1152
      </xul:vbox>
1153
    </content>
1154
    <implementation>
1155
      <method name="writePreferences">
1156
        <parameter name="aFlushToDisk"/>
1157
        <body>
1158
        <![CDATA[
1159
          // Write all values to preferences.
1160
          var preferences = this.preferences;
1161
          for (var i = 0; i < preferences.length; ++i) {
1162
            var preference = preferences[i];
1163
            preference.batching = true;
1164
            preference.valueFromPreferences = preference.value;
1165
            preference.batching = false;
1166
          }
1167
          if (aFlushToDisk) {
1168
            var psvc = Components.classes["@mozilla.org/preferences-service;1"]
1169
                                 .getService(Components.interfaces.nsIPrefService);
1170
            psvc.savePrefFile(null);
1171
          }
1172
        ]]>
1173
        </body>
1174
      </method>
1175
      
1176
      <property name="src" 
1177
                onget="return this.getAttribute('src');"
1178
                onset="this.setAttribute('src', val); return val;"/>
1179
      <property name="selected" 
1180
                onget="return this.getAttribute('selected') == 'true';"
1181
                onset="this.setAttribute('selected', val); return val;"/>
1182
      <property name="image" 
1183
                onget="return this.getAttribute('image');"
1184
                onset="this.setAttribute('image', val); return val;"/>
1185
      <property name="label" 
1186
                onget="return this.getAttribute('label');"
1187
                onset="this.setAttribute('label', val); return val;"/>
1188
      
1189
      <property name="preferenceElements"
1190
                onget="return this.getElementsByAttribute('preference', '*');"/>
1191
      <property name="preferences"
1192
                onget="return this.getElementsByTagName('preference');"/>
1193
1194
      <property name="helpTopic">
1195
        <getter>
1196
        <![CDATA[
1197
          // if there are tabs, and the selected tab provides a helpTopic, return that
1198
          var box = this.getElementsByTagName("tabbox");
1199
          if (box[0]) {
1200
            var tab = box[0].selectedTab;
1201
            if (tab && tab.hasAttribute("helpTopic"))
1202
              return tab.getAttribute("helpTopic");
1203
          }
1204
1205
          // otherwise, return the helpTopic of the current panel
1206
          return this.getAttribute("helpTopic");
1207
        ]]>
1208
        </getter>
1209
      </property>
1210
1211
      <field name="_loaded">false</field>
1212
      <property name="loaded" 
1213
                onget="return !this.src ? true : this._loaded;"
1214
                onset="this._loaded = val; return val;"/>
1215
      
1216
      <method name="preferenceForElement">
1217
        <parameter name="aElement"/>
1218
        <body>
1219
          return document.getElementById(aElement.getAttribute("preference"));
1220
        </body>
1221
      </method>
1222
      
1223
      <method name="getPreferenceElement">
1224
        <parameter name="aStartElement"/>
1225
        <body>
1226
        <![CDATA[
1227
          var temp = aStartElement;
1228
          while (temp && temp.nodeType == Node.ELEMENT_NODE && 
1229
                 !temp.hasAttribute("preference"))
1230
            temp = temp.parentNode;
1231
          return temp.nodeType == Node.ELEMENT_NODE ? temp : aStartElement;
1232
        ]]>
1233
        </body>
1234
      </method>
1235
      
1236
      <method name="userChangedValue">
1237
        <parameter name="aElement"/>
1238
        <body>
1239
        <![CDATA[
1240
          var element = this.getPreferenceElement(aElement);
1241
          if (element.hasAttribute("preference")) {
1242
            var preference = document.getElementById(element.getAttribute("preference"));
1243
            var prefVal = preference.getElementValue(element);
1244
            preference.value = prefVal;
1245
          }
1246
        ]]>
1247
        </body>
1248
      </method>
1249
      
1250
      <property name="contentHeight">
1251
        <getter>
1252
          var targetHeight = parseInt(window.getComputedStyle(this._content, "").height);
1253
          targetHeight += parseInt(window.getComputedStyle(this._content, "").marginTop);
1254
          targetHeight += parseInt(window.getComputedStyle(this._content, "").marginBottom);
1255
          return targetHeight;
1256
        </getter>
1257
      </property>
1258
      <field name="_content">
1259
        document.getAnonymousElementByAttribute(this, "class", "content-box");
1260
      </field>
1261
    </implementation>
1262
    <handlers>
1263
      <handler event="command">
1264
        // This "command" event handler tracks changes made to preferences by 
1265
        // the user in this window. 
1266
	if (event.sourceEvent)
1267
	  event = event.sourceEvent;
1268
        this.userChangedValue(event.target);
1269
      </handler>
1270
      <handler event="select">
1271
        // This "select" event handler tracks changes made to colorpicker 
1272
        // preferences by the user in this window.
1273
        if (event.target.localName == "colorpicker") 
1274
          this.userChangedValue(event.target);
1275
      </handler>
1276
      <handler event="change">
1277
        // This "change" event handler tracks changes made to preferences by 
1278
        // the user in this window. 
1279
        this.userChangedValue(event.target);
1280
      </handler>
1281
      <handler event="input">
1282
        // This "input" event handler tracks changes made to preferences by 
1283
        // the user in this window.
1284
        this.userChangedValue(event.target);
1285
      </handler>
1286
      <handler event="paneload">
1287
      <![CDATA[
1288
        // Initialize all values from preferences.
1289
        var elements = this.preferenceElements;
1290
        for (var i = 0; i < elements.length; ++i) {
1291
          try {
1292
            var preference = this.preferenceForElement(elements[i]);
1293
            preference.setElementValue(elements[i]);
1294
          }
1295
          catch (e) {
1296
            dump("*** No preference found for " + elements[i].getAttribute("preference") + "\n");
1297
          }
1298
        }
1299
      ]]>      
1300
      </handler>
1301
    </handlers>
1302
  </binding>
1303
          
1304
  <binding id="panebutton" extends="chrome://global/content/bindings/radio.xml#radio">
1305
    <resources>
1306
      <stylesheet src="chrome://global/skin/preferences.css"/>
1307
    </resources>
1308
    <content>
1309
      <xul:image class="paneButtonIcon" xbl:inherits="src"/>
1310
      <xul:label class="paneButtonLabel" xbl:inherits="value=label"/>
1311
    </content>
1312
    <implementation implements="nsIAccessible">
1313
      <property name="accessibleType" readonly="true">
1314
        <getter>
1315
          <![CDATA[
1316
            return Components.interfaces.nsIAccessibleProvider.XULListitem;
1317
          ]]>
1318
        </getter>
1319
      </property>
1320
    </implementation>
1321
  </binding>
1322
1323
</bindings>
1324
1325
# -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
1326
# ***** BEGIN LICENSE BLOCK *****
1327
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
1328
#
1329
# The contents of this file are subject to the Mozilla Public License Version
1330
# 1.1 (the "License"); you may not use this file except in compliance with
1331
# the License. You may obtain a copy of the License at
1332
# http://www.mozilla.org/MPL/
1333
#
1334
# Software distributed under the License is distributed on an "AS IS" basis,
1335
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
1336
# for the specific language governing rights and limitations under the
1337
# License.
1338
#
1339
# The Original Code is the Preferences System.
1340
#
1341
# The Initial Developer of the Original Code is
1342
# Ben Goodger.
1343
# Portions created by the Initial Developer are Copyright (C) 2005
1344
# the Initial Developer. All Rights Reserved.
1345
#
1346
# Contributor(s):
1347
#   Ben Goodger <ben@mozilla.org>
1348
#   Josh Aas <josh@mozilla.com>
1349
#
1350
# Alternatively, the contents of this file may be used under the terms of
1351
# either the GNU General Public License Version 2 or later (the "GPL"), or
1352
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
1353
# in which case the provisions of the GPL or the LGPL are applicable instead
1354
# of those above. If you wish to allow use of your version of this file only
1355
# under the terms of either the GPL or the LGPL, and not to allow others to
1356
# use your version of this file under the terms of the MPL, indicate your
1357
# decision by deleting the provisions above and replace them with the notice
1358
# and other provisions required by the GPL or the LGPL. If you do not delete
1359
# the provisions above, a recipient may use your version of this file under
1360
# the terms of any one of the MPL, the GPL or the LGPL.
1361
#
1362
# ***** END LICENSE BLOCK *****
1363
1364
#
1365
# This is PrefWindow 6. The Code Could Well Be Ready, Are You?
1366
#
1367
#    Historical References:
1368
#    PrefWindow V   (February 1, 2003)
1369
#    PrefWindow IV  (April 24, 2000)
1370
#    PrefWindow III (January 6, 2000)
1371
#    PrefWindow II  (???)
1372
#    PrefWindow I   (June 4, 1999)
1373
#
(-)a/toolkit/system/unixproxy/nsUnixSystemProxySettings.cpp (+32 lines)
Lines 46-61 Link Here
46
#include "nsArrayUtils.h"
46
#include "nsArrayUtils.h"
47
#include "prnetdb.h"
47
#include "prnetdb.h"
48
#include "prenv.h"
48
#include "prenv.h"
49
#include "nsPrintfCString.h"
49
#include "nsPrintfCString.h"
50
#include "nsNetUtil.h"
50
#include "nsNetUtil.h"
51
#include "nsISupportsPrimitives.h"
51
#include "nsISupportsPrimitives.h"
52
#include "nsIGSettingsService.h"
52
#include "nsIGSettingsService.h"
53
#include "nsInterfaceHashtable.h"
53
#include "nsInterfaceHashtable.h"
54
#include "nsVoidArray.h"
55
#include "nsKDEUtils.h"
54
56
55
class nsUnixSystemProxySettings : public nsISystemProxySettings {
57
class nsUnixSystemProxySettings : public nsISystemProxySettings {
56
public:
58
public:
57
  NS_DECL_ISUPPORTS
59
  NS_DECL_ISUPPORTS
58
  NS_DECL_NSISYSTEMPROXYSETTINGS
60
  NS_DECL_NSISYSTEMPROXYSETTINGS
59
61
60
  nsUnixSystemProxySettings() {}
62
  nsUnixSystemProxySettings() {}
61
  nsresult Init();
63
  nsresult Init();
Lines 67-82 private: Link Here
67
  nsCOMPtr<nsIGSettingsService> mGSettings;
69
  nsCOMPtr<nsIGSettingsService> mGSettings;
68
  nsCOMPtr<nsIGSettingsCollection> mProxySettings;
70
  nsCOMPtr<nsIGSettingsCollection> mProxySettings;
69
  nsInterfaceHashtable<nsCStringHashKey, nsIGSettingsCollection> mSchemeProxySettings;
71
  nsInterfaceHashtable<nsCStringHashKey, nsIGSettingsCollection> mSchemeProxySettings;
70
  bool IsProxyMode(const char* aMode);
72
  bool IsProxyMode(const char* aMode);
71
  nsresult SetProxyResultFromGConf(const char* aKeyBase, const char* aType, nsACString& aResult);
73
  nsresult SetProxyResultFromGConf(const char* aKeyBase, const char* aType, nsACString& aResult);
72
  nsresult GetProxyFromGConf(const nsACString& aScheme, const nsACString& aHost, PRInt32 aPort, nsACString& aResult);
74
  nsresult GetProxyFromGConf(const nsACString& aScheme, const nsACString& aHost, PRInt32 aPort, nsACString& aResult);
73
  nsresult GetProxyFromGSettings(const nsACString& aScheme, const nsACString& aHost, PRInt32 aPort, nsACString& aResult);
75
  nsresult GetProxyFromGSettings(const nsACString& aScheme, const nsACString& aHost, PRInt32 aPort, nsACString& aResult);
74
  nsresult SetProxyResultFromGSettings(const char* aKeyBase, const char* aType, nsACString& aResult);
76
  nsresult SetProxyResultFromGSettings(const char* aKeyBase, const char* aType, nsACString& aResult);
77
  nsresult GetProxyFromKDE(const nsACString& aScheme, const nsACString& aHost, PRInt32 aPort, nsACString& aResult);
75
};
78
};
76
79
77
NS_IMPL_ISUPPORTS1(nsUnixSystemProxySettings, nsISystemProxySettings)
80
NS_IMPL_ISUPPORTS1(nsUnixSystemProxySettings, nsISystemProxySettings)
78
81
79
nsresult
82
nsresult
80
nsUnixSystemProxySettings::Init()
83
nsUnixSystemProxySettings::Init()
81
{
84
{
82
  // If this is a GNOME session, load gconf and try to use its preferences.
85
  // If this is a GNOME session, load gconf and try to use its preferences.
Lines 529-544 nsUnixSystemProxySettings::GetProxyForUR Link Here
529
  nsCAutoString host;
532
  nsCAutoString host;
530
  rv = aURI->GetHost(host);
533
  rv = aURI->GetHost(host);
531
  NS_ENSURE_SUCCESS(rv, rv);
534
  NS_ENSURE_SUCCESS(rv, rv);
532
535
533
  PRInt32 port;
536
  PRInt32 port;
534
  rv = aURI->GetPort(&port);
537
  rv = aURI->GetPort(&port);
535
  NS_ENSURE_SUCCESS(rv, rv);
538
  NS_ENSURE_SUCCESS(rv, rv);
536
539
540
  if( nsKDEUtils::kdeSupport())
541
    return GetProxyFromKDE(scheme, host, port, aResult);
542
537
  if (mProxySettings) {
543
  if (mProxySettings) {
538
    rv = GetProxyFromGSettings(scheme, host, port, aResult);
544
    rv = GetProxyFromGSettings(scheme, host, port, aResult);
539
    if (rv == NS_OK)
545
    if (rv == NS_OK)
540
      return rv;
546
      return rv;
541
  }
547
  }
542
  if (mGConf)
548
  if (mGConf)
543
    return GetProxyFromGConf(scheme, host, port, aResult);
549
    return GetProxyFromGConf(scheme, host, port, aResult);
544
550
Lines 564-571 static const mozilla::Module::ContractID Link Here
564
570
565
static const mozilla::Module kUnixProxyModule = {
571
static const mozilla::Module kUnixProxyModule = {
566
  mozilla::Module::kVersion,
572
  mozilla::Module::kVersion,
567
  kUnixProxyCIDs,
573
  kUnixProxyCIDs,
568
  kUnixProxyContracts
574
  kUnixProxyContracts
569
};
575
};
570
576
571
NSMODULE_DEFN(nsUnixProxyModule) = &kUnixProxyModule;
577
NSMODULE_DEFN(nsUnixProxyModule) = &kUnixProxyModule;
578
579
nsresult
580
nsUnixSystemProxySettings::GetProxyFromKDE(const nsACString& aScheme,
581
                                           const nsACString& aHost,
582
                                           PRInt32 aPort,
583
                                           nsACString& aResult)
584
{
585
  nsCAutoString url;
586
  url = aScheme;
587
  url += "://";
588
  url += aHost;
589
  if( aPort >= 0 )
590
  {
591
    url += ":";
592
    url += nsPrintfCString("%d", aPort);
593
  }
594
  nsTArray<nsCString> command;
595
  command.AppendElement( NS_LITERAL_CSTRING( "GETPROXY" ));
596
  command.AppendElement( url );
597
  nsTArray<nsCString> result;
598
  if( !nsKDEUtils::command( command, &result ) || result.Length() != 1 )
599
    return NS_ERROR_FAILURE;
600
  aResult = result[0];
601
  return NS_OK;
602
}
603
(-)a/toolkit/xre/Makefile.in (-1 / +2 lines)
Lines 100-116 else Link Here
100
ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
100
ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
101
CMMSRCS = nsNativeAppSupportCocoa.mm
101
CMMSRCS = nsNativeAppSupportCocoa.mm
102
EXPORTS += MacQuirks.h
102
EXPORTS += MacQuirks.h
103
else
103
else
104
ifeq ($(MOZ_WIDGET_TOOLKIT),os2)
104
ifeq ($(MOZ_WIDGET_TOOLKIT),os2)
105
CPPSRCS += nsNativeAppSupportOS2.cpp
105
CPPSRCS += nsNativeAppSupportOS2.cpp
106
else
106
else
107
ifeq ($(MOZ_WIDGET_TOOLKIT),gtk2)
107
ifeq ($(MOZ_WIDGET_TOOLKIT),gtk2)
108
CPPSRCS += nsNativeAppSupportUnix.cpp
108
CPPSRCS += nsNativeAppSupportUnix.cpp nsKDEUtils.cpp
109
EXPORTS += nsKDEUtils.h
109
else
110
else
110
ifeq ($(MOZ_WIDGET_TOOLKIT),qt)
111
ifeq ($(MOZ_WIDGET_TOOLKIT),qt)
111
MOCSRCS += moc_nsNativeAppSupportQt.cpp
112
MOCSRCS += moc_nsNativeAppSupportQt.cpp
112
CPPSRCS += $(MOCSRCS)
113
CPPSRCS += $(MOCSRCS)
113
CPPSRCS += nsNativeAppSupportQt.cpp
114
CPPSRCS += nsNativeAppSupportQt.cpp
114
CPPSRCS += nsQAppInstance.cpp
115
CPPSRCS += nsQAppInstance.cpp
115
EXPORTS += nsQAppInstance.h
116
EXPORTS += nsQAppInstance.h
116
else
117
else
(-)a/toolkit/xre/nsKDEUtils.cpp (+373 lines)
Line 0 Link Here
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4
 *
5
 * The contents of this file are subject to the Mozilla Public License Version
6
 * 1.1 (the "License"); you may not use this file except in compliance with
7
 * the License. You may obtain a copy of the License at
8
 * http://www.mozilla.org/MPL/
9
 *
10
 * Software distributed under the License is distributed on an "AS IS" basis,
11
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
 * for the specific language governing rights and limitations under the
13
 * License.
14
 *
15
 * The Original Code is Unix Native App Support.
16
 *
17
 * The Initial Developer of the Original Code is
18
 * Mozilla Corporation.
19
 * Portions created by the Initial Developer are Copyright (C) 2007
20
 * the Initial Developer. All Rights Reserved.
21
 *
22
 * Contributor(s):
23
 *
24
 * Alternatively, the contents of this file may be used under the terms of
25
 * either the GNU General Public License Version 2 or later (the "GPL"), or
26
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
 * in which case the provisions of the GPL or the LGPL are applicable instead
28
 * of those above. If you wish to allow use of your version of this file only
29
 * under the terms of either the GPL or the LGPL, and not to allow others to
30
 * use your version of this file under the terms of the MPL, indicate your
31
 * decision by deleting the provisions above and replace them with the notice
32
 * and other provisions required by the GPL or the LGPL. If you do not delete
33
 * the provisions above, a recipient may use your version of this file under
34
 * the terms of any one of the MPL, the GPL or the LGPL.
35
 *
36
 * ***** END LICENSE BLOCK ***** */
37
38
#include "nsKDEUtils.h"
39
#include "nsIWidget.h"
40
#include "nsISupportsPrimitives.h"
41
#include "nsIMutableArray.h"
42
#include "nsComponentManagerUtils.h"
43
#include "nsArrayUtils.h"
44
45
#include <gtk/gtk.h>
46
47
#include <limits.h>
48
#include <stdio.h>
49
#include <sys/wait.h>
50
#include <sys/resource.h>
51
#include <unistd.h>
52
#include <X11/Xlib.h>
53
54
//#define DEBUG_KDE
55
#ifdef DEBUG_KDE
56
#define KMOZILLAHELPER "kmozillahelper"
57
#else
58
// not need for lib64, it's a binary
59
#define KMOZILLAHELPER "/usr/lib/mozilla/kmozillahelper"
60
#endif
61
62
#define KMOZILLAHELPER_VERSION 6
63
#define MAKE_STR2( n ) #n
64
#define MAKE_STR( n ) MAKE_STR2( n )
65
66
static bool getKdeSession()
67
    {
68
    Display* dpy = XOpenDisplay( NULL );
69
    if( dpy == NULL )
70
        return false;
71
    Atom kde_full_session = XInternAtom( dpy, "KDE_FULL_SESSION", True );
72
    bool kde = false;
73
    if( kde_full_session != None )
74
        {
75
        int cnt;
76
        if( Atom* props = XListProperties( dpy, DefaultRootWindow( dpy ), &cnt ))
77
            {
78
            for( int i = 0;
79
                 i < cnt;
80
                 ++i )
81
                {
82
                if( props[ i ] == kde_full_session )
83
                    {
84
                    kde = true;
85
#ifdef DEBUG_KDE
86
                    fprintf( stderr, "KDE SESSION %d\n", kde );
87
#endif
88
                    break;
89
                    }
90
                }
91
            XFree( props );
92
            }
93
        }
94
    XCloseDisplay( dpy );
95
    return kde;
96
    }
97
98
static bool getKdeSupport()
99
    {
100
    nsTArray<nsCString> command;
101
    command.AppendElement( NS_LITERAL_CSTRING( "CHECK" ));
102
    command.AppendElement( NS_LITERAL_CSTRING( MAKE_STR( KMOZILLAHELPER_VERSION )));
103
    bool kde = nsKDEUtils::command( command );
104
#ifdef DEBUG_KDE
105
    fprintf( stderr, "KDE RUNNING %d\n", kde );
106
#endif
107
    return kde;
108
    }
109
110
nsKDEUtils::nsKDEUtils()
111
    : commandFile( NULL )
112
    , replyFile( NULL )
113
    {
114
    }
115
116
nsKDEUtils::~nsKDEUtils()
117
    {
118
//    closeHelper(); not actually useful, exiting will close the fd too
119
    }
120
121
nsKDEUtils* nsKDEUtils::self()
122
    {
123
    static nsKDEUtils s;
124
    return &s;
125
    }
126
127
static bool helperRunning = false;
128
static bool helperFailed = false;
129
130
bool nsKDEUtils::kdeSession()
131
    {
132
    static bool session = getKdeSession();
133
    return session;
134
    }
135
136
bool nsKDEUtils::kdeSupport()
137
    {
138
    static bool support = kdeSession() && getKdeSupport();
139
    return support && helperRunning;
140
    }
141
142
struct nsKDECommandData
143
    {
144
    FILE* file;
145
    nsTArray<nsCString>* output;
146
    GMainLoop* loop;
147
    bool success;
148
    };
149
150
static gboolean kdeReadFunc( GIOChannel*, GIOCondition, gpointer data )
151
    {
152
    nsKDECommandData* p = static_cast< nsKDECommandData* >( data );
153
    char buf[ 8192 ]; // TODO big enough
154
    bool command_done = false;
155
    bool command_failed = false;
156
    while( !command_done && !command_failed && fgets( buf, 8192, p->file ) != NULL )
157
        { // TODO what if the kernel splits a line into two chunks?
158
//#ifdef DEBUG_KDE
159
//        fprintf( stderr, "READ: %s %d\n", buf, feof( p->file ));
160
//#endif
161
        if( char* eol = strchr( buf, '\n' ))
162
            *eol = '\0';
163
        command_done = ( strcmp( buf, "\\1" ) == 0 );
164
        command_failed = ( strcmp( buf, "\\0" ) == 0 );
165
        nsCAutoString line( buf );
166
        line.ReplaceSubstring( "\\n", "\n" );
167
        line.ReplaceSubstring( "\\" "\\", "\\" ); //  \\ -> \ , i.e. unescape
168
        if( p->output && !( command_done || command_failed ))
169
            p->output->AppendElement( nsCString( buf )); // TODO utf8?
170
        }
171
    bool quit = false;
172
    if( feof( p->file ) || command_failed )
173
        {
174
        quit = true;
175
        p->success = false;
176
        }
177
    if( command_done )
178
        { // reading one reply finished
179
        quit = true;
180
        p->success = true;
181
        }
182
    if( quit )
183
        {
184
        if( p->loop )
185
            g_main_loop_quit( p->loop );
186
        return FALSE;
187
        }
188
    return TRUE;
189
    }
190
191
bool nsKDEUtils::command( const nsTArray<nsCString>& command, nsTArray<nsCString>* output )
192
    {
193
    return self()->internalCommand( command, NULL, false, output );
194
    }
195
196
bool nsKDEUtils::command( nsIArray* command, nsIArray** output)
197
    {
198
    NS_ENSURE_ARG( command );
199
200
    nsTArray<nsCString> in;
201
    PRUint32 length;
202
    command->GetLength( &length );
203
    for ( PRUint32 i = 0; i < length; i++ )
204
        {
205
        nsCOMPtr<nsISupportsCString> str = do_QueryElementAt( command, i );
206
        if( str )
207
            {
208
            nsCAutoString s;
209
            str->GetData( s );
210
            in.AppendElement( s );
211
            }
212
        }
213
214
    nsTArray<nsCString> out;
215
    bool ret = self()->internalCommand( in, NULL, false, &out );
216
217
    if ( !output ) return ret;
218
219
    nsCOMPtr<nsIMutableArray> result = do_CreateInstance( NS_ARRAY_CONTRACTID );
220
    if ( !result ) return false;
221
222
    for ( PRUint32 i = 0; i < out.Length(); i++ )
223
        {
224
        nsCOMPtr<nsISupportsCString> rstr = do_CreateInstance( NS_SUPPORTS_CSTRING_CONTRACTID );
225
        if ( !rstr ) return false;
226
227
        rstr->SetData( out[i] );
228
        result->AppendElement( rstr, false );
229
        }
230
231
    NS_ADDREF( *output = result);
232
    return ret;
233
    }
234
235
236
bool nsKDEUtils::commandBlockUi( const nsTArray<nsCString>& command, const GtkWindow* parent, nsTArray<nsCString>* output )
237
    {
238
    return self()->internalCommand( command, parent, true, output );
239
    }
240
241
bool nsKDEUtils::internalCommand( const nsTArray<nsCString>& command, const GtkWindow* parent, bool blockUi,
242
    nsTArray<nsCString>* output )
243
    {
244
    if( !startHelper())
245
        return false;
246
    feedCommand( command );
247
    // do not store the data in 'this' but in extra structure, just in case there
248
    // is reentrancy (can there be? the event loop is re-entered)
249
    nsKDECommandData data;
250
    data.file = replyFile;
251
    data.output = output;
252
    data.success = false;
253
    if( blockUi )
254
        {
255
        data.loop = g_main_loop_new( NULL, FALSE );
256
        GtkWidget* window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
257
        if( parent && parent->group )
258
            gtk_window_group_add_window( parent->group, GTK_WINDOW( window ));
259
        gtk_widget_realize( window );
260
        gtk_widget_set_sensitive( window, TRUE );
261
        gtk_grab_add( window );
262
        GIOChannel* channel = g_io_channel_unix_new( fileno( data.file ));
263
        g_io_add_watch( channel, static_cast< GIOCondition >( G_IO_IN | G_IO_ERR | G_IO_HUP ), kdeReadFunc, &data );
264
        g_io_channel_unref( channel );
265
        g_main_loop_run( data.loop );
266
        g_main_loop_unref( data.loop );
267
        gtk_grab_remove( window );
268
        gtk_widget_destroy( window );
269
        }
270
    else
271
        {
272
        data.loop = NULL;
273
        while( kdeReadFunc( NULL, static_cast< GIOCondition >( 0 ), &data ))
274
            ;
275
        }
276
    return data.success;
277
    }
278
279
bool nsKDEUtils::startHelper()
280
    {
281
    if( helperRunning )
282
        return true;
283
    if( helperFailed )
284
        return false;
285
    helperFailed = true;
286
    int fdcommand[ 2 ];
287
    int fdreply[ 2 ];
288
    if( pipe( fdcommand ) < 0 )
289
        return false;
290
    if( pipe( fdreply ) < 0 )
291
        {
292
        close( fdcommand[ 0 ] );
293
        close( fdcommand[ 1 ] );
294
        return false;
295
        }
296
    char* args[ 2 ] = { const_cast< char* >( KMOZILLAHELPER ), NULL };
297
    switch( fork())
298
        {
299
        case -1:
300
            {
301
            close( fdcommand[ 0 ] );
302
            close( fdcommand[ 1 ] );
303
            close( fdreply[ 0 ] );
304
            close( fdreply[ 1 ] );
305
            return false;
306
            }
307
        case 0: // child
308
            {
309
            if( dup2( fdcommand[ 0 ], STDIN_FILENO ) < 0 )
310
                _exit( 1 );
311
            if( dup2( fdreply[ 1 ], STDOUT_FILENO ) < 0 )
312
                _exit( 1 );
313
            int maxfd = 1024; // close all other fds
314
            struct rlimit rl;
315
            if( getrlimit( RLIMIT_NOFILE, &rl ) == 0 )
316
                maxfd = rl.rlim_max;
317
            for( int i = 3;
318
                 i < maxfd;
319
                 ++i )
320
                close( i );
321
#ifdef DEBUG_KDE
322
            execvp( KMOZILLAHELPER, args );
323
#else
324
            execv( KMOZILLAHELPER, args );
325
#endif
326
            _exit( 1 ); // failed
327
            }
328
        default: // parent
329
            {
330
            commandFile = fdopen( fdcommand[ 1 ], "w" );
331
            replyFile = fdopen( fdreply[ 0 ], "r" );
332
            close( fdcommand[ 0 ] );
333
            close( fdreply[ 1 ] );
334
            if( commandFile == NULL || replyFile == NULL )
335
                {
336
                closeHelper();
337
                return false;
338
                }
339
            // ok, helper ready, getKdeRunning() will check if it works
340
            }
341
        }
342
    helperFailed = false;
343
    helperRunning = true;
344
    return true;
345
    }
346
347
void nsKDEUtils::closeHelper()
348
    {
349
    if( commandFile != NULL )
350
        fclose( commandFile ); // this will also make the helper quit
351
    if( replyFile != NULL )
352
        fclose( replyFile );
353
    helperRunning = false;
354
    }
355
356
void nsKDEUtils::feedCommand( const nsTArray<nsCString>& command )
357
    {
358
    for( int i = 0;
359
         i < command.Length();
360
         ++i )
361
        {
362
        nsCString line = command[ i ];
363
        line.ReplaceSubstring( "\\", "\\" "\\" ); // \ -> \\ , i.e. escape
364
        line.ReplaceSubstring( "\n", "\\n" );
365
#ifdef DEBUG_KDE
366
        fprintf( stderr, "COMM: %s\n", line.get());
367
#endif
368
        fputs( line.get(), commandFile );
369
        fputs( "\n", commandFile );
370
        }
371
    fputs( "\\E\n", commandFile ); // done as \E, so it cannot happen in normal data
372
    fflush( commandFile );
373
    }
(-)a/toolkit/xre/nsKDEUtils.h (+81 lines)
Line 0 Link Here
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2
 *
3
 * ***** BEGIN LICENSE BLOCK *****
4
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5
 *
6
 * The contents of this file are subject to the Mozilla Public License Version
7
 * 1.1 (the "License"); you may not use this file except in compliance with
8
 * the License. You may obtain a copy of the License at
9
 * http://www.mozilla.org/MPL/
10
 *
11
 * Software distributed under the License is distributed on an "AS IS" basis,
12
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13
 * for the specific language governing rights and limitations under the
14
 * License.
15
 *
16
 * The Original Code is Mozilla Communicator client code.
17
 *
18
 * The Initial Developer of the Original Code is
19
 * Netscape Communications Corporation.
20
 * Portions created by the Initial Developer are Copyright (C) 1998
21
 * the Initial Developer. All Rights Reserved.
22
 *
23
 * Contributor(s):
24
 *
25
 * Alternatively, the contents of this file may be used under the terms of
26
 * either of the GNU General Public License Version 2 or later (the "GPL"),
27
 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28
 * in which case the provisions of the GPL or the LGPL are applicable instead
29
 * of those above. If you wish to allow use of your version of this file only
30
 * under the terms of either the GPL or the LGPL, and not to allow others to
31
 * use your version of this file under the terms of the MPL, indicate your
32
 * decision by deleting the provisions above and replace them with the notice
33
 * and other provisions required by the GPL or the LGPL. If you do not delete
34
 * the provisions above, a recipient may use your version of this file under
35
 * the terms of any one of the MPL, the GPL or the LGPL.
36
 *
37
 * ***** END LICENSE BLOCK ***** */
38
39
#ifndef nsKDEUtils_h__
40
#define nsKDEUtils_h__
41
42
#include "nsStringGlue.h"
43
#include "nsTArray.h"
44
#include <stdio.h>
45
46
typedef struct _GtkWindow GtkWindow;
47
48
class nsIArray;
49
50
class NS_EXPORT nsKDEUtils
51
    {
52
    public:
53
        /* Returns true if running inside a KDE session (regardless of whether there is KDE
54
           support available for Firefox). This should be used e.g. when determining
55
           dialog button order but not for code that requires the KDE support. */
56
        static bool kdeSession();
57
        /* Returns true if running inside a KDE session and KDE support is available
58
           for Firefox. This should be used everywhere where the external helper is needed. */
59
        static bool kdeSupport();
60
        /* Executes the given helper command, returns true if helper returned success. */
61
        static bool command( const nsTArray<nsCString>& command, nsTArray<nsCString>* output = NULL );
62
        static bool command( nsIArray* command, nsIArray** output = NULL );
63
        /* Like command(), but additionally blocks the parent widget like if there was
64
           a modal dialog shown and enters the event loop (i.e. there are still paint updates,
65
           this is for commands that take long). */
66
        static bool commandBlockUi( const nsTArray<nsCString>& command, const GtkWindow* parent, nsTArray<nsCString>* output = NULL );
67
68
    private:
69
        nsKDEUtils();
70
        ~nsKDEUtils();
71
        static nsKDEUtils* self();
72
        bool startHelper();
73
        void closeHelper();
74
        void feedCommand( const nsTArray<nsCString>& command );
75
        bool internalCommand( const nsTArray<nsCString>& command, const GtkWindow* parent, bool isParent,
76
            nsTArray<nsCString>* output );
77
        FILE* commandFile;
78
        FILE* replyFile;
79
    };
80
81
#endif // nsKDEUtils
(-)a/uriloader/exthandler/Makefile.in (-1 / +2 lines)
Lines 90-107 LOCAL_INCLUDES = -I$(srcdir) Link Here
90
LOCAL_INCLUDES += -I$(topsrcdir)/dom/base \
90
LOCAL_INCLUDES += -I$(topsrcdir)/dom/base \
91
            -I$(topsrcdir)/dom/ipc \
91
            -I$(topsrcdir)/dom/ipc \
92
            -I$(topsrcdir)/content/base/src \
92
            -I$(topsrcdir)/content/base/src \
93
            -I$(topsrcdir)/content/events/src \
93
            -I$(topsrcdir)/content/events/src \
94
            -I$(topsrcdir)/netwerk/base/src \
94
            -I$(topsrcdir)/netwerk/base/src \
95
            -I$(topsrcdir)/netwerk/protocol/http
95
            -I$(topsrcdir)/netwerk/protocol/http
96
96
97
ifeq ($(MOZ_WIDGET_TOOLKIT),gtk2)
97
ifeq ($(MOZ_WIDGET_TOOLKIT),gtk2)
98
OSHELPER	+= nsGNOMERegistry.cpp
98
OSHELPER	+= nsCommonRegistry.cpp nsGNOMERegistry.cpp nsKDERegistry.cpp
99
OSHELPER  += nsMIMEInfoUnix.cpp
99
OSHELPER  += nsMIMEInfoUnix.cpp
100
LOCAL_INCLUDES += -I$(topsrcdir)/toolkit/xre
100
endif
101
endif
101
102
102
ifeq ($(MOZ_WIDGET_TOOLKIT),android)
103
ifeq ($(MOZ_WIDGET_TOOLKIT),android)
103
OSHELPER += nsMIMEInfoAndroid.cpp
104
OSHELPER += nsMIMEInfoAndroid.cpp
104
OSHELPER += nsAndroidHandlerApp.cpp
105
OSHELPER += nsAndroidHandlerApp.cpp
105
OSHELPER += nsExternalSharingAppService.cpp
106
OSHELPER += nsExternalSharingAppService.cpp
106
EXPORTS += nsExternalSharingAppService.h
107
EXPORTS += nsExternalSharingAppService.h
107
OSHELPER += nsExternalURLHandlerService.cpp
108
OSHELPER += nsExternalURLHandlerService.cpp
(-)a/uriloader/exthandler/unix/nsCommonRegistry.cpp (+87 lines)
Line 0 Link Here
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4
 *
5
 * The contents of this file are subject to the Mozilla Public License Version
6
 * 1.1 (the "License"); you may not use this file except in compliance with
7
 * the License. You may obtain a copy of the License at
8
 * http://www.mozilla.org/MPL/
9
 *
10
 * Software distributed under the License is distributed on an "AS IS" basis,
11
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
 * for the specific language governing rights and limitations under the
13
 * License.
14
 *
15
 * The Original Code is the GNOME helper app implementation.
16
 *
17
 * The Initial Developer of the Original Code is
18
 * IBM Corporation.
19
 * Portions created by the Initial Developer are Copyright (C) 2003
20
 * the Initial Developer. All Rights Reserved.
21
 *
22
 * Contributor(s):
23
 *  Brian Ryner <bryner@brianryner.com>  (Original Author)
24
 *
25
 * Alternatively, the contents of this file may be used under the terms of
26
 * either the GNU General Public License Version 2 or later (the "GPL"), or
27
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28
 * in which case the provisions of the GPL or the LGPL are applicable instead
29
 * of those above. If you wish to allow use of your version of this file only
30
 * under the terms of either the GPL or the LGPL, and not to allow others to
31
 * use your version of this file under the terms of the MPL, indicate your
32
 * decision by deleting the provisions above and replace them with the notice
33
 * and other provisions required by the GPL or the LGPL. If you do not delete
34
 * the provisions above, a recipient may use your version of this file under
35
 * the terms of any one of the MPL, the GPL or the LGPL.
36
 *
37
 * ***** END LICENSE BLOCK ***** */
38
39
#include "nsCommonRegistry.h"
40
41
#include "nsGNOMERegistry.h"
42
#include "nsKDERegistry.h"
43
#include "nsString.h"
44
#include "nsVoidArray.h"
45
#include "nsKDEUtils.h"
46
47
/* static */ PRBool
48
nsCommonRegistry::HandlerExists(const char *aProtocolScheme)
49
{
50
    if( nsKDEUtils::kdeSupport())
51
        return nsKDERegistry::HandlerExists( aProtocolScheme );
52
    return nsGNOMERegistry::HandlerExists( aProtocolScheme );
53
}
54
55
/* static */ nsresult
56
nsCommonRegistry::LoadURL(nsIURI *aURL)
57
{
58
    if( nsKDEUtils::kdeSupport())
59
        return nsKDERegistry::LoadURL( aURL );
60
    return nsGNOMERegistry::LoadURL( aURL );
61
}
62
63
/* static */ void
64
nsCommonRegistry::GetAppDescForScheme(const nsACString& aScheme,
65
                                     nsAString& aDesc)
66
{
67
    if( nsKDEUtils::kdeSupport())
68
        return nsKDERegistry::GetAppDescForScheme( aScheme, aDesc );
69
    return nsGNOMERegistry::GetAppDescForScheme( aScheme, aDesc );
70
}
71
72
73
/* static */ already_AddRefed<nsMIMEInfoBase>
74
nsCommonRegistry::GetFromExtension(const nsACString& aFileExt)
75
{
76
    if( nsKDEUtils::kdeSupport())
77
        return nsKDERegistry::GetFromExtension( aFileExt );
78
    return nsGNOMERegistry::GetFromExtension( aFileExt );
79
}
80
81
/* static */ already_AddRefed<nsMIMEInfoBase>
82
nsCommonRegistry::GetFromType(const nsACString& aMIMEType)
83
{
84
    if( nsKDEUtils::kdeSupport())
85
        return nsKDERegistry::GetFromType( aMIMEType );
86
    return nsGNOMERegistry::GetFromType( aMIMEType );
87
}
(-)a/uriloader/exthandler/unix/nsCommonRegistry.h (+56 lines)
Line 0 Link Here
1
/* ***** BEGIN LICENSE BLOCK *****
2
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3
 *
4
 * The contents of this file are subject to the Mozilla Public License Version
5
 * 1.1 (the "License"); you may not use this file except in compliance with
6
 * the License. You may obtain a copy of the License at
7
 * http://www.mozilla.org/MPL/
8
 *
9
 * Software distributed under the License is distributed on an "AS IS" basis,
10
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11
 * for the specific language governing rights and limitations under the
12
 * License.
13
 *
14
 * The Original Code is the GNOME helper app implementation.
15
 *
16
 * The Initial Developer of the Original Code is
17
 * IBM Corporation.
18
 * Portions created by the Initial Developer are Copyright (C) 2003
19
 * the Initial Developer. All Rights Reserved.
20
 *
21
 * Contributor(s):
22
 *  Brian Ryner <bryner@brianryner.com>  (Original Author)
23
 *
24
 * Alternatively, the contents of this file may be used under the terms of
25
 * either the GNU General Public License Version 2 or later (the "GPL"), or
26
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
 * in which case the provisions of the GPL or the LGPL are applicable instead
28
 * of those above. If you wish to allow use of your version of this file only
29
 * under the terms of either the GPL or the LGPL, and not to allow others to
30
 * use your version of this file under the terms of the MPL, indicate your
31
 * decision by deleting the provisions above and replace them with the notice
32
 * and other provisions required by the GPL or the LGPL. If you do not delete
33
 * the provisions above, a recipient may use your version of this file under
34
 * the terms of any one of the MPL, the GPL or the LGPL.
35
 *
36
 * ***** END LICENSE BLOCK ***** */
37
38
#include "nsIURI.h"
39
#include "nsCOMPtr.h"
40
41
class nsMIMEInfoBase;
42
43
class nsCommonRegistry
44
{
45
 public:
46
  static PRBool HandlerExists(const char *aProtocolScheme);
47
48
  static nsresult LoadURL(nsIURI *aURL);
49
50
  static void GetAppDescForScheme(const nsACString& aScheme,
51
                                  nsAString& aDesc);
52
53
  static already_AddRefed<nsMIMEInfoBase> GetFromExtension(const nsACString& aFileExt);
54
55
  static already_AddRefed<nsMIMEInfoBase> GetFromType(const nsACString& aMIMEType);
56
};
(-)a/uriloader/exthandler/unix/nsKDERegistry.cpp (+119 lines)
Line 0 Link Here
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4
 *
5
 * The contents of this file are subject to the Mozilla Public License Version
6
 * 1.1 (the "License"); you may not use this file except in compliance with
7
 * the License. You may obtain a copy of the License at
8
 * http://www.mozilla.org/MPL/
9
 *
10
 * Software distributed under the License is distributed on an "AS IS" basis,
11
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
 * for the specific language governing rights and limitations under the
13
 * License.
14
 *
15
 * The Original Code is the GNOME helper app implementation.
16
 *
17
 * The Initial Developer of the Original Code is
18
 * IBM Corporation.
19
 * Portions created by the Initial Developer are Copyright (C) 2003
20
 * the Initial Developer. All Rights Reserved.
21
 *
22
 * Contributor(s):
23
 *  Brian Ryner <bryner@brianryner.com>  (Original Author)
24
 *
25
 * Alternatively, the contents of this file may be used under the terms of
26
 * either the GNU General Public License Version 2 or later (the "GPL"), or
27
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28
 * in which case the provisions of the GPL or the LGPL are applicable instead
29
 * of those above. If you wish to allow use of your version of this file only
30
 * under the terms of either the GPL or the LGPL, and not to allow others to
31
 * use your version of this file under the terms of the MPL, indicate your
32
 * decision by deleting the provisions above and replace them with the notice
33
 * and other provisions required by the GPL or the LGPL. If you do not delete
34
 * the provisions above, a recipient may use your version of this file under
35
 * the terms of any one of the MPL, the GPL or the LGPL.
36
 *
37
 * ***** END LICENSE BLOCK ***** */
38
39
#include "nsKDERegistry.h"
40
#include "prlink.h"
41
#include "prmem.h"
42
#include "nsString.h"
43
#include "nsILocalFile.h"
44
#include "nsMIMEInfoUnix.h"
45
#include "nsAutoPtr.h"
46
#include "nsKDEUtils.h"
47
48
/* static */ PRBool
49
nsKDERegistry::HandlerExists(const char *aProtocolScheme)
50
{
51
    nsTArray<nsCString> command;
52
    command.AppendElement( NS_LITERAL_CSTRING( "HANDLEREXISTS" ));
53
    command.AppendElement( nsCAutoString( aProtocolScheme ));
54
    return nsKDEUtils::command( command );
55
}
56
57
/* static */ nsresult
58
nsKDERegistry::LoadURL(nsIURI *aURL)
59
{
60
    nsTArray<nsCString> command;
61
    command.AppendElement( NS_LITERAL_CSTRING( "OPEN" ));
62
    nsCString url;
63
    aURL->GetSpec( url );
64
    command.AppendElement( url );
65
    return nsKDEUtils::command( command );
66
}
67
68
/* static */ void
69
nsKDERegistry::GetAppDescForScheme(const nsACString& aScheme,
70
                                     nsAString& aDesc)
71
{
72
    nsTArray<nsCString> command;
73
    command.AppendElement( NS_LITERAL_CSTRING( "GETAPPDESCFORSCHEME" ));
74
    command.AppendElement( aScheme );
75
    nsTArray<nsCString> output;
76
    if( nsKDEUtils::command( command, &output ) && output.Length() == 1 )
77
        CopyUTF8toUTF16( output[ 0 ], aDesc );
78
}
79
80
81
/* static */ already_AddRefed<nsMIMEInfoBase>
82
nsKDERegistry::GetFromExtension(const nsACString& aFileExt)
83
{
84
    NS_ASSERTION(aFileExt[0] != '.', "aFileExt shouldn't start with a dot");
85
    nsTArray<nsCString> command;
86
    command.AppendElement( NS_LITERAL_CSTRING( "GETFROMEXTENSION" ));
87
    command.AppendElement( aFileExt );
88
    return GetFromHelper( command );
89
}
90
91
/* static */ already_AddRefed<nsMIMEInfoBase>
92
nsKDERegistry::GetFromType(const nsACString& aMIMEType)
93
{
94
    nsTArray<nsCString> command;
95
    command.AppendElement( NS_LITERAL_CSTRING( "GETFROMTYPE" ));
96
    command.AppendElement( aMIMEType );
97
    return GetFromHelper( command );
98
}
99
100
/* static */ already_AddRefed<nsMIMEInfoBase>
101
nsKDERegistry::GetFromHelper(const nsTArray<nsCString>& command)
102
{
103
    nsTArray<nsCString> output;
104
    if( nsKDEUtils::command( command, &output ) && output.Length() == 3 )
105
        {
106
        nsCString mimetype = output[ 0 ];
107
        nsRefPtr<nsMIMEInfoUnix> mimeInfo = new nsMIMEInfoUnix( mimetype );
108
        NS_ENSURE_TRUE(mimeInfo, nsnull);
109
        nsCString description = output[ 1 ];
110
        mimeInfo->SetDescription(NS_ConvertUTF8toUTF16(description));
111
        nsCString handlerAppName = output[ 2 ];
112
        mimeInfo->SetDefaultDescription(NS_ConvertUTF8toUTF16(handlerAppName));
113
        mimeInfo->SetPreferredAction(nsIMIMEInfo::useSystemDefault);
114
        nsMIMEInfoBase* retval;
115
        NS_ADDREF((retval = mimeInfo));
116
        return retval;
117
        }
118
    return nsnull;
119
}
(-)a/uriloader/exthandler/unix/nsKDERegistry.h (+62 lines)
Line 0 Link Here
1
/* ***** BEGIN LICENSE BLOCK *****
2
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3
 *
4
 * The contents of this file are subject to the Mozilla Public License Version
5
 * 1.1 (the "License"); you may not use this file except in compliance with
6
 * the License. You may obtain a copy of the License at
7
 * http://www.mozilla.org/MPL/
8
 *
9
 * Software distributed under the License is distributed on an "AS IS" basis,
10
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11
 * for the specific language governing rights and limitations under the
12
 * License.
13
 *
14
 * The Original Code is the GNOME helper app implementation.
15
 *
16
 * The Initial Developer of the Original Code is
17
 * IBM Corporation.
18
 * Portions created by the Initial Developer are Copyright (C) 2003
19
 * the Initial Developer. All Rights Reserved.
20
 *
21
 * Contributor(s):
22
 *  Brian Ryner <bryner@brianryner.com>  (Original Author)
23
 *
24
 * Alternatively, the contents of this file may be used under the terms of
25
 * either the GNU General Public License Version 2 or later (the "GPL"), or
26
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
 * in which case the provisions of the GPL or the LGPL are applicable instead
28
 * of those above. If you wish to allow use of your version of this file only
29
 * under the terms of either the GPL or the LGPL, and not to allow others to
30
 * use your version of this file under the terms of the MPL, indicate your
31
 * decision by deleting the provisions above and replace them with the notice
32
 * and other provisions required by the GPL or the LGPL. If you do not delete
33
 * the provisions above, a recipient may use your version of this file under
34
 * the terms of any one of the MPL, the GPL or the LGPL.
35
 *
36
 * ***** END LICENSE BLOCK ***** */
37
38
#include "nsIURI.h"
39
#include "nsCOMPtr.h"
40
#include "nsTArray.h"
41
42
class nsMIMEInfoBase;
43
class nsCAutoString;
44
class nsCString;
45
46
class nsKDERegistry
47
{
48
 public:
49
  static PRBool HandlerExists(const char *aProtocolScheme);
50
51
  static nsresult LoadURL(nsIURI *aURL);
52
53
  static void GetAppDescForScheme(const nsACString& aScheme,
54
                                  nsAString& aDesc);
55
56
  static already_AddRefed<nsMIMEInfoBase> GetFromExtension(const nsACString& aFileExt);
57
58
  static already_AddRefed<nsMIMEInfoBase> GetFromType(const nsACString& aMIMEType);
59
 private:
60
  static already_AddRefed<nsMIMEInfoBase> GetFromHelper(const nsTArray<nsCString>& command);
61
62
};
(-)a/uriloader/exthandler/unix/nsMIMEInfoUnix.cpp (-5 / +25 lines)
Lines 50-79 Link Here
50
#include <QString>
50
#include <QString>
51
#if (MOZ_ENABLE_CONTENTACTION)
51
#if (MOZ_ENABLE_CONTENTACTION)
52
#include <contentaction/contentaction.h>
52
#include <contentaction/contentaction.h>
53
#include "nsContentHandlerApp.h"
53
#include "nsContentHandlerApp.h"
54
#endif
54
#endif
55
#endif
55
#endif
56
56
57
#include "nsMIMEInfoUnix.h"
57
#include "nsMIMEInfoUnix.h"
58
#include "nsGNOMERegistry.h"
58
#include "nsCommonRegistry.h"
59
#include "nsIGIOService.h"
59
#include "nsIGIOService.h"
60
#include "nsNetCID.h"
60
#include "nsNetCID.h"
61
#include "nsIIOService.h"
61
#include "nsIIOService.h"
62
#include "nsIGnomeVFSService.h"
62
#include "nsIGnomeVFSService.h"
63
#include "nsAutoPtr.h"
63
#include "nsAutoPtr.h"
64
#ifdef MOZ_ENABLE_DBUS
64
#ifdef MOZ_ENABLE_DBUS
65
#include "nsDBusHandlerApp.h"
65
#include "nsDBusHandlerApp.h"
66
#endif
66
#endif
67
#if defined(XP_UNIX) && !defined(XP_MACOSX)
68
#include "nsKDEUtils.h"
69
#endif
67
70
68
nsresult
71
nsresult
69
nsMIMEInfoUnix::LoadUriInternal(nsIURI * aURI)
72
nsMIMEInfoUnix::LoadUriInternal(nsIURI * aURI)
70
{
73
{
71
  nsresult rv = nsGNOMERegistry::LoadURL(aURI);
74
  nsresult rv = nsCommonRegistry::LoadURL(aURI);
72
75
73
#if (MOZ_PLATFORM_MAEMO == 5) && defined (MOZ_ENABLE_GNOMEVFS)
76
#if (MOZ_PLATFORM_MAEMO == 5) && defined (MOZ_ENABLE_GNOMEVFS)
74
  if (NS_FAILED(rv)){
77
  if (NS_FAILED(rv)){
75
    HildonURIAction *action = hildon_uri_get_default_action(mSchemeOrType.get(), nsnull);
78
    HildonURIAction *action = hildon_uri_get_default_action(mSchemeOrType.get(), nsnull);
76
    if (action) {
79
    if (action) {
77
      nsCAutoString spec;
80
      nsCAutoString spec;
78
      aURI->GetAsciiSpec(spec);
81
      aURI->GetAsciiSpec(spec);
79
      if (hildon_uri_open(spec.get(), action, nsnull))
82
      if (hildon_uri_open(spec.get(), action, nsnull))
Lines 95-116 nsMIMEInfoUnix::LoadUriInternal(nsIURI * Link Here
95
98
96
  return rv;
99
  return rv;
97
}
100
}
98
101
99
NS_IMETHODIMP
102
NS_IMETHODIMP
100
nsMIMEInfoUnix::GetHasDefaultHandler(bool *_retval)
103
nsMIMEInfoUnix::GetHasDefaultHandler(bool *_retval)
101
{
104
{
102
  *_retval = false;
105
  *_retval = false;
103
  nsRefPtr<nsMIMEInfoBase> mimeInfo = nsGNOMERegistry::GetFromType(mSchemeOrType);
106
  nsRefPtr<nsMIMEInfoBase> mimeInfo = nsCommonRegistry::GetFromType(mSchemeOrType);
104
  if (!mimeInfo) {
107
  if (!mimeInfo) {
105
    nsCAutoString ext;
108
    nsCAutoString ext;
106
    nsresult rv = GetPrimaryExtension(ext);
109
    nsresult rv = GetPrimaryExtension(ext);
107
    if (NS_SUCCEEDED(rv)) {
110
    if (NS_SUCCEEDED(rv)) {
108
      mimeInfo = nsGNOMERegistry::GetFromExtension(ext);
111
      mimeInfo = nsCommonRegistry::GetFromExtension(ext);
109
    }
112
    }
110
  }
113
  }
111
  if (mimeInfo)
114
  if (mimeInfo)
112
    *_retval = true;
115
    *_retval = true;
113
116
114
  if (*_retval)
117
  if (*_retval)
115
    return NS_OK;
118
    return NS_OK;
116
119
Lines 153-168 nsMIMEInfoUnix::LaunchDefaultWithFile(ns Link Here
153
    ContentAction::Action::defaultActionForFile(uri, QString(mSchemeOrType.get()));
156
    ContentAction::Action::defaultActionForFile(uri, QString(mSchemeOrType.get()));
154
  if (action.isValid()) {
157
  if (action.isValid()) {
155
    action.trigger();
158
    action.trigger();
156
    return NS_OK;
159
    return NS_OK;
157
  }
160
  }
158
  return NS_ERROR_FAILURE;
161
  return NS_ERROR_FAILURE;
159
#endif
162
#endif
160
163
164
  if( nsKDEUtils::kdeSupport()) {
165
    bool supports;
166
    if( NS_SUCCEEDED( GetHasDefaultHandler( &supports )) && supports ) {
167
      nsTArray<nsCString> command;
168
      command.AppendElement( NS_LITERAL_CSTRING( "OPEN" ));
169
      command.AppendElement( nativePath );
170
      command.AppendElement( NS_LITERAL_CSTRING( "MIMETYPE" ));
171
      command.AppendElement( mSchemeOrType );
172
      if( nsKDEUtils::command( command ))
173
        return NS_OK;
174
    }
175
    if (!mDefaultApplication)
176
      return NS_ERROR_FILE_NOT_FOUND;
177
178
    return LaunchWithIProcess(mDefaultApplication, nativePath);
179
  }
180
161
  nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
181
  nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
162
  nsCAutoString uriSpec;
182
  nsCAutoString uriSpec;
163
  if (giovfs) {
183
  if (giovfs) {
164
    // nsGIOMimeApp->Launch wants a URI string instead of local file
184
    // nsGIOMimeApp->Launch wants a URI string instead of local file
165
    nsresult rv;
185
    nsresult rv;
166
    nsCOMPtr<nsIIOService> ioservice = do_GetService(NS_IOSERVICE_CONTRACTID, &rv);
186
    nsCOMPtr<nsIIOService> ioservice = do_GetService(NS_IOSERVICE_CONTRACTID, &rv);
167
    NS_ENSURE_SUCCESS(rv, rv);
187
    NS_ENSURE_SUCCESS(rv, rv);
168
    nsCOMPtr<nsIURI> uri;
188
    nsCOMPtr<nsIURI> uri;
Lines 180-196 nsMIMEInfoUnix::LaunchDefaultWithFile(ns Link Here
180
    /* Fallback to GnomeVFS */
200
    /* Fallback to GnomeVFS */
181
    nsCOMPtr<nsIGnomeVFSMimeApp> app;
201
    nsCOMPtr<nsIGnomeVFSMimeApp> app;
182
    if (NS_SUCCEEDED(gnomevfs->GetAppForMimeType(mSchemeOrType, getter_AddRefs(app))) && app)
202
    if (NS_SUCCEEDED(gnomevfs->GetAppForMimeType(mSchemeOrType, getter_AddRefs(app))) && app)
183
      return app->Launch(nativePath);
203
      return app->Launch(nativePath);
184
  }
204
  }
185
205
186
  // If we haven't got an app we try to get a valid one by searching for the
206
  // If we haven't got an app we try to get a valid one by searching for the
187
  // extension mapped type
207
  // extension mapped type
188
  nsRefPtr<nsMIMEInfoBase> mimeInfo = nsGNOMERegistry::GetFromExtension(nativePath);
208
  nsRefPtr<nsMIMEInfoBase> mimeInfo = nsCommonRegistry::GetFromExtension(nativePath);
189
  if (mimeInfo) {
209
  if (mimeInfo) {
190
    nsCAutoString type;
210
    nsCAutoString type;
191
    mimeInfo->GetType(type);
211
    mimeInfo->GetType(type);
192
    if (giovfs) {
212
    if (giovfs) {
193
      nsCOMPtr<nsIGIOMimeApp> app;
213
      nsCOMPtr<nsIGIOMimeApp> app;
194
      if (NS_SUCCEEDED(giovfs->GetAppForMimeType(type, getter_AddRefs(app))) && app)
214
      if (NS_SUCCEEDED(giovfs->GetAppForMimeType(type, getter_AddRefs(app))) && app)
195
        return app->Launch(uriSpec);
215
        return app->Launch(uriSpec);
196
    } else if (gnomevfs) {
216
    } else if (gnomevfs) {
(-)a/uriloader/exthandler/unix/nsOSHelperAppService.cpp (-5 / +5 lines)
Lines 44-60 Link Here
44
#if defined(MOZ_ENABLE_CONTENTACTION)
44
#if defined(MOZ_ENABLE_CONTENTACTION)
45
#include <contentaction/contentaction.h>
45
#include <contentaction/contentaction.h>
46
#include <QString>
46
#include <QString>
47
#endif
47
#endif
48
48
49
#include "nsOSHelperAppService.h"
49
#include "nsOSHelperAppService.h"
50
#include "nsMIMEInfoUnix.h"
50
#include "nsMIMEInfoUnix.h"
51
#ifdef MOZ_WIDGET_GTK2
51
#ifdef MOZ_WIDGET_GTK2
52
#include "nsGNOMERegistry.h"
52
#include "nsCommonRegistry.h"
53
#endif
53
#endif
54
#include "nsISupports.h"
54
#include "nsISupports.h"
55
#include "nsString.h"
55
#include "nsString.h"
56
#include "nsReadableUtils.h"
56
#include "nsReadableUtils.h"
57
#include "nsUnicharUtils.h"
57
#include "nsUnicharUtils.h"
58
#include "nsXPIDLString.h"
58
#include "nsXPIDLString.h"
59
#include "nsIURL.h"
59
#include "nsIURL.h"
60
#include "nsIFileStreams.h"
60
#include "nsIFileStreams.h"
Lines 1191-1219 nsresult nsOSHelperAppService::OSProtoco Link Here
1191
    ContentAction::Action::defaultActionForScheme(QString(aProtocolScheme) + ':');
1191
    ContentAction::Action::defaultActionForScheme(QString(aProtocolScheme) + ':');
1192
1192
1193
  if (action.isValid())
1193
  if (action.isValid())
1194
    *aHandlerExists = true;
1194
    *aHandlerExists = true;
1195
#endif
1195
#endif
1196
1196
1197
#ifdef MOZ_WIDGET_GTK2
1197
#ifdef MOZ_WIDGET_GTK2
1198
  // Check the GConf registry for a protocol handler
1198
  // Check the GConf registry for a protocol handler
1199
  *aHandlerExists = nsGNOMERegistry::HandlerExists(aProtocolScheme);
1199
  *aHandlerExists = nsCommonRegistry::HandlerExists(aProtocolScheme);
1200
#if (MOZ_PLATFORM_MAEMO == 5) && defined (MOZ_ENABLE_GNOMEVFS)
1200
#if (MOZ_PLATFORM_MAEMO == 5) && defined (MOZ_ENABLE_GNOMEVFS)
1201
  *aHandlerExists = nsMIMEInfoUnix::HandlerExists(aProtocolScheme);
1201
  *aHandlerExists = nsMIMEInfoUnix::HandlerExists(aProtocolScheme);
1202
#endif
1202
#endif
1203
#endif
1203
#endif
1204
1204
1205
  return NS_OK;
1205
  return NS_OK;
1206
}
1206
}
1207
1207
1208
NS_IMETHODIMP nsOSHelperAppService::GetApplicationDescription(const nsACString& aScheme, nsAString& _retval)
1208
NS_IMETHODIMP nsOSHelperAppService::GetApplicationDescription(const nsACString& aScheme, nsAString& _retval)
1209
{
1209
{
1210
#ifdef MOZ_WIDGET_GTK2
1210
#ifdef MOZ_WIDGET_GTK2
1211
  nsGNOMERegistry::GetAppDescForScheme(aScheme, _retval);
1211
  nsCommonRegistry::GetAppDescForScheme(aScheme, _retval);
1212
  return _retval.IsEmpty() ? NS_ERROR_NOT_AVAILABLE : NS_OK;
1212
  return _retval.IsEmpty() ? NS_ERROR_NOT_AVAILABLE : NS_OK;
1213
#else
1213
#else
1214
  return NS_ERROR_NOT_AVAILABLE;
1214
  return NS_ERROR_NOT_AVAILABLE;
1215
#endif
1215
#endif
1216
}
1216
}
1217
1217
1218
nsresult nsOSHelperAppService::GetFileTokenForPath(const PRUnichar * platformAppPath, nsIFile ** aFile)
1218
nsresult nsOSHelperAppService::GetFileTokenForPath(const PRUnichar * platformAppPath, nsIFile ** aFile)
1219
{
1219
{
Lines 1299-1315 nsOSHelperAppService::GetFromExtension(c Link Here
1299
                                         minorType,
1299
                                         minorType,
1300
                                         mime_types_description,
1300
                                         mime_types_description,
1301
                                         true);
1301
                                         true);
1302
1302
1303
  if (NS_FAILED(rv) || majorType.IsEmpty()) {
1303
  if (NS_FAILED(rv) || majorType.IsEmpty()) {
1304
    
1304
    
1305
#ifdef MOZ_WIDGET_GTK2
1305
#ifdef MOZ_WIDGET_GTK2
1306
    LOG(("Looking in GNOME registry\n"));
1306
    LOG(("Looking in GNOME registry\n"));
1307
    nsMIMEInfoBase *gnomeInfo = nsGNOMERegistry::GetFromExtension(aFileExt).get();
1307
    nsMIMEInfoBase *gnomeInfo = nsCommonRegistry::GetFromExtension(aFileExt).get();
1308
    if (gnomeInfo) {
1308
    if (gnomeInfo) {
1309
      LOG(("Got MIMEInfo from GNOME registry\n"));
1309
      LOG(("Got MIMEInfo from GNOME registry\n"));
1310
      return gnomeInfo;
1310
      return gnomeInfo;
1311
    }
1311
    }
1312
#endif
1312
#endif
1313
1313
1314
    rv = LookUpTypeAndDescription(NS_ConvertUTF8toUTF16(aFileExt),
1314
    rv = LookUpTypeAndDescription(NS_ConvertUTF8toUTF16(aFileExt),
1315
                                  majorType,
1315
                                  majorType,
Lines 1425-1441 nsOSHelperAppService::GetFromType(const Link Here
1425
#ifdef MOZ_WIDGET_GTK2
1425
#ifdef MOZ_WIDGET_GTK2
1426
  nsMIMEInfoBase *gnomeInfo = nsnull;
1426
  nsMIMEInfoBase *gnomeInfo = nsnull;
1427
  if (handler.IsEmpty()) {
1427
  if (handler.IsEmpty()) {
1428
    // No useful data yet.  Check the GNOME registry.  Unfortunately, newer
1428
    // No useful data yet.  Check the GNOME registry.  Unfortunately, newer
1429
    // GNOME versions no longer have type-to-extension mappings, so we might
1429
    // GNOME versions no longer have type-to-extension mappings, so we might
1430
    // get back a MIMEInfo without any extensions set.  In that case we'll have
1430
    // get back a MIMEInfo without any extensions set.  In that case we'll have
1431
    // to look in our mime.types files for the extensions.    
1431
    // to look in our mime.types files for the extensions.    
1432
    LOG(("Looking in GNOME registry\n"));
1432
    LOG(("Looking in GNOME registry\n"));
1433
    gnomeInfo = nsGNOMERegistry::GetFromType(aMIMEType).get();
1433
    gnomeInfo = nsCommonRegistry::GetFromType(aMIMEType).get();
1434
    if (gnomeInfo && gnomeInfo->HasExtensions()) {
1434
    if (gnomeInfo && gnomeInfo->HasExtensions()) {
1435
      LOG(("Got MIMEInfo from GNOME registry, and it has extensions set\n"));
1435
      LOG(("Got MIMEInfo from GNOME registry, and it has extensions set\n"));
1436
      return gnomeInfo;
1436
      return gnomeInfo;
1437
    }
1437
    }
1438
  }
1438
  }
1439
#endif
1439
#endif
1440
1440
1441
  // Now look up our extensions
1441
  // Now look up our extensions
(-)a/widget/gtk2/Makefile.in (+3 lines)
Lines 135-145 DEFINES += -DCAIRO_GFX -DMOZ_APP_NAME=' Link Here
135
135
136
INCLUDES	+= \
136
INCLUDES	+= \
137
		-I$(srcdir)/../xpwidgets \
137
		-I$(srcdir)/../xpwidgets \
138
		-I$(srcdir)/../shared \
138
		-I$(srcdir)/../shared \
139
		-I$(topsrcdir)/layout/generic \
139
		-I$(topsrcdir)/layout/generic \
140
		-I$(topsrcdir)/layout/xul/base/src \
140
		-I$(topsrcdir)/layout/xul/base/src \
141
		-I$(topsrcdir)/other-licenses/atk-1.0 \
141
		-I$(topsrcdir)/other-licenses/atk-1.0 \
142
		$(NULL)
142
		$(NULL)
143
144
LOCAL_INCLUDES += -I$(topsrcdir)/toolkit/xre
145
143
ifdef MOZ_X11
146
ifdef MOZ_X11
144
INCLUDES   	+= -I$(srcdir)/../shared/x11
147
INCLUDES   	+= -I$(srcdir)/../shared/x11
145
endif
148
endif
(-)a/widget/gtk2/nsFilePicker.cpp (-1 / +234 lines)
Lines 33-48 Link Here
33
 * the provisions above, a recipient may use your version of this file under
33
 * the provisions above, a recipient may use your version of this file under
34
 * the terms of any one of the MPL, the GPL or the LGPL.
34
 * the terms of any one of the MPL, the GPL or the LGPL.
35
 *
35
 *
36
 * ***** END LICENSE BLOCK ***** */
36
 * ***** END LICENSE BLOCK ***** */
37
37
38
#include "mozilla/Util.h"
38
#include "mozilla/Util.h"
39
39
40
#include <gtk/gtk.h>
40
#include <gtk/gtk.h>
41
#include <gdk/gdkx.h>
41
42
42
#include "nsIFileURL.h"
43
#include "nsIFileURL.h"
43
#include "nsIURI.h"
44
#include "nsIURI.h"
44
#include "nsIWidget.h"
45
#include "nsIWidget.h"
45
#include "nsILocalFile.h"
46
#include "nsILocalFile.h"
46
#include "nsIStringBundle.h"
47
#include "nsIStringBundle.h"
47
48
48
#include "nsArrayEnumerator.h"
49
#include "nsArrayEnumerator.h"
Lines 51-66 Link Here
51
#include "nsNetUtil.h"
52
#include "nsNetUtil.h"
52
#include "nsReadableUtils.h"
53
#include "nsReadableUtils.h"
53
#include "mozcontainer.h"
54
#include "mozcontainer.h"
54
55
55
#include "prmem.h"
56
#include "prmem.h"
56
#include "prlink.h"
57
#include "prlink.h"
57
58
58
#include "nsFilePicker.h"
59
#include "nsFilePicker.h"
60
#include "nsKDEUtils.h"
59
61
60
#if (MOZ_PLATFORM_MAEMO == 5)
62
#if (MOZ_PLATFORM_MAEMO == 5)
61
#include <hildon-fm-2/hildon/hildon-file-chooser-dialog.h>
63
#include <hildon-fm-2/hildon/hildon-file-chooser-dialog.h>
62
#endif
64
#endif
63
65
64
using namespace mozilla;
66
using namespace mozilla;
65
67
66
#define MAX_PREVIEW_SIZE 180
68
#define MAX_PREVIEW_SIZE 180
Lines 285-301 nsFilePicker::AppendFilters(PRInt32 aFil Link Here
285
  return nsBaseFilePicker::AppendFilters(aFilterMask);
287
  return nsBaseFilePicker::AppendFilters(aFilterMask);
286
}
288
}
287
289
288
NS_IMETHODIMP
290
NS_IMETHODIMP
289
nsFilePicker::AppendFilter(const nsAString& aTitle, const nsAString& aFilter)
291
nsFilePicker::AppendFilter(const nsAString& aTitle, const nsAString& aFilter)
290
{
292
{
291
  if (aFilter.EqualsLiteral("..apps")) {
293
  if (aFilter.EqualsLiteral("..apps")) {
292
    // No platform specific thing we can do here, really....
294
    // No platform specific thing we can do here, really....
293
    return NS_OK;
295
    // Unless it's KDE.
296
    if( mMode != modeOpen || !nsKDEUtils::kdeSupport())
297
        return NS_OK;
294
  }
298
  }
295
299
296
  nsCAutoString filter, name;
300
  nsCAutoString filter, name;
297
  CopyUTF16toUTF8(aFilter, filter);
301
  CopyUTF16toUTF8(aFilter, filter);
298
  CopyUTF16toUTF8(aTitle, name);
302
  CopyUTF16toUTF8(aTitle, name);
299
303
300
  mFilters.AppendElement(filter);
304
  mFilters.AppendElement(filter);
301
  mFilterNames.AppendElement(name);
305
  mFilterNames.AppendElement(name);
Lines 390-405 nsFilePicker::GetFiles(nsISimpleEnumerat Link Here
390
  return NS_ERROR_FAILURE;
394
  return NS_ERROR_FAILURE;
391
}
395
}
392
396
393
NS_IMETHODIMP
397
NS_IMETHODIMP
394
nsFilePicker::Show(PRInt16 *aReturn)
398
nsFilePicker::Show(PRInt16 *aReturn)
395
{
399
{
396
  NS_ENSURE_ARG_POINTER(aReturn);
400
  NS_ENSURE_ARG_POINTER(aReturn);
397
401
402
  if( nsKDEUtils::kdeSupport())
403
    return kdeFileDialog(aReturn);
404
398
  nsXPIDLCString title;
405
  nsXPIDLCString title;
399
  title.Adopt(ToNewUTF8String(mTitle));
406
  title.Adopt(ToNewUTF8String(mTitle));
400
407
401
  GtkWindow *parent_widget = get_gtk_window_for_nsiwidget(mParentWidget);
408
  GtkWindow *parent_widget = get_gtk_window_for_nsiwidget(mParentWidget);
402
409
403
  GtkFileChooserAction action = GetGtkFileChooserAction(mMode);
410
  GtkFileChooserAction action = GetGtkFileChooserAction(mMode);
404
  const gchar *accept_button = (action == GTK_FILE_CHOOSER_ACTION_SAVE)
411
  const gchar *accept_button = (action == GTK_FILE_CHOOSER_ACTION_SAVE)
405
                               ? GTK_STOCK_SAVE : GTK_STOCK_OPEN;
412
                               ? GTK_STOCK_SAVE : GTK_STOCK_OPEN;
Lines 538-545 nsFilePicker::Show(PRInt16 *aReturn) Link Here
538
    *aReturn = nsIFilePicker::returnCancel;
545
    *aReturn = nsIFilePicker::returnCancel;
539
    break;
546
    break;
540
  }
547
  }
541
548
542
  gtk_widget_destroy(file_chooser);
549
  gtk_widget_destroy(file_chooser);
543
550
544
  return NS_OK;
551
  return NS_OK;
545
}
552
}
553
554
nsCString nsFilePicker::kdeMakeFilter( int index )
555
    {
556
    nsCString buf = mFilters[ index ];
557
    for( PRUint32 i = 0;
558
         i < buf.Length();
559
         ++i )
560
        if( buf[ i ] == ';' ) // KDE separates just using spaces
561
            buf.SetCharAt( ' ', i );
562
    if (!mFilterNames[index].IsEmpty())
563
        {
564
        buf += "|";
565
        buf += mFilterNames[index].get();
566
        }
567
    return buf;
568
    }
569
570
static PRInt32 windowToXid( nsIWidget* widget )
571
    {
572
    GtkWindow *parent_widget = get_gtk_window_for_nsiwidget( widget );
573
    GdkWindow* gdk_window = gtk_widget_get_window( gtk_widget_get_toplevel( GTK_WIDGET( parent_widget )));
574
    return GDK_WINDOW_XID( gdk_window );
575
    }
576
577
NS_IMETHODIMP nsFilePicker::kdeFileDialog(PRInt16 *aReturn)
578
    {
579
    NS_ENSURE_ARG_POINTER(aReturn);
580
581
    if( mMode == modeOpen && mFilters.Length() == 1 && mFilters[ 0 ].EqualsLiteral( "..apps" ))
582
        return kdeAppsDialog( aReturn );
583
584
    nsXPIDLCString title;
585
    title.Adopt(ToNewUTF8String(mTitle));
586
587
    const char* arg = NULL;
588
    if( mAllowURLs )
589
        {
590
        switch( mMode )
591
            {
592
            case nsIFilePicker::modeOpen:
593
            case nsIFilePicker::modeOpenMultiple:
594
                arg = "GETOPENURL";
595
                break;
596
            case nsIFilePicker::modeSave:
597
                arg = "GETSAVEURL";
598
                break;
599
            case nsIFilePicker::modeGetFolder:
600
                arg = "GETDIRECTORYURL";
601
                break;
602
            }
603
        }
604
    else
605
        {
606
        switch( mMode )
607
            {
608
            case nsIFilePicker::modeOpen:
609
            case nsIFilePicker::modeOpenMultiple:
610
                arg = "GETOPENFILENAME";
611
                break;
612
            case nsIFilePicker::modeSave:
613
                arg = "GETSAVEFILENAME";
614
                break;
615
            case nsIFilePicker::modeGetFolder:
616
                arg = "GETDIRECTORYFILENAME";
617
                break;
618
            }
619
        }
620
621
  nsCAutoString directory;
622
  if (mDisplayDirectory) {
623
    mDisplayDirectory->GetNativePath(directory);
624
  } else if (mPrevDisplayDirectory) {
625
    mPrevDisplayDirectory->GetNativePath(directory);
626
  }
627
628
    nsCAutoString startdir;
629
  if (!directory.IsEmpty()) {
630
    startdir = directory;
631
  }
632
  if (mMode == nsIFilePicker::modeSave) {
633
    if( !startdir.IsEmpty())
634
      {
635
      startdir += "/";
636
      startdir += ToNewUTF8String(mDefault);
637
      }
638
    else
639
      startdir = ToNewUTF8String(mDefault);
640
  }
641
  if( startdir.IsEmpty())
642
      startdir = ".";
643
644
    nsCAutoString filters;
645
    PRInt32 count = mFilters.Length();
646
    if( count == 0 ) //just in case
647
        filters = "*";
648
    else
649
        {
650
        filters = kdeMakeFilter( 0 );
651
        for (PRInt32 i = 1; i < count; ++i)
652
            {
653
            filters += "\n";
654
            filters += kdeMakeFilter( i );
655
            }
656
        }
657
658
    nsTArray<nsCString> command;
659
    command.AppendElement( nsCAutoString( arg ));
660
    command.AppendElement( startdir );
661
    if( mMode != nsIFilePicker::modeGetFolder )
662
        {
663
        command.AppendElement( filters );
664
        nsCAutoString selected;
665
        selected.AppendInt( mSelectedType );
666
        command.AppendElement( selected );
667
        }
668
    command.AppendElement( title );
669
    if( mMode == nsIFilePicker::modeOpenMultiple )
670
        command.AppendElement( NS_LITERAL_CSTRING( "MULTIPLE" ));
671
    if( PRInt32 xid = windowToXid( mParentWidget ))
672
        {
673
        command.AppendElement( NS_LITERAL_CSTRING( "PARENT" ));
674
        nsCAutoString parent;
675
        parent.AppendInt( xid );
676
        command.AppendElement( parent );
677
        }
678
679
    nsTArray<nsCString> output;
680
    if( nsKDEUtils::commandBlockUi( command, get_gtk_window_for_nsiwidget( mParentWidget ), &output ))
681
        {
682
        *aReturn = nsIFilePicker::returnOK;
683
        mFiles.Clear();
684
        if( mMode != nsIFilePicker::modeGetFolder )
685
            {
686
            mSelectedType = atoi( output[ 0 ].get());
687
            output.RemoveElementAt( 0 );
688
            }
689
        if (mMode == nsIFilePicker::modeOpenMultiple)
690
            {
691
            mFileURL.Truncate();
692
            PRUint32 count = output.Length();
693
            for( PRUint32 i = 0;
694
                 i < count;
695
                 ++i )
696
                {
697
                nsCOMPtr<nsILocalFile> localfile;
698
                nsresult rv = NS_NewNativeLocalFile( output[ i ],
699
                                      PR_FALSE,
700
                                      getter_AddRefs(localfile));
701
                if (NS_SUCCEEDED(rv))
702
                    mFiles.AppendObject(localfile);
703
                }
704
            }
705
        else
706
            {
707
            if( output.Length() == 0 )
708
                mFileURL = nsCString();
709
            else if( mAllowURLs )
710
                mFileURL = output[ 0 ];
711
            else // GetFile() actually requires it to be url even for local files :-/
712
                {
713
                mFileURL = nsCString( "file://" );
714
                mFileURL.Append( output[ 0 ] );
715
                }
716
            }
717
  // Remember last used directory.
718
  nsCOMPtr<nsILocalFile> file;
719
  GetFile(getter_AddRefs(file));
720
  if (file) {
721
    nsCOMPtr<nsIFile> dir;
722
    file->GetParent(getter_AddRefs(dir));
723
    nsCOMPtr<nsILocalFile> localDir(do_QueryInterface(dir));
724
    if (localDir) {
725
      localDir.swap(mPrevDisplayDirectory);
726
    }
727
  }
728
        if (mMode == nsIFilePicker::modeSave)
729
            {
730
            nsCOMPtr<nsILocalFile> file;
731
            GetFile(getter_AddRefs(file));
732
            if (file)
733
                {
734
                bool exists = false;
735
                file->Exists(&exists);
736
                if (exists) // TODO do overwrite check in the helper app
737
                    *aReturn = nsIFilePicker::returnReplace;
738
                }
739
            }
740
        }
741
    else
742
        {
743
        *aReturn = nsIFilePicker::returnCancel;
744
        }
745
    return NS_OK;
746
    }
747
748
749
NS_IMETHODIMP nsFilePicker::kdeAppsDialog(PRInt16 *aReturn)
750
    {
751
    NS_ENSURE_ARG_POINTER(aReturn);
752
753
    nsXPIDLCString title;
754
    title.Adopt(ToNewUTF8String(mTitle));
755
756
    nsTArray<nsCString> command;
757
    command.AppendElement( NS_LITERAL_CSTRING( "APPSDIALOG" ));
758
    command.AppendElement( title );
759
    if( PRInt32 xid = windowToXid( mParentWidget ))
760
        {
761
        command.AppendElement( NS_LITERAL_CSTRING( "PARENT" ));
762
        nsCAutoString parent;
763
        parent.AppendInt( xid );
764
        command.AppendElement( parent );
765
        }
766
767
    nsTArray<nsCString> output;
768
    if( nsKDEUtils::commandBlockUi( command, get_gtk_window_for_nsiwidget( mParentWidget ), &output ))
769
        {
770
        *aReturn = nsIFilePicker::returnOK;
771
        mFileURL = output.Length() > 0 ? output[ 0 ] : nsCString();
772
        }
773
    else
774
        {
775
        *aReturn = nsIFilePicker::returnCancel;
776
        }
777
    return NS_OK;
778
    }
(-)a/widget/gtk2/nsFilePicker.h (+6 lines)
Lines 89-99 protected: Link Here
89
  nsString  mDefault;
89
  nsString  mDefault;
90
  nsString  mDefaultExtension;
90
  nsString  mDefaultExtension;
91
91
92
  nsTArray<nsCString> mFilters;
92
  nsTArray<nsCString> mFilters;
93
  nsTArray<nsCString> mFilterNames;
93
  nsTArray<nsCString> mFilterNames;
94
94
95
private:
95
private:
96
  static nsILocalFile *mPrevDisplayDirectory;
96
  static nsILocalFile *mPrevDisplayDirectory;
97
98
  bool kdeRunning();
99
  bool getKdeRunning();
100
  NS_IMETHODIMP kdeFileDialog(PRInt16 *aReturn);
101
  NS_IMETHODIMP kdeAppsDialog(PRInt16 *aReturn);
102
  nsCString kdeMakeFilter( int index );
97
};
103
};
98
104
99
#endif
105
#endif
(-)a/xpcom/components/Makefile.in (+1 lines)
Lines 91-100 LOCAL_INCLUDES = \ Link Here
91
# we don't want the shared lib, but we want to force the creation of a static lib.
91
# we don't want the shared lib, but we want to force the creation of a static lib.
92
FORCE_STATIC_LIB = 1
92
FORCE_STATIC_LIB = 1
93
93
94
include $(topsrcdir)/config/rules.mk
94
include $(topsrcdir)/config/rules.mk
95
95
96
DEFINES	+= -D_IMPL_NS_COM
96
DEFINES	+= -D_IMPL_NS_COM
97
97
98
ifneq (,$(filter gtk2,$(MOZ_WIDGET_TOOLKIT)))
98
ifneq (,$(filter gtk2,$(MOZ_WIDGET_TOOLKIT)))
99
LOCAL_INCLUDES += -I$(topsrcdir)/toolkit/xre
99
CXXFLAGS += $(MOZ_GTK2_CFLAGS)
100
CXXFLAGS += $(MOZ_GTK2_CFLAGS)
100
endif
101
endif
(-)a/xpcom/components/ManifestParser.cpp (+10 lines)
Lines 63-78 Link Here
63
#include "nsTextFormatter.h"
63
#include "nsTextFormatter.h"
64
#include "nsVersionComparator.h"
64
#include "nsVersionComparator.h"
65
#include "nsXPCOMCIDInternal.h"
65
#include "nsXPCOMCIDInternal.h"
66
66
67
#include "nsIConsoleService.h"
67
#include "nsIConsoleService.h"
68
#include "nsIScriptError.h"
68
#include "nsIScriptError.h"
69
#include "nsIXULAppInfo.h"
69
#include "nsIXULAppInfo.h"
70
#include "nsIXULRuntime.h"
70
#include "nsIXULRuntime.h"
71
#include "nsKDEUtils.h"
71
72
72
using namespace mozilla;
73
using namespace mozilla;
73
74
74
struct ManifestDirective
75
struct ManifestDirective
75
{
76
{
76
  const char* directive;
77
  const char* directive;
77
  int argc;
78
  int argc;
78
79
Lines 430-445 ParseManifest(NSLocationType type, FileL Link Here
430
  NS_NAMED_LITERAL_STRING(kPlatform, "platform");
431
  NS_NAMED_LITERAL_STRING(kPlatform, "platform");
431
  NS_NAMED_LITERAL_STRING(kContentAccessible, "contentaccessible");
432
  NS_NAMED_LITERAL_STRING(kContentAccessible, "contentaccessible");
432
  NS_NAMED_LITERAL_STRING(kApplication, "application");
433
  NS_NAMED_LITERAL_STRING(kApplication, "application");
433
  NS_NAMED_LITERAL_STRING(kAppVersion, "appversion");
434
  NS_NAMED_LITERAL_STRING(kAppVersion, "appversion");
434
  NS_NAMED_LITERAL_STRING(kGeckoVersion, "platformversion");
435
  NS_NAMED_LITERAL_STRING(kGeckoVersion, "platformversion");
435
  NS_NAMED_LITERAL_STRING(kOs, "os");
436
  NS_NAMED_LITERAL_STRING(kOs, "os");
436
  NS_NAMED_LITERAL_STRING(kOsVersion, "osversion");
437
  NS_NAMED_LITERAL_STRING(kOsVersion, "osversion");
437
  NS_NAMED_LITERAL_STRING(kABI, "abi");
438
  NS_NAMED_LITERAL_STRING(kABI, "abi");
439
  NS_NAMED_LITERAL_STRING(kDesktop, "desktop");
438
#if defined(MOZ_WIDGET_ANDROID)
440
#if defined(MOZ_WIDGET_ANDROID)
439
  NS_NAMED_LITERAL_STRING(kTablet, "tablet");
441
  NS_NAMED_LITERAL_STRING(kTablet, "tablet");
440
#endif
442
#endif
441
443
442
  // Obsolete
444
  // Obsolete
443
  NS_NAMED_LITERAL_STRING(kXPCNativeWrappers, "xpcnativewrappers");
445
  NS_NAMED_LITERAL_STRING(kXPCNativeWrappers, "xpcnativewrappers");
444
446
445
  nsAutoString appID;
447
  nsAutoString appID;
Lines 477-517 ParseManifest(NSLocationType type, FileL Link Here
477
        CopyUTF8toUTF16(s, abi);
479
        CopyUTF8toUTF16(s, abi);
478
        abi.Insert(PRUnichar('_'), 0);
480
        abi.Insert(PRUnichar('_'), 0);
479
        abi.Insert(osTarget, 0);
481
        abi.Insert(osTarget, 0);
480
      }
482
      }
481
    }
483
    }
482
  }
484
  }
483
485
484
  nsAutoString osVersion;
486
  nsAutoString osVersion;
487
  nsAutoString desktop;
485
#if defined(XP_WIN)
488
#if defined(XP_WIN)
486
  OSVERSIONINFO info = { sizeof(OSVERSIONINFO) };
489
  OSVERSIONINFO info = { sizeof(OSVERSIONINFO) };
487
  if (GetVersionEx(&info)) {
490
  if (GetVersionEx(&info)) {
488
    nsTextFormatter::ssprintf(osVersion, NS_LITERAL_STRING("%ld.%ld").get(),
491
    nsTextFormatter::ssprintf(osVersion, NS_LITERAL_STRING("%ld.%ld").get(),
489
                                         info.dwMajorVersion,
492
                                         info.dwMajorVersion,
490
                                         info.dwMinorVersion);
493
                                         info.dwMinorVersion);
491
  }
494
  }
495
  desktop = NS_LITERAL_STRING("win");
492
#elif defined(MOZ_WIDGET_COCOA)
496
#elif defined(MOZ_WIDGET_COCOA)
493
  SInt32 majorVersion, minorVersion;
497
  SInt32 majorVersion, minorVersion;
494
  if ((Gestalt(gestaltSystemVersionMajor, &majorVersion) == noErr) &&
498
  if ((Gestalt(gestaltSystemVersionMajor, &majorVersion) == noErr) &&
495
      (Gestalt(gestaltSystemVersionMinor, &minorVersion) == noErr)) {
499
      (Gestalt(gestaltSystemVersionMinor, &minorVersion) == noErr)) {
496
    nsTextFormatter::ssprintf(osVersion, NS_LITERAL_STRING("%ld.%ld").get(),
500
    nsTextFormatter::ssprintf(osVersion, NS_LITERAL_STRING("%ld.%ld").get(),
497
                                         majorVersion,
501
                                         majorVersion,
498
                                         minorVersion);
502
                                         minorVersion);
499
  }
503
  }
504
  desktop = NS_LITERAL_STRING("macosx");
500
#elif defined(MOZ_WIDGET_GTK2)
505
#elif defined(MOZ_WIDGET_GTK2)
501
  nsTextFormatter::ssprintf(osVersion, NS_LITERAL_STRING("%ld.%ld").get(),
506
  nsTextFormatter::ssprintf(osVersion, NS_LITERAL_STRING("%ld.%ld").get(),
502
                                       gtk_major_version,
507
                                       gtk_major_version,
503
                                       gtk_minor_version);
508
                                       gtk_minor_version);
509
  desktop = nsKDEUtils::kdeSession() ? NS_LITERAL_STRING("kde") : NS_LITERAL_STRING("gnome");
504
#elif defined(MOZ_WIDGET_ANDROID)
510
#elif defined(MOZ_WIDGET_ANDROID)
505
  bool isTablet = false;
511
  bool isTablet = false;
506
  if (mozilla::AndroidBridge::Bridge()) {
512
  if (mozilla::AndroidBridge::Bridge()) {
507
    mozilla::AndroidBridge::Bridge()->GetStaticStringField("android/os/Build$VERSION", "RELEASE", osVersion);
513
    mozilla::AndroidBridge::Bridge()->GetStaticStringField("android/os/Build$VERSION", "RELEASE", osVersion);
508
    isTablet = mozilla::AndroidBridge::Bridge()->IsTablet();
514
    isTablet = mozilla::AndroidBridge::Bridge()->IsTablet();
509
  }
515
  }
516
  desktop = NS_LITERAL_STRING("android");
510
#endif
517
#endif
511
518
512
  // Because contracts must be registered after CIDs, we save and process them
519
  // Because contracts must be registered after CIDs, we save and process them
513
  // at the end.
520
  // at the end.
514
  nsTArray<CachedDirective> contracts;
521
  nsTArray<CachedDirective> contracts;
515
522
516
  char *token;
523
  char *token;
517
  char *newline = buf;
524
  char *newline = buf;
Lines 593-616 ParseManifest(NSLocationType type, FileL Link Here
593
    TriState stOsVersion = eUnspecified;
600
    TriState stOsVersion = eUnspecified;
594
    TriState stOs = eUnspecified;
601
    TriState stOs = eUnspecified;
595
    TriState stABI = eUnspecified;
602
    TriState stABI = eUnspecified;
596
#if defined(MOZ_WIDGET_ANDROID)
603
#if defined(MOZ_WIDGET_ANDROID)
597
    TriState stTablet = eUnspecified;
604
    TriState stTablet = eUnspecified;
598
#endif
605
#endif
599
    bool platform = false;
606
    bool platform = false;
600
    bool contentAccessible = false;
607
    bool contentAccessible = false;
608
    TriState stDesktop = eUnspecified;
601
609
602
    while (NULL != (token = nsCRT::strtok(whitespace, kWhitespace, &whitespace)) && ok) {
610
    while (NULL != (token = nsCRT::strtok(whitespace, kWhitespace, &whitespace)) && ok) {
603
      ToLowerCase(token);
611
      ToLowerCase(token);
604
      NS_ConvertASCIItoUTF16 wtoken(token);
612
      NS_ConvertASCIItoUTF16 wtoken(token);
605
613
606
      if (CheckStringFlag(kApplication, wtoken, appID, stApp) ||
614
      if (CheckStringFlag(kApplication, wtoken, appID, stApp) ||
607
          CheckStringFlag(kOs, wtoken, osTarget, stOs) ||
615
          CheckStringFlag(kOs, wtoken, osTarget, stOs) ||
608
          CheckStringFlag(kABI, wtoken, abi, stABI) ||
616
          CheckStringFlag(kABI, wtoken, abi, stABI) ||
617
          CheckStringFlag(kDesktop, wtoken, desktop, stDesktop) ||
609
          CheckVersionFlag(kOsVersion, wtoken, osVersion, stOsVersion) ||
618
          CheckVersionFlag(kOsVersion, wtoken, osVersion, stOsVersion) ||
610
          CheckVersionFlag(kAppVersion, wtoken, appVersion, stAppVersion) ||
619
          CheckVersionFlag(kAppVersion, wtoken, appVersion, stAppVersion) ||
611
          CheckVersionFlag(kGeckoVersion, wtoken, geckoVersion, stGeckoVersion))
620
          CheckVersionFlag(kGeckoVersion, wtoken, geckoVersion, stGeckoVersion))
612
        continue;
621
        continue;
613
622
614
#if defined(MOZ_WIDGET_ANDROID)
623
#if defined(MOZ_WIDGET_ANDROID)
615
      bool tablet = false;
624
      bool tablet = false;
616
      if (CheckFlag(kTablet, wtoken, tablet)) {
625
      if (CheckFlag(kTablet, wtoken, tablet)) {
Lines 639-654 ParseManifest(NSLocationType type, FileL Link Here
639
    }
648
    }
640
649
641
    if (!ok ||
650
    if (!ok ||
642
        stApp == eBad ||
651
        stApp == eBad ||
643
        stAppVersion == eBad ||
652
        stAppVersion == eBad ||
644
        stGeckoVersion == eBad ||
653
        stGeckoVersion == eBad ||
645
        stOs == eBad ||
654
        stOs == eBad ||
646
        stOsVersion == eBad ||
655
        stOsVersion == eBad ||
656
        stDesktop == eBad ||
647
#ifdef MOZ_WIDGET_ANDROID
657
#ifdef MOZ_WIDGET_ANDROID
648
        stTablet == eBad ||
658
        stTablet == eBad ||
649
#endif
659
#endif
650
        stABI == eBad)
660
        stABI == eBad)
651
      continue;
661
      continue;
652
662
653
    if (directive->regfunc) {
663
    if (directive->regfunc) {
654
      if (GeckoProcessType_Default != XRE_GetProcessType())
664
      if (GeckoProcessType_Default != XRE_GetProcessType())
(-)a/xpcom/io/Makefile.in (-1 / +1 lines)
Lines 189-205 include $(topsrcdir)/ipc/chromium/chromi Link Here
189
DEFINES		+= -D_IMPL_NS_COM
189
DEFINES		+= -D_IMPL_NS_COM
190
190
191
ifeq ($(OS_ARCH),Linux)
191
ifeq ($(OS_ARCH),Linux)
192
ifneq (,$(findstring lib64,$(libdir)))
192
ifneq (,$(findstring lib64,$(libdir)))
193
DEFINES     += -DHAVE_USR_LIB64_DIR
193
DEFINES     += -DHAVE_USR_LIB64_DIR
194
endif
194
endif
195
endif
195
endif
196
196
197
LOCAL_INCLUDES	+= -I..
197
LOCAL_INCLUDES	+= -I.. -I$(topsrcdir)/toolkit/xre
198
198
199
ifeq ($(MOZ_PLATFORM_MAEMO),5)
199
ifeq ($(MOZ_PLATFORM_MAEMO),5)
200
CFLAGS          += $(MOZ_DBUS_CFLAGS)
200
CFLAGS          += $(MOZ_DBUS_CFLAGS)
201
CXXFLAGS        += $(MOZ_DBUS_CFLAGS)
201
CXXFLAGS        += $(MOZ_DBUS_CFLAGS)
202
endif
202
endif
203
203
204
ifdef MOZ_PLATFORM_MAEMO
204
ifdef MOZ_PLATFORM_MAEMO
205
CFLAGS          += $(MOZ_PLATFORM_MAEMO_CFLAGS) $(MOZ_QT_CFLAGS)
205
CFLAGS          += $(MOZ_PLATFORM_MAEMO_CFLAGS) $(MOZ_QT_CFLAGS)
(-)a/xpcom/io/nsLocalFileUnix.cpp (-14 / +29 lines)
Lines 90-105 Link Here
90
#include "prproces.h"
90
#include "prproces.h"
91
#include "nsIDirectoryEnumerator.h"
91
#include "nsIDirectoryEnumerator.h"
92
#include "nsISimpleEnumerator.h"
92
#include "nsISimpleEnumerator.h"
93
#include "private/pprio.h"
93
#include "private/pprio.h"
94
94
95
#ifdef MOZ_WIDGET_GTK2
95
#ifdef MOZ_WIDGET_GTK2
96
#include "nsIGIOService.h"
96
#include "nsIGIOService.h"
97
#include "nsIGnomeVFSService.h"
97
#include "nsIGnomeVFSService.h"
98
#include "nsKDEUtils.h"
98
#endif
99
#endif
99
100
100
#ifdef MOZ_WIDGET_COCOA
101
#ifdef MOZ_WIDGET_COCOA
101
#include <Carbon/Carbon.h>
102
#include <Carbon/Carbon.h>
102
#include "CocoaFileUtils.h"
103
#include "CocoaFileUtils.h"
103
#include "prmem.h"
104
#include "prmem.h"
104
#include "plbase64.h"
105
#include "plbase64.h"
105
106
Lines 1798-1841 nsLocalFile::SetPersistentDescriptor(con Link Here
1798
    return InitWithNativePath(aPersistentDescriptor);
1799
    return InitWithNativePath(aPersistentDescriptor);
1799
#endif
1800
#endif
1800
}
1801
}
1801
1802
1802
NS_IMETHODIMP
1803
NS_IMETHODIMP
1803
nsLocalFile::Reveal()
1804
nsLocalFile::Reveal()
1804
{
1805
{
1805
#ifdef MOZ_WIDGET_GTK2
1806
#ifdef MOZ_WIDGET_GTK2
1806
    nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
1807
    nsCAutoString url;
1807
    nsCOMPtr<nsIGnomeVFSService> gnomevfs = do_GetService(NS_GNOMEVFSSERVICE_CONTRACTID);
1808
    if (!giovfs && !gnomevfs)
1809
        return NS_ERROR_FAILURE;
1810
1811
    bool isDirectory;
1808
    bool isDirectory;
1812
    if (NS_FAILED(IsDirectory(&isDirectory)))
1809
    if (NS_FAILED(IsDirectory(&isDirectory)))
1813
        return NS_ERROR_FAILURE;
1810
        return NS_ERROR_FAILURE;
1814
1811
1815
    if (isDirectory) {
1812
    if (isDirectory) {
1816
        if (giovfs)
1813
        url = mPath;
1817
            return giovfs->ShowURIForInput(mPath);
1818
        else 
1819
            /* Fallback to GnomeVFS */
1820
            return gnomevfs->ShowURIForInput(mPath);
1821
    } else {
1814
    } else {
1822
        nsCOMPtr<nsIFile> parentDir;
1815
        nsCOMPtr<nsIFile> parentDir;
1823
        nsCAutoString dirPath;
1816
        nsCAutoString dirPath;
1824
        if (NS_FAILED(GetParent(getter_AddRefs(parentDir))))
1817
        if (NS_FAILED(GetParent(getter_AddRefs(parentDir))))
1825
            return NS_ERROR_FAILURE;
1818
            return NS_ERROR_FAILURE;
1826
        if (NS_FAILED(parentDir->GetNativePath(dirPath)))
1819
        if (NS_FAILED(parentDir->GetNativePath(dirPath)))
1827
            return NS_ERROR_FAILURE;
1820
            return NS_ERROR_FAILURE;
1828
1821
1829
        if (giovfs)
1822
        url = dirPath;
1830
            return giovfs->ShowURIForInput(dirPath);
1831
        else 
1832
            return gnomevfs->ShowURIForInput(dirPath);        
1833
    }
1823
    }
1824
1825
    if(nsKDEUtils::kdeSupport()) {
1826
      nsTArray<nsCString> command;
1827
      command.AppendElement( NS_LITERAL_CSTRING("REVEAL") );
1828
      command.AppendElement( mPath );
1829
      return nsKDEUtils::command( command ) ? NS_OK : NS_ERROR_FAILURE;
1830
    }
1831
1832
    nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
1833
    nsCOMPtr<nsIGnomeVFSService> gnomevfs = do_GetService(NS_GNOMEVFSSERVICE_CONTRACTID);
1834
    if (!giovfs && !gnomevfs)
1835
      return NS_ERROR_FAILURE;
1836
1837
    if (giovfs)
1838
      return giovfs->ShowURIForInput(url);
1839
    else
1840
      return gnomevfs->ShowURIForInput(url);
1841
1834
#elif defined(MOZ_WIDGET_COCOA)
1842
#elif defined(MOZ_WIDGET_COCOA)
1835
    CFURLRef url;
1843
    CFURLRef url;
1836
    if (NS_SUCCEEDED(GetCFURL(&url))) {
1844
    if (NS_SUCCEEDED(GetCFURL(&url))) {
1837
      nsresult rv = CocoaFileUtils::RevealFileInFinder(url);
1845
      nsresult rv = CocoaFileUtils::RevealFileInFinder(url);
1838
      ::CFRelease(url);
1846
      ::CFRelease(url);
1839
      return rv;
1847
      return rv;
1840
    }
1848
    }
1841
    return NS_ERROR_FAILURE;
1849
    return NS_ERROR_FAILURE;
Lines 1861-1876 nsLocalFile::Launch() Link Here
1861
1869
1862
    if (nsnull == connection)
1870
    if (nsnull == connection)
1863
      return NS_ERROR_FAILURE;
1871
      return NS_ERROR_FAILURE;
1864
1872
1865
    if (hildon_mime_open_file(connection, mPath.get()) != kHILDON_SUCCESS)
1873
    if (hildon_mime_open_file(connection, mPath.get()) != kHILDON_SUCCESS)
1866
      return NS_ERROR_FAILURE;
1874
      return NS_ERROR_FAILURE;
1867
    return NS_OK;
1875
    return NS_OK;
1868
#else
1876
#else
1877
    if( nsKDEUtils::kdeSupport()) {
1878
      nsTArray<nsCString> command;
1879
      command.AppendElement( NS_LITERAL_CSTRING("OPEN") );
1880
      command.AppendElement( mPath );
1881
      return nsKDEUtils::command( command ) ? NS_OK : NS_ERROR_FAILURE;
1882
    }
1883
1869
    nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
1884
    nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID);
1870
    nsCOMPtr<nsIGnomeVFSService> gnomevfs = do_GetService(NS_GNOMEVFSSERVICE_CONTRACTID);
1885
    nsCOMPtr<nsIGnomeVFSService> gnomevfs = do_GetService(NS_GNOMEVFSSERVICE_CONTRACTID);
1871
    if (giovfs) {
1886
    if (giovfs) {
1872
      return giovfs->ShowURIForInput(mPath);
1887
      return giovfs->ShowURIForInput(mPath);
1873
    } else if (gnomevfs) {
1888
    } else if (gnomevfs) {
1874
      /* GnomeVFS fallback */
1889
      /* GnomeVFS fallback */
1875
      return gnomevfs->ShowURIForInput(mPath);
1890
      return gnomevfs->ShowURIForInput(mPath);
1876
    }
1891
    }

Return to bug 777415