diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-18 05:00:10 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-18 05:00:10 +0000 |
commit | 9966325b7197accb38248ebf48983bf0d06c525b (patch) | |
tree | b33fb7ebf51ae47074e5db5c7f255ffd7c9e75f9 /chrome | |
parent | 9db98a2b1c29c70dc1a2a8a9d5169c7c5411297c (diff) | |
download | chromium_src-9966325b7197accb38248ebf48983bf0d06c525b.zip chromium_src-9966325b7197accb38248ebf48983bf0d06c525b.tar.gz chromium_src-9966325b7197accb38248ebf48983bf0d06c525b.tar.bz2 |
Remove the last Chrome dependencies from renderer, and enforce no more includes through DEPS. I also added DEPS checking for gpu/plugin/worker directories as well. I moved the Chrome specific browser tests to the chrome directory, and removed render_widget_unittest since it didn't seem to be testing much (there are tests that test it much more fully). I had to move bindings_policy.h, which ideally would be split into separate pieces so that the content layer only has to know about the content bindings. Given that it's basically an enum, I moved the whole file now since it's used in a lot of places, and the value of turning on DEPS checking is really high.
Review URL: http://codereview.chromium.org/6874038
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81924 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
43 files changed, 870 insertions, 267 deletions
diff --git a/chrome/browser/chromeos/login/web_page_view.cc b/chrome/browser/chromeos/login/web_page_view.cc index 0ab31ae..0ee2f4d 100644 --- a/chrome/browser/chromeos/login/web_page_view.cc +++ b/chrome/browser/chromeos/login/web_page_view.cc @@ -11,10 +11,10 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/chromeos/login/helper.h" #include "chrome/browser/chromeos/login/rounded_rect_painter.h" -#include "chrome/common/bindings_policy.h" #include "content/browser/child_process_security_policy.h" #include "content/browser/tab_contents/tab_contents.h" #include "content/browser/webui/web_ui.h" +#include "content/common/bindings_policy.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" #include "ipc/ipc_message.h" diff --git a/chrome/browser/debugger/devtools_window.cc b/chrome/browser/debugger/devtools_window.cc index b8a0f8b..bef318d 100644 --- a/chrome/browser/debugger/devtools_window.cc +++ b/chrome/browser/debugger/devtools_window.cc @@ -22,7 +22,6 @@ #include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" -#include "chrome/common/bindings_policy.h" #include "chrome/common/pref_names.h" #include "chrome/common/render_messages.h" #include "chrome/common/url_constants.h" @@ -32,6 +31,7 @@ #include "content/browser/tab_contents/navigation_entry.h" #include "content/browser/tab_contents/tab_contents.h" #include "content/browser/tab_contents/tab_contents_view.h" +#include "content/common/bindings_policy.h" #include "content/common/notification_service.h" #include "grit/generated_resources.h" diff --git a/chrome/browser/desktop_notification_handler.cc b/chrome/browser/desktop_notification_handler.cc index 986425a..e6654ec 100644 --- a/chrome/browser/desktop_notification_handler.cc +++ b/chrome/browser/desktop_notification_handler.cc @@ -7,6 +7,7 @@ #include "chrome/browser/notifications/desktop_notification_service.h" #include "chrome/browser/notifications/desktop_notification_service_factory.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/common/url_constants.h" #include "content/browser/renderer_host/render_process_host.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/renderer_host/render_view_host_delegate.h" @@ -37,6 +38,16 @@ bool DesktopNotificationHandler::OnMessageReceived( void DesktopNotificationHandler::OnShow( const DesktopNotificationHostMsg_Show_Params& params) { + // Disallow HTML notifications from unwanted schemes. javascript: + // in particular allows unwanted cross-domain access. + GURL url = params.contents_url; + if (!url.SchemeIs(chrome::kHttpScheme) && + !url.SchemeIs(chrome::kHttpsScheme) && + !url.SchemeIs(chrome::kExtensionScheme) && + !url.SchemeIs(chrome::kDataScheme)) { + return; + } + RenderProcessHost* process = render_view_host()->process(); DesktopNotificationService* service = DesktopNotificationServiceFactory::GetForProfile(process->profile()); diff --git a/chrome/browser/extensions/extension_host.cc b/chrome/browser/extensions/extension_host.cc index a930350..142a559 100644 --- a/chrome/browser/extensions/extension_host.cc +++ b/chrome/browser/extensions/extension_host.cc @@ -24,7 +24,6 @@ #include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/webui/chrome_web_ui_factory.h" -#include "chrome/common/bindings_policy.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_constants.h" @@ -39,6 +38,7 @@ #include "content/browser/site_instance.h" #include "content/browser/tab_contents/tab_contents.h" #include "content/browser/tab_contents/tab_contents_view.h" +#include "content/common/bindings_policy.h" #include "content/common/native_web_keyboard_event.h" #include "content/common/notification_service.h" #include "content/common/view_messages.h" diff --git a/chrome/browser/extensions/extension_web_ui.cc b/chrome/browser/extensions/extension_web_ui.cc index c6c9611..1a9b122 100644 --- a/chrome/browser/extensions/extension_web_ui.cc +++ b/chrome/browser/extensions/extension_web_ui.cc @@ -18,7 +18,6 @@ #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" -#include "chrome/common/bindings_policy.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_constants.h" @@ -27,6 +26,7 @@ #include "chrome/common/url_constants.h" #include "content/browser/renderer_host/render_widget_host_view.h" #include "content/browser/tab_contents/tab_contents.h" +#include "content/common/bindings_policy.h" #include "content/common/page_transition_types.h" #include "net/base/file_stream.h" #include "third_party/skia/include/core/SkBitmap.h" diff --git a/chrome/browser/external_tab_container_win.cc b/chrome/browser/external_tab_container_win.cc index 4894c2d..c483a78 100644 --- a/chrome/browser/external_tab_container_win.cc +++ b/chrome/browser/external_tab_container_win.cc @@ -30,13 +30,13 @@ #include "chrome/browser/ui/views/tab_contents/render_view_context_menu_views.h" #include "chrome/browser/ui/views/tab_contents/tab_contents_container.h" #include "chrome/common/automation_messages.h" -#include "chrome/common/bindings_policy.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/url_constants.h" #include "content/browser/renderer_host/render_process_host.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" #include "content/browser/tab_contents/provisional_load_details.h" +#include "content/common/bindings_policy.h" #include "content/common/native_web_keyboard_event.h" #include "content/common/notification_service.h" #include "content/common/page_transition_types.h" diff --git a/chrome/browser/memory_details.cc b/chrome/browser/memory_details.cc index 4510aa5..ea1c834 100644 --- a/chrome/browser/memory_details.cc +++ b/chrome/browser/memory_details.cc @@ -11,7 +11,6 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/profiles/profile.h" -#include "chrome/common/bindings_policy.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/url_constants.h" #include "content/browser/browser_child_process_host.h" @@ -21,6 +20,7 @@ #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/tab_contents/navigation_entry.h" #include "content/browser/tab_contents/tab_contents.h" +#include "content/common/bindings_policy.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" diff --git a/chrome/browser/notifications/balloon_host.cc b/chrome/browser/notifications/balloon_host.cc index 1edeb2f..9ac175f 100644 --- a/chrome/browser/notifications/balloon_host.cc +++ b/chrome/browser/notifications/balloon_host.cc @@ -12,11 +12,11 @@ #include "chrome/browser/renderer_preferences_util.h" #include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/webui/chrome_web_ui_factory.h" -#include "chrome/common/bindings_policy.h" #include "chrome/common/render_messages.h" #include "chrome/common/url_constants.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/site_instance.h" +#include "content/common/bindings_policy.h" #include "content/common/notification_service.h" #include "content/common/notification_source.h" #include "content/common/notification_type.h" diff --git a/chrome/browser/prerender/prerender_contents.cc b/chrome/browser/prerender/prerender_contents.cc index ebd530a2..96a7386 100644 --- a/chrome/browser/prerender/prerender_contents.cc +++ b/chrome/browser/prerender/prerender_contents.cc @@ -108,7 +108,6 @@ void PrerenderContents::StartPrerendering() { // Hide the RVH, so that we will run at a lower CPU priority. // Once the RVH is being swapped into a tab, we will Restore it again. render_view_host_->WasHidden(); - render_view_host_->AllowScriptToClose(true); // Register this with the ResourceDispatcherHost as a prerender // RenderViewHost. This must be done before the Navigate message to catch all @@ -439,8 +438,8 @@ bool PrerenderContents::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame, OnDidStartProvisionalLoadForFrame) IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL) - IPC_MESSAGE_HANDLER(ViewHostMsg_MaybeCancelPrerender, - OnMaybeCancelPrerender) + IPC_MESSAGE_HANDLER(ViewHostMsg_MaybeCancelPrerenderForHTML5Media, + OnMaybeCancelPrerenderForHTML5Media) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP_EX() @@ -479,16 +478,8 @@ void PrerenderContents::OnUpdateFaviconURL( } } -void PrerenderContents::OnMaybeCancelPrerender( - PrerenderCancellationReason reason) { - switch (reason) { - case PRERENDER_CANCELLATION_REASON_HTML5_MEDIA: - Destroy(FINAL_STATUS_HTML5_MEDIA); - return; - default: - LOG(DFATAL) << "Invalid reason " << reason - << " in OnMaybeCancelPrerender."; - } +void PrerenderContents::OnMaybeCancelPrerenderForHTML5Media() { + Destroy(FINAL_STATUS_HTML5_MEDIA); } bool PrerenderContents::AddAliasURL(const GURL& url) { diff --git a/chrome/browser/prerender/prerender_contents.h b/chrome/browser/prerender/prerender_contents.h index 541006a..6d9245d 100644 --- a/chrome/browser/prerender/prerender_contents.h +++ b/chrome/browser/prerender/prerender_contents.h @@ -15,7 +15,6 @@ #include "chrome/browser/tab_contents/render_view_host_delegate_helper.h" #include "chrome/browser/ui/app_modal_dialogs/js_modal_dialog.h" #include "chrome/common/icon_messages.h" -#include "chrome/common/prerender_constants.h" #include "chrome/common/view_types.h" #include "content/browser/renderer_host/render_view_host_delegate.h" #include "content/common/notification_registrar.h" @@ -208,10 +207,8 @@ class PrerenderContents : public RenderViewHostDelegate, void OnDidStartProvisionalLoadForFrame(int64 frame_id, bool main_frame, const GURL& url); - void OnUpdateFaviconURL(int32 page_id, const std::vector<FaviconURL>& urls); - - void OnMaybeCancelPrerender(PrerenderCancellationReason reason); + void OnMaybeCancelPrerenderForHTML5Media(); // Adds an alias URL, for one of the many redirections. Returns whether // the URL is valid. diff --git a/chrome/browser/prerender/prerender_manager.cc b/chrome/browser/prerender/prerender_manager.cc index 5c3c3b1..f560fa6 100644 --- a/chrome/browser/prerender/prerender_manager.cc +++ b/chrome/browser/prerender/prerender_manager.cc @@ -12,7 +12,6 @@ #include "chrome/browser/prerender/prerender_contents.h" #include "chrome/browser/prerender/prerender_final_status.h" #include "chrome/browser/profiles/profile.h" -#include "chrome/common/render_messages.h" #include "content/browser/browser_thread.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/renderer_host/render_process_host.h" @@ -20,6 +19,7 @@ #include "content/browser/tab_contents/render_view_host_manager.h" #include "content/browser/tab_contents/tab_contents.h" #include "content/common/notification_service.h" +#include "content/common/view_messages.h" #include "googleurl/src/url_parse.h" #include "googleurl/src/url_canon.h" #include "googleurl/src/url_util.h" diff --git a/chrome/browser/sidebar/sidebar_container.cc b/chrome/browser/sidebar/sidebar_container.cc index 529eb8f..c673906 100644 --- a/chrome/browser/sidebar/sidebar_container.cc +++ b/chrome/browser/sidebar/sidebar_container.cc @@ -7,7 +7,6 @@ #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/renderer_host/browser_render_process_host.h" -#include "chrome/common/bindings_policy.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_resource.h" #include "chrome/common/extensions/extension_sidebar_defaults.h" @@ -17,6 +16,7 @@ #include "content/browser/tab_contents/navigation_entry.h" #include "content/browser/tab_contents/tab_contents.h" #include "content/browser/tab_contents/tab_contents_view.h" +#include "content/common/bindings_policy.h" #include "googleurl/src/gurl.h" #include "third_party/skia/include/core/SkBitmap.h" diff --git a/chrome/browser/tab_contents/background_contents.cc b/chrome/browser/tab_contents/background_contents.cc index 8b30787..c994fad 100644 --- a/chrome/browser/tab_contents/background_contents.cc +++ b/chrome/browser/tab_contents/background_contents.cc @@ -31,7 +31,6 @@ BackgroundContents::BackgroundContents(SiteInstance* site_instance, // TODO(rafaelw): Implement correct session storage. render_view_host_ = new RenderViewHost(site_instance, this, routing_id, NULL); - render_view_host_->AllowScriptToClose(true); // Close ourselves when the application is shutting down. registrar_.Add(this, NotificationType::APP_TERMINATING, diff --git a/chrome/browser/tab_contents/tab_contents_view_mac.mm b/chrome/browser/tab_contents/tab_contents_view_mac.mm index fd2cd1e..cf8efdc 100644 --- a/chrome/browser/tab_contents/tab_contents_view_mac.mm +++ b/chrome/browser/tab_contents/tab_contents_view_mac.mm @@ -28,6 +28,7 @@ #include "content/common/notification_details.h" #include "content/common/notification_source.h" #include "content/common/notification_type.h" +#include "content/common/view_messages.h" #include "skia/ext/skia_utils_mac.h" #import "third_party/mozilla/NSPasteboard+Utils.h" diff --git a/chrome/browser/tab_contents/web_contents_unittest.cc b/chrome/browser/tab_contents/web_contents_unittest.cc index cc26c77..6057195 100644 --- a/chrome/browser/tab_contents/web_contents_unittest.cc +++ b/chrome/browser/tab_contents/web_contents_unittest.cc @@ -8,7 +8,6 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/prefs/pref_value_store.h" -#include "chrome/common/bindings_policy.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/pref_names.h" #include "chrome/common/render_messages.h" @@ -25,6 +24,7 @@ #include "content/browser/tab_contents/navigation_controller.h" #include "content/browser/tab_contents/navigation_entry.h" #include "content/browser/tab_contents/test_tab_contents.h" +#include "content/common/bindings_policy.h" #include "content/common/view_messages.h" #include "ipc/ipc_channel.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc b/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc index 23bd6fd..e602095 100644 --- a/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc +++ b/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc @@ -32,6 +32,7 @@ #include "chrome/common/render_messages.h" #include "content/browser/tab_contents/tab_contents.h" #include "content/common/notification_service.h" +#include "content/common/view_messages.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" #include "grit/platform_locale_settings.h" diff --git a/chrome/browser/ui/webui/chromeos/enterprise_enrollment_ui.cc b/chrome/browser/ui/webui/chromeos/enterprise_enrollment_ui.cc index 5b4cb24..246c447 100644 --- a/chrome/browser/ui/webui/chromeos/enterprise_enrollment_ui.cc +++ b/chrome/browser/ui/webui/chromeos/enterprise_enrollment_ui.cc @@ -13,11 +13,11 @@ #include "base/values.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/webui/chrome_url_data_manager.h" -#include "chrome/common/bindings_policy.h" #include "chrome/common/jstemplate_builder.h" #include "chrome/common/url_constants.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/tab_contents/tab_contents.h" +#include "content/common/bindings_policy.h" #include "content/common/property_bag.h" #include "grit/browser_resources.h" #include "grit/chromium_strings.h" diff --git a/chrome/browser/ui/webui/constrained_html_ui.cc b/chrome/browser/ui/webui/constrained_html_ui.cc index 2bae21f..2e90d0e 100644 --- a/chrome/browser/ui/webui/constrained_html_ui.cc +++ b/chrome/browser/ui/webui/constrained_html_ui.cc @@ -7,9 +7,9 @@ #include "base/lazy_instance.h" #include "base/values.h" #include "chrome/browser/ui/webui/html_dialog_ui.h" -#include "chrome/common/bindings_policy.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/tab_contents/tab_contents.h" +#include "content/common/bindings_policy.h" static base::LazyInstance<PropertyAccessor<ConstrainedHtmlUIDelegate*> > g_constrained_html_ui_property_accessor(base::LINKER_INITIALIZED); diff --git a/chrome/browser/ui/webui/html_dialog_ui.cc b/chrome/browser/ui/webui/html_dialog_ui.cc index 80872aa..871fea2 100644 --- a/chrome/browser/ui/webui/html_dialog_ui.cc +++ b/chrome/browser/ui/webui/html_dialog_ui.cc @@ -7,9 +7,9 @@ #include "base/callback.h" #include "base/lazy_instance.h" #include "base/values.h" -#include "chrome/common/bindings_policy.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/tab_contents/tab_contents.h" +#include "content/common/bindings_policy.h" static base::LazyInstance<PropertyAccessor<HtmlDialogUIDelegate*> > g_html_dialog_ui_property_accessor(base::LINKER_INITIALIZED); diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi index aaeb88f..94971e3 100644 --- a/chrome/chrome_common.gypi +++ b/chrome/chrome_common.gypi @@ -31,7 +31,6 @@ 'common/auto_start_linux.cc', 'common/auto_start_linux.h', 'common/autofill_messages.h', - 'common/bindings_policy.h', 'common/child_process_logging.h', 'common/child_process_logging_linux.cc', 'common/child_process_logging_mac.mm', @@ -67,7 +66,6 @@ 'common/nacl_messages.cc', 'common/nacl_messages.h', 'common/nacl_types.h', - 'common/prerender_constants.h', 'common/profiling.cc', 'common/profiling.h', 'common/ref_counted_util.h', @@ -109,7 +107,7 @@ 'common_constants', 'common_net', 'default_plugin/default_plugin.gyp:default_plugin', - 'safe_browsing_csd_proto', + 'safe_browsing_csd_proto', 'theme_resources', '../app/app.gyp:app_base', '../app/app.gyp:app_resources', @@ -214,7 +212,7 @@ 'common/remoting/chromoting_host_info.h', 'common/render_messages.cc', 'common/render_messages.h', - '<(protoc_out_dir)/chrome/common/safe_browsing/csd.pb.cc', + '<(protoc_out_dir)/chrome/common/safe_browsing/csd.pb.cc', '<(protoc_out_dir)/chrome/common/safe_browsing/csd.pb.h', 'common/search_provider.h', 'common/security_style.h', diff --git a/chrome/chrome_dll.gypi b/chrome/chrome_dll.gypi index e8a7fa1..c701750 100644 --- a/chrome/chrome_dll.gypi +++ b/chrome/chrome_dll.gypi @@ -610,6 +610,7 @@ '../content/common/notification_service.cc', '../content/common/notification_source.cc', '../content/common/sandbox_init_wrapper_win.cc', + '../content/common/url_constants.cc', ], 'msvs_settings': { 'VCLinkerTool': { diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 4b4ff72..94767c6 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1916,7 +1916,6 @@ '../content/renderer/media/audio_renderer_impl_unittest.cc', '../content/renderer/p2p/p2p_transport_impl_unittest.cc', '../content/renderer/paint_aggregator_unittest.cc', - '../content/renderer/render_widget_unittest.cc', '../testing/gtest_mac_unittest.mm', '../third_party/cld/encodings/compact_lang_det/compact_lang_det_unittest_small.cc', '../webkit/fileapi/file_system_dir_url_request_job_unittest.cc', @@ -2357,10 +2356,12 @@ 'browser/ui/webui/file_browse_browsertest.cc', 'browser/ui/webui/mediaplayer_browsertest.cc', 'browser/ui/webui/settings_browsertest.cc', + 'renderer/autofill/autofill_browsertest.cc', 'renderer/autofill/form_autocomplete_browsertest.cc', 'renderer/autofill/form_manager_browsertest.cc', 'renderer/autofill/password_autofill_manager_unittest.cc', 'renderer/page_click_tracker_browsertest.cc', + 'renderer/print_web_view_helper_browsertest.cc', 'renderer/safe_browsing/malware_dom_details_browsertest.cc', 'renderer/safe_browsing/phishing_classifier_browsertest.cc', 'renderer/safe_browsing/phishing_classifier_delegate_browsertest.cc', diff --git a/chrome/common/bindings_policy.h b/chrome/common/bindings_policy.h deleted file mode 100644 index 7d0db25..0000000 --- a/chrome/common/bindings_policy.h +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_COMMON_BINDINGS_POLICY_H__ -#define CHROME_COMMON_BINDINGS_POLICY_H__ -#pragma once - -// This is a utility class that specifies flag values for the types of -// JavaScript bindings exposed to renderers. -class BindingsPolicy { - public: - enum { - // HTML-based UI bindings that allows he js content to send JSON-encoded - // data back to the browser process. - WEB_UI = 1 << 0, - // DOM automation bindings that allows the js content to send JSON-encoded - // data back to automation in the parent process. (By default this isn't - // allowed unless the app has been started up with the --dom-automation - // switch.) - DOM_AUTOMATION = 1 << 1, - // Bindings that allow access to the external host (through automation). - EXTERNAL_HOST = 1 << 2, - // Special bindings with privileged APIs for code running in the extension - // process. - EXTENSION = 1 << 3, - }; - - static bool is_web_ui_enabled(int flags) { - return (flags & WEB_UI) != 0; - } - static bool is_dom_automation_enabled(int flags) { - return (flags & DOM_AUTOMATION) != 0; - } - static bool is_external_host_enabled(int flags) { - return (flags & EXTERNAL_HOST) != 0; - } - static bool is_extension_enabled(int flags) { - return (flags & EXTENSION) != 0; - } -}; - -#endif // CHROME_COMMON_BINDINGS_POLICY_H__ diff --git a/chrome/common/chrome_constants.cc b/chrome/common/chrome_constants.cc index 0ccf500..465a1efe6 100644 --- a/chrome/common/chrome_constants.cc +++ b/chrome/common/chrome_constants.cc @@ -116,8 +116,6 @@ const unsigned int kMaxRendererProcessCount = 42; const int kStatsMaxThreads = 32; const int kStatsMaxCounters = 3000; -const size_t kMaxTitleChars = 4 * 1024; - // We don't enable record mode in the released product because users could // potentially be tricked into running a product in record mode without // knowing it. Enable in debug builds. Playback mode is allowed always, @@ -130,8 +128,6 @@ const bool kRecordModeEnabled = false; const int kHistogramSynchronizerReservedSequenceNumber = 0; -const int kMaxSessionHistoryEntries = 50; - const char* const kUnknownLanguageCode = "und"; const int kJavascriptMessageExpectedDelay = 1000; diff --git a/chrome/common/chrome_constants.h b/chrome/common/chrome_constants.h index 0070a0f..4cc992d 100644 --- a/chrome/common/chrome_constants.h +++ b/chrome/common/chrome_constants.h @@ -74,10 +74,6 @@ extern const unsigned int kMaxRendererProcessCount; extern const int kStatsMaxThreads; extern const int kStatsMaxCounters; -// The maximum number of characters of the document's title that we're willing -// to accept in the browser process. -extern const size_t kMaxTitleChars; - extern const bool kRecordModeEnabled; // Most sequence numbers are used by a renderer when responding to a browser @@ -87,9 +83,6 @@ extern const bool kRecordModeEnabled; // a browser-supplied sequence number. extern const int kHistogramSynchronizerReservedSequenceNumber; -// The maximum number of session history entries per tab. -extern const int kMaxSessionHistoryEntries; - // The language code used when the language of a page could not be detected. // (Matches what the CLD -Compact Language Detection- library reports.) extern const char* const kUnknownLanguageCode; diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index 58410fb..dd92eb7 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -164,10 +164,6 @@ const char kDisableAltWinstation[] = "disable-winsta"; // Replaces the audio IPC layer for <audio> and <video> with a mock audio // device, useful when using remote desktop or machines without sound cards. // This is temporary until we fix the underlying problem. -// -// TODO(scherkus): remove --disable-audio when we have a proper fallback -// mechanism. -const char kDisableAudio[] = "disable-audio"; // Disable CNAME lookup of the host when generating the Kerberos SPN for a // Negotiate challenge. See HttpAuthHandlerNegotiate::CreateSPN @@ -362,9 +358,6 @@ const char kEnableAccelerated2dCanvas[] = "enable-accelerated-2d-canvas"; // Enables the hardware acceleration of plugins. const char kEnableAcceleratedPlugins[] = "enable-accelerated-plugins"; -// Enables WebKit accessibility within the renderer process. -const char kEnableAccessibility[] = "enable-accessibility"; - // Enables AeroPeek for each tab. (This switch only works on Windows 7). const char kEnableAeroPeekTabs[] = "enable-aero-peek-tabs"; @@ -469,9 +462,6 @@ const char kEnableRemoting[] = "enable-remoting"; const char kEnableResourceContentSettings[] = "enable-resource-content-settings"; -// Enable Pepper and JavaScript P2P API. -const char kEnableP2PApi[] = "enable-p2papi"; - // Enable panels (always on-top docked pop-up windows). const char kEnablePanels[] = "enable-panels"; @@ -511,14 +501,6 @@ const char kEnableTcpFastOpen[] = "enable-tcp-fastopen"; // browser window. const char kEnableVerticalTabs[] = "enable-vertical-tabs"; -// Enables support for fullscreen video. Current implementation is -// incomplete and this flag is used for development and testing. -const char kEnableVideoFullscreen[] = "enable-video-fullscreen"; - -// Enables video logging where video elements log playback performance data to -// the debug log. -const char kEnableVideoLogging[] = "enable-video-logging"; - // Spawn threads to watch for excessive delays in specified message loops. // User should set breakpoints on Alarm() to examine problematic thread. // Usage: -enable-watchdog=[ui][io] @@ -909,10 +891,6 @@ const char kSilentDumpOnDCHECK[] = "silent-dump-on-dcheck"; // Replaces the buffered data source for <audio> and <video> with a simplified // resource loader that downloads the entire resource into memory. -// -// TODO(scherkus): remove --simple-data-source when our media resource loading -// is cleaned up and playback testing completed. -const char kSimpleDataSource[] = "simple-data-source"; // Start the browser maximized, regardless of any previous settings. const char kStartMaximized[] = "start-maximized"; diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index e624157..8eae4b0 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -61,7 +61,6 @@ extern const char kDiagnostics[]; extern const char kDisableAcceleratedLayers[]; extern const char kDisableAcceleratedVideo[]; extern const char kDisableAltWinstation[]; -extern const char kDisableAudio[]; extern const char kDisableAuthNegotiateCnameLookup[]; extern const char kDisableBackgroundMode[]; extern const char kDisableBackgroundNetworking[]; @@ -111,7 +110,6 @@ extern const char kDomAutomationController[]; extern const char kDumpHistogramsOnExit[]; extern const char kEnableAccelerated2dCanvas[]; extern const char kEnableAcceleratedPlugins[]; -extern const char kEnableAccessibility[]; extern const char kEnableAeroPeekTabs[]; extern const char kEnableAuthNegotiatePort[]; extern const char kEnableClientSidePhishingInterstitial[]; @@ -137,7 +135,6 @@ extern const char kEnableIPPooling[]; extern const char kEnableMemoryInfo[]; extern const char kEnableNaCl[]; extern const char kEnableNaClDebug[]; -extern const char kEnableP2PApi[]; extern const char kEnablePanels[]; extern const char kEnablePreconnect[]; extern const char kEnablePrintPreview[]; @@ -154,8 +151,6 @@ extern const char kEnableTabGroupsContextMenu[]; extern const char kEnableTcpFastOpen[]; extern const char kEnableTopSites[]; extern const char kEnableVerticalTabs[]; -extern const char kEnableVideoFullscreen[]; -extern const char kEnableVideoLogging[]; extern const char kEnableWatchdog[]; extern const char kExperimentalSpellcheckerFeatures[]; extern const char kExplicitlyAllowedPorts[]; @@ -249,7 +244,6 @@ extern const char kShowCompositedLayerTree[]; extern const char kShowFPSCounter[]; extern const char kShowIcons[]; extern const char kSilentDumpOnDCHECK[]; -extern const char kSimpleDataSource[]; extern const char kStartMaximized[]; extern const char kSyncAllowInsecureXmppConnection[]; extern const char kSyncInvalidateXmppLogin[]; diff --git a/chrome/common/prerender_constants.h b/chrome/common/prerender_constants.h deleted file mode 100644 index 7712ea0..0000000 --- a/chrome/common/prerender_constants.h +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Constants related to the prerendering feature in chrome. - -#ifndef CHROME_COMMON_PRERENDER_CONSTANTS_H_ -#define CHROME_COMMON_PRERENDER_CONSTANTS_H_ -#pragma once - -namespace prerender { - -enum PrerenderCancellationReason { - PRERENDER_CANCELLATION_REASON_FIRST_UNUSED, - PRERENDER_CANCELLATION_REASON_HTML5_MEDIA, - PRERENDER_CANCELLATION_REASON_LAST_UNUSED, -}; - -} // namespace prerender - -#endif // CHROME_COMMON_PRERENDER_CONSTANTS_H_ diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h index f1ee889..510a8f1 100644 --- a/chrome/common/render_messages.h +++ b/chrome/common/render_messages.h @@ -21,7 +21,6 @@ #include "chrome/common/icon_messages.h" #include "chrome/common/instant_types.h" #include "chrome/common/nacl_types.h" -#include "chrome/common/prerender_constants.h" #include "chrome/common/search_provider.h" #include "chrome/common/thumbnail_score.h" #include "chrome/common/translate_errors.h" @@ -37,15 +36,6 @@ #ifndef CHROME_COMMON_RENDER_MESSAGES_H_ #define CHROME_COMMON_RENDER_MESSAGES_H_ -// Values that may be OR'd together to form the 'flags' parameter of the -// ViewMsg_EnablePreferredSizeChangedMode message. -enum ViewHostMsg_EnablePreferredSizeChangedMode_Flags { - kPreferredSizeNothing, - kPreferredSizeWidth = 1 << 0, - // Requesting the height currently requires a polling loop in render_view.cc. - kPreferredSizeHeightThisIsSlow = 1 << 1, -}; - // Command values for the cmd parameter of the // ViewHost_JavaScriptStressTestControl message. For each command the parameter // passed has a different meaning: @@ -100,7 +90,6 @@ struct ParamTraits<ContentSettings> { #define IPC_MESSAGE_START ChromeMsgStart IPC_ENUM_TRAITS(InstantCompleteBehavior) -IPC_ENUM_TRAITS(prerender::PrerenderCancellationReason) IPC_ENUM_TRAITS(search_provider::OSDDType) IPC_ENUM_TRAITS(search_provider::InstallState) IPC_ENUM_TRAITS(TranslateErrors::Type) @@ -187,15 +176,9 @@ IPC_MESSAGE_CONTROL2(ViewMsg_SetContentSettingsForCurrentURL, GURL /* url */, ContentSettings /* content_settings */) -// Install the first missing pluign. -IPC_MESSAGE_ROUTED0(ViewMsg_InstallMissingPlugin) - // Tells the render view to load all blocked plugins. IPC_MESSAGE_ROUTED0(ViewMsg_LoadBlockedPlugins) -// Tells the render view a prerendered page is about to be displayed. -IPC_MESSAGE_ROUTED0(ViewMsg_DisplayPrerenderedPage) - // Used to instruct the RenderView to go into "view source" mode. IPC_MESSAGE_ROUTED0(ViewMsg_EnableViewSourceMode) @@ -242,18 +225,6 @@ IPC_MESSAGE_ROUTED3(ViewMsg_HandleMessageFromExternalHost, std::string /* The origin */, std::string /* The target*/) -// Sent to the renderer when a popup window should no longer count against -// the current popup count (either because it's not a popup or because it was -// a generated by a user action or because a constrained popup got turned -// into a full window). -IPC_MESSAGE_ROUTED0(ViewMsg_DisassociateFromPopupCount) - -// Sent by the Browser process to alert a window about whether a it should -// allow a scripted window.close(). The renderer assumes every new window is a -// blocked popup until notified otherwise. -IPC_MESSAGE_ROUTED1(ViewMsg_AllowScriptToClose, - bool /* script_can_close */) - IPC_MESSAGE_ROUTED4(ViewMsg_SearchBoxChange, string16 /* value */, bool /* verbatim */, @@ -379,11 +350,6 @@ IPC_SYNC_MESSAGE_ROUTED2_1(ViewHostMsg_GetSearchProviderInstallState, GURL /* inquiry url */, search_provider::InstallState /* install */) -// Stores new inspector setting in the profile. -IPC_MESSAGE_ROUTED2(ViewHostMsg_UpdateInspectorSetting, - std::string, /* key */ - std::string /* value */) - // Send back a string to be recorded by UserMetrics. IPC_MESSAGE_CONTROL1(ViewHostMsg_UserMetricsRecordAction, std::string /* action */) @@ -410,10 +376,6 @@ IPC_MESSAGE_CONTROL2(ViewHostMsg_V8HeapStats, IPC_MESSAGE_CONTROL1(ViewHostMsg_DnsPrefetch, std::vector<std::string> /* hostnames */) -// Notifies when default plugin updates status of the missing plugin. -IPC_MESSAGE_ROUTED1(ViewHostMsg_MissingPluginStatus, - int /* status */) - // Requests the outdated plugins policy. // |policy| is one of ALLOW, BLOCK or ASK. Anything else is an error. // ALLOW means that outdated plugins are allowed, and BLOCK that they should @@ -427,9 +389,6 @@ IPC_MESSAGE_ROUTED2(ViewHostMsg_BlockedOutdatedPlugin, string16, /* name */ GURL /* update_url */) -// Displays a JavaScript out-of-memory message in the infobar. -IPC_MESSAGE_ROUTED0(ViewHostMsg_JSOutOfMemory) - IPC_MESSAGE_ROUTED3(ViewHostMsg_SendCurrentPageAllSavableResourceLinks, std::vector<GURL> /* all savable resource links */, std::vector<GURL> /* all referrers of resource links */, @@ -472,12 +431,6 @@ IPC_MESSAGE_ROUTED4(ViewHostMsg_PageTranslated, std::string /* the translated language */, TranslateErrors::Type /* the error type if available */) -// Message sent from the renderer to the browser to notify it of events which -// may lead to the cancellation of a prerender. The message is sent only when -// the renderer is in prerender mode. -IPC_MESSAGE_ROUTED1(ViewHostMsg_MaybeCancelPrerender, - prerender::PrerenderCancellationReason) - // Suggest results ----------------------------------------------------------- IPC_MESSAGE_ROUTED3(ViewHostMsg_SetSuggestions, @@ -489,16 +442,6 @@ IPC_MESSAGE_ROUTED2(ViewHostMsg_InstantSupportDetermined, int32 /* page_id */, bool /* result */) -// Updates the content restrictions, i.e. to disable print/copy. -IPC_MESSAGE_ROUTED1(ViewHostMsg_UpdateContentRestrictions, - int /* restrictions */) - -// The currently displayed PDF has an unsupported feature. -IPC_MESSAGE_ROUTED0(ViewHostMsg_PDFHasUnsupportedFeature) - -// Brings up SaveAs... dialog (similar to the wrench->SaveAs...). -IPC_MESSAGE_ROUTED0(ViewHostMsg_SaveAs) - // JavaScript related messages ----------------------------------------------- // Notify the JavaScript engine in the render to change its parameters @@ -506,9 +449,3 @@ IPC_MESSAGE_ROUTED0(ViewHostMsg_SaveAs) IPC_MESSAGE_ROUTED2(ViewMsg_JavaScriptStressTestControl, int /* cmd */, int /* param */) - -// Register a new handler for URL requests with the given scheme. -IPC_MESSAGE_ROUTED3(ViewHostMsg_RegisterProtocolHandler, - std::string /* scheme */, - GURL /* url */, - string16 /* title */) diff --git a/chrome/common/url_constants.cc b/chrome/common/url_constants.cc index 9fa04de..bfb3254 100644 --- a/chrome/common/url_constants.cc +++ b/chrome/common/url_constants.cc @@ -9,30 +9,10 @@ namespace chrome { -const char kAboutScheme[] = "about"; -const char kBlobScheme[] = "blob"; -const char kChromeDevToolsScheme[] = "chrome-devtools"; -const char kChromeInternalScheme[] = "chrome-internal"; -const char kChromeUIScheme[] = "chrome"; -const char kDataScheme[] = "data"; -const char kExtensionScheme[] = "chrome-extension"; -const char kFileScheme[] = "file"; -const char kFileSystemScheme[] = "filesystem"; -const char kFtpScheme[] = "ftp"; -const char kHttpScheme[] = "http"; -const char kHttpsScheme[] = "https"; -const char kJavaScriptScheme[] = "javascript"; -const char kMailToScheme[] = "mailto"; -const char kMetadataScheme[] = "metadata"; -const char kUserScriptScheme[] = "chrome-user-script"; -const char kViewSourceScheme[] = "view-source"; - #if defined(OS_CHROMEOS) const char kCrosScheme[] = "cros"; #endif -const char kStandardSchemeSeparator[] = "://"; - const char* kSavableSchemes[] = { kHttpScheme, kHttpsScheme, @@ -46,10 +26,8 @@ const char* kSavableSchemes[] = { const char kAboutAboutURL[] = "about:about"; const char kAboutAppCacheInternalsURL[] = "about:appcache-internals"; -const char kAboutBlankURL[] = "about:blank"; const char kAboutCacheURL[] = "about:cache"; const char kAboutConflicts[] = "about:conflicts"; -const char kAboutCrashURL[] = "about:crash"; const char kAboutKillURL[] = "about:kill"; const char kAboutCreditsURL[] = "about:credits"; const char kAboutDNSURL[] = "about:dns"; @@ -180,8 +158,6 @@ const char kChromeUILoginContainerHost[] = "login-container"; const char kChromeUILoginHost[] = "login"; #endif -const char kUnreachableWebDataURL[] = "chrome://chromewebdata/"; - const char kAppCacheViewInternalsURL[] = "chrome://appcache-internals/"; const char kBlobViewInternalsURL[] = "chrome://blob-internals/"; diff --git a/chrome/common/url_constants.h b/chrome/common/url_constants.h index 80bee61..db4bfbe 100644 --- a/chrome/common/url_constants.h +++ b/chrome/common/url_constants.h @@ -8,30 +8,9 @@ #define CHROME_COMMON_URL_CONSTANTS_H_ #pragma once -namespace chrome { +#include "content/common/url_constants.h" -// Canonical schemes you can use as input to GURL.SchemeIs(). -extern const char kAboutScheme[]; -extern const char kBlobScheme[]; -extern const char kChromeDevToolsScheme[]; -extern const char kChromeInternalScheme[]; -extern const char kChromeUIScheme[]; // The scheme used for WebUIs. -extern const char kCrosScheme[]; // The scheme used for ChromeOS. -extern const char kDataScheme[]; -extern const char kExtensionScheme[]; -extern const char kFileScheme[]; -extern const char kFileSystemScheme[]; -extern const char kFtpScheme[]; -extern const char kHttpScheme[]; -extern const char kHttpsScheme[]; -extern const char kJavaScriptScheme[]; -extern const char kMailToScheme[]; -extern const char kMetadataScheme[]; -extern const char kUserScriptScheme[]; -extern const char kViewSourceScheme[]; - -// Used to separate a standard scheme and the hostname: "://". -extern const char kStandardSchemeSeparator[]; +namespace chrome { // Null terminated list of schemes that are savable. extern const char* kSavableSchemes[]; @@ -39,11 +18,9 @@ extern const char* kSavableSchemes[]; // About URLs (including schemes). extern const char kAboutAboutURL[]; extern const char kAboutAppCacheInternalsURL[]; -extern const char kAboutBlankURL[]; extern const char kAboutBrowserCrash[]; extern const char kAboutConflicts[]; extern const char kAboutCacheURL[]; -extern const char kAboutCrashURL[]; extern const char kAboutKillURL[]; extern const char kAboutCreditsURL[]; extern const char kAboutDNSURL[]; @@ -170,9 +147,6 @@ extern const char kChromeUILoginContainerHost[]; extern const char kChromeUILoginHost[]; #endif -// Special URL used to start a navigation to an error page. -extern const char kUnreachableWebDataURL[]; - // AppCache related URL. extern const char kAppCacheViewInternalsURL[]; diff --git a/chrome/renderer/autofill/autofill_browsertest.cc b/chrome/renderer/autofill/autofill_browsertest.cc new file mode 100644 index 0000000..cfb9965 --- /dev/null +++ b/chrome/renderer/autofill/autofill_browsertest.cc @@ -0,0 +1,161 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/utf_string_conversions.h" +#include "chrome/common/autofill_messages.h" +#include "chrome/test/render_view_test.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" +#include "webkit/glue/form_data.h" +#include "webkit/glue/form_field.h" + +using WebKit::WebDocument; +using WebKit::WebFrame; +using WebKit::WebInputElement; +using WebKit::WebString; +using webkit_glue::FormData; +using webkit_glue::FormField; + +TEST_F(RenderViewTest, SendForms) { + // Don't want any delay for form state sync changes. This will still post a + // message so updates will get coalesced, but as soon as we spin the message + // loop, it will generate an update. + view_->set_send_content_state_immediately(true); + + LoadHTML("<form method=\"POST\">" + " <input type=\"text\" id=\"firstname\"/>" + " <input type=\"text\" id=\"middlename\" autoComplete=\"off\"/>" + " <input type=\"hidden\" id=\"lastname\"/>" + " <select id=\"state\"/>" + " <option>?</option>" + " <option>California</option>" + " <option>Texas</option>" + " </select>" + "</form>"); + + // Verify that "FormsSeen" sends the expected number of fields. + ProcessPendingMessages(); + const IPC::Message* message = render_thread_.sink().GetFirstMessageMatching( + AutofillHostMsg_FormsSeen::ID); + ASSERT_NE(static_cast<IPC::Message*>(NULL), message); + AutofillHostMsg_FormsSeen::Param params; + AutofillHostMsg_FormsSeen::Read(message, ¶ms); + const std::vector<FormData>& forms = params.a; + ASSERT_EQ(1UL, forms.size()); + ASSERT_EQ(3UL, forms[0].fields.size()); + EXPECT_TRUE(forms[0].fields[0].StrictlyEqualsHack( + FormField(string16(), + ASCIIToUTF16("firstname"), + string16(), + ASCIIToUTF16("text"), + WebInputElement::defaultMaxLength(), + false))) << forms[0].fields[0]; + EXPECT_TRUE(forms[0].fields[1].StrictlyEqualsHack( + FormField(string16(), + ASCIIToUTF16("middlename"), + string16(), + ASCIIToUTF16("text"), + WebInputElement::defaultMaxLength(), + false))) << forms[0].fields[1]; + EXPECT_TRUE(forms[0].fields[2].StrictlyEqualsHack( + FormField(string16(), + ASCIIToUTF16("state"), + ASCIIToUTF16("?"), + ASCIIToUTF16("select-one"), + 0, + false))) << forms[0].fields[2]; + + // Verify that |didAcceptAutoFillSuggestion()| sends the expected number of + // fields. + WebFrame* web_frame = GetMainFrame(); + WebDocument document = web_frame->document(); + WebInputElement firstname = + document.getElementById("firstname").to<WebInputElement>(); + + // Accept suggestion that contains a label. Labeled items indicate Autofill + // as opposed to Autocomplete. We're testing this distinction below with + // the |AutofillHostMsg_FillAutofillFormData::ID| message. + autofill_agent_->didAcceptAutoFillSuggestion( + firstname, + WebKit::WebString::fromUTF8("Johnny"), + WebKit::WebString::fromUTF8("Home"), + 1, + -1); + + ProcessPendingMessages(); + const IPC::Message* message2 = render_thread_.sink().GetUniqueMessageMatching( + AutofillHostMsg_FillAutofillFormData::ID); + ASSERT_NE(static_cast<IPC::Message*>(NULL), message2); + AutofillHostMsg_FillAutofillFormData::Param params2; + AutofillHostMsg_FillAutofillFormData::Read(message2, ¶ms2); + const FormData& form2 = params2.b; + ASSERT_EQ(3UL, form2.fields.size()); + EXPECT_TRUE(form2.fields[0].StrictlyEqualsHack( + FormField(string16(), + ASCIIToUTF16("firstname"), + string16(), + ASCIIToUTF16("text"), + WebInputElement::defaultMaxLength(), + false))) << form2.fields[0]; + EXPECT_TRUE(form2.fields[1].StrictlyEqualsHack( + FormField(string16(), + ASCIIToUTF16("middlename"), + string16(), + ASCIIToUTF16("text"), + WebInputElement::defaultMaxLength(), + false))) << form2.fields[1]; + EXPECT_TRUE(form2.fields[2].StrictlyEqualsHack( + FormField(string16(), + ASCIIToUTF16("state"), + ASCIIToUTF16("?"), + ASCIIToUTF16("select-one"), + 0, + false))) << form2.fields[2]; +} + +TEST_F(RenderViewTest, FillFormElement) { + // Don't want any delay for form state sync changes. This will still post a + // message so updates will get coalesced, but as soon as we spin the message + // loop, it will generate an update. + view_->set_send_content_state_immediately(true); + + LoadHTML("<form method=\"POST\">" + " <input type=\"text\" id=\"firstname\"/>" + " <input type=\"text\" id=\"middlename\"/>" + "</form>"); + + // Verify that "FormsSeen" isn't sent, as there are too few fields. + ProcessPendingMessages(); + const IPC::Message* message = render_thread_.sink().GetFirstMessageMatching( + AutofillHostMsg_FormsSeen::ID); + ASSERT_EQ(static_cast<IPC::Message*>(NULL), message); + + // Verify that |didAcceptAutoFillSuggestion()| sets the value of the expected + // field. + WebFrame* web_frame = GetMainFrame(); + WebDocument document = web_frame->document(); + WebInputElement firstname = + document.getElementById("firstname").to<WebInputElement>(); + WebInputElement middlename = + document.getElementById("middlename").to<WebInputElement>(); + middlename.setAutofilled(true); + + // Accept a suggestion in a form that has been auto-filled. This triggers + // the direct filling of the firstname element with value parameter. + autofill_agent_->didAcceptAutoFillSuggestion(firstname, + WebString::fromUTF8("David"), + WebString(), + 0, + 0); + + ProcessPendingMessages(); + const IPC::Message* message2 = render_thread_.sink().GetUniqueMessageMatching( + AutofillHostMsg_FillAutofillFormData::ID); + + // No message should be sent in this case. |firstname| is filled directly. + ASSERT_EQ(static_cast<IPC::Message*>(NULL), message2); + EXPECT_EQ(firstname.value(), WebKit::WebString::fromUTF8("David")); +} diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer/chrome_content_renderer_client.cc index dcbf956..1bdf1b5 100644 --- a/chrome/renderer/chrome_content_renderer_client.cc +++ b/chrome/renderer/chrome_content_renderer_client.cc @@ -66,6 +66,7 @@ #include "grit/renderer_resources.h" #include "net/base/net_errors.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebCache.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" @@ -85,6 +86,7 @@ using autofill::AutofillAgent; using autofill::FormManager; using autofill::PasswordAutofillManager; using WebKit::WebCache; +using WebKit::WebDataSource; using WebKit::WebFrame; using WebKit::WebPlugin; using WebKit::WebPluginParams; @@ -398,7 +400,7 @@ WebPlugin* ChromeContentRendererClient::CreatePlugin( plugin_setting == CONTENT_SETTING_ALLOW || host_setting == CONTENT_SETTING_ALLOW) { // Delay loading plugins if prerendering. - if (render_view->is_prerendering_) { + if (render_view->is_prerendering()) { return CreatePluginPlaceholder( render_view, frame, params, *group, IDR_CLICK_TO_PLAY_PLUGIN_HTML, IDS_PLUGIN_LOAD, true, true); @@ -406,9 +408,8 @@ WebPlugin* ChromeContentRendererClient::CreatePlugin( bool pepper_plugin_was_registered = false; scoped_refptr<webkit::ppapi::PluginModule> pepper_module( - render_view->pepper_delegate_.CreatePepperPlugin( - info.path, - &pepper_plugin_was_registered)); + render_view->pepper_delegate()->CreatePepperPlugin( + info.path, &pepper_plugin_was_registered)); if (pepper_plugin_was_registered) { if (pepper_module) { return render_view->CreatePepperPlugin( @@ -461,6 +462,22 @@ WebPlugin* ChromeContentRendererClient::CreatePluginPlaceholder( return blocked_plugin->plugin(); } +void ChromeContentRendererClient::ShowErrorPage(RenderView* render_view, + WebKit::WebFrame* frame, + int http_status_code) { + // Use an internal error page, if we have one for the status code. + if (LocalizedError::HasStrings(LocalizedError::kHttpErrorDomain, + http_status_code)) { + WebURLError error; + error.unreachableURL = frame->url(); + error.domain = WebString::fromUTF8(LocalizedError::kHttpErrorDomain); + error.reason = http_status_code; + + render_view->LoadNavigationErrorPage( + frame, frame->dataSource()->request(), error, std::string(), true); + } +} + std::string ChromeContentRendererClient::GetNavigationErrorHtml( const WebURLRequest& failed_request, const WebURLError& error) { diff --git a/chrome/renderer/chrome_content_renderer_client.h b/chrome/renderer/chrome_content_renderer_client.h index f2de762..d408bab 100644 --- a/chrome/renderer/chrome_content_renderer_client.h +++ b/chrome/renderer/chrome_content_renderer_client.h @@ -42,6 +42,9 @@ class ChromeContentRendererClient : public content::ContentRendererClient { RenderView* render_view, WebKit::WebFrame* frame, const WebKit::WebPluginParams& params); + virtual void ShowErrorPage(RenderView* render_view, + WebKit::WebFrame* frame, + int http_status_code); virtual std::string GetNavigationErrorHtml( const WebKit::WebURLRequest& failed_request, const WebKit::WebURLError& error); diff --git a/chrome/renderer/chrome_render_view_observer.cc b/chrome/renderer/chrome_render_view_observer.cc index fa43970..f7316fa 100644 --- a/chrome/renderer/chrome_render_view_observer.cc +++ b/chrome/renderer/chrome_render_view_observer.cc @@ -10,29 +10,52 @@ #include "chrome/common/chrome_switches.h" #include "chrome/common/render_messages.h" #include "chrome/common/thumbnail_score.h" +#include "chrome/common/url_constants.h" #include "chrome/renderer/about_handler.h" +#include "chrome/renderer/automation/dom_automation_controller.h" +#include "chrome/renderer/external_host_bindings.h" #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h" #include "chrome/renderer/translate_helper.h" +#include "content/common/bindings_policy.h" #include "content/common/view_messages.h" #include "content/renderer/content_renderer_client.h" -#include "content/renderer/render_view.h" +#include "googleurl/src/gurl.h" +#include "net/base/data_url.h" #include "skia/ext/bitmap_platform_device.h" #include "skia/ext/image_operations.h" #include "skia/ext/platform_canvas.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" #include "ui/gfx/color_utils.h" +#include "ui/gfx/favicon_size.h" #include "ui/gfx/skbitmap_operations.h" +#include "webkit/glue/dom_operations.h" +#include "webkit/glue/image_decoder.h" +#include "webkit/glue/image_resource_fetcher.h" #include "webkit/glue/webkit_glue.h" +#include "v8/include/v8-testing.h" +using WebKit::WebCString; using WebKit::WebDataSource; using WebKit::WebFrame; +using WebKit::WebPageSerializer; +using WebKit::WebPageSerializerClient; using WebKit::WebRect; using WebKit::WebSize; +using WebKit::WebString; +using WebKit::WebURL; +using WebKit::WebURLRequest; using WebKit::WebView; +using WebKit::WebVector; +using webkit_glue::ImageResourceFetcher; // Delay in milliseconds that we'll wait before capturing the page contents // and thumbnail. @@ -94,6 +117,12 @@ ChromeRenderViewObserver::ChromeRenderViewObserver( phishing_classifier_(phishing_classifier), last_indexed_page_id_(-1), ALLOW_THIS_IN_INITIALIZER_LIST(page_info_method_factory_(this)) { + const CommandLine& command_line = *CommandLine::ForCurrentProcess(); + if (command_line.HasSwitch(switches::kDomAutomationController)) { + int old_bindings = render_view->enabled_bindings(); + render_view->set_enabled_bindings( + old_bindings |= BindingsPolicy::DOM_AUTOMATION); + } } ChromeRenderViewObserver::~ChromeRenderViewObserver() { @@ -103,6 +132,17 @@ bool ChromeRenderViewObserver::OnMessageReceived(const IPC::Message& message) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(ChromeRenderViewObserver, message) IPC_MESSAGE_HANDLER(ViewMsg_CaptureSnapshot, OnCaptureSnapshot) + IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost, + OnHandleMessageFromExternalHost) + IPC_MESSAGE_HANDLER(ViewMsg_JavaScriptStressTestControl, + OnJavaScriptStressTestControl) + IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage, + OnGetAllSavableResourceLinksForCurrentPage) + IPC_MESSAGE_HANDLER( + ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks, + OnGetSerializedHtmlDataForCurrentPageWithLocalLinks) + IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavicon, OnDownloadFavicon) + IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() @@ -132,6 +172,115 @@ void ChromeRenderViewObserver::OnCaptureSnapshot() { Send(new ViewHostMsg_Snapshot(routing_id(), snapshot)); } +void ChromeRenderViewObserver::OnHandleMessageFromExternalHost( + const std::string& message, + const std::string& origin, + const std::string& target) { + if (message.empty()) + return; + GetExternalHostBindings()->ForwardMessageFromExternalHost(message, origin, + target); +} + +void ChromeRenderViewObserver::OnJavaScriptStressTestControl(int cmd, + int param) { + if (cmd == kJavaScriptStressTestSetStressRunType) { + v8::Testing::SetStressRunType(static_cast<v8::Testing::StressType>(param)); + } else if (cmd == kJavaScriptStressTestPrepareStressRun) { + v8::Testing::PrepareStressRun(param); + } +} + +void ChromeRenderViewObserver::OnGetAllSavableResourceLinksForCurrentPage( + const GURL& page_url) { + // Prepare list to storage all savable resource links. + std::vector<GURL> resources_list; + std::vector<GURL> referrers_list; + std::vector<GURL> frames_list; + webkit_glue::SavableResourcesResult result(&resources_list, + &referrers_list, + &frames_list); + + if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage( + render_view()->webview(), + page_url, + &result, + chrome::kSavableSchemes)) { + // If something is wrong when collecting all savable resource links, + // send empty list to embedder(browser) to tell it failed. + referrers_list.clear(); + resources_list.clear(); + frames_list.clear(); + } + + // Send result of all savable resource links to embedder. + Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(), + resources_list, + referrers_list, + frames_list)); +} + +void +ChromeRenderViewObserver::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks( + const std::vector<GURL>& links, + const std::vector<FilePath>& local_paths, + const FilePath& local_directory_name) { + + // Convert std::vector of GURLs to WebVector<WebURL> + WebVector<WebURL> weburl_links(links); + + // Convert std::vector of std::strings to WebVector<WebString> + WebVector<WebString> webstring_paths(local_paths.size()); + for (size_t i = 0; i < local_paths.size(); i++) + webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]); + + WebPageSerializer::serialize(render_view()->webview()->mainFrame(), + true, this, weburl_links, webstring_paths, + webkit_glue::FilePathToWebString( + local_directory_name)); +} + +void ChromeRenderViewObserver::OnDownloadFavicon(int id, + const GURL& image_url, + int image_size) { + bool data_image_failed = false; + if (image_url.SchemeIs("data")) { + SkBitmap data_image = ImageFromDataUrl(image_url); + data_image_failed = data_image.empty(); + if (!data_image_failed) { + Send(new ViewHostMsg_DidDownloadFavicon( + routing_id(), id, image_url, false, data_image)); + } + } + + if (data_image_failed || + !DownloadFavicon(id, image_url, image_size)) { + Send(new ViewHostMsg_DidDownloadFavicon( + routing_id(), id, image_url, true, SkBitmap())); + } +} + +void ChromeRenderViewObserver::OnEnableViewSourceMode() { + if (!render_view()->webview()) + return; + WebFrame* main_frame = render_view()->webview()->mainFrame(); + if (!main_frame) + return; + + main_frame->enableViewSourceMode(true); +} + +void ChromeRenderViewObserver::didSerializeDataForFrame( + const WebURL& frame_url, + const WebCString& data, + WebPageSerializerClient::PageSerializationStatus status) { + Send(new ViewHostMsg_SendSerializedHtmlData( + routing_id(), + frame_url, + data.data(), + static_cast<int32>(status))); +} + void ChromeRenderViewObserver::OnNavigate( const ViewMsg_Navigate_Params& params) { AboutHandler::MaybeHandle(params.url); @@ -144,6 +293,33 @@ void ChromeRenderViewObserver::DidStopLoading() { &ChromeRenderViewObserver::CapturePageInfo, render_view()->page_id(), false), render_view()->content_state_immediately() ? 0 : kDelayForCaptureMs); + + GURL osd_url = + render_view()->webview()->mainFrame()->openSearchDescriptionURL(); + if (!osd_url.is_empty()) { + Send(new ViewHostMsg_PageHasOSDD( + routing_id(), render_view()->page_id(), osd_url, + search_provider::AUTODETECTED_PROVIDER)); + } + + // TODO : Get both favicon and touch icon url, and send them to the browser. + GURL favicon_url(render_view()->webview()->mainFrame()->favIconURL()); + if (!favicon_url.is_empty()) { + std::vector<FaviconURL> urls; + urls.push_back(FaviconURL(favicon_url, FAVICON)); + Send(new ViewHostMsg_UpdateFaviconURL( + routing_id(), render_view()->page_id(), urls)); + } +} + +void ChromeRenderViewObserver::DidChangeIcons(WebFrame* frame) { + if (frame->parent()) + return; + + std::vector<FaviconURL> urls; + urls.push_back(FaviconURL(frame->favIconURL(), FAVICON)); + Send(new ViewHostMsg_UpdateFaviconURL( + routing_id(), render_view()->page_id(), urls)); } void ChromeRenderViewObserver::DidCommitProvisionalLoad( @@ -159,6 +335,20 @@ void ChromeRenderViewObserver::DidCommitProvisionalLoad( kDelayForForcedCaptureMs); } +void ChromeRenderViewObserver::DidClearWindowObject(WebFrame* frame) { + if (BindingsPolicy::is_dom_automation_enabled( + render_view()->enabled_bindings())) { + BindDOMAutomationController(frame); + } + + if (BindingsPolicy::is_external_host_enabled( + render_view()->enabled_bindings())) { + GetExternalHostBindings()->set_message_sender(render_view()); + GetExternalHostBindings()->set_routing_id(routing_id()); + GetExternalHostBindings()->BindToJavascript(frame, "externalHost"); + } +} + void ChromeRenderViewObserver::CapturePageInfo(int load_id, bool preliminary_capture) { if (load_id != render_view()->page_id()) @@ -359,3 +549,69 @@ bool ChromeRenderViewObserver::CaptureSnapshot(WebView* view, base::TimeTicks::Now() - beginning_time); return true; } + +void ChromeRenderViewObserver::BindDOMAutomationController(WebFrame* frame) { + if (!dom_automation_controller_.get()) { + dom_automation_controller_.reset(new DomAutomationController()); + } + dom_automation_controller_->set_message_sender(this); + dom_automation_controller_->set_routing_id(routing_id()); + dom_automation_controller_->BindToJavascript(frame, + "domAutomationController"); +} + +ExternalHostBindings* ChromeRenderViewObserver::GetExternalHostBindings() { + if (!external_host_bindings_.get()) + external_host_bindings_.reset(new ExternalHostBindings()); + return external_host_bindings_.get(); +} + +bool ChromeRenderViewObserver::DownloadFavicon(int id, + const GURL& image_url, + int image_size) { + // Make sure webview was not shut down. + if (!render_view()->webview()) + return false; + // Create an image resource fetcher and assign it with a call back object. + image_fetchers_.push_back(linked_ptr<ImageResourceFetcher>( + new ImageResourceFetcher( + image_url, render_view()->webview()->mainFrame(), id, image_size, + WebURLRequest::TargetIsFavicon, + NewCallback(this, &ChromeRenderViewObserver::DidDownloadFavicon)))); + return true; +} + +void ChromeRenderViewObserver::DidDownloadFavicon( + ImageResourceFetcher* fetcher, const SkBitmap& image) { + // Notify requester of image download status. + Send(new ViewHostMsg_DidDownloadFavicon(routing_id(), + fetcher->id(), + fetcher->image_url(), + image.isNull(), + image)); + + // Remove the image fetcher from our pending list. We're in the callback from + // ImageResourceFetcher, best to delay deletion. + RenderView::ImageResourceFetcherList::iterator iter; + for (iter = image_fetchers_.begin(); iter != image_fetchers_.end(); ++iter) { + if (iter->get() == fetcher) { + iter->release(); + image_fetchers_.erase(iter); + break; + } + } + MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher); +} + +SkBitmap ChromeRenderViewObserver::ImageFromDataUrl(const GURL& url) const { + std::string mime_type, char_set, data; + if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) { + // Decode the favicon using WebKit's image decoder. + webkit_glue::ImageDecoder decoder(gfx::Size(kFaviconSize, kFaviconSize)); + const unsigned char* src_data = + reinterpret_cast<const unsigned char*>(&data[0]); + + return decoder.Decode(src_data, data.size()); + } + return SkBitmap(); +} diff --git a/chrome/renderer/chrome_render_view_observer.h b/chrome/renderer/chrome_render_view_observer.h index 038753b..11ddff7 100644 --- a/chrome/renderer/chrome_render_view_observer.h +++ b/chrome/renderer/chrome_render_view_observer.h @@ -6,9 +6,18 @@ #define CHROME_RENDERER_CHROME_RENDER_VIEW_OBSERVER_H_ #pragma once +#include <vector> + #include "base/task.h" +#include "base/scoped_ptr.h" +#include "content/renderer/render_view.h" #include "content/renderer/render_view_observer.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializerClient.h" +class DomAutomationController; +class ExternalHostBindings; +class FilePath; +class GURL; class SkBitmap; class TranslateHelper; struct ThumbnailScore; @@ -22,9 +31,14 @@ namespace safe_browsing { class PhishingClassifierDelegate; } +namespace webkit_glue { +class ImageResourceFetcher; +} + // This class holds the Chrome specific parts of RenderView, and has the same // lifetime. -class ChromeRenderViewObserver : public RenderViewObserver { +class ChromeRenderViewObserver : public RenderViewObserver, + public WebKit::WebPageSerializerClient { public: // translate_helper and/or phishing_classifier can be NULL. ChromeRenderViewObserver( @@ -37,10 +51,28 @@ class ChromeRenderViewObserver : public RenderViewObserver { // RenderViewObserver implementation. virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; virtual void DidStopLoading() OVERRIDE; + virtual void DidChangeIcons(WebKit::WebFrame* frame) OVERRIDE; virtual void DidCommitProvisionalLoad(WebKit::WebFrame* frame, bool is_new_navigation) OVERRIDE; + virtual void DidClearWindowObject(WebKit::WebFrame* frame) OVERRIDE; + + // WebKit::WebPageSerializerClient implementation. + virtual void didSerializeDataForFrame(const WebKit::WebURL& frame_url, + const WebKit::WebCString& data, + PageSerializationStatus status); void OnCaptureSnapshot(); + void OnHandleMessageFromExternalHost(const std::string& message, + const std::string& origin, + const std::string& target); + void OnJavaScriptStressTestControl(int cmd, int param); + void OnGetAllSavableResourceLinksForCurrentPage(const GURL& page_url); + void OnGetSerializedHtmlDataForCurrentPageWithLocalLinks( + const std::vector<GURL>& links, + const std::vector<FilePath>& local_paths, + const FilePath& local_directory_name); + void OnDownloadFavicon(int id, const GURL& image_url, int image_size); + void OnEnableViewSourceMode(); void OnNavigate(const ViewMsg_Navigate_Params& params); // Captures the thumbnail and text contents for indexing for the given load @@ -65,7 +97,31 @@ class ChromeRenderViewObserver : public RenderViewObserver { // to get a snapshot of a tab using chrome.tabs.captureVisibleTab(). bool CaptureSnapshot(WebKit::WebView* view, SkBitmap* snapshot); - // Has the same lifetime as us. + // Exposes the DOMAutomationController object that allows JS to send + // information to the browser process. + void BindDOMAutomationController(WebKit::WebFrame* webframe); + + ExternalHostBindings* GetExternalHostBindings(); + + // This callback is triggered when DownloadFavicon completes, either + // succesfully or with a failure. See DownloadFavicon for more + // details. + void DidDownloadFavicon(webkit_glue::ImageResourceFetcher* fetcher, + const SkBitmap& image); + + // Requests to download a favicon image. When done, the RenderView + // is notified by way of DidDownloadFavicon. Returns true if the + // request was successfully started, false otherwise. id is used to + // uniquely identify the request and passed back to the + // DidDownloadFavicon method. If the image has multiple frames, the + // frame whose size is image_size is returned. If the image doesn't + // have a frame at the specified size, the first is returned. + bool DownloadFavicon(int id, const GURL& image_url, int image_size); + + // Decodes a data: URL image or returns an empty image in case of failure. + SkBitmap ImageFromDataUrl(const GURL&) const; + + // Have the same lifetime as us. TranslateHelper* translate_helper_; safe_browsing::PhishingClassifierDelegate* phishing_classifier_; @@ -73,9 +129,19 @@ class ChromeRenderViewObserver : public RenderViewObserver { // same page twice in a row. int32 last_indexed_page_id_; + // Allows JS to access DOM automation. The JS object is only exposed when the + // DOM automation bindings are enabled. + scoped_ptr<DomAutomationController> dom_automation_controller_; + + // External host exposed through automation controller. + scoped_ptr<ExternalHostBindings> external_host_bindings_; + ScopedRunnableMethodFactory<ChromeRenderViewObserver> page_info_method_factory_; + // ImageResourceFetchers schedule via DownloadImage. + RenderView::ImageResourceFetcherList image_fetchers_; + DISALLOW_COPY_AND_ASSIGN(ChromeRenderViewObserver); }; diff --git a/chrome/renderer/extensions/extension_helper.cc b/chrome/renderer/extensions/extension_helper.cc index 888c0ed..691e7cb 100644 --- a/chrome/renderer/extensions/extension_helper.cc +++ b/chrome/renderer/extensions/extension_helper.cc @@ -10,6 +10,7 @@ #include "base/utf_string_conversions.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/extension_messages.h" +#include "chrome/common/render_messages.h" #include "chrome/common/url_constants.h" #include "chrome/renderer/extensions/extension_dispatcher.h" #include "chrome/renderer/extensions/extension_process_bindings.h" @@ -47,7 +48,9 @@ ExtensionHelper::ExtensionHelper(RenderView* render_view, : RenderViewObserver(render_view), RenderViewObserverTracker<ExtensionHelper>(render_view), extension_dispatcher_(extension_dispatcher), - pending_app_icon_requests_(0) { + pending_app_icon_requests_(0), + view_type_(ViewType::INVALID), + browser_window_id_(-1) { } ExtensionHelper::~ExtensionHelper() { @@ -106,6 +109,8 @@ bool ExtensionHelper::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnExtensionMessageInvoke) IPC_MESSAGE_HANDLER(ExtensionMsg_ExecuteCode, OnExecuteCode) IPC_MESSAGE_HANDLER(ExtensionMsg_GetApplicationInfo, OnGetApplicationInfo) + IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId, OnUpdateBrowserWindowId) + IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType, OnNotifyRendererViewType) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() return handled; @@ -221,6 +226,14 @@ void ExtensionHelper::OnGetApplicationInfo(int page_id) { routing_id(), page_id, app_info)); } +void ExtensionHelper::OnNotifyRendererViewType(ViewType::Type type) { + view_type_ = type; +} + +void ExtensionHelper::OnUpdateBrowserWindowId(int window_id) { + browser_window_id_ = window_id; +} + void ExtensionHelper::DidDownloadApplicationDefinition( const WebKit::WebURLResponse& response, const std::string& data) { diff --git a/chrome/renderer/extensions/extension_helper.h b/chrome/renderer/extensions/extension_helper.h index 2fc45ab..c53dad5 100644 --- a/chrome/renderer/extensions/extension_helper.h +++ b/chrome/renderer/extensions/extension_helper.h @@ -8,6 +8,7 @@ #include <map> +#include "chrome/common/view_types.h" #include "content/renderer/render_view.h" #include "content/renderer/render_view_observer.h" #include "content/renderer/render_view_observer_tracker.h" @@ -37,6 +38,9 @@ class ExtensionHelper : public RenderViewObserver, bool InstallWebApplicationUsingDefinitionFile(WebKit::WebFrame* frame, string16* error); + int browser_window_id() const { return browser_window_id_; } + ViewType::Type view_type() const { return view_type_; } + private: // RenderViewObserver implementation. virtual bool OnMessageReceived(const IPC::Message& message); @@ -57,6 +61,8 @@ class ExtensionHelper : public RenderViewObserver, const GURL& event_url); void OnExecuteCode(const ExtensionMsg_ExecuteCode_Params& params); void OnGetApplicationInfo(int page_id); + void OnNotifyRendererViewType(ViewType::Type view_type); + void OnUpdateBrowserWindowId(int window_id); // Callback triggered when we finish downloading the application definition // file. @@ -88,6 +94,12 @@ class ExtensionHelper : public RenderViewObserver, // done processing an app definition file. int pending_app_icon_requests_; + // Type of view attached with RenderView. + ViewType::Type view_type_; + + // Id number of browser window which RenderView is attached to. + int browser_window_id_; + DISALLOW_COPY_AND_ASSIGN(ExtensionHelper); }; diff --git a/chrome/renderer/extensions/extension_process_bindings.cc b/chrome/renderer/extensions/extension_process_bindings.cc index 36b92b1..57d6fec 100644 --- a/chrome/renderer/extensions/extension_process_bindings.cc +++ b/chrome/renderer/extensions/extension_process_bindings.cc @@ -26,6 +26,7 @@ #include "chrome/renderer/extensions/bindings_utils.h" #include "chrome/renderer/extensions/event_bindings.h" #include "chrome/renderer/extensions/extension_dispatcher.h" +#include "chrome/renderer/extensions/extension_helper.h" #include "chrome/renderer/extensions/js_only_v8_extensions.h" #include "chrome/renderer/extensions/renderer_extension_bindings.h" #include "chrome/renderer/extensions/user_script_slave.h" @@ -122,7 +123,8 @@ class ExtensionViewAccumulator : public RenderViewVisitor { v8::Local<v8::Array> views() { return views_; } virtual bool Visit(RenderView* render_view) { - if (!ViewTypeMatches(render_view->view_type(), view_type_)) + ExtensionHelper* helper = ExtensionHelper::Get(render_view); + if (!ViewTypeMatches(helper->view_type(), view_type_)) return true; GURL url = render_view->webview()->mainFrame()->url(); @@ -133,7 +135,7 @@ class ExtensionViewAccumulator : public RenderViewVisitor { return true; if (browser_window_id_ != extension_misc::kUnknownWindowId && - render_view->browser_window_id() != browser_window_id_) { + helper->browser_window_id() != browser_window_id_) { return true; } diff --git a/chrome/renderer/external_extension.cc b/chrome/renderer/external_extension.cc index 47d703b..f101333 100644 --- a/chrome/renderer/external_extension.cc +++ b/chrome/renderer/external_extension.cc @@ -6,9 +6,11 @@ #include "base/command_line.h" #include "chrome/common/chrome_switches.h" +#include "chrome/common/render_messages.h" #include "chrome/common/search_provider.h" #include "content/renderer/render_view.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" #include "v8/include/v8.h" using WebKit::WebFrame; @@ -124,7 +126,16 @@ v8::Handle<v8::Value> ExternalExtensionWrapper::AddSearchProvider( RenderView* render_view = GetRenderView(); if (!render_view) return v8::Undefined(); - render_view->AddSearchProvider(name, provider_type); + if (provider_type != search_provider::EXPLICIT_DEFAULT_PROVIDER || + render_view->webview()->mainFrame()->isProcessingUserGesture()) { + GURL osd_url(name); + if (!osd_url.is_empty()) { + render_view->Send(new ViewHostMsg_PageHasOSDD( + render_view->routing_id(), render_view->page_id(), osd_url, + provider_type)); + } + } + return v8::Undefined(); } @@ -142,8 +153,13 @@ v8::Handle<v8::Value> ExternalExtensionWrapper::IsSearchProviderInstalled( WebFrame* webframe = WebFrame::frameForEnteredContext(); if (!webframe) return v8::Undefined(); - search_provider::InstallState install = - render_view->GetSearchProviderInstallState(webframe, name); + search_provider::InstallState install = search_provider::DENIED; + GURL inquiry_url = GURL(name); + if (!inquiry_url.is_empty()) { + render_view->Send(new ViewHostMsg_GetSearchProviderInstallState( + render_view->routing_id(), webframe->url(), inquiry_url, &install)); + } + if (install == search_provider::DENIED) { // FIXME: throw access denied exception. return v8::ThrowException(v8::Exception::Error(v8::String::Empty())); diff --git a/chrome/renderer/page_load_histograms.cc b/chrome/renderer/page_load_histograms.cc index 7922e48..32a75e2 100644 --- a/chrome/renderer/page_load_histograms.cc +++ b/chrome/renderer/page_load_histograms.cc @@ -9,6 +9,7 @@ #include "base/metrics/histogram.h" #include "base/time.h" #include "chrome/common/chrome_constants.h" +#include "chrome/common/extensions/url_pattern.h" #include "chrome/renderer/renderer_histogram_snapshots.h" #include "content/common/view_messages.h" #include "content/renderer/navigation_state.h" diff --git a/chrome/renderer/print_web_view_helper_browsertest.cc b/chrome/renderer/print_web_view_helper_browsertest.cc new file mode 100644 index 0000000..72b7a2c --- /dev/null +++ b/chrome/renderer/print_web_view_helper_browsertest.cc @@ -0,0 +1,203 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/file_util.h" +#include "chrome/renderer/print_web_view_helper.h" +#include "chrome/test/render_view_test.h" +#include "printing/image.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" + +using WebKit::WebFrame; +using WebKit::WebString; +using WebKit::WebView; + +namespace { + +const char kPrintWithJSHTML[] = + "<body>Hello<script>window.print()</script>World</body>"; + +} // namespace + +// Tests that printing pages work and sending and receiving messages through +// that channel all works. +TEST_F(RenderViewTest, OnPrintPages) { + // Lets simulate a print pages with Hello world. + LoadHTML("<body><p>Hello World!</p></body>"); + PrintWebViewHelper::Get(view_)->OnPrintPages(); + + VerifyPageCount(1); + VerifyPagesPrinted(true); +} + +// Duplicate of OnPrintPagesTest only using javascript to print. +TEST_F(RenderViewTest, PrintWithJavascript) { + // HTML contains a call to window.print() + LoadHTML(kPrintWithJSHTML); + + VerifyPageCount(1); + VerifyPagesPrinted(true); +} + +// Tests that the renderer blocks window.print() calls if they occur too +// frequently. +TEST_F(RenderViewTest, BlockScriptInitiatedPrinting) { + // Pretend user will cancel printing. + render_thread_.set_print_dialog_user_response(false); + // Try to print with window.print() a few times. + LoadHTML(kPrintWithJSHTML); + LoadHTML(kPrintWithJSHTML); + LoadHTML(kPrintWithJSHTML); + VerifyPagesPrinted(false); + + // Pretend user will print. (but printing is blocked.) + render_thread_.set_print_dialog_user_response(true); + LoadHTML(kPrintWithJSHTML); + VerifyPagesPrinted(false); + + // Unblock script initiated printing and verify printing works. + PrintWebViewHelper::Get(view_)->ResetScriptedPrintCount(); + render_thread_.printer()->ResetPrinter(); + LoadHTML(kPrintWithJSHTML); + VerifyPageCount(1); + VerifyPagesPrinted(true); +} + +#if defined(OS_WIN) || defined(OS_MACOSX) +// TODO(estade): I don't think this test is worth porting to Linux. We will have +// to rip out and replace most of the IPC code if we ever plan to improve +// printing, and the comment below by sverrir suggests that it doesn't do much +// for us anyway. +TEST_F(RenderViewTest, PrintWithIframe) { + // Document that populates an iframe. + const char html[] = + "<html><body>Lorem Ipsum:" + "<iframe name=\"sub1\" id=\"sub1\"></iframe><script>" + " document.write(frames['sub1'].name);" + " frames['sub1'].document.write(" + " '<p>Cras tempus ante eu felis semper luctus!</p>');" + "</script></body></html>"; + + LoadHTML(html); + + // Find the frame and set it as the focused one. This should mean that that + // the printout should only contain the contents of that frame. + WebFrame* sub1_frame = + view_->webview()->findFrameByName(WebString::fromUTF8("sub1")); + ASSERT_TRUE(sub1_frame); + view_->webview()->setFocusedFrame(sub1_frame); + ASSERT_NE(view_->webview()->focusedFrame(), + view_->webview()->mainFrame()); + + // Initiate printing. + PrintWebViewHelper::Get(view_)->OnPrintPages(); + + // Verify output through MockPrinter. + const MockPrinter* printer(render_thread_.printer()); + ASSERT_EQ(1, printer->GetPrintedPages()); + const printing::Image& image1(printer->GetPrintedPage(0)->image()); + + // TODO(sverrir): Figure out a way to improve this test to actually print + // only the content of the iframe. Currently image1 will contain the full + // page. + EXPECT_NE(0, image1.size().width()); + EXPECT_NE(0, image1.size().height()); +} +#endif + +// Tests if we can print a page and verify its results. +// This test prints HTML pages into a pseudo printer and check their outputs, +// i.e. a simplified version of the PrintingLayoutTextTest UI test. +namespace { +// Test cases used in this test. +struct TestPageData { + const char* page; + size_t printed_pages; + int width; + int height; + const char* checksum; + const wchar_t* file; +}; + +const TestPageData kTestPages[] = { + {"<html>" + "<head>" + "<meta" + " http-equiv=\"Content-Type\"" + " content=\"text/html; charset=utf-8\"/>" + "<title>Test 1</title>" + "</head>" + "<body style=\"background-color: white;\">" + "<p style=\"font-family: arial;\">Hello World!</p>" + "</body>", +#if defined(OS_MACOSX) + // Mac printing code compensates for the WebKit scale factor while generating + // the metafile, so we expect smaller pages. + 1, 540, 720, +#else + 1, 675, 900, +#endif + NULL, + NULL, + }, +}; +} // namespace + +// TODO(estade): need to port MockPrinter to get this on Linux. This involves +// hooking up Cairo to read a pdf stream, or accessing the cairo surface in the +// metafile directly. +#if defined(OS_WIN) || defined(OS_MACOSX) +TEST_F(RenderViewTest, PrintLayoutTest) { + bool baseline = false; + + EXPECT_TRUE(render_thread_.printer() != NULL); + for (size_t i = 0; i < arraysize(kTestPages); ++i) { + // Load an HTML page and print it. + LoadHTML(kTestPages[i].page); + PrintWebViewHelper::Get(view_)->OnPrintPages(); + + // MockRenderThread::Send() just calls MockRenderThread::OnMsgReceived(). + // So, all IPC messages sent in the above RenderView::OnPrintPages() call + // has been handled by the MockPrinter object, i.e. this printing job + // has been already finished. + // So, we can start checking the output pages of this printing job. + // Retrieve the number of pages actually printed. + size_t pages = render_thread_.printer()->GetPrintedPages(); + EXPECT_EQ(kTestPages[i].printed_pages, pages); + + // Retrieve the width and height of the output page. + int width = render_thread_.printer()->GetWidth(0); + int height = render_thread_.printer()->GetHeight(0); + + // Check with margin for error. This has been failing with a one pixel + // offset on our buildbot. + const int kErrorMargin = 5; // 5% + EXPECT_GT(kTestPages[i].width * (100 + kErrorMargin) / 100, width); + EXPECT_LT(kTestPages[i].width * (100 - kErrorMargin) / 100, width); + EXPECT_GT(kTestPages[i].height * (100 + kErrorMargin) / 100, height); + EXPECT_LT(kTestPages[i].height* (100 - kErrorMargin) / 100, height); + + // Retrieve the checksum of the bitmap data from the pseudo printer and + // compare it with the expected result. + std::string bitmap_actual; + EXPECT_TRUE(render_thread_.printer()->GetBitmapChecksum(0, &bitmap_actual)); + if (kTestPages[i].checksum) + EXPECT_EQ(kTestPages[i].checksum, bitmap_actual); + + if (baseline) { + // Save the source data and the bitmap data into temporary files to + // create base-line results. + FilePath source_path; + file_util::CreateTemporaryFile(&source_path); + render_thread_.printer()->SaveSource(0, source_path); + + FilePath bitmap_path; + file_util::CreateTemporaryFile(&bitmap_path); + render_thread_.printer()->SaveBitmap(0, bitmap_path); + } + } +} +#endif
\ No newline at end of file diff --git a/chrome/renderer/translate_helper_browsertest.cc b/chrome/renderer/translate_helper_browsertest.cc index 9298305..e375148 100644 --- a/chrome/renderer/translate_helper_browsertest.cc +++ b/chrome/renderer/translate_helper_browsertest.cc @@ -293,3 +293,72 @@ TEST_F(TranslateHelperTest, MultipleDifferentTranslations) { EXPECT_EQ(new_target_lang, received_target_lang); EXPECT_EQ(TranslateErrors::NONE, error); } + +// Tests that we send the right translatable for a page and that we respect the +// "no translate" meta-tag. +TEST_F(RenderViewTest, TranslatablePage) { + // Suppress the normal delay that occurs when the page is loaded before which + // the renderer sends the page contents to the browser. + view_->set_send_content_state_immediately(true); + + LoadHTML("<html><body>A random page with random content.</body></html>"); + ProcessPendingMessages(); + const IPC::Message* message = render_thread_.sink().GetUniqueMessageMatching( + ViewHostMsg_TranslateLanguageDetermined::ID); + ASSERT_NE(static_cast<IPC::Message*>(NULL), message); + ViewHostMsg_TranslateLanguageDetermined::Param params; + ViewHostMsg_TranslateLanguageDetermined::Read(message, ¶ms); + EXPECT_TRUE(params.b); // Translatable should be true. + render_thread_.sink().ClearMessages(); + + // Now the page specifies the META tag to prevent translation. + LoadHTML("<html><head><meta name=\"google\" value=\"notranslate\"></head>" + "<body>A random page with random content.</body></html>"); + ProcessPendingMessages(); + message = render_thread_.sink().GetUniqueMessageMatching( + ViewHostMsg_TranslateLanguageDetermined::ID); + ASSERT_NE(static_cast<IPC::Message*>(NULL), message); + ViewHostMsg_TranslateLanguageDetermined::Read(message, ¶ms); + EXPECT_FALSE(params.b); // Translatable should be false. + render_thread_.sink().ClearMessages(); + + // Try the alternate version of the META tag (content instead of value). + LoadHTML("<html><head><meta name=\"google\" content=\"notranslate\"></head>" + "<body>A random page with random content.</body></html>"); + ProcessPendingMessages(); + message = render_thread_.sink().GetUniqueMessageMatching( + ViewHostMsg_TranslateLanguageDetermined::ID); + ASSERT_NE(static_cast<IPC::Message*>(NULL), message); + ViewHostMsg_TranslateLanguageDetermined::Read(message, ¶ms); + EXPECT_FALSE(params.b); // Translatable should be false. +} + +// Tests that the language meta tag takes precedence over the CLD when reporting +// the page's language. +TEST_F(RenderViewTest, LanguageMetaTag) { + // Suppress the normal delay that occurs when the page is loaded before which + // the renderer sends the page contents to the browser. + view_->set_send_content_state_immediately(true); + + LoadHTML("<html><head><meta http-equiv=\"content-language\" content=\"es\">" + "</head><body>A random page with random content.</body></html>"); + ProcessPendingMessages(); + const IPC::Message* message = render_thread_.sink().GetUniqueMessageMatching( + ViewHostMsg_TranslateLanguageDetermined::ID); + ASSERT_NE(static_cast<IPC::Message*>(NULL), message); + ViewHostMsg_TranslateLanguageDetermined::Param params; + ViewHostMsg_TranslateLanguageDetermined::Read(message, ¶ms); + EXPECT_EQ("es", params.a); + render_thread_.sink().ClearMessages(); + + // Makes sure we support multiple languages specified. + LoadHTML("<html><head><meta http-equiv=\"content-language\" " + "content=\" fr , es,en \">" + "</head><body>A random page with random content.</body></html>"); + ProcessPendingMessages(); + message = render_thread_.sink().GetUniqueMessageMatching( + ViewHostMsg_TranslateLanguageDetermined::ID); + ASSERT_NE(static_cast<IPC::Message*>(NULL), message); + ViewHostMsg_TranslateLanguageDetermined::Read(message, ¶ms); + EXPECT_EQ("fr", params.a); +} |