github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

abock / moonshine

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 7
    • 0
  • Source
  • Commits
  • Network (0)
  • Issues (0)
  • Downloads (1)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (2)
    • live-web
    • master ✓
  • Tags (1)
    • live-web
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

An embedded media player plugin for Firefox that leverages Moonlight to provide native Windows Media support for Linux. — Read more

  cancel

http://go-mono.com/moonlight

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Fixes to work with Moonlight 2.0 
jstedfast (author)
Wed Sep 02 12:33:04 -0700 2009
Aaron Bockover (committer)
Wed Sep 02 12:53:06 -0700 2009
commit  1e6efed14d57c937005f8610e2a4fadfea37cfa4
tree    9f86e3093a035e515e3bef043f13574898fcc923
parent  b80f974aaa215a59c852209c767a914d171f9d42
moonshine / plugin / mmp-binder.c plugin/mmp-binder.c
100644 215 lines (170 sloc) 6.317 kb
edit raw blame history
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
//
// This file is licensed under the MIT X11 open source license.
// http://www.opensource.org/licenses/mit-license.php
//
// Authors: Aaron Bockover <abockover@novell.com>
//
// Copyright 2009 Novell, Inc.
//
 
#include <config.h>
 
#include <string.h>
 
#include "mmp-binder.h"
#include "mmp-script.h"
#include "mmp-resources.h"
 
#define MLMP_XAML_LOAD_FUNCTION "__MoonshineWmpPluginBindInstance"
#define MLMP_XAML_DOM_ID "__MoonshineEmptyFakeXamlTrickery"
 
typedef enum {
XAML_LOAD_ERROR = 0,
XAML_LOAD_SUCCESS = 1,
XAML_LOAD_ALREADY_LOADED = 2
} XamlLoadStatus;
 
