diff options
author | mbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-20 18:50:20 +0000 |
---|---|---|
committer | mbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-20 18:50:20 +0000 |
commit | 2ceafa3ddbaaa90ff73abf9941eae217c7808710 (patch) | |
tree | 271fc0e38481710a6fa92d7d59f12e733bec0d66 | |
parent | 8f643b7837cee97b2be71efd0e206568d922d291 (diff) | |
download | chromium_src-2ceafa3ddbaaa90ff73abf9941eae217c7808710.zip chromium_src-2ceafa3ddbaaa90ff73abf9941eae217c7808710.tar.gz chromium_src-2ceafa3ddbaaa90ff73abf9941eae217c7808710.tar.bz2 |
Refactoring of Location to make it port between JSC and V8.
Review URL: http://codereview.chromium.org/7666
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3615 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | webkit/port/page/Location.cpp | 174 | ||||
-rw-r--r-- | webkit/port/page/Location.h | 34 |
2 files changed, 111 insertions, 97 deletions
diff --git a/webkit/port/page/Location.cpp b/webkit/port/page/Location.cpp index 2f4f42f..9933287 100644 --- a/webkit/port/page/Location.cpp +++ b/webkit/port/page/Location.cpp @@ -60,23 +60,87 @@ WebCore::KURL GetFrameUrl(WebCore::Frame* frame) { namespace WebCore { -void Location::ChangeLocationTo(const KURL& url, bool lock_history) { - if (url.isEmpty()) - return; +#if USE(V8) + // Notes about V8/JSC porting of this file. + // The getter functions on this class are generic across V8/JSC. + // The setter functions are basically custom. In JSC, this gets separated + // into Location.h and JSLocation.h, with the implementation in + // JSLocationCustom.cpp. For V8, we include the custom functions here. + // + // This class is not very JS-engine specific. If we can move a couple of + // methods to the scriptController, we should be able to unify the code + // between JSC and V8: + // retrieveActiveFrame() - in JSC, this needs an ExecState. Is there + // a static accessor? + // isSafeScript() +#endif + +String Location::hash() const { + if (!m_frame) + return String(); + KURL url = GetFrameUrl(m_frame); + return url.ref().isNull() ? "" : "#" + url.ref(); +} - Frame* active_frame = ScriptController::retrieveActiveFrame(); - if (!active_frame) - return; +String Location::host() const { + KURL url = GetFrameUrl(m_frame); + + String str = url.host(); + if (url.port()) + str += ":" + String::number((int)url.port()); - bool user_gesture = active_frame->script()->processingUserGesture(); - String referrer = active_frame->loader()->outgoingReferrer(); + return str; +} - m_frame->loader()->scheduleLocationChange(url.string(), referrer, lock_history, user_gesture); +String Location::hostname() const { + KURL url = GetFrameUrl(m_frame); + return url.host(); } -String Location::hash() { +String Location::href() const { KURL url = GetFrameUrl(m_frame); - return url.ref().isNull() ? "" : "#" + url.ref(); + + if (!url.hasPath()) + return url.prettyURL() + "/"; + return url.prettyURL(); +} + +String Location::pathname() const { + KURL url = GetFrameUrl(m_frame); + return url.path().isEmpty() ? "/" : url.path(); +} + +String Location::port() const { + KURL url = GetFrameUrl(m_frame); + return url.port() ? String::number((int)url.port()) : String(); +} + +String Location::protocol() const { + KURL url = GetFrameUrl(m_frame); + return url.protocol() + ":"; +} + +String Location::search() const { + KURL url = GetFrameUrl(m_frame); + return url.query(); +} + +String Location::toString() const { + return href(); +} + +#if USE(V8) +static void navigateIfAllowed(Frame* frame, const KURL& url, bool lock_history) +{ + if (url.isEmpty()) + return; + + Frame* activeFrame = ScriptController::retrieveActiveFrame(); + if (activeFrame && !url.protocolIs("javascript")) { + bool user_gesture = activeFrame->script()->processingUserGesture(); + frame->loader()->scheduleLocationChange(url.string(), + activeFrame->loader()->outgoingReferrer(), lock_history, user_gesture); + } } void Location::setHash(const String& hash) { @@ -93,17 +157,7 @@ void Location::setHash(const String& hash) { return; url.setRef(str); - ChangeLocationTo(url, false); -} - -String Location::host() { - KURL url = GetFrameUrl(m_frame); - - String str = url.host(); - if (url.port()) - str += ":" + String::number((int)url.port()); - - return str; + navigateIfAllowed(m_frame, url, false); } void Location::setHost(const String& host) { @@ -117,12 +171,7 @@ void Location::setHost(const String& host) { url.setHost(newhost); url.setPort(newport.toUInt()); - ChangeLocationTo(url, false); -} - -String Location::hostname() { - KURL url = GetFrameUrl(m_frame); - return url.host(); + navigateIfAllowed(m_frame, url, false); } void Location::setHostname(const String& hostname) { @@ -132,15 +181,7 @@ void Location::setHostname(const String& hostname) { KURL url = m_frame->loader()->url(); url.setHost(hostname); - ChangeLocationTo(url, false); -} - -String Location::href() { - KURL url = GetFrameUrl(m_frame); - - if (!url.hasPath()) - return url.prettyURL() + "/"; - return url.prettyURL(); + navigateIfAllowed(m_frame, url, false); } void Location::setHref(const String& value) { @@ -157,13 +198,8 @@ void Location::setHref(const String& value) { // Allows cross domain access except javascript url. if (!parseURL(value).startsWith("javascript:", false) || ScriptController::isSafeScript(m_frame)) { - ChangeLocationTo(active_frame->loader()->completeURL(value), false); - } -} - -String Location::pathname() { - KURL url = GetFrameUrl(m_frame); - return url.path().isEmpty() ? "/" : url.path(); + navigateIfAllowed(m_frame, active_frame->loader()->completeURL(value), false); + } } void Location::setPathname(const String& pathname) { @@ -173,12 +209,7 @@ void Location::setPathname(const String& pathname) { KURL url = m_frame->loader()->url(); url.setPath(pathname); - ChangeLocationTo(url, false); -} - -String Location::port() { - KURL url = GetFrameUrl(m_frame); - return url.port() ? String::number((int)url.port()) : String(); + navigateIfAllowed(m_frame, url, false); } void Location::setPort(const String& port) { @@ -188,12 +219,7 @@ void Location::setPort(const String& port) { KURL url = m_frame->loader()->url(); url.setPort(port.toUInt()); - ChangeLocationTo(url, false); -} - -String Location::protocol() { - KURL url = GetFrameUrl(m_frame); - return url.protocol() + ":"; + navigateIfAllowed(m_frame, url, false); } void Location::setProtocol(const String& protocol) { @@ -203,12 +229,7 @@ void Location::setProtocol(const String& protocol) { KURL url = m_frame->loader()->url(); url.setProtocol(protocol); - ChangeLocationTo(url, false); -} - -String Location::search() { - KURL url = GetFrameUrl(m_frame); - return url.query(); + navigateIfAllowed(m_frame, url, false); } void Location::setSearch(const String& query) { @@ -218,23 +239,23 @@ void Location::setSearch(const String& query) { KURL url = m_frame->loader()->url(); url.setQuery(query); - ChangeLocationTo(url, false); + navigateIfAllowed(m_frame, url, false); } void Location::reload(bool forceget) { - if (!m_frame) - return; + if (!m_frame) + return; - Frame* active_frame = ScriptController::retrieveActiveFrame(); - if (!active_frame) - return; + Frame* active_frame = ScriptController::retrieveActiveFrame(); + if (!active_frame) + return; - if (!ScriptController::isSafeScript(m_frame)) - return; + if (!ScriptController::isSafeScript(m_frame)) + return; - bool userGesture = active_frame->script()->processingUserGesture(); - m_frame->loader()->scheduleRefresh(userGesture); + bool userGesture = active_frame->script()->processingUserGesture(); + m_frame->loader()->scheduleRefresh(userGesture); } void Location::replace(const String& url) { @@ -251,7 +272,7 @@ void Location::replace(const String& url) { // Allows cross domain access except javascript url. if (!parseURL(url).startsWith("javascript:", false) || ScriptController::isSafeScript(m_frame)) { - ChangeLocationTo(active_frame->loader()->completeURL(url), true); + navigateIfAllowed(m_frame, active_frame->loader()->completeURL(url), true); } } @@ -268,13 +289,10 @@ void Location::assign(const String& url) { if (!parseURL(url).startsWith("javascript:", false) || ScriptController::isSafeScript(m_frame)) { - ChangeLocationTo(active_frame->loader()->completeURL(url), false); + navigateIfAllowed(m_frame, active_frame->loader()->completeURL(url), false); } } +#endif // USE(V8) -String Location::toString() { - return href(); -} - } // namespace WebCore diff --git a/webkit/port/page/Location.h b/webkit/port/page/Location.h index ef77651..66ce396 100644 --- a/webkit/port/page/Location.h +++ b/webkit/port/page/Location.h @@ -20,35 +20,31 @@ class Location : public RefCounted<Location> { Frame* frame() { return m_frame; } - String hash(); + String protocol() const; + String host() const; + String hostname() const; + String port() const; + String pathname() const; + String search() const; + String hash() const; + String href() const; + + String toString() const; + +#if USE(V8) void setHash(const String& str); - - String host(); void setHost(const String& str); - - String hostname(); void setHostname(const String&); - - String href(); void setHref(const String&); - - String pathname(); void setPathname(const String&); - - String port(); void setPort(const String&); - - String protocol(); void setProtocol(const String&); - - String search(); void setSearch(const String&); void reload(bool forceget); void replace(const String& url); void assign(const String& url); - - String toString(); +#endif void disconnectFrame() { m_frame = 0; } @@ -57,9 +53,9 @@ class Location : public RefCounted<Location> { Frame* m_frame; +#if USE(V8) friend class WindowV8; - - void ChangeLocationTo(const KURL& url, bool lock_history); +#endif }; } // namespace WebCore |