Bug 88412 - StorageAreaProxy::canAccessStorage should cache the permissions.
Summary: StorageAreaProxy::canAccessStorage should cache the permissions.
Status: RESOLVED INVALID
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Michael Nordman
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-06-06 06:56 PDT by Marja Hölttä
Modified: 2013-04-08 10:55 PDT (History)
9 users (show)

See Also:


Attachments
Patch (2.68 KB, patch)
2012-06-06 07:00 PDT, Marja Hölttä
no flags Details | Formatted Diff | Diff
Patch (4.37 KB, patch)
2012-06-06 07:54 PDT, Marja Hölttä
no flags Details | Formatted Diff | Diff
tlc (5.47 KB, patch)
2012-06-14 18:37 PDT, Michael Nordman
no flags Details | Formatted Diff | Diff
tlc (6.51 KB, patch)
2012-06-14 18:40 PDT, Michael Nordman
no flags Details | Formatted Diff | Diff
tlc (6.51 KB, patch)
2012-06-15 14:32 PDT, Michael Nordman
no flags Details | Formatted Diff | Diff
tlc (6.53 KB, patch)
2012-06-21 19:39 PDT, Michael Nordman
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Marja Hölttä 2012-06-06 06:56:00 PDT
StorageAreaProxy::canAccessStorage should cache the permissions.
Comment 1 Marja Hölttä 2012-06-06 07:00:08 PDT
Created attachment 146015 [details]
Patch
Comment 2 jochen 2012-06-06 07:14:39 PDT
Comment on attachment 146015 [details]
Patch

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

> Source/WebKit/chromium/ChangeLog:3
> +        StorageAreaProxy::canAccessStorage should cache the permissions.

prefix with [chromium] please

> Source/WebKit/chromium/src/StorageAreaProxy.h:31
> +#include <map>

don't use stl map but <wtf/HashMap.h>

> Source/WebKit/chromium/src/StorageAreaProxy.h:78
> +    mutable std::map<Frame*, bool> m_canAccessStorageCache;

I wonder whether we should instead add a boolean to WebFrameImpl canAccessStorage
Comment 3 Marja Hölttä 2012-06-06 07:54:22 PDT
Created attachment 146032 [details]
Patch
Comment 4 Marja Hölttä 2012-06-06 07:55:35 PDT
Comment on attachment 146015 [details]
Patch

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

>> Source/WebKit/chromium/ChangeLog:3
>> +        StorageAreaProxy::canAccessStorage should cache the permissions.
> 
> prefix with [chromium] please

Done

>> Source/WebKit/chromium/src/StorageAreaProxy.h:31
>> +#include <map>
> 
> don't use stl map but <wtf/HashMap.h>

Removed this

>> Source/WebKit/chromium/src/StorageAreaProxy.h:78
>> +    mutable std::map<Frame*, bool> m_canAccessStorageCache;
> 
> I wonder whether we should instead add a boolean to WebFrameImpl canAccessStorage

Added.
Comment 5 jochen 2012-06-06 08:06:52 PDT
this patch looks good to me, thx
Comment 6 Michael Nordman 2012-06-06 10:57:23 PDT
Comment on attachment 146032 [details]
Patch

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

> Source/WebKit/chromium/src/WebFrameImpl.cpp:1408
> +        m_canAccessStorage = !permissionClient || permissionClient->allowStorage(this, localStorage);

is the answer ever different for local vs session storage?
Comment 7 jochen 2012-06-06 11:01:51 PDT
Comment on attachment 146032 [details]
Patch

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

>> Source/WebKit/chromium/src/WebFrameImpl.cpp:1408
>> +        m_canAccessStorage = !permissionClient || permissionClient->allowStorage(this, localStorage);
> 
> is the answer ever different for local vs session storage?

hum, no, but we show different notifications. Also, it's an implementation detail outside of webkit, so we should probably cache both results
Comment 8 jochen 2012-06-06 11:01:54 PDT
Comment on attachment 146032 [details]
Patch

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

>> Source/WebKit/chromium/src/WebFrameImpl.cpp:1408
>> +        m_canAccessStorage = !permissionClient || permissionClient->allowStorage(this, localStorage);
> 
> is the answer ever different for local vs session storage?

hum, no, but we show different notifications. Also, it's an implementation detail outside of webkit, so we should probably cache both results
Comment 9 Marja Hölttä 2012-06-06 13:22:25 PDT
Comment on attachment 146032 [details]
Patch

Ahh, this was wrong, I'll fix the patch.
Comment 10 Michael Nordman 2012-06-07 10:16:27 PDT
Comment on attachment 146032 [details]
Patch

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

