| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_TAB_CONTENTS_BACKGROUND_CONTENTS_H_ | 5 #ifndef CHROME_BROWSER_TAB_CONTENTS_BACKGROUND_CONTENTS_H_ |
| 6 #define CHROME_BROWSER_TAB_CONTENTS_BACKGROUND_CONTENTS_H_ | 6 #define CHROME_BROWSER_TAB_CONTENTS_BACKGROUND_CONTENTS_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 // TODO(jam): remove this file when all files have been converted. |
| 10 #include <vector> | 10 #include "content/browser/tab_contents/background_contents.h" |
| 11 | |
| 12 #include "chrome/browser/renderer_host/render_view_host_delegate.h" | |
| 13 #include "chrome/browser/tab_contents/render_view_host_delegate_helper.h" | |
| 14 #include "chrome/browser/ui/app_modal_dialogs/js_modal_dialog.h" | |
| 15 #include "chrome/common/notification_registrar.h" | |
| 16 #include "chrome/common/view_types.h" | |
| 17 #include "chrome/common/window_container_type.h" | |
| 18 #include "webkit/glue/window_open_disposition.h" | |
| 19 | |
| 20 class TabContents; | |
| 21 struct WebPreferences; | |
| 22 class DesktopNotificationHandler; | |
| 23 | |
| 24 namespace gfx { | |
| 25 class Rect; | |
| 26 } | |
| 27 | |
| 28 // This class is a peer of TabContents. It can host a renderer, but does not | |
| 29 // have any visible display. Its navigation is not managed by a | |
| 30 // NavigationController because is has no facility for navigating (other than | |
| 31 // programatically view window.location.href) or RenderViewHostManager because | |
| 32 // it is never allowed to navigate across a SiteInstance boundary. | |
| 33 class BackgroundContents : public RenderViewHostDelegate, | |
| 34 public RenderViewHostDelegate::View, | |
| 35 public NotificationObserver, | |
| 36 public JavaScriptAppModalDialogDelegate { | |
| 37 public: | |
| 38 class Delegate { | |
| 39 public: | |
| 40 // Called by ShowCreatedWindow. Asks the delegate to attach the opened | |
| 41 // TabContents to a suitable container (e.g. browser) or to show it if it's | |
| 42 // a popup window. | |
| 43 virtual void AddTabContents(TabContents* new_contents, | |
| 44 WindowOpenDisposition disposition, | |
| 45 const gfx::Rect& initial_pos, | |
| 46 bool user_gesture) = 0; | |
| 47 | |
| 48 protected: | |
| 49 virtual ~Delegate() {} | |
| 50 }; | |
| 51 | |
| 52 BackgroundContents(SiteInstance* site_instance, | |
| 53 int routing_id, | |
| 54 Delegate* delegate); | |
| 55 virtual ~BackgroundContents(); | |
| 56 | |
| 57 // Provide access to the RenderViewHost for the | |
| 58 // RenderViewHostDelegateViewHelper | |
| 59 RenderViewHost* render_view_host() { return render_view_host_; } | |
| 60 | |
| 61 // RenderViewHostDelegate implementation. | |
| 62 virtual BackgroundContents* GetAsBackgroundContents(); | |
| 63 virtual RenderViewHostDelegate::View* GetViewDelegate(); | |
| 64 virtual const GURL& GetURL() const; | |
| 65 virtual ViewType::Type GetRenderViewType() const; | |
| 66 virtual int GetBrowserWindowID() const; | |
| 67 virtual void DidNavigate(RenderViewHost* render_view_host, | |
| 68 const ViewHostMsg_FrameNavigate_Params& params); | |
| 69 virtual WebPreferences GetWebkitPrefs(); | |
| 70 virtual void ProcessWebUIMessage(const ViewHostMsg_DomMessage_Params& params); | |
| 71 virtual void RunJavaScriptMessage(const std::wstring& message, | |
| 72 const std::wstring& default_prompt, | |
| 73 const GURL& frame_url, | |
| 74 const int flags, | |
| 75 IPC::Message* reply_msg, | |
| 76 bool* did_suppress_message); | |
| 77 virtual void Close(RenderViewHost* render_view_host); | |
| 78 virtual RendererPreferences GetRendererPrefs(Profile* profile) const; | |
| 79 virtual void RenderViewGone(RenderViewHost* rvh, | |
| 80 base::TerminationStatus status, | |
| 81 int error_code); | |
| 82 virtual bool OnMessageReceived(const IPC::Message& message); | |
| 83 | |
| 84 // RenderViewHostDelegate::View | |
| 85 virtual void CreateNewWindow( | |
| 86 int route_id, | |
| 87 const ViewHostMsg_CreateWindow_Params& params); | |
| 88 virtual void CreateNewWidget(int route_id, WebKit::WebPopupType popup_type); | |
| 89 virtual void CreateNewFullscreenWidget(int route_id); | |
| 90 virtual void ShowCreatedWindow(int route_id, | |
| 91 WindowOpenDisposition disposition, | |
| 92 const gfx::Rect& initial_pos, | |
| 93 bool user_gesture); | |
| 94 virtual void ShowCreatedWidget(int route_id, | |
| 95 const gfx::Rect& initial_pos); | |
| 96 virtual void ShowCreatedFullscreenWidget(int route_id); | |
| 97 virtual void ShowContextMenu(const ContextMenuParams& params) {} | |
| 98 virtual void ShowPopupMenu(const gfx::Rect& bounds, | |
| 99 int item_height, | |
| 100 double item_font_size, | |
| 101 int selected_item, | |
| 102 const std::vector<WebMenuItem>& items, | |
| 103 bool right_aligned) {} | |
| 104 virtual void StartDragging(const WebDropData& drop_data, | |
| 105 WebKit::WebDragOperationsMask allowed_operations, | |
| 106 const SkBitmap& image, | |
| 107 const gfx::Point& image_offset) {} | |
| 108 virtual void UpdateDragCursor(WebKit::WebDragOperation operation) {} | |
| 109 virtual void GotFocus() {} | |
| 110 virtual void TakeFocus(bool reverse) {} | |
| 111 virtual void LostCapture() {} | |
| 112 virtual void Activate() {} | |
| 113 virtual void Deactivate() {} | |
| 114 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, | |
| 115 bool* is_keyboard_shortcut); | |
| 116 virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {} | |
| 117 virtual void HandleMouseMove() {} | |
| 118 virtual void HandleMouseDown() {} | |
| 119 virtual void HandleMouseLeave() {} | |
| 120 virtual void HandleMouseUp() {} | |
| 121 virtual void HandleMouseActivate() {} | |
| 122 virtual void UpdatePreferredSize(const gfx::Size& new_size) {} | |
| 123 | |
| 124 // NotificationObserver | |
| 125 virtual void Observe(NotificationType type, | |
| 126 const NotificationSource& source, | |
| 127 const NotificationDetails& details); | |
| 128 | |
| 129 // Overridden from JavaScriptAppModalDialogDelegate: | |
| 130 virtual void OnMessageBoxClosed(IPC::Message* reply_msg, | |
| 131 bool success, | |
| 132 const std::wstring& prompt); | |
| 133 virtual void SetSuppressMessageBoxes(bool suppress_message_boxes) {} | |
| 134 virtual gfx::NativeWindow GetMessageBoxRootWindow(); | |
| 135 virtual TabContents* AsTabContents(); | |
| 136 virtual ExtensionHost* AsExtensionHost(); | |
| 137 | |
| 138 virtual void UpdateInspectorSetting(const std::string& key, | |
| 139 const std::string& value); | |
| 140 virtual void ClearInspectorSettings(); | |
| 141 | |
| 142 // Helper to find the BackgroundContents that originated the given request. | |
| 143 // Can be NULL if the page has been closed or some other error occurs. | |
| 144 // Should only be called from the UI thread, since it accesses | |
| 145 // BackgroundContents. | |
| 146 static BackgroundContents* GetBackgroundContentsByID(int render_process_id, | |
| 147 int render_view_id); | |
| 148 | |
| 149 protected: | |
| 150 // Exposed for testing. | |
| 151 BackgroundContents(); | |
| 152 | |
| 153 private: | |
| 154 // The delegate for this BackgroundContents. | |
| 155 Delegate* delegate_; | |
| 156 | |
| 157 // The host for our HTML content. | |
| 158 RenderViewHost* render_view_host_; | |
| 159 | |
| 160 // Common implementations of some RenderViewHostDelegate::View methods. | |
| 161 RenderViewHostDelegateViewHelper delegate_view_helper_; | |
| 162 | |
| 163 // The URL being hosted. | |
| 164 GURL url_; | |
| 165 | |
| 166 NotificationRegistrar registrar_; | |
| 167 | |
| 168 // Handles desktop notification IPCs. | |
| 169 scoped_ptr<DesktopNotificationHandler> desktop_notification_handler_; | |
| 170 | |
| 171 DISALLOW_COPY_AND_ASSIGN(BackgroundContents); | |
| 172 }; | |
| 173 | |
| 174 // This is the data sent out as the details with BACKGROUND_CONTENTS_OPENED. | |
| 175 struct BackgroundContentsOpenedDetails { | |
| 176 // The BackgroundContents object that has just been opened. | |
| 177 BackgroundContents* contents; | |
| 178 | |
| 179 // The name of the parent frame for these contents. | |
| 180 const string16& frame_name; | |
| 181 | |
| 182 // The ID of the parent application (if any). | |
| 183 const string16& application_id; | |
| 184 }; | |
| 185 | 11 |
| 186 #endif // CHROME_BROWSER_TAB_CONTENTS_BACKGROUND_CONTENTS_H_ | 12 #endif // CHROME_BROWSER_TAB_CONTENTS_BACKGROUND_CONTENTS_H_ |
| OLD | NEW |