| 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 #include <string> |
| 10 #include <vector> | |
| 11 | 10 |
| 12 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 13 #include "chrome/browser/tab_contents/render_view_host_delegate_helper.h" | 12 #include "content/browser/tab_contents/tab_contents_delegate.h" |
| 14 #include "content/browser/javascript_dialogs.h" | 13 #include "content/browser/tab_contents/tab_contents_observer.h" |
| 15 #include "content/browser/renderer_host/render_view_host_delegate.h" | |
| 16 #include "content/public/browser/notification_observer.h" | 14 #include "content/public/browser/notification_observer.h" |
| 17 #include "content/public/browser/notification_registrar.h" | 15 #include "content/public/browser/notification_registrar.h" |
| 18 #include "content/public/common/window_container_type.h" | |
| 19 #include "webkit/glue/window_open_disposition.h" | 16 #include "webkit/glue/window_open_disposition.h" |
| 20 | 17 |
| 21 class TabContents; | 18 class Profile; |
| 22 struct WebPreferences; | |
| 23 | 19 |
| 24 namespace gfx { | 20 // This class consumes TabContents. It can host a renderer, but does not |
| 25 class Rect; | 21 // have any visible display. |
| 26 } | 22 class BackgroundContents : public TabContentsDelegate, |
| 27 | 23 public TabContentsObserver, |
| 28 // This class is a peer of TabContents. It can host a renderer, but does not | 24 public content::NotificationObserver { |
| 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 content::NotificationObserver, | |
| 36 public content::JavaScriptDialogDelegate { | |
| 37 public: | 25 public: |
| 38 class Delegate { | 26 class Delegate { |
| 39 public: | 27 public: |
| 40 // Called by ShowCreatedWindow. Asks the delegate to attach the opened | 28 // 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 | 29 // TabContents to a suitable container (e.g. browser) or to show it if it's |
| 42 // a popup window. | 30 // a popup window. |
| 43 virtual void AddTabContents(TabContents* new_contents, | 31 virtual void AddTabContents(TabContents* new_contents, |
| 44 WindowOpenDisposition disposition, | 32 WindowOpenDisposition disposition, |
| 45 const gfx::Rect& initial_pos, | 33 const gfx::Rect& initial_pos, |
| 46 bool user_gesture) = 0; | 34 bool user_gesture) = 0; |
| 47 | 35 |
| 48 protected: | 36 protected: |
| 49 virtual ~Delegate() {} | 37 virtual ~Delegate() {} |
| 50 }; | 38 }; |
| 51 | 39 |
| 52 BackgroundContents(SiteInstance* site_instance, | 40 BackgroundContents(SiteInstance* site_instance, |
| 53 int routing_id, | 41 int routing_id, |
| 54 Delegate* delegate); | 42 Delegate* delegate); |
| 55 virtual ~BackgroundContents(); | 43 virtual ~BackgroundContents(); |
| 56 | 44 |
| 57 // Provide access to the RenderViewHost for the | 45 TabContents* tab_contents() { return tab_contents_.get(); } |
| 58 // RenderViewHostDelegateViewHelper | 46 virtual const GURL& GetURL() const; |
| 59 RenderViewHost* render_view_host() { return render_view_host_; } | |
| 60 | 47 |
| 61 // RenderViewHostDelegate implementation. | 48 // TabContentsDelegate implementation: |
| 62 virtual BackgroundContents* GetAsBackgroundContents() OVERRIDE; | 49 virtual void CloseContents(TabContents* source) OVERRIDE; |
| 63 virtual RenderViewHostDelegate::View* GetViewDelegate() OVERRIDE; | 50 virtual bool ShouldSuppressDialogs() OVERRIDE; |
| 64 virtual const GURL& GetURL() const OVERRIDE; | 51 virtual void DidNavigateMainFramePostCommit(TabContents* tab) OVERRIDE; |
| 65 virtual content::ViewType GetRenderViewType() const OVERRIDE; | |
| 66 virtual void DidNavigate( | |
| 67 RenderViewHost* render_view_host, | |
| 68 const ViewHostMsg_FrameNavigate_Params& params) OVERRIDE; | |
| 69 virtual WebPreferences GetWebkitPrefs() OVERRIDE; | |
| 70 virtual void RunJavaScriptMessage(const RenderViewHost* rvh, | |
| 71 const string16& message, | |
| 72 const string16& default_prompt, | |
| 73 const GURL& frame_url, | |
| 74 const int flags, | |
| 75 IPC::Message* reply_msg, | |
| 76 bool* did_suppress_message) OVERRIDE; | |
| 77 virtual void Close(RenderViewHost* render_view_host) OVERRIDE; | |
| 78 virtual content::RendererPreferences GetRendererPrefs( | |
| 79 content::BrowserContext* browser_context) const OVERRIDE; | |
| 80 virtual void RenderViewGone(RenderViewHost* rvh, | |
| 81 base::TerminationStatus status, | |
| 82 int error_code) OVERRIDE; | |
| 83 | 52 |
| 84 // RenderViewHostDelegate::View | 53 // TabContentsObserver implementation: |
| 85 virtual void CreateNewWindow( | 54 virtual void RenderViewGone() OVERRIDE; |
| 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 | 55 |
| 112 // content::NotificationObserver | 56 // content::NotificationObserver |
| 113 virtual void Observe(int type, | 57 virtual void Observe(int type, |
| 114 const content::NotificationSource& source, | 58 const content::NotificationSource& source, |
| 115 const content::NotificationDetails& details); | 59 const content::NotificationDetails& details); |
| 116 | 60 |
| 117 // Overridden from JavaScriptDialogDelegate: | |
| 118 virtual void OnDialogClosed(IPC::Message* reply_msg, | |
| 119 bool success, | |
| 120 const string16& user_input) OVERRIDE; | |
| 121 virtual gfx::NativeWindow GetDialogRootWindow() OVERRIDE; | |
| 122 | |
| 123 // Helper to find the BackgroundContents that originated the given request. | |
| 124 // Can be NULL if the page has been closed or some other error occurs. | |
| 125 // Should only be called from the UI thread, since it accesses | |
| 126 // BackgroundContents. | |
| 127 static BackgroundContents* GetBackgroundContentsByID(int render_process_id, | |
| 128 int render_view_id); | |
| 129 | |
| 130 protected: | 61 protected: |
| 131 // Exposed for testing. | 62 // Exposed for testing. |
| 132 BackgroundContents(); | 63 BackgroundContents(); |
| 133 | 64 |
| 134 private: | 65 private: |
| 135 // The delegate for this BackgroundContents. | 66 // The delegate for this BackgroundContents. |
| 136 Delegate* delegate_; | 67 Delegate* delegate_; |
| 137 | 68 |
| 138 // The host for our HTML content. | 69 Profile* profile_; |
| 139 RenderViewHost* render_view_host_; | 70 scoped_ptr<TabContents> tab_contents_; |
| 140 | |
| 141 // Common implementations of some RenderViewHostDelegate::View methods. | |
| 142 RenderViewHostDelegateViewHelper delegate_view_helper_; | |
| 143 | |
| 144 // The URL being hosted. | |
| 145 GURL url_; | |
| 146 | |
| 147 content::NotificationRegistrar registrar_; | 71 content::NotificationRegistrar registrar_; |
| 148 | 72 |
| 149 DISALLOW_COPY_AND_ASSIGN(BackgroundContents); | 73 DISALLOW_COPY_AND_ASSIGN(BackgroundContents); |
| 150 }; | 74 }; |
| 151 | 75 |
| 152 // This is the data sent out as the details with BACKGROUND_CONTENTS_OPENED. | 76 // This is the data sent out as the details with BACKGROUND_CONTENTS_OPENED. |
| 153 struct BackgroundContentsOpenedDetails { | 77 struct BackgroundContentsOpenedDetails { |
| 154 // The BackgroundContents object that has just been opened. | 78 // The BackgroundContents object that has just been opened. |
| 155 BackgroundContents* contents; | 79 BackgroundContents* contents; |
| 156 | 80 |
| 157 // The name of the parent frame for these contents. | 81 // The name of the parent frame for these contents. |
| 158 const string16& frame_name; | 82 const string16& frame_name; |
| 159 | 83 |
| 160 // The ID of the parent application (if any). | 84 // The ID of the parent application (if any). |
| 161 const string16& application_id; | 85 const string16& application_id; |
| 162 }; | 86 }; |
| 163 | 87 |
| 164 #endif // CHROME_BROWSER_TAB_CONTENTS_BACKGROUND_CONTENTS_H_ | 88 #endif // CHROME_BROWSER_TAB_CONTENTS_BACKGROUND_CONTENTS_H_ |
| OLD | NEW |