public function handle_remote_request(tool_installaddon_renderer $output, $request) {

        if (is_null($request)) {
            return;
        }

        $data = $this->decode_remote_request($request);

        if ($data === false) {
            echo $output->remote_request_invalid_page($this->index_url());
            exit();
        }

        list($plugintype, $pluginname) = core_component::normalize_component($data->component);
        $pluginman = core_plugin_manager::instance();

        $plugintypepath = $pluginman->get_plugintype_root($plugintype);

        if (file_exists($plugintypepath.'/'.$pluginname)) {
            echo $output->remote_request_alreadyinstalled_page($data, $this->index_url());
            exit();
        }

        if (!$pluginman->is_plugintype_writable($plugintype)) {
            $continueurl = $this->index_url(array('installaddonrequest' => $request));
            echo $output->remote_request_permcheck_page($data, $plugintypepath, $continueurl, $this->index_url());
            exit();
        }

        if (!$pluginman->is_remote_plugin_installable($data->component, $data->version, $reason)) {
            $data->reason = $reason;
            echo $output->remote_request_non_installable_page($data, $this->index_url());
            exit();
        }

        $continueurl = $this->index_url(array(
            'installremote' => $data->component,
            'installremoteversion' => $data->version
        ));

        echo $output->remote_request_confirm_page($data, $continueurl, $this->index_url());
        exit();
    }