コード例 #1
0
ファイル: tab.py プロジェクト: raoariel/quark
 def navigation_cb(self, view, frame, request, action, policy):
     uri = request.get_uri()
     if frame == view.get_main_frame() and (not self.is_tab_sub_origin(self.get_origin(uri))) :
         tlog('NAV: ' + frame.get_name() + " is navigating to " + uri)
         m = msg.create_navigate(uri)
         self.write_message(m)
         policy.ignore()
         return
コード例 #2
0
ファイル: tab.py プロジェクト: raoariel/quark
 def tnavigation_cb(view, frame, request, action, policy):
     tlog("temporary view's navigation callback is called.")
     uri = request.get_uri()
     m = msg.create_navigate(uri)
     self.write_message(m)
     policy.ignore()
     request.set_uri("about:blank")
     view.destroy()
     frame.stop_loading()
     return
コード例 #3
0
ファイル: tab.py プロジェクト: raoariel/quark
    def resource_cb(self, view, frame, resource, request, response):
        try :
            uri = request.get_uri()
            fname = frame.get_name()
            #tlog('resource-request-starting for ' + str(fname) + " : " + str(uri))
        except Error:
            tlog('resource-request-starting for something weird:this is redirected to webkit')
            return

        if string.find(uri, "http") != 0: 
            # tlog("strange url:" + uri)
            # DON: this is going to result in segmentation fault in libsoup
            # in case that the url is outside of the tab domain.
            # We have to deal with this in a better way.
            return

        # First resource loading in this frame. even navigation
        # callback wasn't called for this frame is this only for the
        # main frame?
        if string.find(str(frame.get_load_status()), "PROVISIONAL") >= 0:
            self.frames[frame] = self.get_origin(uri)
            if self.time == None:
                self.time = time.time()
                self.finishedCnt = 0
                # if the redirection is to an origin that belongs to the tab origin, it's allowed for
                # socket connection

            if self.is_tab_sub_origin(self.frames[frame]) == True:
                #tlog("a frame is navigated to :" + uri + " within the tab origin :" + self.tab_origin)
                return
            else:
                #tlog("a frame is navigated to :" + uri + " outside the tab origin :" + self.tab_origin)
                # main frame is navigated to another domain
                # then, this tab should die by sending navigate message
                if frame == view.get_main_frame() :
                    # This must not be taken.
                    # since the navigation action is handled by
                    # navigation_cb().
                    tlog("FATAL ERROR: the main frame is terminated by navigating to " + uri + " from " + self.tab_origin)
                    m = msg.create_navigate(uri)
                    self.write_message(m)
                    #view.load_uri("about:blank")
                    request.set_uri("about:blank")
                    # this will cause segmentation fault. Because
                    # libsoup's going to try to get a web socket from
                    # the kernel, and it is going to fail.  this
                    # socket conneciton will be refused by the kernel
                    return 
                else :
                    # if it's not the main frame, we let it through wget
                    pass
        
        if self.is_tab_sub_origin(uri) :
            # if this request is within the tab's origin, it's allowed for socket conneciton
            # tlog(uri + " is within the tab origin : " + self.tab_origin)
            return

        if self.tab_origin in self.whitelist :
            #tlog(uri + " is within the whitelistn : " + self.whitelist[self.tab_origin])
            if self.is_sub_origin(self.whitelist[self.tab_origin], str(uri)):
                return

            if self.tab_origin =="youtube.com":
                if (self.is_sub_origin("gstatic.com", str(uri))) : 
                    return
                if (self.is_sub_origin("google.com", str(uri))) : 
                    return

            if self.tab_origin == "ebay.com":
                if (self.is_sub_origin("ebayimg.com", str(uri))) : 
                    return
                if (self.is_sub_origin("ebayrtm.com", str(uri))) : 
                    return

            if self.tab_origin == "blogger.com":
                if (self.is_sub_origin("blogspot.com", str(uri))) : 
                    return
                if (self.is_sub_origin("gstatic.com", str(uri))) : 
                    return
                if (self.is_sub_origin("googleusercontent.com", str(uri))) : 
                    return

        #tlog('FROM FILE ' + fname + " : " + uri)
        #tlog("FROM FILE : 1")
        m = msg.create_req_uri_follow(uri)
        self.write_message(m)
        #tlog("FROM FILE : 2")
        to_process = []
        m = self.read_message()
        while m.type != msg.mtypes.RES_URI:
            #tlog("to process: " + str(m))
            to_process = to_process + [m]
            m = self.read_message()

        #assert(not m.content.startswith("QUARK_REDIRECT"))
        tf = tempfile.NamedTemporaryFile(delete=False)
        tf.write(m.content)
        tf_name = tf.name
        tf.close()

        for m in to_process:
            self.process_message(m)

        request.set_uri('file://' + tf_name)