Skip to content

Commit

Permalink
ppb_url_loader: connect first URLLoader with plugin content stream
Browse files Browse the repository at this point in the history
  • Loading branch information
i-rinat committed Apr 28, 2015
1 parent 8bef6d1 commit abe3d52
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/np_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -739,10 +739,21 @@ NPP_NewStream(NPP npp, NPMIMEType type, NPStream *stream, NPBool seekable, uint1
stream->lastmodified, (unsigned)(size_t)stream->notifyData, stream->headers,
seekable);

struct pp_instance_s *pp_i = npp->pdata;

if (config.quirks.plugin_missing)
return NPERR_NO_ERROR;

int rewrite_url_in_loader = 0;
PP_Resource loader = (size_t)stream->notifyData;

if (!loader && pp_i->content_url_loader != 0 && ! pp_i->content_url_loader_used) {
// this is unrequested stream from browser, so it must be the stream we are waiting for
loader = pp_i->content_url_loader;
rewrite_url_in_loader = 1;
pp_i->content_url_loader_used = 1;
}

if (!loader) {
// ignoring unrequested streams
stream->pdata = NULL;
Expand All @@ -761,6 +772,16 @@ NPP_NewStream(NPP npp, NPMIMEType type, NPStream *stream, NPBool seekable, uint1
ul->ccb = PP_MakeCCB(NULL, NULL); // prevent callback from being called twice
ul->np_stream = stream;

if (rewrite_url_in_loader) {
free(ul->url);
ul->url = nullsafe_strdup(stream->url);

// rewriting is only performed for the stream with plugin content, so it's new URL of
// the instance
ppb_var_release(pp_i->instance_url);
pp_i->instance_url = ppb_var_var_from_utf8_z(ul->url);
}

// handling redirection
if (ph->http_code >= 300 && ph->http_code <= 307 && ul->redirect_url) {
if (ul->follow_redirects) {
Expand Down
2 changes: 2 additions & 0 deletions src/pp_resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ struct pp_instance_s {
uint32_t incognito_mode;
volatile gint instance_loaded;
uint32_t ignore_focus_events_cnt; ///< number of focus events to ignore
PP_Resource content_url_loader;
uint32_t content_url_loader_used;

Cursor prev_cursor;
int have_prev_cursor;
Expand Down
9 changes: 9 additions & 0 deletions src/ppb_url_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "tables.h"
#include "eintr_retry.h"
#include "ppb_url_request_info.h"
#include "config.h"


PP_Resource
Expand Down Expand Up @@ -322,6 +323,14 @@ ppb_url_loader_open_target(PP_Resource loader, PP_Resource request_info,
ppb_var_release(full_url);
pp_resource_release(request_info);

if (config.quirks.connect_first_loader_to_unrequested_stream) {
if (ul->instance->content_url_loader == 0) {
ul->instance->content_url_loader = loader;
pp_resource_release(loader);
return PP_OK_COMPLETIONPENDING;
}
}

struct url_loader_open_param_s *p = g_slice_alloc(sizeof(*p));
p->url = ul->url;
p->loader = loader;
Expand Down

0 comments on commit abe3d52

Please sign in to comment.