~ubuntu-branches/ubuntu/natty/miro/natty

« back to all changes in this revision

Viewing changes to windows/plat/frontends/widgets/XULRunnerBrowser/Init.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2011-01-22 02:46:33 UTC
  • mfrom: (1.4.10 upstream) (1.7.5 experimental)
  • Revision ID: james.westby@ubuntu.com-20110122024633-kjme8u93y2il5nmf
Tags: 3.5.1-1ubuntu1
* Merge from debian.  Remaining ubuntu changes:
  - Use python 2.7 instead of python 2.6
  - Relax dependency on python-dbus to >= 0.83.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Miro - an RSS based video player application
 
3
 * Copyright (C) 2005-2010 Participatory Culture Foundation
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 
18
 *
 
19
 * In addition, as a special exception, the copyright holders give
 
20
 * permission to link the code of portions of this program with the OpenSSL
 
21
 * library.
 
22
 *
 
23
 * You must obey the GNU General Public License in all respects for all of
 
24
 * the code used other than OpenSSL. If you modify file(s) with this
 
25
 * exception, you may extend this exception to your version of the file(s),
 
26
 * but you are not obligated to do so. If you do not wish to do so, delete
 
27
 * this exception statement from your version. If you delete this exception
 
28
 * statement from all source files in the program, then also delete it here.
 
29
**/
 
30
 
 
31
/*
 
32
 * Init.cpp
 
33
 *
 
34
 * Initialize and Shutdown XPCom
 
35
 */
 
36
 
 
37
#include <stdlib.h>
 
38
 
 
39
#include "nsCOMPtr.h"
 
40
#include "nsEmbedString.h"
 
41
#include "nsILocalFile.h"
 
42
#include "nsXPCOMGlue.h" 
 
43
#include "pref/nsIPref.h"
 
44
#include "xulapp/nsXULAppAPI.h"
 
45
#include "xpcom/nsServiceManagerUtils.h"
 
46
 
 
47
#include "Init.h"
 
48
 
 
49
XRE_InitEmbeddingType XRE_InitEmbedding;
 
50
XRE_TermEmbeddingType XRE_TermEmbedding; 
 
51
 
 
52
nsresult init_xulrunner(const char* xul_dir, const char* app_dir)
 
53
{
 
54
    nsresult rv;
 
55
 
 
56
    char xpcom_dll[_MAX_PATH ];
 
57
    if(strlen(xul_dir) >= _MAX_PATH) {
 
58
        return NS_ERROR_FAILURE;
 
59
    }
 
60
    strcpy(xpcom_dll, xul_dir);
 
61
    strncat(xpcom_dll, "\\xpcom.dll", _MAX_PATH - strlen(xpcom_dll));
 
62
 
 
63
    rv = XPCOMGlueStartup(xpcom_dll);
 
64
    if (NS_FAILED(rv)) {
 
65
        printf("GLUE STARTUP FAILED\n");
 
66
        return rv;
 
67
    }
 
68
 
 
69
    const nsDynamicFunctionLoad dynamicSymbols[] = {
 
70
        { "XRE_InitEmbedding", (NSFuncPtr*) &XRE_InitEmbedding },
 
71
        { "XRE_TermEmbedding", (NSFuncPtr*) &XRE_TermEmbedding },
 
72
        { nsnull, nsnull }
 
73
    }; 
 
74
    XPCOMGlueLoadXULFunctions(dynamicSymbols);
 
75
 
 
76
    nsCOMPtr<nsILocalFile> xul_dir_file;
 
77
    rv = NS_NewNativeLocalFile(nsEmbedCString(xul_dir), PR_FALSE,
 
78
            getter_AddRefs(xul_dir_file));
 
79
    NS_ENSURE_SUCCESS(rv, rv);
 
80
 
 
81
    nsCOMPtr<nsILocalFile> app_dir_file;
 
82
    rv = NS_NewNativeLocalFile(nsEmbedCString(app_dir), PR_FALSE,
 
83
                getter_AddRefs(app_dir_file));
 
84
    NS_ENSURE_SUCCESS(rv, rv);
 
85
 
 
86
    rv = XRE_InitEmbedding(xul_dir_file, app_dir_file, 0, 0, 0);
 
87
    NS_ENSURE_SUCCESS(rv, rv);
 
88
    return NS_OK;
 
89
}
 
90
 
 
91
 
 
92
nsresult setup_user_agent(const char* vendor, const char* vendor_sub, 
 
93
        const char* comment)
 
94
{
 
95
    nsresult rv;
 
96
    nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID, &rv));
 
97
    NS_ENSURE_SUCCESS(rv, rv);
 
98
    rv = prefs->SetCharPref("general.useragent.vendor", vendor);
 
99
    NS_ENSURE_SUCCESS(rv, rv);
 
100
    rv = prefs->SetCharPref("general.useragent.vendorSub", vendor_sub);
 
101
    NS_ENSURE_SUCCESS(rv, rv);
 
102
    rv = prefs->SetCharPref("general.useragent.vendorComment", comment);
 
103
    NS_ENSURE_SUCCESS(rv, rv);
 
104
    return NS_OK;
 
105
}
 
106
 
 
107
void shutdown_xulrunner()
 
108
{
 
109
    XRE_TermEmbedding();
 
110
    XPCOMGlueShutdown();
 
111
}