>>>> Source/WebKit/chromium/src/WebFrameImpl.cpp:1408
>>>> +        m_canAccessStorage = !permissionClient || permissionClient->allowStorage(this, localStorage);
>>> 
>>> is the answer ever different for local vs session storage?
>> 
>> hum, no, but we show different notifications. Also, it's an implementation detail outside of webkit, so we should probably cache both results
> 
> hum, no, but we show different notifications. Also, it's an implementation detail outside of webkit, so we should probably cache both results

hold on, if this setting can be different per-origin, webframeimpl is probably not a good place to cache this value since the frame can navigate from document to document in different origins. the storageareaproxy class is probably the best place for this cached value. instances of that class are per-document. while the methods of that class take a Frame* as input, in practice, the Frame* param value presented to a StorageAreaProxy instance will be the same value on each call. maybe something like this...

class StorageAreaProxy {

  bool canAccess(frame) {
    if (frame != m_cachedCanAccessSettingForFrame) {
      m_cachedCanAccessSetting = get value out of frame and such;
      m_cachedCanAccessSettingForFrame = frame;
    }
    return m_cachedCanAccessSetting;
  }

  void* m_cachedCanAccessSettingForFrame;  // the frame ptr for which we've cached the value (null if not cached)
  bool m_cachedCanAccessSetting;
};

