首页 \ 问答 \ Firefox Addon观察者http-on-modify-request无法正常工作(Firefox Addon observer http-on-modify-request not working properly)

Firefox Addon观察者http-on-modify-request无法正常工作(Firefox Addon observer http-on-modify-request not working properly)

我的插件中有一个奇怪的错误,插件本身需要为特定域添加一个请求头参数,它一切正常,但是错误是,观察者http-on-modify-request在启动时没有被调用,只是如果我重新加载页面,那么它正在工作。

我的意思是:

  1. 我去mysite.com/ - 没有标题修改
  2. 我重新加载页面 - 标题模式
  3. 重新加载 - 标题修改
  4. mysite.com/上的新标签 - 未修改标题
  5. 重新加载标签 - 标题已修改

我的代码,我正在使用插件sdk:

exports.main = function(options,callbacks) {

// Create observer 
httpRequestObserver =  
{  
  observe: function(subject, topic, data)  
  {  

    if (topic == "http-on-modify-request") {


    //only identify to specific preference domain
    var windowsService = Cc['@mozilla.org/appshell/window-mediator;1'].getService(Ci.nsIWindowMediator);
    var uri = windowsService.getMostRecentWindow('navigator:browser').getBrowser().currentURI;
    var domainloc = uri.host;

        if (domainloc=="mysite.com"){
            var httpChannel = subject.QueryInterface(Ci.nsIHttpChannel);  
            httpChannel.setRequestHeader("x-test", "test", false);  
        }
    }  


  }, 

  register: function()  
  { 
    var observerService = Cc["@mozilla.org/observer-service;1"]  
            .getService(Ci.nsIObserverService);  
    observerService.addObserver(this, "http-on-modify-request", false);         
  },  

  unregister: function()  
  {
    var observerService = Cc["@mozilla.org/observer-service;1"]  
            .getService(Ci.nsIObserverService);  
    observerService.removeObserver(this, "http-on-modify-request"); 


  }  
};


//register observer
httpRequestObserver.register();

};

exports.onUnload = function(reason) {

httpRequestObserver.unregister();
};

请帮助我,我搜索了几个小时没有结果。 代码正在运行,但不是在第一次加载页面时,只有在我重新加载时。

目标是只有在mysite.com上,才会有一个x-text=test header请求,但只能在mysite.com上。


I have a weird bug in my addon, the addon itself needs to add a request header parameters for a specific domain, it's all working, but the bug is, that the observer http-on-modify-request is not called at start, only if I reload the page, then it's working.

I mean:

  1. I go to mysite.com/ - no header modified,
  2. I reload page - header modefied
  3. reload again - header modefied
  4. new tab at mysite.com/ - no header modified
  5. reload tab - header modefied

My code, I'm using the addon sdk:

exports.main = function(options,callbacks) {

// Create observer 
httpRequestObserver =  
{  
  observe: function(subject, topic, data)  
  {  

    if (topic == "http-on-modify-request") {


    //only identify to specific preference domain
    var windowsService = Cc['@mozilla.org/appshell/window-mediator;1'].getService(Ci.nsIWindowMediator);
    var uri = windowsService.getMostRecentWindow('navigator:browser').getBrowser().currentURI;
    var domainloc = uri.host;

        if (domainloc=="mysite.com"){
            var httpChannel = subject.QueryInterface(Ci.nsIHttpChannel);  
            httpChannel.setRequestHeader("x-test", "test", false);  
        }
    }  


  }, 

  register: function()  
  { 
    var observerService = Cc["@mozilla.org/observer-service;1"]  
            .getService(Ci.nsIObserverService);  
    observerService.addObserver(this, "http-on-modify-request", false);         
  },  

  unregister: function()  
  {
    var observerService = Cc["@mozilla.org/observer-service;1"]  
            .getService(Ci.nsIObserverService);  
    observerService.removeObserver(this, "http-on-modify-request"); 


  }  
};


//register observer
httpRequestObserver.register();

};

exports.onUnload = function(reason) {

httpRequestObserver.unregister();
};

Please help me, I searched for hours with no results. The code is working, but not at first time of page loading, only if I reload.

The goal is that only on mysite.com, there will be a x-text=test header request, all the time, but only on mysite.com.


原文:https://stackoverflow.com/questions/21222873
更新时间:2022-04-08 06:04

最满意答案

解决了!

通过正在进行的研究,搜索论坛和源代码库,我只用libwebkit和标准compiz桌面(任何带有合成的Xorg桌面都应该这样做)来完成这些必要步骤。

对于当前的libwebkit(1.1.10-SVN),有一个Ubuntu PPA:

deb http://ppa.launchpad.net/webkit-team/ppa/ubuntu jaunty main
deb-src http://ppa.launchpad.net/webkit-team/ppa/ubuntu jaunty main

