Bug 146089 - [Content Extensions] Log blocked loads to the WebInspector console
Summary: [Content Extensions] Log blocked loads to the WebInspector console
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Alex Christensen
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-06-17 17:22 PDT by Alex Christensen
Modified: 2015-06-18 11:39 PDT (History)
6 users (show)

See Also:


Attachments
Patch (7.03 KB, patch)
2015-06-17 17:25 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews106 for mac-mavericks-wk2 (798.59 KB, application/zip)
2015-06-17 18:15 PDT, Build Bot
no flags Details
Patch (16.88 KB, patch)
2015-06-17 19:01 PDT, Alex Christensen
beidson: review-
achristensen: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Christensen 2015-06-17 17:22:38 PDT
People are asking "Why isn't this showing up?" and there's nothing in the WebInspector.  Let's tell them.
Comment 1 Alex Christensen 2015-06-17 17:25:37 PDT
Created attachment 255052 [details]
Patch
Comment 2 Joseph Pecoraro 2015-06-17 17:41:24 PDT
Comment on attachment 255052 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=255052&action=review

r=me, I'd be surprised if tests don't include logs now. Do we have contentblocker tests?

> Source/WebCore/contentextensions/ContentExtensionsBackend.cpp:219
> +            StringBuilder message;
> +            message.append("Content blocker prevented loading of ");
> +            message.append(request.url());
> +            message.append(" on ");
> +            message.append(mainDocumentURL);

Could this just be a makeString(...) list? If not, some of these appends could be appendLiteral().
Comment 3 Joseph Pecoraro 2015-06-17 18:04:58 PDT
(In reply to comment #2)
> Comment on attachment 255052 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=255052&action=review
> 
> r=me, I'd be surprised if tests don't include logs now. Do we have
> contentblocker tests?

Seems this did cause some text failures on the bots, so seems tests may just need to be updated.

Regressions: Unexpected text-only failures (8)
  http/tests/contentextensions/basic-filter.html [ Failure ]
  http/tests/contentextensions/character-set-basic-support.html [ Failure ]
  http/tests/contentextensions/domain-rules.html [ Failure ]
  http/tests/contentextensions/filters-with-quantifiers-combined.html [ Failure ]
  http/tests/contentextensions/main-resource-redirect-blocked.php [ Failure ]
  http/tests/contentextensions/media-filtered.html [ Failure ]
  http/tests/contentextensions/subresource-redirect-blocked.html [ Failure ]
  http/tests/contentextensions/text-track-blocked.html [ Failure ]
Comment 4 Alex Christensen 2015-06-17 18:06:17 PDT
(In reply to comment #2)
> Could this just be a makeString(...) list? If not, some of these appends could be appendLiteral().
makeString doesn't like URLs.  I'll use appendLiteral.  And I'll check the tests...
Comment 5 Build Bot 2015-06-17 18:15:19 PDT
Comment on attachment 255052 [details]
Patch

Attachment 255052 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.appspot.com/results/4541667524739072

New failing tests:
http/tests/contentextensions/domain-rules.html
http/tests/contentextensions/main-resource-redirect-blocked.php
http/tests/contentextensions/text-track-blocked.html
http/tests/contentextensions/subresource-redirect-blocked.html
http/tests/contentextensions/media-filtered.html
http/tests/contentextensions/character-set-basic-support.html
http/tests/contentextensions/basic-filter.html
http/tests/contentextensions/filters-with-quantifiers-combined.html
Comment 6 Build Bot 2015-06-17 18:15:23 PDT
Created attachment 255057 [details]
Archive of layout-test-results from ews106 for mac-mavericks-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews106  Port: mac-mavericks-wk2  Platform: Mac OS X 10.9.5
Comment 7 Alex Christensen 2015-06-17 19:01:34 PDT
Created attachment 255060 [details]
Patch
Comment 8 Alex Christensen 2015-06-17 19:03:28 PDT
The changes to main-resource-redirect-blocked-expected.txt look a little suspicious.  I think it's a bug in WebKitTestRunner, but we still want to see those previous logs.  Brady, could you take a look and see what is going on?
Comment 9 Brady Eidson 2015-06-17 22:30:00 PDT
(In reply to comment #4)
> (In reply to comment #2)
> > Could this just be a makeString(...) list? If not, some of these appends could be appendLiteral().
> makeString doesn't like URLs.  I'll use appendLiteral.  And I'll check the
> tests...

URL myURL;
makeString("Are you sure that this ", myURL.string(), " doesn't work...?");
Comment 10 Brady Eidson 2015-06-17 22:41:43 PDT
Comment on attachment 255060 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=255060&action=review

> Source/WebCore/contentextensions/ContentExtensionsBackend.cpp:223
> +    if (willBlockLoad) {
> +        if (currentDocument) {
> +            StringBuilder message;
> +            message.appendLiteral("Content blocker prevented loading of ");
> +            message.append(request.url());
> +            message.appendLiteral(" on ");
> +            message.append(mainDocumentURL);
> +            currentDocument->addConsoleMessage(MessageSource::ContentBlocker, MessageLevel::Info, message.toString());
> +        }
>          request = ResourceRequest();
> +    }

I think Joe's suggestion of makeString() should be perfectly fine here.

No, makeString doesn't handle URLs. But URLs are just fancy strings:
makeString("Content blocker prevented loading of ", request.url().string(), " on ", mainDocumentURL.string());

---

*THAT SAID*, I don't like this message. "Content blocker prevented loading of http://foo.com on http://bar.com" <--- This doesn't make sense. You don't load a URL onto another URL.

The blocked resource could be a document, or it could be a sub resource, but it's not "a url".

Additionally, you don't load a <resource located at a url> *on* to a <url>

The grammar just reads incorrectly.

My suggestion - that is off the cuff and might be improved:
"Content blocker prevented frame displaying http://bar.com from loading the resource at http://foo.com/someResource"

> LayoutTests/http/tests/contentextensions/main-resource-redirect-blocked-expected.txt:1
> -main frame - didStartProvisionalLoadForFrame
> -main frame - didFailProvisionalLoadWithError
> -main frame - (kWKErrorCodeCannotShowURL)
> +CONSOLE MESSAGE: Content blocker prevented loading of http://127.0.0.1:8000/contentextensions/resources/main-resource-redirect-blocked-target.html on about:blank

Thanks for alerting me to this one. This is wrong. I don't see how your patch causes it, but it's definitely wrong.

We'll take a look tomorrow on your machine that (presumably) has this built in a debug build already.
Comment 11 Brady Eidson 2015-06-17 22:43:13 PDT
(In reply to comment #10)
> My suggestion - that is off the cuff and might be improved:
> "Content blocker prevented frame displaying http://bar.com from loading the
> resource at http://foo.com/someResource"

Even better:
"Content blocker prevented frame displaying http://bar.com from loading a resource from http://foo.com/someResource"
Comment 12 Brady Eidson 2015-06-17 22:44:01 PDT
(In reply to comment #11)
> (In reply to comment #10)
> > My suggestion - that is off the cuff and might be improved:
> > "Content blocker prevented frame displaying http://bar.com from loading the
> > resource at http://foo.com/someResource"
> 
> Even better:
> "Content blocker prevented frame displaying http://bar.com from loading a
> resource from http://foo.com/someResource"

Bonus points for saying what type of resource.

"...from loading an image resource from..."
"...from loading a stylesheet resource from..."
"...from loading the document found at..."
Comment 13 Alex Christensen 2015-06-18 11:39:41 PDT
used makeString, updated test results.
http://trac.webkit.org/changeset/185714