Home | History | Annotate | Download | only in renderer
      1 // Copyright 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CONTENT_RENDERER_RENDER_FRAME_IMPL_H_
      6 #define CONTENT_RENDERER_RENDER_FRAME_IMPL_H_
      7 
      8 #include <vector>
      9 
     10 #include "base/basictypes.h"
     11 #include "base/files/file_path.h"
     12 #include "base/gtest_prod_util.h"
     13 #include "base/id_map.h"
     14 #include "base/memory/weak_ptr.h"
     15 #include "base/observer_list.h"
     16 #include "base/process/process_handle.h"
     17 #include "content/common/accessibility_mode_enums.h"
     18 #include "content/common/mojo/service_registry_impl.h"
     19 #include "content/public/common/javascript_message_type.h"
     20 #include "content/public/common/referrer.h"
     21 #include "content/public/renderer/render_frame.h"
     22 #include "content/renderer/render_frame_proxy.h"
     23 #include "content/renderer/renderer_webcookiejar_impl.h"
     24 #include "ipc/ipc_message.h"
     25 #include "media/blink/webmediaplayer_delegate.h"
     26 #include "third_party/WebKit/public/web/WebAXObject.h"
     27 #include "third_party/WebKit/public/web/WebDataSource.h"
     28 #include "third_party/WebKit/public/web/WebFrameClient.h"
     29 #include "third_party/WebKit/public/web/WebHistoryCommitType.h"
     30 #include "ui/gfx/range/range.h"
     31 
     32 #if defined(OS_ANDROID)
     33 #include "content/renderer/media/android/renderer_media_player_manager.h"
     34 #endif
     35 
     36 class TransportDIB;
     37 struct FrameMsg_Navigate_Params;
     38 
     39 namespace blink {
     40 class WebGeolocationClient;
     41 class WebInputEvent;
     42 class WebMouseEvent;
     43 class WebContentDecryptionModule;
     44 class WebMediaPlayer;
     45 class WebNotificationPresenter;
     46 class WebPushClient;
     47 class WebSecurityOrigin;
     48 struct WebCompositionUnderline;
     49 struct WebContextMenuData;
     50 struct WebCursorInfo;
     51 }
     52 
     53 namespace gfx {
     54 class Point;
     55 class Range;
     56 class Rect;
     57 }
     58 
     59 namespace content {
     60 
     61 class ChildFrameCompositingHelper;
     62 class ExternalPopupMenu;
     63 class GeolocationDispatcher;
     64 class ManifestManager;
     65 class MediaStreamDispatcher;
     66 class MediaStreamRendererFactory;
     67 class MidiDispatcher;
     68 class NotificationPermissionDispatcher;
     69 class NotificationProvider;
     70 class PepperPluginInstanceImpl;
     71 class PushMessagingDispatcher;
     72 class RendererAccessibility;
     73 class RendererCdmManager;
     74 class RendererMediaPlayerManager;
     75 class RendererPpapiHost;
     76 class RenderFrameObserver;
     77 class RenderViewImpl;
     78 class RenderWidget;
     79 class RenderWidgetFullscreenPepper;
     80 class ScreenOrientationDispatcher;
     81 class UserMediaClientImpl;
     82 struct CustomContextMenuContext;
     83 
     84 class CONTENT_EXPORT RenderFrameImpl
     85     : public RenderFrame,
     86       NON_EXPORTED_BASE(public blink::WebFrameClient),
     87       NON_EXPORTED_BASE(public media::WebMediaPlayerDelegate) {
     88  public:
     89   // Creates a new RenderFrame. |render_view| is the RenderView object that this
     90   // frame belongs to.
     91   // Callers *must* call |SetWebFrame| immediately after creation.
     92   // Note: This is called only when RenderFrame is created by Blink through
     93   // createChildFrame.
     94   // TODO(creis): We should structure this so that |SetWebFrame| isn't needed.
     95   static RenderFrameImpl* Create(RenderViewImpl* render_view, int32 routing_id);
     96 
     97   // Creates a new RenderFrame with |routing_id| as a child of the RenderFrame
     98   // identified by |parent_routing_id| or as the top-level frame if the latter
     99   // is MSG_ROUTING_NONE. It creates the Blink WebLocalFrame and inserts it in
    100   // the proper place in the frame tree.
    101   // Note: This is called only when RenderFrame is being created in response to
    102   // IPC message from the browser process. All other frame creation is driven
    103   // through Blink and Create.
    104   static void CreateFrame(int routing_id, int parent_routing_id);
    105 
    106   // Returns the RenderFrameImpl for the given routing ID.
    107   static RenderFrameImpl* FromRoutingID(int routing_id);
    108 
    109   // Just like RenderFrame::FromWebFrame but returns the implementation.
    110   static RenderFrameImpl* FromWebFrame(blink::WebFrame* web_frame);
    111 
    112   // Used by content_layouttest_support to hook into the creation of
    113   // RenderFrameImpls.
    114   static void InstallCreateHook(
    115       RenderFrameImpl* (*create_render_frame_impl)(RenderViewImpl*, int32));
    116 
    117   virtual ~RenderFrameImpl();
    118 
    119   bool is_swapped_out() const {
    120     return is_swapped_out_;
    121   }
    122 
    123   // TODO(nasko): This can be removed once we don't have a swapped out state on
    124   // RenderFrames. See https://crbug.com/357747.
    125   void set_render_frame_proxy(RenderFrameProxy* proxy) {
    126     render_frame_proxy_ = proxy;
    127   }
    128 
    129   // Out-of-process child frames receive a signal from RenderWidgetCompositor
    130   // when a compositor frame has committed.
    131   void DidCommitCompositorFrame();
    132 
    133   // TODO(jam): this is a temporary getter until all the code is transitioned
    134   // to using RenderFrame instead of RenderView.
    135   RenderViewImpl* render_view() { return render_view_.get(); }
    136 
    137   RendererWebCookieJarImpl* cookie_jar() { return &cookie_jar_; }
    138 
    139   // Returns the RenderWidget associated with this frame.
    140   RenderWidget* GetRenderWidget();
    141 
    142   // This is called right after creation with the WebLocalFrame for this
    143   // RenderFrame. It must be called before Initialize.
    144   void SetWebFrame(blink::WebLocalFrame* web_frame);
    145 
    146   // This method must be called after the frame has been added to the frame
    147   // tree. It creates all objects that depend on the frame being at its proper
    148   // spot.
    149   void Initialize();
    150 
    151   // Notifications from RenderWidget.
    152   void WasHidden();
    153   void WasShown();
    154 
    155   // Start/Stop loading notifications.
    156   // TODO(nasko): Those are page-level methods at this time and come from
    157   // WebViewClient. We should move them to be WebFrameClient calls and put
    158   // logic in the browser side to balance starts/stops.
    159   // |to_different_document| will be true unless the load is a fragment
    160   // navigation, or triggered by history.pushState/replaceState.
    161   virtual void didStartLoading(bool to_different_document);
    162   virtual void didStopLoading();
    163   virtual void didChangeLoadProgress(double load_progress);
    164 
    165   AccessibilityMode accessibility_mode() {
    166     return accessibility_mode_;
    167   }
    168 
    169   RendererAccessibility* renderer_accessibility() {
    170     return renderer_accessibility_;
    171   }
    172 
    173   void HandleWebAccessibilityEvent(const blink::WebAXObject& obj,
    174                                    blink::WebAXEvent event);
    175 
    176   // TODO(dmazzoni): the only reason this is here is to plumb it through to
    177   // RendererAccessibility. It should be part of RenderFrameObserver, once
    178   // blink has a separate accessibility tree per frame.
    179   void FocusedNodeChanged(const blink::WebNode& node);
    180 
    181 #if defined(ENABLE_PLUGINS)
    182   // Notification that a PPAPI plugin has been created.
    183   void PepperPluginCreated(RendererPpapiHost* host);
    184 
    185   // Notifies that |instance| has changed the cursor.
    186   // This will update the cursor appearance if it is currently over the plugin
    187   // instance.
    188   void PepperDidChangeCursor(PepperPluginInstanceImpl* instance,
    189                              const blink::WebCursorInfo& cursor);
    190 
    191   // Notifies that |instance| has received a mouse event.
    192   void PepperDidReceiveMouseEvent(PepperPluginInstanceImpl* instance);
    193 
    194   // Informs the render view that a PPAPI plugin has changed text input status.
    195   void PepperTextInputTypeChanged(PepperPluginInstanceImpl* instance);
    196   void PepperCaretPositionChanged(PepperPluginInstanceImpl* instance);
    197 
    198   // Cancels current composition.
    199   void PepperCancelComposition(PepperPluginInstanceImpl* instance);
    200 
    201   // Informs the render view that a PPAPI plugin has changed selection.
    202   void PepperSelectionChanged(PepperPluginInstanceImpl* instance);
    203 
    204   // Creates a fullscreen container for a pepper plugin instance.
    205   RenderWidgetFullscreenPepper* CreatePepperFullscreenContainer(
    206       PepperPluginInstanceImpl* plugin);
    207 
    208   bool IsPepperAcceptingCompositionEvents() const;
    209 
    210   // Notification that the given plugin has crashed.
    211   void PluginCrashed(const base::FilePath& plugin_path,
    212                      base::ProcessId plugin_pid);
    213 
    214   // Simulates IME events for testing purpose.
    215   void SimulateImeSetComposition(
    216       const base::string16& text,
    217       const std::vector<blink::WebCompositionUnderline>& underlines,
    218       int selection_start,
    219       int selection_end);
    220   void SimulateImeConfirmComposition(const base::string16& text,
    221                                      const gfx::Range& replacement_range);
    222 
    223   // TODO(jam): remove these once the IPC handler moves from RenderView to
    224   // RenderFrame.
    225   void OnImeSetComposition(
    226     const base::string16& text,
    227     const std::vector<blink::WebCompositionUnderline>& underlines,
    228     int selection_start,
    229     int selection_end);
    230  void OnImeConfirmComposition(
    231     const base::string16& text,
    232     const gfx::Range& replacement_range,
    233     bool keep_selection);
    234 #endif  // ENABLE_PLUGINS
    235 
    236   // May return NULL in some cases, especially if userMediaClient() returns
    237   // NULL.
    238   MediaStreamDispatcher* GetMediaStreamDispatcher();
    239 
    240 #if defined(OS_MACOSX) || defined(OS_ANDROID)
    241   void DidHideExternalPopupMenu();
    242 #endif
    243 
    244   // IPC::Sender
    245   virtual bool Send(IPC::Message* msg) OVERRIDE;
    246 
    247   // IPC::Listener
    248   virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
    249 
    250   // RenderFrame implementation:
    251   virtual RenderView* GetRenderView() OVERRIDE;
    252   virtual int GetRoutingID() OVERRIDE;
    253   virtual blink::WebLocalFrame* GetWebFrame() OVERRIDE;
    254   virtual WebPreferences& GetWebkitPreferences() OVERRIDE;
    255   virtual int ShowContextMenu(ContextMenuClient* client,
    256                               const ContextMenuParams& params) OVERRIDE;
    257   virtual void CancelContextMenu(int request_id) OVERRIDE;
    258   virtual blink::WebNode GetContextMenuNode() const OVERRIDE;
    259   virtual blink::WebPlugin* CreatePlugin(
    260       blink::WebFrame* frame,
    261       const WebPluginInfo& info,
    262       const blink::WebPluginParams& params) OVERRIDE;
    263   virtual void LoadURLExternally(blink::WebLocalFrame* frame,
    264                                  const blink::WebURLRequest& request,
    265                                  blink::WebNavigationPolicy policy) OVERRIDE;
    266   virtual void ExecuteJavaScript(const base::string16& javascript) OVERRIDE;
    267   virtual bool IsHidden() OVERRIDE;
    268   virtual ServiceRegistry* GetServiceRegistry() OVERRIDE;
    269   virtual bool IsFTPDirectoryListing() OVERRIDE;
    270   virtual void AttachGuest(int element_instance_id) OVERRIDE;
    271 
    272   // blink::WebFrameClient implementation:
    273   virtual blink::WebPlugin* createPlugin(blink::WebLocalFrame* frame,
    274                                          const blink::WebPluginParams& params);
    275   // TODO(jrummell): Remove this method once blink updated.
    276   virtual blink::WebMediaPlayer* createMediaPlayer(
    277       blink::WebLocalFrame* frame,
    278       const blink::WebURL& url,
    279       blink::WebMediaPlayerClient* client);
    280   virtual blink::WebMediaPlayer* createMediaPlayer(
    281       blink::WebLocalFrame* frame,
    282       const blink::WebURL& url,
    283       blink::WebMediaPlayerClient* client,
    284       blink::WebContentDecryptionModule* initial_cdm);
    285   virtual blink::WebContentDecryptionModule* createContentDecryptionModule(
    286       blink::WebLocalFrame* frame,
    287       const blink::WebSecurityOrigin& security_origin,
    288       const blink::WebString& key_system);
    289   virtual blink::WebApplicationCacheHost* createApplicationCacheHost(
    290       blink::WebLocalFrame* frame,
    291       blink::WebApplicationCacheHostClient* client);
    292   virtual blink::WebWorkerPermissionClientProxy*
    293       createWorkerPermissionClientProxy(blink::WebLocalFrame* frame);
    294   virtual blink::WebExternalPopupMenu* createExternalPopupMenu(
    295       const blink::WebPopupMenuInfo& popup_menu_info,
    296       blink::WebExternalPopupMenuClient* popup_menu_client);
    297   virtual blink::WebCookieJar* cookieJar(blink::WebLocalFrame* frame);
    298   virtual blink::WebServiceWorkerProvider* createServiceWorkerProvider(
    299       blink::WebLocalFrame* frame);
    300   virtual void didAccessInitialDocument(blink::WebLocalFrame* frame);
    301   virtual blink::WebFrame* createChildFrame(blink::WebLocalFrame* parent,
    302                                             const blink::WebString& name);
    303   virtual void didDisownOpener(blink::WebLocalFrame* frame);
    304   virtual void frameDetached(blink::WebFrame* frame);
    305   virtual void frameFocused();
    306   virtual void willClose(blink::WebFrame* frame);
    307   virtual void didChangeName(blink::WebLocalFrame* frame,
    308                              const blink::WebString& name);
    309   virtual void didMatchCSS(
    310       blink::WebLocalFrame* frame,
    311       const blink::WebVector<blink::WebString>& newly_matching_selectors,
    312       const blink::WebVector<blink::WebString>& stopped_matching_selectors);
    313   virtual bool shouldReportDetailedMessageForSource(
    314       const blink::WebString& source);
    315   virtual void didAddMessageToConsole(const blink::WebConsoleMessage& message,
    316                                       const blink::WebString& source_name,
    317                                       unsigned source_line,
    318                                       const blink::WebString& stack_trace);
    319   virtual void loadURLExternally(blink::WebLocalFrame* frame,
    320                                  const blink::WebURLRequest& request,
    321                                  blink::WebNavigationPolicy policy,
    322                                  const blink::WebString& suggested_name);
    323   // The WebDataSource::ExtraData* is assumed to be a DocumentState* subclass.
    324   virtual blink::WebNavigationPolicy decidePolicyForNavigation(
    325       const NavigationPolicyInfo& info);
    326   virtual blink::WebHistoryItem historyItemForNewChildFrame(
    327       blink::WebFrame* frame);
    328   virtual void willSendSubmitEvent(blink::WebLocalFrame* frame,
    329                                    const blink::WebFormElement& form);
    330   virtual void willSubmitForm(blink::WebLocalFrame* frame,
    331                               const blink::WebFormElement& form);
    332   virtual void didCreateDataSource(blink::WebLocalFrame* frame,
    333                                    blink::WebDataSource* datasource);
    334   virtual void didStartProvisionalLoad(blink::WebLocalFrame* frame,
    335                                        bool is_transition_navigation);
    336   virtual void didReceiveServerRedirectForProvisionalLoad(
    337       blink::WebLocalFrame* frame);
    338   virtual void didFailProvisionalLoad(
    339       blink::WebLocalFrame* frame,
    340       const blink::WebURLError& error);
    341   virtual void didCommitProvisionalLoad(
    342       blink::WebLocalFrame* frame,
    343       const blink::WebHistoryItem& item,
    344       blink::WebHistoryCommitType commit_type);
    345   virtual void didClearWindowObject(blink::WebLocalFrame* frame);
    346   virtual void didCreateDocumentElement(blink::WebLocalFrame* frame);
    347   virtual void didReceiveTitle(blink::WebLocalFrame* frame,
    348                                const blink::WebString& title,
    349                                blink::WebTextDirection direction);
    350   virtual void didChangeIcon(blink::WebLocalFrame* frame,
    351                              blink::WebIconURL::Type icon_type);
    352   virtual void didFinishDocumentLoad(blink::WebLocalFrame* frame);
    353   virtual void didHandleOnloadEvents(blink::WebLocalFrame* frame);
    354   virtual void didFailLoad(blink::WebLocalFrame* frame,
    355                            const blink::WebURLError& error);
    356   virtual void didFinishLoad(blink::WebLocalFrame* frame);
    357   virtual void didNavigateWithinPage(blink::WebLocalFrame* frame,
    358                                      const blink::WebHistoryItem& item,
    359                                      blink::WebHistoryCommitType commit_type);
    360   virtual void didUpdateCurrentHistoryItem(blink::WebLocalFrame* frame);
    361   virtual void addNavigationTransitionData(
    362       const blink::WebString& allowedDestinationOrigin,
    363       const blink::WebString& selector,
    364       const blink::WebString& markup);
    365   virtual void didChangeThemeColor();
    366   virtual void requestNotificationPermission(
    367       const blink::WebSecurityOrigin& origin,
    368       blink::WebNotificationPermissionCallback* callback);
    369   virtual blink::WebNotificationPresenter* notificationPresenter();
    370   virtual void didChangeSelection(bool is_empty_selection);
    371   virtual blink::WebColorChooser* createColorChooser(
    372       blink::WebColorChooserClient* client,
    373       const blink::WebColor& initial_color,
    374       const blink::WebVector<blink::WebColorSuggestion>& suggestions);
    375   virtual void runModalAlertDialog(const blink::WebString& message);
    376   virtual bool runModalConfirmDialog(const blink::WebString& message);
    377   virtual bool runModalPromptDialog(const blink::WebString& message,
    378                                     const blink::WebString& default_value,
    379                                     blink::WebString* actual_value);
    380   virtual bool runModalBeforeUnloadDialog(bool is_reload,
    381                                           const blink::WebString& message);
    382   virtual void showContextMenu(const blink::WebContextMenuData& data);
    383   virtual void clearContextMenu();
    384   virtual void willSendRequest(blink::WebLocalFrame* frame,
    385                                unsigned identifier,
    386                                blink::WebURLRequest& request,
    387                                const blink::WebURLResponse& redirect_response);
    388   virtual void didReceiveResponse(blink::WebLocalFrame* frame,
    389                                   unsigned identifier,
    390                                   const blink::WebURLResponse& response);
    391   virtual void didFinishResourceLoad(blink::WebLocalFrame* frame,
    392                                      unsigned identifier);
    393   virtual void didLoadResourceFromMemoryCache(
    394       blink::WebLocalFrame* frame,
    395       const blink::WebURLRequest& request,
    396       const blink::WebURLResponse& response);
    397   virtual void didDisplayInsecureContent(blink::WebLocalFrame* frame);
    398   virtual void didRunInsecureContent(blink::WebLocalFrame* frame,
    399                                      const blink::WebSecurityOrigin& origin,
    400                                      const blink::WebURL& target);
    401   virtual void didAbortLoading(blink::WebLocalFrame* frame);
    402   virtual void didCreateScriptContext(blink::WebLocalFrame* frame,
    403                                       v8::Handle<v8::Context> context,
    404                                       int extension_group,
    405                                       int world_id);
    406   virtual void willReleaseScriptContext(blink::WebLocalFrame* frame,
    407                                         v8::Handle<v8::Context> context,
    408                                         int world_id);
    409   virtual void didFirstVisuallyNonEmptyLayout(blink::WebLocalFrame* frame);
    410   virtual void didChangeScrollOffset(blink::WebLocalFrame* frame);
    411   virtual void willInsertBody(blink::WebLocalFrame* frame);
    412   virtual void reportFindInPageMatchCount(int request_id,
    413                                           int count,
    414                                           bool final_update);
    415   virtual void reportFindInPageSelection(int request_id,
    416                                          int active_match_ordinal,
    417                                          const blink::WebRect& sel);
    418   virtual void requestStorageQuota(blink::WebLocalFrame* frame,
    419                                    blink::WebStorageQuotaType type,
    420                                    unsigned long long requested_size,
    421                                    blink::WebStorageQuotaCallbacks callbacks);
    422   virtual void willOpenSocketStream(
    423       blink::WebSocketStreamHandle* handle);
    424   virtual void willOpenWebSocket(blink::WebSocketHandle* handle);
    425   virtual blink::WebGeolocationClient* geolocationClient();
    426   virtual blink::WebPushClient* pushClient();
    427   virtual void willStartUsingPeerConnectionHandler(
    428       blink::WebLocalFrame* frame,
    429       blink::WebRTCPeerConnectionHandler* handler);
    430   virtual blink::WebUserMediaClient* userMediaClient();
    431   virtual blink::WebMIDIClient* webMIDIClient();
    432   virtual bool willCheckAndDispatchMessageEvent(
    433       blink::WebLocalFrame* source_frame,
    434       blink::WebFrame* target_frame,
    435       blink::WebSecurityOrigin target_origin,
    436       blink::WebDOMMessageEvent event);
    437   virtual blink::WebString userAgentOverride(blink::WebLocalFrame* frame,
    438                                              const blink::WebURL& url);
    439   virtual blink::WebString doNotTrackValue(blink::WebLocalFrame* frame);
    440   virtual bool allowWebGL(blink::WebLocalFrame* frame, bool default_value);
    441   virtual void didLoseWebGLContext(blink::WebLocalFrame* frame,
    442                                    int arb_robustness_status_code);
    443   virtual void forwardInputEvent(const blink::WebInputEvent* event);
    444   virtual blink::WebScreenOrientationClient* webScreenOrientationClient();
    445   virtual bool isControlledByServiceWorker();
    446   virtual void postAccessibilityEvent(const blink::WebAXObject& obj,
    447                                       blink::WebAXEvent event);
    448   virtual void didChangeManifest(blink::WebLocalFrame*);
    449 
    450   // WebMediaPlayerDelegate implementation:
    451   virtual void DidPlay(blink::WebMediaPlayer* player) OVERRIDE;
    452   virtual void DidPause(blink::WebMediaPlayer* player) OVERRIDE;
    453   virtual void PlayerGone(blink::WebMediaPlayer* player) OVERRIDE;
    454 
    455   // TODO(nasko): Make all tests in RenderViewImplTest friends and then move
    456   // this back to private member.
    457   void OnNavigate(const FrameMsg_Navigate_Params& params);
    458 
    459   // Binds this render frame's service registry to a handle to the remote
    460   // service registry.
    461   void BindServiceRegistry(
    462       mojo::ScopedMessagePipeHandle service_provider_handle);
    463 
    464  protected:
    465   RenderFrameImpl(RenderViewImpl* render_view, int32 routing_id);
    466 
    467  private:
    468   friend class RenderFrameObserver;
    469   friend class RendererAccessibilityTest;
    470   FRIEND_TEST_ALL_PREFIXES(ExternalPopupMenuDisplayNoneTest, SelectItem);
    471   FRIEND_TEST_ALL_PREFIXES(ExternalPopupMenuRemoveTest, RemoveOnChange);
    472   FRIEND_TEST_ALL_PREFIXES(ExternalPopupMenuTest, NormalCase);
    473   FRIEND_TEST_ALL_PREFIXES(ExternalPopupMenuTest, ShowPopupThenNavigate);
    474   FRIEND_TEST_ALL_PREFIXES(RendererAccessibilityTest,
    475                            AccessibilityMessagesQueueWhileSwappedOut);
    476   FRIEND_TEST_ALL_PREFIXES(RenderFrameImplTest,
    477                            ShouldUpdateSelectionTextFromContextMenuParams);
    478   FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest,
    479                            OnExtendSelectionAndDelete);
    480   FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, ReloadWhileSwappedOut);
    481   FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, SendSwapOutACK);
    482   FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest,
    483                            SetEditableSelectionAndComposition);
    484   FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest,
    485                            OnSetAccessibilityMode);
    486 
    487   typedef std::map<GURL, double> HostZoomLevels;
    488 
    489   // Functions to add and remove observers for this object.
    490   void AddObserver(RenderFrameObserver* observer);
    491   void RemoveObserver(RenderFrameObserver* observer);
    492 
    493   // Builds and sends DidCommitProvisionalLoad to the host.
    494   void SendDidCommitProvisionalLoad(blink::WebFrame* frame);
    495 
    496   // Gets the focused element. If no such element exists then the element will
    497   // be NULL.
    498   blink::WebElement GetFocusedElement();
    499 
    500   // IPC message handlers ------------------------------------------------------
    501   //
    502   // The documentation for these functions should be in
    503   // content/common/*_messages.h for the message that the function is handling.
    504   void OnBeforeUnload();
    505   void OnSwapOut(int proxy_routing_id);
    506   void OnStop();
    507   void OnShowContextMenu(const gfx::Point& location);
    508   void OnContextMenuClosed(const CustomContextMenuContext& custom_context);
    509   void OnCustomContextMenuAction(const CustomContextMenuContext& custom_context,
    510                                  unsigned action);
    511   void OnUndo();
    512   void OnRedo();
    513   void OnCut();
    514   void OnCopy();
    515   void OnPaste();
    516   void OnPasteAndMatchStyle();
    517   void OnDelete();
    518   void OnSelectAll();
    519   void OnSelectRange(const gfx::Point& start, const gfx::Point& end);
    520   void OnUnselect();
    521   void OnReplace(const base::string16& text);
    522   void OnReplaceMisspelling(const base::string16& text);
    523   void OnCSSInsertRequest(const std::string& css);
    524   void OnJavaScriptExecuteRequest(const base::string16& javascript,
    525                                   int id,
    526                                   bool notify_result);
    527   void OnJavaScriptExecuteRequestForTests(const base::string16& javascript,
    528                                           int id,
    529                                           bool notify_result);
    530   void OnSetEditableSelectionOffsets(int start, int end);
    531   void OnSetCompositionFromExistingText(
    532       int start, int end,
    533       const std::vector<blink::WebCompositionUnderline>& underlines);
    534   void OnExtendSelectionAndDelete(int before, int after);
    535   void OnReload(bool ignore_cache);
    536   void OnTextSurroundingSelectionRequest(size_t max_length);
    537   void OnAddStyleSheetByURL(const std::string& url);
    538   void OnSetupTransitionView(const std::string& markup);
    539   void OnBeginExitTransition(const std::string& css_selector);
    540   void OnSetAccessibilityMode(AccessibilityMode new_mode);
    541   void OnDisownOpener();
    542 #if defined(OS_ANDROID)
    543   void OnSelectPopupMenuItems(bool canceled,
    544                               const std::vector<int>& selected_indices);
    545 #elif defined(OS_MACOSX)
    546   void OnSelectPopupMenuItem(int selected_index);
    547   void OnCopyToFindPboard();
    548 #endif
    549 
    550   // Virtual since overridden by WebTestProxy for layout tests.
    551   virtual blink::WebNavigationPolicy DecidePolicyForNavigation(
    552       RenderFrame* render_frame,
    553       const NavigationPolicyInfo& info);
    554   void OpenURL(blink::WebFrame* frame,
    555                const GURL& url,
    556                const Referrer& referrer,
    557                blink::WebNavigationPolicy policy);
    558 
    559   // Update current main frame's encoding and send it to browser window.
    560   // Since we want to let users see the right encoding info from menu
    561   // before finishing loading, we call the UpdateEncoding in
    562   // a) function:DidCommitLoadForFrame. When this function is called,
    563   // that means we have got first data. In here we try to get encoding
    564   // of page if it has been specified in http header.
    565   // b) function:DidReceiveTitle. When this function is called,
    566   // that means we have got specified title. Because in most of webpages,
    567   // title tags will follow meta tags. In here we try to get encoding of
    568   // page if it has been specified in meta tag.
    569   // c) function:DidFinishDocumentLoadForFrame. When this function is
    570   // called, that means we have got whole html page. In here we should
    571   // finally get right encoding of page.
    572   void UpdateEncoding(blink::WebFrame* frame,
    573                       const std::string& encoding_name);
    574 
    575   // Dispatches the current state of selection on the webpage to the browser if
    576   // it has changed.
    577   // TODO(varunjain): delete this method once we figure out how to keep
    578   // selection handles in sync with the webpage.
    579   void SyncSelectionIfRequired();
    580 
    581   // Returns whether |params.selection_text| should be synchronized to the
    582   // browser before bringing up the context menu. Static for testing.
    583   static bool ShouldUpdateSelectionTextFromContextMenuParams(
    584       const base::string16& selection_text,
    585       size_t selection_text_offset,
    586       const gfx::Range& selection_range,
    587       const ContextMenuParams& params);
    588 
    589   bool RunJavaScriptMessage(JavaScriptMessageType type,
    590                             const base::string16& message,
    591                             const base::string16& default_value,
    592                             const GURL& frame_url,
    593                             base::string16* result);
    594 
    595   // Loads the appropriate error page for the specified failure into the frame.
    596   void LoadNavigationErrorPage(const blink::WebURLRequest& failed_request,
    597                                const blink::WebURLError& error,
    598                                bool replace);
    599 
    600   void HandleJavascriptExecutionResult(const base::string16& javascript,
    601                                        int id,
    602                                        bool notify_result,
    603                                        v8::Handle<v8::Value> result);
    604 
    605   // Initializes |web_user_media_client_|. If this fails, because it wasn't
    606   // possible to create a MediaStreamClient (e.g., WebRTC is disabled), then
    607   // |web_user_media_client_| will remain NULL.
    608   void InitializeUserMediaClient();
    609 
    610   blink::WebMediaPlayer* CreateWebMediaPlayerForMediaStream(
    611       const blink::WebURL& url,
    612       blink::WebMediaPlayerClient* client);
    613 
    614   // Creates a factory object used for creating audio and video renderers.
    615   // The method is virtual so that layouttests can override it.
    616   virtual scoped_ptr<MediaStreamRendererFactory> CreateRendererFactory();
    617 
    618   // Returns the URL being loaded by the |frame_|'s request.
    619   GURL GetLoadingUrl() const;
    620 
    621 #if defined(OS_ANDROID)
    622   blink::WebMediaPlayer* CreateAndroidWebMediaPlayer(
    623       const blink::WebURL& url,
    624       blink::WebMediaPlayerClient* client,
    625       blink::WebContentDecryptionModule* initial_cdm);
    626 
    627   RendererMediaPlayerManager* GetMediaPlayerManager();
    628 #endif
    629 
    630 #if defined(ENABLE_BROWSER_CDMS)
    631   RendererCdmManager* GetCdmManager();
    632 #endif
    633 
    634   // Stores the WebLocalFrame we are associated with.
    635   blink::WebLocalFrame* frame_;
    636 
    637   base::WeakPtr<RenderViewImpl> render_view_;
    638   int routing_id_;
    639   bool is_swapped_out_;
    640   // RenderFrameProxy exists only when is_swapped_out_ is true.
    641   // TODO(nasko): This can be removed once we don't have a swapped out state on
    642   // RenderFrame. See https://crbug.com/357747.
    643   RenderFrameProxy* render_frame_proxy_;
    644   bool is_detaching_;
    645 
    646 #if defined(ENABLE_PLUGINS)
    647   // Current text input composition text. Empty if no composition is in
    648   // progress.
    649   base::string16 pepper_composition_text_;
    650 #endif
    651 
    652   RendererWebCookieJarImpl cookie_jar_;
    653 
    654   // All the registered observers.
    655   ObserverList<RenderFrameObserver> observers_;
    656 
    657   scoped_refptr<ChildFrameCompositingHelper> compositing_helper_;
    658 
    659   // The node that the context menu was pressed over.
    660   blink::WebNode context_menu_node_;
    661 
    662   // External context menu requests we're waiting for. "Internal"
    663   // (WebKit-originated) context menu events will have an ID of 0 and will not
    664   // be in this map.
    665   //
    666   // We don't want to add internal ones since some of the "special" page
    667   // handlers in the browser process just ignore the context menu requests so
    668   // avoid showing context menus, and so this will cause right clicks to leak
    669   // entries in this map. Most users of the custom context menu (e.g. Pepper
    670   // plugins) are normally only on "regular" pages and the regular pages will
    671   // always respond properly to the request, so we don't have to worry so
    672   // much about leaks.
    673   IDMap<ContextMenuClient, IDMapExternalPointer> pending_context_menus_;
    674 
    675   // The text selection the last time DidChangeSelection got called. May contain
    676   // additional characters before and after the selected text, for IMEs. The
    677   // portion of this string that is the actual selected text starts at index
    678   // |selection_range_.GetMin() - selection_text_offset_| and has length
    679   // |selection_range_.length()|.
    680   base::string16 selection_text_;
    681   // The offset corresponding to the start of |selection_text_| in the document.
    682   size_t selection_text_offset_;
    683   // Range over the document corresponding to the actual selected text (which
    684   // could correspond to a substring of |selection_text_|; see above).
    685   gfx::Range selection_range_;
    686   // Used to inform didChangeSelection() when it is called in the context
    687   // of handling a InputMsg_SelectRange IPC.
    688   bool handling_select_range_;
    689 
    690   // The next group of objects all implement RenderFrameObserver, so are deleted
    691   // along with the RenderFrame automatically.  This is why we just store weak
    692   // references.
    693 
    694   // Dispatches permission requests for Web Notifications.
    695   NotificationPermissionDispatcher* notification_permission_dispatcher_;
    696 
    697   // Holds a reference to the service which provides desktop notifications.
    698   // TODO(peter) Remove this once Web Notifications are routed through Platform.
    699   NotificationProvider* notification_provider_;
    700 
    701   // Destroyed via the RenderFrameObserver::OnDestruct() mechanism.
    702   UserMediaClientImpl* web_user_media_client_;
    703 
    704   // MidiClient attached to this frame; lazily initialized.
    705   MidiDispatcher* midi_dispatcher_;
    706 
    707 #if defined(OS_ANDROID)
    708   // Manages all media players in this render frame for communicating with the
    709   // real media player in the browser process. It's okay to use a raw pointer
    710   // since it's a RenderFrameObserver.
    711   RendererMediaPlayerManager* media_player_manager_;
    712 #endif
    713 
    714 #if defined(ENABLE_BROWSER_CDMS)
    715   // Manage all CDMs in this render frame for communicating with the real CDM in
    716   // the browser process. It's okay to use a raw pointer since it's a
    717   // RenderFrameObserver.
    718   RendererCdmManager* cdm_manager_;
    719 #endif
    720 
    721 #if defined(VIDEO_HOLE)
    722   // Whether or not this RenderFrameImpl contains a media player. Used to
    723   // register as an observer for video-hole-specific events.
    724   bool contains_media_player_;
    725 #endif
    726 
    727   // The geolocation dispatcher attached to this frame, lazily initialized.
    728   GeolocationDispatcher* geolocation_dispatcher_;
    729 
    730   // The push messaging dispatcher attached to this frame, lazily initialized.
    731   PushMessagingDispatcher* push_messaging_dispatcher_;
    732 
    733   ServiceRegistryImpl service_registry_;
    734 
    735   // The screen orientation dispatcher attached to the frame, lazily
    736   // initialized.
    737   ScreenOrientationDispatcher* screen_orientation_dispatcher_;
    738 
    739   // The Manifest Manager handles the manifest requests from the browser
    740   // process.
    741   ManifestManager* manifest_manager_;
    742 
    743   // The current accessibility mode.
    744   AccessibilityMode accessibility_mode_;
    745 
    746   // Only valid if |accessibility_mode_| is anything other than
    747   // AccessibilityModeOff.
    748   RendererAccessibility* renderer_accessibility_;
    749 
    750 #if defined(OS_MACOSX) || defined(OS_ANDROID)
    751   // The external popup for the currently showing select popup.
    752   scoped_ptr<ExternalPopupMenu> external_popup_menu_;
    753 #endif
    754 
    755   base::WeakPtrFactory<RenderFrameImpl> weak_factory_;
    756 
    757   DISALLOW_COPY_AND_ASSIGN(RenderFrameImpl);
    758 };
    759 
    760 }  // namespace content
    761 
    762 #endif  // CONTENT_RENDERER_RENDER_FRAME_IMPL_H_
    763