diff options
author | kristianm@chromium.org <kristianm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-16 23:42:57 +0000 |
---|---|---|
committer | kristianm@chromium.org <kristianm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-16 23:42:57 +0000 |
commit | f16cc6780f459ab3167725d4814669daf2a3b0e2 (patch) | |
tree | 96f0a1a35f6d603506012d60a732f38df41af23c | |
parent | 53e193d506a88d8367cd572d9d706846d57db215 (diff) | |
download | chromium_src-f16cc6780f459ab3167725d4814669daf2a3b0e2.zip chromium_src-f16cc6780f459ab3167725d4814669daf2a3b0e2.tar.gz chromium_src-f16cc6780f459ab3167725d4814669daf2a3b0e2.tar.bz2 |
Allow the max url length to be overridden
This is needed for WebView Classic compatibility, and since it shipped with KK it is needed to finish unforking.
There is no define to separate between Android WebView and
Chrome for Android which is why this is done with a setter
function instead of a define.
NOTRY=true
BUG=298495
Review URL: https://codereview.chromium.org/112053002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@241065 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | android_webview/browser/aw_browser_main_parts.cc | 4 | ||||
-rw-r--r-- | content/browser/web_contents/web_contents_impl.cc | 5 | ||||
-rw-r--r-- | content/browser/web_contents/web_contents_impl_unittest.cc | 3 | ||||
-rw-r--r-- | content/public/common/common_param_traits.cc | 5 | ||||
-rw-r--r-- | content/public/common/content_constants.cc | 1 | ||||
-rw-r--r-- | content/public/common/content_constants.h | 7 | ||||
-rw-r--r-- | content/public/common/url_utils.cc | 19 | ||||
-rw-r--r-- | content/public/common/url_utils.h | 25 | ||||
-rw-r--r-- | content/renderer/render_view_impl.cc | 6 |
9 files changed, 59 insertions, 16 deletions
diff --git a/android_webview/browser/aw_browser_main_parts.cc b/android_webview/browser/aw_browser_main_parts.cc index 5f81da8..b300780 100644 --- a/android_webview/browser/aw_browser_main_parts.cc +++ b/android_webview/browser/aw_browser_main_parts.cc @@ -13,6 +13,7 @@ #include "content/public/browser/render_process_host.h" #include "content/public/common/content_client.h" #include "content/public/common/result_codes.h" +#include "content/public/common/url_utils.h" #include "net/android/network_change_notifier_factory_android.h" #include "net/base/network_change_notifier.h" #include "ui/base/l10n/l10n_util_android.h" @@ -59,6 +60,9 @@ int AwBrowserMainParts::PreCreateThreads() { void AwBrowserMainParts::PreMainMessageLoopRun() { browser_context_->PreMainMessageLoopRun(); + // This is needed for WebView Classic backwards compatibility + // See crbug.com/298495 + content::SetMaxURLChars(20 * 1024 * 1024); } bool AwBrowserMainParts::MainMessageLoopRun(int* result_code) { diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc index 2236fa1..554c220 100644 --- a/content/browser/web_contents/web_contents_impl.cc +++ b/content/browser/web_contents/web_contents_impl.cc @@ -78,6 +78,7 @@ #include "content/public/common/page_zoom.h" #include "content/public/common/result_codes.h" #include "content/public/common/url_constants.h" +#include "content/public/common/url_utils.h" #include "net/base/mime_util.h" #include "net/base/net_util.h" #include "net/http/http_cache.h" @@ -1701,8 +1702,8 @@ bool WebContentsImpl::NavigateToEntry( // The renderer will reject IPC messages with URLs longer than // this limit, so don't attempt to navigate with a longer URL. - if (entry.GetURL().spec().size() > kMaxURLChars) { - LOG(WARNING) << "Refusing to load URL as it exceeds " << kMaxURLChars + if (entry.GetURL().spec().size() > GetMaxURLChars()) { + LOG(WARNING) << "Refusing to load URL as it exceeds " << GetMaxURLChars() << " characters."; return false; } diff --git a/content/browser/web_contents/web_contents_impl_unittest.cc b/content/browser/web_contents/web_contents_impl_unittest.cc index 1f11994..1be4a3c 100644 --- a/content/browser/web_contents/web_contents_impl_unittest.cc +++ b/content/browser/web_contents/web_contents_impl_unittest.cc @@ -21,6 +21,7 @@ #include "content/public/common/bindings_policy.h" #include "content/public/common/content_constants.h" #include "content/public/common/url_constants.h" +#include "content/public/common/url_utils.h" #include "content/public/test/mock_render_process_host.h" #include "content/public/test/test_browser_thread.h" #include "content/public/test/test_utils.h" @@ -416,7 +417,7 @@ TEST_F(WebContentsImplTest, SimpleNavigation) { TEST_F(WebContentsImplTest, NavigateToExcessivelyLongURL) { // Construct a URL that's kMaxURLChars + 1 long of all 'a's. const GURL url(std::string("http://example.org/").append( - kMaxURLChars + 1, 'a')); + GetMaxURLChars() + 1, 'a')); controller().LoadURL( url, Referrer(), PAGE_TRANSITION_GENERATED, std::string()); diff --git a/content/public/common/common_param_traits.cc b/content/public/common/common_param_traits.cc index 0501683..4e5d92b 100644 --- a/content/public/common/common_param_traits.cc +++ b/content/public/common/common_param_traits.cc @@ -7,6 +7,7 @@ #include "content/public/common/content_constants.h" #include "content/public/common/page_state.h" #include "content/public/common/referrer.h" +#include "content/public/common/url_utils.h" #include "net/base/host_port_pair.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/gfx/rect.h" @@ -50,7 +51,7 @@ struct SkBitmap_Data { namespace IPC { void ParamTraits<GURL>::Write(Message* m, const GURL& p) { - DCHECK(p.possibly_invalid_spec().length() <= content::kMaxURLChars); + DCHECK(p.possibly_invalid_spec().length() <= content::GetMaxURLChars()); // Beware of print-parse inconsistency which would change an invalid // URL into a valid one. Ideally, the message would contain this flag @@ -69,7 +70,7 @@ void ParamTraits<GURL>::Write(Message* m, const GURL& p) { bool ParamTraits<GURL>::Read(const Message* m, PickleIterator* iter, GURL* p) { std::string s; - if (!m->ReadString(iter, &s) || s.length() > content::kMaxURLChars) { + if (!m->ReadString(iter, &s) || s.length() > content::GetMaxURLChars()) { *p = GURL(); return false; } diff --git a/content/public/common/content_constants.cc b/content/public/common/content_constants.cc index 2083d27..b19888b 100644 --- a/content/public/common/content_constants.cc +++ b/content/public/common/content_constants.cc @@ -25,7 +25,6 @@ const char kFlashPluginSplDescription[] = "FutureSplash Player"; const size_t kMaxRendererProcessCount = 82; const int kMaxSessionHistoryEntries = 50; const size_t kMaxTitleChars = 4 * 1024; -const size_t kMaxURLChars = 2 * 1024 * 1024; const size_t kMaxURLDisplayChars = 32 * 1024; #if defined(GOOGLE_CHROME_BUILD) diff --git a/content/public/common/content_constants.h b/content/public/common/content_constants.h index a3473fd..cad536e 100644 --- a/content/public/common/content_constants.h +++ b/content/public/common/content_constants.h @@ -41,13 +41,6 @@ extern const int kMaxSessionHistoryEntries; // to accept in the browser process. extern const size_t kMaxTitleChars; -// The maximum number of characters in the URL that we're willing to accept -// in the browser process. It is set low enough to avoid damage to the browser -// but high enough that a web site can abuse location.hash for a little storage. -// We have different values for "max accepted" and "max displayed" because -// a data: URI may be legitimately massive, but the full URI would kill all -// known operating systems if you dropped it into a UI control. -CONTENT_EXPORT extern const size_t kMaxURLChars; CONTENT_EXPORT extern const size_t kMaxURLDisplayChars; extern const char kStatsFilename[]; diff --git a/content/public/common/url_utils.cc b/content/public/common/url_utils.cc index 577ea50..1aa1a97 100644 --- a/content/public/common/url_utils.cc +++ b/content/public/common/url_utils.cc @@ -4,13 +4,19 @@ #include "content/public/common/url_utils.h" +#include "base/base_switches.h" +#include "base/command_line.h" +#include "base/logging.h" #include "build/build_config.h" #include "content/common/savable_url_schemes.h" +#include "content/public/common/content_switches.h" #include "content/public/common/url_constants.h" #include "url/gurl.h" namespace content { +static size_t g_max_url_size = 2 * 1024 * 1024; + const char* const* GetSavableSchemes() { return GetSavableSchemesInternal(); } @@ -31,4 +37,17 @@ bool IsSavableURL(const GURL& url) { return false; } +#if defined(OS_ANDROID) +void SetMaxURLChars(size_t max_chars) { + // Check that it is not used by a multiprocesses embedder + CommandLine* cmd = CommandLine::ForCurrentProcess(); + CHECK(cmd->HasSwitch(switches::kSingleProcess)); + g_max_url_size = max_chars; +} +#endif + +size_t GetMaxURLChars() { + return g_max_url_size; +} + } // namespace content diff --git a/content/public/common/url_utils.h b/content/public/common/url_utils.h index 0b67ab8..1d1f68d 100644 --- a/content/public/common/url_utils.h +++ b/content/public/common/url_utils.h @@ -5,6 +5,9 @@ #ifndef CONTENT_PUBLIC_COMMON_URL_UTILS_H_ #define CONTENT_PUBLIC_COMMON_URL_UTILS_H_ +#include <stddef.h> // For size_t + +#include "build/build_config.h" #include "content/common/content_export.h" class GURL; @@ -22,6 +25,28 @@ CONTENT_EXPORT bool HasWebUIScheme(const GURL& url); // Check whether we can do the saving page operation for the specified URL. CONTENT_EXPORT bool IsSavableURL(const GURL& url); +#if defined(OS_ANDROID) +// Set a new max size for URL's that we are willing to accept in the browser +// process. +// Should not be used except by Android WebView for backwards compatibility. +// Should be called early in start up before forking child processes. +// +// This is for supporting legacy android apps, android webview needs to +// support loading long data urls. In chrome, the url length is limited to 2M to +// prevent renderer process DOS-ing the browser process. So only for android +// webview, increase the limit to 20M, which is a large enough value to satisfy +// legacy app compatibility requirements. +CONTENT_EXPORT void SetMaxURLChars(size_t max_chars); +#endif + +// The maximum number of characters in the URL that we're willing to accept +// in the browser process. It is set low enough to avoid damage to the browser +// but high enough that a web site can abuse location.hash for a little storage. +// We have different values for "max accepted" and "max displayed" because +// a data: URI may be legitimately massive, but the full URI would kill all +// known operating systems if you dropped it into a UI control. +CONTENT_EXPORT size_t GetMaxURLChars(); + } // namespace content #endif // CONTENT_PUBLIC_COMMON_URL_UTILS_H_ diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc index 07cad53..73c2ff2 100644 --- a/content/renderer/render_view_impl.cc +++ b/content/renderer/render_view_impl.cc @@ -2695,7 +2695,7 @@ void RenderViewImpl::showContextMenu( // in the context menu. // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large // data encoded images. We should have a way to save them. - if (params.src_url.spec().size() > kMaxURLChars) + if (params.src_url.spec().size() > GetMaxURLChars()) params.src_url = GURL(); context_menu_node_ = data.node; @@ -2735,9 +2735,9 @@ void RenderViewImpl::UpdateTargetURL(const GURL& url, pending_target_url_ = latest_url; target_url_status_ = TARGET_PENDING; } else { - // URLs larger than |kMaxURLChars| cannot be sent through IPC - + // URLs larger than |MaxURLChars()| cannot be sent through IPC - // see |ParamTraits<GURL>|. - if (latest_url.possibly_invalid_spec().size() > kMaxURLChars) + if (latest_url.possibly_invalid_spec().size() > GetMaxURLChars()) latest_url = GURL(); Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url)); target_url_ = latest_url; |