|
|
Chromium Code Reviews
DescriptionIgnore multiple assignments to global context.
WebView encounters applications where they override
getApplicationContext and return fresh instances or wrappers every
time it is called. We cannot rely on that method and so we assume that
the first assignment is the most correct one.
BUG=637389
Committed: https://crrev.com/10f8626fd501f0f58f7136e27da134678300a439
Cr-Commit-Position: refs/heads/master@{#412845}
Patch Set 1 #
Total comments: 8
Patch Set 2 : Switch to debug. #Patch Set 3 : Add TODO. #Messages
Total messages: 29 (10 generated)
The CQ bit was checked by wnwen@chromium.org to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
wnwen@chromium.org changed reviewers: + boliu@chromium.org
🚀
https://codereview.chromium.org/2242173003/diff/1/android_webview/glue/java/s... File android_webview/glue/java/src/com/android/webview/chromium/WebViewChromiumFactoryProvider.java (right): https://codereview.chromium.org/2242173003/diff/1/android_webview/glue/java/s... android_webview/glue/java/src/com/android/webview/chromium/WebViewChromiumFactoryProvider.java:195: ResourcesContextWrapperFactory.get(mWebViewDelegate.getApplication())); while I don't necessarily think this is wrong, why do this? https://codereview.chromium.org/2242173003/diff/1/base/android/java/src/org/c... File base/android/java/src/org/chromium/base/ContextUtils.java (right): https://codereview.chromium.org/2242173003/diff/1/base/android/java/src/org/c... base/android/java/src/org/chromium/base/ContextUtils.java:61: Log.e(TAG, "Multiple contexts detected, ignoring new application context."); so this turns off the check for chrome as well, is it valid for chrome? If yes, maybe have webview call a different method, like initApplicationContextIgnoreDuplicateCall or something like that? plus this error message is useless for app developers, debug instead so it gets striped out of release builds?
The CQ bit was unchecked by commit-bot@chromium.org
Dry run: This issue passed the CQ dry run.
https://codereview.chromium.org/2242173003/diff/1/android_webview/glue/java/s... File android_webview/glue/java/src/com/android/webview/chromium/WebViewChromiumFactoryProvider.java (right): https://codereview.chromium.org/2242173003/diff/1/android_webview/glue/java/s... android_webview/glue/java/src/com/android/webview/chromium/WebViewChromiumFactoryProvider.java:195: ResourcesContextWrapperFactory.get(mWebViewDelegate.getApplication())); On 2016/08/15 21:16:38, boliu wrote: > while I don't necessarily think this is wrong, why do this? We want the application object to be cached if .getApplicationContext is not idempotent. Normally Application#getApplicationContext would return itself, or at least a wrapper that is then idempotent, but in the cases where it doesn't, I think the original Application object is what we are trying to keep anyways. It's the only call we can rely on not being changed/wrongly overridden by the app developer. WDYT? https://codereview.chromium.org/2242173003/diff/1/base/android/java/src/org/c... File base/android/java/src/org/chromium/base/ContextUtils.java (right): https://codereview.chromium.org/2242173003/diff/1/base/android/java/src/org/c... base/android/java/src/org/chromium/base/ContextUtils.java:61: Log.e(TAG, "Multiple contexts detected, ignoring new application context."); On 2016/08/15 21:16:38, boliu wrote: > so this turns off the check for chrome as well, is it valid for chrome? If yes, > maybe have webview call a different method, like > initApplicationContextIgnoreDuplicateCall or something like that? > > plus this error message is useless for app developers, debug instead so it gets > striped out of release builds? If we do use separate calls, it would mean using separate calls for everything in shared code, which I don't really like, since it means a large portion of the code base raises exceptions and a large portion doesn't. I'll change it to debug, basically this reverts to the asserts we had before.
https://codereview.chromium.org/2242173003/diff/1/android_webview/glue/java/s... File android_webview/glue/java/src/com/android/webview/chromium/WebViewChromiumFactoryProvider.java (right): https://codereview.chromium.org/2242173003/diff/1/android_webview/glue/java/s... android_webview/glue/java/src/com/android/webview/chromium/WebViewChromiumFactoryProvider.java:195: ResourcesContextWrapperFactory.get(mWebViewDelegate.getApplication())); On 2016/08/15 21:49:54, Peter Wen wrote: > On 2016/08/15 21:16:38, boliu wrote: > > while I don't necessarily think this is wrong, why do this? > > We want the application object to be cached if .getApplicationContext is not > idempotent. That's not true.. If app intentionally wraps getApplicationContext return value, then we probably should use the wrapped version. > Normally Application#getApplicationContext would return itself, or > at least a wrapper that is then idempotent, but in the cases where it doesn't, I > think the original Application object is what we are trying to keep anyways. > It's the only call we can rely on not being changed/wrongly overridden by the > app developer. > > WDYT? https://codereview.chromium.org/2242173003/diff/1/base/android/java/src/org/c... File base/android/java/src/org/chromium/base/ContextUtils.java (right): https://codereview.chromium.org/2242173003/diff/1/base/android/java/src/org/c... base/android/java/src/org/chromium/base/ContextUtils.java:61: Log.e(TAG, "Multiple contexts detected, ignoring new application context."); On 2016/08/15 21:49:54, Peter Wen wrote: > On 2016/08/15 21:16:38, boliu wrote: > > so this turns off the check for chrome as well, is it valid for chrome? If > yes, > > maybe have webview call a different method, like > > initApplicationContextIgnoreDuplicateCall or something like that? > > > > plus this error message is useless for app developers, debug instead so it > gets > > striped out of release builds? > > If we do use separate calls, it would mean using separate calls for everything > in shared code, which I don't really like, since it means a large portion of the > code base raises exceptions and a large portion doesn't. What do you mean by "large portion of the code base"? Isn't it this method only? > > I'll change it to debug, basically this reverts to the asserts we had before.
https://codereview.chromium.org/2242173003/diff/1/base/android/java/src/org/c... File base/android/java/src/org/chromium/base/ContextUtils.java (right): https://codereview.chromium.org/2242173003/diff/1/base/android/java/src/org/c... base/android/java/src/org/chromium/base/ContextUtils.java:61: Log.e(TAG, "Multiple contexts detected, ignoring new application context."); On 2016/08/15 22:21:32, boliu wrote: > On 2016/08/15 21:49:54, Peter Wen wrote: > > On 2016/08/15 21:16:38, boliu wrote: > > > so this turns off the check for chrome as well, is it valid for chrome? If > > yes, > > > maybe have webview call a different method, like > > > initApplicationContextIgnoreDuplicateCall or something like that? > > > > > > plus this error message is useless for app developers, debug instead so it > > gets > > > striped out of release builds? > > > > If we do use separate calls, it would mean using separate calls for everything > > in shared code, which I don't really like, since it means a large portion of > the > > code base raises exceptions and a large portion doesn't. > > What do you mean by "large portion of the code base"? Isn't it this method only? > > > > > I'll change it to debug, basically this reverts to the asserts we had before. > I mean this is fine. Just feels bad that chrome is losing the more strict check because webview can't satisfy it. And It's not like I own this code..
torne@chromium.org changed reviewers: + torne@chromium.org
Peter, wasn't the idea that we were going to go through and fix the context initialisation so that it was only ever done once in the first place? I thought the multiple calls were a temporary situation until that was done. That seems like a much nicer option in general :)
On 2016/08/16 13:46:57, Torne wrote: > Peter, wasn't the idea that we were going to go through and fix the context > initialisation so that it was only ever done once in the first place? I thought > the multiple calls were a temporary situation until that was done. > > That seems like a much nicer option in general :) Yes, agreed, this bug is good motivation to do so.
https://codereview.chromium.org/2242173003/diff/1/base/android/java/src/org/c... File base/android/java/src/org/chromium/base/ContextUtils.java (right): https://codereview.chromium.org/2242173003/diff/1/base/android/java/src/org/c... base/android/java/src/org/chromium/base/ContextUtils.java:61: Log.e(TAG, "Multiple contexts detected, ignoring new application context."); On 2016/08/15 22:21:32, boliu wrote: > On 2016/08/15 21:49:54, Peter Wen wrote: > > On 2016/08/15 21:16:38, boliu wrote: > > > so this turns off the check for chrome as well, is it valid for chrome? If > > yes, > > > maybe have webview call a different method, like > > > initApplicationContextIgnoreDuplicateCall or something like that? > > > > > > plus this error message is useless for app developers, debug instead so it > > gets > > > striped out of release builds? > > > > If we do use separate calls, it would mean using separate calls for everything > > in shared code, which I don't really like, since it means a large portion of > the > > code base raises exceptions and a large portion doesn't. > > What do you mean by "large portion of the code base"? Isn't it this method only? > > > > > I'll change it to debug, basically this reverts to the asserts we had before. > It means LibraryLoader, which webview calls and now checks to make sure the context.getApplicationContext is the same one, will have to be changed. ChildProcessLauncher, which webview may call in the future, will have to be changed then. I'd much rather for us to just crash new apps that wrap their context poorly, but I agree that we have to make sure webview still works for existing apps that worked before.
On 2016/08/16 13:57:46, Peter Wen wrote: > https://codereview.chromium.org/2242173003/diff/1/base/android/java/src/org/c... > File base/android/java/src/org/chromium/base/ContextUtils.java (right): > > https://codereview.chromium.org/2242173003/diff/1/base/android/java/src/org/c... > base/android/java/src/org/chromium/base/ContextUtils.java:61: Log.e(TAG, > "Multiple contexts detected, ignoring new application context."); > On 2016/08/15 22:21:32, boliu wrote: > > On 2016/08/15 21:49:54, Peter Wen wrote: > > > On 2016/08/15 21:16:38, boliu wrote: > > > > so this turns off the check for chrome as well, is it valid for chrome? If > > > yes, > > > > maybe have webview call a different method, like > > > > initApplicationContextIgnoreDuplicateCall or something like that? > > > > > > > > plus this error message is useless for app developers, debug instead so it > > > gets > > > > striped out of release builds? > > > > > > If we do use separate calls, it would mean using separate calls for > everything > > > in shared code, which I don't really like, since it means a large portion of > > the > > > code base raises exceptions and a large portion doesn't. > > > > What do you mean by "large portion of the code base"? Isn't it this method > only? > > > > > > > > I'll change it to debug, basically this reverts to the asserts we had > before. > > > > It means LibraryLoader, which webview calls and now checks to make sure the > context.getApplicationContext is the same one, will have to be changed. > ChildProcessLauncher, which webview may call in the future, will have to be > changed then. I'd much rather for us to just crash new apps that wrap their > context poorly, but I agree that we have to make sure webview still works for > existing apps that worked before. Well why does LibraryLoader need to set the application context at all? I think most codepaths are already setting it explicitly before that; maybe we can just fix it so they all do?
On 2016/08/16 13:59:06, Torne wrote: > Well why does LibraryLoader need to set the application context at all? I think > most codepaths are already setting it explicitly before that; maybe we can just > fix it so they all do? Yes, agreed, I just meant in the context of the current CL. I'll try to remove that check in a separate CL.
CL: https://codereview.chromium.org/2247143004/ Closing this as it's no longer necessary.
Description was changed from ========== Ignore multiple assignments to global context. WebView encounters applications where they override getApplicationContext and return fresh instances or wrappers every time it is called. We cannot rely on that method and so we assume that the first assignment is the most correct one. BUG=637389 ========== to ========== Ignore multiple assignments to global context. WebView encounters applications where they override getApplicationContext and return fresh instances or wrappers every time it is called. We cannot rely on that method and so we assume that the first assignment is the most correct one. BUG=637389 ==========
Message was sent while issue was closed.
On 2016/08/16 16:50:36, Peter Wen wrote: > CL: https://codereview.chromium.org/2247143004/ That one looks too big to merge to m53.. > > Closing this as it's no longer necessary.
Good point. Let's fix this for now and add the exception back once the other CL lands so third party apps don't crash in M53.
PTAL. :)
lg2m
lgtm
The CQ bit was checked by wnwen@chromium.org
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
Message was sent while issue was closed.
Description was changed from ========== Ignore multiple assignments to global context. WebView encounters applications where they override getApplicationContext and return fresh instances or wrappers every time it is called. We cannot rely on that method and so we assume that the first assignment is the most correct one. BUG=637389 ========== to ========== Ignore multiple assignments to global context. WebView encounters applications where they override getApplicationContext and return fresh instances or wrappers every time it is called. We cannot rely on that method and so we assume that the first assignment is the most correct one. BUG=637389 ==========
Message was sent while issue was closed.
Committed patchset #3 (id:40001)
Message was sent while issue was closed.
Description was changed from ========== Ignore multiple assignments to global context. WebView encounters applications where they override getApplicationContext and return fresh instances or wrappers every time it is called. We cannot rely on that method and so we assume that the first assignment is the most correct one. BUG=637389 ========== to ========== Ignore multiple assignments to global context. WebView encounters applications where they override getApplicationContext and return fresh instances or wrappers every time it is called. We cannot rely on that method and so we assume that the first assignment is the most correct one. BUG=637389 Committed: https://crrev.com/10f8626fd501f0f58f7136e27da134678300a439 Cr-Commit-Position: refs/heads/master@{#412845} ==========
Message was sent while issue was closed.
Patchset 3 (id:??) landed as https://crrev.com/10f8626fd501f0f58f7136e27da134678300a439 Cr-Commit-Position: refs/heads/master@{#412845} |
