~ubuntu-branches/ubuntu/lucid/gecko-mediaplayer/lucid

« back to all changes in this revision

Viewing changes to src/plugin.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cesare Tirabassi
  • Date: 2009-09-24 13:55:35 UTC
  • mfrom: (1.1.14 upstream) (0.1.10 sid)
  • Revision ID: james.westby@ubuntu.com-20090924135535-ftwq9l1ntkt9tdfp
Tags: 0.9.8-1ubuntu1
* Merge from debian unstable (LP: #434106), remaining changes:
  - change Build-Depends iceape-dev to libxul-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
#include "plugin_setup.h"
43
43
#include "plugin_types.h"
44
44
#include "plugin_dbus.h"
 
45
#include "nsIPrefBranch.h"
 
46
#include "nsIPrefService.h"
 
47
#include "nsIServiceManager.h"
45
48
 
 
49
nsIPrefBranch *prefBranch = NULL;
 
50
nsIPrefService *prefService = NULL;
46
51
static NPObject *sWindowObj;
47
52
 
48
53
//#include "nsIServiceManager.h"
172
177
    g_free(jscript);
173
178
}
174
179
 
 
180
void setPreference(CPlugin * instance, const gchar * name, const gchar * value)
 
181
{
 
182
    nsIServiceManager *sm = NULL;
 
183
    NPN_GetValue(NULL, NPNVserviceManager, &sm);
 
184
    PRBool v;
 
185
 
 
186
    if (sm) {
 
187
 
 
188
        sm->GetServiceByContractID("@mozilla.org/preferences-service;1", NS_GET_IID(nsIPrefService), (void **)&prefService);
 
189
        if (prefService) {
 
190
            prefService->GetBranch("", &prefBranch);
 
191
            if (prefBranch) {
 
192
                instance->user_agent = g_new0(gchar, 1024);
 
193
                prefBranch->PrefHasUserValue(name,&v);
 
194
                if (v)
 
195
                    prefBranch->GetCharPref(name, &(instance->user_agent));
 
196
                prefBranch->SetCharPref(name, value);
 
197
            }
 
198
        }
 
199
        NS_RELEASE(sm);
 
200
    }
 
201
 
 
202
}
 
203
 
 
204
void clearPreference(CPlugin * instance, const gchar * name)
 
205
{
 
206
    nsIServiceManager *sm = NULL;
 
207
    NPN_GetValue(NULL, NPNVserviceManager, &sm);
 
208
 
 
209
    if (sm) {
 
210
 
 
211
        sm->GetServiceByContractID("@mozilla.org/preferences-service;1", NS_GET_IID(nsIPrefService), (void **)&prefService);
 
212
        if (prefService) {
 
213
            prefService->GetBranch("", &prefBranch);
 
214
            if (prefBranch) {
 
215
                if (instance->user_agent == NULL || strlen(instance->user_agent) == 0) {
 
216
                    prefBranch->ClearUserPref(name);
 
217
                } else {
 
218
                    if (g_strrstr(instance->user_agent,"QuickTime/7.6.2")) {
 
219
                        prefBranch->ClearUserPref(name);
 
220
                    } else {
 
221
                        prefBranch->SetCharPref(name, instance->user_agent);
 
222
                    }
 
223
                }
 
224
                g_free(instance->user_agent);
 
225
            }
 
226
        }
 
227
        NS_RELEASE(sm);
 
228
    }
 
229
}
 
230
 
175
231
////////////////////////////////////////
176
232
//
177
233
// CPlugin class implementation
202
258
id(NULL),
203
259
console(NULL),
204
260
controls(NULL),
 
261
user_agent(NULL),
205
262
disable_context_menu(FALSE),
206
263
disable_fullscreen(FALSE),
207
264
post_dom_events(FALSE),
214
271
{
215
272
    GRand *rand;
216
273
    GmPrefStore *store;
217
 
    gchar *jscript;
218
274
 
219
275
    NPN_GetValue(mInstance, NPNVWindowNPObject, &sWindowObj);
220
276
 
305
361
    if (connection == NULL) {
306
362
        connection = dbus_hookup(this);
307
363
    }
308
 
 
 
364
    pluginSpecific(this);
 
365
    
309
366
    mInitialized = TRUE;
310
367
}
311
368
 
331
388
        NS_IF_RELEASE(mControlsScriptablePeer);
332
389
    }
333
390
*/
 
391
    clearPreference(this, "general.useragent.override");
 
