Bug 72342 - Refactor SecurityOrigin::create to be easier to understand
Summary: Refactor SecurityOrigin::create to be easier to understand
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Adam Barth
URL:
Keywords:
Depends on:
Blocks: 71745
  Show dependency treegraph
 
Reported: 2011-11-14 17:57 PST by Adam Barth
Modified: 2011-11-17 15:33 PST (History)
2 users (show)

See Also:


Attachments
Patch (8.92 KB, patch)
2011-11-14 17:59 PST, Adam Barth
no flags Details | Formatted Diff | Diff
Patch (11.06 KB, patch)
2011-11-17 14:47 PST, Adam Barth
eric: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Adam Barth 2011-11-14 17:57:21 PST
Refactor SecurityOrigin::create to be easier to understand
Comment 1 Adam Barth 2011-11-14 17:59:07 PST
Created attachment 115076 [details]
Patch
Comment 2 Eric Seidel (no email) 2011-11-14 18:15:45 PST
Comment on attachment 115076 [details]
Patch

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

I'd like to see one more round.

> Source/WebCore/page/SecurityOrigin.cpp:84
> +    return KURL(ParsedURLString, decodeURLEscapeSequences(url.path()));

Why does this work?  Can you add a FIXME about what this should be?

> Source/WebCore/page/SecurityOrigin.cpp:104
> +    // For edge case URLs that were probably misparsed, make sure that the origin is unique.
> +    if (schemeRequiresAuthority(effectiveURL) && effectiveURL.host().isEmpty())
> +        return true;

Why do we do this?  Should this be a FIXME to remove this?  This smells bad...

> Source/WebCore/page/SecurityOrigin.cpp:109
> +    String protocol = effectiveURL.protocol().lower();
> +
> +    if (SchemeRegistry::shouldTreatURLSchemeAsNoAccess(protocol))
> +        return true;

Why do we lower the protocol here?  Why isn't SchemeRegistry case agnostic?

> Source/WebCore/page/SecurityOrigin.cpp:117
> +        // FIXME: Should we be using shouldUseInnerURL here?
> +        // We originally did that check to avoid treating blob and filesystem
> +        // urls as unique when it is created from local file urls.

This FIXME is unclear.  Can you explain better what you're trying to say?

> Source/WebCore/page/SecurityOrigin.cpp:151
> +    : m_protocol("")
> +    , m_host("")
> +    , m_domain("")

Why should this be empty strings instead of null strings?  And what about using String::empty instead of ""?
Comment 3 Adam Barth 2011-11-17 14:25:32 PST
Comment on attachment 115076 [details]
Patch

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

>> Source/WebCore/page/SecurityOrigin.cpp:109
>> +    if (SchemeRegistry::shouldTreatURLSchemeAsNoAccess(protocol))
>> +        return true;
> 
> Why do we lower the protocol here?  Why isn't SchemeRegistry case agnostic?

It's not case agnostic because it uses a hash map lookup.  It could lower the scheme itself, but that would be slow because it often requires a malloc.

>> Source/WebCore/page/SecurityOrigin.cpp:151
>> +    : m_protocol("")
>> +    , m_host("")
>> +    , m_domain("")
> 
> Why should this be empty strings instead of null strings?  And what about using String::empty instead of ""?

We can't use String::empty because this class is used on multiple threads.  I'm not sure whether we can get away with null strings.

Currently, this constructor matches the other constructor, which is very explicit about converting null strings to empty strings.  I'm inclined to experiment with changing these to null in a future patch.
Comment 4 Adam Barth 2011-11-17 14:47:25 PST
Created attachment 115690 [details]
Patch
Comment 5 Eric Seidel (no email) 2011-11-17 14:54:00 PST
Comment on attachment 115690 [details]
Patch

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

OK.

> Source/WebCore/page/SecurityOrigin.cpp:196
> +        if (url.protocolIs("file")) {
> +            // Unfortunately, we can't represent all unique origins exactly
> +            // the same way because we need to produce a quirky database
> +            // identifier for file URLs due to persistent storage in some
> +            // embedders of WebKit.
> +            origin->m_needsDatabaseIdentifierQuirkForFiles = true;
> +        }

Can't we set this only for origins that matter to the database world?
Comment 6 Adam Barth 2011-11-17 15:33:31 PST
Committed r100691: <http://trac.webkit.org/changeset/100691>