Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / tab_contents / core_tab_helper.h
blobc127aa7bc5a3218079b4ab2152c71ff37927877c
1 // Copyright (c) 2012 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.
5 #ifndef CHROME_BROWSER_UI_TAB_CONTENTS_CORE_TAB_HELPER_H_
6 #define CHROME_BROWSER_UI_TAB_CONTENTS_CORE_TAB_HELPER_H_
8 #include "base/time/time.h"
9 #include "content/public/browser/web_contents_observer.h"
10 #include "content/public/browser/web_contents_user_data.h"
12 class CoreTabHelperDelegate;
14 // Per-tab class to handle functionality that is core to the operation of tabs.
15 class CoreTabHelper : public content::WebContentsObserver,
16 public content::WebContentsUserData<CoreTabHelper> {
17 public:
18 ~CoreTabHelper() override;
20 // Initial title assigned to NavigationEntries from Navigate.
21 static base::string16 GetDefaultTitle();
23 // Returns a human-readable description the tab's loading state.
24 base::string16 GetStatusText() const;
26 // Notification that tab closing has started. This can be called multiple
27 // times, subsequent calls are ignored.
28 void OnCloseStarted();
30 // Notification that tab closing was cancelled. This can happen when a user
31 // cancels a window close via another tab's beforeunload dialog.
32 void OnCloseCanceled();
34 // Set the time during close when unload is started. Normally, this is set
35 // after the beforeunload dialog. However, for a window close, it is set
36 // after all the beforeunload dialogs have finished.
37 void OnUnloadStarted();
39 // Set the time during close when the tab is no longer visible.
40 void OnUnloadDetachedStarted();
42 void UpdateContentRestrictions(int content_restrictions);
44 CoreTabHelperDelegate* delegate() const { return delegate_; }
45 void set_delegate(CoreTabHelperDelegate* d) { delegate_ = d; }
47 void set_new_tab_start_time(const base::TimeTicks& time) {
48 new_tab_start_time_ = time;
51 base::TimeTicks new_tab_start_time() const { return new_tab_start_time_; }
52 int content_restrictions() const { return content_restrictions_; }
54 private:
55 explicit CoreTabHelper(content::WebContents* web_contents);
56 friend class content::WebContentsUserData<CoreTabHelper>;
58 static bool GetStatusTextForWebContents(base::string16* status_text,
59 content::WebContents* source);
61 // content::WebContentsObserver overrides:
62 void DidStartLoading() override;
63 void WasShown() override;
64 void WebContentsDestroyed() override;
65 void BeforeUnloadFired(const base::TimeTicks& proceed_time) override;
66 void BeforeUnloadDialogCancelled() override;
67 bool OnMessageReceived(const IPC::Message& message,
68 content::RenderFrameHost* render_frame_host) override;
70 void OnRequestThumbnailForContextNodeACK(const std::string& thumbnail_data,
71 const gfx::Size& original_size);
73 // Delegate for notifying our owner about stuff. Not owned by us.
74 CoreTabHelperDelegate* delegate_;
76 // The time when we started to create the new tab page. This time is from
77 // before we created this WebContents.
78 base::TimeTicks new_tab_start_time_;
80 // The time that we started to close this WebContents.
81 base::TimeTicks close_start_time_;
83 // The time when onbeforeunload ended.
84 base::TimeTicks before_unload_end_time_;
86 // The time when the tab was removed from view during close.
87 base::TimeTicks unload_detached_start_time_;
89 // Content restrictions, used to disable print/copy etc based on content's
90 // (full-page plugins for now only) permissions.
91 int content_restrictions_;
93 DISALLOW_COPY_AND_ASSIGN(CoreTabHelper);
96 #endif // CHROME_BROWSER_UI_TAB_CONTENTS_CORE_TAB_HELPER_H_