392
 
334
393
    if (m_pScriptableObjectControls) {
335
394
        NPN_ReleaseObject(m_pScriptableObjectControls);
336
395
    }
555
614
            ready = item->playerready;
556
615
            newwindow = item->newwindow;
557
616
            playlist = list_parse_qt(playlist, item);
 
617
            playlist = list_parse_qt2(playlist, item);
558
618
            playlist = list_parse_asx(playlist, item);
559
619
            playlist = list_parse_qml(playlist, item);
560
620
            playlist = list_parse_ram(playlist, item);
609
669
void CPlugin::URLNotify(const char *url, NPReason reason, void *notifyData)
610
670
{
611
671
    ListItem *item = (ListItem *) notifyData;
612
 
    DBusMessage *message;
613
 
    const char *file;
 
672
    //DBusMessage *message;
 
673
    //const char *file;
614
674
 
615
675
    printf("URL Notify %s\n,%i = %i\n%s\n%s\n%s\n", url, reason, NPRES_DONE, item->src, item->local,
616
676
           path);
631
691
               dbus_message_unref(message);
632
692
             */
633
693
        }
 
694
    } else {
 
695
        if (item)
 
696
            item->played = TRUE;
 
697
        if (!item->streaming) {
 
698
            item = list_find_next_playable(playlist);
 
699
            if (item) {
 
700
                if (item->retrieved) {
 
701
                    open_location(this, item, TRUE);
 
702
                } else {
 
703
                    NPN_GetURLNotify(mInstance, item->src, NULL, item);
 
704
                }
 
705
            }
 
706
        }
634
707
    }
635
708
}
636
709
 
741
814
    if (item->cancelled || item->retrieved)
742
815
        NPN_DestroyStream(mInstance, stream, NPRES_USER_BREAK);
743
816
 
744
 
    if (strstr((char *) buffer, "ICY 200 OK") != NULL || item->streaming == TRUE) {
745
 
        item->streaming = TRUE;
746
 
        open_location(this, item, FALSE);
747
 
        item->requested = TRUE;
748
 
        if (item->localfp) {
749
 
            fclose(item->localfp);
750
 
        }
751
 
        NPN_DestroyStream(mInstance, stream, NPRES_DONE);
752
 
        return -1;
753
 
    }
754
 
    // If item is a block of jpeg images, just stream it
755
 
    if (strstr((char *) buffer, "Content-length:") != NULL || item->streaming == TRUE) {
756
 
        item->streaming = TRUE;
757
 
        open_location(this, item, FALSE);
758
 
        if (post_dom_events && this->id != NULL) {
759
 
            postDOMEvent(mInstance, this->id, "qt_play");
760
 
        }
761
 
        item->requested = TRUE;
762
 
        if (item->localfp) {
763
 
            fclose(item->localfp);
764
 
        }
765
 
        NPN_DestroyStream(mInstance, stream, NPRES_DONE);
766
 
        return -1;
767
 
    }
768
 
 
769
 
    if (strstr((char *) buffer, "<HTML>") != NULL || item->streaming == TRUE) {
770
 
        item->streaming = TRUE;
771
 
        open_location(this, item, FALSE);
772
 
        if (post_dom_events && this->id != NULL) {
773
 
            postDOMEvent(mInstance, this->id, "qt_play");
774
 
        }
775
 
        item->requested = TRUE;
776
 
        if (item->localfp) {
777
 
            fclose(item->localfp);
778
 
        }
779
 
        NPN_DestroyStream(mInstance, stream, NPRES_DONE);
 
817
    if (strstr((char *) buffer, "ICY 200 OK") != NULL 
 
818
        || strstr((char *) buffer, "Content-length:") != NULL // If item is a block of jpeg images, just stream it
 
819
        || strstr((char *) buffer, "<HTML>") != NULL
 
820
        || item->streaming == TRUE
 
821
        || stream->lastmodified == 0) {
 
822
        item->streaming = TRUE;
 
823
        open_location(this, item, FALSE);
 
824
        if (post_dom_events && this->id != NULL) {
 
825
            postDOMEvent(mInstance, this->id, "qt_play");
 
826
        }
 
827
        item->requested = TRUE;
 
828
        if (item->localfp) {
 
829
            fclose(item->localfp);
 
830
        }
 
831
        NPN_DestroyStream(mInstance, stream, NPRES_USER_BREAK);
780
832
        return -1;
781
833
    }
782
834