就代码而言,关键是调用webkit_web_view_set_transparent

当然,你运行它的系统应该有一个有能力的图形卡(intel,radeon或nvidia),并运行合成窗口管理器(如Compiz)。

最后,为了真正看到透明度,您查看的内容必须使用CSS3设置透明背景,否则它仍然是完全不透明的。

这很简单:

BODY { background-color: rgba(0,0,0,0); }

这里是最简单的webkit浏览器应用程序的完整示例,支持透明度:

#include <gtk/gtk.h>
#include <webkit/webkit.h>

static void destroy_cb(GtkWidget* widget, gpointer data) {
  gtk_main_quit();
}

int main(int argc, char* argv[]) {
  gtk_init(&argc, &argv);

  if(!g_thread_supported())
    g_thread_init(NULL);

  // Create a Window, set colormap to RGBA
  GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  GdkScreen *screen = gtk_widget_get_screen(window);
  GdkColormap *rgba = gdk_screen_get_rgba_colormap (screen);

  if (rgba && gdk_screen_is_composited (screen)) {
    gtk_widget_set_default_colormap(rgba);
    gtk_widget_set_colormap(GTK_WIDGET(window), rgba);
  }

  gtk_window_set_default_size(GTK_WINDOW(window), 800, 800);
  g_signal_connect(window, "destroy", G_CALLBACK(destroy_cb), NULL);

  // Optional: for dashboard style borderless windows
  gtk_window_set_decorated(GTK_WINDOW(window), FALSE);


  // Create a WebView, set it transparent, add it to the window
  WebKitWebView* web_view = web_view = WEBKIT_WEB_VIEW(webkit_web_view_new());
  webkit_web_view_set_transparent(web_view, TRUE);
  gtk_container_add (GTK_CONTAINER(window), GTK_WIDGET(web_view));

  // Load a default page
  webkit_web_view_load_uri(web_view, "http://stackoverflow.com/");

  // Show it and continue running until the window closes
  gtk_widget_grab_focus(GTK_WIDGET(web_view));
  gtk_widget_show_all(window);
  gtk_main();
  return 0;
}

截图! http://i27.tinypic.com/2qntlxl.jpg


Solved!

Through ongoing research, scouring forums and source code repositories, I peiced together the necessary steps to accomplish this using only libwebkit and a standard compiz desktop (any Xorg desktop with compositing should do).

For a current libwebkit (1.1.10-SVN), there is an Ubuntu PPA:

deb http://ppa.launchpad.net/webkit-team/ppa/ubuntu jaunty main
deb-src http://ppa.launchpad.net/webkit-team/ppa/ubuntu jaunty main

As far as the code goes, the key is calling webkit_web_view_set_transparent.

And of course the system you're running it on should have a capable graphics card (intel, radeon, or nvidia) and be running a compositing window manager (like Compiz).

And finally, to actually see transparency, the content you're viewing must set a transparent background using CSS3, otherwise it's still completely opaque.

It's as simple as:

BODY { background-color: rgba(0,0,0,0); }

Here' is the full sample for the simplest possible webkit browser app, with transparency support:

#include <gtk/gtk.h>
#include <webkit/webkit.h>

static void destroy_cb(GtkWidget* widget, gpointer data) {
  gtk_main_quit();
}

int main(int argc, char* argv[]) {
  gtk_init(&argc, &argv);

  if(!g_thread_supported())
    g_thread_init(NULL);

  // Create a Window, set colormap to RGBA
  GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  GdkScreen *screen = gtk_widget_get_screen(window);
  GdkColormap *rgba = gdk_screen_get_rgba_colormap (screen);

  if (rgba && gdk_screen_is_composited (screen)) {
    gtk_widget_set_default_colormap(rgba);
    gtk_widget_set_colormap(GTK_WIDGET(window), rgba);
  }

  gtk_window_set_default_size(GTK_WINDOW(window), 800, 800);
  g_signal_connect(window, "destroy", G_CALLBACK(destroy_cb), NULL);

  // Optional: for dashboard style borderless windows
  gtk_window_set_decorated(GTK_WINDOW(window), FALSE);


  // Create a WebView, set it transparent, add it to the window
  WebKitWebView* web_view = web_view = WEBKIT_WEB_VIEW(webkit_web_view_new());
  webkit_web_view_set_transparent(web_view, TRUE);
  gtk_container_add (GTK_CONTAINER(window), GTK_WIDGET(web_view));

  // Load a default page
  webkit_web_view_load_uri(web_view, "http://stackoverflow.com/");

  // Show it and continue running until the window closes
  gtk_widget_grab_focus(GTK_WIDGET(web_view));
  gtk_widget_show_all(window);
  gtk_main();
  return 0;
}

Screenshot!

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。