summaryrefslogtreecommitdiffstats
path: root/src/core/web_contents_delegate_qt.cpp
diff options
context:
space:
mode:
authorPeter Varga <pvarga@inf.u-szeged.hu>2018-02-07 17:05:37 +0100
committerPeter Varga <pvarga@inf.u-szeged.hu>2018-02-21 14:51:19 +0000
commit732d09331c1e4efa51501aae9bcd6924eecdd5c3 (patch)
tree2376a15e9a7f91f91087f9681e09f4ce2c6961ca /src/core/web_contents_delegate_qt.cpp
parent5983f75003dde37b5429b126149b3bcc6c02d4dc (diff)
Expose actual URL for data URLs instead of the virtual URL in the API
Chromium considers the actual URL as "scary" therefore prefers to pass a simpler URL via the WebContents::GetVisibleURL() content API function. For data URLs, use the actual URL instead to keep their anchor information. Task-number: QTBUG-64972 Change-Id: I74db3e5dd22a728656a58e50a4e3fba93b82dae2 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/core/web_contents_delegate_qt.cpp')
-rw-r--r--src/core/web_contents_delegate_qt.cpp31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/core/web_contents_delegate_qt.cpp b/src/core/web_contents_delegate_qt.cpp
index 3d2337884..bec4d5d2f 100644
--- a/src/core/web_contents_delegate_qt.cpp
+++ b/src/core/web_contents_delegate_qt.cpp
@@ -76,6 +76,7 @@
#include "content/public/common/frame_navigate_params.h"
#include "content/public/common/url_constants.h"
#include "content/public/common/web_preferences.h"
+#include "net/base/data_url.h"
#include <QDesktopServices>
#include <QTimer>
@@ -150,10 +151,38 @@ content::WebContents *WebContentsDelegateQt::OpenURLFromTab(content::WebContents
return target;
}
+static bool shouldUseActualURL(const content::NavigationEntry *entry)
+{
+ if (!entry)
+ return false;
+
+ // Show actual URL for data URLs only
+ if (!entry->GetURL().SchemeIs(url::kDataScheme))
+ return false;
+
+ // Keep view-source: prefix
+ if (entry->IsViewSourceMode())
+ return false;
+
+ // Do not show data URL of interstitial and error pages
+ if (entry->GetPageType() != content::PAGE_TYPE_NORMAL)
+ return false;
+
+ // Show invalid data URL
+ std::string mime_type, charset, data;
+ if (!net::DataURL::Parse(entry->GetURL(), &mime_type, &charset, &data))
+ return false;
+
+ // Do not show empty data URL
+ return !data.empty();
+}
+
void WebContentsDelegateQt::NavigationStateChanged(content::WebContents* source, content::InvalidateTypes changed_flags)
{
if (changed_flags & content::INVALIDATE_TYPE_URL) {
- QUrl newUrl = toQt(source->GetVisibleURL());
+ // If there is a visible entry there are special cases when we dont wan't to use the actual URL
+ content::NavigationEntry *entry = source->GetController().GetVisibleEntry();
+ QUrl newUrl = shouldUseActualURL(entry) ? toQt(entry->GetURL()) : toQt(source->GetVisibleURL());
if (m_url != newUrl) {
m_url = newUrl;
m_viewClient->urlChanged(m_url);