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
|
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_WEBUI_NTP_NEW_TAB_UI_H_
#define CHROME_BROWSER_UI_WEBUI_NTP_NEW_TAB_UI_H_
#include <string>
#include "base/memory/raw_ptr.h"
#include "base/values.h"
#include "chrome/common/webui_url_constants.h"
#include "content/public/browser/url_data_source.h"
#include "content/public/browser/web_ui_controller.h"
#include "content/public/browser/webui_config.h"
#include "content/public/common/url_constants.h"
class GURL;
class NewTabUI;
class Profile;
class NewTabUIConfig : public content::DefaultWebUIConfig<NewTabUI> {
public:
NewTabUIConfig()
: DefaultWebUIConfig(content::kChromeUIScheme,
chrome::kChromeUINewTabHost) {}
// content::WebUIConfig:
bool IsWebUIEnabled(content::BrowserContext* browser_context) override;
};
// The WebUIController used for the incognito and guest mode New Tab page.
class NewTabUI : public content::WebUIController {
public:
explicit NewTabUI(content::WebUI* web_ui);
NewTabUI(const NewTabUI&) = delete;
NewTabUI& operator=(const NewTabUI&) = delete;
~NewTabUI() override;
// Checks whether the given URL points to an NTP WebUI. Note that this only
// applies to incognito and guest mode NTPs - you probably want to check
// search::NavEntryIsInstantNTP too!
static bool IsNewTab(const GURL& url);
// TODO(dbeam): why are these static |Set*()| methods on NewTabUI?
// Adds "url", "title", and "direction" keys on incoming dictionary, setting
// title as the url as a fallback on empty title.
static void SetUrlTitleAndDirection(base::Value::Dict* dictionary,
const std::u16string& title,
const GURL& gurl);
// Adds "full_name" and "full_name_direction" keys on incoming dictionary.
static void SetFullNameAndDirection(const std::u16string& full_name,
base::Value::Dict* dictionary);
private:
class NewTabHTMLSource : public content::URLDataSource {
public:
explicit NewTabHTMLSource(Profile* profile);
NewTabHTMLSource(const NewTabHTMLSource&) = delete;
NewTabHTMLSource& operator=(const NewTabHTMLSource&) = delete;
~NewTabHTMLSource() override;
// content::URLDataSource implementation.
std::string GetSource() override;
void StartDataRequest(
const GURL& url,
const content::WebContents::Getter& wc_getter,
content::URLDataSource::GotDataCallback callback) override;
std::string GetMimeType(const GURL&) override;
bool ShouldReplaceExistingSource() override;
std::string GetContentSecurityPolicy(
network::mojom::CSPDirectiveName directive) override;
private:
// Pointer back to the original profile.
raw_ptr<Profile, FlakyDanglingUntriaged> profile_;
};
void OnShowBookmarkBarChanged();
Profile* GetProfile() const;
};
#endif // CHROME_BROWSER_UI_WEBUI_NTP_NEW_TAB_UI_H_
|