Also, if there's no use case for having the setting be different for local vs session, maybe we should alter the webkit api to remove that param from the permissionClient->allowStorage() method (eventually), and in this patch just pass a hard coded value of 'true' and take it as a TODO or FIXME to clean up that api.
Comment 11 jochen 2012-06-07 11:15:56 PDT
(In reply to comment #10)
> (From update of attachment 146032 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=146032&action=review
> 
> >>>> Source/WebKit/chromium/src/WebFrameImpl.cpp:1408
> >>>> +        m_canAccessStorage = !permissionClient || permissionClient->allowStorage(this, localStorage);
> >>> 
> >>> is the answer ever different for local vs session storage?
> >> 
> >> hum, no, but we show different notifications. Also, it's an implementation detail outside of webkit, so we should probably cache both results
> > 
> > hum, no, but we show different notifications. Also, it's an implementation detail outside of webkit, so we should probably cache both results
> 
> hold on, if this setting can be different per-origin, webframeimpl is probably not a good place to cache this value since the frame can navigate from document to document in different origins. the storageareaproxy class is probably the best place for this cached value. instances of that class are per-document. while the methods of that class take a Frame* as input, in practice, the Frame* param value presented to a StorageAreaProxy instance will be the same value on each call. maybe something like this...

What if a page has multiple frames from the same origin, all using local storage?

> 
> class StorageAreaProxy {
> 
>   bool canAccess(frame) {
>     if (frame != m_cachedCanAccessSettingForFrame) {
>       m_cachedCanAccessSetting = get value out of frame and such;
>       m_cachedCanAccessSettingForFrame = frame;
>     }
>     return m_cachedCanAccessSetting;
>   }
> 
>   void* m_cachedCanAccessSettingForFrame;  // the frame ptr for which we've cached the value (null if not cached)
>   bool m_cachedCanAccessSetting;
> };
> 
> Also, if there's no use case for having the setting be different for local vs session, maybe we should alter the webkit api to remove that param from the permissionClient->allowStorage() method (eventually), and in this patch just pass a hard coded value of 'true' and take it as a TODO or FIXME to clean up that api.

The use case is displaying different UI based on whether it's sessionStorage or localStorage
Comment 12 Michael Nordman 2012-06-07 11:51:09 PDT
> > hold on, if this setting can be different per-origin, webframeimpl is probably not a good place to cache this value since the frame can navigate from document to document in different origins. the storageareaproxy class is probably the best place for this cached value. instances of that class are per-document. while the methods of that class take a Frame* as input, in practice, the Frame* param value presented to a StorageAreaProxy instance will be the same value on each call. maybe something like this...
> 
> What if a page has multiple frames from the same origin, all using local storage?

Each document has a distinct StorageAreaProxy, actually potentially two of them, one for session storage and another for local storage.

> > 
> > class StorageAreaProxy {
> > 
> >   bool canAccess(frame) {
> >     if (frame != m_cachedCanAccessSettingForFrame) {
> >       m_cachedCanAccessSetting = get value out of frame and such;
> >       m_cachedCanAccessSettingForFrame = frame;
> >     }
> >     return m_cachedCanAccessSetting;
> >   }
> > 
> >   void* m_cachedCanAccessSettingForFrame;  // the frame ptr for which we've cached the value (null if not cached)
> >   bool m_cachedCanAccessSetting;
> > };
> > 
> > Also, if there's no use case for having the setting be different for local vs session, maybe we should alter the webkit api to remove that param from the permissionClient->allowStorage() method (eventually), and in this patch just pass a hard coded value of 'true' and take it as a TODO or FIXME to clean up that api.
> 
> The use case is displaying different UI based on whether it's sessionStorage or localStorage

Ok, so we keep the param then.
Comment 13 Michael Nordman 2012-06-11 17:45:55 PDT
(In reply to comment #12)
> > > class StorageAreaProxy {
> > > 
> > >   bool canAccess(frame) {
> > >     if (frame != m_cachedCanAccessSettingForFrame) {
> > >       m_cachedCanAccessSetting = get value out of frame and such;
> > >       m_cachedCanAccessSettingForFrame = frame;
> > >     }
> > >     return m_cachedCanAccessSetting;
> > >   }
> > > 
> > >   void* m_cachedCanAccessSettingForFrame;  // the frame ptr for which we've cached the value (null if not cached)
> > >   bool m_cachedCanAccessSetting;
> > > };

If you like, I can work this into another small performance related change to this class thats in the works... https://chromiumcodereview.appspot.com/10539097/
Comment 14 Michael Nordman 2012-06-14 18:37:17 PDT
Created attachment 147699 [details]
tlc
Comment 15 Michael Nordman 2012-06-14 18:40:47 PDT
Created attachment 147701 [details]
tlc

added missing platform/ChangeLog diffs to the patch
Comment 16 Michael Nordman 2012-06-15 14:32:12 PDT
Created attachment 147899 [details]
tlc

not sure why the patch didn't apply, reupping to run it by the ews bots again
Comment 17 Michael Nordman 2012-06-15 17:21:24 PDT
> not sure why the patch didn't apply, reupping to run it by the ews bots again

i think that may have to do with line endings

fyi, the chrome-side can be seen here, https://chromiumcodereview.appspot.com/10533093/
Comment 18 Michael Nordman 2012-06-21 19:39:27 PDT
Created attachment 148945 [details]
tlc
Comment 19 WebKit Review Bot 2012-06-21 19:41:19 PDT
Please wait for approval from abarth@webkit.org, dglazkov@chromium.org, fishd@chromium.org, jamesr@chromium.org or tkent@chromium.org before submitting, as this patch contains changes to the Chromium public API. See also https://trac.webkit.org/wiki/ChromiumWebKitAPI.
Comment 20 Adam Barth 2012-06-22 10:42:25 PDT
Comment on attachment 148945 [details]
tlc

API change LGTM
Comment 21 Michael Nordman 2012-06-22 11:55:00 PDT
(In reply to comment #20)
> (From update of attachment 148945 [details])
> API change LGTM

jochen, can you take a look at the .cpp parts of this?
Comment 22 jochen 2012-06-25 08:31:13 PDT
(In reply to comment #21)
> (In reply to comment #20)
> > (From update of attachment 148945 [details] [details])
> > API change LGTM
> 
> jochen, can you take a look at the .cpp parts of this?

I'm surprised this doesn't break LayoutTests/platform/chromium/permissionclient/storage-permission.html ?
Comment 23 Michael Nordman 2012-06-25 10:04:59 PDT
> I'm surprised this doesn't break LayoutTests/platform/chromium/permissionclient/storage-permission.html ?

It sure should break that test! Probably 'passing' because of this test expectation...

BUGCR85292 : platform/chromium/permissionclient/storage-permission.html = PASS TEXT
Comment 24 jochen 2012-06-25 11:02:13 PDT
(In reply to comment #23)
> > I'm surprised this doesn't break LayoutTests/platform/chromium/permissionclient/storage-permission.html ?
> 
> It sure should break that test! Probably 'passing' because of this test expectation...
> 
> BUGCR85292 : platform/chromium/permissionclient/storage-permission.html = PASS TEXT

ouch

Anyway, the question is, should the cache be invalidated by the embedder? Alternatively, we could update the test to always block storage.
Comment 25 Michael Nordman 2012-06-25 12:55:29 PDT
(In reply to comment #24)
> (In reply to comment #23)
> > > I'm surprised this doesn't break LayoutTests/platform/chromium/permissionclient/storage-permission.html ?
> > 
> > It sure should break that test! Probably 'passing' because of this test expectation...
> > 
> > BUGCR85292 : platform/chromium/permissionclient/storage-permission.html = PASS TEXT
> 
> ouch
> 
> Anyway, the question is, should the cache be invalidated by the embedder? Alternatively, we could update the test to always block storage.

I'll poke at the test to setup to block access prior to checking and have that test just check the blocked condition.
Comment 26 jochen 2012-07-15 12:27:29 PDT
I've unskipped the test meanwhile. Can you update the test so it still works with this patch in?
Comment 27 Levi Weintraub 2013-04-08 10:55:01 PDT
Comment on attachment 148945 [details]
tlc

Clearing flags.