This source file includes following definitions.
- IsReload
- GetReferrerFromRequest
- NavigationPolicyToDisposition
- DeviceScaleEnsuresTextQuality
- ShouldUseFixedPositionCompositing
- ShouldUseAcceleratedCompositingForOverflowScroll
- ShouldUseAcceleratedCompositingForScrollableFrames
- ShouldUseCompositedScrollingForFrames
- ShouldUseUniversalAcceleratedCompositingForOverflowScroll
- ShouldUseTransitionCompositing
- ShouldUseAcceleratedFixedRootBackground
- ShouldUseCompositingForGpuRasterizationHint
- ToFaviconType
- ConvertToFaviconSizes
- OnLockMouseACK
- OnMouseLockLost
- HandleMouseLockedInputEvent
- TouchEnabled
- DropDataToWebDragData
- next_snapshot_id_
- Initialize
- FromWebView
- FromWebView
- FromRoutingID
- FromRoutingID
- ForEach
- Create
- InstallCreateHook
- AddObserver
- RemoveObserver
- webview
- PepperInstanceCreated
- PepperInstanceDeleted
- PepperFocusChanged
- RegisterPluginDelegate
- UnregisterPluginDelegate
- PluginFocusChanged
- PluginFocusChanged
- StartPluginIme
- TransferActiveWheelFlingAnimation
- HasIMETextFocus
- OnMessageReceived
- OnNavigate
- IsBackForwardToStaleEntry
- OnStop
- OnCopyImageAt
- OnUpdateTargetURLAck
- OnExecuteEditCommand
- OnMoveCaret
- OnScrollFocusedEditableNodeIntoRect
- OnSetEditCommandsForNextKeyEvent
- OnSetName
- OnSetHistoryLengthAndPrune
- OnSetInitialFocus
- OnSetInLiveResize
- OnPauseVideo
- UpdateTitle
- UpdateEncoding
- UpdateSessionHistory
- SendUpdateState
- LoadNavigationErrorPage
- RunJavaScriptMessage
- SendAndRunNestedMessageLoop
- GetWindowSnapshot
- OnWindowSnapshotCompleted
- createView
- createPopupMenu
- createExternalPopupMenu
- createSessionStorageNamespace
- printPage
- notificationPresenter
- enumerateChosenDirectory
- FrameDidStartLoading
- FrameDidStopLoading
- FrameDidChangeLoadProgress
- didCancelCompositionOnSelectionChange
- didExecuteCommand
- handleCurrentKeyboardEvent
- createColorChooser
- runFileChooser
- runModalAlertDialog
- runModalConfirmDialog
- runModalPromptDialog
- runModalBeforeUnloadDialog
- runModalBeforeUnloadDialog
- showValidationMessage
- hideValidationMessage
- moveValidationMessage
- setStatusText
- UpdateTargetURL
- ClientRectToPhysicalWindowRect
- StartNavStateSyncTimerIfNecessary
- setMouseOverURL
- setKeyboardFocusURL
- startDragging
- acceptsLoadDrops
- focusNext
- focusPrevious
- focusedNodeChanged
- numberOfWheelEventHandlersChanged
- didUpdateLayout
- navigateBackForwardSoon
- historyBackListCount
- historyForwardListCount
- postAccessibilityEvent
- didUpdateInspectorSetting
- didFocus
- didBlur
- show
- runModal
- enterFullScreen
- exitFullScreen
- requestPointerLock
- requestPointerUnlock
- isPointerLocked
- didActivateCompositor
- didActivateCompositor
- didHandleGestureEvent
- initializeLayerTreeView
- createMediaPlayer
- CreateMediaPlayer
- didAccessInitialDocument
- didDisownOpener
- frameDetached
- willClose
- didMatchCSS
- Repaint
- SetEditCommandForNextKeyEvent
- ClearEditCommands
- GetSSLStatusOfFrame
- GetAcceptLanguages
- willSendSubmitEvent
- willSubmitForm
- didCreateDataSource
- PopulateDocumentStateFromPending
- CreateNavigationStateFromPending
- ProcessViewLayoutFlags
- didStartProvisionalLoad
- didFailProvisionalLoad
- FrameDidCommitProvisionalLoad
- didClearWindowObject
- didCreateDocumentElement
- didReceiveTitle
- didChangeIcon
- didFinishDocumentLoad
- didHandleOnloadEvents
- didFailLoad
- didFinishLoad
- didUpdateCurrentHistoryItem
- willSendRequest
- didReceiveResponse
- didFinishResourceLoad
- didLoadResourceFromMemoryCache
- didDisplayInsecureContent
- didRunInsecureContent
- didCreateScriptContext
- willReleaseScriptContext
- CheckPreferredSize
- GetBrowserPluginManager
- InitializeMediaStreamClient
- didChangeContentsSize
- UpdateScrollState
- didChangeScrollOffset
- willInsertBody
- didFirstVisuallyNonEmptyLayout
- SendFindReply
- reportFindInPageMatchCount
- reportFindInPageSelection
- requestStorageQuota
- willCheckAndDispatchMessageEvent
- willOpenSocketStream
- willStartUsingPeerConnectionHandler
- acceptLanguages
- userAgentOverride
- doNotTrackValue
- allowWebGL
- didLoseWebGLContext
- didSerializeDataForFrame
- Send
- GetMainRenderFrame
- GetRoutingID
- GetPageId
- GetSize
- GetWebkitPreferences
- SetWebkitPreferences
- GetWebView
- GetFocusedElement
- IsEditableNode
- ShouldDisplayScrollbars
- GetEnabledBindings
- GetContentStateImmediately
- GetFilteredTimePerFrame
- GetVisibilityState
- RunModalAlertDialog
- DidStartLoading
- DidStopLoading
- DidPlay
- DidPause
- PlayerGone
- SyncNavigationState
- GetLoadingUrl
- GetWebPluginForFind
- OnFind
- OnStopFinding
- OnActivateNearestFindResult
- OnFindMatchRects
- OnZoom
- OnSetZoomLevel
- OnSetZoomLevelForLoadingURL
- OnSetPageEncoding
- OnResetPageEncodingToDefault
- OnPostMessageEvent
- OnAllowBindings
- OnDragTargetDragEnter
- OnDragTargetDragOver
- OnDragTargetDragLeave
- OnDragTargetDrop
- OnDragSourceEnded
- OnDragSourceSystemDragEnded
- OnUpdateWebPreferences
- OnEnumerateDirectoryResponse
- OnFileChooserResponse
- OnEnableAutoResize
- OnDisableAutoResize
- OnEnablePreferredSizeChangedMode
- OnDisableScrollbarsForSmallWindows
- OnSetRendererPrefs
- OnMediaPlayerActionAt
- OnOrientationChangeEvent
- OnPluginActionAt
- OnGetAllSavableResourceLinksForCurrentPage
- OnGetSerializedHtmlDataForCurrentPageWithLocalLinks
- OnSuppressDialogsUntilSwapOut
- NavigateToSwappedOutURL
- OnClosePage
- OnThemeChanged
- OnMoveOrResizeStarted
- OnResize
- DidInitiatePaint
- DidFlushPaint
- GetBitmapForOptimizedPluginPaint
- GetScrollOffset
- OnClearFocusedElement
- OnSetBackground
- OnSetAccessibilityMode
- OnSetActive
- OnSetWindowVisibility
- OnWindowFrameChanged
- OnPluginImeCompositionCompleted
- Close
- DidHandleKeyEvent
- WillProcessUserGesture
- WillHandleMouseEvent
- WillHandleGestureEvent
- DidHandleMouseEvent
- DidHandleTouchEvent
- HasTouchEventHandlersAt
- OnWasHidden
- OnWasShown
- GetURLForGraphicsContext3D
- ForceCompositingModeEnabled
- OnSetFocus
- OnImeSetComposition
- OnImeConfirmComposition
- SetDeviceScaleFactor
- GetTextInputType
- GetSelectionBounds
- GetCompositionCharacterBounds
- GetCompositionRange
- CanComposeInline
- InstrumentWillBeginFrame
- InstrumentDidBeginFrame
- InstrumentDidCancelFrame
- InstrumentWillComposite
- SetScreenMetricsEmulationParameters
- ScheduleFileChooser
- geolocationClient
- speechInputController
- speechRecognizer
- zoomLimitsChanged
- zoomLevelChanged
- zoomLevelToZoomFactor
- zoomFactorToZoomLevel
- registerProtocolHandler
- visibilityState
- userMediaClient
- webMIDIClient
- draggableRegionsChanged
- CreateWebMediaPlayerForMediaStream
- detectContentAround
- scheduleContentIntent
- cancelScheduledContentIntents
- LaunchAndroidContentIntent
- openDateTimeChooser
- DismissDateTimeDialog
- CreateAndroidWebMediaPlayer
- OnSelectPopupMenuItem
- OnSelectPopupMenuItems
- DidHideExternalPopupMenu
- OnShowContextMenu
- OnEnableViewSourceMode
- OnDisownOpener
- didTapMultipleTargets
- GetLocalSessionHistoryLengthForTesting
- SetFocusAndActivateForTesting
- SetDeviceScaleFactorForTesting
- ForceResizeForTesting
- UseSynchronousResizeModeForTesting
- EnableAutoResizeForTesting
- DisableAutoResizeForTesting
- SetMediaStreamClientForTesting
- OnReleaseDisambiguationPopupDIB
- DidCommitCompositorFrame
- SendUpdateFaviconURL
- DidStopLoadingIcons
#include "content/renderer/render_view_impl.h"
#include <algorithm>
#include <cmath>
#include "base/auto_reset.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/command_line.h"
#include "base/compiler_specific.h"
#include "base/debug/alias.h"
#include "base/debug/trace_event.h"
#include "base/files/file_path.h"
#include "base/i18n/rtl.h"
#include "base/json/json_writer.h"
#include "base/lazy_instance.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop_proxy.h"
#include "base/metrics/histogram.h"
#include "base/path_service.h"
#include "base/process/kill.h"
#include "base/process/process.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "cc/base/switches.h"
#include "content/child/appcache/appcache_dispatcher.h"
#include "content/child/appcache/web_application_cache_host_impl.h"
#include "content/child/child_thread.h"
#include "content/child/npapi/webplugin_delegate_impl.h"
#include "content/child/request_extra_data.h"
#include "content/child/webmessageportchannel_impl.h"
#include "content/common/database_messages.h"
#include "content/common/dom_storage/dom_storage_types.h"
#include "content/common/drag_messages.h"
#include "content/common/frame_messages.h"
#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
#include "content/common/input_messages.h"
#include "content/common/pepper_messages.h"
#include "content/common/socket_stream_handle_data.h"
#include "content/common/ssl_status_serialization.h"
#include "content/common/view_messages.h"
#include "content/public/common/bindings_policy.h"
#include "content/public/common/content_client.h"
#include "content/public/common/content_constants.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/drop_data.h"
#include "content/public/common/favicon_url.h"
#include "content/public/common/file_chooser_params.h"
#include "content/public/common/page_zoom.h"
#include "content/public/common/ssl_status.h"
#include "content/public/common/three_d_api_types.h"
#include "content/public/common/url_constants.h"
#include "content/public/common/url_utils.h"
#include "content/public/renderer/content_renderer_client.h"
#include "content/public/renderer/document_state.h"
#include "content/public/renderer/history_item_serialization.h"
#include "content/public/renderer/navigation_state.h"
#include "content/public/renderer/render_view_observer.h"
#include "content/public/renderer/render_view_visitor.h"
#include "content/public/renderer/web_preferences.h"
#include "content/renderer/accessibility/renderer_accessibility.h"
#include "content/renderer/accessibility/renderer_accessibility_complete.h"
#include "content/renderer/accessibility/renderer_accessibility_focus_only.h"
#include "content/renderer/browser_plugin/browser_plugin.h"
#include "content/renderer/browser_plugin/browser_plugin_manager.h"
#include "content/renderer/browser_plugin/browser_plugin_manager_impl.h"
#include "content/renderer/devtools/devtools_agent.h"
#include "content/renderer/disambiguation_popup_helper.h"
#include "content/renderer/dom_storage/webstoragenamespace_impl.h"
#include "content/renderer/drop_data_builder.h"
#include "content/renderer/external_popup_menu.h"
#include "content/renderer/geolocation_dispatcher.h"
#include "content/renderer/gpu/render_widget_compositor.h"
#include "content/renderer/idle_user_detector.h"
#include "content/renderer/ime_event_guard.h"
#include "content/renderer/input/input_handler_manager.h"
#include "content/renderer/input_tag_speech_dispatcher.h"
#include "content/renderer/internal_document_state_data.h"
#include "content/renderer/load_progress_tracker.h"
#include "content/renderer/media/audio_device_factory.h"
#include "content/renderer/media/audio_renderer_mixer_manager.h"
#include "content/renderer/media/media_stream_dependency_factory.h"
#include "content/renderer/media/media_stream_dispatcher.h"
#include "content/renderer/media/media_stream_impl.h"
#include "content/renderer/media/midi_dispatcher.h"
#include "content/renderer/media/render_media_log.h"
#include "content/renderer/media/video_capture_impl_manager.h"
#include "content/renderer/media/webmediaplayer_impl.h"
#include "content/renderer/media/webmediaplayer_ms.h"
#include "content/renderer/media/webmediaplayer_params.h"
#include "content/renderer/memory_benchmarking_extension.h"
#include "content/renderer/mhtml_generator.h"
#include "content/renderer/notification_provider.h"
#include "content/renderer/render_frame_impl.h"
#include "content/renderer/render_process.h"
#include "content/renderer/render_thread_impl.h"
#include "content/renderer/render_view_impl_params.h"
#include "content/renderer/render_view_mouse_lock_dispatcher.h"
#include "content/renderer/render_widget_fullscreen_pepper.h"
#include "content/renderer/renderer_webapplicationcachehost_impl.h"
#include "content/renderer/renderer_webcolorchooser_impl.h"
#include "content/renderer/resizing_mode_selector.h"
#include "content/renderer/savable_resources.h"
#include "content/renderer/skia_benchmarking_extension.h"
#include "content/renderer/speech_recognition_dispatcher.h"
#include "content/renderer/stats_collection_controller.h"
#include "content/renderer/stats_collection_observer.h"
#include "content/renderer/text_input_client_observer.h"
#include "content/renderer/v8_value_converter_impl.h"
#include "content/renderer/web_ui_extension.h"
#include "content/renderer/web_ui_extension_data.h"
#include "content/renderer/websharedworker_proxy.h"
#include "media/audio/audio_output_device.h"
#include "media/base/audio_renderer_mixer_input.h"
#include "media/base/filter_collection.h"
#include "media/base/media_switches.h"
#include "media/filters/audio_renderer_impl.h"
#include "media/filters/gpu_video_accelerator_factories.h"
#include "net/base/data_url.h"
#include "net/base/escape.h"
#include "net/base/net_errors.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "net/http/http_util.h"
#include "third_party/WebKit/public/platform/WebCString.h"
#include "third_party/WebKit/public/platform/WebDragData.h"
#include "third_party/WebKit/public/platform/WebHTTPBody.h"
#include "third_party/WebKit/public/platform/WebImage.h"
#include "third_party/WebKit/public/platform/WebMessagePortChannel.h"
#include "third_party/WebKit/public/platform/WebPoint.h"
#include "third_party/WebKit/public/platform/WebRect.h"
#include "third_party/WebKit/public/platform/WebSize.h"
#include "third_party/WebKit/public/platform/WebSocketStreamHandle.h"
#include "third_party/WebKit/public/platform/WebStorageQuotaCallbacks.h"
#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/platform/WebURL.h"
#include "third_party/WebKit/public/platform/WebURLError.h"
#include "third_party/WebKit/public/platform/WebURLRequest.h"
#include "third_party/WebKit/public/platform/WebURLResponse.h"
#include "third_party/WebKit/public/platform/WebVector.h"
#include "third_party/WebKit/public/web/WebAXObject.h"
#include "third_party/WebKit/public/web/WebColorName.h"
#include "third_party/WebKit/public/web/WebColorSuggestion.h"
#include "third_party/WebKit/public/web/WebDOMEvent.h"
#include "third_party/WebKit/public/web/WebDOMMessageEvent.h"
#include "third_party/WebKit/public/web/WebDataSource.h"
#include "third_party/WebKit/public/web/WebDateTimeChooserCompletion.h"
#include "third_party/WebKit/public/web/WebDateTimeChooserParams.h"
#include "third_party/WebKit/public/web/WebDevToolsAgent.h"
#include "third_party/WebKit/public/web/WebDocument.h"
#include "third_party/WebKit/public/web/WebElement.h"
#include "third_party/WebKit/public/web/WebFileChooserParams.h"
#include "third_party/WebKit/public/web/WebFindOptions.h"
#include "third_party/WebKit/public/web/WebFormControlElement.h"
#include "third_party/WebKit/public/web/WebFormElement.h"
#include "third_party/WebKit/public/web/WebFrame.h"
#include "third_party/WebKit/public/web/WebGlyphCache.h"
#include "third_party/WebKit/public/web/WebHistoryItem.h"
#include "third_party/WebKit/public/web/WebInputElement.h"
#include "third_party/WebKit/public/web/WebInputEvent.h"
#include "third_party/WebKit/public/web/WebLocalFrame.h"
#include "third_party/WebKit/public/web/WebMediaPlayerAction.h"
#include "third_party/WebKit/public/web/WebNavigationPolicy.h"
#include "third_party/WebKit/public/web/WebNodeList.h"
#include "third_party/WebKit/public/web/WebPageSerializer.h"
#include "third_party/WebKit/public/web/WebPlugin.h"
#include "third_party/WebKit/public/web/WebPluginAction.h"
#include "third_party/WebKit/public/web/WebPluginContainer.h"
#include "third_party/WebKit/public/web/WebPluginDocument.h"
#include "third_party/WebKit/public/web/WebRange.h"
#include "third_party/WebKit/public/web/WebScriptSource.h"
#include "third_party/WebKit/public/web/WebSearchableFormData.h"
#include "third_party/WebKit/public/web/WebSecurityOrigin.h"
#include "third_party/WebKit/public/web/WebSecurityPolicy.h"
#include "third_party/WebKit/public/web/WebSerializedScriptValue.h"
#include "third_party/WebKit/public/web/WebSettings.h"
#include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
#include "third_party/WebKit/public/web/WebUserMediaClient.h"
#include "third_party/WebKit/public/web/WebView.h"
#include "third_party/WebKit/public/web/WebWindowFeatures.h"
#include "third_party/WebKit/public/web/default/WebRenderTheme.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/ui_base_switches_util.h"
#include "ui/events/latency_info.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/point.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/rect_conversions.h"
#include "ui/gfx/size_conversions.h"
#include "ui/shell_dialogs/selected_file_info.h"
#include "v8/include/v8.h"
#include "webkit/child/weburlresponse_extradata_impl.h"
#if defined(OS_ANDROID)
#include <cpu-features.h>
#include "content/common/android/device_telephony_info.h"
#include "content/common/gpu/client/context_provider_command_buffer.h"
#include "content/renderer/android/address_detector.h"
#include "content/renderer/android/content_detector.h"
#include "content/renderer/android/email_detector.h"
#include "content/renderer/android/phone_number_detector.h"
#include "content/renderer/android/synchronous_compositor_factory.h"
#include "content/renderer/media/android/renderer_media_player_manager.h"
#include "content/renderer/media/android/stream_texture_factory_impl.h"
#include "content/renderer/media/android/webmediaplayer_android.h"
#include "skia/ext/platform_canvas.h"
#include "third_party/WebKit/public/platform/WebFloatPoint.h"
#include "third_party/WebKit/public/platform/WebFloatRect.h"
#include "third_party/WebKit/public/web/WebHitTestResult.h"
#include "ui/gfx/rect_f.h"
#elif defined(OS_WIN)
#include "ui/native_theme/native_theme_win.h"
#elif defined(USE_X11)
#include "ui/native_theme/native_theme.h"
#elif defined(OS_MACOSX)
#include "skia/ext/skia_utils_mac.h"
#endif
#if defined(ENABLE_PLUGINS)
#include "content/renderer/npapi/webplugin_delegate_proxy.h"
#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
#include "content/renderer/pepper/pepper_plugin_registry.h"
#endif
#if defined(ENABLE_WEBRTC)
#include "content/renderer/media/rtc_peer_connection_handler.h"
#endif
#if defined(USE_MOJO)
#include "content/renderer/web_ui_mojo.h"
#endif
using blink::WebAXObject;
using blink::WebApplicationCacheHost;
using blink::WebApplicationCacheHostClient;
using blink::WebCString;
using blink::WebColor;
using blink::WebColorName;
using blink::WebConsoleMessage;
using blink::WebData;
using blink::WebDataSource;
using blink::WebDocument;
using blink::WebDOMEvent;
using blink::WebDOMMessageEvent;
using blink::WebDragData;
using blink::WebDragOperation;
using blink::WebDragOperationsMask;
using blink::WebElement;
using blink::WebExternalPopupMenu;
using blink::WebExternalPopupMenuClient;
using blink::WebFileChooserCompletion;
using blink::WebFindOptions;
using blink::WebFormControlElement;
using blink::WebFormElement;
using blink::WebFrame;
using blink::WebGestureEvent;
using blink::WebHistoryItem;
using blink::WebHTTPBody;
using blink::WebIconURL;
using blink::WebImage;
using blink::WebInputElement;
using blink::WebInputEvent;
using blink::WebLocalFrame;
using blink::WebMediaPlayer;
using blink::WebMediaPlayerAction;
using blink::WebMediaPlayerClient;
using blink::WebMouseEvent;
using blink::WebNavigationPolicy;
using blink::WebNavigationType;
using blink::WebNode;
using blink::WebPageSerializer;
using blink::WebPageSerializerClient;
using blink::WebPeerConnection00Handler;
using blink::WebPeerConnection00HandlerClient;
using blink::WebPeerConnectionHandler;
using blink::WebPeerConnectionHandlerClient;
using blink::WebPluginAction;
using blink::WebPluginContainer;
using blink::WebPluginDocument;
using blink::WebPoint;
using blink::WebPopupMenuInfo;
using blink::WebRange;
using blink::WebRect;
using blink::WebReferrerPolicy;
using blink::WebScriptSource;
using blink::WebSearchableFormData;
using blink::WebSecurityOrigin;
using blink::WebSecurityPolicy;
using blink::WebSerializedScriptValue;
using blink::WebSettings;
using blink::WebSize;
using blink::WebSocketStreamHandle;
using blink::WebStorageNamespace;
using blink::WebStorageQuotaCallbacks;
using blink::WebStorageQuotaError;
using blink::WebStorageQuotaType;
using blink::WebString;
using blink::WebTextAffinity;
using blink::WebTextDirection;
using blink::WebTouchEvent;
using blink::WebURL;
using blink::WebURLError;
using blink::WebURLRequest;
using blink::WebURLResponse;
using blink::WebUserGestureIndicator;
using blink::WebVector;
using blink::WebView;
using blink::WebWidget;
using blink::WebWindowFeatures;
using base::Time;
using base::TimeDelta;
using webkit_glue::WebURLResponseExtraDataImpl;
#if defined(OS_ANDROID)
using blink::WebContentDetectionResult;
using blink::WebFloatPoint;
using blink::WebFloatRect;
using blink::WebHitTestResult;
#endif
namespace content {
typedef std::map<blink::WebView*, RenderViewImpl*> ViewMap;
static base::LazyInstance<ViewMap> g_view_map = LAZY_INSTANCE_INITIALIZER;
typedef std::map<int32, RenderViewImpl*> RoutingIDViewMap;
static base::LazyInstance<RoutingIDViewMap> g_routing_id_view_map =
LAZY_INSTANCE_INITIALIZER;
const int kDelaySecondsForContentStateSyncHidden = 5;
const int kDelaySecondsForContentStateSync = 1;
#if defined(OS_ANDROID)
const size_t kContentIntentDelayMilliseconds = 700;
#endif
static RenderViewImpl* (*g_create_render_view_impl)(RenderViewImplParams*) =
NULL;
bool RenderViewImpl::IsReload(const FrameMsg_Navigate_Params& params) {
return
params.navigation_type == FrameMsg_Navigate_Type::RELOAD ||
params.navigation_type == FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE ||
params.navigation_type ==
FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
}
Referrer RenderViewImpl::GetReferrerFromRequest(
WebFrame* frame,
const WebURLRequest& request) {
return Referrer(GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
request.referrerPolicy());
}
WindowOpenDisposition RenderViewImpl::NavigationPolicyToDisposition(
WebNavigationPolicy policy) {
switch (policy) {
case blink::WebNavigationPolicyIgnore:
return IGNORE_ACTION;
case blink::WebNavigationPolicyDownload:
return SAVE_TO_DISK;
case blink::WebNavigationPolicyCurrentTab:
return CURRENT_TAB;
case blink::WebNavigationPolicyNewBackgroundTab:
return NEW_BACKGROUND_TAB;
case blink::WebNavigationPolicyNewForegroundTab:
return NEW_FOREGROUND_TAB;
case blink::WebNavigationPolicyNewWindow:
return NEW_WINDOW;
case blink::WebNavigationPolicyNewPopup:
return NEW_POPUP;
default:
NOTREACHED() << "Unexpected WebNavigationPolicy";
return IGNORE_ACTION;
}
}
static bool DeviceScaleEnsuresTextQuality(float device_scale_factor) {
#if defined(OS_ANDROID)
return true;
#else
return device_scale_factor > 1.5f;
#endif
}
static bool ShouldUseFixedPositionCompositing(float device_scale_factor) {
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kDisableCompositingForFixedPosition))
return false;
if (command_line.HasSwitch(switches::kEnableCompositingForFixedPosition))
return true;
return DeviceScaleEnsuresTextQuality(device_scale_factor);
}
static bool ShouldUseAcceleratedCompositingForOverflowScroll(
float device_scale_factor) {
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kDisableAcceleratedOverflowScroll))
return false;
if (command_line.HasSwitch(switches::kEnableAcceleratedOverflowScroll))
return true;
return DeviceScaleEnsuresTextQuality(device_scale_factor);
}
static bool ShouldUseAcceleratedCompositingForScrollableFrames(
float device_scale_factor) {
if (RenderThreadImpl::current() &&
!RenderThreadImpl::current()->is_lcd_text_enabled())
return true;
return DeviceScaleEnsuresTextQuality(device_scale_factor);
}
static bool ShouldUseCompositedScrollingForFrames(
float device_scale_factor) {
if (RenderThreadImpl::current() &&
!RenderThreadImpl::current()->is_lcd_text_enabled())
return true;
return DeviceScaleEnsuresTextQuality(device_scale_factor);
}
static bool ShouldUseUniversalAcceleratedCompositingForOverflowScroll() {
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(
switches::kDisableUniversalAcceleratedOverflowScroll))
return false;
if (command_line.HasSwitch(
switches::kEnableUniversalAcceleratedOverflowScroll))
return true;
return false;
}
static bool ShouldUseTransitionCompositing(float device_scale_factor) {
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kDisableCompositingForTransition))
return false;
if (command_line.HasSwitch(switches::kEnableCompositingForTransition))
return true;
return false;
}
static bool ShouldUseAcceleratedFixedRootBackground(float device_scale_factor) {
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kDisableAcceleratedFixedRootBackground))
return false;
if (command_line.HasSwitch(switches::kEnableAcceleratedFixedRootBackground))
return true;
return DeviceScaleEnsuresTextQuality(device_scale_factor);
}
static bool ShouldUseCompositingForGpuRasterizationHint() {
return RenderThreadImpl::current() &&
RenderThreadImpl::current()->is_gpu_rasterization_enabled();
}
static FaviconURL::IconType ToFaviconType(blink::WebIconURL::Type type) {
switch (type) {
case blink::WebIconURL::TypeFavicon:
return FaviconURL::FAVICON;
case blink::WebIconURL::TypeTouch:
return FaviconURL::TOUCH_ICON;
case blink::WebIconURL::TypeTouchPrecomposed:
return FaviconURL::TOUCH_PRECOMPOSED_ICON;
case blink::WebIconURL::TypeInvalid:
return FaviconURL::INVALID_ICON;
}
return FaviconURL::INVALID_ICON;
}
static void ConvertToFaviconSizes(
const blink::WebVector<blink::WebSize>& web_sizes,
std::vector<gfx::Size>* sizes) {
for (size_t i = 0; i < web_sizes.size(); ++i)
sizes->push_back(gfx::Size(web_sizes[i]));
}
struct RenderViewImpl::PendingFileChooser {
PendingFileChooser(const FileChooserParams& p, WebFileChooserCompletion* c)
: params(p),
completion(c) {
}
FileChooserParams params;
WebFileChooserCompletion* completion;
};
namespace {
class WebWidgetLockTarget : public MouseLockDispatcher::LockTarget {
public:
explicit WebWidgetLockTarget(blink::WebWidget* webwidget)
: webwidget_(webwidget) {}
virtual void OnLockMouseACK(bool succeeded) OVERRIDE {
if (succeeded)
webwidget_->didAcquirePointerLock();
else
webwidget_->didNotAcquirePointerLock();
}
virtual void OnMouseLockLost() OVERRIDE {
webwidget_->didLosePointerLock();
}
virtual bool HandleMouseLockedInputEvent(
const blink::WebMouseEvent &event) OVERRIDE {
return false;
}
private:
blink::WebWidget* webwidget_;
};
bool TouchEnabled() {
#if defined(OS_ANDROID)
return true;
#else
return false;
#endif
}
WebDragData DropDataToWebDragData(const DropData& drop_data) {
std::vector<WebDragData::Item> item_list;
DCHECK(drop_data.download_metadata.empty());
DCHECK(drop_data.file_contents.empty());
DCHECK(drop_data.file_description_filename.empty());
if (!drop_data.text.is_null()) {
WebDragData::Item item;
item.storageType = WebDragData::Item::StorageTypeString;
item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeText);
item.stringData = drop_data.text.string();
item_list.push_back(item);
}
if (!drop_data.url.is_empty()) {
WebDragData::Item item;
item.storageType = WebDragData::Item::StorageTypeString;
item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeURIList);
item.stringData = WebString::fromUTF8(drop_data.url.spec());
item.title = drop_data.url_title;
item_list.push_back(item);
}
if (!drop_data.html.is_null()) {
WebDragData::Item item;
item.storageType = WebDragData::Item::StorageTypeString;
item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeHTML);
item.stringData = drop_data.html.string();
item.baseURL = drop_data.html_base_url;
item_list.push_back(item);
}
for (std::vector<ui::FileInfo>::const_iterator it =
drop_data.filenames.begin();
it != drop_data.filenames.end();
++it) {
WebDragData::Item item;
item.storageType = WebDragData::Item::StorageTypeFilename;
item.filenameData = it->path.AsUTF16Unsafe();
item.displayNameData = it->display_name.AsUTF16Unsafe();
item_list.push_back(item);
}
for (std::map<base::string16, base::string16>::const_iterator it =
drop_data.custom_data.begin();
it != drop_data.custom_data.end();
++it) {
WebDragData::Item item;
item.storageType = WebDragData::Item::StorageTypeString;
item.stringType = it->first;
item.stringData = it->second;
item_list.push_back(item);
}
WebDragData result;
result.initialize();
result.setItems(item_list);
result.setFilesystemId(drop_data.filesystem_id);
return result;
}
}
RenderViewImpl::RenderViewImpl(RenderViewImplParams* params)
: RenderWidget(blink::WebPopupTypeNone,
params->screen_info,
params->swapped_out,
params->hidden),
webkit_preferences_(params->webkit_prefs),
send_content_state_immediately_(false),
enabled_bindings_(0),
send_preferred_size_changes_(false),
navigation_gesture_(NavigationGestureUnknown),
opened_by_user_gesture_(true),
opener_suppressed_(false),
suppress_dialogs_until_swap_out_(false),
page_id_(-1),
last_page_id_sent_to_browser_(-1),
next_page_id_(params->next_page_id),
history_list_offset_(-1),
history_list_length_(0),
frames_in_progress_(0),
target_url_status_(TARGET_NONE),
#if defined(OS_ANDROID)
top_controls_constraints_(cc::BOTH),
#endif
cached_is_main_frame_pinned_to_left_(false),
cached_is_main_frame_pinned_to_right_(false),
cached_has_main_frame_horizontal_scrollbar_(false),
cached_has_main_frame_vertical_scrollbar_(false),
has_scrolled_focused_editable_node_into_rect_(false),
notification_provider_(NULL),
geolocation_dispatcher_(NULL),
input_tag_speech_dispatcher_(NULL),
speech_recognition_dispatcher_(NULL),
media_stream_dispatcher_(NULL),
browser_plugin_manager_(NULL),
media_stream_client_(NULL),
web_user_media_client_(NULL),
midi_dispatcher_(NULL),
devtools_agent_(NULL),
accessibility_mode_(AccessibilityModeOff),
renderer_accessibility_(NULL),
mouse_lock_dispatcher_(NULL),
#if defined(OS_ANDROID)
body_background_color_(SK_ColorWHITE),
expected_content_intent_id_(0),
media_player_manager_(NULL),
#endif
#if defined(OS_WIN)
focused_plugin_id_(-1),
#endif
#if defined(ENABLE_PLUGINS)
plugin_find_handler_(NULL),
focused_pepper_plugin_(NULL),
pepper_last_mouse_event_target_(NULL),
#endif
enumeration_completion_id_(0),
load_progress_tracker_(new LoadProgressTracker(this)),
session_storage_namespace_id_(params->session_storage_namespace_id),
next_snapshot_id_(0) {
}
void RenderViewImpl::Initialize(RenderViewImplParams* params) {
routing_id_ = params->routing_id;
surface_id_ = params->surface_id;
if (params->opener_id != MSG_ROUTING_NONE && params->is_renderer_created)
opener_id_ = params->opener_id;
DCHECK_GE(next_page_id_, 0);
#if defined(ENABLE_NOTIFICATIONS)
notification_provider_ = new NotificationProvider(this);
#else
notification_provider_ = NULL;
#endif
webwidget_ = WebView::create(this);
webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_));
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kStatsCollectionController))
stats_collection_observer_.reset(new StatsCollectionObserver(this));
#if defined(OS_ANDROID)
content::DeviceTelephonyInfo device_info;
const std::string region_code =
command_line.HasSwitch(switches::kNetworkCountryIso)
? command_line.GetSwitchValueASCII(switches::kNetworkCountryIso)
: device_info.GetNetworkCountryIso();
content_detectors_.push_back(linked_ptr<ContentDetector>(
new AddressDetector()));
content_detectors_.push_back(linked_ptr<ContentDetector>(
new PhoneNumberDetector(region_code)));
content_detectors_.push_back(linked_ptr<ContentDetector>(
new EmailDetector()));
#endif
RenderThread::Get()->AddRoute(routing_id_, this);
AddRef();
if (RenderThreadImpl::current()) {
RenderThreadImpl::current()->WidgetCreated();
if (is_hidden_)
RenderThreadImpl::current()->WidgetHidden();
}
if (opener_id_ == MSG_ROUTING_NONE) {
did_show_ = true;
CompleteInit();
}
g_view_map.Get().insert(std::make_pair(webview(), this));
g_routing_id_view_map.Get().insert(std::make_pair(routing_id_, this));
webview()->setDeviceScaleFactor(device_scale_factor_);
webview()->settings()->setAcceleratedCompositingForFixedPositionEnabled(
ShouldUseFixedPositionCompositing(device_scale_factor_));
webview()->settings()->setAcceleratedCompositingForOverflowScrollEnabled(
ShouldUseAcceleratedCompositingForOverflowScroll(device_scale_factor_));
webview()->settings()->setCompositorDrivenAcceleratedScrollingEnabled(
ShouldUseUniversalAcceleratedCompositingForOverflowScroll());
webview()->settings()->setAcceleratedCompositingForTransitionEnabled(
ShouldUseTransitionCompositing(device_scale_factor_));
webview()->settings()->setAcceleratedCompositingForFixedRootBackgroundEnabled(
ShouldUseAcceleratedFixedRootBackground(device_scale_factor_));
webview()->settings()->setAcceleratedCompositingForScrollableFramesEnabled(
ShouldUseAcceleratedCompositingForScrollableFrames(device_scale_factor_));
webview()->settings()->setCompositedScrollingForFramesEnabled(
ShouldUseCompositedScrollingForFrames(device_scale_factor_));
webview()->settings()
->setAcceleratedCompositingForGpuRasterizationHintEnabled(
ShouldUseCompositingForGpuRasterizationHint());
ApplyWebPreferences(webkit_preferences_, webview());
main_render_frame_.reset(
RenderFrameImpl::Create(this, params->main_frame_routing_id));
webview()->setMainFrame(WebLocalFrame::create(main_render_frame_.get()));
main_render_frame_->SetWebFrame(webview()->mainFrame()->toWebLocalFrame());
if (switches::IsTouchDragDropEnabled())
webview()->settings()->setTouchDragDropEnabled(true);
if (switches::IsTouchEditingEnabled())
webview()->settings()->setTouchEditingEnabled(true);
if (!params->frame_name.empty())
webview()->mainFrame()->setName(params->frame_name);
OnSetRendererPrefs(params->renderer_prefs);
#if defined(ENABLE_WEBRTC)
if (!media_stream_dispatcher_)
media_stream_dispatcher_ = new MediaStreamDispatcher(this);
#endif
new MHTMLGenerator(this);
#if defined(OS_MACOSX)
new TextInputClientObserver(this);
#endif
#if defined(OS_ANDROID)
media_player_manager_ = new RendererMediaPlayerManager(this);
#endif
devtools_agent_ = new DevToolsAgent(this);
if (RenderWidgetCompositor* rwc = compositor()) {
webview()->devToolsAgent()->setLayerTreeId(rwc->GetLayerTreeId());
}
mouse_lock_dispatcher_ = new RenderViewMouseLockDispatcher(this);
OnSetAccessibilityMode(params->accessibility_mode);
new IdleUserDetector(this);
if (command_line.HasSwitch(switches::kDomAutomationController))
enabled_bindings_ |= BINDINGS_POLICY_DOM_AUTOMATION;
if (command_line.HasSwitch(switches::kStatsCollectionController))
enabled_bindings_ |= BINDINGS_POLICY_STATS_COLLECTION;
ProcessViewLayoutFlags(command_line);
GetContentClient()->renderer()->RenderViewCreated(this);
if (params->opener_id != MSG_ROUTING_NONE && !params->is_renderer_created) {
RenderViewImpl* opener_view = FromRoutingID(params->opener_id);
if (opener_view)
webview()->mainFrame()->setOpener(opener_view->webview()->mainFrame());
}
if (is_swapped_out_)
NavigateToSwappedOutURL(webview()->mainFrame());
}
RenderViewImpl::~RenderViewImpl() {
history_page_ids_.clear();
base::debug::TraceLog::GetInstance()->RemoveProcessLabel(routing_id_);
while (!file_chooser_completions_.empty()) {
if (file_chooser_completions_.front()->completion) {
file_chooser_completions_.front()->completion->didChooseFile(
WebVector<WebString>());
}
file_chooser_completions_.pop_front();
}
#if defined(OS_ANDROID)
date_time_picker_client_.reset();
#endif
#ifndef NDEBUG
ViewMap* views = g_view_map.Pointer();
for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
DCHECK_NE(this, it->second) << "Failed to call Close?";
RoutingIDViewMap* routing_id_views = g_routing_id_view_map.Pointer();
for (RoutingIDViewMap::iterator it = routing_id_views->begin();
it != routing_id_views->end(); ++it)
DCHECK_NE(this, it->second) << "Failed to call Close?";
#endif
FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone());
FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
}
RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
ViewMap* views = g_view_map.Pointer();
ViewMap::iterator it = views->find(webview);
return it == views->end() ? NULL : it->second;
}
RenderView* RenderView::FromWebView(blink::WebView* webview) {
return RenderViewImpl::FromWebView(webview);
}
RenderViewImpl* RenderViewImpl::FromRoutingID(int32 routing_id) {
RoutingIDViewMap* views = g_routing_id_view_map.Pointer();
RoutingIDViewMap::iterator it = views->find(routing_id);
return it == views->end() ? NULL : it->second;
}
RenderView* RenderView::FromRoutingID(int routing_id) {
return RenderViewImpl::FromRoutingID(routing_id);
}
void RenderView::ForEach(RenderViewVisitor* visitor) {
ViewMap* views = g_view_map.Pointer();
for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
if (!visitor->Visit(it->second))
return;
}
}
RenderViewImpl* RenderViewImpl::Create(
int32 opener_id,
const RendererPreferences& renderer_prefs,
const WebPreferences& webkit_prefs,
int32 routing_id,
int32 main_frame_routing_id,
int32 surface_id,
int64 session_storage_namespace_id,
const base::string16& frame_name,
bool is_renderer_created,
bool swapped_out,
bool hidden,
int32 next_page_id,
const blink::WebScreenInfo& screen_info,
AccessibilityMode accessibility_mode) {
DCHECK(routing_id != MSG_ROUTING_NONE);
RenderViewImplParams params(opener_id,
renderer_prefs,
webkit_prefs,
routing_id,
main_frame_routing_id,
surface_id,
session_storage_namespace_id,
frame_name,
is_renderer_created,
swapped_out,
hidden,
next_page_id,
screen_info,
accessibility_mode);
RenderViewImpl* render_view = NULL;
if (g_create_render_view_impl)
render_view = g_create_render_view_impl(¶ms);
else
render_view = new RenderViewImpl(¶ms);
render_view->Initialize(¶ms);
return render_view;
}
void RenderViewImpl::InstallCreateHook(
RenderViewImpl* (*create_render_view_impl)(RenderViewImplParams*)) {
CHECK(!g_create_render_view_impl);
g_create_render_view_impl = create_render_view_impl;
}
void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
observers_.AddObserver(observer);
}
void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
observer->RenderViewGone();
observers_.RemoveObserver(observer);
}
blink::WebView* RenderViewImpl::webview() const {
return static_cast<blink::WebView*>(webwidget());
}
#if defined(ENABLE_PLUGINS)
void RenderViewImpl::PepperInstanceCreated(
PepperPluginInstanceImpl* instance) {
active_pepper_instances_.insert(instance);
}
void RenderViewImpl::PepperInstanceDeleted(
PepperPluginInstanceImpl* instance) {
active_pepper_instances_.erase(instance);
if (pepper_last_mouse_event_target_ == instance)
pepper_last_mouse_event_target_ = NULL;
if (focused_pepper_plugin_ == instance)
PepperFocusChanged(instance, false);
}
void RenderViewImpl::PepperFocusChanged(PepperPluginInstanceImpl* instance,
bool focused) {
if (focused)
focused_pepper_plugin_ = instance;
else if (focused_pepper_plugin_ == instance)
focused_pepper_plugin_ = NULL;
UpdateTextInputType();
UpdateSelectionBounds();
}
void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
plugin_delegates_.insert(delegate);
if (!is_hidden()) {
#if defined(OS_MACOSX)
delegate->SetContainerVisibility(true);
if (webview() && webview()->isActive())
delegate->SetWindowFocus(true);
#endif
}
delegate->SetContentAreaFocus(has_focus());
}
void RenderViewImpl::UnregisterPluginDelegate(
WebPluginDelegateProxy* delegate) {
plugin_delegates_.erase(delegate);
}
#if defined(OS_WIN)
void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
if (focused)
focused_plugin_id_ = plugin_id;
else
focused_plugin_id_ = -1;
}
#endif
#if defined(OS_MACOSX)
void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
Send(new ViewHostMsg_PluginFocusChanged(routing_id(), focused, plugin_id));
}
void RenderViewImpl::StartPluginIme() {
IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
msg->set_unblock(true);
Send(msg);
}
#endif
#endif
void RenderViewImpl::TransferActiveWheelFlingAnimation(
const blink::WebActiveWheelFlingParameters& params) {
if (webview())
webview()->transferActiveWheelFlingAnimation(params);
}
bool RenderViewImpl::HasIMETextFocus() {
return GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE;
}
bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
if (main_frame)
GetContentClient()->SetActiveURL(main_frame->document().url());
ObserverListBase<RenderViewObserver>::Iterator it(observers_);
RenderViewObserver* observer;
while ((observer = it.GetNext()) != NULL)
if (observer->OnMessageReceived(message))
return true;
bool handled = true;
bool msg_is_ok = true;
IPC_BEGIN_MESSAGE_MAP_EX(RenderViewImpl, message, msg_is_ok)
IPC_MESSAGE_HANDLER(InputMsg_ExecuteEditCommand, OnExecuteEditCommand)
IPC_MESSAGE_HANDLER(InputMsg_MoveCaret, OnMoveCaret)
IPC_MESSAGE_HANDLER(InputMsg_ScrollFocusedEditableNodeIntoRect,
OnScrollFocusedEditableNodeIntoRect)
IPC_MESSAGE_HANDLER(InputMsg_SetEditCommandsForNextKeyEvent,
OnSetEditCommandsForNextKeyEvent)
IPC_MESSAGE_HANDLER(FrameMsg_Navigate, OnNavigate)
IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
IPC_MESSAGE_HANDLER(ViewMsg_SetName, OnSetName)
IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
OnSetZoomLevelForLoadingURL)
IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
OnResetPageEncodingToDefault)
IPC_MESSAGE_HANDLER(ViewMsg_PostMessageEvent, OnPostMessageEvent)
IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
IPC_MESSAGE_HANDLER(DragMsg_SourceEnded, OnDragSourceEnded)
IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
OnDragSourceSystemDragEnded)
IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
OnEnumerateDirectoryResponse)
IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
IPC_MESSAGE_HANDLER(ViewMsg_SuppressDialogsUntilSwapOut,
OnSuppressDialogsUntilSwapOut)
IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedElement, OnClearFocusedElement)
IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
OnEnablePreferredSizeChangedMode)
IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize)
IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize)
IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
OnDisableScrollbarsForSmallWindows)
IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
IPC_MESSAGE_HANDLER(ViewMsg_OrientationChangeEvent,
OnOrientationChangeEvent)
IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt)
IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
OnGetAllSavableResourceLinksForCurrentPage)
IPC_MESSAGE_HANDLER(
ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
IPC_MESSAGE_HANDLER(ViewMsg_ShowContextMenu, OnShowContextMenu)
IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune,
OnSetHistoryLengthAndPrune)
IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityMode, OnSetAccessibilityMode)
IPC_MESSAGE_HANDLER(ViewMsg_DisownOpener, OnDisownOpener)
IPC_MESSAGE_HANDLER(ViewMsg_ReleaseDisambiguationPopupDIB,
OnReleaseDisambiguationPopupDIB)
IPC_MESSAGE_HANDLER(ViewMsg_WindowSnapshotCompleted,
OnWindowSnapshotCompleted)
#if defined(OS_ANDROID)
IPC_MESSAGE_HANDLER(InputMsg_ActivateNearestFindResult,
OnActivateNearestFindResult)
IPC_MESSAGE_HANDLER(ViewMsg_FindMatchRects, OnFindMatchRects)
IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItems, OnSelectPopupMenuItems)
IPC_MESSAGE_HANDLER(ViewMsg_UpdateTopControlsState,
OnUpdateTopControlsState)
IPC_MESSAGE_HANDLER(ViewMsg_PauseVideo, OnPauseVideo)
IPC_MESSAGE_HANDLER(ViewMsg_ExtractSmartClipData, OnExtractSmartClipData)
#elif defined(OS_MACOSX)
IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
OnPluginImeCompositionCompleted)
IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize)
IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
#endif
IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
IPC_END_MESSAGE_MAP()
if (!msg_is_ok) {
CHECK(false) << "Unable to deserialize message in RenderViewImpl.";
}
return handled;
}
void RenderViewImpl::OnNavigate(const FrameMsg_Navigate_Params& params) {
FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url));
}
bool RenderViewImpl::IsBackForwardToStaleEntry(
const FrameMsg_Navigate_Params& params,
bool is_reload) {
bool is_back_forward = !is_reload && params.page_state.IsValid();
if (!is_back_forward || history_list_length_ <= 0)
return false;
DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_);
if (params.pending_history_list_offset >= history_list_length_)
return true;
int expected_page_id =
history_page_ids_[params.pending_history_list_offset];
if (expected_page_id > 0 && params.page_id != expected_page_id) {
if (params.page_id < expected_page_id)
return true;
history_page_ids_[params.pending_history_list_offset] = params.page_id;
}
return false;
}
void RenderViewImpl::OnStop() {
if (webview())
webview()->mainFrame()->stopLoading();
FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnStop());
main_render_frame_->OnStop();
}
void RenderViewImpl::OnCopyImageAt(int x, int y) {
webview()->copyImageAt(WebPoint(x, y));
}
void RenderViewImpl::OnUpdateTargetURLAck() {
if (target_url_status_ == TARGET_PENDING) {
Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
pending_target_url_));
}
target_url_status_ = TARGET_NONE;
}
void RenderViewImpl::OnExecuteEditCommand(const std::string& name,
const std::string& value) {
if (!webview() || !webview()->focusedFrame())
return;
webview()->focusedFrame()->executeCommand(
WebString::fromUTF8(name), WebString::fromUTF8(value));
}
void RenderViewImpl::OnMoveCaret(const gfx::Point& point) {
if (!webview())
return;
Send(new ViewHostMsg_MoveCaret_ACK(routing_id_));
webview()->focusedFrame()->moveCaretSelection(point);
}
void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect(
const gfx::Rect& rect) {
if (has_scrolled_focused_editable_node_into_rect_ &&
rect == rect_for_scrolled_focused_editable_node_) {
return;
}
blink::WebElement element = GetFocusedElement();
if (!element.isNull() && IsEditableNode(element)) {
rect_for_scrolled_focused_editable_node_ = rect;
has_scrolled_focused_editable_node_into_rect_ = true;
webview()->scrollFocusedNodeIntoRect(rect);
}
}
void RenderViewImpl::OnSetEditCommandsForNextKeyEvent(
const EditCommands& edit_commands) {
edit_commands_ = edit_commands;
}
void RenderViewImpl::OnSetName(const std::string& name) {
if (!webview())
return;
webview()->mainFrame()->setName(WebString::fromUTF8(name));
}
void RenderViewImpl::OnSetHistoryLengthAndPrune(int history_length,
int32 minimum_page_id) {
DCHECK_GE(history_length, 0);
DCHECK(history_list_offset_ == history_list_length_ - 1);
DCHECK_GE(minimum_page_id, -1);
std::vector<int32> new_history_page_ids(history_length, -1);
for (size_t i = 0; i < history_page_ids_.size(); ++i) {
if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id)
continue;
new_history_page_ids.push_back(history_page_ids_[i]);
}
new_history_page_ids.swap(history_page_ids_);
history_list_length_ = history_page_ids_.size();
history_list_offset_ = history_list_length_ - 1;
}
void RenderViewImpl::OnSetInitialFocus(bool reverse) {
if (!webview())
return;
webview()->setInitialFocus(reverse);
}
#if defined(OS_MACOSX)
void RenderViewImpl::OnSetInLiveResize(bool in_live_resize) {
if (!webview())
return;
if (in_live_resize)
webview()->willStartLiveResize();
else
webview()->willEndLiveResize();
}
#endif
#if defined(OS_ANDROID)
void RenderViewImpl::OnPauseVideo() {
media_player_manager_->ReleaseVideoResources();
}
#endif
void RenderViewImpl::UpdateTitle(WebFrame* frame,
const base::string16& title,
WebTextDirection title_direction) {
if (frame->parent())
return;
base::debug::TraceLog::GetInstance()->UpdateProcessLabel(
routing_id_, base::UTF16ToUTF8(title));
base::string16 shortened_title = title.substr(0, kMaxTitleChars);
Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title,
title_direction));
}
void RenderViewImpl::UpdateEncoding(WebFrame* frame,
const std::string& encoding_name) {
if (webview()->mainFrame() == frame &&
last_encoding_name_ != encoding_name) {
last_encoding_name_ = encoding_name;
Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
}
}
void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) {
if (page_id_ == -1)
return;
const WebHistoryItem& item =
webview()->mainFrame()->previousHistoryItem();
SendUpdateState(item);
}
void RenderViewImpl::SendUpdateState(const WebHistoryItem& item) {
if (item.isNull())
return;
if (item.urlString() == WebString::fromUTF8(kSwappedOutURL))
return;
Send(new ViewHostMsg_UpdateState(
routing_id_, page_id_, HistoryItemToPageState(item)));
}
void RenderViewImpl::LoadNavigationErrorPage(
WebFrame* frame,
const WebURLRequest& failed_request,
const WebURLError& error,
bool replace) {
std::string error_html;
GetContentClient()->renderer()->GetNavigationErrorStrings(
this, frame, failed_request, error, &error_html, NULL);
frame->loadHTMLString(error_html,
GURL(kUnreachableWebDataURL),
error.unreachableURL,
replace);
}
bool RenderViewImpl::RunJavaScriptMessage(JavaScriptMessageType type,
const base::string16& message,
const base::string16& default_value,
const GURL& frame_url,
base::string16* result) {
if (suppress_dialogs_until_swap_out_)
return false;
bool success = false;
base::string16 result_temp;
if (!result)
result = &result_temp;
SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
routing_id_, message, default_value, frame_url, type, &success, result));
return success;
}
bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
if (RenderThreadImpl::current())
RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop();
message->EnableMessagePumping();
return Send(message);
}
void RenderViewImpl::GetWindowSnapshot(const WindowSnapshotCallback& callback) {
int id = next_snapshot_id_++;
pending_snapshots_.insert(std::make_pair(id, callback));
ui::LatencyInfo latency_info;
latency_info.AddLatencyNumber(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT,
0,
id);
scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor;
if (RenderWidgetCompositor* rwc = compositor()) {
latency_info_swap_promise_monitor =
rwc->CreateLatencyInfoSwapPromiseMonitor(&latency_info).Pass();
} else {
latency_info_.push_back(latency_info);
}
ScheduleCompositeWithForcedRedraw();
}
void RenderViewImpl::OnWindowSnapshotCompleted(const int snapshot_id,
const gfx::Size& size, const std::vector<unsigned char>& png) {
PendingSnapshotMap::iterator it = pending_snapshots_.begin();
while(it != pending_snapshots_.end()) {
if (it->first <= snapshot_id) {
it->second.Run(size, png);
pending_snapshots_.erase(it++);
} else {
++it;
}
}
}
WebView* RenderViewImpl::createView(WebLocalFrame* creator,
const WebURLRequest& request,
const WebWindowFeatures& features,
const WebString& frame_name,
WebNavigationPolicy policy,
bool suppress_opener) {
ViewHostMsg_CreateWindow_Params params;
params.opener_id = routing_id_;
params.user_gesture = WebUserGestureIndicator::isProcessingUserGesture();
if (GetContentClient()->renderer()->AllowPopup())
params.user_gesture = true;
params.window_container_type = WindowFeaturesToContainerType(features);
params.session_storage_namespace_id = session_storage_namespace_id_;
if (frame_name != "_blank")
params.frame_name = frame_name;
params.opener_render_frame_id =
RenderFrameImpl::FromWebFrame(creator)->GetRoutingID();
params.opener_url = creator->document().url();
params.opener_top_level_frame_url = creator->top()->document().url();
GURL security_url(creator->document().securityOrigin().toString());
if (!security_url.is_valid())
security_url = GURL();
params.opener_security_origin = security_url;
params.opener_suppressed = suppress_opener;
params.disposition = NavigationPolicyToDisposition(policy);
if (!request.isNull()) {
params.target_url = request.url();
params.referrer = GetReferrerFromRequest(creator, request);
}
params.features = features;
for (size_t i = 0; i < features.additionalFeatures.size(); ++i)
params.additional_features.push_back(features.additionalFeatures[i]);
int32 routing_id = MSG_ROUTING_NONE;
int32 main_frame_routing_id = MSG_ROUTING_NONE;
int32 surface_id = 0;
int64 cloned_session_storage_namespace_id;
RenderThread::Get()->Send(
new ViewHostMsg_CreateWindow(params,
&routing_id,
&main_frame_routing_id,
&surface_id,
&cloned_session_storage_namespace_id));
if (routing_id == MSG_ROUTING_NONE)
return NULL;
WebUserGestureIndicator::consumeUserGesture();
WebPreferences transferred_preferences = webkit_preferences_;
if (!webkit_preferences_.accelerated_compositing_enabled) {
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (!command_line.HasSwitch(switches::kDisableAcceleratedCompositing))
transferred_preferences.accelerated_compositing_enabled = true;
}
RenderViewImpl* view = RenderViewImpl::Create(
routing_id_,
renderer_preferences_,
transferred_preferences,
routing_id,
main_frame_routing_id,
surface_id,
cloned_session_storage_namespace_id,
base::string16(),
true,
false,
params.disposition == NEW_BACKGROUND_TAB,
1,
screen_info_,
accessibility_mode_);
view->opened_by_user_gesture_ = params.user_gesture;
view->opener_suppressed_ = params.opener_suppressed;
return view->webview();
}
WebWidget* RenderViewImpl::createPopupMenu(blink::WebPopupType popup_type) {
RenderWidget* widget =
RenderWidget::Create(routing_id_, popup_type, screen_info_);
if (!widget)
return NULL;
if (screen_metrics_emulator_) {
widget->SetPopupOriginAdjustmentsForEmulation(
screen_metrics_emulator_.get());
}
return widget->webwidget();
}
WebExternalPopupMenu* RenderViewImpl::createExternalPopupMenu(
const WebPopupMenuInfo& popup_menu_info,
WebExternalPopupMenuClient* popup_menu_client) {
#if defined(OS_MACOSX) || defined(OS_ANDROID)
if (external_popup_menu_)
return NULL;
external_popup_menu_.reset(
new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
if (screen_metrics_emulator_) {
SetExternalPopupOriginAdjustmentsForEmulation(
external_popup_menu_.get(), screen_metrics_emulator_.get());
}
return external_popup_menu_.get();
#else
return NULL;
#endif
}
WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace() {
CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
return new WebStorageNamespaceImpl(session_storage_namespace_id_);
}
void RenderViewImpl::printPage(WebLocalFrame* frame) {
FOR_EACH_OBSERVER(RenderViewObserver, observers_,
PrintPage(frame, handling_input_event_));
}
blink::WebNotificationPresenter* RenderViewImpl::notificationPresenter() {
return notification_provider_;
}
bool RenderViewImpl::enumerateChosenDirectory(
const WebString& path,
WebFileChooserCompletion* chooser_completion) {
int id = enumeration_completion_id_++;
enumeration_completions_[id] = chooser_completion;
return Send(new ViewHostMsg_EnumerateDirectory(
routing_id_,
id,
base::FilePath::FromUTF16Unsafe(path)));
}
void RenderViewImpl::FrameDidStartLoading(WebFrame* frame) {
if (load_progress_tracker_ != NULL) {
load_progress_tracker_->DidStartLoading(
RenderFrameImpl::FromWebFrame(frame)->GetRoutingID());
}
DCHECK_GE(frames_in_progress_, 0);
if (frames_in_progress_ == 0)
FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading());
frames_in_progress_++;
}
void RenderViewImpl::FrameDidStopLoading(WebFrame* frame) {
if (load_progress_tracker_ != NULL) {
load_progress_tracker_->DidStopLoading(
RenderFrameImpl::FromWebFrame(frame)->GetRoutingID());
}
frames_in_progress_--;
DCHECK_GE(frames_in_progress_, 0);
if (frames_in_progress_ == 0) {
DidStopLoadingIcons();
FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading());
}
}
void RenderViewImpl::FrameDidChangeLoadProgress(WebFrame* frame,
double load_progress) {
if (load_progress_tracker_ != NULL) {
load_progress_tracker_->DidChangeLoadProgress(
RenderFrameImpl::FromWebFrame(frame)->GetRoutingID(), load_progress);
}
}
void RenderViewImpl::didCancelCompositionOnSelectionChange() {
Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
}
void RenderViewImpl::didExecuteCommand(const WebString& command_name) {
const std::string& name = base::UTF16ToUTF8(command_name);
if (StartsWithASCII(name, "Move", true) ||
StartsWithASCII(name, "Insert", true) ||
StartsWithASCII(name, "Delete", true))
return;
RenderThreadImpl::current()->RecordComputedAction(name);
}
bool RenderViewImpl::handleCurrentKeyboardEvent() {
if (edit_commands_.empty())
return false;
WebFrame* frame = webview()->focusedFrame();
if (!frame)
return false;
EditCommands::iterator it = edit_commands_.begin();
EditCommands::iterator end = edit_commands_.end();
bool did_execute_command = false;
for (; it != end; ++it) {
if (!frame->executeCommand(WebString::fromUTF8(it->name),
WebString::fromUTF8(it->value),
GetFocusedElement()))
break;
did_execute_command = true;
}
return did_execute_command;
}
blink::WebColorChooser* RenderViewImpl::createColorChooser(
blink::WebColorChooserClient* client,
const blink::WebColor& initial_color,
const blink::WebVector<blink::WebColorSuggestion>& suggestions) {
RendererWebColorChooserImpl* color_chooser =
new RendererWebColorChooserImpl(this, client);
std::vector<content::ColorSuggestion> color_suggestions;
for (size_t i = 0; i < suggestions.size(); i++) {
color_suggestions.push_back(content::ColorSuggestion(suggestions[i]));
}
color_chooser->Open(static_cast<SkColor>(initial_color), color_suggestions);
return color_chooser;
}
bool RenderViewImpl::runFileChooser(
const blink::WebFileChooserParams& params,
WebFileChooserCompletion* chooser_completion) {
if (is_hidden())
return false;
FileChooserParams ipc_params;
if (params.directory)
ipc_params.mode = FileChooserParams::UploadFolder;
else if (params.multiSelect)
ipc_params.mode = FileChooserParams::OpenMultiple;
else if (params.saveAs)
ipc_params.mode = FileChooserParams::Save;
else
ipc_params.mode = FileChooserParams::Open;
ipc_params.title = params.title;
ipc_params.default_file_name =
base::FilePath::FromUTF16Unsafe(params.initialValue);
ipc_params.accept_types.reserve(params.acceptTypes.size());
for (size_t i = 0; i < params.acceptTypes.size(); ++i)
ipc_params.accept_types.push_back(params.acceptTypes[i]);
#if defined(OS_ANDROID)
ipc_params.capture = params.useMediaCapture;
#endif
return ScheduleFileChooser(ipc_params, chooser_completion);
}
void RenderViewImpl::runModalAlertDialog(WebLocalFrame* frame,
const WebString& message) {
RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_ALERT,
message,
base::string16(),
frame->document().url(),
NULL);
}
bool RenderViewImpl::runModalConfirmDialog(WebLocalFrame* frame,
const WebString& message) {
return RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_CONFIRM,
message,
base::string16(),
frame->document().url(),
NULL);
}
bool RenderViewImpl::runModalPromptDialog(WebLocalFrame* frame,
const WebString& message,
const WebString& default_value,
WebString* actual_value) {
base::string16 result;
bool ok = RunJavaScriptMessage(JAVASCRIPT_MESSAGE_TYPE_PROMPT,
message,
default_value,
frame->document().url(),
&result);
if (ok)
actual_value->assign(result);
return ok;
}
bool RenderViewImpl::runModalBeforeUnloadDialog(WebLocalFrame* frame,
const WebString& message) {
bool is_reload = false;
WebDataSource* ds = frame->provisionalDataSource();
if (ds)
is_reload = (ds->navigationType() == blink::WebNavigationTypeReload);
return runModalBeforeUnloadDialog(frame, is_reload, message);
}
bool RenderViewImpl::runModalBeforeUnloadDialog(WebLocalFrame* frame,
bool is_reload,
const WebString& message) {
if (is_swapped_out_)
return true;
if (suppress_dialogs_until_swap_out_)
return false;
bool success = false;
base::string16 ignored_result;
SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
routing_id_, frame->document().url(), message, is_reload,
&success, &ignored_result));
return success;
}
void RenderViewImpl::showValidationMessage(
const blink::WebRect& anchor_in_root_view,
const blink::WebString& main_text,
const blink::WebString& sub_text,
blink::WebTextDirection hint) {
base::string16 wrapped_main_text = main_text;
base::string16 wrapped_sub_text = sub_text;
if (hint == blink::WebTextDirectionLeftToRight) {
wrapped_main_text =
base::i18n::GetDisplayStringInLTRDirectionality(wrapped_main_text);
if (!wrapped_sub_text.empty()) {
wrapped_sub_text =
base::i18n::GetDisplayStringInLTRDirectionality(wrapped_sub_text);
}
} else if (hint == blink::WebTextDirectionRightToLeft
&& !base::i18n::IsRTL()) {
base::i18n::WrapStringWithRTLFormatting(&wrapped_main_text);
if (!wrapped_sub_text.empty()) {
base::i18n::WrapStringWithRTLFormatting(&wrapped_sub_text);
}
}
Send(new ViewHostMsg_ShowValidationMessage(
routing_id(), anchor_in_root_view, wrapped_main_text, wrapped_sub_text));
}
void RenderViewImpl::hideValidationMessage() {
Send(new ViewHostMsg_HideValidationMessage(routing_id()));
}
void RenderViewImpl::moveValidationMessage(
const blink::WebRect& anchor_in_root_view) {
Send(new ViewHostMsg_MoveValidationMessage(routing_id(),
anchor_in_root_view));
}
void RenderViewImpl::setStatusText(const WebString& text) {
}
void RenderViewImpl::UpdateTargetURL(const GURL& url,
const GURL& fallback_url) {
GURL latest_url = url.is_empty() ? fallback_url : url;
if (latest_url == target_url_)
return;
if (target_url_status_ == TARGET_INFLIGHT ||
target_url_status_ == TARGET_PENDING) {
pending_target_url_ = latest_url;
target_url_status_ = TARGET_PENDING;
} else {
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;
target_url_status_ = TARGET_INFLIGHT;
}
}
gfx::RectF RenderViewImpl::ClientRectToPhysicalWindowRect(
const gfx::RectF& rect) const {
gfx::RectF window_rect = rect;
window_rect.Scale(device_scale_factor_ * webview()->pageScaleFactor());
return window_rect;
}
void RenderViewImpl::StartNavStateSyncTimerIfNecessary() {
if (page_id_ == -1)
return;
int delay;
if (send_content_state_immediately_)
delay = 0;
else if (is_hidden())
delay = kDelaySecondsForContentStateSyncHidden;
else
delay = kDelaySecondsForContentStateSync;
if (nav_state_sync_timer_.IsRunning()) {
if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
return;
nav_state_sync_timer_.Stop();
}
nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
&RenderViewImpl::SyncNavigationState);
}
void RenderViewImpl::setMouseOverURL(const WebURL& url) {
mouse_over_url_ = GURL(url);
UpdateTargetURL(mouse_over_url_, focus_url_);
}
void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) {
focus_url_ = GURL(url);
UpdateTargetURL(focus_url_, mouse_over_url_);
}
void RenderViewImpl::startDragging(WebLocalFrame* frame,
const WebDragData& data,
WebDragOperationsMask mask,
const WebImage& image,
const WebPoint& webImageOffset) {
DropData drop_data(DropDataBuilder::Build(data));
drop_data.referrer_policy = frame->document().referrerPolicy();
gfx::Vector2d imageOffset(webImageOffset.x, webImageOffset.y);
Send(new DragHostMsg_StartDragging(routing_id_,
drop_data,
mask,
image.getSkBitmap(),
imageOffset,
possible_drag_event_info_));
}
bool RenderViewImpl::acceptsLoadDrops() {
return renderer_preferences_.can_accept_load_drops;
}
void RenderViewImpl::focusNext() {
Send(new ViewHostMsg_TakeFocus(routing_id_, false));
}
void RenderViewImpl::focusPrevious() {
Send(new ViewHostMsg_TakeFocus(routing_id_, true));
}
void RenderViewImpl::focusedNodeChanged(const WebNode& node) {
has_scrolled_focused_editable_node_into_rect_ = false;
Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node));
}
void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) {
Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers));
}
void RenderViewImpl::didUpdateLayout() {
FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidUpdateLayout());
if (!send_preferred_size_changes_ || !webview())
return;
if (check_preferred_size_timer_.IsRunning())
return;
check_preferred_size_timer_.Start(FROM_HERE,
TimeDelta::FromMilliseconds(0), this,
&RenderViewImpl::CheckPreferredSize);
}
void RenderViewImpl::navigateBackForwardSoon(int offset) {
Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
}
int RenderViewImpl::historyBackListCount() {
return history_list_offset_ < 0 ? 0 : history_list_offset_;
}
int RenderViewImpl::historyForwardListCount() {
return history_list_length_ - historyBackListCount() - 1;
}
void RenderViewImpl::postAccessibilityEvent(
const WebAXObject& obj, blink::WebAXEvent event) {
if (renderer_accessibility_) {
renderer_accessibility_->HandleWebAccessibilityEvent(obj, event);
}
}
void RenderViewImpl::didUpdateInspectorSetting(const WebString& key,
const WebString& value) {
Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
key.utf8(),
value.utf8()));
}
void RenderViewImpl::didFocus() {
if (WebUserGestureIndicator::isProcessingUserGesture() &&
!RenderThreadImpl::current()->layout_test_mode()) {
Send(new ViewHostMsg_Focus(routing_id_));
}
}
void RenderViewImpl::didBlur() {
if (WebUserGestureIndicator::isProcessingUserGesture() &&
!RenderThreadImpl::current()->layout_test_mode()) {
Send(new ViewHostMsg_Blur(routing_id_));
}
}
void RenderViewImpl::show(WebNavigationPolicy policy) {
if (did_show_) {
if (webkit_preferences_.supports_multiple_windows)
NOTREACHED() << "received extraneous Show call";
return;
}
did_show_ = true;
DCHECK(opener_id_ != MSG_ROUTING_NONE);
if (!opened_by_user_gesture_) {
if (policy != blink::WebNavigationPolicyNewBackgroundTab)
policy = blink::WebNavigationPolicyNewPopup;
}
Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
NavigationPolicyToDisposition(policy), initial_pos_,
opened_by_user_gesture_));
SetPendingWindowRect(initial_pos_);
}
void RenderViewImpl::runModal() {
DCHECK(did_show_) << "should already have shown the view";
if (suppress_dialogs_until_swap_out_)
return;
if (RenderThreadImpl::current())
RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer();
SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(
routing_id_, opener_id_));
}
bool RenderViewImpl::enterFullScreen() {
Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true));
return true;
}
void RenderViewImpl::exitFullScreen() {
Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false));
}
bool RenderViewImpl::requestPointerLock() {
return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
}
void RenderViewImpl::requestPointerUnlock() {
mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
}
bool RenderViewImpl::isPointerLocked() {
return mouse_lock_dispatcher_->IsMouseLockedTo(
webwidget_mouse_lock_target_.get());
}
void RenderViewImpl::didActivateCompositor(int input_handler_identifier) {
#if !defined(OS_MACOSX)
InputHandlerManager* input_handler_manager =
RenderThreadImpl::current()->input_handler_manager();
if (input_handler_manager) {
input_handler_manager->AddInputHandler(
routing_id_,
compositor_->GetInputHandler(),
AsWeakPtr());
}
#endif
RenderWidget::didActivateCompositor(input_handler_identifier);
}
void RenderViewImpl::didActivateCompositor() {
#if !defined(OS_MACOSX)
InputHandlerManager* input_handler_manager =
RenderThreadImpl::current()->input_handler_manager();
if (input_handler_manager) {
input_handler_manager->AddInputHandler(
routing_id_,
compositor_->GetInputHandler(),
AsWeakPtr());
}
#endif
RenderWidget::didActivateCompositor();
}
void RenderViewImpl::didHandleGestureEvent(
const WebGestureEvent& event,
bool event_cancelled) {
RenderWidget::didHandleGestureEvent(event, event_cancelled);
if (event.type != blink::WebGestureEvent::GestureTap)
return;
blink::WebTextInputType text_input_type =
GetWebView()->textInputInfo().type;
Send(new ViewHostMsg_FocusedNodeTouched(
routing_id(), text_input_type != blink::WebTextInputTypeNone));
}
void RenderViewImpl::initializeLayerTreeView() {
RenderWidget::initializeLayerTreeView();
RenderWidgetCompositor* rwc = compositor();
if (!rwc || !webview() || !webview()->devToolsAgent())
return;
webview()->devToolsAgent()->setLayerTreeId(rwc->GetLayerTreeId());
}
WebMediaPlayer* RenderViewImpl::createMediaPlayer(
WebLocalFrame* frame,
const blink::WebURL& url,
WebMediaPlayerClient* client) {
NOTREACHED();
return NULL;
}
blink::WebMediaPlayer* RenderViewImpl::CreateMediaPlayer(
RenderFrame* render_frame,
blink::WebLocalFrame* frame,
const blink::WebURL& url,
blink::WebMediaPlayerClient* client) {
FOR_EACH_OBSERVER(
RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client));
WebMediaPlayer* player = CreateWebMediaPlayerForMediaStream(frame, url,
client);
if (player)
return player;
#if defined(OS_ANDROID)
return CreateAndroidWebMediaPlayer(frame, url, client);
#else
WebMediaPlayerParams params(
base::Bind(&ContentRendererClient::DeferMediaLoad,
base::Unretained(GetContentClient()->renderer()),
static_cast<RenderFrame*>(render_frame)),
RenderThreadImpl::current()->GetAudioRendererMixerManager()->CreateInput(
routing_id_, render_frame->GetRoutingID()));
return new WebMediaPlayerImpl(frame, client, AsWeakPtr(), params);
#endif
}
void RenderViewImpl::didAccessInitialDocument(WebLocalFrame* frame) {
if (!frame->parent() && page_id_ == -1)
Send(new ViewHostMsg_DidAccessInitialDocument(routing_id_));
}
void RenderViewImpl::didDisownOpener(blink::WebLocalFrame* frame) {
if (is_swapped_out_ || frame->parent())
return;
Send(new ViewHostMsg_DidDisownOpener(routing_id_));
}
void RenderViewImpl::frameDetached(WebFrame* frame) {
FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
}
void RenderViewImpl::willClose(WebFrame* frame) {
FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
}
void RenderViewImpl::didMatchCSS(
WebLocalFrame* frame,
const WebVector<WebString>& newly_matching_selectors,
const WebVector<WebString>& stopped_matching_selectors) {
FOR_EACH_OBSERVER(
RenderViewObserver, observers_,
DidMatchCSS(frame, newly_matching_selectors, stopped_matching_selectors));
}
void RenderViewImpl::Repaint(const gfx::Size& size) {
OnRepaint(size);
}
void RenderViewImpl::SetEditCommandForNextKeyEvent(const std::string& name,
const std::string& value) {
EditCommands edit_commands;
edit_commands.push_back(EditCommand(name, value));
OnSetEditCommandsForNextKeyEvent(edit_commands);
}
void RenderViewImpl::ClearEditCommands() {
edit_commands_.clear();
}
SSLStatus RenderViewImpl::GetSSLStatusOfFrame(blink::WebFrame* frame) const {
std::string security_info;
if (frame && frame->dataSource())
security_info = frame->dataSource()->response().securityInfo();
SSLStatus ssl_status;
DeserializeSecurityInfo(security_info,
&ssl_status.cert_id,
&ssl_status.cert_status,
&ssl_status.security_bits,
&ssl_status.connection_status,
&ssl_status.signed_certificate_timestamp_ids);
return ssl_status;
}
const std::string& RenderViewImpl::GetAcceptLanguages() const {
return renderer_preferences_.accept_languages;
}
void RenderViewImpl::willSendSubmitEvent(blink::WebLocalFrame* frame,
const blink::WebFormElement& form) {
FOR_EACH_OBSERVER(
RenderViewObserver, observers_, WillSendSubmitEvent(frame, form));
}
void RenderViewImpl::willSubmitForm(WebLocalFrame* frame,
const WebFormElement& form) {
FOR_EACH_OBSERVER(
RenderViewObserver, observers_, WillSubmitForm(frame, form));
}
void RenderViewImpl::didCreateDataSource(WebLocalFrame* frame,
WebDataSource* ds) {
bool content_initiated = !pending_navigation_params_.get();
if (pending_navigation_params_.get()) {
for (std::vector<GURL>::const_iterator i =
pending_navigation_params_->redirects.begin();
i != pending_navigation_params_->redirects.end(); ++i) {
ds->appendRedirect(*i);
}
}
DocumentState* document_state = DocumentState::FromDataSource(ds);
if (!document_state) {
document_state = new DocumentState;
ds->setExtraData(document_state);
if (!content_initiated)
PopulateDocumentStateFromPending(document_state);
}
if (content_initiated && webview() && webview()->mainFrame() &&
webview()->mainFrame()->dataSource()) {
DocumentState* old_document_state =
DocumentState::FromDataSource(webview()->mainFrame()->dataSource());
if (old_document_state) {
InternalDocumentStateData* internal_data =
InternalDocumentStateData::FromDocumentState(document_state);
InternalDocumentStateData* old_internal_data =
InternalDocumentStateData::FromDocumentState(old_document_state);
internal_data->set_is_overriding_user_agent(
old_internal_data->is_overriding_user_agent());
}
}
if (content_initiated) {
document_state->set_navigation_state(
NavigationState::CreateContentInitiated());
} else {
document_state->set_navigation_state(CreateNavigationStateFromPending());
pending_navigation_params_.reset();
}
if (webview()) {
if (WebFrame* old_frame = webview()->mainFrame()) {
const WebURLRequest& original_request = ds->originalRequest();
const GURL referrer(
original_request.httpHeaderField(WebString::fromUTF8("Referer")));
if (!referrer.is_empty() &&
DocumentState::FromDataSource(
old_frame->dataSource())->was_prefetcher()) {
for (; old_frame; old_frame = old_frame->traverseNext(false)) {
WebDataSource* old_frame_ds = old_frame->dataSource();
if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
document_state->set_was_referred_by_prefetcher(true);
break;
}
}
}
}
}
if (content_initiated) {
const WebURLRequest& request = ds->request();
switch (request.cachePolicy()) {
case WebURLRequest::UseProtocolCachePolicy:
document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL);
break;
case WebURLRequest::ReloadIgnoringCacheData:
document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD);
break;
case WebURLRequest::ReturnCacheDataElseLoad:
document_state->set_load_type(
DocumentState::LINK_LOAD_CACHE_STALE_OK);
break;
case WebURLRequest::ReturnCacheDataDontLoad:
document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY);
break;
}
}
FOR_EACH_OBSERVER(
RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
}
void RenderViewImpl::PopulateDocumentStateFromPending(
DocumentState* document_state) {
const FrameMsg_Navigate_Params& params = *pending_navigation_params_.get();
document_state->set_request_time(params.request_time);
InternalDocumentStateData* internal_data =
InternalDocumentStateData::FromDocumentState(document_state);
if (!params.url.SchemeIs(kJavaScriptScheme) &&
params.navigation_type == FrameMsg_Navigate_Type::RESTORE) {
internal_data->set_cache_policy_override(
WebURLRequest::UseProtocolCachePolicy);
}
if (IsReload(params))
document_state->set_load_type(DocumentState::RELOAD);
else if (params.page_state.IsValid())
document_state->set_load_type(DocumentState::HISTORY_LOAD);
else
document_state->set_load_type(DocumentState::NORMAL_LOAD);
internal_data->set_is_overriding_user_agent(params.is_overriding_user_agent);
internal_data->set_must_reset_scroll_and_scale_state(
params.navigation_type ==
FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL);
document_state->set_can_load_local_resources(params.can_load_local_resources);
}
NavigationState* RenderViewImpl::CreateNavigationStateFromPending() {
const FrameMsg_Navigate_Params& params = *pending_navigation_params_.get();
NavigationState* navigation_state = NULL;
if (!params.url.SchemeIs(kJavaScriptScheme)) {
navigation_state = NavigationState::CreateBrowserInitiated(
params.page_id,
params.pending_history_list_offset,
params.should_clear_history_list,
params.transition);
navigation_state->set_should_replace_current_entry(
params.should_replace_current_entry);
navigation_state->set_transferred_request_child_id(
params.transferred_request_child_id);
navigation_state->set_transferred_request_request_id(
params.transferred_request_request_id);
navigation_state->set_allow_download(params.allow_download);
navigation_state->set_extra_headers(params.extra_headers);
} else {
navigation_state = NavigationState::CreateContentInitiated();
}
return navigation_state;
}
void RenderViewImpl::ProcessViewLayoutFlags(const CommandLine& command_line) {
bool enable_viewport =
command_line.HasSwitch(switches::kEnableViewport) ||
command_line.HasSwitch(switches::kEnableViewportMeta);
if (enable_viewport)
return;
webview()->setInitialPageScaleOverride(1.f);
float maxPageScaleFactor =
command_line.HasSwitch(switches::kEnablePinch) ? 4.f : 1.f ;
webview()->setPageScaleFactorLimits(1, maxPageScaleFactor);
}
void RenderViewImpl::didStartProvisionalLoad(WebLocalFrame* frame) {}
void RenderViewImpl::didFailProvisionalLoad(WebLocalFrame* frame,
const WebURLError& error) {
FOR_EACH_OBSERVER(
RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
}
void RenderViewImpl::FrameDidCommitProvisionalLoad(WebFrame* frame,
bool is_new_navigation) {
FOR_EACH_OBSERVER(RenderViewObserver, observers_,
DidCommitProvisionalLoad(frame, is_new_navigation));
if (!frame->parent()) {
RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
if (render_thread_impl) {
render_thread_impl->histogram_customizer()->
RenderViewNavigatedToHost(GURL(GetLoadingUrl(frame)).host(),
g_view_map.Get().size());
}
}
}
void RenderViewImpl::didClearWindowObject(WebLocalFrame* frame, int world_id) {
FOR_EACH_OBSERVER(RenderViewObserver, observers_,
DidClearWindowObject(frame, world_id));
if (world_id)
return;
if (enabled_bindings_& BINDINGS_POLICY_WEB_UI)
WebUIExtension::Install(frame);
if (enabled_bindings_ & BINDINGS_POLICY_STATS_COLLECTION)
StatsCollectionController::Install(frame);
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kEnableSkiaBenchmarking))
SkiaBenchmarking::Install(frame);
if (command_line.HasSwitch(switches::kEnableMemoryBenchmarking))
MemoryBenchmarkingExtension::Install(frame);
}
void RenderViewImpl::didCreateDocumentElement(WebLocalFrame* frame) {
FOR_EACH_OBSERVER(RenderViewObserver, observers_,
DidCreateDocumentElement(frame));
}
void RenderViewImpl::didReceiveTitle(WebLocalFrame* frame,
const WebString& title,
WebTextDirection direction) {
UpdateTitle(frame, title, direction);
UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
}
void RenderViewImpl::didChangeIcon(WebLocalFrame* frame,
WebIconURL::Type icon_type) {
if (frame->parent())
return;
if (!TouchEnabled() && icon_type != WebIconURL::TypeFavicon)
return;
WebVector<WebIconURL> icon_urls = frame->iconURLs(icon_type);
std::vector<FaviconURL> urls;
for (size_t i = 0; i < icon_urls.size(); i++) {
std::vector<gfx::Size> sizes(icon_urls[i].sizes().size());
ConvertToFaviconSizes(icon_urls[i].sizes(), &sizes);
urls.push_back(FaviconURL(
icon_urls[i].iconURL(), ToFaviconType(icon_urls[i].iconType()), sizes));
}
SendUpdateFaviconURL(urls);
}
void RenderViewImpl::didFinishDocumentLoad(WebLocalFrame* frame) {
FOR_EACH_OBSERVER(RenderViewObserver, observers_,
DidFinishDocumentLoad(frame));
}
void RenderViewImpl::didHandleOnloadEvents(WebLocalFrame* frame) {
if (webview()->mainFrame() == frame) {
Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
page_id_));
}
}
void RenderViewImpl::didFailLoad(WebLocalFrame* frame,
const WebURLError& error) {
FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
}
void RenderViewImpl::didFinishLoad(WebLocalFrame* frame) {
FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
}
void RenderViewImpl::didUpdateCurrentHistoryItem(WebLocalFrame* frame) {
StartNavStateSyncTimerIfNecessary();
}
void RenderViewImpl::willSendRequest(WebLocalFrame* frame,
unsigned identifier,
WebURLRequest& request,
const WebURLResponse& redirect_response) {
NOTREACHED();
}
void RenderViewImpl::didReceiveResponse(WebLocalFrame* frame,
unsigned identifier,
const WebURLResponse& response) {
NOTREACHED();
}
void RenderViewImpl::didFinishResourceLoad(WebLocalFrame* frame,
unsigned identifier) {
InternalDocumentStateData* internal_data =
InternalDocumentStateData::FromDataSource(frame->dataSource());
if (!internal_data->use_error_page())
return;
if (devtools_agent_->IsAttached())
return;
std::string error_domain = "http";
int http_status_code = internal_data->http_status_code();
if (GetContentClient()->renderer()->HasErrorPage(
http_status_code, &error_domain)) {
WebURLError error;
error.unreachableURL = frame->document().url();
error.domain = WebString::fromUTF8(error_domain);
error.reason = http_status_code;
LoadNavigationErrorPage(frame, frame->dataSource()->request(), error, true);
}
}
void RenderViewImpl::didLoadResourceFromMemoryCache(
WebLocalFrame* frame,
const WebURLRequest& request,
const WebURLResponse& response) {
NOTREACHED();
}
void RenderViewImpl::didDisplayInsecureContent(WebLocalFrame* frame) {
NOTREACHED();
}
void RenderViewImpl::didRunInsecureContent(WebLocalFrame* frame,
const WebSecurityOrigin& origin,
const WebURL& target) {
NOTREACHED();
}
void RenderViewImpl::didCreateScriptContext(WebLocalFrame* frame,
v8::Handle<v8::Context> context,
int extension_group,
int world_id) {
NOTREACHED();
}
void RenderViewImpl::willReleaseScriptContext(WebLocalFrame* frame,
v8::Handle<v8::Context> context,
int world_id) {
NOTREACHED();
}
void RenderViewImpl::CheckPreferredSize() {
if (!send_preferred_size_changes_ || !webview())
return;
gfx::Size size = webview()->contentsPreferredMinimumSize();
double zoom_factor = ZoomLevelToZoomFactor(webview()->zoomLevel());
size.set_width(static_cast<int>(size.width() * zoom_factor));
size.set_height(static_cast<int>(size.height() * zoom_factor));
if (size == preferred_size_)
return;
preferred_size_ = size;
Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
preferred_size_));
}
BrowserPluginManager* RenderViewImpl::GetBrowserPluginManager() {
if (!browser_plugin_manager_.get())
browser_plugin_manager_ = BrowserPluginManager::Create(this);
return browser_plugin_manager_.get();
}
bool RenderViewImpl::InitializeMediaStreamClient() {
if (media_stream_client_)
return true;
if (!RenderThreadImpl::current())
return false;
#if defined(OS_ANDROID)
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableWebRTC))
return false;
#endif
#if defined(ENABLE_WEBRTC)
if (!media_stream_dispatcher_)
media_stream_dispatcher_ = new MediaStreamDispatcher(this);
MediaStreamImpl* media_stream_impl = new MediaStreamImpl(
this,
media_stream_dispatcher_,
RenderThreadImpl::current()->GetMediaStreamDependencyFactory());
media_stream_client_ = media_stream_impl;
web_user_media_client_ = media_stream_impl;
return true;
#else
return false;
#endif
}
void RenderViewImpl::didChangeContentsSize(WebLocalFrame* frame,
const WebSize& size) {
if (webview()->mainFrame() != frame)
return;
WebView* frameView = frame->view();
if (!frameView)
return;
bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar();
bool has_vertical_scrollbar = frame->hasVerticalScrollbar();
if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ ||
has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) {
Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame(
routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar));
cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar;
cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar;
}
}
void RenderViewImpl::UpdateScrollState(WebFrame* frame) {
WebSize offset = frame->scrollOffset();
WebSize minimum_offset = frame->minimumScrollOffset();
WebSize maximum_offset = frame->maximumScrollOffset();
bool is_pinned_to_left = offset.width <= minimum_offset.width;
bool is_pinned_to_right = offset.width >= maximum_offset.width;
if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ ||
is_pinned_to_right != cached_is_main_frame_pinned_to_right_) {
Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame(
routing_id_, is_pinned_to_left, is_pinned_to_right));
cached_is_main_frame_pinned_to_left_ = is_pinned_to_left;
cached_is_main_frame_pinned_to_right_ = is_pinned_to_right;
}
Send(new ViewHostMsg_DidChangeScrollOffset(routing_id_));
}
void RenderViewImpl::didChangeScrollOffset(WebLocalFrame* frame) {
StartNavStateSyncTimerIfNecessary();
if (webview()->mainFrame() == frame)
UpdateScrollState(frame);
FOR_EACH_OBSERVER(
RenderViewObserver, observers_, DidChangeScrollOffset(frame));
}
void RenderViewImpl::willInsertBody(blink::WebLocalFrame* frame) {
NOTREACHED();
}
void RenderViewImpl::didFirstVisuallyNonEmptyLayout(WebLocalFrame* frame) {
if (frame != webview()->mainFrame())
return;
InternalDocumentStateData* data =
InternalDocumentStateData::FromDataSource(frame->dataSource());
data->set_did_first_visually_non_empty_layout(true);
#if defined(OS_ANDROID)
SkColor bg_color = webwidget_->backgroundColor();
if (!bg_color)
bg_color = SK_ColorWHITE;
if (bg_color != body_background_color_) {
body_background_color_ = bg_color;
Send(new ViewHostMsg_DidChangeBodyBackgroundColor(
GetRoutingID(), bg_color));
}
#endif
}
void RenderViewImpl::SendFindReply(int request_id,
int match_count,
int ordinal,
const WebRect& selection_rect,
bool final_status_update) {
Send(new ViewHostMsg_Find_Reply(routing_id_,
request_id,
match_count,
selection_rect,
ordinal,
final_status_update));
}
void RenderViewImpl::reportFindInPageMatchCount(int request_id,
int count,
bool final_update) {
NOTREACHED();
}
void RenderViewImpl::reportFindInPageSelection(int request_id,
int active_match_ordinal,
const WebRect& selection_rect) {
NOTREACHED();
}
void RenderViewImpl::requestStorageQuota(
WebLocalFrame* frame,
WebStorageQuotaType type,
unsigned long long requested_size,
blink::WebStorageQuotaCallbacks callbacks) {
NOTREACHED();
}
bool RenderViewImpl::willCheckAndDispatchMessageEvent(
blink::WebLocalFrame* sourceFrame,
blink::WebFrame* targetFrame,
blink::WebSecurityOrigin target_origin,
blink::WebDOMMessageEvent event) {
if (!is_swapped_out_)
return false;
ViewMsg_PostMessage_Params params;
params.data = event.data().toString();
params.source_origin = event.origin();
if (!target_origin.isNull())
params.target_origin = target_origin.toString();
blink::WebMessagePortChannelArray channels = event.releaseChannels();
if (!channels.isEmpty()) {
std::vector<int> message_port_ids(channels.size());
for (size_t i = 0; i < channels.size(); ++i) {
WebMessagePortChannelImpl* webchannel =
static_cast<WebMessagePortChannelImpl*>(channels[i]);
message_port_ids[i] = webchannel->message_port_id();
webchannel->QueueMessages();
DCHECK_NE(message_port_ids[i], MSG_ROUTING_NONE);
}
params.message_port_ids = message_port_ids;
}
params.source_routing_id = MSG_ROUTING_NONE;
if (sourceFrame) {
RenderViewImpl* source_view = FromWebView(sourceFrame->view());
if (source_view)
params.source_routing_id = source_view->routing_id();
}
Send(new ViewHostMsg_RouteMessageEvent(routing_id_, params));
return true;
}
void RenderViewImpl::willOpenSocketStream(
WebSocketStreamHandle* handle) {
NOTREACHED();
}
void RenderViewImpl::willStartUsingPeerConnectionHandler(
blink::WebLocalFrame* frame,
blink::WebRTCPeerConnectionHandler* handler) {
NOTREACHED();
}
blink::WebString RenderViewImpl::acceptLanguages() {
return WebString::fromUTF8(renderer_preferences_.accept_languages);
}
blink::WebString RenderViewImpl::userAgentOverride(blink::WebLocalFrame* frame,
const blink::WebURL& url) {
NOTREACHED();
return blink::WebString();
}
WebString RenderViewImpl::doNotTrackValue(WebLocalFrame* frame) {
NOTREACHED();
return blink::WebString();
}
bool RenderViewImpl::allowWebGL(WebLocalFrame* frame, bool default_value) {
NOTREACHED();
return false;
}
void RenderViewImpl::didLoseWebGLContext(blink::WebLocalFrame* frame,
int arb_robustness_status_code) {
NOTREACHED();
}
void RenderViewImpl::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)));
}
bool RenderViewImpl::Send(IPC::Message* message) {
return RenderWidget::Send(message);
}
RenderFrame* RenderViewImpl::GetMainRenderFrame() {
return main_render_frame_.get();
}
int RenderViewImpl::GetRoutingID() const {
return routing_id_;
}
int RenderViewImpl::GetPageId() const {
return page_id_;
}
gfx::Size RenderViewImpl::GetSize() const {
return size();
}
WebPreferences& RenderViewImpl::GetWebkitPreferences() {
return webkit_preferences_;
}
void RenderViewImpl::SetWebkitPreferences(const WebPreferences& preferences) {
OnUpdateWebPreferences(preferences);
}
blink::WebView* RenderViewImpl::GetWebView() {
return webview();
}
blink::WebElement RenderViewImpl::GetFocusedElement() const {
if (!webview())
return WebElement();
WebFrame* focused_frame = webview()->focusedFrame();
if (focused_frame) {
WebDocument doc = focused_frame->document();
if (!doc.isNull())
return doc.focusedElement();
}
return WebElement();
}
bool RenderViewImpl::IsEditableNode(const WebNode& node) const {
if (node.isNull())
return false;
if (node.isContentEditable())
return true;
if (node.isElementNode()) {
const WebElement& element = node.toConst<WebElement>();
if (element.isTextFormControlElement())
return true;
for (unsigned i = 0; i < element.attributeCount(); ++i) {
if (LowerCaseEqualsASCII(element.attributeLocalName(i), "role")) {
if (LowerCaseEqualsASCII(element.attributeValue(i), "textbox"))
return true;
break;
}
}
}
return false;
}
bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
return (!send_preferred_size_changes_ ||
(disable_scrollbars_size_limit_.width() <= width ||
disable_scrollbars_size_limit_.height() <= height));
}
int RenderViewImpl::GetEnabledBindings() const {
return enabled_bindings_;
}
bool RenderViewImpl::GetContentStateImmediately() const {
return send_content_state_immediately_;
}
float RenderViewImpl::GetFilteredTimePerFrame() const {
return filtered_time_per_frame();
}
blink::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const {
return visibilityState();
}
void RenderViewImpl::RunModalAlertDialog(blink::WebLocalFrame* frame,
const blink::WebString& message) {
return runModalAlertDialog(frame, message);
}
void RenderViewImpl::DidStartLoading() {
main_render_frame_->didStartLoading(true);
}
void RenderViewImpl::DidStopLoading() {
main_render_frame_->didStopLoading();
}
void RenderViewImpl::DidPlay(blink::WebMediaPlayer* player) {
Send(new ViewHostMsg_MediaPlayingNotification(routing_id_,
reinterpret_cast<int64>(player),
player->hasVideo(),
player->hasAudio()));
}
void RenderViewImpl::DidPause(blink::WebMediaPlayer* player) {
Send(new ViewHostMsg_MediaPausedNotification(
routing_id_, reinterpret_cast<int64>(player)));
}
void RenderViewImpl::PlayerGone(blink::WebMediaPlayer* player) {
DidPause(player);
}
void RenderViewImpl::SyncNavigationState() {
if (!webview())
return;
const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
SendUpdateState(item);
}
GURL RenderViewImpl::GetLoadingUrl(blink::WebFrame* frame) const {
WebDataSource* ds = frame->dataSource();
if (ds->hasUnreachableURL())
return ds->unreachableURL();
const WebURLRequest& request = ds->request();
return request.url();
}
blink::WebPlugin* RenderViewImpl::GetWebPluginForFind() {
if (!webview())
return NULL;
WebFrame* main_frame = webview()->mainFrame();
if (main_frame->document().isPluginDocument())
return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
#if defined(ENABLE_PLUGINS)
if (plugin_find_handler_)
return plugin_find_handler_->container()->plugin();
#endif
return NULL;
}
void RenderViewImpl::OnFind(int request_id,
const base::string16& search_text,
const WebFindOptions& options) {
WebFrame* main_frame = webview()->mainFrame();
blink::WebPlugin* plugin = GetWebPluginForFind();
if (plugin) {
if (options.findNext) {
plugin->selectFindResult(options.forward);
} else {
if (!plugin->startFind(
search_text, options.matchCase, request_id)) {
SendFindReply(request_id, 0, 0, gfx::Rect(), true);
}
}
return;
}
WebFrame* frame_after_main = main_frame->traverseNext(true);
WebFrame* focused_frame = webview()->focusedFrame();
WebFrame* search_frame = focused_frame;
bool multi_frame = (frame_after_main != main_frame);
bool wrap_within_frame = !multi_frame;
WebRect selection_rect;
bool result = false;
WebRange current_selection = focused_frame->selectionRange();
do {
result = search_frame->find(
request_id, search_text, options, wrap_within_frame, &selection_rect);
if (!result) {
search_frame->executeCommand(WebString::fromUTF8("Unselect"),
GetFocusedElement());
do {
search_frame = options.forward ?
search_frame->traverseNext(true) :
search_frame->traversePrevious(true);
} while (!search_frame->hasVisibleContent() &&
search_frame != focused_frame);
search_frame->executeCommand(WebString::fromUTF8("Unselect"),
GetFocusedElement());
if (multi_frame && search_frame == focused_frame) {
result = search_frame->find(
request_id, search_text, options, true,
&selection_rect);
}
}
webview()->setFocusedFrame(search_frame);
} while (!result && search_frame != focused_frame);
if (options.findNext && current_selection.isNull()) {
main_frame->increaseMatchCount(0, request_id);
} else {
int ordinal = result ? -1 : 0;
int match_count = result ? 1 : 0;
bool final_status_update = !result;
SendFindReply(request_id, match_count, ordinal, selection_rect,
final_status_update);
search_frame = main_frame;
main_frame->resetMatchCount();
do {
search_frame->cancelPendingScopingEffort();
if (result) {
search_frame->scopeStringMatches(request_id,
search_text,
options,
true);
}
search_frame = search_frame->traverseNext(true);
} while (search_frame != main_frame);
}
}
void RenderViewImpl::OnStopFinding(StopFindAction action) {
WebView* view = webview();
if (!view)
return;
blink::WebPlugin* plugin = GetWebPluginForFind();
if (plugin) {
plugin->stopFind();
return;
}
bool clear_selection = action == STOP_FIND_ACTION_CLEAR_SELECTION;
if (clear_selection) {
view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"),
GetFocusedElement());
}
WebFrame* frame = view->mainFrame();
while (frame) {
frame->stopFinding(clear_selection);
frame = frame->traverseNext(false);
}
if (action == STOP_FIND_ACTION_ACTIVATE_SELECTION) {
WebFrame* focused_frame = view->focusedFrame();
if (focused_frame) {
WebDocument doc = focused_frame->document();
if (!doc.isNull()) {
WebElement element = doc.focusedElement();
if (!element.isNull())
element.simulateClick();
}
}
}
}
#if defined(OS_ANDROID)
void RenderViewImpl::OnActivateNearestFindResult(int request_id,
float x, float y) {
if (!webview())
return;
WebFrame* main_frame = webview()->mainFrame();
WebRect selection_rect;
int ordinal = main_frame->selectNearestFindMatch(WebFloatPoint(x, y),
&selection_rect);
if (ordinal == -1) {
main_frame->increaseMatchCount(0, request_id);
return;
}
SendFindReply(request_id,
-1 ,
ordinal,
selection_rect,
true );
}
void RenderViewImpl::OnFindMatchRects(int current_version) {
if (!webview())
return;
WebFrame* main_frame = webview()->mainFrame();
std::vector<gfx::RectF> match_rects;
int rects_version = main_frame->findMatchMarkersVersion();
if (current_version != rects_version) {
WebVector<WebFloatRect> web_match_rects;
main_frame->findMatchRects(web_match_rects);
match_rects.reserve(web_match_rects.size());
for (size_t i = 0; i < web_match_rects.size(); ++i)
match_rects.push_back(gfx::RectF(web_match_rects[i]));
}
gfx::RectF active_rect = main_frame->activeFindMatchRect();
Send(new ViewHostMsg_FindMatchRects_Reply(routing_id_,
rects_version,
match_rects,
active_rect));
}
#endif
void RenderViewImpl::OnZoom(PageZoom zoom) {
if (!webview())
return;
webview()->hidePopups();
double old_zoom_level = webview()->zoomLevel();
double zoom_level;
if (zoom == PAGE_ZOOM_RESET) {
zoom_level = 0;
} else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
zoom_level = old_zoom_level + zoom;
} else {
if ((old_zoom_level > 1 && zoom > 0) ||
(old_zoom_level < 1 && zoom < 0)) {
zoom_level = static_cast<int>(old_zoom_level + zoom);
} else {
zoom_level = static_cast<int>(old_zoom_level);
}
}
webview()->setZoomLevel(zoom_level);
zoomLevelChanged();
}
void RenderViewImpl::OnSetZoomLevel(double zoom_level) {
webview()->hidePopups();
webview()->setZoomLevel(zoom_level);
zoomLevelChanged();
}
void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url,
double zoom_level) {
#if !defined(OS_ANDROID)
host_zoom_levels_[url] = zoom_level;
#endif
}
void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) {
webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
}
void RenderViewImpl::OnResetPageEncodingToDefault() {
WebString no_encoding;
webview()->setPageEncoding(no_encoding);
}
void RenderViewImpl::OnPostMessageEvent(
const ViewMsg_PostMessage_Params& params) {
WebFrame* frame = webview()->mainFrame();
WebFrame* source_frame = NULL;
if (params.source_routing_id != MSG_ROUTING_NONE) {
RenderViewImpl* source_view = FromRoutingID(params.source_routing_id);
if (source_view)
source_frame = source_view->webview()->mainFrame();
}
DCHECK_EQ(params.message_port_ids.size(), params.new_routing_ids.size());
blink::WebMessagePortChannelArray channels(params.message_port_ids.size());
for (size_t i = 0;
i < params.message_port_ids.size() && i < params.new_routing_ids.size();
++i) {
channels[i] =
new WebMessagePortChannelImpl(params.new_routing_ids[i],
params.message_port_ids[i],
base::MessageLoopProxy::current().get());
}
WebDOMEvent event = frame->document().createEvent("MessageEvent");
WebDOMMessageEvent msg_event = event.to<WebDOMMessageEvent>();
msg_event.initMessageEvent("message",
false, false,
WebSerializedScriptValue::fromString(params.data),
params.source_origin, source_frame, "", channels);
WebSecurityOrigin target_origin;
if (!params.target_origin.empty()) {
target_origin =
WebSecurityOrigin::createFromString(WebString(params.target_origin));
}
frame->dispatchMessageEventWithOriginCheck(target_origin, msg_event);
}
void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) {
if ((enabled_bindings_flags & BINDINGS_POLICY_WEB_UI) &&
!(enabled_bindings_ & BINDINGS_POLICY_WEB_UI)) {
new WebUIExtensionData(this);
#if defined(USE_MOJO)
new WebUIMojo(this);
#endif
}
enabled_bindings_ |= enabled_bindings_flags;
RenderProcess::current()->AddBindings(enabled_bindings_flags);
}
void RenderViewImpl::OnDragTargetDragEnter(const DropData& drop_data,
const gfx::Point& client_point,
const gfx::Point& screen_point,
WebDragOperationsMask ops,
int key_modifiers) {
WebDragOperation operation = webview()->dragTargetDragEnter(
DropDataToWebDragData(drop_data),
client_point,
screen_point,
ops,
key_modifiers);
Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
}
void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point,
const gfx::Point& screen_point,
WebDragOperationsMask ops,
int key_modifiers) {
WebDragOperation operation = webview()->dragTargetDragOver(
client_point,
screen_point,
ops,
key_modifiers);
Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
}
void RenderViewImpl::OnDragTargetDragLeave() {
webview()->dragTargetDragLeave();
}
void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point,
const gfx::Point& screen_point,
int key_modifiers) {
webview()->dragTargetDrop(client_point, screen_point, key_modifiers);
Send(new DragHostMsg_TargetDrop_ACK(routing_id_));
}
void RenderViewImpl::OnDragSourceEnded(const gfx::Point& client_point,
const gfx::Point& screen_point,
WebDragOperation op) {
webview()->dragSourceEndedAt(client_point, screen_point, op);
}
void RenderViewImpl::OnDragSourceSystemDragEnded() {
webview()->dragSourceSystemDragEnded();
}
void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
webkit_preferences_ = prefs;
ApplyWebPreferences(webkit_preferences_, webview());
}
void RenderViewImpl::OnEnumerateDirectoryResponse(
int id,
const std::vector<base::FilePath>& paths) {
if (!enumeration_completions_[id])
return;
WebVector<WebString> ws_file_names(paths.size());
for (size_t i = 0; i < paths.size(); ++i)
ws_file_names[i] = paths[i].AsUTF16Unsafe();
enumeration_completions_[id]->didChooseFile(ws_file_names);
enumeration_completions_.erase(id);
}
void RenderViewImpl::OnFileChooserResponse(
const std::vector<ui::SelectedFileInfo>& files) {
if (file_chooser_completions_.empty())
return;
WebVector<WebFileChooserCompletion::SelectedFileInfo> selected_files(
files.size());
for (size_t i = 0; i < files.size(); ++i) {
WebFileChooserCompletion::SelectedFileInfo selected_file;
selected_file.path = files[i].local_path.AsUTF16Unsafe();
selected_file.displayName =
base::FilePath(files[i].display_name).AsUTF16Unsafe();
selected_files[i] = selected_file;
}
if (file_chooser_completions_.front()->completion)
file_chooser_completions_.front()->completion->didChooseFile(
selected_files);
file_chooser_completions_.pop_front();
if (!file_chooser_completions_.empty()) {
Send(new ViewHostMsg_RunFileChooser(routing_id_,
file_chooser_completions_.front()->params));
}
}
void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size,
const gfx::Size& max_size) {
DCHECK(disable_scrollbars_size_limit_.IsEmpty());
if (!webview())
return;
auto_resize_mode_ = true;
webview()->enableAutoResizeMode(min_size, max_size);
}
void RenderViewImpl::OnDisableAutoResize(const gfx::Size& new_size) {
DCHECK(disable_scrollbars_size_limit_.IsEmpty());
if (!webview())
return;
auto_resize_mode_ = false;
webview()->disableAutoResizeMode();
if (!new_size.IsEmpty()) {
Resize(new_size,
physical_backing_size_,
overdraw_bottom_height_,
resizer_rect_,
is_fullscreen_,
NO_RESIZE_ACK);
}
}
void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
if (send_preferred_size_changes_)
return;
send_preferred_size_changes_ = true;
didUpdateLayout();
}
void RenderViewImpl::OnDisableScrollbarsForSmallWindows(
const gfx::Size& disable_scrollbar_size_limit) {
disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
}
void RenderViewImpl::OnSetRendererPrefs(
const RendererPreferences& renderer_prefs) {
double old_zoom_level = renderer_preferences_.default_zoom_level;
renderer_preferences_ = renderer_prefs;
UpdateFontRenderingFromRendererPrefs();
#if defined(USE_DEFAULT_RENDER_THEME) || defined(TOOLKIT_GTK)
if (renderer_prefs.use_custom_colors) {
WebColorName name = blink::WebColorWebkitFocusRingColor;
blink::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
blink::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
#if defined(TOOLKIT_GTK)
ui::NativeTheme::instance()->SetScrollbarColors(
renderer_prefs.thumb_inactive_color,
renderer_prefs.thumb_active_color,
renderer_prefs.track_color);
#endif
if (webview()) {
webview()->setSelectionColors(
renderer_prefs.active_selection_bg_color,
renderer_prefs.active_selection_fg_color,
renderer_prefs.inactive_selection_bg_color,
renderer_prefs.inactive_selection_fg_color);
webview()->themeChanged();
}
}
#endif
if (RenderThreadImpl::current())
RenderThreadImpl::current()->SetFlingCurveParameters(
renderer_prefs.touchpad_fling_profile,
renderer_prefs.touchscreen_fling_profile);
if (webview() && !webview()->mainFrame()->document().isPluginDocument() &&
!ZoomValuesEqual(old_zoom_level,
renderer_preferences_.default_zoom_level) &&
ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level)) {
webview()->setZoomLevel(renderer_preferences_.default_zoom_level);
zoomLevelChanged();
}
}
void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location,
const WebMediaPlayerAction& action) {
if (webview())
webview()->performMediaPlayerAction(action, location);
}
void RenderViewImpl::OnOrientationChangeEvent(int orientation) {
FOR_EACH_OBSERVER(RenderViewObserver,
observers_,
OrientationChangeEvent(orientation));
webview()->mainFrame()->sendOrientationChangeEvent(orientation);
}
void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
const WebPluginAction& action) {
if (webview())
webview()->performPluginAction(action, location);
}
void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage(
const GURL& page_url) {
std::vector<GURL> resources_list;
std::vector<GURL> referrer_urls_list;
std::vector<blink::WebReferrerPolicy> referrer_policies_list;
std::vector<GURL> frames_list;
SavableResourcesResult result(&resources_list,
&referrer_urls_list,
&referrer_policies_list,
&frames_list);
if (!GetAllSavableResourceLinksForCurrentPage(
webview(),
page_url,
&result,
const_cast<const char**>(GetSavableSchemes()))) {
referrer_urls_list.clear();
referrer_policies_list.clear();
resources_list.clear();
frames_list.clear();
}
std::vector<Referrer> referrers_list;
CHECK_EQ(referrer_urls_list.size(), referrer_policies_list.size());
for (unsigned i = 0; i < referrer_urls_list.size(); ++i) {
referrers_list.push_back(
Referrer(referrer_urls_list[i], referrer_policies_list[i]));
}
Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(),
resources_list,
referrers_list,
frames_list));
}
void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
const std::vector<GURL>& links,
const std::vector<base::FilePath>& local_paths,
const base::FilePath& local_directory_name) {
WebVector<WebURL> weburl_links(links);
WebVector<WebString> webstring_paths(local_paths.size());
for (size_t i = 0; i < local_paths.size(); i++)
webstring_paths[i] = local_paths[i].AsUTF16Unsafe();
WebPageSerializer::serialize(webview()->mainFrame()->toWebLocalFrame(),
true,
this,
weburl_links,
webstring_paths,
local_directory_name.AsUTF16Unsafe());
}
void RenderViewImpl::OnSuppressDialogsUntilSwapOut() {
suppress_dialogs_until_swap_out_ = true;
}
void RenderViewImpl::NavigateToSwappedOutURL(blink::WebFrame* frame) {
RenderFrameImpl* rf = RenderFrameImpl::FromWebFrame(frame);
CHECK(is_swapped_out_ || rf->is_swapped_out());
GURL swappedOutURL(kSwappedOutURL);
WebURLRequest request(swappedOutURL);
frame->loadRequest(request);
}
void RenderViewImpl::OnClosePage() {
FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage());
webview()->mainFrame()->dispatchUnloadEvent();
Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
}
void RenderViewImpl::OnThemeChanged() {
#if defined(USE_AURA)
#elif defined(OS_WIN)
ui::NativeThemeWin::instance()->CloseHandles();
if (webview())
webview()->themeChanged();
#else
NOTIMPLEMENTED();
#endif
}
void RenderViewImpl::OnMoveOrResizeStarted() {
if (webview())
webview()->hidePopups();
}
void RenderViewImpl::OnResize(const ViewMsg_Resize_Params& params) {
if (webview()) {
webview()->hidePopups();
if (send_preferred_size_changes_) {
webview()->mainFrame()->setCanHaveScrollbars(
ShouldDisplayScrollbars(params.new_size.width(),
params.new_size.height()));
}
UpdateScrollState(webview()->mainFrame());
}
RenderWidget::OnResize(params);
}
void RenderViewImpl::DidInitiatePaint() {
#if defined(ENABLE_PLUGINS)
PepperPluginSet plugins = active_pepper_instances_;
for (PepperPluginSet::iterator i = plugins.begin(); i != plugins.end(); ++i) {
if (active_pepper_instances_.find(*i) != active_pepper_instances_.end())
(*i)->ViewInitiatedPaint();
}
#endif
}
void RenderViewImpl::DidFlushPaint() {
#if defined(ENABLE_PLUGINS)
PepperPluginSet plugins = active_pepper_instances_;
for (PepperPluginSet::iterator i = plugins.begin(); i != plugins.end(); ++i) {
if (active_pepper_instances_.find(*i) != active_pepper_instances_.end())
(*i)->ViewFlushedPaint();
}
#endif
if (!webview())
return;
WebFrame* main_frame = webview()->mainFrame();
if (!main_frame->provisionalDataSource()) {
WebDataSource* ds = main_frame->dataSource();
DocumentState* document_state = DocumentState::FromDataSource(ds);
InternalDocumentStateData* data =
InternalDocumentStateData::FromDocumentState(document_state);
if (data->did_first_visually_non_empty_layout() &&
!data->did_first_visually_non_empty_paint()) {
data->set_did_first_visually_non_empty_paint(true);
Send(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_,
page_id_));
}
Time now = Time::Now();
if (document_state->first_paint_time().is_null()) {
document_state->set_first_paint_time(now);
}
if (document_state->first_paint_after_load_time().is_null() &&
!document_state->finish_load_time().is_null()) {
document_state->set_first_paint_after_load_time(now);
}
}
}
PepperPluginInstanceImpl* RenderViewImpl::GetBitmapForOptimizedPluginPaint(
const gfx::Rect& paint_bounds,
TransportDIB** dib,
gfx::Rect* location,
gfx::Rect* clip,
float* scale_factor) {
#if defined(ENABLE_PLUGINS)
for (PepperPluginSet::iterator i = active_pepper_instances_.begin();
i != active_pepper_instances_.end(); ++i) {
PepperPluginInstanceImpl* instance = *i;
if (!instance->FlashIsFullscreenOrPending() &&
instance->GetBitmapForOptimizedPluginPaint(paint_bounds, dib, location,
clip, scale_factor))
return *i;
}
#endif
return NULL;
}
gfx::Vector2d RenderViewImpl::GetScrollOffset() {
WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
return gfx::Vector2d(scroll_offset.width, scroll_offset.height);
}
void RenderViewImpl::OnClearFocusedElement() {
if (webview())
webview()->clearFocusedElement();
}
void RenderViewImpl::OnSetBackground(const SkBitmap& background) {
if (webview())
webview()->setIsTransparent(!background.empty());
if (compositor_)
compositor_->setHasTransparentBackground(!background.empty());
SetBackground(background);
}
void RenderViewImpl::OnSetAccessibilityMode(AccessibilityMode new_mode) {
if (accessibility_mode_ == new_mode)
return;
accessibility_mode_ = new_mode;
if (renderer_accessibility_) {
delete renderer_accessibility_;
renderer_accessibility_ = NULL;
}
if (accessibility_mode_ == AccessibilityModeOff)
return;
if (accessibility_mode_ & AccessibilityModeFlagFullTree)
renderer_accessibility_ = new RendererAccessibilityComplete(this);
#if !defined(OS_ANDROID)
else
renderer_accessibility_ = new RendererAccessibilityFocusOnly(this);
#endif
}
void RenderViewImpl::OnSetActive(bool active) {
if (webview())
webview()->setIsActive(active);
#if defined(ENABLE_PLUGINS) && defined(OS_MACOSX)
std::set<WebPluginDelegateProxy*>::iterator plugin_it;
for (plugin_it = plugin_delegates_.begin();
plugin_it != plugin_delegates_.end(); ++plugin_it) {
(*plugin_it)->SetWindowFocus(active);
}
#endif
}
#if defined(OS_MACOSX)
void RenderViewImpl::OnSetWindowVisibility(bool visible) {
#if defined(ENABLE_PLUGINS)
std::set<WebPluginDelegateProxy*>::iterator plugin_it;
for (plugin_it = plugin_delegates_.begin();
plugin_it != plugin_delegates_.end(); ++plugin_it) {
(*plugin_it)->SetContainerVisibility(visible);
}
#endif
}
void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame,
const gfx::Rect& view_frame) {
#if defined(ENABLE_PLUGINS)
std::set<WebPluginDelegateProxy*>::iterator plugin_it;
for (plugin_it = plugin_delegates_.begin();
plugin_it != plugin_delegates_.end(); ++plugin_it) {
(*plugin_it)->WindowFrameChanged(window_frame, view_frame);
}
#endif
}
void RenderViewImpl::OnPluginImeCompositionCompleted(const base::string16& text,
int plugin_id) {
std::set<WebPluginDelegateProxy*>::iterator plugin_it;
for (plugin_it = plugin_delegates_.begin();
plugin_it != plugin_delegates_.end(); ++plugin_it) {
(*plugin_it)->ImeCompositionCompleted(text, plugin_id);
}
}
#endif
void RenderViewImpl::Close() {
WebView* doomed = webview();
RenderWidget::Close();
g_view_map.Get().erase(doomed);
g_routing_id_view_map.Get().erase(routing_id_);
}
void RenderViewImpl::DidHandleKeyEvent() {
ClearEditCommands();
}
void RenderViewImpl::WillProcessUserGesture() {
FOR_EACH_OBSERVER(
RenderViewObserver, observers_, WillProcessUserGesture());
}
bool RenderViewImpl::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
possible_drag_event_info_.event_source =
ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE;
possible_drag_event_info_.event_location =
gfx::Point(event.globalX, event.globalY);
#if defined(ENABLE_PLUGINS)
pepper_last_mouse_event_target_ = NULL;
#endif
return mouse_lock_dispatcher_->WillHandleMouseEvent(event);
}
bool RenderViewImpl::WillHandleGestureEvent(
const blink::WebGestureEvent& event) {
possible_drag_event_info_.event_source =
ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH;
possible_drag_event_info_.event_location =
gfx::Point(event.globalX, event.globalY);
return false;
}
void RenderViewImpl::DidHandleMouseEvent(const WebMouseEvent& event) {
FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
}
void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) {
FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event));
}
bool RenderViewImpl::HasTouchEventHandlersAt(const gfx::Point& point) const {
if (!webview())
return false;
return webview()->hasTouchEventHandlersAt(point);
}
void RenderViewImpl::OnWasHidden() {
RenderWidget::OnWasHidden();
#if defined(OS_ANDROID) && defined(ENABLE_WEBRTC)
RenderThreadImpl::current()->video_capture_impl_manager()->
SuspendDevices(true);
#endif
if (webview())
webview()->setVisibilityState(visibilityState(), false);
#if defined(ENABLE_PLUGINS)
for (PepperPluginSet::iterator i = active_pepper_instances_.begin();
i != active_pepper_instances_.end(); ++i)
(*i)->PageVisibilityChanged(false);
#if defined(OS_MACOSX)
std::set<WebPluginDelegateProxy*>::iterator plugin_it;
for (plugin_it = plugin_delegates_.begin();
plugin_it != plugin_delegates_.end(); ++plugin_it) {
(*plugin_it)->SetContainerVisibility(false);
}
#endif
#endif
}
void RenderViewImpl::OnWasShown(bool needs_repainting) {
RenderWidget::OnWasShown(needs_repainting);
#if defined(OS_ANDROID) && defined(ENABLE_WEBRTC)
RenderThreadImpl::current()->video_capture_impl_manager()->
SuspendDevices(false);
#endif
if (webview())
webview()->setVisibilityState(visibilityState(), false);
#if defined(ENABLE_PLUGINS)
for (PepperPluginSet::iterator i = active_pepper_instances_.begin();
i != active_pepper_instances_.end(); ++i)
(*i)->PageVisibilityChanged(true);
#if defined(OS_MACOSX)
std::set<WebPluginDelegateProxy*>::iterator plugin_it;
for (plugin_it = plugin_delegates_.begin();
plugin_it != plugin_delegates_.end(); ++plugin_it) {
(*plugin_it)->SetContainerVisibility(true);
}
#endif
#endif
}
GURL RenderViewImpl::GetURLForGraphicsContext3D() {
DCHECK(webview());
if (webview()->mainFrame())
return GURL(webview()->mainFrame()->document().url());
else
return GURL("chrome://gpu/RenderViewImpl::CreateGraphicsContext3D");
}
bool RenderViewImpl::ForceCompositingModeEnabled() {
return webkit_preferences_.force_compositing_mode;
}
void RenderViewImpl::OnSetFocus(bool enable) {
RenderWidget::OnSetFocus(enable);
#if defined(ENABLE_PLUGINS)
if (webview() && webview()->isActive()) {
std::set<WebPluginDelegateProxy*>::iterator plugin_it;
for (plugin_it = plugin_delegates_.begin();
plugin_it != plugin_delegates_.end(); ++plugin_it) {
#if defined(OS_MACOSX)
if (enable)
(*plugin_it)->SetWindowFocus(true);
#endif
(*plugin_it)->SetContentAreaFocus(enable);
}
}
for (PepperPluginSet::iterator i = active_pepper_instances_.begin();
i != active_pepper_instances_.end(); ++i)
(*i)->SetContentAreaFocus(enable);
#endif
if (browser_plugin_manager_.get())
browser_plugin_manager_->UpdateFocusState();
}
void RenderViewImpl::OnImeSetComposition(
const base::string16& text,
const std::vector<blink::WebCompositionUnderline>& underlines,
int selection_start,
int selection_end) {
#if defined(ENABLE_PLUGINS)
if (focused_pepper_plugin_) {
focused_pepper_plugin_->render_frame()->OnImeSetComposition(
text, underlines, selection_start, selection_end);
return;
}
#if defined(OS_WIN)
if (focused_plugin_id_ >= 0) {
std::vector<int> clauses;
std::vector<int> target;
for (size_t i = 0; i < underlines.size(); ++i) {
clauses.push_back(underlines[i].startOffset);
clauses.push_back(underlines[i].endOffset);
if (underlines[i].thick) {
target.clear();
target.push_back(underlines[i].startOffset);
target.push_back(underlines[i].endOffset);
}
}
std::set<WebPluginDelegateProxy*>::iterator it;
for (it = plugin_delegates_.begin(); it != plugin_delegates_.end(); ++it) {
(*it)->ImeCompositionUpdated(text, clauses, target, selection_end,
focused_plugin_id_);
}
return;
}
#endif
#endif
RenderWidget::OnImeSetComposition(text,
underlines,
selection_start,
selection_end);
}
void RenderViewImpl::OnImeConfirmComposition(
const base::string16& text,
const gfx::Range& replacement_range,
bool keep_selection) {
#if defined(ENABLE_PLUGINS)
if (focused_pepper_plugin_) {
focused_pepper_plugin_->render_frame()->OnImeConfirmComposition(
text, replacement_range, keep_selection);
return;
}
#if defined(OS_WIN)
if (focused_plugin_id_ >= 0) {
std::set<WebPluginDelegateProxy*>::iterator it;
for (it = plugin_delegates_.begin();
it != plugin_delegates_.end(); ++it) {
(*it)->ImeCompositionCompleted(text, focused_plugin_id_);
}
return;
}
#endif
#endif
if (replacement_range.IsValid() && webview()) {
if (WebLocalFrame* frame = webview()->focusedFrame()->toWebLocalFrame()) {
WebRange webrange = WebRange::fromDocumentRange(
frame, replacement_range.start(), replacement_range.length());
if (!webrange.isNull())
frame->selectRange(webrange);
}
}
RenderWidget::OnImeConfirmComposition(text,
replacement_range,
keep_selection);
}
void RenderViewImpl::SetDeviceScaleFactor(float device_scale_factor) {
RenderWidget::SetDeviceScaleFactor(device_scale_factor);
if (webview()) {
webview()->setDeviceScaleFactor(device_scale_factor);
webview()->settings()->setAcceleratedCompositingForFixedPositionEnabled(
ShouldUseFixedPositionCompositing(device_scale_factor_));
webview()->settings()->setAcceleratedCompositingForOverflowScrollEnabled(
ShouldUseAcceleratedCompositingForOverflowScroll(device_scale_factor_));
webview()->settings()->setAcceleratedCompositingForTransitionEnabled(
ShouldUseTransitionCompositing(device_scale_factor_));
webview()->settings()->
setAcceleratedCompositingForFixedRootBackgroundEnabled(
ShouldUseAcceleratedFixedRootBackground(device_scale_factor_));
webview()->settings()->setAcceleratedCompositingForScrollableFramesEnabled(
ShouldUseAcceleratedCompositingForScrollableFrames(
device_scale_factor_));
webview()->settings()->setCompositedScrollingForFramesEnabled(
ShouldUseCompositedScrollingForFrames(device_scale_factor_));
}
if (auto_resize_mode_)
AutoResizeCompositor();
if (browser_plugin_manager_.get())
browser_plugin_manager_->UpdateDeviceScaleFactor(device_scale_factor_);
}
ui::TextInputType RenderViewImpl::GetTextInputType() {
#if defined(ENABLE_PLUGINS)
if (focused_pepper_plugin_)
return focused_pepper_plugin_->text_input_type();
#endif
return RenderWidget::GetTextInputType();
}
void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
#if defined(ENABLE_PLUGINS)
if (focused_pepper_plugin_) {
gfx::Rect caret = focused_pepper_plugin_->GetCaretBounds();
*start = caret;
*end = caret;
return;
}
#endif
RenderWidget::GetSelectionBounds(start, end);
}
#if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA)
void RenderViewImpl::GetCompositionCharacterBounds(
std::vector<gfx::Rect>* bounds) {
DCHECK(bounds);
bounds->clear();
#if defined(ENABLE_PLUGINS)
if (focused_pepper_plugin_) {
return;
}
#endif
if (!webview())
return;
size_t start_offset = 0;
size_t character_count = 0;
if (!webview()->compositionRange(&start_offset, &character_count))
return;
if (character_count == 0)
return;
blink::WebFrame* frame = webview()->focusedFrame();
if (!frame)
return;
bounds->reserve(character_count);
blink::WebRect webrect;
for (size_t i = 0; i < character_count; ++i) {
if (!frame->firstRectForCharacterRange(start_offset + i, 1, webrect)) {
DLOG(ERROR) << "Could not retrieve character rectangle at " << i;
bounds->clear();
return;
}
bounds->push_back(webrect);
}
}
void RenderViewImpl::GetCompositionRange(gfx::Range* range) {
#if defined(ENABLE_PLUGINS)
if (focused_pepper_plugin_) {
return;
}
#endif
RenderWidget::GetCompositionRange(range);
}
#endif
bool RenderViewImpl::CanComposeInline() {
#if defined(ENABLE_PLUGINS)
if (focused_pepper_plugin_)
return focused_pepper_plugin_->IsPluginAcceptingCompositionEvents();
#endif
return true;
}
void RenderViewImpl::InstrumentWillBeginFrame(int frame_id) {
if (!webview())
return;
if (!webview()->devToolsAgent())
return;
webview()->devToolsAgent()->didBeginFrame(frame_id);
}
void RenderViewImpl::InstrumentDidBeginFrame() {
if (!webview())
return;
if (!webview()->devToolsAgent())
return;
webview()->devToolsAgent()->didComposite();
}
void RenderViewImpl::InstrumentDidCancelFrame() {
if (!webview())
return;
if (!webview()->devToolsAgent())
return;
webview()->devToolsAgent()->didCancelFrame();
}
void RenderViewImpl::InstrumentWillComposite() {
if (!webview())
return;
if (!webview()->devToolsAgent())
return;
webview()->devToolsAgent()->willComposite();
}
void RenderViewImpl::SetScreenMetricsEmulationParameters(
float device_scale_factor,
const gfx::Point& root_layer_offset,
float root_layer_scale) {
if (webview()) {
webview()->setCompositorDeviceScaleFactorOverride(device_scale_factor);
webview()->setRootLayerTransform(
blink::WebSize(root_layer_offset.x(), root_layer_offset.y()),
root_layer_scale);
}
}
bool RenderViewImpl::ScheduleFileChooser(
const FileChooserParams& params,
WebFileChooserCompletion* completion) {
static const size_t kMaximumPendingFileChooseRequests = 4;
if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
return false;
}
file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
new PendingFileChooser(params, completion)));
if (file_chooser_completions_.size() == 1) {
Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
}
return true;
}
blink::WebGeolocationClient* RenderViewImpl::geolocationClient() {
if (!geolocation_dispatcher_)
geolocation_dispatcher_ = new GeolocationDispatcher(this);
return geolocation_dispatcher_;
}
blink::WebSpeechInputController* RenderViewImpl::speechInputController(
blink::WebSpeechInputListener* listener) {
#if defined(ENABLE_INPUT_SPEECH)
if (!input_tag_speech_dispatcher_)
input_tag_speech_dispatcher_ =
new InputTagSpeechDispatcher(this, listener);
#endif
return input_tag_speech_dispatcher_;
}
blink::WebSpeechRecognizer* RenderViewImpl::speechRecognizer() {
if (!speech_recognition_dispatcher_)
speech_recognition_dispatcher_ = new SpeechRecognitionDispatcher(this);
return speech_recognition_dispatcher_;
}
void RenderViewImpl::zoomLimitsChanged(double minimum_level,
double maximum_level) {
bool remember = !webview()->mainFrame()->document().isPluginDocument();
int minimum_percent = static_cast<int>(
ZoomLevelToZoomFactor(minimum_level) * 100);
int maximum_percent = static_cast<int>(
ZoomLevelToZoomFactor(maximum_level) * 100);
Send(new ViewHostMsg_UpdateZoomLimits(
routing_id_, minimum_percent, maximum_percent, remember));
}
void RenderViewImpl::zoomLevelChanged() {
bool remember = !webview()->mainFrame()->document().isPluginDocument();
float zoom_level = webview()->zoomLevel();
FOR_EACH_OBSERVER(RenderViewObserver, observers_, ZoomLevelChanged());
Send(new ViewHostMsg_DidZoomURL(
routing_id_, zoom_level, remember,
GURL(webview()->mainFrame()->document().url())));
}
double RenderViewImpl::zoomLevelToZoomFactor(double zoom_level) const {
return ZoomLevelToZoomFactor(zoom_level);
}
double RenderViewImpl::zoomFactorToZoomLevel(double factor) const {
return ZoomFactorToZoomLevel(factor);
}
void RenderViewImpl::registerProtocolHandler(const WebString& scheme,
const WebURL& base_url,
const WebURL& url,
const WebString& title) {
bool user_gesture = WebUserGestureIndicator::isProcessingUserGesture();
GURL base(base_url);
GURL absolute_url = base.Resolve(base::UTF16ToUTF8(url.string()));
if (base.GetOrigin() != absolute_url.GetOrigin()) {
return;
}
Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_,
base::UTF16ToUTF8(scheme),
absolute_url,
title,
user_gesture));
}
blink::WebPageVisibilityState RenderViewImpl::visibilityState() const {
blink::WebPageVisibilityState current_state = is_hidden() ?
blink::WebPageVisibilityStateHidden :
blink::WebPageVisibilityStateVisible;
blink::WebPageVisibilityState override_state = current_state;
if (GetContentClient()->renderer()->
ShouldOverridePageVisibilityState(main_render_frame_.get(),
&override_state))
return override_state;
return current_state;
}
blink::WebUserMediaClient* RenderViewImpl::userMediaClient() {
if (!InitializeMediaStreamClient())
return NULL;
return web_user_media_client_;
}
blink::WebMIDIClient* RenderViewImpl::webMIDIClient() {
if (!midi_dispatcher_)
midi_dispatcher_ = new MidiDispatcher(this);
return midi_dispatcher_;
}
void RenderViewImpl::draggableRegionsChanged() {
FOR_EACH_OBSERVER(
RenderViewObserver,
observers_,
DraggableRegionsChanged(webview()->mainFrame()));
}
WebMediaPlayer* RenderViewImpl::CreateWebMediaPlayerForMediaStream(
WebFrame* frame,
const blink::WebURL& url,
WebMediaPlayerClient* client) {
#if defined(ENABLE_WEBRTC)
if (!InitializeMediaStreamClient()) {
LOG(ERROR) << "Failed to initialize MediaStreamClient";
return NULL;
}
if (media_stream_client_->IsMediaStream(url)) {
#if defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL)
bool found_neon =
(android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0;
UMA_HISTOGRAM_BOOLEAN("Platform.WebRtcNEONFound", found_neon);
#endif
return new WebMediaPlayerMS(frame, client, AsWeakPtr(),
media_stream_client_, new RenderMediaLog());
}
#endif
return NULL;
}
#if defined(OS_ANDROID)
WebContentDetectionResult RenderViewImpl::detectContentAround(
const WebHitTestResult& touch_hit) {
DCHECK(!touch_hit.isNull());
DCHECK(!touch_hit.node().isNull());
DCHECK(touch_hit.node().isTextNode());
for (ContentDetectorList::const_iterator it = content_detectors_.begin();
it != content_detectors_.end(); ++it) {
ContentDetector::Result content = (*it)->FindTappedContent(touch_hit);
if (content.valid) {
return WebContentDetectionResult(content.content_boundaries,
base::UTF8ToUTF16(content.text), content.intent_url);
}
}
return WebContentDetectionResult();
}
void RenderViewImpl::scheduleContentIntent(const WebURL& intent) {
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE,
base::Bind(&RenderViewImpl::LaunchAndroidContentIntent,
AsWeakPtr(),
intent,
expected_content_intent_id_),
base::TimeDelta::FromMilliseconds(kContentIntentDelayMilliseconds));
}
void RenderViewImpl::cancelScheduledContentIntents() {
++expected_content_intent_id_;
}
void RenderViewImpl::LaunchAndroidContentIntent(const GURL& intent,
size_t request_id) {
if (request_id != expected_content_intent_id_)
return;
scheduleComposite();
if (!intent.is_empty())
Send(new ViewHostMsg_StartContentIntent(routing_id_, intent));
}
bool RenderViewImpl::openDateTimeChooser(
const blink::WebDateTimeChooserParams& params,
blink::WebDateTimeChooserCompletion* completion) {
if (date_time_picker_client_)
return false;
date_time_picker_client_.reset(
new RendererDateTimePicker(this, params, completion));
return date_time_picker_client_->Open();
}
void RenderViewImpl::DismissDateTimeDialog() {
DCHECK(date_time_picker_client_);
date_time_picker_client_.reset(NULL);
}
WebMediaPlayer* RenderViewImpl::CreateAndroidWebMediaPlayer(
WebFrame* frame,
const blink::WebURL& url,
WebMediaPlayerClient* client) {
GpuChannelHost* gpu_channel_host =
RenderThreadImpl::current()->EstablishGpuChannelSync(
CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE);
if (!gpu_channel_host) {
LOG(ERROR) << "Failed to establish GPU channel for media player";
return NULL;
}
scoped_refptr<StreamTextureFactory> stream_texture_factory;
if (UsingSynchronousRendererCompositor()) {
SynchronousCompositorFactory* factory =
SynchronousCompositorFactory::GetInstance();
stream_texture_factory = factory->CreateStreamTextureFactory(routing_id_);
} else {
scoped_refptr<webkit::gpu::ContextProviderWebContext> context_provider =
RenderThreadImpl::current()->SharedMainThreadContextProvider();
if (!context_provider.get()) {
LOG(ERROR) << "Failed to get context3d for media player";
return NULL;
}
stream_texture_factory = StreamTextureFactoryImpl::Create(
context_provider, gpu_channel_host, routing_id_);
}
return new WebMediaPlayerAndroid(
frame,
client,
AsWeakPtr(),
media_player_manager_,
stream_texture_factory,
RenderThreadImpl::current()->GetMediaThreadMessageLoopProxy(),
new RenderMediaLog());
}
#endif
#if defined(OS_MACOSX)
void RenderViewImpl::OnSelectPopupMenuItem(int selected_index) {
if (external_popup_menu_ == NULL)
return;
external_popup_menu_->DidSelectItem(selected_index);
external_popup_menu_.reset();
}
#endif
#if defined(OS_ANDROID)
void RenderViewImpl::OnSelectPopupMenuItems(
bool canceled,
const std::vector<int>& selected_indices) {
if (!external_popup_menu_)
return;
external_popup_menu_->DidSelectItems(canceled, selected_indices);
external_popup_menu_.reset();
}
#endif
#if defined(OS_MACOSX) || defined(OS_ANDROID)
void RenderViewImpl::DidHideExternalPopupMenu() {
external_popup_menu_.reset();
}
#endif
void RenderViewImpl::OnShowContextMenu(const gfx::Point& location) {
context_menu_source_type_ = ui::MENU_SOURCE_TOUCH_EDIT_MENU;
touch_editing_context_menu_location_ = location;
if (webview())
webview()->showContextMenu();
}
void RenderViewImpl::OnEnableViewSourceMode() {
if (!webview())
return;
WebFrame* main_frame = webview()->mainFrame();
if (!main_frame)
return;
main_frame->enableViewSourceMode(true);
}
void RenderViewImpl::OnDisownOpener() {
if (!webview())
return;
WebFrame* main_frame = webview()->mainFrame();
if (main_frame && main_frame->opener())
main_frame->setOpener(NULL);
}
#if defined(OS_ANDROID)
bool RenderViewImpl::didTapMultipleTargets(
const blink::WebGestureEvent& event,
const WebVector<WebRect>& target_rects) {
bool matchesAccessibilityModeComplete =
(accessibility_mode_ & AccessibilityModeComplete) ==
AccessibilityModeComplete;
if (matchesAccessibilityModeComplete)
return false;
gfx::Rect finger_rect(
event.x - event.data.tap.width / 2, event.y - event.data.tap.height / 2,
event.data.tap.width, event.data.tap.height);
gfx::Rect zoom_rect;
float new_total_scale =
DisambiguationPopupHelper::ComputeZoomAreaAndScaleFactor(
finger_rect, target_rects, GetSize(),
gfx::Rect(webview()->mainFrame()->visibleContentRect()).size(),
device_scale_factor_ * webview()->pageScaleFactor(), &zoom_rect);
if (!new_total_scale)
return false;
bool handled = false;
switch (renderer_preferences_.tap_multiple_targets_strategy) {
case TAP_MULTIPLE_TARGETS_STRATEGY_ZOOM:
handled = webview()->zoomToMultipleTargetsRect(zoom_rect);
break;
case TAP_MULTIPLE_TARGETS_STRATEGY_POPUP: {
gfx::Size canvas_size =
gfx::ToCeiledSize(gfx::ScaleSize(zoom_rect.size(), new_total_scale));
TransportDIB* transport_dib = NULL;
{
scoped_ptr<skia::PlatformCanvas> canvas(
RenderProcess::current()->GetDrawingCanvas(&transport_dib,
gfx::Rect(canvas_size)));
if (!canvas) {
handled = false;
break;
}
canvas->scale(new_total_scale / device_scale_factor_,
new_total_scale / device_scale_factor_);
canvas->translate(-zoom_rect.x() * device_scale_factor_,
-zoom_rect.y() * device_scale_factor_);
webwidget_->paint(
canvas.get(),
zoom_rect,
WebWidget::ForceSoftwareRenderingAndIgnoreGPUResidentContent);
}
gfx::Rect physical_window_zoom_rect = gfx::ToEnclosingRect(
ClientRectToPhysicalWindowRect(gfx::RectF(zoom_rect)));
Send(new ViewHostMsg_ShowDisambiguationPopup(routing_id_,
physical_window_zoom_rect,
canvas_size,
transport_dib->id()));
handled = true;
break;
}
case TAP_MULTIPLE_TARGETS_STRATEGY_NONE:
break;
}
return handled;
}
#endif
unsigned RenderViewImpl::GetLocalSessionHistoryLengthForTesting() const {
return history_list_length_;
}
void RenderViewImpl::SetFocusAndActivateForTesting(bool enable) {
if (enable) {
if (has_focus())
return;
OnSetActive(true);
OnSetFocus(true);
} else {
if (!has_focus())
return;
OnSetFocus(false);
OnSetActive(false);
}
}
void RenderViewImpl::SetDeviceScaleFactorForTesting(float factor) {
ViewMsg_Resize_Params params;
params.screen_info = screen_info_;
params.screen_info.deviceScaleFactor = factor;
params.new_size = size();
params.physical_backing_size =
gfx::ToCeiledSize(gfx::ScaleSize(size(), factor));
params.overdraw_bottom_height = 0.f;
params.resizer_rect = WebRect();
params.is_fullscreen = is_fullscreen();
OnResize(params);
}
void RenderViewImpl::ForceResizeForTesting(const gfx::Size& new_size) {
gfx::Rect new_position(rootWindowRect().x,
rootWindowRect().y,
new_size.width(),
new_size.height());
ResizeSynchronously(new_position);
}
void RenderViewImpl::UseSynchronousResizeModeForTesting(bool enable) {
resizing_mode_selector_->set_is_synchronous_mode(enable);
}
void RenderViewImpl::EnableAutoResizeForTesting(const gfx::Size& min_size,
const gfx::Size& max_size) {
OnEnableAutoResize(min_size, max_size);
}
void RenderViewImpl::DisableAutoResizeForTesting(const gfx::Size& new_size) {
OnDisableAutoResize(new_size);
}
void RenderViewImpl::SetMediaStreamClientForTesting(
MediaStreamClient* media_stream_client) {
DCHECK(!media_stream_client_);
DCHECK(!web_user_media_client_);
media_stream_client_ = media_stream_client;
}
void RenderViewImpl::OnReleaseDisambiguationPopupDIB(
TransportDIB::Handle dib_handle) {
TransportDIB* dib = TransportDIB::CreateWithHandle(dib_handle);
RenderProcess::current()->ReleaseTransportDIB(dib);
}
void RenderViewImpl::DidCommitCompositorFrame() {
RenderWidget::DidCommitCompositorFrame();
FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidCommitCompositorFrame());
}
void RenderViewImpl::SendUpdateFaviconURL(const std::vector<FaviconURL>& urls) {
if (!urls.empty())
Send(new ViewHostMsg_UpdateFaviconURL(routing_id_, page_id_, urls));
}
void RenderViewImpl::DidStopLoadingIcons() {
int icon_types = WebIconURL::TypeFavicon;
if (TouchEnabled())
icon_types |= WebIconURL::TypeTouchPrecomposed | WebIconURL::TypeTouch;
WebVector<WebIconURL> icon_urls =
webview()->mainFrame()->iconURLs(icon_types);
std::vector<FaviconURL> urls;
for (size_t i = 0; i < icon_urls.size(); i++) {
WebURL url = icon_urls[i].iconURL();
std::vector<gfx::Size> sizes(icon_urls[i].sizes().size());
ConvertToFaviconSizes(icon_urls[i].sizes(), &sizes);
if (!url.isEmpty())
urls.push_back(
FaviconURL(url, ToFaviconType(icon_urls[i].iconType()), sizes));
}
SendUpdateFaviconURL(urls);
}
}