1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_TAB_CONTENTS_TAB_CONTENTS_WRAPPER_H_
#define CHROME_BROWSER_UI_TAB_CONTENTS_TAB_CONTENTS_WRAPPER_H_
#pragma once
#include <string>
#include <vector>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/prefs/pref_change_registrar.h"
#include "chrome/browser/printing/print_view_manager.h"
#include "content/browser/tab_contents/tab_contents.h"
#include "content/browser/tab_contents/tab_contents_observer.h"
#include "content/common/notification_registrar.h"
namespace prerender {
class PrerenderObserver;
}
namespace printing {
class PrintPreviewMessageHandler;
}
class AutocompleteHistoryManager;
class AutofillManager;
class AutomationTabHelper;
class BlockedContentTabHelper;
class BookmarkTabHelper;
class DownloadTabHelper;
class Extension;
class ExtensionTabHelper;
class ExtensionWebNavigationTabObserver;
class ExternalProtocolObserver;
class FaviconTabHelper;
class FileSelectObserver;
class FindTabHelper;
class InfoBarDelegate;
class HistoryTabHelper;
class NavigationController;
class OmniboxSearchHint;
class PasswordManager;
class PasswordManagerDelegate;
class PluginObserver;
class RestoreTabHelper;
class SearchEngineTabHelper;
class TabContentsSSLHelper;
class TabContentsWrapperDelegate;
class TabSpecificContentSettings;
class ThumbnailGenerator;
class TranslateTabHelper;
namespace safe_browsing {
class ClientSideDetectionHost;
}
// Wraps TabContents and all of its supporting objects in order to control
// their ownership and lifetime, while allowing TabContents to remain generic
// and re-usable in other projects.
// TODO(pinkerton): Eventually, this class will become TabContents as far as
// the browser front-end is concerned, and the current TabContents will be
// renamed to something like WebPage or WebView (ben's suggestions).
class TabContentsWrapper : public TabContentsObserver,
public NotificationObserver {
public:
// Takes ownership of |contents|, which must be heap-allocated (as it lives
// in a scoped_ptr) and can not be NULL.
explicit TabContentsWrapper(TabContents* contents);
virtual ~TabContentsWrapper();
// Used to retrieve this object from |tab_contents_|, which is placed in
// its property bag to avoid adding additional interfaces.
static PropertyAccessor<TabContentsWrapper*>* property_accessor();
static void RegisterUserPrefs(PrefService* prefs);
// Initial title assigned to NavigationEntries from Navigate.
static string16 GetDefaultTitle();
// Returns a human-readable description the tab's loading state.
string16 GetStatusText() const;
// Create a TabContentsWrapper with the same state as this one. The returned
// heap-allocated pointer is owned by the caller.
TabContentsWrapper* Clone();
// Captures a snapshot of the page.
void CaptureSnapshot();
// Helper to retrieve the existing instance that wraps a given TabContents.
// Returns NULL if there is no such existing instance.
// NOTE: This is not intended for general use. It is intended for situations
// like callbacks from content/ where only a TabContents is available. In the
// general case, please do NOT use this; plumb TabContentsWrapper through the
// chrome/ code instead of TabContents.
static TabContentsWrapper* GetCurrentWrapperForContents(
TabContents* contents);
static const TabContentsWrapper* GetCurrentWrapperForContents(
const TabContents* contents);
TabContentsWrapperDelegate* delegate() const { return delegate_; }
void set_delegate(TabContentsWrapperDelegate* d) { delegate_ = d; }
TabContents* tab_contents() const { return tab_contents_.get(); }
NavigationController& controller() const {
return tab_contents()->controller();
}
TabContentsView* view() const { return tab_contents()->view(); }
RenderViewHost* render_view_host() const {
return tab_contents()->render_view_host();
}
Profile* profile() const { return tab_contents()->profile(); }
// Tab Helpers ---------------------------------------------------------------
AutocompleteHistoryManager* autocomplete_history_manager() {
return autocomplete_history_manager_.get();
}
AutofillManager* autofill_manager() { return autofill_manager_.get(); }
// Used only for testing/automation.
AutomationTabHelper* automation_tab_helper() {
return automation_tab_helper_.get();
}
BlockedContentTabHelper* blocked_content_tab_helper() {
return blocked_content_tab_helper_.get();
}
BookmarkTabHelper* bookmark_tab_helper() {
return bookmark_tab_helper_.get();
}
DownloadTabHelper* download_tab_helper() {
return download_tab_helper_.get();
}
ExtensionTabHelper* extension_tab_helper() {
return extension_tab_helper_.get();
}
const ExtensionTabHelper* extension_tab_helper() const {
return extension_tab_helper_.get();
}
FindTabHelper* find_tab_helper() { return find_tab_helper_.get(); }
FaviconTabHelper* favicon_tab_helper() { return favicon_tab_helper_.get(); }
HistoryTabHelper* history_tab_helper() { return history_tab_helper_.get(); }
PasswordManager* password_manager() { return password_manager_.get(); }
printing::PrintViewManager* print_view_manager() {
return print_view_manager_.get();
}
safe_browsing::ClientSideDetectionHost* safebrowsing_detection_host() {
return safebrowsing_detection_host_.get();
}
SearchEngineTabHelper* search_engine_tab_helper() {
return search_engine_tab_helper_.get();
}
TabContentsSSLHelper* ssl_helper() { return ssl_helper_.get(); }
TabSpecificContentSettings* content_settings() {
return content_settings_.get();
}
TranslateTabHelper* translate_tab_helper() {
return translate_tab_helper_.get();
}
prerender::PrerenderObserver* prerender_observer() {
return prerender_observer_.get();
}
RestoreTabHelper* restore_tab_helper() {
return restore_tab_helper_.get();
}
const RestoreTabHelper* restore_tab_helper() const {
return restore_tab_helper_.get();
}
// Overrides -----------------------------------------------------------------
// TabContentsObserver overrides:
virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE;
virtual void RenderViewGone() OVERRIDE;
virtual void DidBecomeSelected() OVERRIDE;
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
virtual void TabContentsDestroyed(TabContents* tab) OVERRIDE;
// NotificationObserver overrides:
virtual void Observe(int type,
const NotificationSource& source,
const NotificationDetails& details) OVERRIDE;
// Infobars ------------------------------------------------------------------
// Adds an InfoBar for the specified |delegate|.
//
// If infobars are disabled for this tab or the tab already has a delegate
// which returns true for InfoBarDelegate::EqualsDelegate(delegate),
// |delegate| is closed immediately without being added.
void AddInfoBar(InfoBarDelegate* delegate);
// Removes the InfoBar for the specified |delegate|.
//
// If infobars are disabled for this tab, this will do nothing, on the
// assumption that the matching AddInfoBar() call will have already closed the
// delegate (see above).
void RemoveInfoBar(InfoBarDelegate* delegate);
// Replaces one infobar with another, without any animation in between.
//
// If infobars are disabled for this tab, |new_delegate| is closed immediately
// without being added, and nothing else happens.
//
// NOTE: This does not perform any EqualsDelegate() checks like AddInfoBar().
void ReplaceInfoBar(InfoBarDelegate* old_delegate,
InfoBarDelegate* new_delegate);
// Enumeration and access functions.
size_t infobar_count() const { return infobars_.size(); }
// WARNING: This does not sanity-check |index|!
InfoBarDelegate* GetInfoBarDelegateAt(size_t index);
void set_infobars_enabled(bool value) { infobars_enabled_ = value; }
private:
// Internal helpers ----------------------------------------------------------
// Message handlers.
void OnJSOutOfMemory();
void OnRegisterProtocolHandler(const std::string& protocol,
const GURL& url,
const string16& title);
void OnSnapshot(const SkBitmap& bitmap);
void OnPDFHasUnsupportedFeature();
void OnDidBlockDisplayingInsecureContent();
void OnDidBlockRunningInsecureContent();
// Returns the server that can provide alternate error pages. If the returned
// URL is empty, the default error page built into WebKit will be used.
GURL GetAlternateErrorPageURL() const;
// Send the alternate error page URL to the renderer.
void UpdateAlternateErrorPageURL(RenderViewHost* rvh);
// Update the RenderView's WebPreferences.
void UpdateWebPreferences();
// Update the TabContents's RendererPreferences.
void UpdateRendererPreferences();
// Create or destroy SafebrowsingDetectionHost as needed if the user's
// safe browsing preference has changed.
void UpdateSafebrowsingDetectionHost();
void RemoveInfoBarInternal(InfoBarDelegate* delegate, bool animate);
void RemoveAllInfoBars(bool animate);
// Data for core operation ---------------------------------------------------
// Delegate for notifying our owner about stuff. Not owned by us.
TabContentsWrapperDelegate* delegate_;
// Delegates for InfoBars associated with this TabContentsWrapper.
std::vector<InfoBarDelegate*> infobars_;
bool infobars_enabled_;
NotificationRegistrar registrar_;
PrefChangeRegistrar pref_change_registrar_;
// Data for current page -----------------------------------------------------
// Shows an info-bar to users when they search from a known search engine and
// have never used the omnibox for search before.
scoped_ptr<OmniboxSearchHint> omnibox_search_hint_;
// Tab Helpers ---------------------------------------------------------------
// (These provide API for callers and have a getter function listed in the
// "Tab Helpers" section in the member functions area, above.)
scoped_ptr<AutocompleteHistoryManager> autocomplete_history_manager_;
scoped_ptr<AutofillManager> autofill_manager_;
scoped_ptr<AutomationTabHelper> automation_tab_helper_;
scoped_ptr<BlockedContentTabHelper> blocked_content_tab_helper_;
scoped_ptr<BookmarkTabHelper> bookmark_tab_helper_;
scoped_ptr<DownloadTabHelper> download_tab_helper_;
scoped_ptr<ExtensionTabHelper> extension_tab_helper_;
scoped_ptr<FaviconTabHelper> favicon_tab_helper_;
scoped_ptr<FindTabHelper> find_tab_helper_;
scoped_ptr<HistoryTabHelper> history_tab_helper_;
scoped_ptr<RestoreTabHelper> restore_tab_helper_;
// PasswordManager and its delegate. The delegate must outlive the manager,
// per documentation in password_manager.h.
scoped_ptr<PasswordManagerDelegate> password_manager_delegate_;
scoped_ptr<PasswordManager> password_manager_;
// Handles print job for this contents.
scoped_ptr<printing::PrintViewManager> print_view_manager_;
// Handles IPCs related to SafeBrowsing client-side phishing detection.
scoped_ptr<safe_browsing::ClientSideDetectionHost>
safebrowsing_detection_host_;
scoped_ptr<SearchEngineTabHelper> search_engine_tab_helper_;
scoped_ptr<TabContentsSSLHelper> ssl_helper_;
// The TabSpecificContentSettings object is used to query the blocked content
// state by various UI elements.
scoped_ptr<TabSpecificContentSettings> content_settings_;
scoped_ptr<TranslateTabHelper> translate_tab_helper_;
// Per-tab observers ---------------------------------------------------------
// (These provide no API for callers; objects that need to exist 1:1 with tabs
// and silently do their thing live here.)
scoped_ptr<ExternalProtocolObserver> external_protocol_observer_;
scoped_ptr<FileSelectObserver> file_select_observer_;
scoped_ptr<PluginObserver> plugin_observer_;
scoped_ptr<prerender::PrerenderObserver> prerender_observer_;
scoped_ptr<printing::PrintPreviewMessageHandler> print_preview_;
scoped_ptr<ExtensionWebNavigationTabObserver> webnavigation_observer_;
scoped_ptr<ThumbnailGenerator> thumbnail_generation_observer_;
// TabContents (MUST BE LAST) ------------------------------------------------
// If true, we're running the destructor.
bool in_destructor_;
// The supporting objects need to outlive the TabContents dtor (as they may
// be called upon during its execution). As a result, this must come last
// in the list.
scoped_ptr<TabContents> tab_contents_;
DISALLOW_COPY_AND_ASSIGN(TabContentsWrapper);
};
#endif // CHROME_BROWSER_UI_TAB_CONTENTS_TAB_CONTENTS_WRAPPER_H_
|