Closed
Bug 93330
Opened 23 years ago
Closed 23 years ago
Manually override charset doesn't work in View | Page Source window
Categories
(Core :: Internationalization, defect)
Core
Internationalization
Tracking
()
VERIFIED
FIXED
mozilla0.9.5
People
(Reporter: amyy, Assigned: shanjian)
Details
(Keywords: intl)
Attachments
(6 files)
(deleted),
patch
|
Details | Diff | Splinter Review | |
(deleted),
patch
|
Details | Diff | Splinter Review | |
(deleted),
patch
|
Details | Diff | Splinter Review | |
(deleted),
patch
|
Details | Diff | Splinter Review | |
(deleted),
patch
|
Details | Diff | Splinter Review | |
(deleted),
patch
|
Details | Diff | Splinter Review |
Build: 07-26 Branch build.
Steps to reproduce:
1. Launch browser, go to any page.
2. View | Page Source, then will bring up a Page Source window.
3. View | Character Coding, change the charset to something other than
the current one.
Result:
The Page Source page doesn't get reloaded, and the charset still keep the same
as the orginal one.
Note: Auto-detect menu is working fine here - if you have a wrong charset in
Page Source, you can correct it by going auto-detect menu.
Reporter | ||
Comment 1•23 years ago
|
||
Reassign to Shanjian and change the QA contact to myself.
Assignee | ||
Comment 2•23 years ago
|
||
The problem seems exist in
/xpfe/browser/resources/content/navigator.js, function
"BrowserReloadWithFlags()".
The code there does not work in view source. Statement
" var sh = getWebNavigation().sessionHistory;"
cause a exception and following statements are not executed.
Assignee | ||
Comment 3•23 years ago
|
||
radha, can you explain why the code in
http://lxr.mozilla.org/seamonkey/source/xpfe/browser/resources/content/navigator
.js#485
does not work for view source?
Status: NEW → ASSIGNED
Comment 4•23 years ago
|
||
Shajian: I do not know why it is failing for view-source with manually
overridden charset changes. May be you are calling getWebNavigation on the
chrome window or you are calling getSessionHistory() in a subframe that doesn't
have session History. You may want
to break up that call and see what is going on.
In general only top level docshells with type, "content" have session history
in them.
Assignee | ||
Comment 5•23 years ago
|
||
radha, I found out that the problem is caused by failing to get sessionHistory.
It seems like sessionHistory does not exist for viewsource window. I am not
familiar with the code, so my question might sounds stupid. Why can't we just
get nsIWebNavigation interface directly from webNavigation? I assume there is a
good reason not to do so. The following lines also seems fixing my problem:
try {
/* Need to get SessionHistory from docshell so that
* reload on framed pages will work right. This
* method should not be used for the context menu item "Reload frame".
* "Reload frame" should directly call into docshell as it does right now
*/
var webNavigation = getWebNavigation();
var sh = webNavigation.sessionHistory;
var webNav = sh.QueryInterface(Components.interfaces.nsIWebNavigation);
webNav.reload(reloadFlags);
}
catch(ex) {
var webNav =
webNavigation.QueryInterface(Components.interfaces.nsIWebNavigation);
webNav.reload(reloadFlags);
}
But I am afraid it is not a good idea to put normal code into exception
handling. Can you suggest a way to test if sessionHistory exist or not?
thanks!
Assignee | ||
Comment 6•23 years ago
|
||
Assignee | ||
Comment 7•23 years ago
|
||
radha, can you review my patch?
Comment 8•23 years ago
|
||
shajian,
1) I don't think, it is a good idea to put the new piece of code in the catch()
segment of the existing code. I suggest that you add that piece of code in the
caller with its own try{} catch() block, OR make a different function and call it
2) I think getWebNavigation() already returns a handle to nsIWebNavigation and
there is no need to do a explicit QI to nsIWebNavigation on it again.
Assignee | ||
Comment 9•23 years ago
|
||
radha, I agree with your 2nd point. I tried it and it works fine. However, I am
hesitating about your first suggestion. Function "BrowserReloadWithFlags" should
do its work, it is unreasonable to me to pop up this inside logic to its caller.
If there is a way to detect if "sessionHistory" exit in "webNavigation" or not
before "var sh = webNavigation.sessionHistory;" is called, that should be a
better choice. If not, I don't see anything wrong with doing a alternative
approach in catch segment.
Comment 10•23 years ago
|
||
Here are my suggestions at this time:
a) Please provide a updated patch (remove the additional QI for nsIWebnavigation
on webNav) and see if someone in navigator group blakeross@telocity.com or
jaggernaut@netscape.com or alecf@netscape.com will review the code that is in
the catch block.
OR
b) Try something similar to the following, and if it works get reviews from the
above mentioned people. If you go with the following, I would also like to try
the patch and make sure that it doesn't break anything.
function getSessionHistory()
{
try {
return getWebNavigation().sessionHistory;
} catch (e) {
return null;
}
}
BrowserReloadWithFlags(reloadFlags)
{
/* Whenever available, get sessionHistory and docshell and call
* reload() on sessionHistory. This is required so that reload
* on frameset pages will work right. However,this should not to be
* done for "reload Frame" context menu.
*/
var sh = getSessionHistory();
if (sh) {
try {
var webNav = sh.QueryInterface(Components.interfaces.nsIWebNavigation);
webNav.reload(reloadFlags);
} catch (e) {
}
}else {
// no session History. Call reload() directly on nsIWebNavigation
var webNav = getWebNavigation();
if (webNav) {
try {
webNav.reload(reloadFlags)
} catch(e) {
}
} // webnav
}
}
Assignee | ||
Comment 11•23 years ago
|
||
I like this idea. New patch is following.
Assignee | ||
Comment 12•23 years ago
|
||
Assignee | ||
Comment 13•23 years ago
|
||
blake, could you review my fix for this bug? Thx.
Comment 14•23 years ago
|
||
shanjian,
1) Please remove the dump statements
2) The name of the BrowserReloadWithFlags() is garbled as
BrowsebbrReloadWithFlags(). I bet your patch will cause lots of breakage with
this typo.
Assignee | ||
Comment 15•23 years ago
|
||
This is very embrassing. It is my carelessness to let those junk into my diff. I
will post a new diff.
Assignee | ||
Comment 16•23 years ago
|
||
Assignee | ||
Comment 18•23 years ago
|
||
Peter, could you review my patch? thanks.
Comment 19•23 years ago
|
||
Shanjian, a few comments on your patch:
function BrowserReloadWithFlags(reloadFlags)
{
+ /* Whenever available, get sessionHistory and docshell and call
+ * reload() on sessionHistory. This is required so that reload
You are using 3-space indent here while (most of) the rest of the file uses
2-space indent. If you're uncertain which indentation mode to use, look at the
first line for "tab-width":
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
------
+ var webNav = getWebNavigation();
+
if (webNav) {
+ webNav.reload(reloadFlags)
Here you have a tab before the if. One of our coding guidelines is not to use
tabs, but instead expand them to spaces. Most editors can do this for you.
Other than those nits, your code looks good, but let me attach another patch
with a slightly different approach.
Comment 20•23 years ago
|
||
Comment 21•23 years ago
|
||
By the way, that try/catch around var sh = webNav.sessionHistory shouldn't be
needed I think. Session History is optional, and in such cases a getter
shouldn't throw an error if returns null.
Let me talk to some people and file a bug on this if needed.
In the mean time, what do you think of this patch?
Assignee | ||
Comment 22•23 years ago
|
||
I like your patch better than mine. Let's fix it that way. I need to seek sr
now.
Assignee | ||
Comment 23•23 years ago
|
||
alec, can you sr this one?
Comment 24•23 years ago
|
||
Is alecf back from sabbatical yet? Blake could sr= this I think.
Assignee | ||
Comment 25•23 years ago
|
||
I found out that fact after an email is sent to alecf. I asked waterson to take
a look.
Comment 26•23 years ago
|
||
So attachment 47463 [details] [diff] [review] could use a bit of explanation, because it sure looks
squirrely. It looks like we try to get the ``session history'' object from the
``web navigation'' object, but this might fail sometimes (why?). When it does
fail, we'll just go ahead and use the web navigation object (what are the
consequences of doing this?).
So, could somebody explain:
- Under what circumstances ``getting'' the session history object (or QI'ing
it to nsIWebNavigation) might fail?
- When we fail to get the SH object, what are the consequences of ``just using''
the original web navigation object?
And then update the patch with appropriate comments that would answer these
questions for the next person that has to read this code?
Comment 27•23 years ago
|
||
Radha explained this in bug 68847.
Radha, if I read you correctly there, what we should be aiming for is that we
eliminate nsIWebNavigation from the nsDocShell implementation and call a bunch
of methods, like goBack(), goForward() etc. directly on the nsIWebNavigation
implemented by Session History? And as part of that, all normal reloads should
also go through Session History (when available), except for per-frame reloads,
which still would need to go through nsDocShell (for lack of a better/cleaner
mechanism?)
As for when Session History is and isn't available: a browser (window) will
generally have support for session history, a view source window won't.
Comment 28•23 years ago
|
||
Yes. QI of session history to nsIWebNavigation will not fail. However, access to
session history from a docshell will fail in a view-source window. That's why we
first try to access SH, and call reload() off of it. This is done to provide
proper behavior on frameset pages.
If it fails then we call straight in to docshell. This is needed for cases like
view-source. (this bug). Reload off of docshell is primarily used by layout when
it detects a different charset in a page. It is identical to
nsISHistory::Reload() on a simple page, but lacks functionality on frameset pages.
Comment 29•23 years ago
|
||
> Yes. QI of session history to nsIWebNavigation will not fail.
Why do we need a |try| block then?
> However, access to session history from a docshell will fail in
> a view-source window.
Will it hard-fail? I.e., return an error code? If not, let's remove the |try| block.
> That's why we first try to access SH, and call reload() off of it. This is
> done to provide proper behavior on frameset pages.
Or any page, yes?
> If it fails then we call straight in to docshell. This is needed for
> cases like view-source. (this bug). Reload off of docshell is primarily used
> by layout when it detects a different charset in a page. It is identical to
> nsISHistory::Reload() on a simple page, but lacks functionality on frameset
> pages.
Okay, so why not add some comments to that effect in the patch. ``First, we'll
try to use the session history object to reload so that framesets are handled
properly. If we're in a special window (such as view-source) that has no session
history, fall back on using the web navigation's reload method.''
Also, convince me you need to use this tortured try/catch logic instead of
something simple like |if (!webnav.sessionHistory) {...}|, and I'll be happy.
Assignee | ||
Comment 30•23 years ago
|
||
Assignee | ||
Comment 31•23 years ago
|
||
jag, radha, thanks for providing the information. Jag, could you review my
new patch (basically just some additional comment)?
Comment 32•23 years ago
|
||
waterson: getting the session history will give you a hard error if it's not
there. Hence the try/catch, not around the QI but around the .sessionHistory,
and to keep the code somewhat readable I opted for this grouping.
Whether it should or shouldn't be a hard error is a different issue. I don't
think it should be (as perfectly demonstrated by viewsource).
Comment 33•23 years ago
|
||
jag: ok, thanks. I still think the comment in attachment 47680 [details] [diff] [review] is pretty
cryptic, but if you guys understand it, I'm okay with it. sr=waterson
Assignee | ||
Comment 34•23 years ago
|
||
reset milestone to 0.9.5.
Target Milestone: mozilla0.9.4 → mozilla0.9.5
Comment 35•23 years ago
|
||
I think I like waterson's comment better:
``First, we'll try to use the session history object to reload so that framesets
are handled properly. If we're in a special window (such as view-source) that
has no session history, fall back on using the web navigation's reload method.''
I believe the context menu item "Reload Frame" comment is better placed near
that code, instead of here.
r=jag with that change.
Assignee | ||
Comment 36•23 years ago
|
||
Assignee | ||
Comment 37•23 years ago
|
||
Now waterson's comment is a consensus, I have no objection either. I update my
patch as such.
A question to radha, can we hide the logic of session history inside docshell? I
mean let docshell worry about either session history should be called or not,
and we can just simply call reload on nsIWebNavigation.
Comment 38•23 years ago
|
||
Point out the obvious, why don't you ;-)
I was wondering that myself, but I figured radha had good reasons not to.
Assignee | ||
Comment 39•23 years ago
|
||
fix checked in.
Status: ASSIGNED → RESOLVED
Closed: 23 years ago
Resolution: --- → FIXED
Reporter | ||
Comment 40•23 years ago
|
||
Verified on 10-05 trunk build, this feature is functional working, however the
charset menu is not marked as the updated one.
Opened a new bug 104474 for that, and mark this one as verified.
Status: RESOLVED → VERIFIED
You need to log in
before you can comment on or make changes to this bug.
Description
•