How to cancel a navigation?

42 views
Skip to first unread message

Jorge

unread,
Jul 4, 2012, 4:00:25 AM7/4/12
to berk...@googlegroups.com
Hi,

I'm using the 11.0.696.77 release. I wan't to know how to avoid navigating away from a page?
I've seen the "onNavigationRequested" method but setting the cancelDefaultAction to true
doesn't changes the behaviour. I only want to get the URL where the user wants to go but
I don't want allow to do it...
Anybody has checked the method works as expected?

Thanks!

Jorge

unread,
Jul 4, 2012, 4:34:38 AM7/4/12
to berk...@googlegroups.com
I've follow the code to WindowImpl.cpp line 1264, but the code to cancel a request
is commented...

void WindowImpl::OnDidStartProvisionalLoadForFrame(
        int64 frame_id,
        bool is_main_frame,
        const GURL& url) {
    if (!is_main_frame) {
        return;
    }

    if (mDelegate) {
        bool cancelDefault = false;
        const std::string &urlstring = url.spec();
        const std::string &referrerstring = this->mCurrentURL.spec();

        // Note: cancelDefault is currently broken. Don't depend on this feature.
        if (urlstring != referrerstring) {
            mDelegate->onNavigationRequested(
              this,
              URLString::point_to(urlstring),
              URLString::point_to(referrerstring),
              false, cancelDefault
            );
        }
        if (cancelDefault) {
            // FIXME: Hack for browser_handles_top_level_requests disabled.
            //mRenderViewHost->Stop();
            //this->goBack();
            //return;
        }
    }

    this->mCurrentURL = url;

    if (mDelegate) {
        const std::string&spec=url.spec();
        mDelegate->onStartLoading(this, URLString::point_to(spec));
        mDelegate->onAddressBarChanged(this, URLString::point_to(spec));
    }
}


Any hint? I've try to uncomment the code but no luck...

Patrick Reiter Horn

unread,
Jul 4, 2012, 5:53:26 PM7/4/12
to berk...@googlegroups.com
The commented code does not work in most cases.

I'm afraid this isn't easy without deeper integration into the renderer process... currently, the renderer makes the decision to begin navigation independent of the browser process.

It is possible for the browser process to cancel the navigation, for example if the url leads to a file download, but I'm afraid I haven't figured out how to do this. This may be easier to do after the rewrite of WindowImpl to work with newer versions of chromium.
Reply all
Reply to author
Forward
0 new messages