blob: 206357b1ce7a39790e5a25974da573cad79dd9c1 [file] [log] [blame]
// Copyright (c) 2012 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_CORE_TAB_HELPER_H_
#define CHROME_BROWSER_UI_TAB_CONTENTS_CORE_TAB_HELPER_H_
#include <string>
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "chrome/common/chrome_render_frame.mojom.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"
#include "ui/gfx/geometry/size.h"
#include "url/gurl.h"
// Per-tab class to handle functionality that is core to the operation of tabs.
class CoreTabHelper : public content::WebContentsObserver,
public content::WebContentsUserData<CoreTabHelper> {
public:
~CoreTabHelper() override;
// Initial title assigned to NavigationEntries from Navigate.
static base::string16 GetDefaultTitle();
// Returns a human-readable description the tab's loading state.
base::string16 GetStatusText() const;
void UpdateContentRestrictions(int content_restrictions);
// Perform an image search for the image that triggered the context menu. The
// |src_url| is passed to the search request and is not used directly to fetch
// the image resources.
void SearchByImageInNewTab(content::RenderFrameHost* render_frame_host,
const GURL& src_url);
void set_new_tab_start_time(const base::TimeTicks& time) {
new_tab_start_time_ = time;
}
base::TimeTicks new_tab_start_time() const { return new_tab_start_time_; }
int content_restrictions() const { return content_restrictions_; }
std::unique_ptr<content::WebContents> SwapWebContents(
std::unique_ptr<content::WebContents> new_contents,
bool did_start_load,
bool did_finish_load);
private:
explicit CoreTabHelper(content::WebContents* web_contents);
friend class content::WebContentsUserData<CoreTabHelper>;
static bool GetStatusTextForWebContents(base::string16* status_text,
content::WebContents* source);
// content::WebContentsObserver overrides:
void DidStartLoading() override;
void OnVisibilityChanged(content::Visibility visibility) override;
void NavigationEntriesDeleted() override;
void DoSearchByImageInNewTab(
mojo::AssociatedRemote<chrome::mojom::ChromeRenderFrame>
chrome_render_frame,
const GURL& src_url,
const std::vector<uint8_t>& thumbnail_data,
const gfx::Size& original_size,
const std::string& image_extension);
// The time when we started to create the new tab page. This time is from
// before we created this WebContents.
base::TimeTicks new_tab_start_time_;
// Content restrictions, used to disable print/copy etc based on content's
// (full-page plugins for now only) permissions.
int content_restrictions_;
base::WeakPtrFactory<CoreTabHelper> weak_factory_{this};
WEB_CONTENTS_USER_DATA_KEY_DECL();
DISALLOW_COPY_AND_ASSIGN(CoreTabHelper);
};
#endif // CHROME_BROWSER_UI_TAB_CONTENTS_CORE_TAB_HELPER_H_