static XamlLoadStatus
mmp_binder_load_player_xaml (MoonlightPluginInstance *plugin)
{
NPP npp = plugin->moz_instance;
NPObject *window = mmp_script_get_window (npp);
NPVariant document;
NPVariant script_element;
NPVariant xaml_node;
NPVariant body;
XamlLoadStatus xaml_loaded = XAML_LOAD_ERROR;
 
g_return_val_if_fail (npp != NULL, XAML_LOAD_ERROR);
g_return_val_if_fail (window != NULL, XAML_LOAD_ERROR);
 
// Load the document object
if (!mmp_script_get_document (npp, window, &document)) {
mp_error ("Unable to get document object via npruntime");
return XAML_LOAD_ERROR;
}
 
// Check to see if the XAML was already loaded into the DOM
if (mmp_script_document_get_element_by_id (npp, &document, MLMP_XAML_DOM_ID, &xaml_node)) {
NPN_ReleaseVariantValue (&xaml_node);
NPN_ReleaseVariantValue (&document);
return XAML_LOAD_ALREADY_LOADED;
}
 
// Create the XAML and add to the DOM (<script id='foo' type='text/xaml'>[xaml data]</script>)
if (mmp_script_document_create_element (npp, &document, "script", &script_element)) {
if (mmp_script_element_set_property_string (npp, &script_element, "id", MLMP_XAML_DOM_ID) &&
mmp_script_element_set_property_string (npp, &script_element, "type", "text/xaml") &&
mmp_script_document_create_text_node (npp, &document, "<Canvas xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"/>", &xaml_node)) {
 
if (mmp_script_element_append_child (npp, &script_element, &xaml_node)) {
if (mmp_script_element_get_property_object (npp, &document, "body", &body)) {
if (mmp_script_element_append_child (npp, &body, &script_element)) {
xaml_loaded = XAML_LOAD_SUCCESS;
}
 
NPN_ReleaseVariantValue (&body);
}
}
 
NPN_ReleaseVariantValue (&xaml_node);
}
 
NPN_ReleaseVariantValue (&script_element);
}
 
NPN_ReleaseVariantValue (&document);
return xaml_loaded;
}
 
static void
mmp_binder_bind (MoonlightPluginInstance *plugin)
{
XamlLoadStatus status;
 
status = mmp_binder_load_player_xaml (plugin);
 
if (status == XAML_LOAD_ERROR) {
mp_error ("Unable to load player XAML into the DOM");
return;
} else if (status == XAML_LOAD_SUCCESS) {
// Only load the JS once, when the XAML is actually added to the DOM
gint i = 0;
for (; MLMP_RESOURCES_ALL[i]; i++) {
mmp_script_evaluate (plugin->moz_instance, MLMP_RESOURCES_ALL[i]);
}
}
}
 
NPError mmp_binder_npp_new (NPMIMEType pluginType, NPP instance, gushort mode,
gshort argc, gchar **argn, gchar **argv, NPSavedData *saved)
{
NPError result;
gchar **param_names;
gchar **param_values;
gint param_count = 0, i;
MoonlightPluginInstance *plugin;
 
mp_debug ("NPP_New");
 
// +2 to ensure space for onload and source
param_names = g_new0 (gchar *, argc + 3);
param_values = g_new0 (gchar *, argc + 3);
 
// We only preserve and proxy id, width, and height
for (i = 0; i < argc; i++) {
if (g_ascii_strncasecmp (argn[i], "id", 2) == 0 ||
g_ascii_strncasecmp (argn[i], "width", 5) == 0 ||
g_ascii_strncasecmp (argn[i], "height", 6) == 0) {
param_names[param_count] = g_strdup (argn[i]);
param_values[param_count] = g_strdup (argv[i]);
param_count++;
}
}
 
param_names[param_count] = g_strdup ("source");
param_values[param_count++] = g_strdup ( "#" MLMP_XAML_DOM_ID );
 
param_names[param_count] = g_strdup ("onload");
param_values[param_count++] = g_strdup (MLMP_XAML_LOAD_FUNCTION);
 
param_names[param_count] = g_strdup ("moonlight-relaxed-media-mode");
param_values[param_count++] = g_strdup ("true");
 
// Create an NPP wrapper and send the NPP_New to Moonlight
plugin = mmp_plugin_new (instance);
plugin->param_names = param_names;
plugin->param_values = param_values;
 
result = MMP_HANDLE ()->moon_npp_new ("application/x-silverlight", instance, mode,
param_count, param_names, param_values, saved);
 
if (result == NPERR_NO_ERROR) {
// Everything was okay, so bind XAML and JS to the plugin instance
mmp_binder_bind (plugin);
return NPERR_NO_ERROR;
}
 
mmp_plugin_free (plugin);
 
return result;
}
 
NPError
mmp_binder_npp_destroy (NPP instance, NPSavedData **save)
{
MoonlightPluginInstance *plugin;
 
mp_debug ("NPP_Destroy");
 
plugin = mmp_plugin_find_instance (instance);
if (plugin != NULL) {
mmp_plugin_free (plugin);
}
 
return MMP_HANDLE ()->moon_npp_destroy (instance, save);
}
 
// This is the NPStream::notifyData type that Moonlight uses internally!
 
typedef enum {
STREAM_NOTIFY_NONE = 0,
STREAM_NOTIFY_SOURCE = 1,
STREAM_NOTIFY_DOWNLOADER = 2,
STREAM_NOTIFY_REQUEST = 3
} StreamNotifyFlags;
 
typedef struct {
StreamNotifyFlags type;
gpointer pdata;
} StreamNotify;
 
void
mmp_binder_npp_stream_as_file (NPP instance, NPStream *stream, const gchar *fname)
{
// Mozilla ends up calling this in some cases. It results in the file
// being loaded as XAML inside of Moonlight, which is very bad since
// it's going to be some kind of WM content.
//
// Observed cases where Mozilla does this:
//
// <embed src="..." />
// <object data="..." />
//
 
if (stream && stream->notifyData && ((StreamNotify *)stream->notifyData)->type == STREAM_NOTIFY_DOWNLOADER) {
gchar *basename = g_path_get_basename (stream->url);
 
MMP_HANDLE ()->moon_npp_stream_as_file (instance, stream, fname);
 
if (g_str_has_prefix (basename, "silverlight-media-pack") && g_str_has_suffix (basename, ".so")) {
NPObject *object = NULL;
NPVariant result;
NPIdentifier method = NPN_GetStringIdentifier ("ReloadMediaSource");
 
if (NPN_GetValue (instance, NPNVPluginElementNPObject, &object) == NPERR_NO_ERROR &&
NPN_Invoke (instance, object, method, NULL, 0, &result) == NPERR_NO_ERROR) {
mp_debug ("Silverlight Media Pack downloaded, reloading media");
}
}
 
g_free (basename);
}
}
 
 
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server